diff --git a/accounts/abi/bind/v2/internal/contracts/db/bindings.go b/accounts/abi/bind/v2/internal/contracts/db/bindings.go index 2980dbf2da..60d2c5bf85 100644 --- a/accounts/abi/bind/v2/internal/contracts/db/bindings.go +++ b/accounts/abi/bind/v2/internal/contracts/db/bindings.go @@ -52,7 +52,7 @@ func NewDB() *DB { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *DB) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *DB) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } diff --git a/accounts/abi/bind/v2/internal/contracts/events/bindings.go b/accounts/abi/bind/v2/internal/contracts/events/bindings.go index 73e28168a2..ce8d80419b 100644 --- a/accounts/abi/bind/v2/internal/contracts/events/bindings.go +++ b/accounts/abi/bind/v2/internal/contracts/events/bindings.go @@ -51,7 +51,7 @@ func NewC() *C { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *C) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *C) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } diff --git a/accounts/abi/bind/v2/internal/contracts/nested_libraries/bindings.go b/accounts/abi/bind/v2/internal/contracts/nested_libraries/bindings.go index 62c30e69e0..457147cd75 100644 --- a/accounts/abi/bind/v2/internal/contracts/nested_libraries/bindings.go +++ b/accounts/abi/bind/v2/internal/contracts/nested_libraries/bindings.go @@ -49,7 +49,7 @@ func NewC1() *C1 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *C1) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *C1) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -112,7 +112,7 @@ func NewC2() *C2 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *C2) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *C2) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -171,7 +171,7 @@ func NewL1() *L1 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *L1) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *L1) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -225,7 +225,7 @@ func NewL2() *L2 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *L2) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *L2) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -279,7 +279,7 @@ func NewL2b() *L2b { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *L2b) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *L2b) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -330,7 +330,7 @@ func NewL3() *L3 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *L3) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *L3) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -385,7 +385,7 @@ func NewL4() *L4 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *L4) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *L4) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -439,7 +439,7 @@ func NewL4b() *L4b { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *L4b) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *L4b) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } diff --git a/accounts/abi/bind/v2/internal/contracts/solc_errors/bindings.go b/accounts/abi/bind/v2/internal/contracts/solc_errors/bindings.go index 4fc138ae60..e763057826 100644 --- a/accounts/abi/bind/v2/internal/contracts/solc_errors/bindings.go +++ b/accounts/abi/bind/v2/internal/contracts/solc_errors/bindings.go @@ -45,7 +45,7 @@ func NewC() *C { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *C) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *C) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } @@ -151,7 +151,7 @@ func NewC2() *C2 { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *C2) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *C2) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } diff --git a/accounts/abi/bind/v2/internal/contracts/uint256arrayreturn/bindings.go b/accounts/abi/bind/v2/internal/contracts/uint256arrayreturn/bindings.go index badd8133af..77dbe0d146 100644 --- a/accounts/abi/bind/v2/internal/contracts/uint256arrayreturn/bindings.go +++ b/accounts/abi/bind/v2/internal/contracts/uint256arrayreturn/bindings.go @@ -45,7 +45,7 @@ func NewMyContract() *MyContract { // Instance creates a wrapper for a deployed contract instance at the given address. // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc. -func (c *MyContract) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance { +func (c *MyContract) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract { return bind.NewContractInstance(backend, addr, c.abi) } diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 29925f0ba0..add552282f 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -27,22 +27,12 @@ import ( "github.com/ethereum/go-ethereum/event" ) -// ContractInstance represents a contract deployed on-chain that can be interacted with (filter for past logs, watch -// for new logs, call, transact). -type ContractInstance struct { - Address common.Address - Backend ContractBackend - abi abi.ABI -} - -func NewContractInstance(backend ContractBackend, addr common.Address, abi abi.ABI) ContractInstance { - return ContractInstance{addr, backend, abi} +func NewContractInstance(backend ContractBackend, addr common.Address, abi abi.ABI) *BoundContract { + return NewBoundContract(addr, abi, backend, backend, backend) } // 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 := NewBoundContract(instance.Address, instance.abi, backend, backend, backend) +func FilterEvents[T any](c *BoundContract, opts *FilterOpts, eventName string, unpack func(*types.Log) (*T, error), topics ...[]any) (*EventIterator[T], error) { logs, sub, err := c.FilterLogs(opts, eventName, topics...) if err != nil { return nil, err @@ -54,9 +44,7 @@ func FilterEvents[T any](instance ContractInstance, opts *FilterOpts, eventName // contract to be intercepted, unpacked, and forwarded to sink. If // unpack returns an error, the returned subscription is closed with the // 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 := NewBoundContract(instance.Address, instance.abi, backend, backend, backend) +func WatchEvents[T any](c *BoundContract, opts *WatchOpts, eventName string, unpack func(*types.Log) (*T, error), sink chan<- *T, topics ...[]any) (event.Subscription, error) { logs, sub, err := c.WatchLogs(opts, eventName, topics...) if err != nil { return nil, err @@ -159,26 +147,13 @@ func (it *EventIterator[T]) Close() error { return nil } -// Transact creates and submits a transaction to the bound contract instance -// using the provided abi-encoded input (or nil). -func Transact(instance ContractInstance, opts *TransactOpts, input []byte) (*types.Transaction, error) { - var ( - addr = instance.Address - backend = instance.Backend - ) - c := NewBoundContract(addr, instance.abi, backend, backend, backend) - return c.RawTransact(opts, input) -} - // Call performs an eth_call on the given bound contract instance, using the provided // ABI-encoded input. // // To call a function that doesn't return any output, pass nil as the unpack function. // This can be useful if you just want to check that the function doesn't revert. -func Call[T any](instance ContractInstance, opts *CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) { +func Call[T any](c *BoundContract, opts *CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) { var defaultResult T - backend := instance.Backend - c := NewBoundContract(instance.Address, instance.abi, backend, backend, backend) packedOutput, err := c.CallRaw(opts, packedInput) if err != nil { return defaultResult, err diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index c4ba694fc8..6a37c3e814 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -237,7 +237,7 @@ func TestEvents(t *testing.T) { defer sub2.Unsubscribe() packedInput := c.PackEmitMulti() - tx, err := bind.Transact(instance, txAuth, packedInput) + tx, err := instance.RawTransact(txAuth, packedInput) if err != nil { t.Fatalf("failed to send transaction: %v", err) }