2019-07-15 14:13:59 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2020-10-06 18:57:55 +00:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
|
|
|
|
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
2020-10-22 20:39:51 +00:00
|
|
|
"github.com/cosmos/ethermint/rpc/backend"
|
|
|
|
"github.com/cosmos/ethermint/rpc/namespaces/eth"
|
|
|
|
"github.com/cosmos/ethermint/rpc/namespaces/eth/filters"
|
|
|
|
"github.com/cosmos/ethermint/rpc/namespaces/net"
|
|
|
|
"github.com/cosmos/ethermint/rpc/namespaces/personal"
|
|
|
|
"github.com/cosmos/ethermint/rpc/namespaces/web3"
|
|
|
|
rpctypes "github.com/cosmos/ethermint/rpc/types"
|
2019-07-15 14:13:59 +00:00
|
|
|
)
|
|
|
|
|
2020-07-03 15:40:00 +00:00
|
|
|
// RPC namespaces and API version
|
|
|
|
const (
|
|
|
|
Web3Namespace = "web3"
|
|
|
|
EthNamespace = "eth"
|
|
|
|
PersonalNamespace = "personal"
|
|
|
|
NetNamespace = "net"
|
|
|
|
|
|
|
|
apiVersion = "1.0"
|
|
|
|
)
|
2020-04-02 00:43:59 +00:00
|
|
|
|
2020-10-22 20:39:51 +00:00
|
|
|
// GetAPIs returns the list of all APIs from the Ethereum namespaces
|
|
|
|
func GetAPIs(clientCtx context.CLIContext, keys ...ethsecp256k1.PrivKey) []rpc.API {
|
|
|
|
nonceLock := new(rpctypes.AddrLocker)
|
|
|
|
backend := backend.New(clientCtx)
|
|
|
|
ethAPI := eth.NewAPI(clientCtx, backend, nonceLock, keys...)
|
2020-07-06 17:23:35 +00:00
|
|
|
|
2019-07-15 14:13:59 +00:00
|
|
|
return []rpc.API{
|
|
|
|
{
|
2020-04-02 00:43:59 +00:00
|
|
|
Namespace: Web3Namespace,
|
2020-07-03 15:40:00 +00:00
|
|
|
Version: apiVersion,
|
2020-10-22 20:39:51 +00:00
|
|
|
Service: web3.NewAPI(),
|
2019-09-18 18:45:21 +00:00
|
|
|
Public: true,
|
2019-07-15 14:13:59 +00:00
|
|
|
},
|
|
|
|
{
|
2020-04-02 00:43:59 +00:00
|
|
|
Namespace: EthNamespace,
|
2020-07-03 15:40:00 +00:00
|
|
|
Version: apiVersion,
|
2020-08-13 17:14:48 +00:00
|
|
|
Service: ethAPI,
|
2019-09-18 18:45:21 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
{
|
2020-10-22 20:39:51 +00:00
|
|
|
Namespace: EthNamespace,
|
2020-07-03 15:40:00 +00:00
|
|
|
Version: apiVersion,
|
2020-10-22 20:39:51 +00:00
|
|
|
Service: filters.NewAPI(clientCtx, backend),
|
|
|
|
Public: true,
|
2019-07-15 14:13:59 +00:00
|
|
|
},
|
2019-10-08 03:32:28 +00:00
|
|
|
{
|
2020-10-22 20:39:51 +00:00
|
|
|
Namespace: PersonalNamespace,
|
2020-07-03 15:40:00 +00:00
|
|
|
Version: apiVersion,
|
2020-10-22 20:39:51 +00:00
|
|
|
Service: personal.NewAPI(ethAPI),
|
|
|
|
Public: false,
|
2019-10-08 03:32:28 +00:00
|
|
|
},
|
2019-10-15 01:20:35 +00:00
|
|
|
{
|
2020-04-02 00:43:59 +00:00
|
|
|
Namespace: NetNamespace,
|
2020-07-03 15:40:00 +00:00
|
|
|
Version: apiVersion,
|
2020-10-22 20:39:51 +00:00
|
|
|
Service: net.NewAPI(clientCtx),
|
2019-10-15 01:20:35 +00:00
|
|
|
Public: true,
|
|
|
|
},
|
2019-07-15 14:13:59 +00:00
|
|
|
}
|
|
|
|
}
|