Skip to content

Commit e035171

Browse files
Fix 'all defaults' case for eth_estimateGas (#3790) (#3824)
* Fix 'all defaults' case for eth_estimateGas * fix tests Co-authored-by: Igor Mandrigin <i@mandrigin.ru> Co-authored-by: Igor Mandrigin <mandrigin@users.noreply.github.com> Co-authored-by: Igor Mandrigin <i@mandrigin.ru>
1 parent 59cd45b commit e035171

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cmd/rpcdaemon/commands/eth_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type EthAPI interface {
7575

7676
// Sending related (see ./eth_call.go)
7777
Call(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *ethapi.StateOverrides) (hexutil.Bytes, error)
78-
EstimateGas(ctx context.Context, args ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error)
78+
EstimateGas(ctx context.Context, argsOrNil *ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error)
7979
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
8080
SendTransaction(_ context.Context, txObject interface{}) (common.Hash, error)
8181
Sign(ctx context.Context, _ common.Address, _ hexutil.Bytes) (hexutil.Bytes, error)

cmd/rpcdaemon/commands/eth_call.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ func HeaderByNumberOrHash(ctx context.Context, tx kv.Tx, blockNrOrHash rpc.Block
113113
}
114114

115115
// EstimateGas implements eth_estimateGas. Returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain.
116-
func (api *APIImpl) EstimateGas(ctx context.Context, args ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) {
116+
func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) {
117+
var args ethapi.CallArgs
118+
// if we actually get CallArgs here, we use them
119+
if argsOrNil != nil {
120+
args = *argsOrNil
121+
}
122+
117123
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
118124
if blockNrOrHash != nil {
119125
bNrOrHash = *blockNrOrHash

cmd/rpcdaemon/commands/eth_call_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestEstimateGas(t *testing.T) {
1919
api := NewEthAPI(NewBaseApi(nil, stateCache, false), db, nil, nil, nil, 5000000)
2020
var from = common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")
2121
var to = common.HexToAddress("0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e")
22-
if _, err := api.EstimateGas(context.Background(), ethapi.CallArgs{
22+
if _, err := api.EstimateGas(context.Background(), &ethapi.CallArgs{
2323
From: &from,
2424
To: &to,
2525
}, nil); err != nil {

0 commit comments

Comments
 (0)