2020-10-22 20:39:51 +00:00
|
|
|
package net
|
2019-10-15 01:20:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
|
2020-09-24 17:50:47 +00:00
|
|
|
ethermint "github.com/cosmos/ethermint/types"
|
2019-10-15 01:20:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PublicNetAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
|
|
|
|
type PublicNetAPI struct {
|
|
|
|
networkVersion uint64
|
|
|
|
}
|
|
|
|
|
2020-10-22 20:39:51 +00:00
|
|
|
// NewAPI creates an instance of the public Net Web3 API.
|
2021-04-17 10:00:07 +00:00
|
|
|
func NewAPI(clientCtx client.Context) *PublicNetAPI {
|
2019-10-15 01:20:35 +00:00
|
|
|
// parse the chainID from a integer string
|
2020-10-22 20:39:51 +00:00
|
|
|
chainIDEpoch, err := ethermint.ParseChainID(clientCtx.ChainID)
|
2019-10-15 01:20:35 +00:00
|
|
|
if err != nil {
|
2020-09-24 17:50:47 +00:00
|
|
|
panic(err)
|
2019-10-15 01:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &PublicNetAPI{
|
2020-09-24 17:50:47 +00:00
|
|
|
networkVersion: chainIDEpoch.Uint64(),
|
2019-10-15 01:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version returns the current ethereum protocol version.
|
2020-10-22 20:39:51 +00:00
|
|
|
func (api *PublicNetAPI) Version() string {
|
|
|
|
return fmt.Sprintf("%d", api.networkVersion)
|
2019-10-15 01:20:35 +00:00
|
|
|
}
|