From aaefa0065527149799a1988983eda6bbba5f74c2 Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Mon, 9 Oct 2023 12:35:03 -0700 Subject: [PATCH] fix(`rpc`): adding namespaces back (#1228) * add apis * add eth api * goimports * disable eth --- rpc/apis.go | 121 +++++++++++++++-------------- rpc/namespaces/ethereum/eth/api.go | 6 +- 2 files changed, 64 insertions(+), 63 deletions(-) diff --git a/rpc/apis.go b/rpc/apis.go index da130ad0a1..e214368a71 100644 --- a/rpc/apis.go +++ b/rpc/apis.go @@ -24,9 +24,13 @@ import ( ethermint "github.com/evmos/ethermint/types" rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client" "github.com/zeta-chain/zetacore/rpc/backend" + "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/debug" "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/eth" "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/eth/filters" + "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/miner" "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/net" + "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/personal" + "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/txpool" "github.com/zeta-chain/zetacore/rpc/namespaces/ethereum/web3" ) @@ -105,66 +109,65 @@ func init() { }, } }, - // Disabled // NOTE: Public field of API is deprecated and defined only for compatibility. - //PersonalNamespace: func(ctx *server.Context, - // clientCtx client.Context, - // _ *rpcclient.WSClient, - // allowUnprotectedTxs bool, - // indexer ethermint.EVMTxIndexer, - //) []rpc.API { - // evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) - // return []rpc.API{ - // { - // Namespace: PersonalNamespace, - // Version: apiVersion, - // Service: personal.NewAPI(ctx.Logger, evmBackend), - // Public: false, - // }, - // } - //}, - //TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API { - // return []rpc.API{ - // { - // Namespace: TxPoolNamespace, - // Version: apiVersion, - // Service: txpool.NewPublicAPI(ctx.Logger), - // Public: true, - // }, - // } - //}, - //DebugNamespace: func(ctx *server.Context, - // clientCtx client.Context, - // _ *rpcclient.WSClient, - // allowUnprotectedTxs bool, - // indexer ethermint.EVMTxIndexer, - //) []rpc.API { - // evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) - // return []rpc.API{ - // { - // Namespace: DebugNamespace, - // Version: apiVersion, - // Service: debug.NewAPI(ctx, evmBackend), - // Public: true, - // }, - // } - //}, - //MinerNamespace: func(ctx *server.Context, - // clientCtx client.Context, - // _ *rpcclient.WSClient, - // allowUnprotectedTxs bool, - // indexer ethermint.EVMTxIndexer, - //) []rpc.API { - // evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) - // return []rpc.API{ - // { - // Namespace: MinerNamespace, - // Version: apiVersion, - // Service: miner.NewPrivateAPI(ctx, evmBackend), - // Public: false, - // }, - // } - //}, + PersonalNamespace: func(ctx *server.Context, + clientCtx client.Context, + _ *rpcclient.WSClient, + allowUnprotectedTxs bool, + indexer ethermint.EVMTxIndexer, + ) []rpc.API { + evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) + return []rpc.API{ + { + Namespace: PersonalNamespace, + Version: apiVersion, + Service: personal.NewAPI(ctx.Logger, evmBackend), + Public: false, + }, + } + }, + TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient, _ bool, _ ethermint.EVMTxIndexer) []rpc.API { + return []rpc.API{ + { + Namespace: TxPoolNamespace, + Version: apiVersion, + Service: txpool.NewPublicAPI(ctx.Logger), + Public: true, + }, + } + }, + DebugNamespace: func(ctx *server.Context, + clientCtx client.Context, + _ *rpcclient.WSClient, + allowUnprotectedTxs bool, + indexer ethermint.EVMTxIndexer, + ) []rpc.API { + evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) + return []rpc.API{ + { + Namespace: DebugNamespace, + Version: apiVersion, + Service: debug.NewAPI(ctx, evmBackend), + Public: true, + }, + } + }, + MinerNamespace: func(ctx *server.Context, + clientCtx client.Context, + _ *rpcclient.WSClient, + allowUnprotectedTxs bool, + indexer ethermint.EVMTxIndexer, + ) []rpc.API { + evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer) + return []rpc.API{ + { + Namespace: MinerNamespace, + Version: apiVersion, + Service: miner.NewPrivateAPI(ctx, evmBackend), + Public: false, + }, + } + }, } } diff --git a/rpc/namespaces/ethereum/eth/api.go b/rpc/namespaces/ethereum/eth/api.go index 5200e26495..1de121c024 100644 --- a/rpc/namespaces/ethereum/eth/api.go +++ b/rpc/namespaces/ethereum/eth/api.go @@ -117,7 +117,7 @@ type EthereumAPI interface { // eth_submitWork (on Ethereum.org) // eth_submitHashrate (on Ethereum.org) - // Disabled APIs for security reasons + // Disabled //SendTransaction(args evmtypes.TransactionArgs) (common.Hash, error) //Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error) //SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error) @@ -507,9 +507,7 @@ func (e *PublicAPI) GetPendingTransactions() ([]*rpctypes.RPCTransaction, error) return result, nil } -/////////////////////////////////////////////////////////////////////////////// -/// Disabled /// -/////////////////////////////////////////////////////////////////////////////// +// Disabled //// SendTransaction sends an Ethereum transaction. //func (e *PublicAPI) SendTransaction(args evmtypes.TransactionArgs) (common.Hash, error) {