diff options
author | Antoine A <> | 2022-03-21 17:49:42 +0100 |
---|---|---|
committer | Antoine A <> | 2022-03-21 17:49:42 +0100 |
commit | 9d00fd837855f3480f169f7361f484e5038bc1d6 (patch) | |
tree | e020afab373bd6585f7cb8bf83224526a5ee2b47 /btc-wire | |
parent | 471390e2b829f9c5ff229d994d789c89bdc802d3 (diff) | |
download | depolymerization-9d00fd837855f3480f169f7361f484e5038bc1d6.tar.gz depolymerization-9d00fd837855f3480f169f7361f484e5038bc1d6.tar.bz2 depolymerization-9d00fd837855f3480f169f7361f484e5038bc1d6.zip |
remove all occurrence of withdraw and deposit
Diffstat (limited to 'btc-wire')
-rw-r--r-- | btc-wire/README.md | 2 | ||||
-rw-r--r-- | btc-wire/src/bin/btc-wire-utils.rs | 2 | ||||
-rw-r--r-- | btc-wire/src/loops/worker.rs | 56 |
3 files changed, 30 insertions, 30 deletions
diff --git a/btc-wire/README.md b/btc-wire/README.md index 0a2fd9b..9e281f7 100644 --- a/btc-wire/README.md +++ b/btc-wire/README.md @@ -3,7 +3,7 @@ btc-wire is taler wire adapter for [bitcoincore](https://bitcoincore.org/en/about/) node -## Deposit metadata format +## Credit metadata format Starting from a bitcoin payto URI you will have to generate fake segwit addresses to encode the reserve public key as metadata into a common bitcoin diff --git a/btc-wire/src/bin/btc-wire-utils.rs b/btc-wire/src/bin/btc-wire-utils.rs index 841df85..7520874 100644 --- a/btc-wire/src/bin/btc-wire-utils.rs +++ b/btc-wire/src/bin/btc-wire-utils.rs @@ -40,7 +40,7 @@ struct Args { #[derive(clap::Subcommand, Debug)]
enum Cmd {
- /// Send taler deposit transactions
+ /// Perform wire credit transactions
Transfer {
#[clap(short, long, default_value_t = String::from("client"))]
/// sender wallet
diff --git a/btc-wire/src/loops/worker.rs b/btc-wire/src/loops/worker.rs index aeb56b9..7ab6390 100644 --- a/btc-wire/src/loops/worker.rs +++ b/btc-wire/src/loops/worker.rs @@ -34,7 +34,7 @@ use common::{ postgres, reconnect::AutoReconnectDb, sql::{sql_array, sql_url}, - status::{BounceStatus, WithdrawStatus}, + status::{BounceStatus, DebitStatus}, }; use postgres::{fallible_iterator::FallibleIterator, Client}; @@ -101,8 +101,8 @@ pub fn worker(mut rpc: AutoRpcWallet, mut db: AutoReconnectDb, state: &WireState if let Some(stuck) = sync_chain(rpc, db, state, &mut status)? { // As we are now in sync with the blockchain if a transaction has Requested status it have not been sent - // Send requested withdraws - while withdraw(db, rpc, state)? {} + // Send requested debits + while debit(db, rpc, state)? {} // Bump stuck transactions for id in stuck { @@ -239,13 +239,13 @@ fn sync_chain_removed( db: &mut Client, min_confirmations: i32, ) -> LoopResult<bool> { - // Removed transactions are correctness issues in only two cases: - // - An incoming valid transaction considered confirmed in the database - // - An incoming invalid transactions already bounced + // A removed incoming transaction is a correctness issues in only two cases: + // - it is a confirmed credit registered in the database + // - it is an invalid transactions already bounced // Those two cases can compromise bitcoin backing // Removed outgoing transactions will be retried automatically by the node - let mut blocking_deposit = Vec::new(); + let mut blocking_debit = Vec::new(); let mut blocking_bounce = Vec::new(); // Only keep incoming transaction that are not reconfirmed @@ -259,13 +259,13 @@ fn sync_chain_removed( }) { match rpc.get_tx_segwit_key(id) { Ok((full, key)) => { - // Deposit are only problematic if not reconfirmed and stored in the database + // Credits are only problematic if not reconfirmed and stored in the database if db .query_opt("SELECT 1 FROM tx_in WHERE reserve_pub=$1", &[&key.as_ref()])? .is_some() { let debit_addr = sender_address(rpc, &full)?; - blocking_deposit.push((key, id, debit_addr)); + blocking_debit.push((key, id, debit_addr)); } } Err(err) => match err { @@ -286,12 +286,12 @@ fn sync_chain_removed( } } - if !blocking_bounce.is_empty() || !blocking_deposit.is_empty() { + if !blocking_bounce.is_empty() || !blocking_debit.is_empty() { let mut buf = "The following transaction have been removed from the blockchain, bitcoin backing is compromised until the transaction reappear:".to_string(); - for (key, id, addr) in blocking_deposit { + for (key, id, addr) in blocking_debit { write!( &mut buf, - "\n\tdeposit {} in {} from {}", + "\n\tcredit {} in {} from {}", base32(&key), id, addr @@ -349,8 +349,8 @@ fn sync_chain_incoming_confirmed( Ok(()) } -/// Sync database with an outgoing withdraw transaction, return true if stuck -fn sync_chain_withdraw( +/// Sync database with a debit transaction, return true if stuck +fn sync_chain_debit( id: &Txid, full: &Transaction, wtid: &[u8; 32], @@ -367,7 +367,7 @@ fn sync_chain_withdraw( // Handle conflicting tx let nb_row = db.execute( "UPDATE tx_out SET status=$1, txid=NULL where txid=$2", - &[&(WithdrawStatus::Requested as i16), &id.as_ref()], + &[&(DebitStatus::Requested as i16), &id.as_ref()], )?; if nb_row > 0 { warn!( @@ -388,12 +388,12 @@ fn sync_chain_withdraw( // If already in database, sync status let row_id: i32 = row.get(0); let status: i16 = row.get(1); - match WithdrawStatus::try_from(status as u8).unwrap() { - WithdrawStatus::Requested => { + match DebitStatus::try_from(status as u8).unwrap() { + DebitStatus::Requested => { let nb_row = db.execute( "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3 AND status=$4", &[ - &(WithdrawStatus::Sent as i16), + &(DebitStatus::Sent as i16), &id.as_ref(), &row_id, &status, @@ -409,7 +409,7 @@ fn sync_chain_withdraw( ); } } - WithdrawStatus::Sent => { + DebitStatus::Sent => { if let Some(txid) = full.replaces_txid { let stored_id = sql_txid(&row, 2); if txid == stored_id { @@ -435,7 +435,7 @@ fn sync_chain_withdraw( let date = SystemTime::UNIX_EPOCH + Duration::from_secs(full.time); let nb = db.execute( "INSERT INTO tx_out (_date, amount, wtid, debit_acc, credit_acc, exchange_url, status, txid, request_uid) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (wtid) DO NOTHING", - &[&date, &amount.to_string(), &wtid.as_ref(), &btc_payto_url(&debit_addr).as_ref(), &btc_payto_url(credit_addr).as_ref(), &state.base_url.as_ref(), &(WithdrawStatus::Sent as i16), &id.as_ref(), &None::<&[u8]>], + &[&date, &amount.to_string(), &wtid.as_ref(), &btc_payto_url(&debit_addr).as_ref(), &btc_payto_url(credit_addr).as_ref(), &state.base_url.as_ref(), &(DebitStatus::Sent as i16), &id.as_ref(), &None::<&[u8]>], )?; if nb > 0 { warn!( @@ -534,8 +534,8 @@ fn sync_chain_outgoing( .map(|(full, bytes)| (full, OutMetadata::decode(&bytes))) { Ok((full, Ok(info))) => match info { - OutMetadata::Withdraw { wtid, .. } => { - return sync_chain_withdraw(id, &full, &wtid, rpc, db, confirmations, state); + OutMetadata::Debit { wtid, .. } => { + return sync_chain_debit(id, &full, &wtid, rpc, db, confirmations, state); } OutMetadata::Bounce { bounced } => { sync_chain_bounce(id, &Txid::from_inner(bounced), db, confirmations)? @@ -550,12 +550,12 @@ fn sync_chain_outgoing( Ok(false) } -/// Send a withdraw transaction on the blockchain, return false if no more requested transactions are found -fn withdraw(db: &mut Client, rpc: &mut Rpc, state: &WireState) -> LoopResult<bool> { +/// Send a debit transaction on the blockchain, return false if no more requested transactions are found +fn debit(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", - &[&(WithdrawStatus::Requested as i16)], + &[&(DebitStatus::Requested as i16)], )?; if let Some(row) = &row { let id: i32 = row.get(0); @@ -563,13 +563,13 @@ fn withdraw(db: &mut Client, rpc: &mut Rpc, state: &WireState) -> LoopResult<boo let wtid: [u8; 32] = sql_array(row, 2); let addr = sql_addr(row, 3); let url = sql_url(row, 4); - let metadata = OutMetadata::Withdraw { wtid, url }; + let metadata = OutMetadata::Debit { wtid, url }; let tx_id = rpc.send(&addr, &amount, Some(&metadata.encode()), false)?; - fail_point("(injected) fail withdraw", 0.3)?; + fail_point("(injected) fail debit", 0.3)?; db.execute( "UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3", - &[&(WithdrawStatus::Sent as i16), &tx_id.as_ref(), &id], + &[&(DebitStatus::Sent as i16), &tx_id.as_ref(), &id], )?; let amount = btc_to_taler(&amount.to_signed().unwrap(), state.currency); info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id, addr); |