From 1795bec928ce9e72d3ae1b3a9d1c159a48cda0ea Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 11:26:11 +0200 Subject: [PATCH 1/6] tried to fix --- internal/ethapi/api.go | 1 + internal/jsre/deps/web3.js | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index eaa743fe3473..fffbfcc6b4e8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1054,6 +1054,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) if blockNrOrHash != nil { + panic(blockNrOrHash) bNrOrHash = *blockNrOrHash } return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap()) diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index f1fe15d48d21..39c7622f08b7 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -4148,13 +4148,13 @@ SolidityFunction.prototype.sendTransaction = function () { SolidityFunction.prototype.estimateGas = function () { var args = Array.prototype.slice.call(arguments); var callback = this.extractCallback(args); + var defaultBlock = this.extractDefaultBlock(args); var payload = this.toPayload(args); if (!callback) { - return this._eth.estimateGas(payload); + return this._eth.estimateGas(payload, defaultBlock); } - - this._eth.estimateGas(payload, callback); + this._eth.estimateGas(payload, callback, defaultBlock); }; /** @@ -5396,8 +5396,8 @@ var methods = function () { var estimateGas = new Method({ name: 'estimateGas', call: 'eth_estimateGas', - params: 1, - inputFormatter: [formatters.inputCallFormatter], + params: 2, + inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter], outputFormatter: utils.toDecimal }); From 0c78bdf5ee3014718480067376ce75459f80bde2 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 11:43:38 +0200 Subject: [PATCH 2/6] fix for js api --- internal/ethapi/api.go | 1 - internal/jsre/deps/web3.js | 9 ++++----- internal/web3ext/web3ext.go | 7 +++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index fffbfcc6b4e8..eaa743fe3473 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1054,7 +1054,6 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) if blockNrOrHash != nil { - panic(blockNrOrHash) bNrOrHash = *blockNrOrHash } return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap()) diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 39c7622f08b7..4ac734fcca88 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -4148,13 +4148,12 @@ SolidityFunction.prototype.sendTransaction = function () { SolidityFunction.prototype.estimateGas = function () { var args = Array.prototype.slice.call(arguments); var callback = this.extractCallback(args); - var defaultBlock = this.extractDefaultBlock(args); var payload = this.toPayload(args); if (!callback) { - return this._eth.estimateGas(payload, defaultBlock); + return this._eth.estimateGas(payload); } - this._eth.estimateGas(payload, callback, defaultBlock); + this._eth.estimateGas(payload, callback); }; /** @@ -5396,8 +5395,8 @@ var methods = function () { var estimateGas = new Method({ name: 'estimateGas', call: 'eth_estimateGas', - params: 2, - inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter], + params: 1, + inputFormatter: [formatters.inputCallFormatter], outputFormatter: utils.toDecimal }); diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 300c2b054f38..6a9f14c65797 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.inputTransactionFormatter, web3._extend.formatters.inputBlockNumberFormatter], + outputFormatter: web3._extend.utils.toDecimal + }), new web3._extend.Method({ name: 'submitTransaction', call: 'eth_submitTransaction', From 78e44bee5071690058f2c072a14872c3d12bb1d7 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 11:46:41 +0200 Subject: [PATCH 3/6] fix for nil pointer ex --- internal/ethapi/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index eaa743fe3473..c7d1e0020f77 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. From bfa50dcc2b85aa5c75b802c3a3dca5b65b8f90c2 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 11:48:01 +0200 Subject: [PATCH 4/6] rev space --- internal/jsre/deps/web3.js | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 4ac734fcca88..510d07a664cf 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -4153,6 +4153,7 @@ SolidityFunction.prototype.estimateGas = function () { if (!callback) { return this._eth.estimateGas(payload); } + this._eth.estimateGas(payload, callback); }; From c23e72e48ede3332c4815b099a8ae3445c441962 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 11:48:39 +0200 Subject: [PATCH 5/6] rev space --- internal/jsre/deps/web3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 510d07a664cf..f1fe15d48d21 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -4153,7 +4153,7 @@ SolidityFunction.prototype.estimateGas = function () { if (!callback) { return this._eth.estimateGas(payload); } - + this._eth.estimateGas(payload, callback); }; From 8d559dd22e4ad02e3cfed180a144a34c1689b3a2 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 23 Sep 2020 11:53:13 +0200 Subject: [PATCH 6/6] input call formatter --- internal/web3ext/web3ext.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 6a9f14c65797..e2b8ad17188f 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -504,7 +504,7 @@ web3._extend({ name: 'estimateGas', call: 'eth_estimateGas', params: 2, - inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.formatters.inputBlockNumberFormatter], + inputFormatter: [web3._extend.formatters.inputCallFormatter, web3._extend.formatters.inputBlockNumberFormatter], outputFormatter: web3._extend.utils.toDecimal }), new web3._extend.Method({