Skip to content

Commit

Permalink
feat: store complete revert transaction result into database
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent f03c9e2 commit b6a3020
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/controller/ledger/controller_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (ctrl *DefaultController) importLog(ctx context.Context, sqlTx TX, log ledg
}
}
case ledger.RevertedTransactionLogPayload:
_, _, err := sqlTx.RevertTransaction(ctx, payload.RevertedTransactionID)
_, _, err := sqlTx.RevertTransaction(ctx, payload.RevertedTransaction.ID)
if err != nil {
return errors.Wrap(err, "failed to revert transaction")
}
Expand Down Expand Up @@ -335,15 +335,15 @@ func (ctrl *DefaultController) RevertTransaction(ctx context.Context, parameters
return nil, errors.Wrap(err, "failed to insert transaction")
}

return pointer.For(ledger.NewRevertedTransactionLog(input.TransactionID, reversedTx)), nil
return pointer.For(ledger.NewRevertedTransactionLog(*originalTransaction, reversedTx)), nil
})
if err != nil {
return nil, err
}

return &RevertTransactionResult{
RevertedTransaction: *originalTransaction,
ReversedTransaction: log.Data.(ledger.RevertedTransactionLogPayload).RevertTransaction,
ReversedTransaction: log.Data.(ledger.RevertedTransactionLogPayload).RevertTransaction,
}, nil
}

Expand Down
22 changes: 17 additions & 5 deletions internal/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,26 @@ func NewDeleteAccountMetadataLog(id string, key string) Log {
}

type RevertedTransactionLogPayload struct {
RevertedTransactionID int `json:"revertedTransactionID"`
RevertTransaction Transaction `json:"transaction"`
RevertedTransaction Transaction `json:"revertedTransaction"`
RevertTransaction Transaction `json:"transaction"`
}

func NewRevertedTransactionLog(revertedTxID int, tx Transaction) Log {
func (r RevertedTransactionLogPayload) hashValue() any {
return struct {
RevertedTransactionID int `json:"revertedTransactionID"`
RevertTransaction Transaction `json:"transaction"`
}{
RevertedTransactionID: r.RevertedTransaction.ID,
RevertTransaction: r.RevertTransaction,
}
}

var _ hashValuer = (*RevertedTransactionLogPayload)(nil)

func NewRevertedTransactionLog(revertedTx, tx Transaction) Log {
return NewLog(RevertedTransactionLogType, RevertedTransactionLogPayload{
RevertedTransactionID: revertedTxID,
RevertTransaction: tx,
RevertedTransaction: revertedTx,
RevertTransaction: tx,
})
}

Expand Down

0 comments on commit b6a3020

Please sign in to comment.