accounts/abi/bind/v2: fix Call helper method: don't return a pointer to the generic unpacked type (b/c it may be a pointer itself in the case of *big.Int underlying type. in this case, double-pointer syntax in the generated binding code would look ugly.

This commit is contained in:
Jared Wasinger 2025-01-08 20:01:16 +08:00 committed by Felix Lange
parent 4d2706c1c5
commit 8c20a2c987

View file

@ -165,16 +165,22 @@ func Transact(instance *ContractInstance, opts *bind.TransactOpts, input []byte)
return c.RawTransact(opts, input)
}
// TODO: test coverage for Call where the unpack method returns a pointer object.
// Call performs an eth_call on the given bound contract instance, using the
// provided abi-encoded input (or nil).
func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []byte, unpack func([]byte) (*T, error)) (*T, error) {
func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) {
var defaultResult T
backend := instance.Backend
c := bind.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
packedOutput, err := c.CallRaw(opts, packedInput)
if err != nil {
return nil, err
return defaultResult, err
}
return unpack(packedOutput)
res, err := unpack(packedOutput)
if err != nil {
return defaultResult, err
}
return res, err
}
// DeployContractRaw deploys a contract onto the Ethereum blockchain and binds the