diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-12-09 06:22:02 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-12-09 06:22:02 +0800 |
commit | ab9e15b782620002c0a2477829db3e56a25a7d5c (patch) | |
tree | f35f27db6ecd1dc04649a4d9c13625580e4b98e5 /app | |
parent | 9e3fa3cfba20299413df87d18158180c7798d2ac (diff) | |
download | tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.gz tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.bz2 tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.lz tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.xz tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.tar.zst tangerine-wallet-browser-ab9e15b782620002c0a2477829db3e56a25a7d5c.zip |
Mostly added bad account detection
Currently riddled with logs, because the migrator is inexplicably returning before generating the new style accounts for comparison.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/keyring-controller.js | 8 | ||||
-rw-r--r-- | app/scripts/keyrings/hd.js | 8 | ||||
-rw-r--r-- | app/scripts/lib/config-manager.js | 12 | ||||
-rw-r--r-- | app/scripts/lib/idStore-migrator.js | 55 |
4 files changed, 74 insertions, 9 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 40c9695dd..d0ce16cbb 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -113,6 +113,7 @@ module.exports = class KeyringController extends EventEmitter { conversionDate: this.configManager.getConversionDate(), keyringTypes: this.keyringTypes.map(krt => krt.type), identities: this.identities, + lostAccounts: this.configManager.getLostAccounts(), } } @@ -623,7 +624,12 @@ module.exports = class KeyringController extends EventEmitter { migrateOldVaultIfAny (password) { const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault() return this.idStoreMigrator.migratedVaultForPassword(password) - .then((serialized) => { + .then((result) => { + console.log('migrator called back with') + console.dir(result) + const { serialized, lostAccounts } = result + console.dir({ serialized, lostAccounts }) + this.configManager.setLostAccounts(lostAccounts) this.password = password if (serialized && shouldMigrate) { diff --git a/app/scripts/keyrings/hd.js b/app/scripts/keyrings/hd.js index cfec56561..55c008601 100644 --- a/app/scripts/keyrings/hd.js +++ b/app/scripts/keyrings/hd.js @@ -38,16 +38,18 @@ class HdKeyring extends EventEmitter { } if ('numberOfAccounts' in opts) { - this.addAccounts(opts.numberOfAccounts) + console.log('number of accounts detected, adding accounts.') + return this.addAccounts(opts.numberOfAccounts) } - return Promise.resolve() + return Promise.resolve([]) } addAccounts (numberOfAccounts = 1) { if (!this.root) { this._initFromMnemonic(bip39.generateMnemonic()) } + console.log('attempting to add %s accounts', numberOfAccounts) const oldLen = this.wallets.length const newWallets = [] @@ -57,7 +59,9 @@ class HdKeyring extends EventEmitter { newWallets.push(wallet) this.wallets.push(wallet) } + console.log('hd has %s wallets', this.wallets.length) const hexWallets = newWallets.map(w => w.getAddress().toString('hex')) + console.log('hd calling back w promise of hex wallets ' + hexWallets) return Promise.resolve(hexWallets) } diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 59cc2b63c..efc0b4628 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -432,3 +432,15 @@ ConfigManager.prototype.setGasMultiplier = function (gasMultiplier) { data.gasMultiplier = gasMultiplier this.setData(data) } + +ConfigManager.prototype.setLostAccounts = function (lostAccounts) { + var data = this.getData() + data.lostAccounts = lostAccounts + this.setData(data) +} + +ConfigManager.prototype.getLostAccounts = function () { + var data = this.getData() + return ('lostAccounts' in data) && data.lostAccounts || [] +} + diff --git a/app/scripts/lib/idStore-migrator.js b/app/scripts/lib/idStore-migrator.js index 40b08efee..c13015b96 100644 --- a/app/scripts/lib/idStore-migrator.js +++ b/app/scripts/lib/idStore-migrator.js @@ -1,5 +1,7 @@ const IdentityStore = require('./idStore') - +const HdKeyring = require('../keyrings/hd') +const sigUtil = require('./sig-util') +const normalize = sigUtil.normalize module.exports = class IdentityStoreMigrator { @@ -12,25 +14,34 @@ module.exports = class IdentityStoreMigrator { } migratedVaultForPassword (password) { + console.log('migrating vault for password') const hasOldVault = this.hasOldVault() const configManager = this.configManager if (!this.idStore) { + console.log('initializing id store') this.idStore = new IdentityStore({ configManager }) + console.log('initialized') } if (!hasOldVault) { + console.log('no old vault recognized') return Promise.resolve(null) } + console.log('returning new promise') return new Promise((resolve, reject) => { + console.log('submitting password to idStore') this.idStore.submitPassword(password, (err) => { + console.log('returned ' + err) if (err) return reject(err) - try { - resolve(this.serializeVault()) - } catch (e) { - reject(e) - } + console.log('serializing vault') + const serialized = this.serializeVault() + console.log('migrated and serialized into') + console.dir(serialized) + this.checkForErrors(serialized) + .then(resolve) + .catch(reject) }) }) } @@ -45,6 +56,38 @@ module.exports = class IdentityStoreMigrator { } } + checkForErrors (serialized) { + console.log('checking for errors, first making hd wallet') + const hd = new HdKeyring() + return hd.deserialize(serialized) + .then(() => { + console.log('deserialized, now getting accounts') + console.dir(arguments) + return hd.getAccounts() + }) + .then((hexAccounts) => { + console.log('hd returned accounts', hexAccounts) + const newAccounts = hexAccounts.map(normalize) + const oldAccounts = this.idStore._getAddresses().map(normalize) + const lostAccounts = oldAccounts.reduce((result, account) => { + if (newAccounts.includes(account)) { + return result + } else { + result.push(account) + return result + } + }, []) + + console.log('migrator has') + console.dir({ newAccounts, oldAccounts, lostAccounts, hexAccounts }) + + return { + serialized, + lostAccounts, + } + }) + } + hasOldVault () { const wallet = this.configManager.getWallet() return wallet |