/
api.go
38 lines (33 loc) · 1.16 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package web3
import (
"fmt"
"github.com/cosmos/cosmos-sdk/version"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/okex/exchain/app/rpc/monitor"
"github.com/tendermint/tendermint/libs/log"
)
// PublicWeb3API is the web3_ prefixed set of APIs in the Web3 JSON-RPC spec.
type PublicWeb3API struct {
logger log.Logger
Metrics map[string]*monitor.RpcMetrics
}
// NewAPI creates an instance of the Web3 API.
func NewAPI(log log.Logger) *PublicWeb3API {
return &PublicWeb3API{
logger: log.With("module", "json-rpc", "namespace", "web3"),
}
}
// ClientVersion returns the client version in the Web3 user agent format.
func (api *PublicWeb3API) ClientVersion() string {
monitor := monitor.GetMonitor("web3_clientVersion", api.logger, api.Metrics).OnBegin()
defer monitor.OnEnd()
info := version.NewInfo()
return fmt.Sprintf("%s-%s", info.Name, info.Version)
}
// Sha3 returns the keccak-256 hash of the passed-in input.
func (api *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes {
monitor := monitor.GetMonitor("web3_sha3", api.logger, api.Metrics).OnBegin()
defer monitor.OnEnd()
return crypto.Keccak256(input)
}