github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/execution/exec/log_event.go (about) 1 // Copyright Monax Industries Limited 2 // SPDX-License-Identifier: Apache-2.0 3 4 package exec 5 6 import ( 7 "fmt" 8 "strings" 9 10 . "github.com/hyperledger/burrow/binary" 11 "github.com/hyperledger/burrow/event" 12 "github.com/hyperledger/burrow/execution/evm/abi" 13 "github.com/tmthrgd/go-hex" 14 ) 15 16 const logNTextTopicCutset = "\x00" 17 const LogNKeyPrefix = "Log" 18 19 func LogNKey(topic int) string { 20 return fmt.Sprintf("%s%d", LogNKeyPrefix, topic) 21 } 22 23 func LogNTextKey(topic int) string { 24 return fmt.Sprintf("%s%dText", LogNKeyPrefix, topic) 25 } 26 27 var logTagKeys []string 28 var logNTopicIndex = make(map[string]int, 5) 29 var logNTextTopicIndex = make(map[string]int, 5) 30 31 func init() { 32 for i := 0; i <= 4; i++ { 33 logN := LogNKey(i) 34 logTagKeys = append(logTagKeys, LogNKey(i)) 35 logNText := LogNTextKey(i) 36 logTagKeys = append(logTagKeys, logNText) 37 logNTopicIndex[logN] = i 38 logNTextTopicIndex[logNText] = i 39 } 40 logTagKeys = append(logTagKeys, event.AddressKey) 41 } 42 43 func (log *LogEvent) Get(key string) (interface{}, bool) { 44 if log == nil { 45 return "", false 46 } 47 var value interface{} 48 switch key { 49 case event.AddressKey: 50 value = log.Address 51 default: 52 if i, ok := logNTopicIndex[key]; ok { 53 return hex.EncodeUpperToString(log.GetTopic(i).Bytes()), true 54 } 55 if i, ok := logNTextTopicIndex[key]; ok { 56 return strings.Trim(string(log.GetTopic(i).Bytes()), logNTextTopicCutset), true 57 } 58 return "", false 59 } 60 return value, true 61 } 62 63 func (log *LogEvent) GetTopic(i int) Word256 { 64 if i < len(log.Topics) { 65 return log.Topics[i] 66 } 67 return Word256{} 68 } 69 70 func SolidityEventID(topics []Word256) abi.EventID { 71 var eventID abi.EventID 72 copy(eventID[:], topics[0].Bytes()) 73 return eventID 74 }