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
6d038e76
Commit
6d038e76
authored
Mar 16, 2017
by
Bas van Kervel
Committed by
Felix Lange
Mar 16, 2017
Browse files
Options
Downloads
Patches
Plain Diff
accounts/abi/bind: allow client to specify sender address for call (#3782)
parent
4e4e5fca
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
accounts/abi/bind/base.go
+3
-2
3 additions, 2 deletions
accounts/abi/bind/base.go
accounts/abi/bind/bind_test.go
+39
-0
39 additions, 0 deletions
accounts/abi/bind/bind_test.go
with
42 additions
and
2 deletions
accounts/abi/bind/base.go
+
3
−
2
View file @
6d038e76
...
@@ -36,6 +36,7 @@ type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Tra
...
@@ -36,6 +36,7 @@ type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Tra
// CallOpts is the collection of options to fine tune a contract call request.
// CallOpts is the collection of options to fine tune a contract call request.
type
CallOpts
struct
{
type
CallOpts
struct
{
Pending
bool
// Whether to operate on the pending state or the last known one
Pending
bool
// Whether to operate on the pending state or the last known one
From
common
.
Address
// Optional the sender address, otherwise the first account is used
Context
context
.
Context
// Network context to support cancellation and timeouts (nil = no timeout)
Context
context
.
Context
// Network context to support cancellation and timeouts (nil = no timeout)
}
}
...
@@ -108,7 +109,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
...
@@ -108,7 +109,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
return
err
return
err
}
}
var
(
var
(
msg
=
ethereum
.
CallMsg
{
To
:
&
c
.
address
,
Data
:
input
}
msg
=
ethereum
.
CallMsg
{
From
:
opts
.
From
,
To
:
&
c
.
address
,
Data
:
input
}
ctx
=
ensureContext
(
opts
.
Context
)
ctx
=
ensureContext
(
opts
.
Context
)
code
[]
byte
code
[]
byte
output
[]
byte
output
[]
byte
...
...
This diff is collapsed.
Click to expand it.
accounts/abi/bind/bind_test.go
+
39
−
0
View file @
6d038e76
...
@@ -408,6 +408,45 @@ var bindTests = []struct {
...
@@ -408,6 +408,45 @@ var bindTests = []struct {
}
}
`
,
`
,
},
},
// Test that constant functions can be called from an (optional) specified address
{
`CallFrom`
,
`
contract CallFrom {
function callFrom() constant returns(address) {
return msg.sender;
}
}
`
,
`6060604052346000575b6086806100176000396000f300606060405263ffffffff60e060020a60003504166349f8e98281146022575b6000565b34600057602c6055565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b335b905600a165627a7a72305820aef6b7685c0fa24ba6027e4870404a57df701473fe4107741805c19f5138417c0029`
,
`[{"constant":true,"inputs":[],"name":"callFrom","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"}]`
,
`
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: auth.From, Balance: big.NewInt(10000000000)})
// Deploy a sender tester contract and execute a structured call on it
_, _, callfrom, err := DeployCallFrom(auth, sim)
if err != nil {
t.Fatalf("Failed to deploy sender contract: %v", err)
}
sim.Commit()
if res, err := callfrom.CallFrom(nil); err != nil {
t.Errorf("Failed to call constant function: %v", err)
} else if res != (common.Address{}) {
t.Errorf("Invalid address returned, want: %x, got: %x", (common.Address{}), res)
}
for _, addr := range []common.Address{common.Address{}, common.Address{1}, common.Address{2}} {
if res, err := callfrom.CallFrom(&bind.CallOpts{From: addr}); err != nil {
t.Fatalf("Failed to call constant function: %v", err)
} else if res != addr {
t.Fatalf("Invalid address returned, want: %x, got: %x", addr, res)
}
}
`
,
},
}
}
// 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.
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