@@ -47,23 +47,25 @@ type Dump struct {
47
47
}
48
48
49
49
// iterativeDump is a 'collector'-implementation which dump output line-by-line iteratively
50
- type iterativeDump json.Encoder
50
+ type iterativeDump struct {
51
+ * json.Encoder
52
+ }
51
53
52
54
// Collector interface which the state trie calls during iteration
53
55
type collector interface {
54
56
onRoot (common.Hash )
55
57
onAccount (common.Address , DumpAccount )
56
58
}
57
59
58
- func (self * Dump ) onRoot (root common.Hash ) {
59
- self .Root = fmt .Sprintf ("%x" , root )
60
+ func (d * Dump ) onRoot (root common.Hash ) {
61
+ d .Root = fmt .Sprintf ("%x" , root )
60
62
}
61
63
62
- func (self * Dump ) onAccount (addr common.Address , account DumpAccount ) {
63
- self .Accounts [addr ] = account
64
+ func (d * Dump ) onAccount (addr common.Address , account DumpAccount ) {
65
+ d .Accounts [addr ] = account
64
66
}
65
67
66
- func (self iterativeDump ) onAccount (addr common.Address , account DumpAccount ) {
68
+ func (d iterativeDump ) onAccount (addr common.Address , account DumpAccount ) {
67
69
dumpAccount := & DumpAccount {
68
70
Balance : account .Balance ,
69
71
Nonce : account .Nonce ,
@@ -77,25 +79,26 @@ func (self iterativeDump) onAccount(addr common.Address, account DumpAccount) {
77
79
if addr != (common.Address {}) {
78
80
dumpAccount .Address = & addr
79
81
}
80
- ( * json . Encoder )( & self ) .Encode (dumpAccount )
82
+ d .Encode (dumpAccount )
81
83
}
82
- func (self iterativeDump ) onRoot (root common.Hash ) {
83
- (* json .Encoder )(& self ).Encode (struct {
84
+
85
+ func (d iterativeDump ) onRoot (root common.Hash ) {
86
+ d .Encode (struct {
84
87
Root common.Hash `json:"root"`
85
88
}{root })
86
89
}
87
90
88
- func (self * StateDB ) dump (c collector , excludeCode , excludeStorage , excludeMissingPreimages bool ) {
91
+ func (s * StateDB ) dump (c collector , excludeCode , excludeStorage , excludeMissingPreimages bool ) {
89
92
emptyAddress := (common.Address {})
90
93
missingPreimages := 0
91
- c .onRoot (self .trie .Hash ())
92
- it := trie .NewIterator (self .trie .NodeIterator (nil ))
94
+ c .onRoot (s .trie .Hash ())
95
+ it := trie .NewIterator (s .trie .NodeIterator (nil ))
93
96
for it .Next () {
94
97
var data Account
95
98
if err := rlp .DecodeBytes (it .Value , & data ); err != nil {
96
99
panic (err )
97
100
}
98
- addr := common .BytesToAddress (self .trie .GetKey (it .Key ))
101
+ addr := common .BytesToAddress (s .trie .GetKey (it .Key ))
99
102
obj := newObject (nil , addr , data )
100
103
account := DumpAccount {
101
104
Balance : data .Balance .String (),
@@ -112,18 +115,18 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi
112
115
account .SecureKey = it .Key
113
116
}
114
117
if ! excludeCode {
115
- account .Code = common .Bytes2Hex (obj .Code (self .db ))
118
+ account .Code = common .Bytes2Hex (obj .Code (s .db ))
116
119
}
117
120
if ! excludeStorage {
118
121
account .Storage = make (map [common.Hash ]string )
119
- storageIt := trie .NewIterator (obj .getTrie (self .db ).NodeIterator (nil ))
122
+ storageIt := trie .NewIterator (obj .getTrie (s .db ).NodeIterator (nil ))
120
123
for storageIt .Next () {
121
124
_ , content , _ , err := rlp .Split (storageIt .Value )
122
125
if err != nil {
123
126
log .Error ("Failed to decode the value returned by iterator" , "error" , err )
124
127
continue
125
128
}
126
- account .Storage [common .BytesToHash (self .trie .GetKey (storageIt .Key ))] = common .Bytes2Hex (content )
129
+ account .Storage [common .BytesToHash (s .trie .GetKey (storageIt .Key ))] = common .Bytes2Hex (content )
127
130
}
128
131
}
129
132
c .onAccount (addr , account )
@@ -134,17 +137,17 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi
134
137
}
135
138
136
139
// RawDump returns the entire state an a single large object
137
- func (self * StateDB ) RawDump (excludeCode , excludeStorage , excludeMissingPreimages bool ) Dump {
140
+ func (s * StateDB ) RawDump (excludeCode , excludeStorage , excludeMissingPreimages bool ) Dump {
138
141
dump := & Dump {
139
142
Accounts : make (map [common.Address ]DumpAccount ),
140
143
}
141
- self .dump (dump , excludeCode , excludeStorage , excludeMissingPreimages )
144
+ s .dump (dump , excludeCode , excludeStorage , excludeMissingPreimages )
142
145
return * dump
143
146
}
144
147
145
148
// Dump returns a JSON string representing the entire state as a single json-object
146
- func (self * StateDB ) Dump (excludeCode , excludeStorage , excludeMissingPreimages bool ) []byte {
147
- dump := self .RawDump (excludeCode , excludeStorage , excludeMissingPreimages )
149
+ func (s * StateDB ) Dump (excludeCode , excludeStorage , excludeMissingPreimages bool ) []byte {
150
+ dump := s .RawDump (excludeCode , excludeStorage , excludeMissingPreimages )
148
151
json , err := json .MarshalIndent (dump , "" , " " )
149
152
if err != nil {
150
153
fmt .Println ("dump err" , err )
@@ -153,6 +156,6 @@ func (self *StateDB) Dump(excludeCode, excludeStorage, excludeMissingPreimages b
153
156
}
154
157
155
158
// IterativeDump dumps out accounts as json-objects, delimited by linebreaks on stdout
156
- func (self * StateDB ) IterativeDump (excludeCode , excludeStorage , excludeMissingPreimages bool , output * json.Encoder ) {
157
- self .dump (iterativeDump ( * output ) , excludeCode , excludeStorage , excludeMissingPreimages )
159
+ func (s * StateDB ) IterativeDump (excludeCode , excludeStorage , excludeMissingPreimages bool , output * json.Encoder ) {
160
+ s .dump (iterativeDump { output } , excludeCode , excludeStorage , excludeMissingPreimages )
158
161
}
0 commit comments