diff options
author | Paweł Bylica <pawel.bylica@imapp.pl> | 2015-03-03 01:46:55 +0800 |
---|---|---|
committer | Paweł Bylica <pawel.bylica@imapp.pl> | 2015-03-03 01:46:55 +0800 |
commit | 24003c76d12b83602ca93be375a3bc19f4fb3f1b (patch) | |
tree | 90e77c349df52806d78693f93704b92786fcb693 /state | |
parent | 9c6d9dfc5c9fdd9aeb8f4d9926ed98008b849f2e (diff) | |
parent | 65cad14f9b27db396d036f47814d4843d947ac43 (diff) | |
download | dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.tar dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.tar.gz dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.tar.bz2 dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.tar.lz dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.tar.xz dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.tar.zst dexon-24003c76d12b83602ca93be375a3bc19f4fb3f1b.zip |
Merge remote-tracking branch 'upstream/develop' into evmjit
Diffstat (limited to 'state')
-rw-r--r-- | state/dump.go | 9 | ||||
-rw-r--r-- | state/state_object.go | 21 |
2 files changed, 21 insertions, 9 deletions
diff --git a/state/dump.go b/state/dump.go index 81895f1a3..2c611d76b 100644 --- a/state/dump.go +++ b/state/dump.go @@ -20,7 +20,7 @@ type World struct { Accounts map[string]Account `json:"accounts"` } -func (self *StateDB) Dump() []byte { +func (self *StateDB) RawDump() World { world := World{ Root: ethutil.Bytes2Hex(self.trie.Root()), Accounts: make(map[string]Account), @@ -35,12 +35,15 @@ func (self *StateDB) Dump() []byte { storageIt := stateObject.State.trie.Iterator() for storageIt.Next() { - account.Storage[ethutil.Bytes2Hex(it.Key)] = ethutil.Bytes2Hex(it.Value) + account.Storage[ethutil.Bytes2Hex(storageIt.Key)] = ethutil.Bytes2Hex(storageIt.Value) } world.Accounts[ethutil.Bytes2Hex(it.Key)] = account } + return world +} - json, err := json.MarshalIndent(world, "", " ") +func (self *StateDB) Dump() []byte { + json, err := json.MarshalIndent(self.RawDump(), "", " ") if err != nil { fmt.Println("dump err", err) } diff --git a/state/state_object.go b/state/state_object.go index 477b912a1..487952a02 100644 --- a/state/state_object.go +++ b/state/state_object.go @@ -19,6 +19,14 @@ func (self Code) String() string { type Storage map[string]*ethutil.Value +func (self Storage) String() (str string) { + for key, value := range self { + str += fmt.Sprintf("%X : %X\n", key, value.Bytes()) + } + + return +} + func (self Storage) Copy() Storage { cpy := make(Storage) for key, value := range self { @@ -119,10 +127,9 @@ func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value { } func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) { self.SetState(key.Bytes(), value) - self.dirty = true } -func (self *StateObject) Storage() map[string]*ethutil.Value { +func (self *StateObject) Storage() Storage { return self.storage } @@ -172,20 +179,22 @@ func (c *StateObject) AddBalance(amount *big.Int) { statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount) } -func (c *StateObject) AddAmount(amount *big.Int) { c.AddBalance(amount) } func (c *StateObject) SubBalance(amount *big.Int) { c.SetBalance(new(big.Int).Sub(c.balance, amount)) statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount) } -func (c *StateObject) SubAmount(amount *big.Int) { c.SubBalance(amount) } func (c *StateObject) SetBalance(amount *big.Int) { c.balance = amount c.dirty = true } +func (c *StateObject) St() Storage { + return c.storage +} + // // Gas setters and getters // @@ -198,7 +207,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error { return fmt.Errorf("insufficient amount: %v, %v", c.balance, total) } - c.SubAmount(total) + c.SubBalance(total) c.dirty = true @@ -221,7 +230,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error { rGas := new(big.Int).Set(gas) rGas.Mul(rGas, price) - self.AddAmount(rGas) + self.AddBalance(rGas) self.dirty = true |