-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache most recent account balances in the account-tracker
- Loading branch information
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// next version number | ||
const version = 30 | ||
|
||
/* | ||
Adds cachedAccountBalances to the account tracker. | ||
*/ | ||
|
||
const clone = require('clone') | ||
|
||
module.exports = { | ||
version, | ||
|
||
migrate: async function (originalVersionedData) { | ||
const versionedData = clone(originalVersionedData) | ||
versionedData.meta.version = version | ||
const state = versionedData.data | ||
const newState = transformState(state) | ||
versionedData.data = newState | ||
return versionedData | ||
}, | ||
} | ||
|
||
function transformState (state) { | ||
if (!state.AccountTracker) { | ||
return state | ||
} | ||
|
||
const cachedAccountBalances = {} | ||
const accounts = state.AccountTracker.accounts | ||
|
||
let balance | ||
for (const accountId in state.AccountTracker.accounts) { | ||
balance = accounts[accountId].balance | ||
if (balance !== null && balance !== undefined) { | ||
cachedAccountBalances[accountId] = balance | ||
} | ||
} | ||
state.AccountTracker.cachedAccountBalances = cachedAccountBalances | ||
return state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,5 @@ module.exports = [ | |
require('./027'), | ||
require('./028'), | ||
require('./029'), | ||
require('./030'), | ||
] |