Skip to content

Commit ff3851b

Browse files
Refactored base data provider according to comments
1 parent 1a2698f commit ff3851b

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

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

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,23 @@ import (
88
"github.com/onflow/flow-go/engine/access/subscription"
99
)
1010

11-
// BaseDataProvider defines the basic interface for a data provider. It provides methods
12-
// for retrieving the provider's unique ID, topic, and a method to close the provider.
13-
type BaseDataProvider interface {
14-
// ID returns the unique identifier of the data provider.
15-
ID() uuid.UUID
16-
// Topic returns the topic associated with the data provider.
17-
Topic() string
18-
// Close terminates the data provider.
19-
Close() error
20-
}
21-
22-
var _ BaseDataProvider = (*BaseDataProviderImpl)(nil)
23-
24-
// BaseDataProviderImpl is the concrete implementation of the BaseDataProvider interface.
25-
// It holds common objects for the provider.
26-
type BaseDataProviderImpl struct {
11+
// baseDataProvider holds common objects for the provider
12+
type baseDataProvider struct {
2713
id uuid.UUID
2814
topic string
2915
cancel context.CancelFunc
3016
send chan<- interface{}
3117
subscription subscription.Subscription
3218
}
3319

34-
// NewBaseDataProviderImpl creates a new instance of BaseDataProviderImpl.
35-
func NewBaseDataProviderImpl(
20+
// newBaseDataProvider creates a new instance of baseDataProvider.
21+
func newBaseDataProvider(
3622
topic string,
3723
cancel context.CancelFunc,
3824
send chan<- interface{},
3925
subscription subscription.Subscription,
40-
) *BaseDataProviderImpl {
41-
return &BaseDataProviderImpl{
26+
) *baseDataProvider {
27+
return &baseDataProvider{
4228
id: uuid.New(),
4329
topic: topic,
4430
cancel: cancel,
@@ -48,17 +34,19 @@ func NewBaseDataProviderImpl(
4834
}
4935

5036
// ID returns the unique identifier of the data provider.
51-
func (b *BaseDataProviderImpl) ID() uuid.UUID {
37+
func (b *baseDataProvider) ID() uuid.UUID {
5238
return b.id
5339
}
5440

5541
// Topic returns the topic associated with the data provider.
56-
func (b *BaseDataProviderImpl) Topic() string {
42+
func (b *baseDataProvider) Topic() string {
5743
return b.topic
5844
}
5945

6046
// Close terminates the data provider.
61-
func (b *BaseDataProviderImpl) Close() error {
47+
//
48+
// No errors are expected during normal operations.
49+
func (b *baseDataProvider) Close() error {
6250
b.cancel()
6351
return nil
6452
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
// BlockDigestsDataProvider is responsible for providing block digests
1717
type BlockDigestsDataProvider struct {
18-
*BaseDataProviderImpl
18+
*baseDataProvider
1919

2020
logger zerolog.Logger
2121
api access.API
@@ -44,7 +44,7 @@ func NewBlockDigestsDataProvider(
4444
}
4545

4646
subCtx, cancel := context.WithCancel(ctx)
47-
p.BaseDataProviderImpl = NewBaseDataProviderImpl(
47+
p.baseDataProvider = newBaseDataProvider(
4848
topic,
4949
cancel,
5050
send,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
// BlockHeadersDataProvider is responsible for providing block headers
1717
type BlockHeadersDataProvider struct {
18-
*BaseDataProviderImpl
18+
*baseDataProvider
1919

2020
logger zerolog.Logger
2121
api access.API
@@ -44,7 +44,7 @@ func NewBlockHeadersDataProvider(
4444
}
4545

4646
subCtx, cancel := context.WithCancel(ctx)
47-
p.BaseDataProviderImpl = NewBaseDataProviderImpl(
47+
p.baseDataProvider = newBaseDataProvider(
4848
topic,
4949
cancel,
5050
send,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type BlocksArguments struct {
2424

2525
// BlocksDataProvider is responsible for providing blocks
2626
type BlocksDataProvider struct {
27-
*BaseDataProviderImpl
27+
*baseDataProvider
2828

2929
logger zerolog.Logger
3030
api access.API
@@ -53,7 +53,7 @@ func NewBlocksDataProvider(
5353
}
5454

5555
subCtx, cancel := context.WithCancel(ctx)
56-
p.BaseDataProviderImpl = NewBaseDataProviderImpl(
56+
p.baseDataProvider = newBaseDataProvider(
5757
topic,
5858
cancel,
5959
send,

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
package data_providers
22

3+
import (
4+
"github.com/google/uuid"
5+
)
6+
37
// The DataProvider is the interface abstracts of the actual data provider used by the WebSocketCollector.
8+
// It provides methods for retrieving the provider's unique ID, topic, and a methods to close and run the provider.
49
type DataProvider interface {
5-
BaseDataProvider
6-
10+
// ID returns the unique identifier of the data provider.
11+
ID() uuid.UUID
12+
// Topic returns the topic associated with the data provider.
13+
Topic() string
14+
// Close terminates the data provider.
15+
//
16+
// No errors are expected during normal operations.
17+
Close() error
718
// Run starts processing the subscription and handles responses.
819
//
920
// No errors are expected during normal operations.

0 commit comments

Comments
 (0)