Merge branch 'dev' into integrateTxManagerUI

feature/default_network_editable
Frankie 8 years ago
commit 0b59dafc34
  1. 1
      .gitignore
  2. 3
      CHANGELOG.md
  3. 7
      app/scripts/lib/config-manager.js
  4. 17
      app/scripts/lib/tx-utils.js
  5. 23
      app/scripts/metamask-controller.js
  6. 117
      gulpfile.js
  7. 8
      package.json
  8. 4
      test/unit/config-manager-test.js

1
.gitignore vendored

@ -9,6 +9,7 @@ test/bower_components
package package
.DS_Store .DS_Store
builds/ builds/
disc/
notes.txt notes.txt
app/.DS_Store app/.DS_Store
development/bundle.js development/bundle.js

@ -2,8 +2,11 @@
## Current Master ## Current Master
- Fix memory leak in RPC Cache
- Override RPC commands eth_syncing and web3_clientVersion
- Remove certain non-essential permissions from certain builds. - Remove certain non-essential permissions from certain builds.
- Add a check for when a tx is included in a block. - Add a check for when a tx is included in a block.
- Fix bug where browser-solidity would sometimes warn of a contract creation error when there was none.
- Minor modifications to network display. - Minor modifications to network display.
- Network now displays properly for pending transactions. - Network now displays properly for pending transactions.
- Implement replay attack protections allowed by EIP 155. - Implement replay attack protections allowed by EIP 155.

