From 75ee3b3f089e703b728bb301cc6b2abe4c111c41 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 11 Nov 2014 12:16:36 +0100 Subject: debugging code --- state/log.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'state/log.go') diff --git a/state/log.go b/state/log.go index 73039d7ce..e61a4186e 100644 --- a/state/log.go +++ b/state/log.go @@ -1,6 +1,11 @@ package state -import "github.com/ethereum/go-ethereum/ethutil" +import ( + "fmt" + "strings" + + "github.com/ethereum/go-ethereum/ethutil" +) type Log struct { Address []byte @@ -26,6 +31,10 @@ func (self Log) 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) +} + type Logs []Log func (self Logs) RlpData() interface{} { @@ -36,3 +45,11 @@ func (self Logs) RlpData() interface{} { return data } + +func (self Logs) String() string { + var logs []string + for _, log := range self { + logs = append(logs, log.String()) + } + return "[ " + strings.Join(logs, ", ") + " ]" +} -- cgit v1.2.3 From 6c9e503eb8d41d331d6a74e69539a06590072190 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 11 Nov 2014 22:51:26 +0100 Subject: Removed all implicit logging. Fixed gas issues and jump errors --- state/log.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'state/log.go') diff --git a/state/log.go b/state/log.go index e61a4186e..49da30535 100644 --- a/state/log.go +++ b/state/log.go @@ -13,8 +13,8 @@ type Log struct { Data []byte } -func NewLogFromValue(decoder *ethutil.Value) Log { - log := Log{ +func NewLogFromValue(decoder *ethutil.Value) *Log { + log := &Log{ Address: decoder.Get(0).Bytes(), Data: decoder.Get(2).Bytes(), } @@ -27,15 +27,15 @@ func NewLogFromValue(decoder *ethutil.Value) Log { return log } -func (self Log) RlpData() interface{} { +func (self *Log) RlpData() interface{} { return []interface{}{self.Address, ethutil.ByteSliceToInterface(self.Topics), self.Data} } -func (self Log) String() string { +func (self *Log) 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)) -- cgit v1.2.3 From 3043b233ea4df9b630638d75f3589b94653ccfa9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 12:35:23 +0100 Subject: Log is now interface --- state/log.go | 61 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 19 deletions(-) (limited to 'state/log.go') 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 + "]" } -- cgit v1.2.3