From c3d7547a3049204294ea79011a81d9279d8f5347 Mon Sep 17 00:00:00 2001 From: xiaying-peng Date: Wed, 24 Apr 2024 14:50:37 -0700 Subject: [PATCH] validate staking ops (#415) --- .gitignore | 2 ++ pkg/processor/broadcast_storage_handler.go | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 218fd2fa..0795dcbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ rosetta-cli bin/ +/.vscode +/cli-data diff --git a/pkg/processor/broadcast_storage_handler.go b/pkg/processor/broadcast_storage_handler.go index aad34491..0fc0b378 100644 --- a/pkg/processor/broadcast_storage_handler.go +++ b/pkg/processor/broadcast_storage_handler.go @@ -81,7 +81,10 @@ func (h *BroadcastStorageHandler) TransactionConfirmed( } if err := h.parser.ExpectedOperations(intent, observed, false, true); err != nil { - return fmt.Errorf("confirmed transaction did not match intent: %w", err) + errMsg := fmt.Errorf("confirmed transaction did not match intent: %w", err) + if !isValidStakingOperation(intent, intentMetadata) { + return errMsg + } } // Validate destination memo if it's needed @@ -114,6 +117,23 @@ func (h *BroadcastStorageHandler) TransactionConfirmed( return nil } +func isValidStakingOperation(intent []*types.Operation, metadata map[string]interface{}) bool { + stakingOpsTypes := map[string]bool{ + "stake": true, + "unstake": true, + "withdraw": true, + "restake": true, + } + + if _, found := metadata["validator_src_address"]; found { + if len(intent) == 1 { + _, found := stakingOpsTypes[intent[0].Type] + return found + } + } + return false +} + // TransactionStale is called when a transaction has not yet been // seen on-chain and is considered stale. This occurs when // current block height - last broadcast > staleDepth.