Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

eth_accounts endpoint #2022

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jsonrpc/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"
"unicode"

"github.com/0xPolygon/polygon-edge/secrets"
"github.com/armon/go-metrics"
"github.com/hashicorp/go-hclog"
)
Expand Down Expand Up @@ -61,6 +62,8 @@ type dispatcherParams struct {
blockRangeLimit uint64

concurrentRequestsDebug uint64

secretsManager secrets.SecretsManager
}

func (dp dispatcherParams) isExceedingBatchLengthLimit(value uint64) bool {
Expand Down Expand Up @@ -96,6 +99,7 @@ func (d *Dispatcher) registerEndpoints(store JSONRPCStore) error {
d.params.chainID,
d.filterManager,
d.params.priceLimit,
d.params.secretsManager,
}
d.endpoints.Net = &Net{
store,
Expand Down
23 changes: 18 additions & 5 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"github.com/hashicorp/go-hclog"

"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/gasprice"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/helper/progress"
"github.com/0xPolygon/polygon-edge/secrets"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/state/runtime"
"github.com/0xPolygon/polygon-edge/types"
Expand Down Expand Up @@ -93,11 +95,12 @@ type ethStore interface {

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

var (
Expand All @@ -111,6 +114,16 @@ func (e *Eth) ChainId() (interface{}, error) {
return argUintPtr(e.chainID), nil
}

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
}

func (e *Eth) Syncing() (interface{}, error) {
if syncProgression := e.store.GetSyncProgression(); syncProgression != nil {
// Node is bulk syncing, return the status
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/eth_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ func TestEth_TxnType(t *testing.T) {

func newTestEthEndpoint(store testStore) *Eth {
return &Eth{
hclog.NewNullLogger(), store, 100, nil, 0,
hclog.NewNullLogger(), store, 100, nil, 0, nil,
}
}

func newTestEthEndpointWithPriceLimit(store testStore, priceLimit uint64) *Eth {
return &Eth{
hclog.NewNullLogger(), store, 100, nil, priceLimit,
hclog.NewNullLogger(), store, 100, nil, priceLimit, nil,
}
}

Expand Down
4 changes: 4 additions & 0 deletions jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/0xPolygon/polygon-edge/secrets"
"github.com/0xPolygon/polygon-edge/versioning"
"github.com/gorilla/websocket"
"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -71,6 +72,8 @@ type Config struct {

ConcurrentRequestsDebug uint64
WebSocketReadLimit uint64

SecretsManager secrets.SecretsManager
}

// NewJSONRPC returns the JSONRPC http server
Expand All @@ -85,6 +88,7 @@ func NewJSONRPC(logger hclog.Logger, config *Config) (*JSONRPC, error) {
jsonRPCBatchLengthLimit: config.BatchLengthLimit,
blockRangeLimit: config.BlockRangeLimit,
concurrentRequestsDebug: config.ConcurrentRequestsDebug,
secretsManager: config.SecretsManager,
},
)

Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ func (s *Server) setupJSONRPC() error {
BlockRangeLimit: s.config.JSONRPC.BlockRangeLimit,
ConcurrentRequestsDebug: s.config.JSONRPC.ConcurrentRequestsDebug,
WebSocketReadLimit: s.config.JSONRPC.WebSocketReadLimit,
SecretsManager: s.secretsManager,
}

srv, err := jsonrpc.NewJSONRPC(s.logger, conf)
Expand Down
Loading