simplify results parameter

This commit is contained in:
maskpp 2024-07-21 15:54:01 +08:00
parent f59d013e40
commit 5487b1c634

View file

@ -154,14 +154,11 @@ func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend Co
// sets the output to result. The result type might be a single field for simple // sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named // returns, a slice of interfaces for anonymous returns and a struct for named
// returns. // returns.
func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method string, params ...interface{}) error { func (c *BoundContract) Call(opts *CallOpts, results []interface{}, method string, params ...interface{}) error {
// Don't crash on a lazy user // Don't crash on a lazy user
if opts == nil { if opts == nil {
opts = new(CallOpts) opts = new(CallOpts)
} }
if results == nil {
results = new([]interface{})
}
// Pack the input, call and unpack the results // Pack the input, call and unpack the results
input, err := c.abi.Pack(method, params...) input, err := c.abi.Pack(method, params...)
if err != nil { if err != nil {
@ -222,12 +219,12 @@ func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method stri
} }
} }
if len(*results) == 0 { if len(results) == 0 {
res, err := c.abi.Unpack(method, output) res, err := c.abi.Unpack(method, output)
*results = res results = res
return err return err
} }
res := *results res := results
return c.abi.UnpackIntoInterface(res[0], method, output) return c.abi.UnpackIntoInterface(res[0], method, output)
} }