From c6f3a7dfec6012dbf54e79efa5c761c0c59ba7db Mon Sep 17 00:00:00 2001 From: nkbai Date: Mon, 16 Oct 2017 10:44:41 +0800 Subject: [PATCH 1/2] whisper/shhclient: Api Version's return type should be string --- whisper/shhclient/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/whisper/shhclient/client.go b/whisper/shhclient/client.go index 61c1b7ab72..61b4775d95 100644 --- a/whisper/shhclient/client.go +++ b/whisper/shhclient/client.go @@ -45,8 +45,8 @@ func NewClient(c *rpc.Client) *Client { } // Version returns the Whisper sub-protocol version. -func (sc *Client) Version(ctx context.Context) (uint, error) { - var result uint +func (sc *Client) Version(ctx context.Context) (string, error) { + var result string err := sc.c.CallContext(ctx, &result, "shh_version") return result, err } From 9417a681bc63960fc172a51fdd3151a9f5646278 Mon Sep 17 00:00:00 2001 From: nkbai Date: Thu, 28 Dec 2017 09:00:20 +0800 Subject: [PATCH 2/2] accounts/abi: estimateGas before send transaction --- accounts/abi/bind/base.go | 29 +++++++++++++++-------------- whisper/shhclient/client.go | 4 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index b40bd65e80..3db0ab66b4 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -189,22 +189,23 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i } } gasLimit := opts.GasLimit - if gasLimit == nil { - // Gas estimation cannot succeed without code for method invocations - if contract != nil { - if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil { - return nil, err - } else if len(code) == 0 { - return nil, ErrNoCode - } - } - // If the contract surely has code (or code is not needed), estimate the transaction - msg := ethereum.CallMsg{From: opts.From, To: contract, Value: value, Data: input} - gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg) - if err != nil { - return nil, fmt.Errorf("failed to estimate gas needed: %v", err) + // Gas estimation cannot succeed without code for method invocations + if contract != nil { + if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil { + return nil, err + } else if len(code) == 0 { + return nil, ErrNoCode } } + // If the contract surely has code (or code is not needed), estimate the transaction + msg := ethereum.CallMsg{From: opts.From, To: contract, Value: value, Data: input} + gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg) + if err != nil { + return nil, fmt.Errorf("failed to estimate gas needed: %v", err) + } + if opts.GasLimit != nil && opts.GasLimit.Cmp(gasLimit) < 0 { + return nil, fmt.Errorf("Gas required is %s, it exceeds limit: %s. An important gas estimation might also be the sign of a problem in the contract code", gasLimit, opts.GasLimit) + } // Create the transaction, sign it and schedule it for execution var rawTx *types.Transaction if contract == nil { diff --git a/whisper/shhclient/client.go b/whisper/shhclient/client.go index 61b4775d95..61c1b7ab72 100644 --- a/whisper/shhclient/client.go +++ b/whisper/shhclient/client.go @@ -45,8 +45,8 @@ func NewClient(c *rpc.Client) *Client { } // Version returns the Whisper sub-protocol version. -func (sc *Client) Version(ctx context.Context) (string, error) { - var result string +func (sc *Client) Version(ctx context.Context) (uint, error) { + var result uint err := sc.c.CallContext(ctx, &result, "shh_version") return result, err }