From 5a19ae570667c843a53236e78391bfbe59726744 Mon Sep 17 00:00:00 2001 From: Austin Abell Date: Tue, 15 Oct 2019 10:20:35 +0900 Subject: [PATCH] Implements net_version for Ethers (#121) --- go.mod | 1 + rpc/apis.go | 6 ++++++ rpc/net_api.go | 34 ++++++++++++++++++++++++++++++++++ x/evm/types/msg.go | 2 +- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 rpc/net_api.go diff --git a/go.mod b/go.mod index bfb4587e..77993556 100644 --- a/go.mod +++ b/go.mod @@ -53,6 +53,7 @@ require ( golang.org/x/net v0.0.0-20190628185345-da137c7871d7 golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect golang.org/x/text v0.3.2 // indirect + google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190708153700-3bdd9d9f5532 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v2 v2.2.2 diff --git a/rpc/apis.go b/rpc/apis.go index 3c9ed42e..dc51e16f 100644 --- a/rpc/apis.go +++ b/rpc/apis.go @@ -36,5 +36,11 @@ func GetRPCAPIs(cliCtx context.CLIContext, key emintcrypto.PrivKeySecp256k1) []r Service: NewPublicFilterAPI(cliCtx), Public: true, }, + { + Namespace: "net", + Version: "1.0", + Service: NewPublicNetAPI(cliCtx), + Public: true, + }, } } diff --git a/rpc/net_api.go b/rpc/net_api.go new file mode 100644 index 00000000..058fd35b --- /dev/null +++ b/rpc/net_api.go @@ -0,0 +1,34 @@ +package rpc + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/viper" +) + +// PublicNetAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec. +type PublicNetAPI struct { + networkVersion uint64 +} + +// NewPersonalEthAPI creates an instance of the public ETH Web3 API. +func NewPublicNetAPI(cliCtx context.CLIContext) *PublicNetAPI { + chainID := viper.GetString(flags.FlagChainID) + // parse the chainID from a integer string + intChainID, err := strconv.ParseUint(chainID, 0, 64) + if err != nil { + panic(fmt.Sprintf("Invalid chainID: %s, must be integer format", chainID)) + } + + return &PublicNetAPI{ + networkVersion: intChainID, + } +} + +// Version returns the current ethereum protocol version. +func (s *PublicNetAPI) Version() string { + return fmt.Sprintf("%d", s.networkVersion) +} diff --git a/x/evm/types/msg.go b/x/evm/types/msg.go index cc235a9b..7d04186e 100644 --- a/x/evm/types/msg.go +++ b/x/evm/types/msg.go @@ -427,7 +427,7 @@ func GenerateFromArgs(args args.SendTxArgs, ctx context.CLIContext) (msg *Ethere if args.Gas == nil { // Estimate the gas usage if necessary. // TODO: Set gas based on estimate when simulating txs are setup - gasLimit = 22000 + gasLimit = 60000 } else { gasLimit = (uint64)(*args.Gas) }