aboutsummaryrefslogtreecommitdiffstats
path: root/state
diff options
context:
space:
mode:
Diffstat (limited to 'state')
-rw-r--r--state/manifest.go61
-rw-r--r--state/statedb.go51
2 files changed, 21 insertions, 91 deletions
diff --git a/state/manifest.go b/state/manifest.go
deleted file mode 100644
index 994019a08..000000000
--- a/state/manifest.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package state
-
-import (
- "fmt"
- "math/big"
-)
-
-// Object manifest
-//
-// The object manifest is used to keep changes to the state so we can keep track of the changes
-// that occurred during a state transitioning phase.
-type Manifest struct {
- Messages Messages
-}
-
-func NewManifest() *Manifest {
- m := &Manifest{}
- m.Reset()
-
- return m
-}
-
-func (m *Manifest) Reset() {
- m.Messages = nil
-}
-
-func (self *Manifest) AddMessage(msg *Message) *Message {
- self.Messages = append(self.Messages, msg)
-
- return msg
-}
-
-func (self *Manifest) SetHash(hash []byte) {
- for _, message := range self.Messages {
- message.Block = hash
- }
-}
-
-type Messages []*Message
-type Message struct {
- To, From []byte
- Input []byte
- Output []byte
- Path int
- Origin []byte
- Timestamp int64
- Coinbase []byte
- Block []byte
- Number *big.Int
- Value *big.Int
-
- ChangedAddresses [][]byte
-}
-
-func (self *Message) AddStorageChange(addr []byte) {
- self.ChangedAddresses = append(self.ChangedAddresses, addr)
-}
-
-func (self *Message) String() string {
- return fmt.Sprintf("Message{to: %x from: %x input: %x output: %x origin: %x coinbase: %x block: %x number: %v timestamp: %d path: %d value: %v", self.To, self.From, self.Input, self.Output, self.Origin, self.Coinbase, self.Block, self.Number, self.Timestamp, self.Path, self.Value)
-}
diff --git a/state/statedb.go b/state/statedb.go
index af054ff09..c83d59ed7 100644
--- a/state/statedb.go
+++ b/state/statedb.go
@@ -22,8 +22,6 @@ type StateDB struct {
stateObjects map[string]*StateObject
- manifest *Manifest
-
refund map[string]*big.Int
logs Logs
@@ -32,7 +30,7 @@ type StateDB struct {
// Create a new state from a given trie
func New(root []byte, db ethutil.Database) *StateDB {
trie := trie.New(ethutil.CopyBytes(root), db)
- return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string]*big.Int)}
+ return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: make(map[string]*big.Int)}
}
func (self *StateDB) EmptyLogs() {
@@ -47,6 +45,13 @@ func (self *StateDB) Logs() Logs {
return self.logs
}
+func (self *StateDB) Refund(addr []byte, gas *big.Int) {
+ if self.refund[string(addr)] == nil {
+ self.refund[string(addr)] = new(big.Int)
+ }
+ self.refund[string(addr)].Add(self.refund[string(addr)], gas)
+}
+
// Retrieve the balance from the given address or 0 if object not found
func (self *StateDB) GetBalance(addr []byte) *big.Int {
stateObject := self.GetStateObject(addr)
@@ -57,13 +62,6 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
return ethutil.Big0
}
-func (self *StateDB) Refund(addr []byte, gas *big.Int) {
- if self.refund[string(addr)] == nil {
- self.refund[string(addr)] = new(big.Int)
- }
- self.refund[string(addr)].Add(self.refund[string(addr)], gas)
-}
-
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
@@ -103,6 +101,7 @@ func (self *StateDB) SetCode(addr, code []byte) {
}
}
+// TODO vars
func (self *StateDB) GetState(a, b []byte) []byte {
stateObject := self.GetStateObject(a)
if stateObject != nil {
@@ -212,25 +211,21 @@ func (s *StateDB) Cmp(other *StateDB) bool {
}
func (self *StateDB) Copy() *StateDB {
- if self.trie != nil {
- state := New(nil, self.db)
- state.trie = self.trie.Copy()
- for k, stateObject := range self.stateObjects {
- state.stateObjects[k] = stateObject.Copy()
- }
-
- for addr, refund := range self.refund {
- state.refund[addr] = new(big.Int).Set(refund)
- }
-
- logs := make(Logs, len(self.logs))
- copy(logs, self.logs)
- state.logs = logs
+ state := New(nil, self.db)
+ state.trie = self.trie.Copy()
+ for k, stateObject := range self.stateObjects {
+ state.stateObjects[k] = stateObject.Copy()
+ }
- return state
+ for addr, refund := range self.refund {
+ state.refund[addr] = new(big.Int).Set(refund)
}
- return nil
+ logs := make(Logs, len(self.logs))
+ copy(logs, self.logs)
+ state.logs = logs
+
+ return state
}
func (self *StateDB) Set(state *StateDB) {
@@ -301,10 +296,6 @@ func (self *StateDB) Update(gasUsed *big.Int) {
}
}
-func (self *StateDB) Manifest() *Manifest {
- return self.manifest
-}
-
// Debug stuff
func (self *StateDB) CreateOutputForDiff() {
for _, stateObject := range self.stateObjects {