depolymerization

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

commit a9dfe0e23f161458a018caafad966b1c3c68ae2f
parent 7e023efbd0dc93dcdee840092e53b000def844cc
Author: Antoine A <>
Date:   Tue, 29 Jul 2025 14:42:54 +0200

bictoin: clean worker

Diffstat:
Mdepolymerizer-bitcoin/src/loops/worker.rs | 54+++++++++++++++++++++---------------------------------
Mdepolymerizer-bitcoin/src/rpc.rs | 2+-
2 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/depolymerizer-bitcoin/src/loops/worker.rs b/depolymerizer-bitcoin/src/loops/worker.rs @@ -13,9 +13,9 @@ 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/> */ -use std::{collections::HashMap, fmt::Write, time::SystemTime}; +use std::{fmt::Write, time::SystemTime}; -use bitcoin::{Amount as BtcAmount, BlockHash, Txid, hashes::Hash}; +use bitcoin::{Amount as BtcAmount, Txid, hashes::Hash}; use common::{ metadata::OutMetadata, status::BounceStatus, @@ -31,7 +31,9 @@ use crate::{ config::WorkerCfg, db::{self, AddIncomingResult, SyncBounceResult, SyncOutResult, worker_lock}, fail_point::fail_point, - rpc::{self, Category, ErrorCode, Rpc, Transaction, rpc_wallet}, + rpc::{ + self, Category, ErrorCode, ListSinceBlock, ListTransaction, Rpc, Transaction, rpc_wallet, + }, rpc_utils::sender_address, taler_utils::btc_to_taler, }; @@ -193,27 +195,12 @@ async fn sync_chain( // Get the current confirmation delay let conf_delay = state.confirmation; - // Get a set of transactions ids to parse - let (txs, removed, lastblock): ( - HashMap<Txid, (Category, i32)>, - HashMap<Txid, (Category, i32)>, - BlockHash, - ) = { - // Get all transactions made since this block - let list = rpc.list_since_block(Some(&sync_state), conf_delay).await?; - // Only keep ids and category - let txs = list - .transactions - .into_iter() - .map(|tx| (tx.txid, (tx.category, tx.confirmations))) - .collect(); - let removed = list - .removed - .into_iter() - .map(|tx| (tx.txid, (tx.category, tx.confirmations))) - .collect(); - (txs, removed, list.lastblock) - }; + // Get all transactions made since this block + let ListSinceBlock { + transactions, + removed, + lastblock, + } = rpc.list_since_block(Some(&sync_state), conf_delay).await?; // Check if a confirmed incoming transaction have been removed by a blockchain reorganization let new_status = sync_chain_removed(removed, db, conf_delay as i32).await?; @@ -232,15 +219,15 @@ async fn sync_chain( let mut stuck = vec![]; - for (id, (category, confirmations)) in txs { - match category { + for tx in transactions { + match tx.category { Category::Send => { - if sync_chain_outgoing(&id, confirmations, rpc, db, state).await? { - stuck.push(id); + if sync_chain_outgoing(&tx.txid, tx.confirmations, rpc, db, state).await? { + stuck.push(tx.txid); } } - Category::Receive if confirmations >= conf_delay as i32 => { - sync_chain_incoming_confirmed(&id, rpc, db, state).await? + Category::Receive if tx.confirmations >= conf_delay as i32 => { + sync_chain_incoming_confirmed(&tx.txid, rpc, db, state).await? } _ => { // Ignore coinbase and unconfirmed send transactions @@ -256,7 +243,7 @@ async fn sync_chain( /// Sync database with removed transactions, return false if bitcoin backing is compromised async fn sync_chain_removed( - removed: HashMap<Txid, (Category, i32)>, + removed: Vec<ListTransaction>, db: &mut PgListener, min_confirmations: i32, ) -> LoopResult<bool> { @@ -268,8 +255,9 @@ async fn sync_chain_removed( let potential_problematic_ids: Vec<Txid> = removed .into_iter() - .filter_map(|(id, (cat, confirmations))| { - (cat == Category::Receive && confirmations < min_confirmations).then_some(id) + .filter_map(|tx| { + (tx.category == Category::Receive && tx.confirmations < min_confirmations) + .then_some(tx.txid) }) .collect(); diff --git a/depolymerizer-bitcoin/src/rpc.rs b/depolymerizer-bitcoin/src/rpc.rs @@ -523,7 +523,7 @@ pub struct ListTransaction { pub confirmations: i32, pub txid: Txid, pub category: Category, - pub vout: i32 + pub vout: i32, } #[derive(Debug, serde::Deserialize)]