Skip to content

Commit

Permalink
Fixed parse function for event privoder
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiDiachuk committed Dec 6, 2024
1 parent 8d0543d commit d6fc9df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
27 changes: 6 additions & 21 deletions engine/access/rest/websockets/data_providers/events_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package data_providers

import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/rs/zerolog"

Check failure on line 6 in engine/access/rest/websockets/data_providers/events_provider.go

View workflow job for this annotation

GitHub Actions / Lint (./)

File is not `goimports`-ed with -local github.com/onflow/flow-go/ (goimports)
"strconv"

"github.com/onflow/flow-go/engine/access/rest/common/parser"
"github.com/onflow/flow-go/engine/access/rest/http/request"
Expand Down Expand Up @@ -175,16 +172,12 @@ func parseEventsArguments(
// Parse 'event_types' as a JSON array
var eventTypes parser.EventTypes
if eventTypesIn, ok := arguments["event_types"]; ok && eventTypesIn != "" {
result, ok := eventTypesIn.(string)
result, ok := eventTypesIn.([]string)
if !ok {
return args, fmt.Errorf("'event_types' must be a string")
}
err := json.Unmarshal([]byte(result), &eventTypes) // Expect a JSON array
if err != nil {
return args, fmt.Errorf("could not parse 'event_types': %w", err)
return args, fmt.Errorf("'event_types' must be an array of string")
}

err = eventTypes.Parse(strings.Split(result, ","))
err := eventTypes.Parse(result)
if err != nil {
return args, fmt.Errorf("invalid 'event_types': %w", err)
}
Expand All @@ -193,27 +186,19 @@ func parseEventsArguments(
// Parse 'addresses' as []string{}
var addresses []string
if addressesIn, ok := arguments["addresses"]; ok && addressesIn != "" {
result, ok := addressesIn.(string)
addresses, ok = addressesIn.([]string)
if !ok {
return args, fmt.Errorf("'addresses' must be a string")
}
err := json.Unmarshal([]byte(result), &addresses) // Expect a JSON array
if err != nil {
return args, fmt.Errorf("could not parse 'addresses': %w", err)
}
}

// Parse 'contracts' as []string{}
var contracts []string
if contractsIn, ok := arguments["contracts"]; ok && contractsIn != "" {
result, ok := contractsIn.(string)
contracts, ok = contractsIn.([]string)
if !ok {
return args, fmt.Errorf("'contracts' must be a string")
}
err := json.Unmarshal([]byte(result), &contracts) // Expect a JSON array
if err != nil {
return args, fmt.Errorf("could not parse 'contracts': %w", err)
}
}

// Initialize the event filter with the parsed arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (s *EventsProviderSuite) subscribeEventsDataProviderTestCases() []testType
name: "SubscribeBlocksFromStartBlockID happy path",
arguments: models.Arguments{
"start_block_id": s.rootBlock.ID().String(),
"event_types": []string{"flow.AccountCreated", "flow.AccountUpdated"},
},
setupBackend: func(sub *ssmock.Subscription) {
s.api.On(
Expand Down

0 comments on commit d6fc9df

Please sign in to comment.