mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 23:56:43 +00:00
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:
parent
4d2706c1c5
commit
8c20a2c987
1 changed files with 9 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue