aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/backends/remote.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-05-20 17:29:28 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-05-20 17:29:28 +0800
commit1580ec180414bce1e37acc614bc2445f778efb75 (patch)
tree7c8276f3f1558b5ce62edd0bff87745956084a4c /accounts/abi/bind/backends/remote.go
parente798e4fd750745cec99c5a531e42998d9a7be85e (diff)
downloadgo-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.tar
go-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.tar.gz
go-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.tar.bz2
go-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.tar.lz
go-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.tar.xz
go-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.tar.zst
go-tangerine-1580ec180414bce1e37acc614bc2445f778efb75.zip
accounts/abi/bind, eth: rely on getCode for sanity checks, not estimate and call
Diffstat (limited to 'accounts/abi/bind/backends/remote.go')
-rw-r--r--accounts/abi/bind/backends/remote.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/accounts/abi/bind/backends/remote.go b/accounts/abi/bind/backends/remote.go
index 9b3647192..d903cbc8f 100644
--- a/accounts/abi/bind/backends/remote.go
+++ b/accounts/abi/bind/backends/remote.go
@@ -111,6 +111,26 @@ func (b *rpcBackend) request(method string, params []interface{}) (json.RawMessa
return res.Result, nil
}
+// HasCode implements ContractVerifier.HasCode by retrieving any code associated
+// with the contract from the remote node, and checking its size.
+func (b *rpcBackend) HasCode(contract common.Address, pending bool) (bool, error) {
+ // Execute the RPC code retrieval
+ block := "latest"
+ if pending {
+ block = "pending"
+ }
+ res, err := b.request("eth_getCode", []interface{}{contract.Hex(), block})
+ if err != nil {
+ return false, err
+ }
+ var hex string
+ if err := json.Unmarshal(res, &hex); err != nil {
+ return false, err
+ }
+ // Convert the response back to a Go byte slice and return
+ return len(common.FromHex(hex)) > 0, nil
+}
+
// ContractCall implements ContractCaller.ContractCall, delegating the execution of
// a contract call to the remote node, returning the reply to for local processing.
func (b *rpcBackend) ContractCall(contract common.Address, data []byte, pending bool) ([]byte, error) {