aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-08-15 09:46:18 +0800
committerkumavis <aaron@kumavis.me>2017-08-15 09:46:18 +0800
commitaccd057b1abf519551dab253845085c40eb1415c (patch)
tree0fb1fbe59d837d801f2b1b6cafe0f83cab3a37fb /app
parentfdffb6fedc6a29a2f952f7db669bdc2907afb854 (diff)
downloadtangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.tar
tangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.tar.gz
tangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.tar.bz2
tangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.tar.lz
tangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.tar.xz
tangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.tar.zst
tangerine-wallet-browser-accd057b1abf519551dab253845085c40eb1415c.zip
migration 18 - move to diff-based history
Diffstat (limited to 'app')
-rw-r--r--app/scripts/migrations/018.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/scripts/migrations/018.js b/app/scripts/migrations/018.js
new file mode 100644
index 000000000..c8d2332ab
--- /dev/null
+++ b/app/scripts/migrations/018.js
@@ -0,0 +1,52 @@
+const version = 18
+
+/*
+
+This migration updates "transaction state history" to diffs style
+
+*/
+
+const clone = require('clone')
+const txStateHistoryHelper = require('../tx-state-history-helper')
+
+
+module.exports = {
+ version,
+
+ migrate: function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ try {
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ } catch (err) {
+ console.warn(`MetaMask Migration #${version}` + err.stack)
+ }
+ return Promise.resolve(versionedData)
+ },
+}
+
+function transformState (state) {
+ const newState = state
+ const transactions = newState.TransactionController.transactions
+ newState.TransactionController.transactions = transactions.map((txMeta) => {
+ // no history: initialize
+ if (!txMeta.history || tx.history.length === 0) {
+ const snapshot = txStateHistoryHelper.snapshotFromTxMeta(txMeta)
+ txMeta.history = [snapshot]
+ return txMeta
+ }
+ // has history: migrate
+ const newHistory = (
+ txStateHistoryHelper.migrateFromSnapshotsToDiffs(txMeta.history)
+ // remove empty diffs
+ .filter((entry) => {
+ return !Array.isArray(entry) || entry.length > 0
+ })
+ )
+ txMeta.history = newHistory
+ return txMeta
+ })
+ return newState
+}