396db9f20a
* miner namespace * SetGasPrice call * Added note plus fixed error logging * Refactor to use the keyring in the miner namespace * Changed keyring function return * Added more detailed logs to unsupported functions * Reverted changes on ethapi and just using a refrence to it on miner * Creating a transaction * fix condition * Error string not capitalized * suggested changes to setEtherbase * change log level * minor changes * minor changes * Sending tx to test the endpoint * get tx nonce * Using aphoton const and changing the logger to debug * Using default RPC gas limit constant * Apply suggestions from code review Renames and log changes Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * pair programming session * get gas * Set gas prices note added * Setting fess and max gas * delete unnecessary log * Apply suggestions from code review return false in case of error Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Suggested changes applied * Updated changelog and json_rpc docs * Update CHANGELOG.md Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/miner/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/miner/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/miner/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/miner/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Using the same coin denom as the gas price for the fee Co-authored-by: ramacarlucho <ramirocarlucho@gmail.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
137 lines
3.5 KiB
Go
137 lines
3.5 KiB
Go
// 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/cosmos/cosmos-sdk/server"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
"github.com/tharsis/ethermint/ethereum/rpc/backend"
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/debug"
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/eth"
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/eth/filters"
|
|
"github.com/tharsis/ethermint/ethereum/rpc/namespaces/miner"
|
|
"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"
|
|
"github.com/tharsis/ethermint/ethereum/rpc/types"
|
|
|
|
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
|
)
|
|
|
|
// RPC namespaces and API version
|
|
const (
|
|
Web3Namespace = "web3"
|
|
EthNamespace = "eth"
|
|
PersonalNamespace = "personal"
|
|
NetNamespace = "net"
|
|
TxPoolNamespace = "txpool"
|
|
DebugNamespace = "debug"
|
|
MinerNamespace = "miner"
|
|
|
|
apiVersion = "1.0"
|
|
)
|
|
|
|
// GetRPCAPIs returns the list of all APIs
|
|
func GetRPCAPIs(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient, selectedAPIs []string) []rpc.API {
|
|
nonceLock := new(types.AddrLocker)
|
|
evmBackend := backend.NewEVMBackend(ctx.Logger, clientCtx)
|
|
ethAPI := eth.NewPublicAPI(ctx.Logger, clientCtx, evmBackend, nonceLock)
|
|
|
|
var apis []rpc.API
|
|
|
|
// remove duplicates
|
|
selectedAPIs = unique(selectedAPIs)
|
|
|
|
for index := range selectedAPIs {
|
|
switch selectedAPIs[index] {
|
|
case EthNamespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: EthNamespace,
|
|
Version: apiVersion,
|
|
Service: ethAPI,
|
|
Public: true,
|
|
},
|
|
rpc.API{
|
|
Namespace: EthNamespace,
|
|
Version: apiVersion,
|
|
Service: filters.NewPublicAPI(ctx.Logger, tmWSClient, evmBackend),
|
|
Public: true,
|
|
},
|
|
)
|
|
case Web3Namespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: Web3Namespace,
|
|
Version: apiVersion,
|
|
Service: web3.NewPublicAPI(),
|
|
Public: true,
|
|
},
|
|
)
|
|
case NetNamespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: NetNamespace,
|
|
Version: apiVersion,
|
|
Service: net.NewPublicAPI(clientCtx),
|
|
Public: true,
|
|
},
|
|
)
|
|
case PersonalNamespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: PersonalNamespace,
|
|
Version: apiVersion,
|
|
Service: personal.NewAPI(ctx.Logger, ethAPI),
|
|
Public: true,
|
|
},
|
|
)
|
|
case TxPoolNamespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: TxPoolNamespace,
|
|
Version: apiVersion,
|
|
Service: txpool.NewPublicAPI(ctx.Logger),
|
|
Public: true,
|
|
},
|
|
)
|
|
case DebugNamespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: DebugNamespace,
|
|
Version: apiVersion,
|
|
Service: debug.NewInternalAPI(ctx),
|
|
Public: true,
|
|
},
|
|
)
|
|
case MinerNamespace:
|
|
apis = append(apis,
|
|
rpc.API{
|
|
Namespace: MinerNamespace,
|
|
Version: apiVersion,
|
|
Service: miner.NewMinerAPI(ctx, ethAPI, evmBackend),
|
|
Public: true,
|
|
},
|
|
)
|
|
default:
|
|
ctx.Logger.Error("invalid namespace value", "namespace", selectedAPIs[index])
|
|
}
|
|
}
|
|
|
|
return apis
|
|
}
|
|
|
|
func unique(intSlice []string) []string {
|
|
keys := make(map[string]bool)
|
|
var list []string
|
|
for _, entry := range intSlice {
|
|
if _, value := keys[entry]; !value {
|
|
keys[entry] = true
|
|
list = append(list, entry)
|
|
}
|
|
}
|
|
return list
|
|
}
|