ソースを参照

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
Marius van der Wijden 5 年 前
コミット
d1f95d5fd3
2 ファイル変更10 行追加0 行削除
  1. 3 0
      internal/ethapi/api.go
  2. 7 0
      internal/web3ext/web3ext.go

+ 3 - 0
internal/ethapi/api.go

@@ -900,6 +900,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.

+ 7 - 0
internal/web3ext/web3ext.go

@@ -493,6 +493,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',