diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-05-20 21:13:29 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-05-20 21:13:29 +0800 |
commit | 847aaffbb8748e6b4d5cff106c809ace35bbc815 (patch) | |
tree | a32f6725a16fef663b2e222c00f873e5164fe9dc /eth | |
parent | a8472e0fdbb4ac157671ba3bcc79001674d582d2 (diff) | |
parent | 1580ec180414bce1e37acc614bc2445f778efb75 (diff) | |
download | go-tangerine-847aaffbb8748e6b4d5cff106c809ace35bbc815.tar.gz go-tangerine-847aaffbb8748e6b4d5cff106c809ace35bbc815.tar.zst go-tangerine-847aaffbb8748e6b4d5cff106c809ace35bbc815.zip |
Merge pull request #2589 from karalabe/estimate-remove-codecheck
accounts/abi/bind, eth: rely on getCode for sanity checks, not estimate and call
Diffstat (limited to 'eth')
-rw-r--r-- | eth/api.go | 15 | ||||
-rw-r--r-- | eth/bind.go | 18 |
2 files changed, 11 insertions, 22 deletions
diff --git a/eth/api.go b/eth/api.go index c8ccbd51b..8203424ae 100644 --- a/eth/api.go +++ b/eth/api.go @@ -52,15 +52,6 @@ import ( "golang.org/x/net/context" ) -// errNoCode is returned by call and transact operations for which the requested -// recipient contract to operate on does not exist in the state db or does not -// have any code associated with it (i.e. suicided). -// -// Please note, this error string is part of the RPC API and is expected by the -// native contract bindings to signal this particular error. Do not change this -// as it will break all dependent code! -var errNoCode = errors.New("no contract code at given address") - const defaultGas = uint64(90000) // blockByNumber is a commonly used helper function which retrieves and returns @@ -717,12 +708,6 @@ func (s *PublicBlockChainAPI) doCall(args CallArgs, blockNr rpc.BlockNumber) (st } stateDb = stateDb.Copy() - // If there's no code to interact with, respond with an appropriate error - if args.To != nil { - if code := stateDb.GetCode(*args.To); len(code) == 0 { - return "0x", nil, errNoCode - } - } // Retrieve the account state object to interact with var from *state.StateObject if args.From == (common.Address{}) { diff --git a/eth/bind.go b/eth/bind.go index 3a3eca062..fb7f29f60 100644 --- a/eth/bind.go +++ b/eth/bind.go @@ -19,7 +19,6 @@ package eth import ( "math/big" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" @@ -49,6 +48,17 @@ func NewContractBackend(eth *Ethereum) *ContractBackend { } } +// HasCode implements bind.ContractVerifier.HasCode by retrieving any code associated +// with the contract from the local API, and checking its size. +func (b *ContractBackend) HasCode(contract common.Address, pending bool) (bool, error) { + block := rpc.LatestBlockNumber + if pending { + block = rpc.PendingBlockNumber + } + out, err := b.bcapi.GetCode(contract, block) + return len(common.FromHex(out)) > 0, err +} + // ContractCall implements bind.ContractCaller executing an Ethereum contract // call with the specified data as the input. The pending flag requests execution // against the pending block, not the stable head of the chain. @@ -64,9 +74,6 @@ func (b *ContractBackend) ContractCall(contract common.Address, data []byte, pen } // Execute the call and convert the output back to Go types out, err := b.bcapi.Call(args, block) - if err == errNoCode { - err = bind.ErrNoCode - } return common.FromHex(out), err } @@ -95,9 +102,6 @@ func (b *ContractBackend) EstimateGasLimit(sender common.Address, contract *comm Value: *rpc.NewHexNumber(value), Data: common.ToHex(data), }) - if err == errNoCode { - err = bind.ErrNoCode - } return out.BigInt(), err } |