diff options
author | kumavis <aaron@kumavis.me> | 2017-01-12 18:24:33 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2017-01-12 18:24:33 +0800 |
commit | 80514d73b5bc6887cea877194091c941cfb9a8e6 (patch) | |
tree | 24e051368ffe23fdc126ae30407f79febb4a7760 /app/scripts/migrations | |
parent | b33c51c0a6c7c8a7b0c0a9a6ca101f874f2db3d1 (diff) | |
download | tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.gz tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.zst tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.zip |
migrations - wip - 005 multivault migration
Diffstat (limited to 'app/scripts/migrations')
-rw-r--r-- | app/scripts/migrations/002.js | 12 | ||||
-rw-r--r-- | app/scripts/migrations/003.js | 10 | ||||
-rw-r--r-- | app/scripts/migrations/004.js | 14 | ||||
-rw-r--r-- | app/scripts/migrations/005.js | 44 | ||||
-rw-r--r-- | app/scripts/migrations/index.js | 18 |
5 files changed, 80 insertions, 18 deletions
diff --git a/app/scripts/migrations/002.js b/app/scripts/migrations/002.js index 97f427d3a..476b0a43a 100644 --- a/app/scripts/migrations/002.js +++ b/app/scripts/migrations/002.js @@ -3,14 +3,14 @@ const version = 2 module.exports = { version, - migrate: function (meta) { - meta.version = version + migrate: function (versionedData) { + versionedData.meta.version = version try { - if (meta.data.config.provider.type === 'etherscan') { - meta.data.config.provider.type = 'rpc' - meta.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 Promise.resolve(meta) + return Promise.resolve(versionedData) }, } diff --git a/app/scripts/migrations/003.js b/app/scripts/migrations/003.js index b25e26e01..eceaeaa4b 100644 --- a/app/scripts/migrations/003.js +++ b/app/scripts/migrations/003.js @@ -5,13 +5,13 @@ const newTestRpc = 'https://testrpc.metamask.io/' module.exports = { version, - migrate: function (meta) { - meta.version = version + migrate: function (versionedData) { + versionedData.meta.version = version try { - if (meta.data.config.provider.rpcTarget === oldTestRpc) { - meta.data.config.provider.rpcTarget = newTestRpc + if (versionedData.data.config.provider.rpcTarget === oldTestRpc) { + versionedData.data.config.provider.rpcTarget = newTestRpc } } catch (e) {} - return Promise.resolve(meta) + return Promise.resolve(versionedData) }, } diff --git a/app/scripts/migrations/004.js b/app/scripts/migrations/004.js index e72eef2b7..0f9850208 100644 --- a/app/scripts/migrations/004.js +++ b/app/scripts/migrations/004.js @@ -3,23 +3,23 @@ const version = 4 module.exports = { version, - migrate: function (meta) { - meta.version = version + migrate: function (versionedData) { + versionedData.meta.version = version try { - if (meta.data.config.provider.type !== 'rpc') return Promise.resolve(meta) - switch (meta.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/': - meta.data.config.provider = { + versionedData.data.config.provider = { type: 'testnet', } break case 'https://rpc.metamask.io/': - meta.data.config.provider = { + versionedData.data.config.provider = { type: 'mainnet', } break } } catch (_) {} - return Promise.resolve(meta) + return Promise.resolve(versionedData) }, } diff --git a/app/scripts/migrations/005.js b/app/scripts/migrations/005.js new file mode 100644 index 000000000..4c76b1dcf --- /dev/null +++ b/app/scripts/migrations/005.js @@ -0,0 +1,44 @@ +const version = 5 + +const ObservableStore = require('../../app/scripts/lib/observable/') +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..d2ac221b9 --- /dev/null +++ b/app/scripts/migrations/index.js @@ -0,0 +1,18 @@ +/* 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'), +] |