diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-09-26 16:20:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-26 16:20:47 +0800 |
commit | 2e14aff80f294a34f6b28f0149b94fa7b9d3bf81 (patch) | |
tree | 17d1f3abefabfd7f8cb9149994a4788d2c0f08bc /core/state/dump.go | |
parent | e859f3696783ec75d9bb39c0c66eda3a88cea8c6 (diff) | |
parent | a59a93f476434f2805c8fd3e10bf1b2f579b078f (diff) | |
download | go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.tar go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.tar.gz go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.tar.bz2 go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.tar.lz go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.tar.xz go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.tar.zst go-tangerine-2e14aff80f294a34f6b28f0149b94fa7b9d3bf81.zip |
Merge pull request #3037 from karalabe/state-caching
State caching
Diffstat (limited to 'core/state/dump.go')
-rw-r--r-- | core/state/dump.go | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/core/state/dump.go b/core/state/dump.go index a328b0537..58ecd852b 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -21,9 +21,10 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/rlp" ) -type Account struct { +type DumpAccount struct { Balance string `json:"balance"` Nonce uint64 `json:"nonce"` Root string `json:"root"` @@ -32,40 +33,41 @@ type Account struct { Storage map[string]string `json:"storage"` } -type World struct { - Root string `json:"root"` - Accounts map[string]Account `json:"accounts"` +type Dump struct { + Root string `json:"root"` + Accounts map[string]DumpAccount `json:"accounts"` } -func (self *StateDB) RawDump() World { - world := World{ +func (self *StateDB) RawDump() Dump { + dump := Dump{ Root: common.Bytes2Hex(self.trie.Root()), - Accounts: make(map[string]Account), + Accounts: make(map[string]DumpAccount), } it := self.trie.Iterator() for it.Next() { addr := self.trie.GetKey(it.Key) - stateObject, err := DecodeObject(common.BytesToAddress(addr), self.db, it.Value) - if err != nil { + var data Account + if err := rlp.DecodeBytes(it.Value, &data); err != nil { panic(err) } - account := Account{ - Balance: stateObject.balance.String(), - Nonce: stateObject.nonce, - Root: common.Bytes2Hex(stateObject.Root()), - CodeHash: common.Bytes2Hex(stateObject.codeHash), - Code: common.Bytes2Hex(stateObject.Code()), + obj := NewObject(common.BytesToAddress(addr), data, nil) + account := DumpAccount{ + Balance: data.Balance.String(), + Nonce: data.Nonce, + Root: common.Bytes2Hex(data.Root[:]), + CodeHash: common.Bytes2Hex(data.CodeHash), + Code: common.Bytes2Hex(obj.Code(self.db)), Storage: make(map[string]string), } - storageIt := stateObject.trie.Iterator() + storageIt := obj.getTrie(self.db).Iterator() for storageIt.Next() { account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value) } - world.Accounts[common.Bytes2Hex(addr)] = account + dump.Accounts[common.Bytes2Hex(addr)] = account } - return world + return dump } func (self *StateDB) Dump() []byte { @@ -76,12 +78,3 @@ func (self *StateDB) Dump() []byte { return json } - -// Debug stuff -func (self *StateObject) CreateOutputForDiff() { - fmt.Printf("%x %x %x %x\n", self.Address(), self.Root(), self.balance.Bytes(), self.nonce) - it := self.trie.Iterator() - for it.Next() { - fmt.Printf("%x %x\n", it.Key, it.Value) - } -} |