Skip to content

Commit

Permalink
Add hooks to allow overriding Helper field in Syncer
Browse files Browse the repository at this point in the history
Needed by a Concordium fork of 'rosetta-cli' that understands account aliases. This is necessary for the 'rosetta-cli check:data' test to pass on a Concordium network.
  • Loading branch information
bisgardo committed Jul 6, 2022
1 parent 136b591 commit 7942ab4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions statefulsyncer/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package statefulsyncer

import (
"time"

"github.com/coinbase/rosetta-sdk-go/syncer"
)

// Option is used to overwrite default values in
Expand Down Expand Up @@ -66,3 +68,9 @@ func WithSeenConcurrency(concurrency int64) Option {
s.seenSemaphoreSize = concurrency
}
}

func WithExtraSyncerOpts(os ...syncer.Option) Option {
return func(s *StatefulSyncer) {
s.extraSyncerOpts = os
}
}
12 changes: 8 additions & 4 deletions statefulsyncer/stateful_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type StatefulSyncer struct {
// BlockSeen occur concurrently.
seenSemaphore *semaphore.Weighted
seenSemaphoreSize int64

extraSyncerOpts []syncer.Option
}

// Logger is used by the statefulsyncer to
Expand Down Expand Up @@ -162,10 +164,12 @@ func (s *StatefulSyncer) Sync(ctx context.Context, startIndex int64, endIndex in
s,
s,
s.cancel,
syncer.WithPastBlocks(pastBlocks),
syncer.WithCacheSize(s.cacheSize),
syncer.WithMaxConcurrency(s.maxConcurrency),
syncer.WithAdjustmentWindow(s.adjustmentWindow),
append([]syncer.Option{
syncer.WithPastBlocks(pastBlocks),
syncer.WithCacheSize(s.cacheSize),
syncer.WithMaxConcurrency(s.maxConcurrency),
syncer.WithAdjustmentWindow(s.adjustmentWindow),
}, s.extraSyncerOpts...)...,
)

return syncer.Sync(ctx, startIndex, endIndex)
Expand Down
6 changes: 6 additions & 0 deletions syncer/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ func WithAdjustmentWindow(adjustmentWindow int64) Option {
s.adjustmentWindow = adjustmentWindow
}
}

func WithCustomHelper(h func(Helper) Helper) Option {
return func(s *Syncer) {
s.helper = h(s.helper)
}
}

0 comments on commit 7942ab4

Please sign in to comment.