Skip to content

Commit

Permalink
small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Dec 26, 2023
1 parent 0173f3d commit ce54945
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
14 changes: 9 additions & 5 deletions jsonrpc/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ func newDispatcher(
}

func (d *Dispatcher) registerEndpoints(store JSONRPCStore) error {
d.endpoints.Eth = &Eth{
var err error

d.endpoints.Eth, err = NewEth(
d.logger,
store,
d.params.chainID,
d.filterManager,
d.params.priceLimit,
d.params.secretsManager,
d.params.chainID,
d.params.priceLimit,
)
if err != nil {
return err
}

d.endpoints.Net = &Net{
store,
d.params.chainID,
Expand All @@ -120,8 +126,6 @@ func (d *Dispatcher) registerEndpoints(store JSONRPCStore) error {
}
d.endpoints.Debug = NewDebug(store, d.params.concurrentRequestsDebug)

var err error

if err = d.registerService("eth", d.endpoints.Eth); err != nil {
return err
}
Expand Down
42 changes: 29 additions & 13 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,34 @@ type ethStore interface {

// Eth is the eth jsonrpc endpoint
type Eth struct {
logger hclog.Logger
store ethStore
chainID uint64
filterManager *FilterManager
priceLimit uint64
secretsManager secrets.SecretsManager
logger hclog.Logger
store ethStore
chainID uint64
filterManager *FilterManager
priceLimit uint64
account *wallet.Account
}

func NewEth(
logger hclog.Logger,
store ethStore,
filterManager *FilterManager,
secretsManager secrets.SecretsManager,
chainID uint64,
priceLimit uint64) (*Eth, error) {
account, err := wallet.NewAccountFromSecret(secretsManager)
if err != nil {
return nil, fmt.Errorf("failed to read account data: %w", err)
}

return &Eth{
store: store,
logger: logger,
chainID: chainID,
account: account,
priceLimit: priceLimit,
filterManager: filterManager,
}, nil
}

var (
Expand All @@ -115,13 +137,7 @@ func (e *Eth) ChainId() (interface{}, error) {
}

func (e *Eth) Accounts() (interface{}, error) {
// read account
account, err := wallet.NewAccountFromSecret(e.secretsManager)
if err != nil {
return nil, fmt.Errorf("failed to read account data: %w", err)
}

return []types.Address{types.Address(wallet.NewKey(account).Address())}, nil
return []types.Address{types.Address(wallet.NewKey(e.account).Address())}, nil
}

func (e *Eth) Syncing() (interface{}, error) {
Expand Down

0 comments on commit ce54945

Please sign in to comment.