aboutsummaryrefslogtreecommitdiffstats
path: root/state
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-04 19:35:23 +0800
committerobscuren <geffobscura@gmail.com>2014-12-04 19:35:23 +0800
commit3043b233ea4df9b630638d75f3589b94653ccfa9 (patch)
tree8e426de17ebd46bcbd830abb78af58dd4035206c /state
parentbff5999efaaa0aa7a2b6518b58d489ad4be9e4ff (diff)
downloaddexon-3043b233ea4df9b630638d75f3589b94653ccfa9.tar
dexon-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.gz
dexon-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.bz2
dexon-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.lz
dexon-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.xz
dexon-3043b233ea4df9b630638d75f3589b94653ccfa9.tar.zst
dexon-3043b233ea4df9b630638d75f3589b94653ccfa9.zip
Log is now interface
Diffstat (limited to 'state')
-rw-r--r--state/log.go61
-rw-r--r--state/state.go2
2 files changed, 43 insertions, 20 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 + "]"
}
diff --git a/state/state.go b/state/state.go
index 39c5f33cc..ca3f2af9c 100644
--- a/state/state.go
+++ b/state/state.go
@@ -37,7 +37,7 @@ func (self *StateDB) EmptyLogs() {
self.logs = nil
}
-func (self *StateDB) AddLog(log *Log) {
+func (self *StateDB) AddLog(log Log) {
self.logs = append(self.logs, log)
}