Skip to content

Commit

Permalink
Fix: waiting RPC only in indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 11, 2023
1 parent a40be4f commit 012c7ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/indexer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewBlockchainIndexer(ctx context.Context, cfg config.Config, network string
networkType,
config.WithConfigCopy(cfg),
config.WithStorage(cfg.Storage, "indexer", 10, cfg.Indexer.Connections.Open, cfg.Indexer.Connections.Idle, true),
config.WithRPC(cfg.RPC),
config.WithWaitRPC(cfg.RPC),
)
logger.Info().Str("network", internalCtx.Network.String()).Msg("Creating indexer object...")

Expand Down
20 changes: 20 additions & 0 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ type ContextOption func(ctx *Context)

// WithRPC -
func WithRPC(rpcConfig map[string]RPCConfig) ContextOption {
return func(ctx *Context) {
if rpcProvider, ok := rpcConfig[ctx.Network.String()]; ok {
if rpcProvider.URI == "" {
return
}
opts := []noderpc.NodeOption{
noderpc.WithTimeout(time.Second * time.Duration(rpcProvider.Timeout)),
noderpc.WithRateLimit(rpcProvider.RequestsPerSecond),
}
if rpcProvider.Log {
opts = append(opts, noderpc.WithLog())
}

ctx.RPC = noderpc.NewNodeRPC(rpcProvider.URI, opts...)
}
}
}

// WithWaitRPC -
func WithWaitRPC(rpcConfig map[string]RPCConfig) ContextOption {
return func(ctx *Context) {
if rpcProvider, ok := rpcConfig[ctx.Network.String()]; ok {
if rpcProvider.URI == "" {
Expand Down

0 comments on commit 012c7ae

Please sign in to comment.