From 81851190f037d81680c8b6a6e235cea10a4cb79c Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 1 Jun 2021 16:19:32 +0200 Subject: [PATCH] correctly initialize UTXO keychain kind --- src/blockchain/rpc.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/blockchain/rpc.rs b/src/blockchain/rpc.rs index f272246d..ea5b8dd1 100644 --- a/src/blockchain/rpc.rs +++ b/src/blockchain/rpc.rs @@ -242,17 +242,22 @@ impl Blockchain for RpcBlockchain { } } - let current_utxos: HashSet = current_utxo + let current_utxos: HashSet<_> = current_utxo .into_iter() - .map(|u| LocalUtxo { - outpoint: OutPoint::new(u.txid, u.vout), - txout: TxOut { - value: u.amount.as_sat(), - script_pubkey: u.script_pub_key, - }, - keychain: KeychainKind::External, + .map(|u| { + Ok(LocalUtxo { + outpoint: OutPoint::new(u.txid, u.vout), + keychain: db + .get_path_from_script_pubkey(&u.script_pub_key)? + .ok_or(Error::TransactionNotFound)? + .0, + txout: TxOut { + value: u.amount.as_sat(), + script_pubkey: u.script_pub_key, + }, + }) }) - .collect(); + .collect::>()?; let spent: HashSet<_> = known_utxos.difference(¤t_utxos).collect(); for s in spent {