Skip to content

Commit

Permalink
ethcoder: additional helper methods on EventDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Jul 19, 2024
1 parent 3f61ced commit c929bb1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ethcoder/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,32 @@ func (d *EventDecoder) DecodeLogAsHex(log types.Log) (EventDef, []string, bool,
return eventDef, out, true, nil
}

func (d *EventDecoder) EventDefList() []EventDef {
eventDefs := []EventDef{}
for _, dds := range d.decoders {
for _, dd := range dds {
eventDefs = append(eventDefs, dd.EventDef)
}
}
return eventDefs
}

func (d *EventDecoder) TopicsList() []string {
topics := []string{}
for topic := range d.decoders {
topics = append(topics, topic)
}
return topics
}

func (d *EventDecoder) TopicsMap() map[string]struct{} {
topics := map[string]struct{}{}
for topic := range d.decoders {
topics[topic] = struct{}{}
}
return topics
}

func (d *EventDecoder) getLogDecoder(log types.Log) (eventDecoderDef, error) {
if len(log.Topics) == 0 {
return eventDecoderDef{}, fmt.Errorf("log has no topics, unable to decode")
Expand Down

0 comments on commit c929bb1

Please sign in to comment.