Skip to content

Commit

Permalink
genabi: bugfix. handle case where log has no topics
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandotsmith committed Mar 9, 2023
1 parent 5dc7b49 commit f902eac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

var (
NoTopics = errors.New("no data in topics")
SigMismatch = errors.New("event signature doesn't match topics[0]")
IndexMismatch = errors.New("num indexed inputs doesn't match len(topics)")
)
Expand Down
3 changes: 3 additions & 0 deletions genabi/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ import (
// event inputs from the log's data field into [{{ camel .Name }}]:
// {{ .SchemaSignature }}
func Match{{ camel .Name }}(l abi.Log) ({{ camel .Name}}, error) {
if len(l.Topics) == 0 {
return {{ camel .Name }}{}, abi.NoTopics
}
if len(l.Topics) > 0 && {{ lower .Name }}Signature != l.Topics[0] {
return {{ camel .Name }}{}, abi.SigMismatch
}
Expand Down

0 comments on commit f902eac

Please sign in to comment.