@@ -24,6 +24,7 @@ import (
24
24
25
25
"github.com/ethereum/go-ethereum"
26
26
"github.com/ethereum/go-ethereum/common"
27
+ "github.com/ethereum/go-ethereum/common/hexutil"
27
28
"github.com/ethereum/go-ethereum/core/types"
28
29
"github.com/ethereum/go-ethereum/core/vm"
29
30
"github.com/ethereum/go-ethereum/rlp"
@@ -156,9 +157,9 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (*typ
156
157
157
158
// TransactionCount returns the total number of transactions in the given block.
158
159
func (ec * Client ) TransactionCount (ctx context.Context , blockHash common.Hash ) (uint , error ) {
159
- var num rpc. HexNumber
160
+ var num hexutil. Uint
160
161
err := ec .c .CallContext (ctx , & num , "eth_getBlockTransactionCountByHash" , blockHash )
161
- return num . Uint ( ), err
162
+ return uint ( num ), err
162
163
}
163
164
164
165
// TransactionInBlock returns a single transaction at index in the given block.
@@ -196,11 +197,11 @@ func toBlockNumArg(number *big.Int) string {
196
197
}
197
198
198
199
type rpcProgress struct {
199
- StartingBlock rpc. HexNumber
200
- CurrentBlock rpc. HexNumber
201
- HighestBlock rpc. HexNumber
202
- PulledStates rpc. HexNumber
203
- KnownStates rpc. HexNumber
200
+ StartingBlock hexutil. Uint64
201
+ CurrentBlock hexutil. Uint64
202
+ HighestBlock hexutil. Uint64
203
+ PulledStates hexutil. Uint64
204
+ KnownStates hexutil. Uint64
204
205
}
205
206
206
207
// SyncProgress retrieves the current progress of the sync algorithm. If there's
@@ -220,11 +221,11 @@ func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, err
220
221
return nil , err
221
222
}
222
223
return & ethereum.SyncProgress {
223
- StartingBlock : progress .StartingBlock . Uint64 ( ),
224
- CurrentBlock : progress .CurrentBlock . Uint64 ( ),
225
- HighestBlock : progress .HighestBlock . Uint64 ( ),
226
- PulledStates : progress .PulledStates . Uint64 ( ),
227
- KnownStates : progress .KnownStates . Uint64 ( ),
224
+ StartingBlock : uint64 ( progress .StartingBlock ),
225
+ CurrentBlock : uint64 ( progress .CurrentBlock ),
226
+ HighestBlock : uint64 ( progress .HighestBlock ),
227
+ PulledStates : uint64 ( progress .PulledStates ),
228
+ KnownStates : uint64 ( progress .KnownStates ),
228
229
}, nil
229
230
}
230
231
@@ -239,33 +240,33 @@ func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header)
239
240
// BalanceAt returns the wei balance of the given account.
240
241
// The block number can be nil, in which case the balance is taken from the latest known block.
241
242
func (ec * Client ) BalanceAt (ctx context.Context , account common.Address , blockNumber * big.Int ) (* big.Int , error ) {
242
- var result rpc. HexNumber
243
+ var result hexutil. Big
243
244
err := ec .c .CallContext (ctx , & result , "eth_getBalance" , account , toBlockNumArg (blockNumber ))
244
245
return (* big .Int )(& result ), err
245
246
}
246
247
247
248
// StorageAt returns the value of key in the contract storage of the given account.
248
249
// The block number can be nil, in which case the value is taken from the latest known block.
249
250
func (ec * Client ) StorageAt (ctx context.Context , account common.Address , key common.Hash , blockNumber * big.Int ) ([]byte , error ) {
250
- var result rpc. HexBytes
251
+ var result hexutil. Bytes
251
252
err := ec .c .CallContext (ctx , & result , "eth_getStorageAt" , account , key , toBlockNumArg (blockNumber ))
252
253
return result , err
253
254
}
254
255
255
256
// CodeAt returns the contract code of the given account.
256
257
// The block number can be nil, in which case the code is taken from the latest known block.
257
258
func (ec * Client ) CodeAt (ctx context.Context , account common.Address , blockNumber * big.Int ) ([]byte , error ) {
258
- var result rpc. HexBytes
259
+ var result hexutil. Bytes
259
260
err := ec .c .CallContext (ctx , & result , "eth_getCode" , account , toBlockNumArg (blockNumber ))
260
261
return result , err
261
262
}
262
263
263
264
// NonceAt returns the account nonce of the given account.
264
265
// The block number can be nil, in which case the nonce is taken from the latest known block.
265
266
func (ec * Client ) NonceAt (ctx context.Context , account common.Address , blockNumber * big.Int ) (uint64 , error ) {
266
- var result rpc. HexNumber
267
+ var result hexutil. Uint64
267
268
err := ec .c .CallContext (ctx , & result , "eth_getTransactionCount" , account , toBlockNumArg (blockNumber ))
268
- return result . Uint64 ( ), err
269
+ return uint64 ( result ), err
269
270
}
270
271
271
272
// Filters
@@ -299,38 +300,38 @@ func toFilterArg(q ethereum.FilterQuery) interface{} {
299
300
300
301
// PendingBalanceAt returns the wei balance of the given account in the pending state.
301
302
func (ec * Client ) PendingBalanceAt (ctx context.Context , account common.Address ) (* big.Int , error ) {
302
- var result rpc. HexNumber
303
+ var result hexutil. Big
303
304
err := ec .c .CallContext (ctx , & result , "eth_getBalance" , account , "pending" )
304
305
return (* big .Int )(& result ), err
305
306
}
306
307
307
308
// PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
308
309
func (ec * Client ) PendingStorageAt (ctx context.Context , account common.Address , key common.Hash ) ([]byte , error ) {
309
- var result rpc. HexBytes
310
+ var result hexutil. Bytes
310
311
err := ec .c .CallContext (ctx , & result , "eth_getStorageAt" , account , key , "pending" )
311
312
return result , err
312
313
}
313
314
314
315
// PendingCodeAt returns the contract code of the given account in the pending state.
315
316
func (ec * Client ) PendingCodeAt (ctx context.Context , account common.Address ) ([]byte , error ) {
316
- var result rpc. HexBytes
317
+ var result hexutil. Bytes
317
318
err := ec .c .CallContext (ctx , & result , "eth_getCode" , account , "pending" )
318
319
return result , err
319
320
}
320
321
321
322
// PendingNonceAt returns the account nonce of the given account in the pending state.
322
323
// This is the nonce that should be used for the next transaction.
323
324
func (ec * Client ) PendingNonceAt (ctx context.Context , account common.Address ) (uint64 , error ) {
324
- var result rpc. HexNumber
325
+ var result hexutil. Uint64
325
326
err := ec .c .CallContext (ctx , & result , "eth_getTransactionCount" , account , "pending" )
326
- return result . Uint64 ( ), err
327
+ return uint64 ( result ), err
327
328
}
328
329
329
330
// PendingTransactionCount returns the total number of transactions in the pending state.
330
331
func (ec * Client ) PendingTransactionCount (ctx context.Context ) (uint , error ) {
331
- var num rpc. HexNumber
332
+ var num hexutil. Uint
332
333
err := ec .c .CallContext (ctx , & num , "eth_getBlockTransactionCountByNumber" , "pending" )
333
- return num . Uint ( ), err
334
+ return uint ( num ), err
334
335
}
335
336
336
337
// TODO: SubscribePendingTransactions (needs server side)
@@ -344,29 +345,29 @@ func (ec *Client) PendingTransactionCount(ctx context.Context) (uint, error) {
344
345
// case the code is taken from the latest known block. Note that state from very old
345
346
// blocks might not be available.
346
347
func (ec * Client ) CallContract (ctx context.Context , msg ethereum.CallMsg , blockNumber * big.Int ) ([]byte , error ) {
347
- var hex string
348
+ var hex hexutil. Bytes
348
349
err := ec .c .CallContext (ctx , & hex , "eth_call" , toCallArg (msg ), toBlockNumArg (blockNumber ))
349
350
if err != nil {
350
351
return nil , err
351
352
}
352
- return common . FromHex ( hex ) , nil
353
+ return hex , nil
353
354
}
354
355
355
356
// PendingCallContract executes a message call transaction using the EVM.
356
357
// The state seen by the contract call is the pending state.
357
358
func (ec * Client ) PendingCallContract (ctx context.Context , msg ethereum.CallMsg ) ([]byte , error ) {
358
- var hex string
359
+ var hex hexutil. Bytes
359
360
err := ec .c .CallContext (ctx , & hex , "eth_call" , toCallArg (msg ), "pending" )
360
361
if err != nil {
361
362
return nil , err
362
363
}
363
- return common . FromHex ( hex ) , nil
364
+ return hex , nil
364
365
}
365
366
366
367
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
367
368
// execution of a transaction.
368
369
func (ec * Client ) SuggestGasPrice (ctx context.Context ) (* big.Int , error ) {
369
- var hex rpc. HexNumber
370
+ var hex hexutil. Big
370
371
if err := ec .c .CallContext (ctx , & hex , "eth_gasPrice" ); err != nil {
371
372
return nil , err
372
373
}
@@ -378,7 +379,7 @@ func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
378
379
// the true gas limit requirement as other transactions may be added or removed by miners,
379
380
// but it should provide a basis for setting a reasonable default.
380
381
func (ec * Client ) EstimateGas (ctx context.Context , msg ethereum.CallMsg ) (* big.Int , error ) {
381
- var hex rpc. HexNumber
382
+ var hex hexutil. Big
382
383
err := ec .c .CallContext (ctx , & hex , "eth_estimateGas" , toCallArg (msg ))
383
384
if err != nil {
384
385
return nil , err
@@ -404,16 +405,16 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
404
405
"to" : msg .To ,
405
406
}
406
407
if len (msg .Data ) > 0 {
407
- arg ["data" ] = fmt . Sprintf ( "%#x" , msg .Data )
408
+ arg ["data" ] = hexutil . Bytes ( msg .Data )
408
409
}
409
410
if msg .Value != nil {
410
- arg ["value" ] = fmt . Sprintf ( "%#x" , msg .Value )
411
+ arg ["value" ] = ( * hexutil . Big )( msg .Value )
411
412
}
412
413
if msg .Gas != nil {
413
- arg ["gas" ] = fmt . Sprintf ( "%#x" , msg .Gas )
414
+ arg ["gas" ] = ( * hexutil . Big )( msg .Gas )
414
415
}
415
416
if msg .GasPrice != nil {
416
- arg ["gasPrice" ] = fmt . Sprintf ( "%#x" , msg .GasPrice )
417
+ arg ["gasPrice" ] = ( * hexutil . Big )( msg .GasPrice )
417
418
}
418
419
return arg
419
420
}
0 commit comments