Skip to content

Commit 3043b23

Browse files
committed
Log is now interface
1 parent bff5999 commit 3043b23

10 files changed

Lines changed: 75 additions & 30 deletions

File tree

‎cmd/evm/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func main() {
6262

6363
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(*loglevel)))
6464

65-
ethutil.ReadConfig("/tm/evmtest", "/tmp/evm", "")
65+
ethutil.ReadConfig("/tmp/evmtest", "/tmp/evm", "")
6666

6767
db, _ := ethdb.NewMemDatabase()
6868
statedb := state.New(trie.New(db, ""))

‎cmd/utils/vm_env.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
4141
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit }
4242
func (self *VMEnv) Depth() int { return self.depth }
4343
func (self *VMEnv) SetDepth(i int) { self.depth = i }
44-
func (self *VMEnv) AddLog(log *state.Log) {
44+
func (self *VMEnv) AddLog(log state.Log) {
4545
self.state.AddLog(log)
4646
}
4747
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {

‎core/types/bloom9.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func CreateBloom(receipts Receipts) []byte {
2020
func LogsBloom(logs state.Logs) *big.Int {
2121
bin := new(big.Int)
2222
for _, log := range logs {
23-
data := [][]byte{log.Address}
24-
for _, topic := range log.Topics {
23+
data := [][]byte{log.Address()}
24+
for _, topic := range log.Topics() {
2525
data = append(data, topic)
2626
}
2727

‎core/vm_env.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
3535
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit }
3636
func (self *VMEnv) Depth() int { return self.depth }
3737
func (self *VMEnv) SetDepth(i int) { self.depth = i }
38-
func (self *VMEnv) AddLog(log *state.Log) {
38+
func (self *VMEnv) AddLog(log state.Log) {
3939
self.state.AddLog(log)
4040
}
4141
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {

‎state/log.go‎

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,63 @@ package state
22

33
import (
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

4063
func (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
}

‎state/state.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (self *StateDB) EmptyLogs() {
3737
self.logs = nil
3838
}
3939

40-
func (self *StateDB) AddLog(log *Log) {
40+
func (self *StateDB) AddLog(log Log) {
4141
self.logs = append(self.logs, log)
4242
}
4343

‎tests/helper/vm.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (self *Env) Difficulty() *big.Int { return self.difficulty }
5757
func (self *Env) BlockHash() []byte { return nil }
5858
func (self *Env) State() *state.StateDB { return self.state }
5959
func (self *Env) GasLimit() *big.Int { return self.gasLimit }
60-
func (self *Env) AddLog(log *state.Log) {
60+
func (self *Env) AddLog(log state.Log) {
6161
self.logs = append(self.logs, log)
6262
}
6363
func (self *Env) Depth() int { return self.depth }

‎vm/environment.go‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Environment interface {
2020
BlockHash() []byte
2121
GasLimit() *big.Int
2222
Transfer(from, to Account, amount *big.Int) error
23-
AddLog(*state.Log)
23+
AddLog(state.Log)
2424

2525
Depth() int
2626
SetDepth(i int)
@@ -52,3 +52,25 @@ func Transfer(from, to Account, amount *big.Int) error {
5252

5353
return nil
5454
}
55+
56+
type Log struct {
57+
address []byte
58+
topics [][]byte
59+
data []byte
60+
}
61+
62+
func (self *Log) Address() []byte {
63+
return self.address
64+
}
65+
66+
func (self *Log) Topics() [][]byte {
67+
return self.topics
68+
}
69+
70+
func (self *Log) Data() []byte {
71+
return self.data
72+
}
73+
74+
func (self *Log) RlpData() interface{} {
75+
return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data}
76+
}

‎vm/vm_debug.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewDebugVm(env Environment) *DebugVm {
3535
lt = LogTyDiff
3636
}
3737

38-
return &DebugVm{env: env, logTy: lt, Recoverable: false}
38+
return &DebugVm{env: env, logTy: lt, Recoverable: true}
3939
}
4040

4141
func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) {
@@ -750,7 +750,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
750750
topics[i] = ethutil.LeftPadBytes(stack.Pop().Bytes(), 32)
751751
}
752752

753-
log := &state.Log{closure.Address(), topics, data}
753+
log := &Log{closure.Address(), topics, data}
754754
self.env.AddLog(log)
755755

756756
self.Printf(" => %v", log)

‎xeth/vm_env.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
3939
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit }
4040
func (self *VMEnv) Depth() int { return self.depth }
4141
func (self *VMEnv) SetDepth(i int) { self.depth = i }
42-
func (self *VMEnv) AddLog(log *state.Log) {
42+
func (self *VMEnv) AddLog(log state.Log) {
4343
self.state.AddLog(log)
4444
}
4545
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {

0 commit comments

Comments
 (0)