Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
123aa659
Commit
123aa659
authored
Apr 27, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2496 from karalabe/abibind-missing-contract-error
accounts/abi/bind, eth: add contract non-existent error
parents
db629795
cdcbb2f1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
4 deletions
+75
-4
backend.go
accounts/abi/bind/backend.go
+10
-0
remote.go
accounts/abi/bind/backends/remote.go
+12
-3
simulated.go
accounts/abi/bind/backends/simulated.go
+10
-1
bind_test.go
accounts/abi/bind/bind_test.go
+28
-0
api.go
eth/api.go
+15
-0
No files found.
accounts/abi/bind/backend.go
View file @
123aa659
...
...
@@ -17,12 +17,22 @@
package
bind
import
(
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// 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"
)
// ContractCaller defines the methods needed to allow operating with contract on a read
// only basis.
type
ContractCaller
interface
{
...
...
accounts/abi/bind/backends/remote.go
View file @
123aa659
...
...
@@ -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
}
...
...
accounts/abi/bind/backends/simulated.go
View file @
123aa659
...
...
@@ -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
)
...
...
accounts/abi/bind/bind_test.go
View file @
123aa659
...
...
@@ -303,6 +303,34 @@ var bindTests = []struct {
}
`
,
},
// Tests that non-existent contracts are reported as such (though only simulator test)
{
`NonExistent`
,
`
contract NonExistent {
function String() constant returns(string) {
return "I don't exist";
}
}
`
,
`6060604052609f8060106000396000f3606060405260e060020a6000350463f97a60058114601a575b005b600060605260c0604052600d60809081527f4920646f6e27742065786973740000000000000000000000000000000000000060a052602060c0908152600d60e081905281906101009060a09080838184600060046012f15050815172ffffffffffffffffffffffffffffffffffffff1916909152505060405161012081900392509050f3`
,
`[{"constant":true,"inputs":[],"name":"String","outputs":[{"name":"","type":"string"}],"type":"function"}]`
,
`
// Create a simulator and wrap a non-deployed contract
sim := backends.NewSimulatedBackend()
nonexistent, err := NewNonExistent(common.Address{}, sim)
if err != nil {
t.Fatalf("Failed to access non-existent contract: %v", err)
}
// Ensure that contract calls fail with the appropriate error
if res, err := nonexistent.String(nil); err == nil {
t.Fatalf("Call succeeded on non-existent contract: %v", res)
} else if (err != bind.ErrNoCode) {
t.Fatalf("Error mismatch: have %v, want %v", err, bind.ErrNoCode)
}
`
,
},
}
// Tests that packages generated by the binder can be successfully compiled and
...
...
eth/api.go
View file @
123aa659
...
...
@@ -51,6 +51,15 @@ 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
...
...
@@ -694,6 +703,12 @@ 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
{})
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment