From b301c0fb48f8a6ba464c7ed48d009166ea1fc230 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 12:04:26 -0800 Subject: [PATCH 01/12] deps - replace promise-request with fetch --- app/scripts/lib/config-manager.js | 7 +++---- package.json | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 93501c859..3a1f12ac0 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -1,7 +1,6 @@ const Migrator = require('pojo-migrator') const MetamaskConfig = require('../config.js') const migrations = require('./migrations') -const rp = require('request-promise') const ethUtil = require('ethereumjs-util') const normalize = require('./sig-util').normalize @@ -301,9 +300,9 @@ ConfigManager.prototype.getCurrentFiat = function () { ConfigManager.prototype.updateConversionRate = function () { var data = this.getData() - return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) - .then((response) => { - const parsedResponse = JSON.parse(response) + return fetch(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) + .then(response => response.json()) + .then((parsedResponse) => { this.setConversionPrice(parsedResponse.ticker.price) this.setConversionDate(parsedResponse.timestamp) }).catch((err) => { diff --git a/package.json b/package.json index 6f0fe00c7..23070cceb 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,6 @@ "redux": "^3.0.5", "redux-logger": "^2.3.1", "redux-thunk": "^1.0.2", - "request-promise": "^4.1.1", "sandwich-expando": "^1.0.5", "textarea-caret": "^3.0.1", "three.js": "^0.73.2", From bd382f4705ffdc10d193d02dfaa9d1b5ff2f1488 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 12:39:01 -0800 Subject: [PATCH 02/12] tests - add fetch polyfill --- package.json | 1 + test/unit/config-manager-test.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 23070cceb..3a02c64df 100644 --- a/package.json +++ b/package.json @@ -117,6 +117,7 @@ "gulp-util": "^3.0.7", "gulp-watch": "^4.3.5", "gulp-zip": "^3.2.0", + "isomorphic-fetch": "^2.2.1", "jsdom": "^8.1.0", "jsdom-global": "^1.7.0", "jshint-stylish": "~0.1.5", diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 075abbe65..77d431d5f 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -1,8 +1,10 @@ +// polyfill fetch +global.fetch = global.fetch || require('isomorphic-fetch') const assert = require('assert') const extend = require('xtend') const rp = require('request-promise') const nock = require('nock') -var configManagerGen = require('../lib/mock-config-manager') +const configManagerGen = require('../lib/mock-config-manager') const STORAGE_KEY = 'metamask-persistance-key' describe('config-manager', function() { From 464b7d581424c04340281878a2a0f20e73bf8188 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 13:08:13 -0800 Subject: [PATCH 03/12] gulp - clean and simplify --- gulpfile.js | 38 +++++++++++++++----------------------- package.json | 3 +-- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ca69b36a8..9f55e99a8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -193,26 +193,10 @@ gulp.task('clean', function clean() { }) // zip tasks for distribution -gulp.task('zip:chrome', () => { - return gulp.src('dist/chrome/**') - .pipe(zip(`metamask-chrome-${manifest.version}.zip`)) - .pipe(gulp.dest('builds')); -}) -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:chrome', zipTask('chrome')) +gulp.task('zip:firefox', zipTask('firefox')) +gulp.task('zip:edge', zipTask('edge')) +gulp.task('zip:opera', zipTask('opera')) gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge', 'zip:opera')) // high level tasks @@ -243,15 +227,23 @@ function copyTask(opts){ } } +function zipTask(target) { + return () => { + return gulp.src(`dist/${target}/**`) + .pipe(zip(`metamask-${target}-${manifest.version}.zip`)) + .pipe(gulp.dest('builds')); + } +} + function bundleTask(opts) { var browserifyOpts = assign({}, watchify.args, { entries: ['./app/scripts/'+opts.filename], - debug: true, plugin: 'browserify-derequire', + debug: debug, + fullPaths: debug, }) var bundler = browserify(browserifyOpts) - bundler.transform('brfs') if (opts.watch) { bundler = watchify(bundler) bundler.on('update', performBundle) // on any dep update, runs the bundler @@ -281,7 +273,7 @@ function bundleTask(opts) { .pipe(gulp.dest('./dist/chrome/scripts')) .pipe(gulp.dest('./dist/edge/scripts')) .pipe(gulp.dest('./dist/opera/scripts')) - .pipe(gulpif(!disableLiveReload,livereload())) + .pipe(gulpif(!disableLiveReload, livereload())) ) } diff --git a/package.json b/package.json index 6f0fe00c7..e49ca0c72 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,7 @@ "es2015" ] } - ], - "brfs" + ] ] }, "dependencies": { From 8e3661555d789037542d09d4135f5750d5b29222 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 13:46:15 -0800 Subject: [PATCH 04/12] gulp - add disc bundle analysis task --- .gitignore | 1 + gulpfile.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++----- package.json | 3 +++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index af6449834..c61847aab 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ test/bower_components package .DS_Store builds/ +disc/ notes.txt app/.DS_Store development/bundle.js diff --git a/gulpfile.js b/gulpfile.js index 9f55e99a8..f9eb663b6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,6 @@ var watchify = require('watchify') var browserify = require('browserify') +var disc = require('disc') var gulp = require('gulp') var source = require('vinyl-source-stream') var buffer = require('vinyl-buffer') @@ -21,6 +22,7 @@ var replace = require('gulp-replace') var disclaimer = fs.readFileSync(path.join(__dirname, 'USER_AGREEMENT.md')).toString() var crypto = require('crypto') var hash = crypto.createHash('sha256') +var mkdirp = require('mkdirp') hash.update(disclaimer) var tosHash = hash.digest('hex') @@ -172,18 +174,27 @@ const jsFiles = [ 'popup', ] +// bundle tasks + var jsDevStrings = jsFiles.map(jsFile => `dev:js:${jsFile}`) var jsBuildStrings = jsFiles.map(jsFile => `build:js:${jsFile}`) jsFiles.forEach((jsFile) => { - gulp.task(`dev:js:${jsFile}`, bundleTask({ watch: true, filename: `${jsFile}.js` })) - gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, filename: `${jsFile}.js` })) + gulp.task(`dev:js:${jsFile}`, bundleTask({ watch: true, label: jsFile, 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('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 @@ -235,7 +246,7 @@ function zipTask(target) { } } -function bundleTask(opts) { +function generateBundler(opts) { var browserifyOpts = assign({}, watchify.args, { entries: ['./app/scripts/'+opts.filename], plugin: 'browserify-derequire', @@ -243,7 +254,42 @@ function bundleTask(opts) { fullPaths: debug, }) - var bundler = browserify(browserifyOpts) + return browserify(browserifyOpts) +} + +function discTask(opts) { + let bundler = generateBundler(opts) + + if (opts.watch) { + bundler = watchify(bundler) + bundler.on('update', performBundle) // on any dep update, runs the bundler + } + + bundler.on('log', gutil.log) // output build logs to terminal + + 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)) + // .once('close', function() { + // console.log(`disc: ${opts.label} build completed.`) + // }) + ) + } +} + + +function bundleTask(opts) { + let bundler = generateBundler(opts) + if (opts.watch) { bundler = watchify(bundler) bundler.on('update', performBundle) // on any dep update, runs the bundler diff --git a/package.json b/package.json index e49ca0c72..ad9cf8f9b 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "lint": "gulp lint", "buildCiUnits": "node test/integration/index.js", "dev": "gulp dev --debug", + "disc": "gulp disc --debug", "dist": "gulp dist --disableLiveReload", "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\"", @@ -42,6 +43,7 @@ "copy-to-clipboard": "^2.0.0", "debounce": "^1.0.0", "denodeify": "^1.2.1", + "disc": "^1.3.2", "dnode": "^1.2.2", "end-of-stream": "^1.1.0", "ensnare": "^1.0.0", @@ -64,6 +66,7 @@ "menu-droppo": "^1.1.0", "metamask-logo": "^2.1.2", "mississippi": "^1.2.0", + "mkdirp": "^0.5.1", "multiplex": "^6.7.0", "once": "^1.3.3", "ping-pong-stream": "^1.0.0", From 074e3f4ab437369635a7df50abd879d6a32c70a5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 13:56:31 -0800 Subject: [PATCH 05/12] gulp - cleanup comments --- gulpfile.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index f9eb663b6..d0e8a2ced 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -35,7 +35,6 @@ var debug = gutil.env.debug gulp.task('dev:reload', function() { livereload.listen({ port: 35729, - // basePath: './dist/firefox/' }) }) @@ -262,10 +261,12 @@ function discTask(opts) { if (opts.watch) { bundler = watchify(bundler) - bundler.on('update', performBundle) // on any dep update, runs the bundler + // on any dep update, 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 @@ -279,9 +280,6 @@ function discTask(opts) { bundler.bundle() .pipe(disc()) .pipe(fs.createWriteStream(discPath)) - // .once('close', function() { - // console.log(`disc: ${opts.label} build completed.`) - // }) ) } } @@ -292,10 +290,12 @@ function bundleTask(opts) { if (opts.watch) { 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 @@ -305,20 +305,26 @@ function bundleTask(opts) { bundler.bundle() // log errors if they happen .on('error', gutil.log.bind(gutil, 'Browserify Error')) + // convert bundle stream to gulp vinyl stream .pipe(source(opts.filename)) + // gulp-level browserify transforms .pipe(brfs()) + // inject variables into bundle .pipe(replace('GULP_TOS_HASH', tosHash)) .pipe(replace('\'GULP_METAMASK_DEBUG\'', debug)) - // optional, remove if you don't need to buffer file contents + // buffer file contents (?) .pipe(buffer()) - // optional, remove if you dont want sourcemaps - .pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file - // Add transformation tasks to the pipeline here. - .pipe(sourcemaps.write('./')) // writes .map file + // sourcemaps + // loads map from browserify file + .pipe(sourcemaps.init({loadMaps: true})) + // writes .map file + .pipe(sourcemaps.write('./')) + // write completed bundles .pipe(gulp.dest('./dist/firefox/scripts')) .pipe(gulp.dest('./dist/chrome/scripts')) .pipe(gulp.dest('./dist/edge/scripts')) .pipe(gulp.dest('./dist/opera/scripts')) + // finally, trigger live reload .pipe(gulpif(!disableLiveReload, livereload())) ) From 21e2e4efd803c8c904cecf039ee73fead0e6c4c1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 10 Jan 2017 14:20:46 -0800 Subject: [PATCH 06/12] Remove erroneous OOG estimation logic. --- app/scripts/lib/tx-utils.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js index a976173f5..d1fb98f42 100644 --- a/app/scripts/lib/tx-utils.js +++ b/app/scripts/lib/tx-utils.js @@ -20,7 +20,6 @@ module.exports = class txProviderUtils { if (err) return cb(err) async.waterfall([ self.estimateTxGas.bind(self, txData, block.gasLimit), - self.checkForTxGasError.bind(self, txData), self.setTxGas.bind(self, txData, block.gasLimit), ], cb) }) @@ -38,22 +37,10 @@ module.exports = class txProviderUtils { this.query.estimateGas(txParams, cb) } - checkForTxGasError (txData, estimatedGasHex, cb) { + setTxGas (txData, blockGasLimitHex, estimatedGasHex, cb) { 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 - // if OOG, nothing more to do - if (txData.simulationFails) { - cb() - return - } + // if gasLimit was specified and doesnt OOG, // use original specified amount if (txData.gasLimitSpecified) { From 55a55754d02672982bb57c496b5773e8ea1b8869 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 10 Jan 2017 14:20:51 -0800 Subject: [PATCH 07/12] Bump changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 420296bbd..9cd13e102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Remove certain non-essential permissions from certain builds. - 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. - Network now displays properly for pending transactions. - Implement replay attack protections allowed by EIP 155. From 2efcbd9674be56984de596cd0272fb380a30609e Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 15:33:00 -0800 Subject: [PATCH 08/12] gulp - fix brfs instrumentation --- gulpfile.js | 3 --- package.json | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d0e8a2ced..1ea431aef 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,7 +11,6 @@ var jsoneditor = require('gulp-json-editor') var zip = require('gulp-zip') var assign = require('lodash.assign') var livereload = require('gulp-livereload') -var brfs = require('gulp-brfs') var del = require('del') var eslint = require('gulp-eslint') var fs = require('fs') @@ -307,8 +306,6 @@ function bundleTask(opts) { .on('error', gutil.log.bind(gutil, 'Browserify Error')) // convert bundle stream to gulp vinyl stream .pipe(source(opts.filename)) - // gulp-level browserify transforms - .pipe(brfs()) // inject variables into bundle .pipe(replace('GULP_TOS_HASH', tosHash)) .pipe(replace('\'GULP_METAMASK_DEBUG\'', debug)) diff --git a/package.json b/package.json index ad9cf8f9b..17c3e3dcc 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "es2015" ] } - ] + ], + "brfs" ] }, "dependencies": { @@ -111,7 +112,6 @@ "del": "^2.2.0", "fs-promise": "^1.0.0", "gulp": "github:gulpjs/gulp#4.0", - "gulp-brfs": "^0.1.0", "gulp-if": "^2.0.1", "gulp-json-editor": "^2.2.1", "gulp-livereload": "^3.8.1", From f6900422d13811ae5dc43149954d0d74271927ae Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 10 Jan 2017 23:35:24 -0800 Subject: [PATCH 09/12] deps - bump provider engine addresses caching memory leak that can cause slow downs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58c33c170..0d0835a86 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "0.17.0-beta", - "web3-provider-engine": "^8.1.14", + "web3-provider-engine": "^8.2.0", "web3-stream-provider": "^2.0.6", "xtend": "^4.0.1" }, From 61637c738bf0e1625b1b6f69ef3747c60d564304 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 00:46:44 -0800 Subject: [PATCH 10/12] web3 provider - override eth_syncing and web3_clientVersion --- app/scripts/metamask-controller.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 555460f3d..d79fd3cd3 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -13,6 +13,7 @@ const extension = require('./lib/extension') const autoFaucet = require('./lib/auto-faucet') const nodeify = require('./lib/nodeify') const IdStoreMigrator = require('./lib/idStore-migrator') +const version = require('../manifest.json').version module.exports = class MetamaskController extends EventEmitter { @@ -175,6 +176,10 @@ module.exports = class MetamaskController extends EventEmitter { const keyringController = this.keyringController var providerOpts = { + static: { + eth_syncing: false, + web3_clientVersion: `MetaMask/v${version}`, + }, rpcUrl: this.configManager.getCurrentRpcAddress(), // account mgmt getAccounts: (cb) => { From a9bdc76e408283b97365809801b31faf6f5b5039 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 00:48:06 -0800 Subject: [PATCH 11/12] changelog - add note on rpc overrides --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cd13e102..9f1ec6823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +- Fix memory leak in RPC Cache +- Override RPC commands eth_syncing and web3_clientVersion - Remove certain non-essential permissions from certain builds. - 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. From 26e4ff40e15c74d5fc2613d33686d480f6eed25a Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 02:33:57 -0800 Subject: [PATCH 12/12] rpc - fix sync account cache setting --- app/scripts/metamask-controller.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index d79fd3cd3..1fc97e81d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -228,37 +228,21 @@ module.exports = class MetamaskController extends EventEmitter { initPublicConfigStore () { // get init state - var initPublicState = extend( - keyringControllerToPublic(this.keyringController.getState()), - configToPublic(this.configManager.getConfig()) - ) - + var initPublicState = configToPublic(this.configManager.getConfig()) var publicConfigStore = new HostStore(initPublicState) // subscribe to changes this.configManager.subscribe(function (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) => { autoFaucet(account) }) - // keyringController substate - function keyringControllerToPublic (state) { - return { - selectedAccount: state.selectedAccount, - } - } // config substate function configToPublic (state) { return { - provider: state.provider, selectedAccount: state.selectedAccount, } }