Skip to content

Commit

Permalink
cancelation by txid can affect several transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Aug 25, 2024
1 parent eecbe2b commit 14fce85
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions libwallet/src/internal/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,29 +453,32 @@ where
None,
None,
)?;
if tx_vec.len() != 1 {
if tx_vec.len() == 1 {
return Err(Error::TransactionDoesntExist(tx_id_string));
}
let tx = tx_vec[0].clone();
match tx.tx_type {
TxLogEntryType::TxSent | TxLogEntryType::TxReceived | TxLogEntryType::TxReverted => {}
_ => return Err(Error::TransactionNotCancellable(tx_id_string)),
}
if tx.confirmed {
return Err(Error::TransactionNotCancellable(tx_id_string));
// there are can be several transactions with a same txid (send file to self).
// In such case we need to cancel all of them
for tx in tx_vec {
match tx.tx_type {
TxLogEntryType::TxSent | TxLogEntryType::TxReceived | TxLogEntryType::TxReverted => {}
_ => return Err(Error::TransactionNotCancellable(tx_id_string)),
}
if tx.confirmed {
return Err(Error::TransactionNotCancellable(tx_id_string));
}
// get outputs associated with tx
let res = updater::retrieve_outputs(
wallet,
keychain_mask,
false,
Some(&tx),
&parent_key_id,
None,
None,
)?;
let outputs = res.iter().map(|m| m.output.clone()).collect();
updater::cancel_tx_and_outputs(wallet, keychain_mask, tx, outputs, parent_key_id)?;
}
// get outputs associated with tx
let res = updater::retrieve_outputs(
wallet,
keychain_mask,
false,
Some(&tx),
&parent_key_id,
None,
None,
)?;
let outputs = res.iter().map(|m| m.output.clone()).collect();
updater::cancel_tx_and_outputs(wallet, keychain_mask, tx, outputs, parent_key_id)?;
Ok(())
}

Expand Down

0 comments on commit 14fce85

Please sign in to comment.