diff options
author | kumavis <kumavis@users.noreply.github.com> | 2017-02-08 10:55:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 10:55:26 +0800 |
commit | c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9 (patch) | |
tree | 139d5dfad53652b50e0af07c3aec37394b3b654b /app/scripts/migrations | |
parent | ffe588365cb2dd84906613d13ad8e35b08a08dbb (diff) | |
parent | ce57957aa0fdeb79efd6ede8b6e94b8f26131dcf (diff) | |
download | tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.tar tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.tar.gz tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.tar.bz2 tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.tar.lz tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.tar.xz tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.tar.zst tangerine-wallet-browser-c9aab2084ec7dd8b81b02c9053a8fcbb6038e0b9.zip |
Merge pull request #1094 from MetaMask/dev
Version 3.2.0
Diffstat (limited to 'app/scripts/migrations')
-rw-r--r-- | app/scripts/migrations/002.js | 15 | ||||
-rw-r--r-- | app/scripts/migrations/003.js | 16 | ||||
-rw-r--r-- | app/scripts/migrations/004.js | 17 | ||||
-rw-r--r-- | app/scripts/migrations/005.js | 41 | ||||
-rw-r--r-- | app/scripts/migrations/006.js | 41 | ||||
-rw-r--r-- | app/scripts/migrations/007.js | 38 | ||||
-rw-r--r-- | app/scripts/migrations/008.js | 36 | ||||
-rw-r--r-- | app/scripts/migrations/009.js | 40 | ||||
-rw-r--r-- | app/scripts/migrations/010.js | 36 | ||||
-rw-r--r-- | app/scripts/migrations/_multi-keyring.js | 51 | ||||
-rw-r--r-- | app/scripts/migrations/index.js | 24 |
11 files changed, 335 insertions, 20 deletions
diff --git a/app/scripts/migrations/002.js b/app/scripts/migrations/002.js index 0b654f825..476b0a43a 100644 --- a/app/scripts/migrations/002.js +++ b/app/scripts/migrations/002.js @@ -1,13 +1,16 @@ +const version = 2 + module.exports = { - version: 2, + version, - migrate: function (data) { + migrate: function (versionedData) { + versionedData.meta.version = version try { - if (data.config.provider.type === 'etherscan') { - data.config.provider.type = 'rpc' - data.config.provider.rpcTarget = 'https://rpc.metamask.io/' + if (versionedData.data.config.provider.type === 'etherscan') { + versionedData.data.config.provider.type = 'rpc' + versionedData.data.config.provider.rpcTarget = 'https://rpc.metamask.io/' } } catch (e) {} - return data + return Promise.resolve(versionedData) }, } diff --git a/app/scripts/migrations/003.js b/app/scripts/migrations/003.js index 617c55c09..eceaeaa4b 100644 --- a/app/scripts/migrations/003.js +++ b/app/scripts/migrations/003.js @@ -1,15 +1,17 @@ -var oldTestRpc = 'https://rawtestrpc.metamask.io/' -var newTestRpc = 'https://testrpc.metamask.io/' +const version = 3 +const oldTestRpc = 'https://rawtestrpc.metamask.io/' +const newTestRpc = 'https://testrpc.metamask.io/' module.exports = { - version: 3, + version, - migrate: function (data) { + migrate: function (versionedData) { + versionedData.meta.version = version try { - if (data.config.provider.rpcTarget === oldTestRpc) { - data.config.provider.rpcTarget = newTestRpc + if (versionedData.data.config.provider.rpcTarget === oldTestRpc) { + versionedData.data.config.provider.rpcTarget = newTestRpc } } catch (e) {} - return data + return Promise.resolve(versionedData) }, } diff --git a/app/scripts/migrations/004.js b/app/scripts/migrations/004.js index 1329a1eed..0f9850208 100644 --- a/app/scripts/migrations/004.js +++ b/app/scripts/migrations/004.js @@ -1,22 +1,25 @@ +const version = 4 + module.exports = { - version: 4, + version, - migrate: function (data) { + migrate: function (versionedData) { + versionedData.meta.version = version try { - if (data.config.provider.type !== 'rpc') return data - switch (data.config.provider.rpcTarget) { + if (versionedData.data.config.provider.type !== 'rpc') return Promise.resolve(versionedData) + switch (versionedData.data.config.provider.rpcTarget) { case 'https://testrpc.metamask.io/': - data.config.provider = { + versionedData.data.config.provider = { type: 'testnet', } break case 'https://rpc.metamask.io/': - data.config.provider = { + versionedData.data.config.provider = { type: 'mainnet', } break } } catch (_) {} - return data + return Promise.resolve(versionedData) }, } diff --git a/app/scripts/migrations/005.js b/app/scripts/migrations/005.js new file mode 100644 index 000000000..65f62a861 --- /dev/null +++ b/app/scripts/migrations/005.js @@ -0,0 +1,41 @@ +const version = 5 + +/* + +This migration moves state from the flat state trie into KeyringController substate + +*/ + +const extend = require('xtend') + +module.exports = { + version, + + migrate: function (versionedData) { + versionedData.meta.version = version + try { + const state = versionedData.data + const newState = selectSubstateForKeyringController(state) + versionedData.data = newState + } catch (err) { + console.warn('MetaMask Migration #5' + err.stack) + } + return Promise.resolve(versionedData) + }, +} + +function selectSubstateForKeyringController (state) { + const config = state.config + const newState = extend(state, { + KeyringController: { + vault: state.vault, + selectedAccount: config.selectedAccount, + walletNicknames: state.walletNicknames, + }, + }) + delete newState.vault + delete newState.walletNicknames + delete newState.config.selectedAccount + + return newState +} diff --git a/app/scripts/migrations/006.js b/app/scripts/migrations/006.js new file mode 100644 index 000000000..950c4deb8 --- /dev/null +++ b/app/scripts/migrations/006.js @@ -0,0 +1,41 @@ +const version = 6 + +/* + +This migration moves KeyringController.selectedAddress to PreferencesController.selectedAddress + +*/ + +const extend = require('xtend') + +module.exports = { + version, + + migrate: function (versionedData) { + versionedData.meta.version = version + try { + const state = versionedData.data + const newState = migrateState(state) + versionedData.data = newState + } catch (err) { + console.warn(`MetaMask Migration #${version}` + err.stack) + } + return Promise.resolve(versionedData) + }, +} + +function migrateState (state) { + const keyringSubstate = state.KeyringController + + // add new state + const newState = extend(state, { + PreferencesController: { + selectedAddress: keyringSubstate.selectedAccount, + }, + }) + + // rm old state + delete newState.KeyringController.selectedAccount + + return newState +} diff --git a/app/scripts/migrations/007.js b/app/scripts/migrations/007.js new file mode 100644 index 000000000..3ae8cdc2d --- /dev/null +++ b/app/scripts/migrations/007.js @@ -0,0 +1,38 @@ +const version = 7 + +/* + +This migration breaks out the TransactionManager substate + +*/ + +const extend = require('xtend') + +module.exports = { + version, + + migrate: function (versionedData) { + 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 = extend(state, { + TransactionManager: { + transactions: state.transactions || [], + gasMultiplier: state.gasMultiplier || 1, + }, + }) + delete newState.transactions + delete newState.gasMultiplier + + return newState +} diff --git a/app/scripts/migrations/008.js b/app/scripts/migrations/008.js new file mode 100644 index 000000000..7f6e72ee6 --- /dev/null +++ b/app/scripts/migrations/008.js @@ -0,0 +1,36 @@ +const version = 8 + +/* + +This migration breaks out the NoticeController substate + +*/ + +const extend = require('xtend') + +module.exports = { + version, + + migrate: function (versionedData) { + 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 = extend(state, { + NoticeController: { + noticesList: state.noticesList || [], + }, + }) + delete newState.noticesList + + return newState +} diff --git a/app/scripts/migrations/009.js b/app/scripts/migrations/009.js new file mode 100644 index 000000000..38e6dcc09 --- /dev/null +++ b/app/scripts/migrations/009.js @@ -0,0 +1,40 @@ +const version = 9 + +/* + +This migration breaks out the CurrencyController substate + +*/ + +const merge = require('deep-extend') + +module.exports = { + version, + + migrate: function (versionedData) { + 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 = merge({}, state, { + CurrencyController: { + currentCurrency: state.currentFiat || 'USD', + conversionRate: state.conversionRate, + conversionDate: state.conversionDate, + }, + }) + delete newState.currentFiat + delete newState.conversionRate + delete newState.conversionDate + + return newState +} diff --git a/app/scripts/migrations/010.js b/app/scripts/migrations/010.js new file mode 100644 index 000000000..d41c63fcd --- /dev/null +++ b/app/scripts/migrations/010.js @@ -0,0 +1,36 @@ +const version = 10 + +/* + +This migration breaks out the CurrencyController substate + +*/ + +const merge = require('deep-extend') + +module.exports = { + version, + + migrate: function (versionedData) { + 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 = merge({}, state, { + ShapeShiftController: { + shapeShiftTxList: state.shapeShiftTxList || [], + }, + }) + delete newState.shapeShiftTxList + + return newState +} diff --git a/app/scripts/migrations/_multi-keyring.js b/app/scripts/migrations/_multi-keyring.js new file mode 100644 index 000000000..04c966d4d --- /dev/null +++ b/app/scripts/migrations/_multi-keyring.js @@ -0,0 +1,51 @@ +const version = 5 + +/* + +This is an incomplete migration bc it requires post-decrypted data +which we dont have access to at the time of this writing. + +*/ + +const ObservableStore = require('obs-store') +const ConfigManager = require('../../app/scripts/lib/config-manager') +const IdentityStoreMigrator = require('../../app/scripts/lib/idStore-migrator') +const KeyringController = require('../../app/scripts/lib/keyring-controller') + +const password = 'obviously not correct' + +module.exports = { + version, + + migrate: function (versionedData) { + versionedData.meta.version = version + + let store = new ObservableStore(versionedData.data) + let configManager = new ConfigManager({ store }) + let idStoreMigrator = new IdentityStoreMigrator({ configManager }) + let keyringController = new KeyringController({ + configManager: configManager, + }) + + // attempt to migrate to multiVault + return idStoreMigrator.migratedVaultForPassword(password) + .then((result) => { + // skip if nothing to migrate + if (!result) return Promise.resolve(versionedData) + delete versionedData.data.wallet + // create new keyrings + const privKeys = result.lostAccounts.map(acct => acct.privateKey) + return Promise.all([ + keyringController.restoreKeyring(result.serialized), + keyringController.restoreKeyring({ type: 'Simple Key Pair', data: privKeys }), + ]).then(() => { + return keyringController.persistAllKeyrings(password) + }).then(() => { + // copy result on to state object + versionedData.data = store.get() + return Promise.resolve(versionedData) + }) + }) + + }, +} diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js new file mode 100644 index 000000000..2db8646b0 --- /dev/null +++ b/app/scripts/migrations/index.js @@ -0,0 +1,24 @@ +/* The migrator has two methods the user should be concerned with: + * + * getData(), which returns the app-consumable data object + * saveData(), which persists the app-consumable data object. + */ + +// Migrations must start at version 1 or later. +// They are objects with a `version` number +// and a `migrate` function. +// +// The `migrate` function receives the previous +// config data format, and returns the new one. + +module.exports = [ + require('./002'), + require('./003'), + require('./004'), + require('./005'), + require('./006'), + require('./007'), + require('./008'), + require('./009'), + require('./010'), +] |