Skip to content

Commit 468017e

Browse files
committed
rust: use specific error TxNotFound instead of generic one
1 parent 84e721d commit 468017e

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

subprojects/gdk_rust/gdk_electrum/src/account.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,7 @@ pub fn populate_unspent_from_db(
925925
return Err(Error::Generic("vout greater or equal number of outputs".into()));
926926
}
927927
let script_pubkey = tx.output_script(vout);
928-
let derivation_path =
929-
cache.paths.get(&script_pubkey).ok_or_else(|| Error::ScriptPubkeyNotFound)?;
928+
let derivation_path = cache.get_path(&script_pubkey)?;
930929
u.user_path = account.get_full_path(derivation_path).into();
931930
u.scriptpubkey = script_pubkey;
932931
}
@@ -938,7 +937,7 @@ pub fn create_tx(
938937
account: &Account,
939938
request: &mut CreateTransaction,
940939
) -> Result<TransactionMeta, Error> {
941-
let _ = populate_unspent_from_db(account, request);
940+
populate_unspent_from_db(account, request)?;
942941
info!("create_tx {:?}", request);
943942

944943
let network = &account.network;

subprojects/gdk_rust/gdk_electrum/src/store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ impl RawAccountCache {
468468
pub fn get_bitcoin_tx(&self, txid: &bitcoin::Txid) -> Result<Transaction, Error> {
469469
match self.all_txs.get(&txid.into_be()).map(|etx| &etx.tx) {
470470
Some(BETransaction::Bitcoin(tx)) => Ok(tx.clone()),
471-
_ => Err(Error::Generic("expected bitcoin tx".to_string())),
471+
_ => Err(Error::TxNotFound(BETxid::Bitcoin(txid.clone()))),
472472
}
473473
}
474474

475475
pub fn get_liquid_tx(&self, txid: &elements::Txid) -> Result<elements::Transaction, Error> {
476476
match self.all_txs.get(&txid.into_be()).map(|etx| &etx.tx) {
477477
Some(BETransaction::Elements(tx)) => Ok(tx.clone()),
478-
_ => Err(Error::Generic("expected liquid tx".to_string())),
478+
_ => Err(Error::TxNotFound(BETxid::Elements(txid.clone()))),
479479
}
480480
}
481481

0 commit comments

Comments
 (0)