diff --git a/libwallet/src/internal/tx.rs b/libwallet/src/internal/tx.rs index 230e8e0cd..2ecd215f4 100644 --- a/libwallet/src/internal/tx.rs +++ b/libwallet/src/internal/tx.rs @@ -359,31 +359,32 @@ where Some(&parent_key_id), false, )?; - if tx_vec.len() != 1 { + if tx_vec.len() == 0 { return Err(Error::TransactionDoesntExist(tx_id_string)); } - let tx = tx_vec[0].clone(); - debug!("cancel_tx: tx: {}", tx.tx_type); - match tx.tx_type { - TxLogEntryType::TxSent - | TxLogEntryType::TxReceived - | TxLogEntryType::TxReverted - | TxLogEntryType::TxSelfSpend => {} - _ => return Err(Error::TransactionNotCancellable(tx_id_string)), - } - if tx.confirmed { - return Err(Error::TransactionNotCancellable(tx_id_string)); + for tx in tx_vec { + debug!("cancel_tx: tx: {}", tx.tx_type); + match tx.tx_type { + TxLogEntryType::TxSent + | TxLogEntryType::TxReceived + | TxLogEntryType::TxReverted + | TxLogEntryType::TxSelfSpend => {} + _ => 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.id), + Some(&parent_key_id), + )?; + 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.id), - Some(&parent_key_id), - )?; - let outputs = res.iter().map(|m| m.output.clone()).collect(); - updater::cancel_tx_and_outputs(wallet, keychain_mask, tx, outputs, parent_key_id)?; Ok(()) }