Skip to content

Commit

Permalink
[Contracts] Cancel self-spend TX Pt. 2 (#703)
Browse files Browse the repository at this point in the history
* add tests + legacy self send cancel

* add missing file
  • Loading branch information
yeastplume authored Feb 23, 2024
1 parent f94a0a4 commit 6f226ea
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions libwallet/src/internal/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit 6f226ea

Please sign in to comment.