@ -1,7 +1,6 @@
const Migrator = require('pojo-migrator') const Migrator = require('pojo-migrator')
const MetamaskConfig = require('../config.js') const MetamaskConfig = require('../config.js')
const migrations = require('./migrations') const migrations = require('./migrations')
const rp = require('request-promise')
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
const normalize = require('./sig-util').normalize const normalize = require('./sig-util').normalize
@ -301,9 +300,9 @@ ConfigManager.prototype.getCurrentFiat = function () {
ConfigManager.prototype.updateConversionRate = function () { ConfigManager.prototype.updateConversionRate = function () {
var data = this.getData() var data = this.getData()
return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) return fetch(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`)
.then((response) => { .then(response => response.json())
const parsedResponse = JSON.parse(response) .then((parsedResponse) => {
this.setConversionPrice(parsedResponse.ticker.price) this.setConversionPrice(parsedResponse.ticker.price)
this.setConversionDate(parsedResponse.timestamp) this.setConversionDate(parsedResponse.timestamp)
}).catch((err) => { }).catch((err) => {

@ -20,7 +20,6 @@ module.exports = class txProviderUtils {
if (err) return cb(err) if (err) return cb(err)
async.waterfall([ async.waterfall([
self.estimateTxGas.bind(self, txData, block.gasLimit), self.estimateTxGas.bind(self, txData, block.gasLimit),
self.checkForTxGasError.bind(self, txData),
self.setTxGas.bind(self, txData, block.gasLimit), self.setTxGas.bind(self, txData, block.gasLimit),
], cb) ], cb)
}) })
@ -38,22 +37,10 @@ module.exports = class txProviderUtils {
this.query.estimateGas(txParams, cb) this.query.estimateGas(txParams, cb)
} }
checkForTxGasError (txData, estimatedGasHex, cb) { setTxGas (txData, blockGasLimitHex, estimatedGasHex, cb) {
txData.estimatedGas = estimatedGasHex txData.estimatedGas = estimatedGasHex
// all gas used - must be an error
if (estimatedGasHex === txData.txParams.gas) {
txData.simulationFails = true
}
cb()
}
setTxGas (txData, blockGasLimitHex, cb) {
const txParams = txData.txParams const txParams = txData.txParams
// if OOG, nothing more to do
if (txData.simulationFails) {
cb()
return
}
// if gasLimit was specified and doesnt OOG, // if gasLimit was specified and doesnt OOG,
// use original specified amount // use original specified amount
if (txData.gasLimitSpecified) { if (txData.gasLimitSpecified) {

@ -13,6 +13,7 @@ const extension = require('./lib/extension')
const autoFaucet = require('./lib/auto-faucet') const autoFaucet = require('./lib/auto-faucet')
const nodeify = require('./lib/nodeify') const nodeify = require('./lib/nodeify')
const IdStoreMigrator = require('./lib/idStore-migrator') const IdStoreMigrator = require('./lib/idStore-migrator')
const version = require('../manifest.json').version
module.exports = class MetamaskController extends EventEmitter { module.exports = class MetamaskController extends EventEmitter {
@ -176,6 +177,10 @@ module.exports = class MetamaskController extends EventEmitter {
const keyringController = this.keyringController const keyringController = this.keyringController
var providerOpts = { var providerOpts = {
static: {
eth_syncing: false,
web3_clientVersion: `MetaMask/v${version}`,
},
rpcUrl: this.configManager.getCurrentRpcAddress(), rpcUrl: this.configManager.getCurrentRpcAddress(),
// account mgmt // account mgmt
getAccounts: (cb) => { getAccounts: (cb) => {
@ -224,37 +229,21 @@ module.exports = class MetamaskController extends EventEmitter {
initPublicConfigStore () { initPublicConfigStore () {
// get init state // get init state
var initPublicState = extend( var initPublicState = configToPublic(this.configManager.getConfig())
keyringControllerToPublic(this.keyringController.getState()),
configToPublic(this.configManager.getConfig())
)
var publicConfigStore = new HostStore(initPublicState) var publicConfigStore = new HostStore(initPublicState)
// subscribe to changes // subscribe to changes
this.configManager.subscribe(function (state) { this.configManager.subscribe(function (state) {
storeSetFromObj(publicConfigStore, configToPublic(state)) storeSetFromObj(publicConfigStore, configToPublic(state))
}) })
this.keyringController.on('update', () => {
const state = this.keyringController.getState()
storeSetFromObj(publicConfigStore, keyringControllerToPublic(state))
this.sendUpdate()
})
this.keyringController.on('newAccount', (account) => { this.keyringController.on('newAccount', (account) => {
autoFaucet(account) autoFaucet(account)
}) })
// keyringController substate
function keyringControllerToPublic (state) {
return {
selectedAccount: state.selectedAccount,
}
}
// config substate // config substate
function configToPublic (state) { function configToPublic (state) {
return { return {
provider: state.provider,
selectedAccount: state.selectedAccount, selectedAccount: state.selectedAccount,
} }
} }

@ -1,5 +1,6 @@
var watchify = require('watchify') var watchify = require('watchify')
var browserify = require('browserify') var browserify = require('browserify')
var disc = require('disc')
var gulp = require('gulp') var gulp = require('gulp')
var source = require('vinyl-source-stream') var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer') var buffer = require('vinyl-buffer')
@ -10,7 +11,6 @@ var jsoneditor = require('gulp-json-editor')
var zip = require('gulp-zip') var zip = require('gulp-zip')
var assign = require('lodash.assign') var assign = require('lodash.assign')
var livereload = require('gulp-livereload') var livereload = require('gulp-livereload')
var brfs = require('gulp-brfs')
var del = require('del') var del = require('del')
var eslint = require('gulp-eslint') var eslint = require('gulp-eslint')
var fs = require('fs') var fs = require('fs')
@ -21,6 +21,7 @@ var replace = require('gulp-replace')
var disclaimer = fs.readFileSync(path.join(__dirname, 'USER_AGREEMENT.md')).toString() var disclaimer = fs.readFileSync(path.join(__dirname, 'USER_AGREEMENT.md')).toString()
var crypto = require('crypto') var crypto = require('crypto')
var hash = crypto.createHash('sha256') var hash = crypto.createHash('sha256')
var mkdirp = require('mkdirp')
hash.update(disclaimer) hash.update(disclaimer)
var tosHash = hash.digest('hex') var tosHash = hash.digest('hex')
@ -33,7 +34,6 @@ var debug = gutil.env.debug
gulp.task('dev:reload', function() { gulp.task('dev:reload', function() {
livereload.listen({ livereload.listen({
port: 35729, port: 35729,
// basePath: './dist/firefox/'
}) })
}) })
@ -172,18 +172,27 @@ const jsFiles = [
'popup', 'popup',
] ]
// bundle tasks
var jsDevStrings = jsFiles.map(jsFile => `dev:js:${jsFile}`) var jsDevStrings = jsFiles.map(jsFile => `dev:js:${jsFile}`)
var jsBuildStrings = jsFiles.map(jsFile => `build:js:${jsFile}`) var jsBuildStrings = jsFiles.map(jsFile => `build:js:${jsFile}`)
jsFiles.forEach((jsFile) => { jsFiles.forEach((jsFile) => {
gulp.task(`dev:js:${jsFile}`, bundleTask({ watch: true, filename: `${jsFile}.js` })) gulp.task(`dev:js:${jsFile}`, bundleTask({ watch: true, label: jsFile, filename: `${jsFile}.js` }))
gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, filename: `${jsFile}.js` })) gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, label: jsFile, filename: `${jsFile}.js` }))
}) })
gulp.task('dev:js', gulp.parallel(...jsDevStrings)) gulp.task('dev:js', gulp.parallel(...jsDevStrings))
gulp.task('build:js', gulp.parallel(...jsBuildStrings)) gulp.task('build:js', gulp.parallel(...jsBuildStrings))
// disc bundle analyzer tasks
jsFiles.forEach((jsFile) => {
gulp.task(`disc:${jsFile}`, bundleTask({ label: jsFile, filename: `${jsFile}.js` }))
})
gulp.task('disc', gulp.parallel(jsFiles.map(jsFile => `disc:${jsFile}`)))
// clean dist // clean dist
@ -193,26 +202,10 @@ gulp.task('clean', function clean() {
}) })
// zip tasks for distribution // zip tasks for distribution
gulp.task('zip:chrome', () => { gulp.task('zip:chrome', zipTask('chrome'))
return gulp.src('dist/chrome/**') gulp.task('zip:firefox', zipTask('firefox'))
.pipe(zip(`metamask-chrome-${manifest.version}.zip`)) gulp.task('zip:edge', zipTask('edge'))
.pipe(gulp.dest('builds')); gulp.task('zip:opera', zipTask('opera'))
})
gulp.task('zip:firefox', () => {
return gulp.src('dist/firefox/**')
.pipe(zip(`metamask-firefox-${manifest.version}.zip`))
.pipe(gulp.dest('builds'));
})
gulp.task('zip:edge', () => {
return gulp.src('dist/edge/**')
.pipe(zip(`metamask-edge-${manifest.version}.zip`))
.pipe(gulp.dest('builds'));
})
gulp.task('zip:opera', () => {
return gulp.src('dist/opera/**')
.pipe(zip(`metamask-opera-${manifest.version}.zip`))
.pipe(gulp.dest('builds'));
})
gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge', 'zip:opera')) gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge', 'zip:opera'))
// high level tasks // high level tasks
@ -243,21 +236,65 @@ function copyTask(opts){
} }
} }
function bundleTask(opts) { function zipTask(target) {
return () => {
return gulp.src(`dist/${target}/**`)
.pipe(zip(`metamask-${target}-${manifest.version}.zip`))
.pipe(gulp.dest('builds'));
}
}
function generateBundler(opts) {
var browserifyOpts = assign({}, watchify.args, { var browserifyOpts = assign({}, watchify.args, {
entries: ['./app/scripts/'+opts.filename], entries: ['./app/scripts/'+opts.filename],
debug: true,
plugin: 'browserify-derequire', plugin: 'browserify-derequire',
debug: debug,
fullPaths: debug,
}) })
var bundler = browserify(browserifyOpts) return browserify(browserifyOpts)
bundler.transform('brfs') }
function discTask(opts) {
let bundler = generateBundler(opts)
if (opts.watch) {
bundler = watchify(bundler)
// on any dep update, runs the bundler
bundler.on('update', performBundle)
}
// output build logs to terminal
bundler.on('log', gutil.log)
return performBundle
function performBundle(){
// start "disc" build
let discDir = path.join(__dirname, 'disc')
mkdirp.sync(discDir)
let discPath = path.join(discDir, `${opts.label}.html`)
return (
bundler.bundle()
.pipe(disc())
.pipe(fs.createWriteStream(discPath))
)
}
}
function bundleTask(opts) {
let bundler = generateBundler(opts)
if (opts.watch) { if (opts.watch) {
bundler = watchify(bundler) bundler = watchify(bundler)
bundler.on('update', performBundle) // on any dep update, runs the bundler // on any file update, re-runs the bundler
bundler.on('update', performBundle)
} }
bundler.on('log', gutil.log) // output build logs to terminal // output build logs to terminal
bundler.on('log', gutil.log)
return performBundle return performBundle
@ -267,21 +304,25 @@ function bundleTask(opts) {
bundler.bundle() bundler.bundle()
// log errors if they happen // log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error')) .on('error', gutil.log.bind(gutil, 'Browserify Error'))
// convert bundle stream to gulp vinyl stream
.pipe(source(opts.filename)) .pipe(source(opts.filename))
.pipe(brfs()) // inject variables into bundle
.pipe(replace('GULP_TOS_HASH', tosHash)) .pipe(replace('GULP_TOS_HASH', tosHash))
.pipe(replace('\'GULP_METAMASK_DEBUG\'', debug)) .pipe(replace('\'GULP_METAMASK_DEBUG\'', debug))
// optional, remove if you don't need to buffer file contents // buffer file contents (?)
.pipe(buffer()) .pipe(buffer())
// optional, remove if you dont want sourcemaps // sourcemaps
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file // loads map from browserify file
// Add transformation tasks to the pipeline here. .pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./')) // writes .map file // writes .map file
.pipe(sourcemaps.write('./'))
// write completed bundles
.pipe(gulp.dest('./dist/firefox/scripts')) .pipe(gulp.dest('./dist/firefox/scripts'))
.pipe(gulp.dest('./dist/chrome/scripts')) .pipe(gulp.dest('./dist/chrome/scripts'))
.pipe(gulp.dest('./dist/edge/scripts')) .pipe(gulp.dest('./dist/edge/scripts'))
.pipe(gulp.dest('./dist/opera/scripts')) .pipe(gulp.dest('./dist/opera/scripts'))
.pipe(gulpif(!disableLiveReload,livereload())) // finally, trigger live reload
.pipe(gulpif(!disableLiveReload, livereload()))
) )
} }

@ -8,6 +8,7 @@
"lint": "gulp lint", "lint": "gulp lint",
"buildCiUnits": "node test/integration/index.js", "buildCiUnits": "node test/integration/index.js",
"dev": "gulp dev --debug", "dev": "gulp dev --debug",
"disc": "gulp disc --debug",
"dist": "gulp dist --disableLiveReload", "dist": "gulp dist --disableLiveReload",
"test": "npm run fastTest && npm run ci && npm run lint", "test": "npm run fastTest && npm run ci && npm run lint",
"fastTest": "METAMASK_ENV=test mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "fastTest": "METAMASK_ENV=test mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"",
@ -43,6 +44,7 @@
"copy-to-clipboard": "^2.0.0", "copy-to-clipboard": "^2.0.0",
"debounce": "^1.0.0", "debounce": "^1.0.0",
"denodeify": "^1.2.1", "denodeify": "^1.2.1",
"disc": "^1.3.2",
"dnode": "^1.2.2", "dnode": "^1.2.2",
"end-of-stream": "^1.1.0", "end-of-stream": "^1.1.0",
"ensnare": "^1.0.0", "ensnare": "^1.0.0",
@ -65,6 +67,7 @@
"menu-droppo": "^1.1.0", "menu-droppo": "^1.1.0",
"metamask-logo": "^2.1.2", "metamask-logo": "^2.1.2",
"mississippi": "^1.2.0", "mississippi": "^1.2.0",
"mkdirp": "^0.5.1",
"multiplex": "^6.7.0", "multiplex": "^6.7.0",
"once": "^1.3.3", "once": "^1.3.3",
"ping-pong-stream": "^1.0.0", "ping-pong-stream": "^1.0.0",
@ -85,7 +88,6 @@
"redux": "^3.0.5", "redux": "^3.0.5",
"redux-logger": "^2.3.1", "redux-logger": "^2.3.1",
"redux-thunk": "^1.0.2", "redux-thunk": "^1.0.2",
"request-promise": "^4.1.1",
"sandwich-expando": "^1.0.5", "sandwich-expando": "^1.0.5",
"textarea-caret": "^3.0.1", "textarea-caret": "^3.0.1",
"three.js": "^0.73.2", "three.js": "^0.73.2",
@ -93,7 +95,7 @@
"valid-url": "^1.0.9", "valid-url": "^1.0.9",
"vreme": "^3.0.2", "vreme": "^3.0.2",
"web3": "0.17.0-beta", "web3": "0.17.0-beta",
"web3-provider-engine": "^8.1.14", "web3-provider-engine": "^8.2.0",
"web3-stream-provider": "^2.0.6", "web3-stream-provider": "^2.0.6",
"xtend": "^4.0.1" "xtend": "^4.0.1"
}, },
@ -109,7 +111,6 @@
"del": "^2.2.0", "del": "^2.2.0",
"fs-promise": "^1.0.0", "fs-promise": "^1.0.0",
"gulp": "github:gulpjs/gulp#4.0", "gulp": "github:gulpjs/gulp#4.0",
"gulp-brfs": "^0.1.0",
"gulp-if": "^2.0.1", "gulp-if": "^2.0.1",
"gulp-json-editor": "^2.2.1", "gulp-json-editor": "^2.2.1",
"gulp-livereload": "^3.8.1", "gulp-livereload": "^3.8.1",
@ -118,6 +119,7 @@
"gulp-util": "^3.0.7", "gulp-util": "^3.0.7",
"gulp-watch": "^4.3.5", "gulp-watch": "^4.3.5",
"gulp-zip": "^3.2.0", "gulp-zip": "^3.2.0",
"isomorphic-fetch": "^2.2.1",
"jsdom": "^8.1.0", "jsdom": "^8.1.0",
"jsdom-global": "^1.7.0", "jsdom-global": "^1.7.0",
"jshint-stylish": "~0.1.5", "jshint-stylish": "~0.1.5",

@ -1,8 +1,10 @@
// polyfill fetch
global.fetch = global.fetch || require('isomorphic-fetch')
const assert = require('assert') const assert = require('assert')
const extend = require('xtend') const extend = require('xtend')
const rp = require('request-promise') const rp = require('request-promise')
const nock = require('nock') const nock = require('nock')
var configManagerGen = require('../lib/mock-config-manager') const configManagerGen = require('../lib/mock-config-manager')
const STORAGE_KEY = 'metamask-persistance-key' const STORAGE_KEY = 'metamask-persistance-key'
describe('config-manager', function() { describe('config-manager', function() {

Loading…
Cancel
Save