-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
null_client.go
237 lines (187 loc) · 6.67 KB
/
null_client.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package client
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)
// NullClient satisfies the Client but has no side effects
type NullClient struct {
cid *big.Int
lggr logger.Logger
}
func NewNullClient(cid *big.Int, lggr logger.Logger) *NullClient {
return &NullClient{cid: cid, lggr: logger.Named(lggr, "NullClient")}
}
// NullClientChainID the ChainID that nullclient will return
// 0 is never used as a real chain ID so makes sense as a dummy value here
const NullClientChainID = 0
//
// Client methods
//
func (nc *NullClient) Dial(context.Context) error {
nc.lggr.Debug("Dial")
return nil
}
func (nc *NullClient) Close() {
nc.lggr.Debug("Close")
}
func (nc *NullClient) TokenBalance(ctx context.Context, address common.Address, contractAddress common.Address) (*big.Int, error) {
nc.lggr.Debug("TokenBalance")
return big.NewInt(0), nil
}
func (nc *NullClient) LINKBalance(ctx context.Context, address common.Address, linkAddress common.Address) (*assets.Link, error) {
nc.lggr.Debug("LINKBalance")
return assets.NewLinkFromJuels(0), nil
}
func (nc *NullClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
nc.lggr.Debug("CallContext")
return nil
}
func (nc *NullClient) HeadByNumber(ctx context.Context, n *big.Int) (*evmtypes.Head, error) {
nc.lggr.Debug("HeadByNumber")
return nil, nil
}
func (nc *NullClient) HeadByHash(ctx context.Context, h common.Hash) (*evmtypes.Head, error) {
nc.lggr.Debug("HeadByHash")
return nil, nil
}
type nullSubscription struct {
lggr logger.Logger
}
func newNullSubscription(lggr logger.Logger) *nullSubscription {
return &nullSubscription{lggr: logger.Named(lggr, "NullSubscription")}
}
func (ns *nullSubscription) Unsubscribe() {
ns.lggr.Debug("Unsubscribe")
}
func (ns *nullSubscription) Err() <-chan error {
ns.lggr.Debug("Err")
return nil
}
func (nc *NullClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
nc.lggr.Debug("SubscribeFilterLogs")
return newNullSubscription(nc.lggr), nil
}
func (nc *NullClient) SubscribeNewHead(ctx context.Context, ch chan<- *evmtypes.Head) (ethereum.Subscription, error) {
nc.lggr.Debug("SubscribeNewHead")
return newNullSubscription(nc.lggr), nil
}
//
// GethClient methods
//
func (nc *NullClient) ConfiguredChainID() *big.Int {
nc.lggr.Debug("ConfiguredChainID")
if nc.cid != nil {
return nc.cid
}
return big.NewInt(NullClientChainID)
}
func (nc *NullClient) ChainID() (*big.Int, error) {
nc.lggr.Debug("ChainID")
return nil, nil
}
func (nc *NullClient) HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error) {
nc.lggr.Debug("HeaderByNumber")
return nil, nil
}
func (nc *NullClient) HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error) {
nc.lggr.Debug("HeaderByHash")
return nil, nil
}
func (nc *NullClient) SendTransactionReturnCode(ctx context.Context, tx *types.Transaction, sender common.Address) (commonclient.SendTxReturnCode, error) {
nc.lggr.Debug("SendTransactionReturnCode")
return commonclient.Successful, nil
}
func (nc *NullClient) SendTransaction(ctx context.Context, tx *types.Transaction) error {
nc.lggr.Debug("SendTransaction")
return nil
}
func (nc *NullClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) {
nc.lggr.Debug("PendingCodeAt")
return nil, nil
}
func (nc *NullClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
nc.lggr.Debug("PendingNonceAt")
return 0, nil
}
func (nc *NullClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error) {
nc.lggr.Debug("SequenceAt")
return 0, nil
}
func (nc *NullClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
nc.lggr.Debug("TransactionReceipt")
return nil, nil
}
func (nc *NullClient) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error) {
nc.lggr.Debug("TransactionByHash")
return nil, nil
}
func (nc *NullClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
nc.lggr.Debug("BlockByNumber")
return nil, nil
}
func (nc *NullClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
nc.lggr.Debug("BlockByHash")
return nil, nil
}
func (nc *NullClient) LatestBlockHeight(ctx context.Context) (*big.Int, error) {
nc.lggr.Debug("LatestBlockHeight")
return nil, nil
}
func (nc *NullClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
nc.lggr.Debug("BalanceAt")
return big.NewInt(0), nil
}
func (nc *NullClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
nc.lggr.Debug("FilterLogs")
return nil, nil
}
func (nc *NullClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) {
nc.lggr.Debug("EstimateGas")
return 0, nil
}
func (nc *NullClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
nc.lggr.Debug("SuggestGasPrice")
return big.NewInt(0), nil
}
func (nc *NullClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
nc.lggr.Debug("CallContract")
return nil, nil
}
func (nc *NullClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
nc.lggr.Debug("PendingCallContract")
return nil, nil
}
func (nc *NullClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
nc.lggr.Debug("CodeAt")
return nil, nil
}
func (nc *NullClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error {
return nil
}
// BatchCallContextAll implements evmclient.Client interface
func (nc *NullClient) BatchCallContextAll(ctx context.Context, b []rpc.BatchElem) error {
return nil
}
func (nc *NullClient) SuggestGasTipCap(ctx context.Context) (tipCap *big.Int, err error) {
return nil, nil
}
// NodeStates implements evmclient.Client
func (nc *NullClient) NodeStates() map[string]string { return nil }
func (nc *NullClient) IsL2() bool {
nc.lggr.Debug("IsL2")
return false
}
func (nc *NullClient) LatestFinalizedBlock(_ context.Context) (*evmtypes.Head, error) {
return nil, nil
}
func (nc *NullClient) CheckTxValidity(_ context.Context, _ common.Address, _ common.Address, _ []byte) *SendError {
return nil
}