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"
|
2021-02-26 21:52:33 +00:00
|
|
|
flagRPCAPI = "rpc-api"
|
2020-07-03 15:40:00 +00:00
|
|
|
|
|
|
|
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
|
2021-02-26 21:52:33 +00:00
|
|
|
func GetAPIs(clientCtx context.CLIContext, selectedApis []string, keys ...ethsecp256k1.PrivKey) []rpc.API {
|
2020-10-22 20:39:51 +00:00
|
|
|
nonceLock := new(rpctypes.AddrLocker)
|
|
|
|
backend := backend.New(clientCtx)
|
|
|
|
ethAPI := eth.NewAPI(clientCtx, backend, nonceLock, keys...)
|
2020-07-06 17:23:35 +00:00
|
|
|
|
2021-02-26 21:52:33 +00:00
|
|
|
var apis []rpc.API
|
|
|
|
|
|
|
|
for _, api := range selectedApis {
|
|
|
|
switch api {
|
|
|
|
case Web3Namespace:
|
|
|
|
apis = append(apis,
|
|
|
|
rpc.API{
|
|
|
|
Namespace: Web3Namespace,
|
|
|
|
Version: apiVersion,
|
|
|
|
Service: web3.NewAPI(),
|
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case EthNamespace:
|
|
|
|
apis = append(apis,
|
|
|
|
rpc.API{
|
|
|
|
Namespace: EthNamespace,
|
|
|
|
Version: apiVersion,
|
|
|
|
Service: ethAPI,
|
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
apis = append(apis,
|
|
|
|
rpc.API{
|
|
|
|
Namespace: EthNamespace,
|
|
|
|
Version: apiVersion,
|
|
|
|
Service: filters.NewAPI(clientCtx, backend),
|
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case PersonalNamespace:
|
|
|
|
apis = append(apis,
|
|
|
|
rpc.API{
|
|
|
|
Namespace: PersonalNamespace,
|
|
|
|
Version: apiVersion,
|
|
|
|
Service: personal.NewAPI(ethAPI),
|
|
|
|
Public: false,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case NetNamespace:
|
|
|
|
apis = append(apis,
|
|
|
|
rpc.API{
|
|
|
|
Namespace: NetNamespace,
|
|
|
|
Version: apiVersion,
|
|
|
|
Service: net.NewAPI(clientCtx),
|
|
|
|
Public: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2019-07-15 14:13:59 +00:00
|
|
|
}
|
2021-02-26 21:52:33 +00:00
|
|
|
|
|
|
|
return apis
|
2019-07-15 14:13:59 +00:00
|
|
|
}
|