Skip to content

Commit 13a543a

Browse files
committed
rust: store: add method to get derivation path from scriptpubkey
1 parent 0e68e77 commit 13a543a

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

subprojects/gdk_rust/gdk_electrum/src/account.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,7 @@ impl Account {
365365
acc_store.all_txs.get(&txid).ok_or_else(|| Error::TxNotFound(txid.to_string()))?;
366366
let tx = &txe.tx;
367367
let height = acc_store.heights.get(&txid).cloned().flatten().unwrap_or(0);
368-
let script_pubkey = tx.output_script(vout);
369-
let account_path: DerivationPath = acc_store
370-
.paths
371-
.get(&script_pubkey)
372-
.ok_or_else(|| Error::Generic("can't find derivation path".into()))?
373-
.clone();
368+
let account_path = acc_store.get_path(&tx.output_script(vout))?;
374369
let (is_internal, pointer) = parse_path(&account_path)?;
375370
let satoshi = tx.output_value(vout, &acc_store.unblinded).unwrap_or_default();
376371

@@ -582,11 +577,7 @@ impl Account {
582577
info!("input#{} prev_output:{:?}", i, prev_output);
583578
let prev_tx = acc_store.get_bitcoin_tx(&prev_output.txid)?;
584579
let out = prev_tx.output[prev_output.vout as usize].clone();
585-
let derivation_path: DerivationPath = acc_store
586-
.paths
587-
.get(&out.script_pubkey.into())
588-
.ok_or_else(|| Error::Generic("can't find derivation path".into()))?
589-
.clone();
580+
let derivation_path = acc_store.get_path(&out.script_pubkey.into())?;
590581
info!(
591582
"input#{} prev_output:{:?} derivation_path:{:?}",
592583
i, prev_output, derivation_path
@@ -621,11 +612,7 @@ impl Account {
621612
info!("input#{} prev_output:{:?}", i, prev_output);
622613
let prev_tx = acc_store.get_liquid_tx(&prev_output.txid)?;
623614
let out = prev_tx.output[prev_output.vout as usize].clone();
624-
let derivation_path: DerivationPath = acc_store
625-
.paths
626-
.get(&out.script_pubkey.into())
627-
.ok_or_else(|| Error::Generic("can't find derivation path".into()))?
628-
.clone();
615+
let derivation_path = acc_store.get_path(&out.script_pubkey.into())?;
629616

630617
let (script_sig, witness) = internal_sign_elements(
631618
&tx,

subprojects/gdk_rust/gdk_electrum/src/store.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ impl RawAccountCache {
478478
_ => Err(Error::Generic("expected liquid tx".to_string())),
479479
}
480480
}
481+
482+
pub fn get_path(&self, script_pubkey: &BEScript) -> Result<&DerivationPath, Error> {
483+
self.paths
484+
.get(script_pubkey)
485+
.ok_or_else(|| Error::Generic("can't find derivation path".into()))
486+
}
481487
}
482488

483489
#[cfg(test)]

0 commit comments

Comments
 (0)