aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--cmd/evm/main.go2
-rw-r--r--cmd/utils/vm_env.go2
-rw-r--r--core/types/bloom9.go4
-rw-r--r--core/vm_env.go2
-rw-r--r--state/log.go61
-rw-r--r--state/state.go2
-rw-r--r--tests/helper/vm.go2
-rw-r--r--vm/environment.go24
-rw-r--r--vm/vm_debug.go4
-rw-r--r--xeth/vm_env.go2
10 files changed, 75 insertions, 30 deletions
diff --git a/cmd/evm/main.go b/cmd/evm/main.go
index ade4fa611..1e6c807b1 100644
--- a/cmd/evm/main.go
+++ b/cmd/evm/main.go
@@ -62,7 +62,7 @@ func main() {
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(*loglevel)))
- ethutil.ReadConfig("/tm/evmtest", "/tmp/evm", "")
+ ethutil.ReadConfig("/tmp/evmtest", "/tmp/evm", "")
db, _ := ethdb.NewMemDatabase()
statedb := state.New(trie.New(db, ""))
diff --git a/cmd/utils/vm_env.go b/cmd/utils/vm_env.go
index e12fe805d..eb52602c4 100644
--- a/cmd/utils/vm_env.go
+++ b/cmd/utils/vm_env.go
@@ -41,7 +41,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
-func (self *VMEnv) AddLog(log *state.Log) {
+func (self *VMEnv) AddLog(log state.Log) {
self.state.AddLog(log)
}
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
diff --git a/core/types/bloom9.go b/core/types/bloom9.go
index 77aa6eef5..d04656b0d 100644
--- a/core/types/bloom9.go
+++ b/core/types/bloom9.go
@@ -20,8 +20,8 @@ func CreateBloom(receipts Receipts) []byte {
func LogsBloom(logs state.Logs) *big.Int {
bin := new(big.Int)
for _, log := range logs {
- data := [][]byte{log.Address}
- for _, topic := range log.Topics {
+ data := [][]byte{log.Address()}
+ for _, topic := range log.Topics() {
data = append(data, topic)
}
diff --git a/core/vm_env.go b/core/vm_env.go
index 6332abc39..9e1815188 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -35,7 +35,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
-func (self *VMEnv) AddLog(log *state.Log) {
+func (self *VMEnv) AddLog(log state.Log) {
self.state.AddLog(log)
}
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
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)
}
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index f32f98694..0c77e87fb 100644
--- a/tests/helper/vm.go
+++ b/tests/helper/vm.go
@@ -57,7 +57,7 @@ func (self *Env) Difficulty() *big.Int { return self.difficulty }
func (self *Env) BlockHash() []byte { return nil }
func (self *Env) State() *state.StateDB { return self.state }
func (self *Env) GasLimit() *big.Int { return self.gasLimit }
-func (self *Env) AddLog(log *state.Log) {
+func (self *Env) AddLog(log state.Log) {
self.logs = append(self.logs, log)
}
func (self *Env) Depth() int { return self.depth }
diff --git a/vm/environment.go b/vm/environment.go
index 9e129b6ee..d77fb1419 100644
--- a/vm/environment.go
+++ b/vm/environment.go
@@ -20,7 +20,7 @@ type Environment interface {
BlockHash() []byte
GasLimit() *big.Int
Transfer(from, to Account, amount *big.Int) error
- AddLog(*state.Log)
+ AddLog(state.Log)
Depth() int
SetDepth(i int)
@@ -52,3 +52,25 @@ func Transfer(from, to Account, amount *big.Int) error {
return nil
}
+
+type Log struct {
+ address []byte
+ topics [][]byte
+ data []byte
+}
+
+func (self *Log) Address() []byte {
+ return self.address
+}
+
+func (self *Log) Topics() [][]byte {
+ return self.topics
+}
+
+func (self *Log) Data() []byte {
+ return self.data
+}
+
+func (self *Log) RlpData() interface{} {
+ return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data}
+}
diff --git a/vm/vm_debug.go b/vm/vm_debug.go
index 62b1f121c..0a541a769 100644
--- a/vm/vm_debug.go
+++ b/vm/vm_debug.go
@@ -35,7 +35,7 @@ func NewDebugVm(env Environment) *DebugVm {
lt = LogTyDiff
}
- return &DebugVm{env: env, logTy: lt, Recoverable: false}
+ return &DebugVm{env: env, logTy: lt, Recoverable: true}
}
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 *
topics[i] = ethutil.LeftPadBytes(stack.Pop().Bytes(), 32)
}
- log := &state.Log{closure.Address(), topics, data}
+ log := &Log{closure.Address(), topics, data}
self.env.AddLog(log)
self.Printf(" => %v", log)
diff --git a/xeth/vm_env.go b/xeth/vm_env.go
index 4a2827ff4..ce53e9a30 100644
--- a/xeth/vm_env.go
+++ b/xeth/vm_env.go
@@ -39,7 +39,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
-func (self *VMEnv) AddLog(log *state.Log) {
+func (self *VMEnv) AddLog(log state.Log) {
self.state.AddLog(log)
}
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {