aboutsummaryrefslogtreecommitdiffstats
path: root/ethstate/dump.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-21 21:46:26 +0800
committerobscuren <geffobscura@gmail.com>2014-08-21 21:46:26 +0800
commit0af0f0d890120e007ce42f072e1ee179a62115d3 (patch)
tree5ae9ecafbb729d1636fadfcfa49fd9100959560c /ethstate/dump.go
parentd761af84c83ae8d9d723e6766abb7950ff59cdf3 (diff)
parentc173e9f4ab463cf3a44d35215bc29d846d6f6b02 (diff)
downloadgo-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.tar
go-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.gz
go-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.bz2
go-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.lz
go-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.xz
go-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.tar.zst
go-tangerine-0af0f0d890120e007ce42f072e1ee179a62115d3.zip
Merge branch 'release/0.6.3'
Diffstat (limited to 'ethstate/dump.go')
-rw-r--r--ethstate/dump.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/ethstate/dump.go b/ethstate/dump.go
new file mode 100644
index 000000000..be60a05fc
--- /dev/null
+++ b/ethstate/dump.go
@@ -0,0 +1,47 @@
+package ethstate
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "github.com/ethereum/eth-go/ethutil"
+)
+
+type Account struct {
+ Balance string `json:"balance"`
+ Nonce uint64 `json:"nonce"`
+ CodeHash string `json:"codeHash"`
+ Storage map[string]string `json:"storage"`
+}
+
+type World struct {
+ Root string `json:"root"`
+ Accounts map[string]Account `json:"accounts"`
+}
+
+func (self *State) Dump() []byte {
+ world := World{
+ Root: ethutil.Bytes2Hex(self.Trie.Root.([]byte)),
+ Accounts: make(map[string]Account),
+ }
+
+ self.Trie.NewIterator().Each(func(key string, value *ethutil.Value) {
+ stateObject := NewStateObjectFromBytes([]byte(key), value.Bytes())
+
+ account := Account{Balance: stateObject.Balance.String(), Nonce: stateObject.Nonce, CodeHash: ethutil.Bytes2Hex(stateObject.CodeHash)}
+ account.Storage = make(map[string]string)
+
+ stateObject.EachStorage(func(key string, value *ethutil.Value) {
+ value.Decode()
+ account.Storage[ethutil.Bytes2Hex([]byte(key))] = ethutil.Bytes2Hex(value.Bytes())
+ })
+ world.Accounts[ethutil.Bytes2Hex([]byte(key))] = account
+ })
+
+ json, err := json.MarshalIndent(world, "", " ")
+ if err != nil {
+ fmt.Println("dump err", err)
+ }
+
+ return json
+}