This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
log_event.go
74 lines (63 loc) · 1.64 KB
/
log_event.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright Monax Industries Limited
// SPDX-License-Identifier: Apache-2.0
package exec
import (
"fmt"
"strings"
. "github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/event"
"github.com/hyperledger/burrow/execution/evm/abi"
"github.com/tmthrgd/go-hex"
)
const logNTextTopicCutset = "\x00"
const LogNKeyPrefix = "Log"
func LogNKey(topic int) string {
return fmt.Sprintf("%s%d", LogNKeyPrefix, topic)
}
func LogNTextKey(topic int) string {
return fmt.Sprintf("%s%dText", LogNKeyPrefix, topic)
}
var logTagKeys []string
var logNTopicIndex = make(map[string]int, 5)
var logNTextTopicIndex = make(map[string]int, 5)
func init() {
for i := 0; i <= 4; i++ {
logN := LogNKey(i)
logTagKeys = append(logTagKeys, LogNKey(i))
logNText := LogNTextKey(i)
logTagKeys = append(logTagKeys, logNText)
logNTopicIndex[logN] = i
logNTextTopicIndex[logNText] = i
}
logTagKeys = append(logTagKeys, event.AddressKey)
}
func (log *LogEvent) Get(key string) (interface{}, bool) {
if log == nil {
return "", false
}
var value interface{}
switch key {
case event.AddressKey:
value = log.Address
default:
if i, ok := logNTopicIndex[key]; ok {
return hex.EncodeUpperToString(log.GetTopic(i).Bytes()), true
}
if i, ok := logNTextTopicIndex[key]; ok {
return strings.Trim(string(log.GetTopic(i).Bytes()), logNTextTopicCutset), true
}
return "", false
}
return value, true
}
func (log *LogEvent) GetTopic(i int) Word256 {
if i < len(log.Topics) {
return log.Topics[i]
}
return Word256{}
}
func SolidityEventID(topics []Word256) abi.EventID {
var eventID abi.EventID
copy(eventID[:], topics[0].Bytes())
return eventID
}