diff --git a/accounts/abi/bind/old.go b/accounts/abi/bind/old.go new file mode 100644 index 0000000000..8783622606 --- /dev/null +++ b/accounts/abi/bind/old.go @@ -0,0 +1,184 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +// Package bind is the runtime for abigen v1 generated contract bindings. +// Deprecated: please use github.com/ethereum/go-ethereum/bind/v2 +package bind + +import ( + "context" + "crypto/ecdsa" + "io" + "math/big" + + "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/abigen" + bind2 "github.com/ethereum/go-ethereum/accounts/abi/bind/v2" + "github.com/ethereum/go-ethereum/accounts/external" + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" +) + +// Bind generates a v1 contract binding. +// Deprecated: binding generation has moved to github.com/ethereum/go-ethereum/accounts/abi/abigen +func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]string, pkg string, libs map[string]string, aliases map[string]string) (string, error) { + return abigen.Bind(types, abis, bytecodes, fsigs, pkg, libs, aliases) +} + +// auth.go + +// NewTransactor is a utility method to easily create a transaction signer from +// an encrypted json key stream and the associated passphrase. +// +// Deprecated: Use NewTransactorWithChainID instead. +func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) { + return bind2.NewTransactor(keyin, passphrase) +} + +// NewKeyedTransactor is a utility method to easily create a transaction signer +// from a single private key. +// +// Deprecated: Use NewKeyedTransactorWithChainID instead. +func NewKeyedTransactor(key *ecdsa.PrivateKey) *bind2.TransactOpts { + return bind2.NewKeyedTransactor(key) +} + +// NewTransactorWithChainID is a utility method to easily create a transaction signer from +// an encrypted json key stream and the associated passphrase. +func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) { + return bind2.NewTransactorWithChainID(keyin, passphrase, chainID) +} + +// NewKeyStoreTransactorWithChainID is a utility method to easily create a transaction signer from +// a decrypted key from a keystore. +func NewKeyStoreTransactorWithChainID(keystore *keystore.KeyStore, account accounts.Account, chainID *big.Int) (*TransactOpts, error) { + return bind2.NewKeyStoreTransactorWithChainID(keystore, account, chainID) +} + +// NewKeyedTransactorWithChainID is a utility method to easily create a transaction signer +// from a single private key. +func NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainID *big.Int) (*TransactOpts, error) { + return bind2.NewKeyedTransactorWithChainID(key, chainID) +} + +// NewClefTransactor is a utility method to easily create a transaction signer +// with a clef backend. +func NewClefTransactor(clef *external.ExternalSigner, account accounts.Account) *TransactOpts { + return bind2.NewClefTransactor(clef, account) +} + +// backend.go + +var ( + // 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. self-destructed). + ErrNoCode = bind2.ErrNoCode + + // ErrNoPendingState is raised when attempting to perform a pending state action + // on a backend that doesn't implement PendingContractCaller. + ErrNoPendingState = bind2.ErrNoPendingState + + // ErrNoBlockHashState is raised when attempting to perform a block hash action + // on a backend that doesn't implement BlockHashContractCaller. + ErrNoBlockHashState = bind2.ErrNoBlockHashState + + // ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves + // an empty contract behind. + ErrNoCodeAfterDeploy = bind2.ErrNoCodeAfterDeploy +) + +// ContractCaller defines the methods needed to allow operating with a contract on a read +// only basis. +type ContractCaller = bind2.ContractCaller + +// PendingContractCaller defines methods to perform contract calls on the pending state. +// Call will try to discover this interface when access to the pending state is requested. +// If the backend does not support the pending state, Call returns ErrNoPendingState. +type PendingContractCaller = bind2.PendingContractCaller + +// BlockHashContractCaller defines methods to perform contract calls on a specific block hash. +// Call will try to discover this interface when access to a block by hash is requested. +// If the backend does not support the block hash state, Call returns ErrNoBlockHashState. +type BlockHashContractCaller = bind2.BlockHashContractCaller + +// ContractTransactor defines the methods needed to allow operating with a contract +// on a write only basis. Besides the transacting method, the remainder are helpers +// used when the user does not provide some needed values, but rather leaves it up +// to the transactor to decide. +type ContractTransactor = bind2.ContractTransactor + +// DeployBackend wraps the operations needed by WaitMined and WaitDeployed. +type DeployBackend = bind2.DeployBackend + +// ContractFilterer defines the methods needed to access log events using one-off +// queries or continuous event subscriptions. +type ContractFilterer = bind2.ContractFilterer + +// ContractBackend defines the methods needed to work with contracts on a read-write basis. +type ContractBackend = bind2.ContractBackend + +// base.go + +type SignerFn = bind2.SignerFn + +type CallOpts = bind2.CallOpts + +type TransactOpts = bind2.TransactOpts + +type FilterOpts = bind2.FilterOpts + +type WatchOpts = bind2.WatchOpts + +type MetaData = bind2.MetaData + +type BoundContract = bind2.BoundContract + +func NewBoundContract(address common.Address, abi abi.ABI, caller ContractCaller, transactor ContractTransactor, filterer ContractFilterer) *BoundContract { + return bind2.NewBoundContract(address, abi, caller, transactor, filterer) +} + +func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend ContractBackend, params ...interface{}) (common.Address, *types.Transaction, *BoundContract, error) { + return bind2.DeployContract(opts, abi, bytecode, backend, params...) +} + +// util.go + +// WaitMined waits for tx to be mined on the blockchain. +// It stops waiting when the context is canceled. +func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) { + return bind2.WaitMined(ctx, b, tx) +} + +// WaitMinedHash waits for a transaction with the provided hash to be mined on the blockchain. +// It stops waiting when the context is canceled. +func WaitMinedHash(ctx context.Context, b DeployBackend, hash common.Hash) (*types.Receipt, error) { + return bind2.WaitMinedHash(ctx, b, hash) +} + +// WaitDeployed waits for a contract deployment transaction and returns the on-chain +// contract address when it is mined. It stops waiting when ctx is canceled. +func WaitDeployed(ctx context.Context, b DeployBackend, tx *types.Transaction) (common.Address, error) { + return bind2.WaitDeployed(ctx, b, tx) +} + +// WaitDeployedHash waits for a contract deployment transaction with the provided hash and returns the on-chain +// contract address when it is mined. It stops waiting when ctx is canceled. +func WaitDeployedHash(ctx context.Context, b DeployBackend, hash common.Hash) (common.Address, error) { + return bind2.WaitDeployedHash(ctx, b, hash) +} diff --git a/accounts/abi/bind/auth.go b/accounts/abi/bind/v2/auth.go similarity index 100% rename from accounts/abi/bind/auth.go rename to accounts/abi/bind/v2/auth.go diff --git a/accounts/abi/bind/backend.go b/accounts/abi/bind/v2/backend.go similarity index 100% rename from accounts/abi/bind/backend.go rename to accounts/abi/bind/v2/backend.go diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/v2/base.go similarity index 100% rename from accounts/abi/bind/base.go rename to accounts/abi/bind/v2/base.go diff --git a/accounts/abi/bind/base_test.go b/accounts/abi/bind/v2/base_test.go similarity index 99% rename from accounts/abi/bind/base_test.go rename to accounts/abi/bind/v2/base_test.go index f7eb7d14d3..80d0f22f2c 100644 --- a/accounts/abi/bind/base_test.go +++ b/accounts/abi/bind/v2/base_test.go @@ -26,7 +26,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/abi/bind/v2" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" diff --git a/accounts/abi/bind/dep_tree.go b/accounts/abi/bind/v2/dep_tree.go similarity index 100% rename from accounts/abi/bind/dep_tree.go rename to accounts/abi/bind/v2/dep_tree.go diff --git a/accounts/abi/bind/dep_tree_test.go b/accounts/abi/bind/v2/dep_tree_test.go similarity index 99% rename from accounts/abi/bind/dep_tree_test.go rename to accounts/abi/bind/v2/dep_tree_test.go index 50c8a68b80..3d0dd0fe5e 100644 --- a/accounts/abi/bind/dep_tree_test.go +++ b/accounts/abi/bind/v2/dep_tree_test.go @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . + package bind import ( diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 6570ac6a71..29925f0ba0 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -21,7 +21,6 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" - bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -43,7 +42,7 @@ func NewContractInstance(backend ContractBackend, addr common.Address, abi abi.A // FilterEvents returns an EventIterator instance for filtering historical events based on the event id and a block range. func FilterEvents[T any](instance ContractInstance, opts *FilterOpts, eventName string, unpack func(*types.Log) (*T, error), topics ...[]any) (*EventIterator[T], error) { backend := instance.Backend - c := bind1.NewBoundContract(instance.Address, instance.abi, backend, backend, backend) + c := NewBoundContract(instance.Address, instance.abi, backend, backend, backend) logs, sub, err := c.FilterLogs(opts, eventName, topics...) if err != nil { return nil, err @@ -57,7 +56,7 @@ func FilterEvents[T any](instance ContractInstance, opts *FilterOpts, eventName // error. func WatchEvents[T any](instance ContractInstance, opts *WatchOpts, eventName string, unpack func(*types.Log) (*T, error), sink chan<- *T, topics ...[]any) (event.Subscription, error) { backend := instance.Backend - c := bind1.NewBoundContract(instance.Address, instance.abi, backend, backend, backend) + c := NewBoundContract(instance.Address, instance.abi, backend, backend, backend) logs, sub, err := c.WatchLogs(opts, eventName, topics...) if err != nil { return nil, err @@ -167,7 +166,7 @@ func Transact(instance ContractInstance, opts *TransactOpts, input []byte) (*typ addr = instance.Address backend = instance.Backend ) - c := bind1.NewBoundContract(addr, instance.abi, backend, backend, backend) + c := NewBoundContract(addr, instance.abi, backend, backend, backend) return c.RawTransact(opts, input) } @@ -179,7 +178,7 @@ func Transact(instance ContractInstance, opts *TransactOpts, input []byte) (*typ func Call[T any](instance ContractInstance, opts *CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) { var defaultResult T backend := instance.Backend - c := bind1.NewBoundContract(instance.Address, instance.abi, backend, backend, backend) + c := NewBoundContract(instance.Address, instance.abi, backend, backend, backend) packedOutput, err := c.CallRaw(opts, packedInput) if err != nil { return defaultResult, err @@ -201,7 +200,7 @@ func Call[T any](instance ContractInstance, opts *CallOpts, packedInput []byte, // 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, error) { - c := bind1.NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend) + c := NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend) tx, err := c.RawCreationTransact(opts, append(bytecode, packedParams...)) if err != nil { return common.Address{}, nil, err diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index a79ed2dd96..f7ad2efa8c 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -25,7 +25,6 @@ import ( "time" "github.com/ethereum/go-ethereum/accounts/abi" - bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/accounts/abi/bind/v2" "github.com/ethereum/go-ethereum/accounts/abi/bind/v2/internal/contracts/events" @@ -109,9 +108,9 @@ func TestDeploymentLibraries(t *testing.T) { c := nested_libraries.NewC1() constructorInput := c.PackConstructor(big.NewInt(42), big.NewInt(1)) - deploymentParams := bind1.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, nil) + deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, nil) - res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) + res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) if err != nil { t.Fatalf("err: %+v\n", err) } @@ -121,7 +120,7 @@ func TestDeploymentLibraries(t *testing.T) { t.Fatalf("deployment should have generated 5 addresses. got %d", len(res.Addrs)) } for _, tx := range res.Txs { - _, err = bind1.WaitDeployed(context.Background(), bindBackend, tx) + _, err = bind.WaitDeployed(context.Background(), bindBackend, tx) if err != nil { t.Fatalf("error deploying library: %+v", err) } @@ -153,9 +152,9 @@ func TestDeploymentWithOverrides(t *testing.T) { defer bindBackend.Backend.Close() // deploy all the library dependencies of our target contract, but not the target contract itself. - deploymentParams := bind1.NewDeploymentParams(nested_libraries.C1MetaData.Deps, nil, nil) + deploymentParams := bind.NewDeploymentParams(nested_libraries.C1MetaData.Deps, nil, nil) - res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) + res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) if err != nil { t.Fatalf("err: %+v\n", err) } @@ -165,7 +164,7 @@ func TestDeploymentWithOverrides(t *testing.T) { t.Fatalf("deployment should have generated 4 addresses. got %d", len(res.Addrs)) } for _, tx := range res.Txs { - _, err = bind1.WaitDeployed(context.Background(), bindBackend, tx) + _, err = bind.WaitDeployed(context.Background(), bindBackend, tx) if err != nil { t.Fatalf("error deploying library: %+v", err) } @@ -175,8 +174,8 @@ func TestDeploymentWithOverrides(t *testing.T) { constructorInput := c.PackConstructor(big.NewInt(42), big.NewInt(1)) overrides := res.Addrs // deploy the contract - deploymentParams = bind1.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, overrides) - res, err = bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) + deploymentParams = bind.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, overrides) + res, err = bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) if err != nil { t.Fatalf("err: %+v\n", err) } @@ -186,7 +185,7 @@ func TestDeploymentWithOverrides(t *testing.T) { t.Fatalf("deployment should have generated 1 address. got %d", len(res.Addrs)) } for _, tx := range res.Txs { - _, err = bind1.WaitDeployed(context.Background(), bindBackend, tx) + _, err = bind.WaitDeployed(context.Background(), bindBackend, tx) if err != nil { t.Fatalf("error deploying library: %+v", err) } @@ -216,14 +215,14 @@ func TestEvents(t *testing.T) { t.Fatalf("error setting up testing env: %v", err) } - deploymentParams := bind1.NewDeploymentParams([]*bind.MetaData{&events.CMetaData}, nil, nil) - res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend)) + deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&events.CMetaData}, nil, nil) + res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend)) if err != nil { t.Fatalf("error deploying contract for testing: %v", err) } backend.Commit() - if _, err := bind1.WaitDeployed(context.Background(), backend, res.Txs[events.CMetaData.Pattern]); err != nil { + if _, err := bind.WaitDeployed(context.Background(), backend, res.Txs[events.CMetaData.Pattern]); err != nil { t.Fatalf("WaitDeployed failed %v", err) } @@ -232,7 +231,7 @@ func TestEvents(t *testing.T) { newCBasic1Ch := make(chan *events.CBasic1) newCBasic2Ch := make(chan *events.CBasic2) - watchOpts := &bind1.WatchOpts{} + watchOpts := &bind.WatchOpts{} sub1, err := bind.WatchEvents(instance, watchOpts, events.CBasic1EventName, c.UnpackBasic1Event, newCBasic1Ch) if err != nil { t.Fatalf("WatchEvents returned error: %v", err) @@ -250,7 +249,7 @@ func TestEvents(t *testing.T) { t.Fatalf("failed to send transaction: %v", err) } backend.Commit() - if _, err := bind1.WaitMined(context.Background(), backend, tx); err != nil { + if _, err := bind.WaitMined(context.Background(), backend, tx); err != nil { t.Fatalf("error waiting for tx to be mined: %v", err) } @@ -315,14 +314,14 @@ func TestErrors(t *testing.T) { t.Fatalf("error setting up testing env: %v", err) } - deploymentParams := bind1.NewDeploymentParams([]*bind.MetaData{&solc_errors.CMetaData}, nil, nil) - res, err := bind1.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend)) + deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&solc_errors.CMetaData}, nil, nil) + res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend)) if err != nil { t.Fatalf("error deploying contract for testing: %v", err) } backend.Commit() - if _, err := bind1.WaitDeployed(context.Background(), backend, res.Txs[solc_errors.CMetaData.Pattern]); err != nil { + if _, err := bind.WaitDeployed(context.Background(), backend, res.Txs[solc_errors.CMetaData.Pattern]); err != nil { t.Fatalf("WaitDeployed failed %v", err) } diff --git a/accounts/abi/bind/v2/reexp.go b/accounts/abi/bind/v2/reexp.go deleted file mode 100644 index b5ed563f23..0000000000 --- a/accounts/abi/bind/v2/reexp.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2024 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package bind - -import bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind" - -type ContractBackend = bind1.ContractBackend - -type MetaData = bind1.MetaData - -type FilterOpts = bind1.FilterOpts - -type WatchOpts = bind1.WatchOpts - -type TransactOpts = bind1.TransactOpts - -type CallOpts = bind1.CallOpts diff --git a/accounts/abi/bind/util.go b/accounts/abi/bind/v2/util.go similarity index 88% rename from accounts/abi/bind/util.go rename to accounts/abi/bind/v2/util.go index a6ceede116..c83116e9a1 100644 --- a/accounts/abi/bind/util.go +++ b/accounts/abi/bind/v2/util.go @@ -22,18 +22,11 @@ import ( "time" "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/accounts/abi/abigen" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" ) -// Bind generates a v1 contract binding. -// Deprecated: binding generation has moved to github.com/ethereum/go-ethereum/accounts/abi/abigen -func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]string, pkg string, libs map[string]string, aliases map[string]string) (string, error) { - return abigen.Bind(types, abis, bytecodes, fsigs, pkg, libs, aliases) -} - // WaitMined waits for tx to be mined on the blockchain. // It stops waiting when the context is canceled. func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) { diff --git a/accounts/abi/bind/util_test.go b/accounts/abi/bind/v2/util_test.go similarity index 96% rename from accounts/abi/bind/util_test.go rename to accounts/abi/bind/v2/util_test.go index 04d1bb63bc..26ac78c96f 100644 --- a/accounts/abi/bind/util_test.go +++ b/accounts/abi/bind/v2/util_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/abi/bind/v2" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -31,8 +31,6 @@ import ( "github.com/ethereum/go-ethereum/params" ) -var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") - var waitDeployedTests = map[string]struct { code string gas uint64