2019-10-15 01:20:35 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2020-07-02 15:19:48 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2019-10-15 01:20:35 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PublicNetAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
|
|
|
|
type PublicNetAPI struct {
|
|
|
|
networkVersion uint64
|
|
|
|
}
|
|
|
|
|
2020-07-03 15:40:00 +00:00
|
|
|
// NewPublicNetAPI creates an instance of the public Net Web3 API.
|
|
|
|
func NewPublicNetAPI(_ context.CLIContext) *PublicNetAPI {
|
2019-10-15 01:20:35 +00:00
|
|
|
chainID := viper.GetString(flags.FlagChainID)
|
|
|
|
// parse the chainID from a integer string
|
|
|
|
intChainID, err := strconv.ParseUint(chainID, 0, 64)
|
|
|
|
if err != nil {
|
2020-03-16 22:53:24 +00:00
|
|
|
panic(fmt.Sprintf("invalid chainID: %s, must be integer format", chainID))
|
2019-10-15 01:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &PublicNetAPI{
|
|
|
|
networkVersion: intChainID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version returns the current ethereum protocol version.
|
|
|
|
func (s *PublicNetAPI) Version() string {
|
|
|
|
return fmt.Sprintf("%d", s.networkVersion)
|
|
|
|
}
|