summaryrefslogtreecommitdiff
path: root/eth-wire
diff options
context:
space:
mode:
authorAntoine A <>2022-02-03 18:26:19 +0100
committerAntoine A <>2022-02-03 18:26:19 +0100
commit9eabce59a590696c5ca5c2a787c3867256348c4f (patch)
treed3695ea60dfe11612c8434fafe473de07267cf99 /eth-wire
parent6d2599c1b1ed11109b6a7c012167608eca00145e (diff)
downloaddepolymerization-9eabce59a590696c5ca5c2a787c3867256348c4f.tar.gz
depolymerization-9eabce59a590696c5ca5c2a787c3867256348c4f.tar.bz2
depolymerization-9eabce59a590696c5ca5c2a787c3867256348c4f.zip
Remove Delayed transaction status
Diffstat (limited to 'eth-wire')
-rw-r--r--eth-wire/src/loops/worker.rs46
-rw-r--r--eth-wire/src/main.rs15
-rw-r--r--eth-wire/src/status.rs69
3 files changed, 26 insertions, 104 deletions
diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs
index ab0f0e3..a98571e 100644
--- a/eth-wire/src/loops/worker.rs
+++ b/eth-wire/src/loops/worker.rs
@@ -15,22 +15,22 @@
*/
use std::time::SystemTime;
-use eth_wire::{
- metadata::InMetadata,
- rpc::Rpc,
- taler_util::{eth_payto_url, eth_to_taler},
- BlockState,
-};
use common::{
api_common::base32,
log::log::{error, info},
postgres::{fallible_iterator::FallibleIterator, Client},
sql::{sql_array, sql_url},
+ status::WithdrawStatus,
+};
+use eth_wire::{
+ metadata::InMetadata,
+ rpc::Rpc,
+ taler_util::{eth_payto_url, eth_to_taler},
+ BlockState,
};
use crate::{
sql::{sql_addr, sql_eth_amount},
- status::TxStatus,
LoopResult, WireState,
};
@@ -54,7 +54,7 @@ pub fn worker(mut rpc: Rpc, mut db: Client, state: &WireState) {
sync_chain(&mut rpc, &mut db, state)?;
- while send(&mut db, &mut rpc, state)? {}
+ while withdraw(&mut db, &mut rpc, state)? {}
Ok(())
})();
@@ -115,12 +115,12 @@ fn sync_chain(rpc: &mut Rpc, db: &mut Client, state: &WireState) -> LoopResult<b
Ok(true)
}
-/// Send a transaction on the blockchain, return true if more transactions with the same status remains
-fn send(db: &mut Client, rpc: &mut Rpc, state: &WireState) -> LoopResult<bool> {
+/// Send a withdraw transaction on the blockchain, return false if no more requested transaction are found
+fn withdraw(db: &mut Client, rpc: &mut Rpc, state: &WireState) -> LoopResult<bool> {
// We rely on the advisory lock to ensure we are the only one sending transactions
let row = db.query_opt(
"SELECT id, amount, wtid, credit_acc, exchange_url FROM tx_out WHERE status=$1 ORDER BY _date LIMIT 1",
-&[&(TxStatus::Requested as i16)],
+&[&(WithdrawStatus::Requested as i16)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
@@ -128,23 +128,13 @@ fn send(db: &mut Client, rpc: &mut Rpc, state: &WireState) -> LoopResult<bool> {
let wtid: [u8; 32] = sql_array(row, 2);
let addr = sql_addr(row, 3);
let url = sql_url(row, 4);
- match rpc.withdraw(state.address, addr, amount, wtid, url) {
- Ok(tx_id) => {
- db.execute(
- "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
- &[&(TxStatus::Sent as i16), &tx_id.as_ref(), &id],
- )?;
- let amount = eth_to_taler(&amount);
- info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id, addr);
- }
- Err(e) => {
- db.execute(
- "UPDATE tx_out SET status=$1 WHERE id=$2",
- &[&(TxStatus::Delayed as i16), &id],
- )?;
- Err(e)?;
- }
- }
+ let tx_id = rpc.withdraw(state.address, addr, amount, wtid, url)?;
+ db.execute(
+ "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
+ &[&(WithdrawStatus::Sent as i16), &tx_id.as_ref(), &id],
+ )?;
+ let amount = eth_to_taler(&amount);
+ info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id, addr);
}
Ok(row.is_some())
}
diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs
index a229ddd..de76e33 100644
--- a/eth-wire/src/main.rs
+++ b/eth-wire/src/main.rs
@@ -16,20 +16,19 @@
use std::sync::atomic::AtomicU16;
+use common::{
+ config::{load_eth_config, EthConfig},
+ postgres::{self, Client, NoTls},
+};
use eth_wire::{
rpc::{self, Rpc},
taler_util::eth_payto_addr,
};
use ethereum_types::H160;
use loops::{watcher::watcher, worker::worker};
-use common::{
- config::{load_eth_config, EthConfig},
- postgres::{self, Client, NoTls},
-};
-mod status;
-mod sql;
mod loops;
+mod sql;
pub struct WireState {
confirmation: AtomicU16,
@@ -74,7 +73,9 @@ fn main() {
)
.unwrap();
- rpc_worker.unlock_account(&state.address, "password").unwrap();
+ rpc_worker
+ .unlock_account(&state.address, "password")
+ .unwrap();
let rpc_watcher = Rpc::new(
state
diff --git a/eth-wire/src/status.rs b/eth-wire/src/status.rs
deleted file mode 100644
index 3ad45f9..0000000
--- a/eth-wire/src/status.rs
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-//! Transactions status in database
-
-/// Outgoing transaction status
-#[repr(u8)]
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum TxStatus {
- /// Client have ask for a transaction (default)
- Requested = 0,
- /// The wire failed to send this transaction and will try later
- Delayed = 1,
- /// Transaction have been announced to the bitcoin network
- Sent = 2,
-}
-
-impl TryFrom<u8> for TxStatus {
- type Error = ();
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- x if x == TxStatus::Requested as u8 => Ok(TxStatus::Requested),
- x if x == TxStatus::Sent as u8 => Ok(TxStatus::Sent),
- x if x == TxStatus::Delayed as u8 => Ok(TxStatus::Delayed),
- _ => Err(()),
- }
- }
-}
-
-/// Bounce transaction status
-#[repr(u8)]
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum BounceStatus {
- /// Bounce have been requested (default)
- Requested = 0,
- /// The wire failed to send this bounce and will try later
- Delayed = 1,
- /// Bounce will not be sent (e.g: bounce amount smaller than bounce fee)
- Ignored = 2,
- /// Bounce have been announced to the bitcoin network
- Sent = 3,
-}
-
-impl TryFrom<u8> for BounceStatus {
- type Error = ();
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- x if x == BounceStatus::Requested as u8 => Ok(BounceStatus::Requested),
- x if x == BounceStatus::Sent as u8 => Ok(BounceStatus::Sent),
- x if x == BounceStatus::Delayed as u8 => Ok(BounceStatus::Delayed),
- x if x == BounceStatus::Ignored as u8 => Ok(BounceStatus::Ignored),
- _ => Err(()),
- }
- }
-}