depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit dda381097b71d82d1c055c2f00bc924aa4003ce6
parent 2295a6e5fc493341bfc2aff49df4392020a17c43
Author: Antoine A <>
Date:   Wed,  2 Mar 2022 21:22:36 +0100

Fix gateway and clippy fix

Diffstat:
Mbtc-wire/src/lib.rs | 4++--
Meth-wire/src/lib.rs | 4++--
Minstrumentation/src/btc.rs | 4++--
Minstrumentation/src/eth.rs | 4++--
Minstrumentation/src/main.rs | 37+++++++++++++++----------------------
Mwire-gateway/src/main.rs | 8++++----
6 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/btc-wire/src/lib.rs b/btc-wire/src/lib.rs @@ -140,12 +140,12 @@ impl Rpc { } } -const DEFAULT_BOUNCE_FEE: &'static str = "BTC:0.00001"; +const DEFAULT_BOUNCE_FEE: &str = "BTC:0.00001"; const DEFAULT_CONFIRMATION: u16 = 6; fn config_bounce_fee(config: &BtcConfig) -> Amount { let config = config.bounce_fee.as_deref().unwrap_or(DEFAULT_BOUNCE_FEE); - TalerAmount::from_str(&config) + TalerAmount::from_str(config) .ok() .and_then(|a| taler_to_btc(&a).ok()) .expect("config value BOUNCE_FEE is no a valid bitcoin amount") diff --git a/eth-wire/src/lib.rs b/eth-wire/src/lib.rs @@ -197,7 +197,7 @@ impl SyncState { } const DEFAULT_CONFIRMATION: u16 = 24; -const DEFAULT_BOUNCE_FEE: &'static str = "ETH:0.00001"; +const DEFAULT_BOUNCE_FEE: &str = "ETH:0.00001"; pub struct WireState { pub confirmation: AtomicU32, pub max_confirmations: u32, @@ -221,7 +221,7 @@ impl WireState { fn config_bounce_fee(config: &EthConfig) -> U256 { let config = config.bounce_fee.as_deref().unwrap_or(DEFAULT_BOUNCE_FEE); - Amount::from_str(&config) + Amount::from_str(config) .ok() .and_then(|a| taler_to_eth(&a).ok()) .expect("config value BOUNCE_FEE is no a valid ethereum amount") diff --git a/instrumentation/src/btc.rs b/instrumentation/src/btc.rs @@ -39,8 +39,8 @@ fn wait_for_pending(since: &mut BlockHash, client_rpc: &mut Rpc, wire_rpc: &mut print_now("Wait for pending transactions mining:"); 'l: loop { std::thread::sleep(Duration::from_secs(1)); // Wait for btc-wire to act - let sync = client_rpc.list_since_block(Some(&since), 1).unwrap(); - let sync2 = wire_rpc.list_since_block(Some(&since), 1).unwrap(); + let sync = client_rpc.list_since_block(Some(since), 1).unwrap(); + let sync2 = wire_rpc.list_since_block(Some(since), 1).unwrap(); *since = sync.lastblock; for tx in sync .transactions diff --git a/instrumentation/src/eth.rs b/instrumentation/src/eth.rs @@ -50,8 +50,8 @@ pub fn eth_test(config: Option<&Path>, base_url: &str) { .unwrap() .into_iter() .skip(1) // Skip etherbase if dev network - .filter(|addr| addr != &state.address) // Skip wire - .next(); + .find(|addr| addr != &state.address); // Skip wire + let client_addr = match client { Some(addr) => addr, None => rpc.new_account("password").unwrap(), diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs @@ -22,7 +22,8 @@ use common::{ api_common::{Amount, Base32}, api_wire::{IncomingBankTransaction, IncomingHistory, OutgoingHistory, TransferRequest}, config::{Config, GatewayConfig}, - url::Url, rand_slice, + rand_slice, + url::Url, }; use eth::eth_test; @@ -42,20 +43,16 @@ fn check_incoming(base_url: &str, reserve_pub_key: &[u8; 32], taler_amount: &Amo .unwrap() .into_json() .unwrap(); - assert!(history - .incoming_transactions - .iter() - .find(|h| { - matches!( - h, - IncomingBankTransaction::IncomingReserveTransaction { - reserve_pub, - amount, - .. - } if reserve_pub == &Base32::from(*reserve_pub_key) && amount == taler_amount - ) - }) - .is_some()); + assert!(history.incoming_transactions.iter().any(|h| { + matches!( + h, + IncomingBankTransaction::IncomingReserveTransaction { + reserve_pub, + amount, + .. + } if reserve_pub == &Base32::from(*reserve_pub_key) && amount == taler_amount + ) + })); } fn transfer(base_url: &str, wtid: &[u8; 32], url: &Url, credit_account: Url, amount: &Amount) { @@ -79,13 +76,9 @@ fn check_outgoing(base_url: &str, wtid: &[u8; 32], url: &Url, amount: &Amount) { .unwrap() .into_json() .unwrap(); - assert!(history - .outgoing_transactions - .iter() - .find(|h| { - h.wtid == Base32::from(*wtid) && &h.exchange_base_url == url && &h.amount == amount - }) - .is_some()); + assert!(history.outgoing_transactions.iter().any(|h| { + h.wtid == Base32::from(*wtid) && &h.exchange_base_url == url && &h.amount == amount + })); } /// Depolymerizer instrumentation test diff --git a/wire-gateway/src/main.rs b/wire-gateway/src/main.rs @@ -23,7 +23,7 @@ use common::{ config::{Config, GatewayConfig}, error_codes::ErrorCode, log::log::{error, info, log, Level}, - postgres::{fallible_iterator::FallibleIterator, Client}, + postgres::fallible_iterator::FallibleIterator, sql::{sql_amount, sql_array, sql_safe_u64, sql_url}, url::Url, }; @@ -98,13 +98,13 @@ struct Args { async fn main() { common::log::init(); let args = Args::parse(); - let conf = GatewayConfig::load_taler_config(args.config.as_deref(),None); + let conf = GatewayConfig::load_taler_config(args.config.as_deref(), None); #[cfg(feature = "test")] common::log::log::warn!("Running with test admin endpoint unsuitable for production"); // Parse postgres url - let config = tokio_postgres::Config::from_str(&conf.core.db_url).unwrap(); + let config = &conf.core.db_config; // TODO find a way to clean this ugly mess let mut cfg = deadpool_postgres::Config::new(); cfg.user = config.get_user().map(|it| it.to_string()); @@ -480,7 +480,7 @@ async fn router( /// Listen to backend status change fn status_watcher(state: &'static ServerState) { fn inner(state: &'static ServerState) -> Result<(), Box<dyn std::error::Error>> { - let mut db = Client::connect(&state.config.core.db_url, NoTls)?; + let mut db = state.config.core.db_config.connect(NoTls)?; // Register as listener db.batch_execute("LISTEN status")?; loop {