@@ -14,10 +14,10 @@ module.exports = class Cache {
14
14
* Puts account to cache under its address.
15
15
* @param {Buffer } key - Address of account
16
16
* @param {Account } val - Account
17
- * @param {bool } fromTrie
17
+ * @param {bool } [ fromTrie]
18
18
*/
19
- put ( key , val , fromTrie ) {
20
- var modified = ! fromTrie
19
+ put ( key , val , fromTrie = false ) {
20
+ const modified = ! fromTrie
21
21
this . _update ( key , val , modified , false )
22
22
}
23
23
@@ -26,7 +26,7 @@ module.exports = class Cache {
26
26
* @param {Buffer } key - Address of account
27
27
*/
28
28
get ( key ) {
29
- var account = this . lookup ( key )
29
+ let account = this . lookup ( key )
30
30
if ( ! account ) {
31
31
account = new Account ( )
32
32
}
@@ -40,9 +40,9 @@ module.exports = class Cache {
40
40
lookup ( key ) {
41
41
key = key . toString ( 'hex' )
42
42
43
- var it = this . _cache . find ( key )
43
+ const it = this . _cache . find ( key )
44
44
if ( it . node ) {
45
- var account = new Account ( it . value . val )
45
+ const account = new Account ( it . value . val )
46
46
return account
47
47
}
48
48
}
@@ -53,8 +53,7 @@ module.exports = class Cache {
53
53
* @param {Function } cb - Callback with params (err, account)
54
54
*/
55
55
_lookupAccount ( address , cb ) {
56
- var self = this
57
- self . _trie . get ( address , function ( err , raw ) {
56
+ this . _trie . get ( address , ( err , raw ) => {
58
57
if ( err ) return cb ( err )
59
58
var account = new Account ( raw )
60
59
cb ( null , account )
@@ -68,14 +67,13 @@ module.exports = class Cache {
68
67
* @param {Function } cb - Callback with params (err, account)
69
68
*/
70
69
getOrLoad ( key , cb ) {
71
- var self = this
72
- var account = this . lookup ( key )
70
+ const account = this . lookup ( key )
73
71
if ( account ) {
74
72
async . nextTick ( cb , null , account )
75
73
} else {
76
- self . _lookupAccount ( key , function ( err , account ) {
74
+ this . _lookupAccount ( key , ( err , account ) => {
77
75
if ( err ) return cb ( err )
78
- self . _update ( key , account , false , false )
76
+ this . _update ( key , account , false , false )
79
77
cb ( null , account )
80
78
} )
81
79
}
@@ -88,18 +86,17 @@ module.exports = class Cache {
88
86
* @param {Function } cb - Callback
89
87
*/
90
88
warm ( addresses , cb ) {
91
- var self = this
92
89
// shim till async supports iterators
93
90
var accountArr = [ ]
94
- addresses . forEach ( function ( val ) {
91
+ addresses . forEach ( ( val ) => {
95
92
if ( val ) accountArr . push ( val )
96
93
} )
97
94
98
- async . eachSeries ( accountArr , function ( addressHex , done ) {
95
+ async . eachSeries ( accountArr , ( addressHex , done ) => {
99
96
var address = Buffer . from ( addressHex , 'hex' )
100
- self . _lookupAccount ( address , function ( err , account ) {
97
+ this . _lookupAccount ( address , ( err , account ) => {
101
98
if ( err ) return done ( err )
102
- self . _update ( address , account , false , false )
99
+ this . _update ( address , account , false , false )
103
100
done ( )
104
101
} )
105
102
} , cb )
@@ -111,16 +108,13 @@ module.exports = class Cache {
111
108
* @param {function } cb - Callback
112
109
*/
113
110
flush ( cb ) {
114
- var it = this . _cache . begin
115
- var self = this
116
- var next = true
117
- async . whilst ( function ( ) {
118
- return next
119
- } , function ( done ) {
111
+ const it = this . _cache . begin
112
+ let next = true
113
+ async . whilst ( ( ) => next , ( done ) => {
120
114
if ( it . value && it . value . modified ) {
121
115
it . value . modified = false
122
116
it . value . val = it . value . val . serialize ( )
123
- self . _trie . put ( Buffer . from ( it . key , 'hex' ) , it . value . val , function ( ) {
117
+ this . _trie . put ( Buffer . from ( it . key , 'hex' ) , it . value . val , ( ) => {
124
118
next = it . hasNext
125
119
it . next ( )
126
120
done ( )
@@ -129,7 +123,7 @@ module.exports = class Cache {
129
123
it . value . modified = false
130
124
it . value . deleted = false
131
125
it . value . val = ( new Account ( ) ) . serialize ( )
132
- self . _trie . del ( Buffer . from ( it . key , 'hex' ) , function ( ) {
126
+ this . _trie . del ( Buffer . from ( it . key , 'hex' ) , ( ) => {
133
127
next = it . hasNext
134
128
it . next ( )
135
129
done ( )
@@ -154,7 +148,7 @@ module.exports = class Cache {
154
148
* Revert changes to cache last checkpoint (no effect on trie).
155
149
*/
156
150
revert ( ) {
157
- this . _cache = this . _checkpoints . pop ( this . _cache )
151
+ this . _cache = this . _checkpoints . pop ( )
158
152
}
159
153
160
154
/**
@@ -181,7 +175,7 @@ module.exports = class Cache {
181
175
182
176
_update ( key , val , modified , deleted ) {
183
177
key = key . toString ( 'hex' )
184
- var it = this . _cache . find ( key )
178
+ const it = this . _cache . find ( key )
185
179
if ( it . node ) {
186
180
this . _cache = it . update ( {
187
181
val : val ,
0 commit comments