-
Notifications
You must be signed in to change notification settings - Fork 23
/
methods.go
109 lines (96 loc) · 4.32 KB
/
methods.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package client
import (
"github.com/benbjohnson/immutable"
"github.com/ipfs/go-log"
"strings"
)
var logger = log.Logger("ethergo-client-logger")
// RPCMethod is an enum type for an rpc method.
type RPCMethod string
// NOTE: any changes here must be added to allMethods list below.
// ETH METHODS:.
const (
// ChainIDMethod is used to retrieve the current chain ID for transaction replay protection.
ChainIDMethod RPCMethod = "eth_chainId"
// BlockByHashMethod gets a block by hash.
BlockByHashMethod RPCMethod = "eth_getBlockByHash"
// BlockByNumberMethod gets a block by number.
BlockByNumberMethod RPCMethod = "eth_getBlockByNumber"
// BlockNumberMethod gets the latest block number.
BlockNumberMethod RPCMethod = "eth_blockNumber"
// TransactionByHashMethod returns the transaction with the given hash.
TransactionByHashMethod RPCMethod = "eth_getTransactionByHash"
// TransactionByBlockHashAndIndexMethod returns a transaction by its hash and index.
TransactionByBlockHashAndIndexMethod RPCMethod = "eth_getTransactionByBlockHashAndIndex"
// TransactionCountByHashMethod get sthe transaction count by hash.
TransactionCountByHashMethod RPCMethod = "eth_getBlockTransactionCountByHash"
// TransactionReceiptByHashMethod gets the transaction receipt from a hash.
TransactionReceiptByHashMethod RPCMethod = "eth_getTransactionReceipt"
// SyncProgressMethod gets the sync progress.
SyncProgressMethod RPCMethod = "eth_syncing"
// GetBalanceMethod gets the balance for a given address.
GetBalanceMethod RPCMethod = "eth_getBalance"
// StorageAtMethod returns the value of key in the contract storage of the given account.
StorageAtMethod RPCMethod = "eth_getStorageAt"
// GetCodeMethod returns the contract code of the given account.
GetCodeMethod RPCMethod = "eth_getCode"
// TransactionCountMethod returns the account nonce of the given account.
TransactionCountMethod RPCMethod = "eth_getTransactionCount"
// GetLogsMethod filters logs.
GetLogsMethod RPCMethod = "eth_getLogs"
// CallMethod calls a contract.
CallMethod RPCMethod = "eth_call"
// GasPriceMethod gets the gas price.
GasPriceMethod RPCMethod = "eth_gasPrice"
// MaxPriorityMethod gets the max priority fee.
MaxPriorityMethod RPCMethod = "eth_maxPriorityFeePerGas"
// FeeHistoryMethod gets the fee history.
FeeHistoryMethod RPCMethod = "eth_feeHistory"
// EstimateGasMethod tries to estimate the gas needed to execute a specific transaction.
EstimateGasMethod RPCMethod = "eth_estimateGas"
// PendingTransactionCountMethod gets the pending transaction count.
PendingTransactionCountMethod RPCMethod = "eth_getBlockTransactionCountByNumber"
// SendRawTransactionMethod sends a raw tx.
SendRawTransactionMethod RPCMethod = "eth_sendRawTransaction"
// SubscribeMethod subscribes to an event.
SubscribeMethod RPCMethod = "eth_subscribe"
)
// Harmony Methods:.
const (
// HarmonyGetLogsMethod filters logs on harmony.
HarmonyGetLogsMethod RPCMethod = "hmy_getLogs"
// HarmonyGetReceiptMethod gets a receipt on harmony
// this should always return Hash rather than Ethereum Hash.
HarmonyGetReceiptMethod RPCMethod = "hmy_getTransactionReceipt"
)
// NetMethods:.
const (
// NetVersionMethod gets the network version.
NetVersionMethod RPCMethod = "net_version"
Web3VersionMethod RPCMethod = "web3_clientVersion"
)
// allMethods gets all available rpc methods.
var allMethods = []RPCMethod{ChainIDMethod, BlockByHashMethod, BlockByNumberMethod, BlockNumberMethod,
BlockNumberMethod, TransactionByHashMethod, TransactionByBlockHashAndIndexMethod, TransactionCountByHashMethod,
TransactionReceiptByHashMethod, SyncProgressMethod, GetBalanceMethod, SubscribeMethod, NetVersionMethod, Web3VersionMethod, HarmonyGetReceiptMethod, HarmonyGetLogsMethod}
var methodMap *immutable.Map[RPCMethod, string]
func init() {
methodLowerMap := immutable.NewMapBuilder[RPCMethod, string](nil)
for _, method := range allMethods {
methodLowerMap.Set(method, strings.ToLower(string(method)))
}
methodMap = methodLowerMap.Map()
}
// Comparable converts an rpc method to lowercase based on a preset map
// can be used for case sensitive comparison.
func (r RPCMethod) Comparable() string {
res, ok := methodMap.Get(r)
if !ok {
logger.Warnf("rpc method not found for %s", r)
}
return res
}
// String returns the string representation of an rpc method.
func (r RPCMethod) String() string {
return string(r)
}