good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
40974788
Commit
40974788
authored
Apr 1, 2016
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
accounts/abi/bind: surface raw wrappers to access low level ops
parent
10d3466c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
accounts/abi/bind/base.go
+7
-2
7 additions, 2 deletions
accounts/abi/bind/base.go
accounts/abi/bind/bind_test.go
+42
-3
42 additions, 3 deletions
accounts/abi/bind/bind_test.go
accounts/abi/bind/template.go
+53
-0
53 additions, 0 deletions
accounts/abi/bind/template.go
with
102 additions
and
5 deletions
accounts/abi/bind/base.go
+
7
−
2
View file @
40974788
...
@@ -108,8 +108,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
...
@@ -108,8 +108,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
return
c
.
abi
.
Unpack
(
result
,
method
,
output
)
return
c
.
abi
.
Unpack
(
result
,
method
,
output
)
}
}
// Transact invokes the (paid) contract method with params as input values and
// Transact invokes the (paid) contract method with params as input values.
// value as the fund transfer to the contract.
func
(
c
*
BoundContract
)
Transact
(
opts
*
TransactOpts
,
method
string
,
params
...
interface
{})
(
*
types
.
Transaction
,
error
)
{
func
(
c
*
BoundContract
)
Transact
(
opts
*
TransactOpts
,
method
string
,
params
...
interface
{})
(
*
types
.
Transaction
,
error
)
{
// Otherwise pack up the parameters and invoke the contract
// Otherwise pack up the parameters and invoke the contract
input
,
err
:=
c
.
abi
.
Pack
(
method
,
params
...
)
input
,
err
:=
c
.
abi
.
Pack
(
method
,
params
...
)
...
@@ -119,6 +118,12 @@ func (c *BoundContract) Transact(opts *TransactOpts, method string, params ...in
...
@@ -119,6 +118,12 @@ func (c *BoundContract) Transact(opts *TransactOpts, method string, params ...in
return
c
.
transact
(
opts
,
&
c
.
address
,
input
)
return
c
.
transact
(
opts
,
&
c
.
address
,
input
)
}
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func
(
c
*
BoundContract
)
Transfer
(
opts
*
TransactOpts
)
(
*
types
.
Transaction
,
error
)
{
return
c
.
transact
(
opts
,
&
c
.
address
,
nil
)
}
// transact executes an actual transaction invocation, first deriving any missing
// transact executes an actual transaction invocation, first deriving any missing
// authorization fields, and then scheduling the transaction for execution.
// authorization fields, and then scheduling the transaction for execution.
func
(
c
*
BoundContract
)
transact
(
opts
*
TransactOpts
,
contract
*
common
.
Address
,
input
[]
byte
)
(
*
types
.
Transaction
,
error
)
{
func
(
c
*
BoundContract
)
transact
(
opts
*
TransactOpts
,
contract
*
common
.
Address
,
input
[]
byte
)
(
*
types
.
Transaction
,
error
)
{
...
...
This diff is collapsed.
Click to expand it.
accounts/abi/bind/bind_test.go
+
42
−
3
View file @
40974788
...
@@ -228,6 +228,45 @@ var bindTests = []struct {
...
@@ -228,6 +228,45 @@ var bindTests = []struct {
}
}
`
,
`
,
},
},
// Tests that anonymous default methods can be correctly invoked
{
`Defaulter`
,
`
contract Defaulter {
address public caller;
function() {
caller = msg.sender;
}
}
`
,
`6060604052606a8060106000396000f360606040523615601d5760e060020a6000350463fc9c8d3981146040575b605e6000805473ffffffffffffffffffffffffffffffffffffffff191633179055565b606060005473ffffffffffffffffffffffffffffffffffffffff1681565b005b6060908152602090f3`
,
`[{"constant":true,"inputs":[],"name":"caller","outputs":[{"name":"","type":"address"}],"type":"function"}]`
,
`
// Generate a new random account and a funded simulator
key := crypto.NewKey(rand.Reader)
sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: key.Address, Balance: big.NewInt(10000000000)})
// Convert the tester key to an authorized transactor for ease of use
auth := bind.NewKeyedTransactor(key)
// Deploy a default method invoker contract and execute its default method
_, _, defaulter, err := DeployDefaulter(auth, sim)
if err != nil {
t.Fatalf("Failed to deploy defaulter contract: %v", err)
}
if _, err := (&DefaulterRaw{defaulter}).Transfer(auth); err != nil {
t.Fatalf("Failed to invoke default method: %v", err)
}
sim.Commit()
if caller, err := defaulter.Caller(nil); err != nil {
t.Fatalf("Failed to call address retriever: %v", err)
} else if (caller != key.Address) {
t.Fatalf("Address mismatch: have %v, want %v", caller, key.Address)
}
`
,
},
}
}
// Tests that packages generated by the binder can be successfully compiled and
// Tests that packages generated by the binder can be successfully compiled and
...
...
This diff is collapsed.
Click to expand it.
accounts/abi/bind/template.go
+
53
−
0
View file @
40974788
...
@@ -110,6 +110,21 @@ package {{.Package}}
...
@@ -110,6 +110,21 @@ package {{.Package}}
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
}
// {{.Type}}Raw is an auto generated low-level Go binding around an Ethereum contract.
type {{.Type}}Raw struct {
Contract *{{.Type}} // Generic contract binding to access the raw methods on
}
// {{.Type}}CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type {{.Type}}CallerRaw struct {
Contract *{{.Type}}Caller // Generic read-only contract binding to access the raw methods on
}
// {{.Type}}TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type {{.Type}}TransactorRaw struct {
Contract *{{.Type}}Transactor // Generic write-only contract binding to access the raw methods on
}
// New{{.Type}} creates a new instance of {{.Type}}, bound to a specific deployed contract.
// New{{.Type}} creates a new instance of {{.Type}}, bound to a specific deployed contract.
func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) {
func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) {
contract, err := bind{{.Type}}(address, backend.(bind.ContractCaller), backend.(bind.ContractTransactor))
contract, err := bind{{.Type}}(address, backend.(bind.ContractCaller), backend.(bind.ContractTransactor))
...
@@ -146,6 +161,44 @@ package {{.Package}}
...
@@ -146,6 +161,44 @@ package {{.Package}}
return bind.NewBoundContract(address, parsed, caller, transactor), nil
return bind.NewBoundContract(address, parsed, caller, transactor), nil
}
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_{{$contract.Type}} *{{$contract.Type}}Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact(opts, method, params...)
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_{{$contract.Type}} *{{$contract.Type}}CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _{{$contract.Type}}.Contract.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.contract.Transact(opts, method, params...)
}
{{range .Calls}}
{{range .Calls}}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
//
//
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment