Skip to content

Commit 0ebaa6e

Browse files
committed
Handle delegations, orders in rollback
1 parent 75019a9 commit 0ebaa6e

File tree

1 file changed

+21
-8
lines changed
  • wallet/src/account/output_cache

1 file changed

+21
-8
lines changed

wallet/src/account/output_cache/mod.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl OutputCache {
860860
}
861861

862862
for tx in tx_to_rollback_data {
863-
self.rollback_tx_data(&tx);
863+
self.rollback_tx_data(&tx)?;
864864
}
865865

866866
conflicting_txs_with_descendants.extend(txs_to_rollback.into_iter());
@@ -1242,7 +1242,7 @@ impl OutputCache {
12421242
pub fn remove_confirmed_tx(&mut self, tx_id: &OutPointSourceId) -> WalletResult<()> {
12431243
if let Some(tx) = self.txs.remove(tx_id) {
12441244
matches!(tx.state(), TxState::Confirmed(..));
1245-
self.rollback_tx_data(&tx);
1245+
self.rollback_tx_data(&tx)?;
12461246
}
12471247

12481248
ensure!(
@@ -1459,7 +1459,7 @@ impl OutputCache {
14591459

14601460
// After tx is removed as a result of reorg, abandoning or marking as conflicted
14611461
// its effect on OutputCache's data fields should be rolled back
1462-
fn rollback_tx_data(&mut self, tx: &WalletTx) {
1462+
fn rollback_tx_data(&mut self, tx: &WalletTx) -> WalletResult<()> {
14631463
let tx_id = tx.id();
14641464

14651465
// Iterate in reverse to handle situations where an account is modified twice in the same tx
@@ -1514,18 +1514,31 @@ impl OutputCache {
15141514
}
15151515
}
15161516
}
1517+
TxOutput::CreateDelegationId(_, _) => {
1518+
let input0_outpoint = crate::utils::get_first_utxo_outpoint(tx.inputs())?;
1519+
let delegation_id = make_delegation_id(input0_outpoint);
1520+
self.delegations.remove(&delegation_id);
1521+
}
1522+
TxOutput::IssueFungibleToken(_) => {
1523+
let token_id = make_token_id(tx.inputs()).ok_or(WalletError::NoUtxos)?;
1524+
self.token_issuance.remove(&token_id);
1525+
}
1526+
TxOutput::CreateOrder(_) => {
1527+
let input0_outpoint = crate::utils::get_first_utxo_outpoint(tx.inputs())?;
1528+
let order_id = make_order_id(input0_outpoint);
1529+
self.orders.remove(&order_id);
1530+
}
15171531
TxOutput::Burn(_)
15181532
| TxOutput::Transfer(_, _)
15191533
| TxOutput::IssueNft(_, _, _)
15201534
| TxOutput::DataDeposit(_)
15211535
| TxOutput::DelegateStaking(_, _)
15221536
| TxOutput::LockThenTransfer(_, _, _)
1523-
| TxOutput::CreateDelegationId(_, _)
1524-
| TxOutput::IssueFungibleToken(_)
1525-
| TxOutput::Htlc(_, _)
1526-
| TxOutput::CreateOrder(_) => {}
1537+
| TxOutput::Htlc(_, _) => {}
15271538
}
15281539
}
1540+
1541+
Ok(())
15291542
}
15301543

15311544
/// Mark a transaction and its descendants as abandoned
@@ -1562,7 +1575,7 @@ impl OutputCache {
15621575
}
15631576

15641577
for tx in txs_to_rollback {
1565-
self.rollback_tx_data(&tx);
1578+
self.rollback_tx_data(&tx)?;
15661579
}
15671580

15681581
Ok(all_abandoned)

0 commit comments

Comments
 (0)