@@ -2,40 +2,63 @@ package state
22
33import (
44 "fmt"
5- "strings"
65
76 "github.com/ethereum/go-ethereum/ethutil"
87)
98
10- type Log struct {
11- Address []byte
12- Topics [][]byte
13- Data []byte
9+ type Log interface {
10+ ethutil.RlpEncodable
11+
12+ Address () []byte
13+ Topics () [][]byte
14+ Data () []byte
15+ }
16+
17+ type StateLog struct {
18+ address []byte
19+ topics [][]byte
20+ data []byte
21+ }
22+
23+ func NewLog (address []byte , topics [][]byte , data []byte ) * StateLog {
24+ return & StateLog {address , topics , data }
25+ }
26+
27+ func (self * StateLog ) Address () []byte {
28+ return self .address
29+ }
30+
31+ func (self * StateLog ) Topics () [][]byte {
32+ return self .topics
1433}
1534
16- func NewLogFromValue (decoder * ethutil.Value ) * Log {
17- log := & Log {
18- Address : decoder .Get (0 ).Bytes (),
19- Data : decoder .Get (2 ).Bytes (),
35+ func (self * StateLog ) Data () []byte {
36+ return self .data
37+ }
38+
39+ func NewLogFromValue (decoder * ethutil.Value ) * StateLog {
40+ log := & StateLog {
41+ address : decoder .Get (0 ).Bytes (),
42+ data : decoder .Get (2 ).Bytes (),
2043 }
2144
2245 it := decoder .Get (1 ).NewIterator ()
2346 for it .Next () {
24- log .Topics = append (log .Topics , it .Value ().Bytes ())
47+ log .topics = append (log .topics , it .Value ().Bytes ())
2548 }
2649
2750 return log
2851}
2952
30- func (self * Log ) RlpData () interface {} {
31- return []interface {}{self .Address , ethutil .ByteSliceToInterface (self .Topics ), self .Data }
53+ func (self * StateLog ) RlpData () interface {} {
54+ return []interface {}{self .address , ethutil .ByteSliceToInterface (self .topics ), self .data }
3255}
3356
34- func (self * Log ) String () string {
35- return fmt .Sprintf (`log: %x %x %x` , self .Address , self .Topics , self .Data )
57+ func (self * StateLog ) String () string {
58+ return fmt .Sprintf (`log: %x %x %x` , self .address , self .topics , self .data )
3659}
3760
38- type Logs []* Log
61+ type Logs []Log
3962
4063func (self Logs ) RlpData () interface {} {
4164 data := make ([]interface {}, len (self ))
@@ -46,10 +69,10 @@ func (self Logs) RlpData() interface{} {
4669 return data
4770}
4871
49- func (self Logs ) String () string {
50- var logs []string
72+ func (self Logs ) String () (ret string ) {
5173 for _ , log := range self {
52- logs = append ( logs , log . String () )
74+ ret += fmt . Sprintf ( "%v" , log )
5375 }
54- return "[ " + strings .Join (logs , ", " ) + " ]"
76+
77+ return "[" + ret + "]"
5578}
0 commit comments