laconicd-deprecated/rpc/apis.go

88 lines
2.0 KiB
Go
Raw Normal View History

package rpc
import (
2021-04-17 10:00:07 +00:00
"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"
"github.com/ethereum/go-ethereum/rpc"
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
2021-04-17 10:00:07 +00:00
"github.com/cosmos/ethermint/rpc/backend"
"github.com/cosmos/ethermint/rpc/namespaces/eth"
rpctypes "github.com/cosmos/ethermint/rpc/types"
2021-04-17 10:00:07 +00:00
"github.com/cosmos/cosmos-sdk/client"
)
// RPC namespaces and API version
const (
Web3Namespace = "web3"
EthNamespace = "eth"
PersonalNamespace = "personal"
NetNamespace = "net"
flagRPCAPI = "rpc-api"
apiVersion = "1.0"
2021-04-17 10:00:07 +00:00
flagRPCAPI = "rpc-api"
)
// GetAPIs returns the list of all APIs from the Ethereum namespaces
2021-04-17 10:00:07 +00:00
func GetAPIs(clientCtx client.Context, selectedApis []string, keys ...ethsecp256k1.PrivKey) []rpc.API {
nonceLock := new(rpctypes.AddrLocker)
backend := backend.New(clientCtx)
ethAPI := eth.NewAPI(clientCtx, backend, nonceLock, keys...)
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,
},
)
2021-04-17 10:00:07 +00:00
case EthNamespace:
apis = append(apis,
rpc.API{
Namespace: EthNamespace,
Version: apiVersion,
Service: ethAPI,
Public: true,
},
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,
},
)
}
}
return apis
}