Skip to content

Commit

Permalink
Decode fixed bytes in topic (umbracle#168)
Browse files Browse the repository at this point in the history
* Decode fixed bytes in topic

* Update Changelog
  • Loading branch information
ferranbt authored Mar 11, 2022
1 parent 2e51d36 commit 88d505b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# 0.1.1 (Not released)

- Parse `fixed bytes` type in event topic [[GH-168](https://github.com/umbracle/ethgo/issues/168)]
- Introduce `NodeProvider` and update `Contract` and `abigen` format. [[GH-167](https://github.com/umbracle/ethgo/issues/167)]

# 0.1.0 (5 March, 2022)
Expand Down
9 changes: 4 additions & 5 deletions abi/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ func ParseTopic(t *Type, topic ethgo.Hash) (interface{}, error) {
case KindAddress:
return readAddr(topic[:])

case KindFixedBytes:
return readFixedBytes(t, topic[:])

default:
return nil, fmt.Errorf("Topic parsing for type %s not supported", t.String())
return nil, fmt.Errorf("topic parsing for type %s not supported", t.String())
}
}

Expand Down Expand Up @@ -150,7 +153,3 @@ func encodeTopicBool(v reflect.Value) (res ethgo.Hash, err error) {
}
return topicFalse, nil
}

func encodeTopicErr(val reflect.Value, str string) error {
return fmt.Errorf("cannot encode %s as %s", val.Type().String(), str)
}
8 changes: 8 additions & 0 deletions abi/topics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ func TestIntegrationTopics(t *testing.T) {
fields []field
}{
{
// uint
fields: []field{
{"uint32", false, uint32(1), "1"},
{"uint8", true, uint8(10), "10"},
},
},
{
// fixed bytes
fields: []field{
{"bytes1", false, [1]byte{0x1}, "0x01"},
{"bytes1", true, [1]byte{0x1}, "0x01"},
},
},
}

for _, c := range cases {
Expand Down

0 comments on commit 88d505b

Please sign in to comment.