Skip to content

Commit 3cb67c4

Browse files
Updated ParseBlocksArguments for block data provider
1 parent c5a9f17 commit 3cb67c4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

engine/access/rest/websockets/data_providers/blocks_provider.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,16 @@ func ParseBlocksArguments(arguments models.Arguments) (BlocksArguments, error) {
114114
return args, fmt.Errorf("'block_status' must be provided")
115115
}
116116

117+
startBlockIDIn, hasStartBlockID := arguments["start_block_id"]
118+
startBlockHeightIn, hasStartBlockHeight := arguments["start_block_height"]
119+
120+
// Ensure only one of start_block_id or start_block_height is provided
121+
if hasStartBlockID && hasStartBlockHeight {
122+
return args, fmt.Errorf("can only provide either 'start_block_id' or 'start_block_height'")
123+
}
124+
117125
// Parse 'start_block_id' if provided
118-
if startBlockIDIn, ok := arguments["start_block_id"]; ok {
126+
if hasStartBlockID {
119127
var startBlockID parser.ID
120128
err := startBlockID.Parse(startBlockIDIn)
121129
if err != nil {
@@ -125,7 +133,7 @@ func ParseBlocksArguments(arguments models.Arguments) (BlocksArguments, error) {
125133
}
126134

127135
// Parse 'start_block_height' if provided
128-
if startBlockHeightIn, ok := arguments["start_block_height"]; ok {
136+
if hasStartBlockHeight {
129137
var err error
130138
args.StartBlockHeight, err = util.ToUint64(startBlockHeightIn)
131139
if err != nil {
@@ -135,10 +143,5 @@ func ParseBlocksArguments(arguments models.Arguments) (BlocksArguments, error) {
135143
args.StartBlockHeight = request.EmptyHeight
136144
}
137145

138-
// Ensure only one of start_block_id or start_block_height is provided
139-
if args.StartBlockID != flow.ZeroID && args.StartBlockHeight != request.EmptyHeight {
140-
return args, fmt.Errorf("can only provide either 'start_block_id' or 'start_block_height'")
141-
}
142-
143146
return args, nil
144147
}

0 commit comments

Comments
 (0)