2021-06-23 06:38:05 +00:00
|
|
|
package net
|
2019-10-15 01:20:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-06-22 10:49:18 +00:00
|
|
|
ethermint "github.com/tharsis/ethermint/types"
|
2021-04-18 16:39:15 +00:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-10-15 01:20:35 +00:00
|
|
|
)
|
|
|
|
|
2021-06-23 06:38:05 +00:00
|
|
|
// PublicAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
|
|
|
|
type PublicAPI struct {
|
2019-10-15 01:20:35 +00:00
|
|
|
networkVersion uint64
|
|
|
|
}
|
|
|
|
|
2021-06-23 06:38:05 +00:00
|
|
|
// NewPublicAPI creates an instance of the public Net Web3 API.
|
|
|
|
func NewPublicAPI(clientCtx client.Context) *PublicAPI {
|
2019-10-15 01:20:35 +00:00
|
|
|
// parse the chainID from a integer string
|
2021-04-19 07:30:55 +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
|
|
|
}
|
|
|
|
|
2021-06-23 06:38:05 +00:00
|
|
|
return &PublicAPI{
|
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.
|
2021-06-23 06:38:05 +00:00
|
|
|
func (s *PublicAPI) Version() string {
|
2021-04-18 16:39:15 +00:00
|
|
|
return fmt.Sprintf("%d", s.networkVersion)
|
2019-10-15 01:20:35 +00:00
|
|
|
}
|