diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-04 19:35:23 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-04 19:35:23 +0800 |
commit | 3043b233ea4df9b630638d75f3589b94653ccfa9 (patch) | |
tree | 8e426de17ebd46bcbd830abb78af58dd4035206c /state/log.go | |
parent | bff5999efaaa0aa7a2b6518b58d489ad4be9e4ff (diff) | |
download | go-tangerine-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.gz go-tangerine-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.zst go-tangerine-3043b233ea4df9b630638d75f3589b94653ccfa9.zip |
Log is now interface
Diffstat (limited to 'state/log.go')
-rw-r--r-- | state/log.go | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/state/log.go b/state/log.go index 49da30535..46360f4aa 100644 --- a/state/log.go +++ b/state/log.go @@ -2,40 +2,63 @@ package state import ( "fmt" - "strings" "github.com/ethereum/go-ethereum/ethutil" ) -type Log struct { - Address []byte - Topics [][]byte - Data []byte +type Log interface { + ethutil.RlpEncodable + + Address() []byte + Topics() [][]byte + Data() []byte +} + +type StateLog struct { + address []byte + topics [][]byte + data []byte +} + +func NewLog(address []byte, topics [][]byte, data []byte) *StateLog { + return &StateLog{address, topics, data} +} + +func (self *StateLog) Address() []byte { + return self.address +} + +func (self *StateLog) Topics() [][]byte { + return self.topics } -func NewLogFromValue(decoder *ethutil.Value) *Log { - log := &Log{ - Address: decoder.Get(0).Bytes(), - Data: decoder.Get(2).Bytes(), +func (self *StateLog) Data() []byte { + return self.data +} + +func NewLogFromValue(decoder *ethutil.Value) *StateLog { + log := &StateLog{ + address: decoder.Get(0).Bytes(), + data: decoder.Get(2).Bytes(), } it := decoder.Get(1).NewIterator() for it.Next() { - log.Topics = append(log.Topics, it.Value().Bytes()) + log.topics = append(log.topics, it.Value().Bytes()) } return log } -func (self *Log) RlpData() interface{} { - return []interface{}{self.Address, ethutil.ByteSliceToInterface(self.Topics), self.Data} +func (self *StateLog) RlpData() interface{} { + return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data} } -func (self *Log) String() string { - return fmt.Sprintf(`log: %x %x %x`, self.Address, self.Topics, self.Data) +func (self *StateLog) String() string { + return fmt.Sprintf(`log: %x %x %x`, self.address, self.topics, self.data) } -type Logs []*Log +type Logs []Log func (self Logs) RlpData() interface{} { data := make([]interface{}, len(self)) @@ -46,10 +69,10 @@ func (self Logs) RlpData() interface{} { return data } -func (self Logs) String() string { - var logs []string +func (self Logs) String() (ret string) { for _, log := range self { - logs = append(logs, log.String()) + ret += fmt.Sprintf("%v", log) } - return "[ " + strings.Join(logs, ", ") + " ]" + + return "[" + ret + "]" } |