Skip to content

Commit 6796db4

Browse files
committed
rust: fix populate bug
Do not trust the user provided subaccount value.
1 parent c53e855 commit 6796db4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

subprojects/gdk_rust/gdk_electrum/src/account.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ pub fn discover_account(
906906
Ok(false)
907907
}
908908

909-
/// Populate `derivation_path` and `scriptpubkey` in `UnspentOutput` by looking in our internal
910-
/// cache by provided `subaccount`, `txid` and `pt_idx` (vout) and return an error if not present.
909+
/// Populate `derivation_path` and `scriptpubkey` in `utxos` by looking in our internal
910+
/// cache by provided `txhash` and `pt_idx` and return an error if not present.
911911
/// This allows to have this data if missing, but also avoid trusting the user input for this fields.
912912
pub fn populate_unspent_from_db(
913913
account: &Account,
@@ -916,7 +916,7 @@ pub fn populate_unspent_from_db(
916916
let store = account.store.read()?;
917917

918918
for u in request.utxos.0.values_mut().flat_map(|e| e.iter_mut()) {
919-
let cache = store.account_cache(u.subaccount)?;
919+
let cache = store.account_cache(account.account_num)?;
920920
let txid = BETxid::from_hex(&u.txhash, account.network.id())?;
921921
let tx_entry = cache.all_txs.get(&txid).ok_or_else(|| Error::TxNotFound(txid))?;
922922
let tx = &tx_entry.tx;
@@ -937,7 +937,7 @@ pub fn create_tx(
937937
account: &Account,
938938
request: &mut CreateTransaction,
939939
) -> Result<TransactionMeta, Error> {
940-
let _ = populate_unspent_from_db(account, request); // FIXME: throw error if cannot be populated
940+
populate_unspent_from_db(account, request)?;
941941
info!("create_tx {:?}", request);
942942

943943
let network = &account.network;

0 commit comments

Comments
 (0)