From c1544423d655f540b55bb6ec0e7167dad9683c42 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 13:08:40 +0200 Subject: [PATCH] internal/ethapi: fix nil deref + fix estimateGas console bindings (#21601) * tried to fix * fix for js api * fix for nil pointer ex * rev space * rev space * input call formatter --- internal/ethapi/api.go | 3 +++ internal/web3ext/web3ext.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index eaa743fe3..c7d1e0020 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -963,6 +963,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash if err != nil { return 0, err } + if block == nil { + return 0, errors.New("block not found") + } hi = block.GasLimit() } // Recap the highest gas limit with account's available balance. diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 300c2b054..e2b8ad171 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -500,6 +500,13 @@ web3._extend({ params: 1, inputFormatter: [web3._extend.formatters.inputTransactionFormatter] }), + new web3._extend.Method({ + name: 'estimateGas', + call: 'eth_estimateGas', + params: 2, + inputFormatter: [web3._extend.formatters.inputCallFormatter, web3._extend.formatters.inputBlockNumberFormatter], + outputFormatter: web3._extend.utils.toDecimal + }), new web3._extend.Method({ name: 'submitTransaction', call: 'eth_submitTransaction',