-
Notifications
You must be signed in to change notification settings - Fork 23
/
topics.go
46 lines (38 loc) · 999 Bytes
/
topics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package origin
import (
"bytes"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"strings"
)
func init() {
// set topics
var err error
parsedOrigin, err := abi.JSON(strings.NewReader(OriginMetaData.ABI))
if err != nil {
panic(err)
}
SentTopic = parsedOrigin.Events["Sent"].ID
if SentTopic == (common.Hash{}) {
panic("SentTopic is nil")
}
}
// SentTopic is the topic that gets emitted when the sent event is called.
var SentTopic common.Hash
// topicMap maps events to topics.
// this is returned as a function to assert immutability.
func topicMap() map[EventType]common.Hash {
return map[EventType]common.Hash{
SentEvent: SentTopic,
}
}
// eventTypeFromTopic gets the event type from the topic
// returns nil if the topic is not found.
func eventTypeFromTopic(ogTopic common.Hash) *EventType {
for eventType, topic := range topicMap() {
if bytes.Equal(ogTopic.Bytes(), topic.Bytes()) {
return &eventType
}
}
return nil
}