Skip to content

Commit c5a9f17

Browse files
Added names to interface arguments, created Arguments type for websockets
1 parent 399b604 commit c5a9f17

File tree

10 files changed

+50
-29
lines changed

10 files changed

+50
-29
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type BaseDataProvider interface {
1616
// Topic returns the topic associated with the data provider.
1717
Topic() string
1818
// Close terminates the data provider.
19-
Close()
19+
Close() error
2020
}
2121

2222
var _ BaseDataProvider = (*BaseDataProviderImpl)(nil)
@@ -58,6 +58,7 @@ func (b *BaseDataProviderImpl) Topic() string {
5858
}
5959

6060
// Close terminates the data provider.
61-
func (b *BaseDataProviderImpl) Close() {
61+
func (b *BaseDataProviderImpl) Close() error {
6262
b.cancel()
63+
return nil
6364
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewBlockDigestsDataProvider(
3030
logger zerolog.Logger,
3131
api access.API,
3232
topic string,
33-
arguments map[string]string,
33+
arguments models.Arguments,
3434
send chan<- interface{},
3535
) (*BlockDigestsDataProvider, error) {
3636
p := &BlockDigestsDataProvider{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewBlockHeadersDataProvider(
3030
logger zerolog.Logger,
3131
api access.API,
3232
topic string,
33-
arguments map[string]string,
33+
arguments models.Arguments,
3434
send chan<- interface{},
3535
) (*BlockHeadersDataProvider, error) {
3636
p := &BlockHeadersDataProvider{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewBlocksDataProvider(
3939
logger zerolog.Logger,
4040
api access.API,
4141
topic string,
42-
arguments map[string]string,
42+
arguments models.Arguments,
4343
send chan<- interface{},
4444
) (*BlocksDataProvider, error) {
4545
p := &BlocksDataProvider{
@@ -100,7 +100,7 @@ func (p *BlocksDataProvider) handleResponse(send chan<- interface{}) func(*flow.
100100
}
101101

102102
// ParseBlocksArguments validates and initializes the blocks arguments.
103-
func ParseBlocksArguments(arguments map[string]string) (BlocksArguments, error) {
103+
func ParseBlocksArguments(arguments models.Arguments) (BlocksArguments, error) {
104104
var args BlocksArguments
105105

106106
// Parse 'block_status'

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
accessmock "github.com/onflow/flow-go/access/mock"
1212
"github.com/onflow/flow-go/engine/access/rest/common/parser"
13+
"github.com/onflow/flow-go/engine/access/rest/websockets/models"
1314
"github.com/onflow/flow-go/model/flow"
1415
"github.com/onflow/flow-go/utils/unittest"
1516
)
@@ -18,7 +19,7 @@ const unknownBlockStatus = "unknown_block_status"
1819

1920
type testErrType struct {
2021
name string
21-
arguments map[string]string
22+
arguments models.Arguments
2223
expectedErrorMsg string
2324
}
2425

@@ -69,21 +70,21 @@ func (s *BlocksProviderSuite) invalidArgumentsTestCases() []testErrType {
6970
return []testErrType{
7071
{
7172
name: "missing 'block_status' argument",
72-
arguments: map[string]string{
73+
arguments: models.Arguments{
7374
"start_block_id": s.rootBlock.ID().String(),
7475
},
7576
expectedErrorMsg: "'block_status' must be provided",
7677
},
7778
{
7879
name: "unknown 'block_status' argument",
79-
arguments: map[string]string{
80+
arguments: models.Arguments{
8081
"block_status": unknownBlockStatus,
8182
},
8283
expectedErrorMsg: fmt.Sprintf("invalid 'block_status', must be '%s' or '%s'", parser.Finalized, parser.Sealed),
8384
},
8485
{
8586
name: "provide both 'start_block_id' and 'start_block_height' arguments",
86-
arguments: map[string]string{
87+
arguments: models.Arguments{
8788
"block_status": parser.Finalized,
8889
"start_block_id": s.rootBlock.ID().String(),
8990
"start_block_height": fmt.Sprintf("%d", s.rootBlock.Header.Height),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/rs/zerolog"
88

99
"github.com/onflow/flow-go/access"
10+
"github.com/onflow/flow-go/engine/access/rest/websockets/models"
1011
"github.com/onflow/flow-go/engine/access/state_stream"
1112
)
1213

@@ -29,7 +30,7 @@ type DataProviderFactory interface {
2930
// and configuration parameters.
3031
//
3132
// No errors are expected during normal operations.
32-
NewDataProvider(context.Context, string, map[string]string, chan<- interface{}) (DataProvider, error)
33+
NewDataProvider(ctx context.Context, topic string, arguments models.Arguments, ch chan<- interface{}) (DataProvider, error)
3334
}
3435

3536
var _ DataProviderFactory = (*DataProviderFactoryImpl)(nil)
@@ -76,7 +77,7 @@ func NewDataProviderFactory(
7677
func (s *DataProviderFactoryImpl) NewDataProvider(
7778
ctx context.Context,
7879
topic string,
79-
arguments map[string]string,
80+
arguments models.Arguments,
8081
ch chan<- interface{},
8182
) (DataProvider, error) {
8283
switch topic {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
accessmock "github.com/onflow/flow-go/access/mock"
1212
"github.com/onflow/flow-go/engine/access/rest/common/parser"
13+
"github.com/onflow/flow-go/engine/access/rest/websockets/models"
1314
statestreammock "github.com/onflow/flow-go/engine/access/state_stream/mock"
1415
"github.com/onflow/flow-go/model/flow"
1516
"github.com/onflow/flow-go/utils/unittest"
@@ -63,14 +64,14 @@ func (s *DataProviderFactorySuite) TestSupportedTopics() {
6364
testCases := []struct {
6465
name string
6566
topic string
66-
arguments map[string]string
67+
arguments models.Arguments
6768
setupSubscription func()
6869
assertExpectations func()
6970
}{
7071
{
7172
name: "block topic",
7273
topic: BlocksTopic,
73-
arguments: map[string]string{"block_status": parser.Finalized},
74+
arguments: models.Arguments{"block_status": parser.Finalized},
7475
setupSubscription: func() {
7576
s.setupSubscription(s.accessApi.On("SubscribeBlocksFromLatest", mock.Anything, flow.BlockStatusFinalized))
7677
},
@@ -81,7 +82,7 @@ func (s *DataProviderFactorySuite) TestSupportedTopics() {
8182
{
8283
name: "block headers topic",
8384
topic: BlockHeadersTopic,
84-
arguments: map[string]string{"block_status": parser.Finalized},
85+
arguments: models.Arguments{"block_status": parser.Finalized},
8586
setupSubscription: func() {
8687
s.setupSubscription(s.accessApi.On("SubscribeBlockHeadersFromLatest", mock.Anything, flow.BlockStatusFinalized))
8788
},
@@ -92,7 +93,7 @@ func (s *DataProviderFactorySuite) TestSupportedTopics() {
9293
{
9394
name: "block digests topic",
9495
topic: BlockDigestsTopic,
95-
arguments: map[string]string{"block_status": parser.Finalized},
96+
arguments: models.Arguments{"block_status": parser.Finalized},
9697
setupSubscription: func() {
9798
s.setupSubscription(s.accessApi.On("SubscribeBlockDigestsFromLatest", mock.Anything, flow.BlockStatusFinalized))
9899
},

engine/access/rest/websockets/data_providers/mock/data_provider.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/access/rest/websockets/data_providers/mock/data_provider_factory.go

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/access/rest/websockets/models/subscribe.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package models
22

3+
type Arguments map[string]string
4+
35
// SubscribeMessageRequest represents a request to subscribe to a topic.
46
type SubscribeMessageRequest struct {
57
BaseMessageRequest
6-
Topic string `json:"topic"` // Topic to subscribe to
7-
Arguments map[string]string `json:"arguments"` // Additional arguments for subscription
8+
Topic string `json:"topic"` // Topic to subscribe to
9+
Arguments Arguments `json:"arguments"` // Additional arguments for subscription
810
}
911

1012
// SubscribeMessageResponse represents the response to a subscription request.

0 commit comments

Comments
 (0)