mirror of https://github.com/status-im/op-geth.git
Log is now interface
This commit is contained in:
parent
bff5999efa
commit
3043b233ea
|
@ -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, ""))
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
61
state/log.go
61
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
|
||||
}
|
||||
|
||||
func NewLogFromValue(decoder *ethutil.Value) *Log {
|
||||
log := &Log{
|
||||
Address: decoder.Get(0).Bytes(),
|
||||
Data: decoder.Get(2).Bytes(),
|
||||
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 (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 + "]"
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue