Skip to content

Commit 0e856b5

Browse files
committed
accounts/abi/bind/v2: rename package to "bind" and reexport some v1 stuff
1 parent dbe316a commit 0e856b5

File tree

3 files changed

+72
-41
lines changed

3 files changed

+72
-41
lines changed

accounts/abi/bind/v2/lib.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
package v2
17+
package bind
1818

1919
import (
2020
"github.com/ethereum/go-ethereum"
2121
"github.com/ethereum/go-ethereum/accounts/abi"
22-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
22+
bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind"
2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/core/types"
2525
"github.com/ethereum/go-ethereum/crypto"
@@ -30,14 +30,14 @@ import (
3030
// for new logs, call, transact).
3131
type ContractInstance struct {
3232
Address common.Address
33-
Backend bind.ContractBackend
33+
Backend ContractBackend
3434
abi abi.ABI
3535
}
3636

3737
// FilterEvents returns an EventIterator instance for filtering historical events based on the event id and a block range.
38-
func FilterEvents[T any](instance *ContractInstance, opts *bind.FilterOpts, eventName string, unpack func(*types.Log) (*T, error), topics ...[]any) (*EventIterator[T], error) {
38+
func FilterEvents[T any](instance *ContractInstance, opts *FilterOpts, eventName string, unpack func(*types.Log) (*T, error), topics ...[]any) (*EventIterator[T], error) {
3939
backend := instance.Backend
40-
c := bind.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
40+
c := bind1.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
4141
logs, sub, err := c.FilterLogs(opts, eventName, topics...)
4242
if err != nil {
4343
return nil, err
@@ -49,9 +49,9 @@ func FilterEvents[T any](instance *ContractInstance, opts *bind.FilterOpts, even
4949
// contract to be intercepted, unpacked, and forwarded to sink. If
5050
// unpack returns an error, the returned subscription is closed with the
5151
// error.
52-
func WatchEvents[T any](instance *ContractInstance, opts *bind.WatchOpts, eventName string, unpack func(*types.Log) (*T, error), sink chan<- *T, topics ...[]any) (event.Subscription, error) {
52+
func WatchEvents[T any](instance *ContractInstance, opts *WatchOpts, eventName string, unpack func(*types.Log) (*T, error), sink chan<- *T, topics ...[]any) (event.Subscription, error) {
5353
backend := instance.Backend
54-
c := bind.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
54+
c := bind1.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
5555
logs, sub, err := c.WatchLogs(opts, eventName, topics...)
5656
if err != nil {
5757
return nil, err
@@ -156,21 +156,21 @@ func (it *EventIterator[T]) Close() error {
156156

157157
// Transact creates and submits a transaction to the bound contract instance
158158
// using the provided abi-encoded input (or nil).
159-
func Transact(instance *ContractInstance, opts *bind.TransactOpts, input []byte) (*types.Transaction, error) {
159+
func Transact(instance *ContractInstance, opts *TransactOpts, input []byte) (*types.Transaction, error) {
160160
var (
161161
addr = instance.Address
162162
backend = instance.Backend
163163
)
164-
c := bind.NewBoundContract(addr, instance.abi, backend, backend, backend)
164+
c := bind1.NewBoundContract(addr, instance.abi, backend, backend, backend)
165165
return c.RawTransact(opts, input)
166166
}
167167

168168
// Call performs an eth_call on the given bound contract instance, using the
169169
// provided abi-encoded input (or nil).
170-
func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) {
170+
func Call[T any](instance *ContractInstance, opts *CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) {
171171
var defaultResult T
172172
backend := instance.Backend
173-
c := bind.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
173+
c := bind1.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
174174
packedOutput, err := c.CallRaw(opts, packedInput)
175175
if err != nil {
176176
return defaultResult, err
@@ -185,8 +185,8 @@ func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []
185185
// DeployContractRaw deploys a contract onto the Ethereum blockchain and binds the
186186
// deployment address with a Go wrapper. It expects its parameters to be abi-encoded
187187
// bytes.
188-
func DeployContractRaw(opts *bind.TransactOpts, bytecode []byte, backend bind.ContractBackend, packedParams []byte) (common.Address, *types.Transaction, *bind.BoundContract, error) {
189-
c := bind.NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend)
188+
func DeployContractRaw(opts *TransactOpts, bytecode []byte, backend ContractBackend, packedParams []byte) (common.Address, *types.Transaction, *bind1.BoundContract, error) {
189+
c := bind1.NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend)
190190
tx, err := c.RawCreationTransact(opts, append(bytecode, packedParams...))
191191
if err != nil {
192192
return common.Address{}, nil, nil, err

accounts/abi/bind/v2/lib_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
package v2
17+
package bind
1818

1919
import (
2020
"context"
@@ -27,12 +27,12 @@ import (
2727
"testing"
2828
"time"
2929

30+
bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind"
3031
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/contracts/events"
3132
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/contracts/nested_libraries"
3233
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/contracts/solc_errors"
3334

3435
"github.com/ethereum/go-ethereum/accounts/abi"
35-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
3636
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
3737
"github.com/ethereum/go-ethereum/cmd/utils"
3838
"github.com/ethereum/go-ethereum/common"
@@ -59,7 +59,7 @@ func JSON(reader io.Reader) (abi.ABI, error) {
5959
return instance, nil
6060
}
6161

62-
func testSetup() (*bind.TransactOpts, *backends.SimulatedBackend, error) {
62+
func testSetup() (*TransactOpts, *backends.SimulatedBackend, error) {
6363
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
6464
backend := simulated.NewBackend(
6565
types.GenesisAlloc{
@@ -71,7 +71,7 @@ func testSetup() (*bind.TransactOpts, *backends.SimulatedBackend, error) {
7171
)
7272

7373
signer := types.LatestSigner(params.AllDevChainProtocolChanges)
74-
opts := &bind.TransactOpts{
74+
opts := &TransactOpts{
7575
From: testAddr,
7676
Nonce: nil,
7777
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
@@ -97,7 +97,7 @@ func testSetup() (*bind.TransactOpts, *backends.SimulatedBackend, error) {
9797
return opts, &bindBackend, nil
9898
}
9999

100-
func makeTestDeployer(auth *bind.TransactOpts, backend bind.ContractBackend) func(input, deployer []byte) (common.Address, *types.Transaction, error) {
100+
func makeTestDeployer(auth *TransactOpts, backend ContractBackend) func(input, deployer []byte) (common.Address, *types.Transaction, error) {
101101
return func(input, deployer []byte) (common.Address, *types.Transaction, error) {
102102
addr, tx, _, err := DeployContractRaw(auth, deployer, backend, input)
103103
return addr, tx, err
@@ -119,9 +119,9 @@ func TestDeploymentLibraries(t *testing.T) {
119119
}
120120

121121
constructorInput := ctrct.PackConstructor(big.NewInt(42), big.NewInt(1))
122-
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, nil)
122+
deploymentParams := bind1.NewDeploymentParams([]*MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, nil)
123123

124-
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
124+
res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
125125
if err != nil {
126126
t.Fatalf("err: %+v\n", err)
127127
}
@@ -131,7 +131,7 @@ func TestDeploymentLibraries(t *testing.T) {
131131
t.Fatalf("deployment should have generated 5 addresses. got %d", len(res.Addrs))
132132
}
133133
for _, tx := range res.Txs {
134-
_, err = bind.WaitDeployed(context.Background(), bindBackend, tx)
134+
_, err = bind1.WaitDeployed(context.Background(), bindBackend, tx)
135135
if err != nil {
136136
t.Fatalf("error deploying library: %+v", err)
137137
}
@@ -146,7 +146,7 @@ func TestDeploymentLibraries(t *testing.T) {
146146
}
147147

148148
contractAddr := res.Addrs[nested_libraries.C1MetaData.Pattern]
149-
callOpts := &bind.CallOpts{
149+
callOpts := &CallOpts{
150150
From: common.Address{},
151151
Context: context.Background(),
152152
}
@@ -174,9 +174,9 @@ func TestDeploymentWithOverrides(t *testing.T) {
174174
defer bindBackend.Backend.Close()
175175

176176
// deploy all the library dependencies of our target contract, but not the target contract itself.
177-
deploymentParams := bind.NewDeploymentParams(nested_libraries.C1MetaData.Deps, nil, nil)
177+
deploymentParams := bind1.NewDeploymentParams(nested_libraries.C1MetaData.Deps, nil, nil)
178178

179-
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
179+
res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
180180
if err != nil {
181181
t.Fatalf("err: %+v\n", err)
182182
}
@@ -186,7 +186,7 @@ func TestDeploymentWithOverrides(t *testing.T) {
186186
t.Fatalf("deployment should have generated 4 addresses. got %d", len(res.Addrs))
187187
}
188188
for _, tx := range res.Txs {
189-
_, err = bind.WaitDeployed(context.Background(), bindBackend, tx)
189+
_, err = bind1.WaitDeployed(context.Background(), bindBackend, tx)
190190
if err != nil {
191191
t.Fatalf("error deploying library: %+v", err)
192192
}
@@ -199,8 +199,8 @@ func TestDeploymentWithOverrides(t *testing.T) {
199199
constructorInput := ctrct.PackConstructor(big.NewInt(42), big.NewInt(1))
200200
overrides := res.Addrs
201201
// deploy the contract
202-
deploymentParams = bind.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, overrides)
203-
res, err = bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
202+
deploymentParams = bind1.NewDeploymentParams([]*MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, overrides)
203+
res, err = bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
204204
if err != nil {
205205
t.Fatalf("err: %+v\n", err)
206206
}
@@ -210,7 +210,7 @@ func TestDeploymentWithOverrides(t *testing.T) {
210210
t.Fatalf("deployment should have generated 1 address. got %d", len(res.Addrs))
211211
}
212212
for _, tx := range res.Txs {
213-
_, err = bind.WaitDeployed(context.Background(), bindBackend, tx)
213+
_, err = bind1.WaitDeployed(context.Background(), bindBackend, tx)
214214
if err != nil {
215215
t.Fatalf("error deploying library: %+v", err)
216216
}
@@ -231,8 +231,8 @@ func TestDeploymentWithOverrides(t *testing.T) {
231231
t.Fatalf("error getting abi object: %v", err)
232232
}
233233
contractAddr := res.Addrs[nested_libraries.C1MetaData.Pattern]
234-
boundContract := bind.NewBoundContract(contractAddr, *cABI, bindBackend, bindBackend, bindBackend)
235-
callOpts := &bind.CallOpts{
234+
boundContract := bind1.NewBoundContract(contractAddr, *cABI, bindBackend, bindBackend, bindBackend)
235+
callOpts := &CallOpts{
236236
From: common.Address{},
237237
Context: context.Background(),
238238
}
@@ -256,14 +256,14 @@ func TestEvents(t *testing.T) {
256256
t.Fatalf("error setting up testing env: %v", err)
257257
}
258258

259-
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&events.CMetaData}, nil, nil)
260-
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
259+
deploymentParams := bind1.NewDeploymentParams([]*MetaData{&events.CMetaData}, nil, nil)
260+
res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
261261
if err != nil {
262262
t.Fatalf("error deploying contract for testing: %v", err)
263263
}
264264

265265
backend.Commit()
266-
if _, err := bind.WaitDeployed(context.Background(), backend, res.Txs[events.CMetaData.Pattern]); err != nil {
266+
if _, err := bind1.WaitDeployed(context.Background(), backend, res.Txs[events.CMetaData.Pattern]); err != nil {
267267
t.Fatalf("WaitDeployed failed %v", err)
268268
}
269269

@@ -281,7 +281,7 @@ func TestEvents(t *testing.T) {
281281

282282
newCBasic1Ch := make(chan *events.CBasic1)
283283
newCBasic2Ch := make(chan *events.CBasic2)
284-
watchOpts := &bind.WatchOpts{
284+
watchOpts := &bind1.WatchOpts{
285285
Start: nil,
286286
Context: context.Background(),
287287
}
@@ -302,7 +302,7 @@ func TestEvents(t *testing.T) {
302302
t.Fatalf("failed to send transaction: %v", err)
303303
}
304304
backend.Commit()
305-
if _, err := bind.WaitMined(context.Background(), backend, tx); err != nil {
305+
if _, err := bind1.WaitMined(context.Background(), backend, tx); err != nil {
306306
t.Fatalf("error waiting for tx to be mined: %v", err)
307307
}
308308

@@ -332,7 +332,7 @@ done:
332332

333333
// now, test that we can filter those same logs after they were included in the chain
334334

335-
filterOpts := &bind.FilterOpts{
335+
filterOpts := &FilterOpts{
336336
Start: 0,
337337
Context: context.Background(),
338338
}
@@ -367,21 +367,21 @@ func TestErrors(t *testing.T) {
367367
t.Fatalf("error setting up testing env: %v", err)
368368
}
369369

370-
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&solc_errors.CMetaData}, nil, nil)
371-
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
370+
deploymentParams := bind1.NewDeploymentParams([]*MetaData{&solc_errors.CMetaData}, nil, nil)
371+
res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
372372
if err != nil {
373373
t.Fatalf("error deploying contract for testing: %v", err)
374374
}
375375

376376
backend.Commit()
377-
if _, err := bind.WaitDeployed(context.Background(), backend, res.Txs[solc_errors.CMetaData.Pattern]); err != nil {
377+
if _, err := bind1.WaitDeployed(context.Background(), backend, res.Txs[solc_errors.CMetaData.Pattern]); err != nil {
378378
t.Fatalf("WaitDeployed failed %v", err)
379379
}
380380

381381
ctrct, _ := solc_errors.NewC()
382382

383383
var packedInput []byte
384-
opts := &bind.CallOpts{
384+
opts := &CallOpts{
385385
From: res.Addrs[solc_errors.CMetaData.Pattern],
386386
}
387387
packedInput, _ = ctrct.PackFoo()
@@ -467,7 +467,7 @@ func TestBindingGeneration(t *testing.T) {
467467
libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36] // the first 2 chars are 0x
468468
libs[libPattern] = typeName
469469
}
470-
code, err := bind.BindV2(types, abis, bins, dir, libs, make(map[string]string))
470+
code, err := bind1.BindV2(types, abis, bins, dir, libs, make(map[string]string))
471471
if err != nil {
472472
t.Fatalf("error creating bindings for package %s: %v", dir, err)
473473
}

accounts/abi/bind/v2/reexp.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package bind
18+
19+
import bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind"
20+
21+
type ContractBackend = bind1.ContractBackend
22+
23+
type MetaData = bind1.MetaData
24+
25+
type FilterOpts = bind1.FilterOpts
26+
27+
type WatchOpts = bind1.WatchOpts
28+
29+
type TransactOpts = bind1.TransactOpts
30+
31+
type CallOpts = bind1.CallOpts

0 commit comments

Comments
 (0)