mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-01 17:01:10 +03:00
[Contracts] Cancel self-spend TX Pt. 2 (#703)
* add tests + legacy self send cancel * add missing file
This commit is contained in:
parent
f94a0a4a08
commit
6f226ea3e2
1 changed files with 23 additions and 22 deletions
|
@ -359,31 +359,32 @@ where
|
||||||
Some(&parent_key_id),
|
Some(&parent_key_id),
|
||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
if tx_vec.len() != 1 {
|
if tx_vec.len() == 0 {
|
||||||
return Err(Error::TransactionDoesntExist(tx_id_string));
|
return Err(Error::TransactionDoesntExist(tx_id_string));
|
||||||
}
|
}
|
||||||
let tx = tx_vec[0].clone();
|
for tx in tx_vec {
|
||||||
debug!("cancel_tx: tx: {}", tx.tx_type);
|
debug!("cancel_tx: tx: {}", tx.tx_type);
|
||||||
match tx.tx_type {
|
match tx.tx_type {
|
||||||
TxLogEntryType::TxSent
|
TxLogEntryType::TxSent
|
||||||
| TxLogEntryType::TxReceived
|
| TxLogEntryType::TxReceived
|
||||||
| TxLogEntryType::TxReverted
|
| TxLogEntryType::TxReverted
|
||||||
| TxLogEntryType::TxSelfSpend => {}
|
| TxLogEntryType::TxSelfSpend => {}
|
||||||
_ => return Err(Error::TransactionNotCancellable(tx_id_string)),
|
_ => 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue