From accd057b1abf519551dab253845085c40eb1415c Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 14 Aug 2017 18:46:18 -0700 Subject: migration 18 - move to diff-based history --- app/scripts/migrations/018.js | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/scripts/migrations/018.js (limited to 'app/scripts/migrations/018.js') 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 +} -- cgit v1.2.3 From 1af797b1b3a37d8fe00afbd0d84cb3349b8fd471 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 14 Aug 2017 19:15:36 -0700 Subject: tx controller - tx state history various small fixes --- app/scripts/migrations/018.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/migrations/018.js') diff --git a/app/scripts/migrations/018.js b/app/scripts/migrations/018.js index c8d2332ab..41e7de391 100644 --- a/app/scripts/migrations/018.js +++ b/app/scripts/migrations/018.js @@ -32,7 +32,7 @@ function transformState (state) { const transactions = newState.TransactionController.transactions newState.TransactionController.transactions = transactions.map((txMeta) => { // no history: initialize - if (!txMeta.history || tx.history.length === 0) { + if (!txMeta.history || txMeta.history.length === 0) { const snapshot = txStateHistoryHelper.snapshotFromTxMeta(txMeta) txMeta.history = [snapshot] return txMeta -- cgit v1.2.3 From ac2b572c3442a42286f3d10be454e3b21d06dde8 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 14 Aug 2017 20:05:57 -0700 Subject: migration 18 - fix an oops --- app/scripts/migrations/018.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/migrations/018.js') diff --git a/app/scripts/migrations/018.js b/app/scripts/migrations/018.js index 41e7de391..d27fe3f46 100644 --- a/app/scripts/migrations/018.js +++ b/app/scripts/migrations/018.js @@ -7,7 +7,7 @@ This migration updates "transaction state history" to diffs style */ const clone = require('clone') -const txStateHistoryHelper = require('../tx-state-history-helper') +const txStateHistoryHelper = require('../lib/tx-state-history-helper') module.exports = { -- cgit v1.2.3