Skip to content

Commit

Permalink
implement MoveConfirmedToUnconfirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
poopoothegorilla committed Feb 23, 2024
1 parent 659b2fb commit debfdc9
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion common/txmgr/address_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,32 @@ func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveIn
}

// MoveConfirmedToUnconfirmed moves the confirmed transaction to the unconfirmed state.
func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveConfirmedToUnconfirmed(attempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
func (as *AddressState[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) MoveConfirmedToUnconfirmed(txAttempt txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error {
as.Lock()
defer as.Unlock()

if txAttempt.State != txmgrtypes.TxAttemptBroadcast {
return fmt.Errorf("move_confirmed_to_unconfirmed: attempt must be in broadcast state")
}

tx, ok := as.confirmedTxs[txAttempt.TxID]
if !ok || tx == nil {
return fmt.Errorf("move_confirmed_to_unconfirmed: no confirmed transaction with ID %d", txAttempt.TxID)
}
tx.State = TxUnconfirmed

// Delete the receipt from the attempt
txAttempt.Receipts = nil
// Reset the broadcast information for the attempt
txAttempt.State = txmgrtypes.TxAttemptInProgress
txAttempt.BroadcastBeforeBlockNum = nil
if len(tx.TxAttempts) == 0 {
tx.TxAttempts = []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]{}
}
tx.TxAttempts = append(tx.TxAttempts, txAttempt)

as.unconfirmedTxs[tx.ID] = tx
delete(as.confirmedTxs, tx.ID)

return nil
}

0 comments on commit debfdc9

Please sign in to comment.