Skip to content

Commit

Permalink
core: Confirm refund txs.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Nov 17, 2024
1 parent 5f90685 commit 9491c14
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 125 deletions.
44 changes: 27 additions & 17 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -10665,9 +10665,9 @@ func (c *Core) deleteRequestedAction(uniqueID string) {
c.requestedActionMtx.Unlock()
}

// handleRetryRedemptionAction handles a response to a user response to an
// ActionRequiredNote for a rejected redemption transaction.
func (c *Core) handleRetryRedemptionAction(actionB []byte) error {
// handleRetryTxAction handles a response to a user response to an
// ActionRequiredNote for a rejected redemption or refund transaction.
func (c *Core) handleRetryTxAction(actionB []byte, isRedeem bool) error {
var req struct {
OrderID dex.Bytes `json:"orderID"`
CoinID dex.Bytes `json:"coinID"`
Expand Down Expand Up @@ -10703,23 +10703,31 @@ func (c *Core) handleRetryRedemptionAction(actionB []byte) error {
coinID = match.MetaData.Proof.MakerRedeem
}
if bytes.Equal(coinID, req.CoinID) {
if match.Side == order.Taker && match.Status == order.MatchComplete {
// Try to redeem again.
match.redemptionRejected = false
match.MetaData.Proof.TakerRedeem = nil
match.Status = order.MakerRedeemed
if err := c.db.UpdateMatch(&match.MetaMatch); err != nil {
c.log.Errorf("Failed to update match in DB: %v", err)
if isRedeem {
if match.Side == order.Taker && match.Status == order.MatchComplete {
// Try to redeem again.
match.redemptionRejected = false
match.MetaData.Proof.TakerRedeem = nil
match.Status = order.MakerRedeemed
if err := c.db.UpdateMatch(&match.MetaMatch); err != nil {
c.log.Errorf("Failed to update match in DB: %v", err)
}
} else if match.Side == order.Maker && match.Status == order.MakerRedeemed {
match.redemptionRejected = false
match.MetaData.Proof.MakerRedeem = nil
match.Status = order.TakerSwapCast
if err := c.db.UpdateMatch(&match.MetaMatch); err != nil {
c.log.Errorf("Failed to update match in DB: %v", err)
}
} else {
c.log.Errorf("Redemption retry attempted for order side %s status %s", match.Side, match.Status)
}
} else if match.Side == order.Maker && match.Status == order.MakerRedeemed {
match.redemptionRejected = false
match.MetaData.Proof.MakerRedeem = nil
match.Status = order.TakerSwapCast
} else {
match.MetaData.Proof.RefundCoin = nil
match.refundRejected = false
if err := c.db.UpdateMatch(&match.MetaMatch); err != nil {
c.log.Errorf("Failed to update match in DB: %v", err)
}
} else {
c.log.Errorf("Redemption retry attempted for order side %s status %s", match.Side, match.Status)
}
}
}
Expand All @@ -10731,7 +10739,9 @@ func (c *Core) handleRetryRedemptionAction(actionB []byte) error {
func (c *Core) handleCoreAction(actionID string, actionB json.RawMessage) ( /* handled */ bool, error) {
switch actionID {
case ActionIDRedeemRejected:
return true, c.handleRetryRedemptionAction(actionB)
return true, c.handleRetryTxAction(actionB, true)
case ActionIDRefundRejected:
return true, c.handleRetryTxAction(actionB, false)
}
return false, nil
}
Expand Down
Loading

0 comments on commit 9491c14

Please sign in to comment.