mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
Merge 9417a681bc into f7ca03ae87
This commit is contained in:
commit
24b42c2a95
2 changed files with 17 additions and 16 deletions
|
|
@ -189,22 +189,23 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gasLimit := opts.GasLimit
|
gasLimit := opts.GasLimit
|
||||||
if gasLimit == nil {
|
// Gas estimation cannot succeed without code for method invocations
|
||||||
// Gas estimation cannot succeed without code for method invocations
|
if contract != nil {
|
||||||
if contract != nil {
|
if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil {
|
||||||
if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil {
|
return nil, err
|
||||||
return nil, err
|
} else if len(code) == 0 {
|
||||||
} else if len(code) == 0 {
|
return nil, ErrNoCode
|
||||||
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 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
|
// Create the transaction, sign it and schedule it for execution
|
||||||
var rawTx *types.Transaction
|
var rawTx *types.Transaction
|
||||||
if contract == nil {
|
if contract == nil {
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ func NewClient(c *rpc.Client) *Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version returns the Whisper sub-protocol version.
|
// Version returns the Whisper sub-protocol version.
|
||||||
func (sc *Client) Version(ctx context.Context) (string, error) {
|
func (sc *Client) Version(ctx context.Context) (uint, error) {
|
||||||
var result string
|
var result uint
|
||||||
err := sc.c.CallContext(ctx, &result, "shh_version")
|
err := sc.c.CallContext(ctx, &result, "shh_version")
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue