]> Untitled Git - bdk/commitdiff
correctly initialize UTXO keychain kind
authorRiccardo Casatta <riccardo@casatta.it>
Tue, 1 Jun 2021 14:19:32 +0000 (16:19 +0200)
committerRiccardo Casatta <riccardo@casatta.it>
Thu, 3 Jun 2021 08:56:02 +0000 (10:56 +0200)
src/blockchain/rpc.rs

index f272246de08598b19e91715d7bccf67c17a478fc..ea5b8dd17730ac5f3dec114f10e414ac02007d97 100644 (file)
@@ -242,17 +242,22 @@ impl Blockchain for RpcBlockchain {
             }
         }
 
-        let current_utxos: HashSet<LocalUtxo> = 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::<Result<_, Error>>()?;
 
         let spent: HashSet<_> = known_utxos.difference(&current_utxos).collect();
         for s in spent {