Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove BlacklistController from disk state #3148

Merged
merged 9 commits into from
Jan 31, 2018
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Current Master

- Remove BlacklistController from disk state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to include recent blocks, or just generalize “removed unneeded data from storage”

- Add a "reset account" feature to Settings
- Add warning for importing some kinds of files.

Expand Down
11 changes: 2 additions & 9 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ module.exports = class MetamaskController extends EventEmitter {
})
this.infuraController.scheduleInfuraNetworkCheck()

this.blacklistController = new BlacklistController({
initState: initState.BlacklistController,
})
this.blacklistController = new BlacklistController()
this.blacklistController.scheduleUpdates()

// rpc provider
Expand Down Expand Up @@ -200,12 +198,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.networkController.store.subscribe((state) => {
this.store.updateState({ NetworkController: state })
})
this.blacklistController.store.subscribe((state) => {
this.store.updateState({ BlacklistController: state })
})
this.recentBlocksController.store.subscribe((state) => {
this.store.updateState({ RecentBlocks: state })
})

this.infuraController.store.subscribe((state) => {
this.store.updateState({ InfuraController: state })
})
Expand Down
34 changes: 34 additions & 0 deletions app/scripts/migrations/021.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const version = 21

/*

This migration removes the BlackListController from disk state

*/

const clone = require('clone')

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
delete newState.BlacklistController
delete newState.RecentBlocks
return newState
}

1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ module.exports = [
require('./018'),
require('./019'),
require('./020'),
require('./021'),
]
1 change: 1 addition & 0 deletions test/lib/migrations/002.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions test/unit/migrations/021-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const assert = require('assert')

const wallet2 = require('../../lib/migrations/002.json')
const migration21 = require('../../../app/scripts/migrations/021')

describe('wallet2 is migrated successfully with out the BlacklistController', () => {
it('should delete BlacklistController key', (done) => {
migration21.migrate(wallet2)
.then((migratedData) => {
assert.equal(migratedData.meta.version, 21)
assert(!migratedData.data.BlacklistController)
assert(!migratedData.data.RecentBlocks)
done()
}).catch(done)
})
})