forked from cerc-io/laconicd-deprecated
Implements net_version for Ethers (#121)
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user