2021-04-18 16:39:15 +00:00
|
|
|
// Package rpc contains RPC handler methods and utilities to start
|
|
|
|
// Ethermint's Web3-compatibly JSON-RPC server.
|
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2021-06-23 06:38:05 +00:00
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/backend"
|
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/eth"
|
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/eth/filters"
|
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/net"
|
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/personal"
|
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/txpool"
|
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/web3"
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/ethereum/rpc/types"
|
2021-04-19 10:49:55 +00:00
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RPC namespaces and API version
|
|
|
|
const (
|
|
|
|
Web3Namespace = "web3"
|
|
|
|
EthNamespace = "eth"
|
|
|
|
PersonalNamespace = "personal"
|
|
|
|
NetNamespace = "net"
|
2021-06-21 14:06:30 +00:00
|
|
|
TxPoolNamespace = "txpool"
|
2021-04-18 16:39:15 +00:00
|
|
|
|
|
|
|
apiVersion = "1.0"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetRPCAPIs returns the list of all APIs
|
|
|
|
func GetRPCAPIs(clientCtx client.Context, tmWSClient *rpcclient.WSClient) []rpc.API {
|
|
|
|
nonceLock := new(types.AddrLocker)
|
2021-06-23 06:38:05 +00:00
|
|
|
backend := backend.NewEVMBackend(clientCtx)
|
|
|
|
ethAPI := eth.NewPublicAPI(clientCtx, backend, nonceLock)
|
2021-04-18 16:39:15 +00:00
|
|
|
|
|
|
|
return []rpc.API{
|
|
|
|
{
|
|
|
|
Namespace: Web3Namespace,
|
|
|
|
Version: apiVersion,
|
2021-06-23 06:38:05 +00:00
|
|
|
Service: web3.NewPublicAPI(),
|
2021-04-18 16:39:15 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: EthNamespace,
|
|
|
|
Version: apiVersion,
|
|
|
|
Service: ethAPI,
|
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: EthNamespace,
|
|
|
|
Version: apiVersion,
|
2021-06-23 06:38:05 +00:00
|
|
|
Service: filters.NewPublicAPI(tmWSClient, backend),
|
2021-04-18 16:39:15 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: NetNamespace,
|
|
|
|
Version: apiVersion,
|
2021-06-23 06:38:05 +00:00
|
|
|
Service: net.NewPublicAPI(clientCtx),
|
2021-04-18 16:39:15 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
2021-05-12 16:50:26 +00:00
|
|
|
{
|
|
|
|
Namespace: PersonalNamespace,
|
|
|
|
Version: apiVersion,
|
2021-06-23 06:38:05 +00:00
|
|
|
Service: personal.NewAPI(ethAPI),
|
2021-05-12 16:50:26 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
2021-06-21 14:06:30 +00:00
|
|
|
{
|
|
|
|
Namespace: TxPoolNamespace,
|
|
|
|
Version: apiVersion,
|
2021-06-23 06:38:05 +00:00
|
|
|
Service: txpool.NewPublicAPI(),
|
2021-06-21 14:06:30 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
2021-04-18 16:39:15 +00:00
|
|
|
}
|
|
|
|
}
|