Skip to content

Commit c3d7547

Browse files
authored
validate staking ops (#415)
1 parent ae92cd6 commit c3d7547

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
rosetta-cli
22
bin/
3+
/.vscode
4+
/cli-data

pkg/processor/broadcast_storage_handler.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ func (h *BroadcastStorageHandler) TransactionConfirmed(
8181
}
8282

8383
if err := h.parser.ExpectedOperations(intent, observed, false, true); err != nil {
84-
return fmt.Errorf("confirmed transaction did not match intent: %w", err)
84+
errMsg := fmt.Errorf("confirmed transaction did not match intent: %w", err)
85+
if !isValidStakingOperation(intent, intentMetadata) {
86+
return errMsg
87+
}
8588
}
8689

8790
// Validate destination memo if it's needed
@@ -114,6 +117,23 @@ func (h *BroadcastStorageHandler) TransactionConfirmed(
114117
return nil
115118
}
116119

120+
func isValidStakingOperation(intent []*types.Operation, metadata map[string]interface{}) bool {
121+
stakingOpsTypes := map[string]bool{
122+
"stake": true,
123+
"unstake": true,
124+
"withdraw": true,
125+
"restake": true,
126+
}
127+
128+
if _, found := metadata["validator_src_address"]; found {
129+
if len(intent) == 1 {
130+
_, found := stakingOpsTypes[intent[0].Type]
131+
return found
132+
}
133+
}
134+
return false
135+
}
136+
117137
// TransactionStale is called when a transaction has not yet been
118138
// seen on-chain and is considered stale. This occurs when
119139
// current block height - last broadcast > staleDepth.

0 commit comments

Comments
 (0)