Skip to content

Commit

Permalink
validate staking ops (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaying-peng authored Apr 24, 2024
1 parent ae92cd6 commit c3d7547
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
rosetta-cli
bin/
/.vscode
/cli-data
22 changes: 21 additions & 1 deletion pkg/processor/broadcast_storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c3d7547

Please sign in to comment.