@@ -284,16 +284,16 @@ func parseLogRequest(in gjson.Result) (*filterObject, error) {
284
284
}
285
285
286
286
type callMsg struct {
287
- From address.Address // the sender of the 'transaction'
288
- To string // the destination contract (empty for contract creation)
289
- Gas uint64 // if 0, the call executes with near-infinite gas
290
- GasPrice * big.Int // wei <-> gas exchange ratio
291
- GasFeeCap * big.Int // EIP-1559 fee cap per gas.
292
- GasTipCap * big.Int // EIP-1559 tip per gas.
293
- Value * big.Int // amount of wei sent along with the call
294
- Data []byte // input data, usually an ABI-encoded contract method invocation
295
- AccessList types.AccessList // EIP-2930 access list.
296
- BlockNumber rpc.BlockNumber
287
+ From address.Address // the sender of the 'transaction'
288
+ To string // the destination contract (empty for contract creation)
289
+ Gas uint64 // if 0, the call executes with near-infinite gas
290
+ GasPrice * big.Int // wei <-> gas exchange ratio
291
+ GasFeeCap * big.Int // EIP-1559 fee cap per gas.
292
+ GasTipCap * big.Int // EIP-1559 tip per gas.
293
+ Value * big.Int // amount of wei sent along with the call
294
+ Data []byte // input data, usually an ABI-encoded contract method invocation
295
+ AccessList types.AccessList // EIP-2930 access list.
296
+ BlockNumberOrHash rpc.BlockNumberOrHash // EIP-1898
297
297
}
298
298
299
299
func parseCallObject (in * gjson.Result ) (* callMsg , error ) {
@@ -307,7 +307,7 @@ func parseCallObject(in *gjson.Result) (*callMsg, error) {
307
307
value * big.Int = big .NewInt (0 )
308
308
data []byte
309
309
acl types.AccessList
310
- bn = rpc .LatestBlockNumber
310
+ bn = rpc .BlockNumberOrHashWithNumber ( rpc . LatestBlockNumber )
311
311
err error
312
312
)
313
313
fromStr := in .Get ("params.0.from" ).String ()
@@ -378,24 +378,25 @@ func parseCallObject(in *gjson.Result) (*callMsg, error) {
378
378
}
379
379
}
380
380
if bnParam := in .Get ("params.1" ); bnParam .Exists () {
381
- if err = bn .UnmarshalJSON ([]byte (bnParam .String () )); err != nil {
381
+ if err = bn .UnmarshalJSON ([]byte (bnParam .Raw )); err != nil {
382
382
return nil , errors .Wrapf (err , "failed to unmarshal height %s" , bnParam .String ())
383
383
}
384
384
}
385
385
return & callMsg {
386
- From : from ,
387
- To : to ,
388
- Gas : gasLimit ,
389
- GasPrice : gasPrice ,
390
- GasFeeCap : gasFeeCap ,
391
- GasTipCap : gasTipCap ,
392
- Value : value ,
393
- Data : data ,
394
- AccessList : acl ,
395
- BlockNumber : bn ,
386
+ From : from ,
387
+ To : to ,
388
+ Gas : gasLimit ,
389
+ GasPrice : gasPrice ,
390
+ GasFeeCap : gasFeeCap ,
391
+ GasTipCap : gasTipCap ,
392
+ Value : value ,
393
+ Data : data ,
394
+ AccessList : acl ,
395
+ BlockNumberOrHash : bn ,
396
396
}, nil
397
397
}
398
398
399
+ // TODO: fix this to support eip 1898
399
400
func parseBlockNumber (in * gjson.Result ) (rpc.BlockNumber , error ) {
400
401
if ! in .Exists () {
401
402
return rpc .LatestBlockNumber , nil
@@ -407,14 +408,23 @@ func parseBlockNumber(in *gjson.Result) (rpc.BlockNumber, error) {
407
408
return height , nil
408
409
}
409
410
410
- func blockNumberToHeight (bn rpc.BlockNumber ) (uint64 , bool ) {
411
- switch bn {
411
+ func (svr * web3Handler ) blockNumberOrHashToHeight (bn rpc.BlockNumberOrHash ) (uint64 , bool , error ) {
412
+ if bn .BlockHash != nil {
413
+ bh := (* bn .BlockHash ).String ()
414
+ blk , err := svr .coreService .BlockByHash (util .Remove0xPrefix (bh ))
415
+ if err != nil {
416
+ return 0 , false , errors .Wrapf (err , "failed to get block height by hash %s" , bh )
417
+ }
418
+ return uint64 (blk .Block .Height ()), true , nil
419
+ }
420
+
421
+ switch * bn .BlockNumber {
412
422
case rpc .SafeBlockNumber , rpc .FinalizedBlockNumber , rpc .LatestBlockNumber , rpc .PendingBlockNumber :
413
- return 0 , false
423
+ return 0 , false , nil
414
424
case rpc .EarliestBlockNumber :
415
- return 1 , true
425
+ return 1 , true , nil
416
426
default :
417
- return uint64 (bn ), true
427
+ return uint64 (* bn . BlockNumber ), true , nil
418
428
}
419
429
}
420
430
0 commit comments