[Contracts] Cancel self-spend TX Pt. 2 (#703)

* add tests + legacy self send cancel

* add missing file
This commit is contained in:
Yeastplume 2024-02-23 09:24:47 +00:00 committed by GitHub
parent f94a0a4a08
commit 6f226ea3e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)),
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)?;
}
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)?;
Ok(())
}