aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/backends
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-04-27 21:29:13 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-04-27 22:15:23 +0800
commitcdcbb2f16014077597e5901c0f328920c904409e (patch)
treec0b750618d97a278f73ccfd7bbf380b40f1d3a0f /accounts/abi/bind/backends
parentdb62979514c69574aefdcf8c2ed9099aa0cd1abe (diff)
downloadgo-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.tar
go-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.tar.gz
go-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.tar.bz2
go-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.tar.lz
go-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.tar.xz
go-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.tar.zst
go-tangerine-cdcbb2f16014077597e5901c0f328920c904409e.zip
accounts/abi/bind, eth: add contract non-existent error
Diffstat (limited to 'accounts/abi/bind/backends')
-rw-r--r--accounts/abi/bind/backends/remote.go15
-rw-r--r--accounts/abi/bind/backends/simulated.go11
2 files changed, 22 insertions, 4 deletions
diff --git a/accounts/abi/bind/backends/remote.go b/accounts/abi/bind/backends/remote.go
index 8e990f076..9b3647192 100644
--- a/accounts/abi/bind/backends/remote.go
+++ b/accounts/abi/bind/backends/remote.go
@@ -66,10 +66,16 @@ type request struct {
type response struct {
JSONRPC string `json:"jsonrpc"` // Version of the JSON RPC protocol, always set to 2.0
ID int `json:"id"` // Auto incrementing ID number for this request
- Error json.RawMessage `json:"error"` // Any error returned by the remote side
+ Error *failure `json:"error"` // Any error returned by the remote side
Result json.RawMessage `json:"result"` // Whatever the remote side sends us in reply
}
+// failure is a JSON RPC response error field sent back from the API server.
+type failure struct {
+ Code int `json:"code"` // JSON RPC error code associated with the failure
+ Message string `json:"message"` // Specific error message of the failure
+}
+
// request forwards an API request to the RPC server, and parses the response.
//
// This is currently painfully non-concurrent, but it will have to do until we
@@ -96,8 +102,11 @@ func (b *rpcBackend) request(method string, params []interface{}) (json.RawMessa
if err := b.client.Recv(res); err != nil {
return nil, err
}
- if len(res.Error) > 0 {
- return nil, fmt.Errorf("remote error: %s", string(res.Error))
+ if res.Error != nil {
+ if res.Error.Message == bind.ErrNoCode.Error() {
+ return nil, bind.ErrNoCode
+ }
+ return nil, fmt.Errorf("remote error: %s", res.Error.Message)
}
return res.Result, nil
}
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go
index 6cdb9a0cc..4866c4f58 100644
--- a/accounts/abi/bind/backends/simulated.go
+++ b/accounts/abi/bind/backends/simulated.go
@@ -92,6 +92,10 @@ func (b *SimulatedBackend) ContractCall(contract common.Address, data []byte, pe
block = b.blockchain.CurrentBlock()
statedb, _ = b.blockchain.State()
}
+ // If there's no code to interact with, respond with an appropriate error
+ if code := statedb.GetCode(contract); len(code) == 0 {
+ return nil, bind.ErrNoCode
+ }
// Set infinite balance to the a fake caller account
from := statedb.GetOrNewStateObject(common.Address{})
from.SetBalance(common.MaxBig)
@@ -134,7 +138,12 @@ func (b *SimulatedBackend) EstimateGasLimit(sender common.Address, contract *com
block = b.pendingBlock
statedb = b.pendingState.Copy()
)
-
+ // If there's no code to interact with, respond with an appropriate error
+ if contract != nil {
+ if code := statedb.GetCode(*contract); len(code) == 0 {
+ return nil, bind.ErrNoCode
+ }
+ }
// Set infinite balance to the a fake caller account
from := statedb.GetOrNewStateObject(sender)
from.SetBalance(common.MaxBig)