Skip to content

Commit 00e5fb7

Browse files
committed
Minor syntactic changes
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
1 parent ed3a7da commit 00e5fb7

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

lib/cache.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ module.exports = class Cache {
1414
* Puts account to cache under its address.
1515
* @param {Buffer} key - Address of account
1616
* @param {Account} val - Account
17-
* @param {bool} fromTrie
17+
* @param {bool} [fromTrie]
1818
*/
19-
put (key, val, fromTrie) {
20-
var modified = !fromTrie
19+
put (key, val, fromTrie = false) {
20+
const modified = !fromTrie
2121
this._update(key, val, modified, false)
2222
}
2323

@@ -26,7 +26,7 @@ module.exports = class Cache {
2626
* @param {Buffer} key - Address of account
2727
*/
2828
get (key) {
29-
var account = this.lookup(key)
29+
let account = this.lookup(key)
3030
if (!account) {
3131
account = new Account()
3232
}
@@ -40,9 +40,9 @@ module.exports = class Cache {
4040
lookup (key) {
4141
key = key.toString('hex')
4242

43-
var it = this._cache.find(key)
43+
const it = this._cache.find(key)
4444
if (it.node) {
45-
var account = new Account(it.value.val)
45+
const account = new Account(it.value.val)
4646
return account
4747
}
4848
}
@@ -53,8 +53,7 @@ module.exports = class Cache {
5353
* @param {Function} cb - Callback with params (err, account)
5454
*/
5555
_lookupAccount (address, cb) {
56-
var self = this
57-
self._trie.get(address, function (err, raw) {
56+
this._trie.get(address, (err, raw) => {
5857
if (err) return cb(err)
5958
var account = new Account(raw)
6059
cb(null, account)
@@ -68,14 +67,13 @@ module.exports = class Cache {
6867
* @param {Function} cb - Callback with params (err, account)
6968
*/
7069
getOrLoad (key, cb) {
71-
var self = this
72-
var account = this.lookup(key)
70+
const account = this.lookup(key)
7371
if (account) {
7472
async.nextTick(cb, null, account)
7573
} else {
76-
self._lookupAccount(key, function (err, account) {
74+
this._lookupAccount(key, (err, account) => {
7775
if (err) return cb(err)
78-
self._update(key, account, false, false)
76+
this._update(key, account, false, false)
7977
cb(null, account)
8078
})
8179
}
@@ -88,18 +86,17 @@ module.exports = class Cache {
8886
* @param {Function} cb - Callback
8987
*/
9088
warm (addresses, cb) {
91-
var self = this
9289
// shim till async supports iterators
9390
var accountArr = []
94-
addresses.forEach(function (val) {
91+
addresses.forEach((val) => {
9592
if (val) accountArr.push(val)
9693
})
9794

98-
async.eachSeries(accountArr, function (addressHex, done) {
95+
async.eachSeries(accountArr, (addressHex, done) => {
9996
var address = Buffer.from(addressHex, 'hex')
100-
self._lookupAccount(address, function (err, account) {
97+
this._lookupAccount(address, (err, account) => {
10198
if (err) return done(err)
102-
self._update(address, account, false, false)
99+
this._update(address, account, false, false)
103100
done()
104101
})
105102
}, cb)
@@ -111,16 +108,13 @@ module.exports = class Cache {
111108
* @param {function} cb - Callback
112109
*/
113110
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) => {
120114
if (it.value && it.value.modified) {
121115
it.value.modified = false
122116
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, () => {
124118
next = it.hasNext
125119
it.next()
126120
done()
@@ -129,7 +123,7 @@ module.exports = class Cache {
129123
it.value.modified = false
130124
it.value.deleted = false
131125
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'), () => {
133127
next = it.hasNext
134128
it.next()
135129
done()
@@ -154,7 +148,7 @@ module.exports = class Cache {
154148
* Revert changes to cache last checkpoint (no effect on trie).
155149
*/
156150
revert () {
157-
this._cache = this._checkpoints.pop(this._cache)
151+
this._cache = this._checkpoints.pop()
158152
}
159153

160154
/**
@@ -181,7 +175,7 @@ module.exports = class Cache {
181175

182176
_update (key, val, modified, deleted) {
183177
key = key.toString('hex')
184-
var it = this._cache.find(key)
178+
const it = this._cache.find(key)
185179
if (it.node) {
186180
this._cache = it.update({
187181
val: val,

0 commit comments

Comments
 (0)