Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABIGEN v2 #26782

Open
wants to merge 104 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
0830ae4
accounts/abi: abigen v2
s1na Jan 6, 2023
7024b98
add copyright header to lib.go
s1na Mar 1, 2023
cf6d5ad
drop unnecessary imports
s1na Mar 1, 2023
8ad40f7
replace fmt with errors
s1na Mar 1, 2023
33560ae
drop fmt
s1na Mar 1, 2023
6b37f7a
skip unpack method when no return args
s1na Mar 1, 2023
1da0b78
define contract instance type
s1na Mar 1, 2023
1850e4a
Add deploy code to contract struct
s1na Mar 2, 2023
4611b5c
Pass pointer to log for unpack
s1na Mar 2, 2023
a31d191
clean lang selection leftovers
s1na Mar 2, 2023
2cdb4cc
fix test
s1na Mar 3, 2023
fe2c5b3
add back code that got mistakenly removed in the rebase
jwasinger Oct 31, 2024
6b8e25e
fix last rebase regression
jwasinger Oct 31, 2024
fc97915
isolate V2 contract interaction API into its own package
jwasinger Nov 4, 2024
cbdec2a
move v2 contract interaction methods into v2 package. add test
jwasinger Nov 4, 2024
379f152
stage point before I try to dedup contract interaction api
jwasinger Nov 6, 2024
e6af3fe
still in a wip state
jwasinger Nov 20, 2024
59731ca
dependency graph calculation working
jwasinger Nov 20, 2024
403329b
commit of wip-code: rework the contract deployment code to be cleaner
jwasinger Nov 24, 2024
bab050c
rework contract deployment API
jwasinger Nov 24, 2024
3fa52cd
closer to test passing now...
jwasinger Nov 24, 2024
b45d532
fix contract
jwasinger Nov 24, 2024
9e388bd
update library test contract to have constructor with inputs. remove…
jwasinger Nov 25, 2024
e552b8b
format improvements
jwasinger Nov 25, 2024
46908d0
add missing files from testdata. refactor contract deployment API to…
jwasinger Nov 26, 2024
9f5de95
more docs. fix nested library contract. fix associated test case.
jwasinger Nov 26, 2024
5c57149
fix v2 test
jwasinger Nov 26, 2024
bc96b7e
some more docs
jwasinger Nov 26, 2024
8a8d7df
simplify generated code for list of library dependencies
jwasinger Nov 26, 2024
70cb700
remove old half-written test case with events (I will add it back in …
jwasinger Nov 26, 2024
613690a
make tests run again
jwasinger Nov 26, 2024
d41e112
add copyright notices. move v2 template to its own file. Rename V2B…
jwasinger Nov 26, 2024
1d7fef8
various small fixes: better error message, remove unecessary comment…
jwasinger Nov 26, 2024
58cddb2
add test for overrides
jwasinger Nov 27, 2024
fa7fea2
add test coverage for events watching
jwasinger Nov 27, 2024
2277beb
add coverage for event filtering
jwasinger Nov 27, 2024
adbe12b
return multiple results in exported struct (instead of anonymous one)…
jwasinger Nov 28, 2024
a7e9fbe
add errors to emitted code.
jwasinger Nov 28, 2024
0f39859
add error unpacking. simplify WatchLogs api.
jwasinger Dec 2, 2024
3653585
fix contract filter test. rename *Logs methods to *Events, to reflec…
jwasinger Dec 2, 2024
1ac716b
delete unused test data. remove useless v2 helper methods. update t…
jwasinger Dec 2, 2024
8a9fe99
remove unused error test, other unused code in tests
jwasinger Dec 2, 2024
4507f3c
small cleanups
jwasinger Dec 2, 2024
5cc5898
add binding generation test
jwasinger Dec 2, 2024
4b69e05
add generic log watching/filtering. skip adding generic call/transac…
jwasinger Dec 3, 2024
0c66c02
add generic call/transact
jwasinger Dec 3, 2024
97b4576
add db example from sina
jwasinger Dec 3, 2024
fec62d2
remove unecessary abi parameter from WatchEvents. simplify event tests
jwasinger Dec 3, 2024
b90cf25
mv test contracts to internal directory under v2
jwasinger Dec 3, 2024
b2e27be
staging changes for linking tests. rework LinkAndDeploy to decouple …
jwasinger Dec 5, 2024
8fdb5ef
wip
jwasinger Dec 6, 2024
3c7ce61
basic linking test working
jwasinger Dec 6, 2024
53b5b21
add test cases for contract linking that I forgot to push earlier. F…
jwasinger Dec 6, 2024
fc681fa
wip: update
jwasinger Dec 6, 2024
af405b1
fix test cases
jwasinger Dec 9, 2024
32ead61
one more test
jwasinger Dec 9, 2024
58ba987
make link test case input be its own struct
jwasinger Dec 9, 2024
5bd9d71
rewrite contract link/deploy again
jwasinger Dec 10, 2024
8c6173d
fix linking tests
jwasinger Dec 10, 2024
2e0de31
tests working now
jwasinger Dec 10, 2024
8e1f4f9
remove debug prints. fix contract linking test condition
jwasinger Dec 10, 2024
3f758c3
generation of custom error unpacking builds (not tested yet)
jwasinger Dec 12, 2024
326da99
wip (just committing so that I can rebase off master to use ethclient…
jwasinger Dec 12, 2024
f9a9db6
full support for errors with working test
jwasinger Dec 12, 2024
8da5bcd
change semantics of contract overrides again: any direct/indirect de…
jwasinger Dec 13, 2024
5297dd0
clean up link/deploy code. add docs
jwasinger Dec 13, 2024
55778ba
gofmt files. add a TODO comment and remove another useless comment
jwasinger Dec 13, 2024
68f4019
fix regex for solc pattern matching
jwasinger Dec 13, 2024
e140c3d
move contract dep tree, link-and-deploy to bind package. This is so …
jwasinger Dec 15, 2024
d53b218
add some docs
jwasinger Dec 15, 2024
eec95b6
move abigen2 specific bind code into BindV2. fix broken v1 tests
jwasinger Dec 16, 2024
a009c60
export event names in bindings. remove added APIs Filter/Watch-Logs …
jwasinger Dec 16, 2024
a30ccd5
update dep tree
jwasinger Dec 16, 2024
ff2050f
remove TODO comment about adding a test case that I have added
jwasinger Dec 16, 2024
fae212e
regenerate bindings
jwasinger Dec 16, 2024
2c76a71
add comment for tmplError struct and remove unused v2 backend interface
jwasinger Dec 16, 2024
78202cd
remove field that I added to abi.Error and never used
jwasinger Dec 16, 2024
36ecad0
wip...
jwasinger Dec 17, 2024
49a9c51
refactor builds
jwasinger Dec 17, 2024
724792c
tests pass
jwasinger Dec 18, 2024
be372ef
remove unecessarily-added method
jwasinger Dec 18, 2024
4736f76
add docs
jwasinger Dec 18, 2024
cf1cfed
move BindV2 and methods it depends on into their own file.
jwasinger Dec 18, 2024
3f52ae8
make DeploymentParams fields private. instantiate it with a construc…
jwasinger Dec 18, 2024
f8f0d94
fix comment for bindError method
jwasinger Dec 18, 2024
0381e27
Update accounts/abi/bind/dep_tree.go
jwasinger Dec 18, 2024
2913781
Update accounts/abi/bind/dep_tree.go
jwasinger Dec 18, 2024
f6bffbb
Update accounts/abi/bind/dep_tree.go
jwasinger Dec 18, 2024
6d626c4
wip: embed library relations in metadata
jwasinger Dec 18, 2024
0d443b8
embed direct library relations in metadata in bindings. simplify dep…
jwasinger Dec 19, 2024
4ad21ba
accounts/abi/bind: simplifications
holiman Dec 19, 2024
62a7806
clarifications
holiman Dec 19, 2024
f0902b3
accounts/abi/bind: make link test case failure output the index of t…
jwasinger Dec 19, 2024
0d14a79
accounts/abi/bind: don't define link test case table as a package-pri…
jwasinger Dec 19, 2024
6be0f63
accounts/abi/bind: remove unused fields from template structs
jwasinger Dec 19, 2024
b5862df
wip
jwasinger Dec 20, 2024
7a9259e
fix events/error args normalization capitalization. add unit test th…
jwasinger Dec 23, 2024
230b3f4
simplify vars naming in normalizeArgs
jwasinger Dec 23, 2024
c802765
remove capitalize helper method. simplify call/event/error symbol na…
jwasinger Dec 23, 2024
1e8be79
copy DeploymentParams overrides before creating tree deployer (preven…
jwasinger Dec 23, 2024
4fc03b1
remove error return from generated pack method for constructors. add…
jwasinger Dec 23, 2024
8b33f64
accounts/abi/bind/v2: fix lib_test.go (update test to reflect that bi…
jwasinger Dec 30, 2024
50f8694
accounts/abi/bind: remove duplicate convertedv1bindtests
jwasinger Dec 30, 2024
f9bca58
accounts/abi/bind/v2/internal/contracts: regenerate bindings (they w…
jwasinger Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 60 additions & 29 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ type WatchOpts struct {

// MetaData collects all metadata for a bound contract.
type MetaData struct {
mu sync.Mutex
Sigs map[string]string
jwasinger marked this conversation as resolved.
Show resolved Hide resolved
Bin string
ABI string
ab *abi.ABI
mu sync.Mutex
Sigs map[string]string
Bin string
ABI string
ab *abi.ABI
Pattern string
Deps []*MetaData
}

func (m *MetaData) GetAbi() (*abi.ABI, error) {
Expand Down Expand Up @@ -151,15 +153,25 @@ func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend Co
return c.address, tx, c, nil
}

// DeployContractRaw deploys a contract onto the Ethereum blockchain and binds the
// deployment address with a Go wrapper. It expects its parameters to be abi-encoded
// bytes.
func DeployContractRaw(opts *TransactOpts, bytecode []byte, backend ContractBackend, packedParams []byte) (common.Address, *types.Transaction, *BoundContract, error) {
jwasinger marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about moving this also to the v2 library? It feels weird that almost all the other utilities are there but to deploy I need to do from accounts/bind.

Copy link
Contributor

@jwasinger jwasinger Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM!

c := NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend)

tx, err := c.transact(opts, nil, append(bytecode, packedParams...))
if err != nil {
return common.Address{}, nil, nil, err
}
c.address = crypto.CreateAddress(opts.From, tx.Nonce())
return c.address, tx, c, 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 (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method string, params ...interface{}) error {
// Don't crash on a lazy user
if opts == nil {
opts = new(CallOpts)
}
if results == nil {
results = new([]interface{})
}
Expand All @@ -168,68 +180,88 @@ func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method stri
if err != nil {
return err
}

output, err := c.call(opts, input)
if err != nil {
return err
}

if len(*results) == 0 {
res, err := c.abi.Unpack(method, output)
*results = res
return err
}
res := *results
return c.abi.UnpackIntoInterface(res[0], method, output)
}

// CallRaw executes an eth_call against the contract with the raw calldata as
// input. It returns the call's return data or an error.
func (c *BoundContract) CallRaw(opts *CallOpts, input []byte) ([]byte, error) {
jwasinger marked this conversation as resolved.
Show resolved Hide resolved
return c.call(opts, input)
}

func (c *BoundContract) call(opts *CallOpts, input []byte) ([]byte, error) {
// Don't crash on a lazy user
if opts == nil {
opts = new(CallOpts)
}
var (
msg = ethereum.CallMsg{From: opts.From, To: &c.address, Data: input}
ctx = ensureContext(opts.Context)
code []byte
output []byte
err error
)
if opts.Pending {
pb, ok := c.caller.(PendingContractCaller)
if !ok {
return ErrNoPendingState
return nil, ErrNoPendingState
}
output, err = pb.PendingCallContract(ctx, msg)
if err != nil {
return err
return nil, err
}
if len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = pb.PendingCodeAt(ctx, c.address); err != nil {
return err
return nil, err
} else if len(code) == 0 {
return ErrNoCode
return nil, ErrNoCode
}
}
} else if opts.BlockHash != (common.Hash{}) {
bh, ok := c.caller.(BlockHashContractCaller)
if !ok {
return ErrNoBlockHashState
return nil, ErrNoBlockHashState
}
output, err = bh.CallContractAtHash(ctx, msg, opts.BlockHash)
if err != nil {
return err
return nil, err
}
if len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = bh.CodeAtHash(ctx, c.address, opts.BlockHash); err != nil {
return err
return nil, err
} else if len(code) == 0 {
return ErrNoCode
return nil, ErrNoCode
}
}
} else {
output, err = c.caller.CallContract(ctx, msg, opts.BlockNumber)
if err != nil {
return err
return nil, err
}
if len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = c.caller.CodeAt(ctx, c.address, opts.BlockNumber); err != nil {
return err
return nil, err
} else if len(code) == 0 {
return ErrNoCode
return nil, ErrNoCode
}
}
}

if len(*results) == 0 {
res, err := c.abi.Unpack(method, output)
*results = res
return err
}
res := *results
return c.abi.UnpackIntoInterface(res[0], method, output)
return output, nil
}

// Transact invokes the (paid) contract method with params as input values.
Expand Down Expand Up @@ -440,7 +472,6 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int
}
// Append the event selector to the query parameters and construct the topic set
query = append([][]interface{}{{c.abi.Events[name].ID}}, query...)

topics, err := abi.MakeTopics(query...)
if err != nil {
return nil, nil, err
Expand Down
Loading
Loading