Skip to content

Commit a6787a6

Browse files
committed
accounts/abi: fix the output at the beginning instead of making a workaround
1 parent 88e67c5 commit a6787a6

3 files changed

Lines changed: 13 additions & 51 deletions

File tree

‎accounts/abi/argument.go‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,6 @@ func (arguments Arguments) unpackAtomic(v interface{}, output []byte) error {
169169
if err != nil {
170170
return err
171171
}
172-
173-
// if we reach this part, there is only one output member from the contract event.
174-
// for mobile, the result type is always a slice.
175-
if reflect.Slice == value.Kind() && value.Len() >= 1 {
176-
//check if it's not a byte slice
177-
if reflect.TypeOf([]byte{}) != value.Type() {
178-
value = value.Index(0).Elem()
179-
}
180-
}
181-
182172
return set(value, reflect.ValueOf(marshalledValue), arg)
183173
}
184174

‎accounts/abi/unpack_test.go‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -287,42 +287,6 @@ func TestUnpack(t *testing.T) {
287287
}
288288
}
289289

290-
var unpackMobileTests = []unpackTest{
291-
{
292-
def: `[{"type": "uint256"}]`,
293-
enc: "0000000000000000000000000000000000000000000000000000000000000001",
294-
want: big.NewInt(1),
295-
},
296-
}
297-
298-
func TestUnpackMobileOnly(t *testing.T) {
299-
for i, test := range unpackMobileTests {
300-
t.Run(strconv.Itoa(i), func(t *testing.T) {
301-
def := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
302-
abi, err := JSON(strings.NewReader(def))
303-
if err != nil {
304-
t.Fatalf("invalid ABI definition %s: %v", def, err)
305-
}
306-
encb, err := hex.DecodeString(test.enc)
307-
if err != nil {
308-
t.Fatalf("invalid hex: %s" + test.enc)
309-
}
310-
outptr := reflect.New(reflect.TypeOf(test.want))
311-
results := make([]interface{}, 1)
312-
copy(results, []interface{}{outptr.Interface()})
313-
err = abi.Unpack(&results, "method", encb)
314-
if err := test.checkError(err); err != nil {
315-
t.Errorf("test %d (%v) failed: %v", i, test.def, err)
316-
return
317-
}
318-
out := outptr.Elem().Interface()
319-
if !reflect.DeepEqual(test.want, out) {
320-
t.Errorf("test %d (%v) failed: expected %v, got %v", i, test.def, test.want, out)
321-
}
322-
})
323-
}
324-
}
325-
326290
type methodMultiOutput struct {
327291
Int *big.Int
328292
String string

‎mobile/bind.go‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,20 @@ func (c *BoundContract) GetDeployer() *Transaction {
154154
// Call invokes the (constant) contract method with params as input values and
155155
// sets the output to result.
156156
func (c *BoundContract) Call(opts *CallOpts, out *Interfaces, method string, args *Interfaces) error {
157-
results := make([]interface{}, len(out.objects))
158-
copy(results, out.objects)
159-
if err := c.contract.Call(&opts.opts, &results, method, args.objects...); err != nil {
160-
return err
157+
if len(out.objects) == 1 {
158+
result := out.objects[0]
159+
if err := c.contract.Call(&opts.opts, result, method, args.objects...); err != nil {
160+
return err
161+
}
162+
out.objects[0] = result
163+
} else {
164+
results := make([]interface{}, len(out.objects))
165+
copy(results, out.objects)
166+
if err := c.contract.Call(&opts.opts, &results, method, args.objects...); err != nil {
167+
return err
168+
}
169+
copy(out.objects, results)
161170
}
162-
copy(out.objects, results)
163171
return nil
164172
}
165173

0 commit comments

Comments
 (0)