-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathethrpc.go
More file actions
71 lines (63 loc) · 1.99 KB
/
Copy pathethrpc.go
File metadata and controls
71 lines (63 loc) · 1.99 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ethrpc
import (
"encoding/json"
"fmt"
"math/big"
)
// EthError - ethereum error
type EthError struct {
Code int `json:"code"`
Message string `json:"message"`
}
func (err EthError) Error() string {
return fmt.Sprintf("EthError %d (%s)", err.Code, err.Message)
}
type EthResponse struct {
ID int `json:"id,omitempty"`
Version string `json:"jsonrpc"`
Result json.RawMessage `json:"result"`
Error *EthError `json:"error"`
}
type EthRequest struct {
ID int `json:"id,omitempty"`
Version string `json:"jsonrpc"`
Method string `json:"method"`
Params []interface{} `json:"params"`
}
func NewEthRequest(method string, params ...interface{}) EthRequest {
return EthRequest{
ID: 1,
Version: "2.0",
Method: method,
Params: params,
}
}
var (
_ EthRPC = (*NodeAPI)(nil)
_ EthRPC = (*InfuraAPI)(nil)
_ EthRPC = (*EtherscanAPI)(nil)
)
type EthRPC interface {
String() string
Debug(bool)
BatchCall(reqs []EthRequest) ([]EthResponse, error)
Call(method string, params ...interface{}) (json.RawMessage, error)
Web3ClientVersion() (string, error)
NetVersion() (string, error)
NetListening() (bool, error)
NetPeerCount() (int, error)
EthProtocolVersion() (string, error)
EthSyncing() (*Syncing, error)
EthGasPrice() (big.Int, error)
EthBlockNumber() (int, error)
EthGetBalance(address, block string) (big.Int, error)
EthGetStorageAt(data string, position int, tag string) (string, error)
EthGetTransactionCount(address, block string) (int, error)
EthGetBlockTransactionCountByNumber(number int) (int, error)
EthGetBlockByNumber(number int, withTransactions bool) (*Block, error)
EthGetTransactionByHash(hash string) (*Transaction, error)
EthGetTransactionByBlockNumberAndIndex(blockNumber, transactionIndex int) (*Transaction, error)
EthGetTransactionReceipt(hash string) (*TransactionReceipt, error)
EthGetLogs(params FilterParams) ([]Log, error)
EthGetUncleByBlockNumberAndIndex(number int, pos int) (*Block, error)
}