未验证 提交 9becba55 编写于 作者: R Robert Zaremba 提交者: Martin Holst Swende

accounts/abi: fix event tupleUnpack

Event.tupleUnpack doesn't handle correctly Indexed arguments,
hence it can't unpack an event with indexed arguments.
上级 3511904a
...@@ -65,13 +65,13 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error { ...@@ -65,13 +65,13 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error {
return fmt.Errorf("abi: cannot unmarshal tuple in to %v", typ) return fmt.Errorf("abi: cannot unmarshal tuple in to %v", typ)
} }
j := 0 i, j := -1, 0
for i := 0; i < len(e.Inputs); i++ { for _, input := range e.Inputs {
input := e.Inputs[i]
if input.Indexed { if input.Indexed {
// can't read, continue // can't read, continue
continue continue
} }
i++
marshalledValue, err := toGoType((i+j)*32, input.Type, output) marshalledValue, err := toGoType((i+j)*32, input.Type, output)
if err != nil { if err != nil {
return err return err
...@@ -88,22 +88,22 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error { ...@@ -88,22 +88,22 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error {
for j := 0; j < typ.NumField(); j++ { for j := 0; j < typ.NumField(); j++ {
field := typ.Field(j) field := typ.Field(j)
// TODO read tags: `abi:"fieldName"` // TODO read tags: `abi:"fieldName"`
if field.Name == strings.ToUpper(e.Inputs[i].Name[:1])+e.Inputs[i].Name[1:] { if field.Name == strings.ToUpper(input.Name[:1])+input.Name[1:] {
if err := set(value.Field(j), reflectValue, e.Inputs[i]); err != nil { if err := set(value.Field(j), reflectValue, input); err != nil {
return err return err
} }
} }
} }
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array:
if value.Len() < i { if value.Len() < i {
return fmt.Errorf("abi: insufficient number of arguments for unpack, want %d, got %d", len(e.Inputs), value.Len()) return fmt.Errorf("abi: insufficient number of arguments for unpack, want %d, got %d", i, value.Len())
} }
v := value.Index(i) v := value.Index(i)
if v.Kind() != reflect.Ptr && v.Kind() != reflect.Interface { if v.Kind() != reflect.Ptr && v.Kind() != reflect.Interface {
return fmt.Errorf("abi: cannot unmarshal %v in to %v", v.Type(), reflectValue.Type()) return fmt.Errorf("abi: cannot unmarshal %v in to %v", v.Type(), reflectValue.Type())
} }
reflectValue := reflect.ValueOf(marshalledValue) reflectValue := reflect.ValueOf(marshalledValue)
if err := set(v.Elem(), reflectValue, e.Inputs[i]); err != nil { if err := set(v.Elem(), reflectValue, input); err != nil {
return err return err
} }
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册