Skip to content

Commit 8c20a2c

Browse files
jwasingerfjl
authored andcommitted
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.
1 parent 4d2706c commit 8c20a2c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

accounts/abi/bind/v2/lib.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,22 @@ func Transact(instance *ContractInstance, opts *bind.TransactOpts, input []byte)
165165
return c.RawTransact(opts, input)
166166
}
167167

168+
// TODO: test coverage for Call where the unpack method returns a pointer object.
168169
// Call performs an eth_call on the given bound contract instance, using the
169170
// provided abi-encoded input (or nil).
170-
func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []byte, unpack func([]byte) (*T, error)) (*T, error) {
171+
func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput []byte, unpack func([]byte) (T, error)) (T, error) {
172+
var defaultResult T
171173
backend := instance.Backend
172174
c := bind.NewBoundContract(instance.Address, instance.abi, backend, backend, backend)
173175
packedOutput, err := c.CallRaw(opts, packedInput)
174176
if err != nil {
175-
return nil, err
177+
return defaultResult, err
178+
}
179+
res, err := unpack(packedOutput)
180+
if err != nil {
181+
return defaultResult, err
176182
}
177-
return unpack(packedOutput)
183+
return res, err
178184
}
179185

180186
// DeployContractRaw deploys a contract onto the Ethereum blockchain and binds the

0 commit comments

Comments
 (0)