github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/app/rpc/namespaces/web3/api.go (about) 1 package web3 2 3 import ( 4 "fmt" 5 6 "github.com/ethereum/go-ethereum/common/hexutil" 7 "github.com/ethereum/go-ethereum/crypto" 8 "github.com/fibonacci-chain/fbc/app/rpc/monitor" 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/version" 10 "github.com/fibonacci-chain/fbc/libs/tendermint/libs/log" 11 "github.com/spf13/viper" 12 ) 13 14 const ( 15 NameSpace = "web3" 16 ) 17 18 // PublicWeb3API is the web3_ prefixed set of APIs in the Web3 JSON-RPC spec. 19 type PublicWeb3API struct { 20 logger log.Logger 21 Metrics *monitor.RpcMetrics 22 } 23 24 // NewAPI creates an instance of the Web3 API. 25 func NewAPI(log log.Logger) *PublicWeb3API { 26 api := &PublicWeb3API{ 27 logger: log.With("module", "json-rpc", "namespace", NameSpace), 28 } 29 if viper.GetBool(monitor.FlagEnableMonitor) { 30 api.Metrics = monitor.MakeMonitorMetrics(NameSpace) 31 } 32 return api 33 } 34 35 // ClientVersion returns the client version in the Web3 user agent format. 36 func (api *PublicWeb3API) ClientVersion() string { 37 monitor := monitor.GetMonitor("web3_clientVersion", api.logger, api.Metrics).OnBegin() 38 defer monitor.OnEnd() 39 info := version.NewInfo() 40 return fmt.Sprintf("%s-%s", info.Name, info.Version) 41 } 42 43 // Sha3 returns the keccak-256 hash of the passed-in input. 44 func (api *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes { 45 monitor := monitor.GetMonitor("web3_sha3", api.logger, api.Metrics).OnBegin() 46 defer monitor.OnEnd() 47 return crypto.Keccak256(input) 48 }