From 890ffd9e7f6a1a99c67ec57d6f56513a8cf23d53 Mon Sep 17 00:00:00 2001 From: Igor Crevar Date: Wed, 1 Nov 2023 11:26:21 +0100 Subject: [PATCH] eth_accounts endpoint --- jsonrpc/dispatcher.go | 4 ++++ jsonrpc/eth_endpoint.go | 23 ++++++++++++++++++----- jsonrpc/eth_endpoint_test.go | 4 ++-- jsonrpc/jsonrpc.go | 4 ++++ server/server.go | 1 + 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/jsonrpc/dispatcher.go b/jsonrpc/dispatcher.go index 6d234ccd91..4b4db7a753 100644 --- a/jsonrpc/dispatcher.go +++ b/jsonrpc/dispatcher.go @@ -12,6 +12,7 @@ import ( "time" "unicode" + "github.com/0xPolygon/polygon-edge/secrets" "github.com/armon/go-metrics" "github.com/hashicorp/go-hclog" ) @@ -61,6 +62,8 @@ type dispatcherParams struct { blockRangeLimit uint64 concurrentRequestsDebug uint64 + + secretsManager secrets.SecretsManager } func (dp dispatcherParams) isExceedingBatchLengthLimit(value uint64) bool { @@ -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, diff --git a/jsonrpc/eth_endpoint.go b/jsonrpc/eth_endpoint.go index e564950822..71b5ba8f49 100644 --- a/jsonrpc/eth_endpoint.go +++ b/jsonrpc/eth_endpoint.go @@ -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" @@ -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 ( @@ -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 diff --git a/jsonrpc/eth_endpoint_test.go b/jsonrpc/eth_endpoint_test.go index ed61a4184a..930471fc82 100644 --- a/jsonrpc/eth_endpoint_test.go +++ b/jsonrpc/eth_endpoint_test.go @@ -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, } } diff --git a/jsonrpc/jsonrpc.go b/jsonrpc/jsonrpc.go index bfae70b15b..3de16f4bdf 100644 --- a/jsonrpc/jsonrpc.go +++ b/jsonrpc/jsonrpc.go @@ -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" @@ -71,6 +72,8 @@ type Config struct { ConcurrentRequestsDebug uint64 WebSocketReadLimit uint64 + + SecretsManager secrets.SecretsManager } // NewJSONRPC returns the JSONRPC http server @@ -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, }, ) diff --git a/server/server.go b/server/server.go index 8688105ee2..e1d4c8fa95 100644 --- a/server/server.go +++ b/server/server.go @@ -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)