1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Merge branch 'master' into i1407-FixNonEditingTxForm

This commit is contained in:
Dan Finlay 2017-05-15 15:36:03 -07:00
commit 6abdec608e
8 changed files with 282 additions and 5777 deletions

View File

@ -2,6 +2,8 @@
## Current Master
- Trim currency list.
## 3.6.4 2017-5-8
- Fix main-net ENS resolution.

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,5 @@
const urlUtil = require('url')
const endOfStream = require('end-of-stream')
const asyncQ = require('async-q')
const pipe = require('pump')
const LocalStorageStore = require('obs-store/lib/localStorage')
const storeTransform = require('obs-store/lib/transform')
@ -30,34 +29,29 @@ let popupIsOpen = false
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
// initialization flow
asyncQ.waterfall([
() => loadStateFromPersistence(),
(initState) => setupController(initState),
])
.then(() => console.log('MetaMask initialization complete.'))
.catch((err) => { console.error(err) })
initialize().catch(console.error)
async function initialize() {
const initState = await loadStateFromPersistence()
await setupController(initState)
console.log('MetaMask initialization complete.')
}
//
// State and Persistence
//
function loadStateFromPersistence () {
async function loadStateFromPersistence () {
// migrations
const migrator = new Migrator({ migrations })
const initialState = migrator.generateInitialState(firstTimeState)
return asyncQ.waterfall([
// read from disk
() => Promise.resolve(diskStore.getState() || initialState),
// migrate data
(versionedData) => migrator.migrateData(versionedData),
// write to disk
(versionedData) => {
diskStore.putState(versionedData)
return Promise.resolve(versionedData)
},
// resolve to just data
(versionedData) => Promise.resolve(versionedData.data),
])
// read from disk
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
// migrate data
versionedData = await migrator.migrateData(versionedData)
// write to disk
diskStore.putState(versionedData)
// return just the data
return versionedData.data
}
function setupController (initState) {

View File

@ -1,42 +1,35 @@
const asyncQ = require('async-q')
class Migrator {
constructor (opts = {}) {
const migrations = opts.migrations || []
// sort migrations by version
this.migrations = migrations.sort((a, b) => a.version - b.version)
// grab migration with highest version
const lastMigration = this.migrations.slice(-1)[0]
// use specified defaultVersion or highest migration version
this.defaultVersion = opts.defaultVersion || (lastMigration && lastMigration.version) || 0
}
// run all pending migrations on meta in place
migrateData (versionedData = this.generateInitialState()) {
const remaining = this.migrations.filter(migrationIsPending)
async migrateData (versionedData = this.generateInitialState()) {
const pendingMigrations = this.migrations.filter(migrationIsPending)
return (
asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration))
.then(() => versionedData)
)
for (let index in pendingMigrations) {
let migration = pendingMigrations[index]
versionedData = await migration.migrate(versionedData)
if (!versionedData.data) throw new Error('Migrator - migration returned empty data')
if (versionedData.version !== undefined && versionedData.meta.version !== migration.version) throw new Error('Migrator - Migration did not update version number correctly')
}
// migration is "pending" if hit has a higher
return versionedData
// migration is "pending" if it has a higher
// version number than currentVersion
function migrationIsPending (migration) {
return migration.version > versionedData.meta.version
}
}
runMigration (versionedData, migration) {
return (
migration.migrate(versionedData)
.then((versionedData) => {
if (!versionedData.data) return Promise.reject(new Error('Migrator - Migration returned empty data'))
if (migration.version !== undefined && versionedData.meta.version !== migration.version) return Promise.reject(new Error('Migrator - Migration did not update version number correctly'))
return Promise.resolve(versionedData)
})
)
}
generateInitialState (initState) {
return {
meta: {

View File

@ -1,6 +1,6 @@
machine:
node:
version: 6.0.0
version: 7.6.0
dependencies:
pre:
- "npm i -g testem"

View File

@ -35,7 +35,7 @@
{
"presets": [
"es2015",
"stage-3"
"stage-0"
]
}
],
@ -45,7 +45,6 @@
},
"dependencies": {
"async": "^1.5.2",
"async-q": "^0.3.1",
"babel-runtime": "^6.23.0",
"bip39": "^2.2.0",
"bluebird": "^3.5.0",
@ -129,7 +128,7 @@
"devDependencies": {
"babel-eslint": "^6.0.5",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-stage-3": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.7.2",
"babelify": "^7.2.0",
"beefy": "^2.1.5",

View File

@ -0,0 +1,41 @@
const assert = require('assert')
const clone = require('clone')
const Migrator = require('../../app/scripts/lib/migrator/')
const migrations = [
{
version: 1,
migrate: (data) => {
// clone the data just like we do in migrations
const clonedData = clone(data)
clonedData.meta.version = 1
return Promise.resolve(clonedData)
},
},
{
version: 2,
migrate: (data) => {
const clonedData = clone(data)
clonedData.meta.version = 2
return Promise.resolve(clonedData)
},
},
{
version: 3,
migrate: (data) => {
const clonedData = clone(data)
clonedData.meta.version = 3
return Promise.resolve(clonedData)
},
},
]
const versionedData = {meta: {version: 0}, data:{hello:'world'}}
describe('Migrator', () => {
const migrator = new Migrator({ migrations })
it('migratedData version should be version 3', (done) => {
migrator.migrateData(versionedData)
.then((migratedData) => {
assert.equal(migratedData.meta.version, migrations[2].version)
done()
}).catch(done)
})
})

File diff suppressed because it is too large Load Diff