diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 1be51fae4e..3ae5b4283e 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -345,19 +345,23 @@ func (it *EventIterator[T]) Close() error { // Transact creates and submits a transaction to the bound contract instance // using the provided abi-encoded input (or nil). -func Transact(instance *ContractInstance, opts *bind.TransactOpts, packedInput []byte) (*types.Transaction, error) { +func Transact(instance *ContractInstance, opts *bind.TransactOpts, input []byte) (*types.Transaction, error) { var ( addr = instance.Address backend = instance.Backend ) c := bind.NewBoundContract(addr, abi.ABI{}, backend, backend, backend) - return c.RawTransact(opts, packedInput) + return c.RawTransact(opts, input) } // Call performs an eth_call on the given bound contract instance, using the // provided abi-encoded input (or nil). -func Call(instance *ContractInstance, opts *bind.CallOpts, packedInput []byte) ([]byte, error) { +func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []byte, unpack func([]byte) (*T, error)) (*T, error) { backend := instance.Backend c := bind.NewBoundContract(instance.Address, abi.ABI{}, backend, backend, backend) - return c.CallRaw(opts, packedInput) + packedOutput, err := c.CallRaw(opts, packedInput) + if err != nil { + return nil, err + } + return unpack(packedOutput) } diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index bedd368216..a7e548e5b9 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -148,21 +148,17 @@ func TestDeploymentLibraries(t *testing.T) { t.Fatalf("pack function input err: %v\n", doInput) } - cABI, err := nested_libraries.C1MetaData.GetAbi() - if err != nil { - t.Fatalf("error getting abi object: %v", err) - } contractAddr := res.Addrs[nested_libraries.C1MetaData.Pattern] - boundC := bind.NewBoundContract(contractAddr, *cABI, bindBackend, bindBackend, bindBackend) callOpts := &bind.CallOpts{ From: common.Address{}, Context: context.Background(), } - callRes, err := boundC.CallRaw(callOpts, doInput) - if err != nil { - t.Fatalf("err calling contract: %v", err) + + ctrctInstance := &ContractInstance{ + Address: contractAddr, + Backend: bindBackend, } - internalCallCount, err := c.UnpackDo(callRes) + internalCallCount, err := Call[big.Int](ctrctInstance, callOpts, doInput, ctrct.UnpackDo) if err != nil { t.Fatalf("err unpacking result: %v", err) }