Skip to content

Commit

Permalink
ethproviders: add websocket to config
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Mar 18, 2024
1 parent e38e491 commit a06badc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions ethproviders/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import "strings"
type Config map[string]NetworkConfig

type NetworkConfig struct {
ID uint64 `toml:"id" json:"id"`
URL string `toml:"url" json:"url"`
AuthChain bool `toml:"auth_chain" json:"authChain"`
Testnet bool `toml:"testnet" json:"testnet"`
Disabled bool `toml:"disabled" json:"disabled"`
ID uint64 `toml:"id" json:"id"`
URL string `toml:"url" json:"url"`

WSEnabled bool `toml:"ws_enabled" json:"wsEnabled"`
WSURL string `toml:"ws_url" json:"wsUrl"`

AuthChain bool `toml:"auth_chain" json:"authChain"`
Testnet bool `toml:"testnet" json:"testnet"`
Disabled bool `toml:"disabled" json:"disabled"`
}

func (n Config) GetByID(id uint64) (NetworkConfig, bool) {
Expand Down
8 changes: 4 additions & 4 deletions ethrpc/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type Provider struct {
log logger.Logger
nodeURL string
nodeWSSURL string
nodeWSURL string
httpClient httpClient
br breaker.Breaker
jwtToken string // optional
Expand Down Expand Up @@ -420,7 +420,7 @@ func (p *Provider) SubscribeFilterLogs(ctx context.Context, query ethereum.Filte
}
if p.gethRPC == nil {
var err error
p.gethRPC, err = rpc.Dial(p.nodeWSSURL)
p.gethRPC, err = rpc.Dial(p.nodeWSURL)
if err != nil {
return nil, fmt.Errorf("ethrpc: SubscribeFilterLogs failed: %w", err)
}
Expand All @@ -436,7 +436,7 @@ func (p *Provider) SubscribeNewHeads(ctx context.Context, ch chan<- *types.Heade
}
if p.gethRPC == nil {
var err error
p.gethRPC, err = rpc.Dial(p.nodeWSSURL)
p.gethRPC, err = rpc.Dial(p.nodeWSURL)
if err != nil {
return nil, fmt.Errorf("ethrpc: SubscribeNewHeads failed: %w", err)
}
Expand Down Expand Up @@ -477,5 +477,5 @@ func (p *Provider) contractQuery(ctx context.Context, contractAddress string, in

// ...
func (p *Provider) IsStreamingEnabled() bool {
return p.nodeWSSURL != ""
return p.nodeWSURL != ""
}
2 changes: 1 addition & 1 deletion ethrpc/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type httpClient interface {

func WithStreaming(nodeWebsocketURL string) Option {
return func(p *Provider) {
p.nodeWSSURL = nodeWebsocketURL
p.nodeWSURL = nodeWebsocketURL
}
}

Expand Down

0 comments on commit a06badc

Please sign in to comment.