aboutsummaryrefslogtreecommitdiffstats
path: root/ethstate
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-30 20:32:50 +0800
committerobscuren <geffobscura@gmail.com>2014-10-30 20:32:50 +0800
commitdf5603de0a34e80a1af6ad03e37ce43728baad35 (patch)
tree5d9a71ad887c243b781b1c2d6077336bed82057b /ethstate
parentfa890c8c0140dac1e02038a6134db0d83bb85af9 (diff)
downloadgo-tangerine-df5603de0a34e80a1af6ad03e37ce43728baad35.tar.gz
go-tangerine-df5603de0a34e80a1af6ad03e37ce43728baad35.tar.zst
go-tangerine-df5603de0a34e80a1af6ad03e37ce43728baad35.zip
Moved logging to state, proper structured block
* Moved logs to state so it's subject to snapshotting * Split up block header * Removed logs from transactions and made them receipts only
Diffstat (limited to 'ethstate')
-rw-r--r--ethstate/log.go38
-rw-r--r--ethstate/state.go19
2 files changed, 57 insertions, 0 deletions
diff --git a/ethstate/log.go b/ethstate/log.go
new file mode 100644
index 000000000..a2e9ca041
--- /dev/null
+++ b/ethstate/log.go
@@ -0,0 +1,38 @@
+package ethstate
+
+import "github.com/ethereum/go-ethereum/ethutil"
+
+type Log struct {
+ Address []byte
+ Topics [][]byte
+ Data []byte
+}
+
+func NewLogFromValue(decoder *ethutil.Value) Log {
+ log := Log{
+ 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())
+ }
+
+ return log
+}
+
+func (self Log) RlpData() interface{} {
+ return []interface{}{self.Address, ethutil.ByteSliceToInterface(self.Topics), self.Data}
+}
+
+type Logs []Log
+
+func (self Logs) RlpData() interface{} {
+ data := make([]interface{}, len(self))
+ for i, log := range self {
+ data[i] = log.RlpData()
+ }
+
+ return data
+}
diff --git a/ethstate/state.go b/ethstate/state.go
index 97958cc0a..48efeae46 100644
--- a/ethstate/state.go
+++ b/ethstate/state.go
@@ -24,6 +24,8 @@ type State struct {
manifest *Manifest
refund map[string]*big.Int
+
+ logs Logs
}
// Create a new state from a given trie
@@ -31,6 +33,18 @@ func New(trie *ethtrie.Trie) *State {
return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string]*big.Int)}
}
+func (self *State) EmptyLogs() {
+ self.logs = nil
+}
+
+func (self *State) AddLog(log Log) {
+ self.logs = append(self.logs, log)
+}
+
+func (self *State) Logs() Logs {
+ return self.logs
+}
+
// Retrieve the balance from the given address or 0 if object not found
func (self *State) GetBalance(addr []byte) *big.Int {
stateObject := self.GetStateObject(addr)
@@ -202,6 +216,10 @@ func (self *State) Copy() *State {
state.refund[addr] = refund
}
+ logs := make(Logs, len(self.logs))
+ copy(logs, self.logs)
+ state.logs = logs
+
return state
}
@@ -216,6 +234,7 @@ func (self *State) Set(state *State) {
self.Trie = state.Trie
self.stateObjects = state.stateObjects
self.refund = state.refund
+ self.logs = state.logs
}
func (s *State) Root() interface{} {