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

Merge branch 'master' into version-debugging

This commit is contained in:
Kevin Serrano 2017-10-05 17:06:55 -07:00
commit b9012a62e5
No known key found for this signature in database
GPG Key ID: BF999DEFC7371BA1
15 changed files with 94 additions and 98 deletions

View File

@ -2,7 +2,11 @@
## Current Master ## Current Master
## 3.10.9 2017-10-5
- Only rebrodcast transactions for a day not a days worth of blocks
- Remove Slack link from info page, since it is a big phishing target. - Remove Slack link from info page, since it is a big phishing target.
- Stop computing balance based on pending transactions, to avoid edge case where users are unable to send transactions.
## 3.10.8 2017-9-28 ## 3.10.8 2017-9-28

View File

@ -1,7 +1,7 @@
{ {
"name": "MetaMask", "name": "MetaMask",
"short_name": "Metamask", "short_name": "Metamask",
"version": "3.10.8", "version": "3.10.9",
"manifest_version": 2, "manifest_version": 2,
"author": "https://metamask.io", "author": "https://metamask.io",
"description": "Ethereum Browser Extension", "description": "Ethereum Browser Extension",

View File

@ -59,7 +59,7 @@ module.exports = class TransactionController extends EventEmitter {
this.pendingTxTracker = new PendingTransactionTracker({ this.pendingTxTracker = new PendingTransactionTracker({
provider: this.provider, provider: this.provider,
nonceTracker: this.nonceTracker, nonceTracker: this.nonceTracker,
retryLimit: 3500, // Retry 3500 blocks, or about 1 day. retryTimePeriod: 86400000, // Retry 3500 blocks, or about 1 day.
publishTransaction: (rawTx) => this.query.sendRawTransaction(rawTx), publishTransaction: (rawTx) => this.query.sendRawTransaction(rawTx),
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager), getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
}) })

View File

@ -22,7 +22,8 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
super() super()
this.query = new EthQuery(config.provider) this.query = new EthQuery(config.provider)
this.nonceTracker = config.nonceTracker this.nonceTracker = config.nonceTracker
this.retryLimit = config.retryLimit || Infinity // default is one day
this.retryTimePeriod = config.retryTimePeriod || 86400000
this.getPendingTransactions = config.getPendingTransactions this.getPendingTransactions = config.getPendingTransactions
this.publishTransaction = config.publishTransaction this.publishTransaction = config.publishTransaction
} }
@ -99,8 +100,9 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
} }
async _resubmitTx (txMeta) { async _resubmitTx (txMeta) {
if (txMeta.retryCount > this.retryLimit) { if (Date.now() > txMeta.time + this.retryTimePeriod) {
const err = new Error(`Gave up submitting after ${this.retryLimit} blocks un-mined.`) const hours = (this.retryTimePeriod / 3.6e+6).toFixed(1)
const err = new Error(`Gave up submitting after ${hours} hours.`)
return this.emit('tx:failed', txMeta.id, err) return this.emit('tx:failed', txMeta.id, err)
} }

View File

@ -151,7 +151,7 @@ gulp.task('copy:watch', function(){
gulp.task('lint', function () { gulp.task('lint', function () {
// Ignoring node_modules, dist/firefox, and docs folders: // Ignoring node_modules, dist/firefox, and docs folders:
return gulp.src(['app/**/*.js', 'ui/**/*.js', '!node_modules/**', '!dist/firefox/**', '!docs/**', '!app/scripts/chromereload.js']) return gulp.src(['app/**/*.js', 'ui/**/*.js', 'mascara/src/*.js', 'mascara/server/*.js', '!node_modules/**', '!dist/firefox/**', '!docs/**', '!app/scripts/chromereload.js', '!mascara/test/jquery-3.1.0.min.js'])
.pipe(eslint(fs.readFileSync(path.join(__dirname, '.eslintrc')))) .pipe(eslint(fs.readFileSync(path.join(__dirname, '.eslintrc'))))
// eslint.format() outputs the lint results to the console. // eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs). // Alternatively use eslint.formatEach() (see Docs).

View File

@ -7,20 +7,32 @@ async function loadProvider() {
const ethereumProvider = window.metamask.createDefaultProvider({ host: 'http://localhost:9001' }) const ethereumProvider = window.metamask.createDefaultProvider({ host: 'http://localhost:9001' })
const ethQuery = new EthQuery(ethereumProvider) const ethQuery = new EthQuery(ethereumProvider)
const accounts = await ethQuery.accounts() const accounts = await ethQuery.accounts()
logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined') window.METAMASK_ACCOUNT = accounts[0] || 'locked'
setupButton(ethQuery) logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined', 'account')
setupButtons(ethQuery)
} }
function logToDom(message){ function logToDom(message, context){
document.getElementById('account').innerText = message document.getElementById(context).innerText = message
console.log(message) console.log(message)
} }
function setupButton (ethQuery) { function setupButtons (ethQuery) {
const button = document.getElementById('action-button-1') const accountButton = document.getElementById('action-button-1')
button.addEventListener('click', async () => { accountButton.addEventListener('click', async () => {
const accounts = await ethQuery.accounts() const accounts = await ethQuery.accounts()
logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined') window.METAMASK_ACCOUNT = accounts[0] || 'locked'
logToDom(accounts.length ? accounts[0] : 'LOCKED or undefined', 'account')
})
const txButton = document.getElementById('action-button-2')
txButton.addEventListener('click', async () => {
if (!window.METAMASK_ACCOUNT || window.METAMASK_ACCOUNT === 'locked') return
const txHash = await ethQuery.sendTransaction({
from: window.METAMASK_ACCOUNT,
to: window.METAMASK_ACCOUNT,
data: '',
})
logToDom(txHash, 'cb-value')
}) })
} }

View File

@ -10,6 +10,8 @@
<body> <body>
<button id="action-button-1">GET ACCOUNT</button> <button id="action-button-1">GET ACCOUNT</button>
<div id="account"></div> <div id="account"></div>
<button id="action-button-2">SEND TRANSACTION</button>
<div id="cb-value" ></div>
<script src="./app.js"></script> <script src="./app.js"></script>
</body> </body>
</html> </html>

View File

@ -5,7 +5,7 @@ const serveBundle = require('./util').serveBundle
module.exports = createMetamascaraServer module.exports = createMetamascaraServer
function createMetamascaraServer(){ function createMetamascaraServer () {
// start bundlers // start bundlers
const metamascaraBundle = createBundle(__dirname + '/../src/mascara.js') const metamascaraBundle = createBundle(__dirname + '/../src/mascara.js')
@ -17,13 +17,13 @@ function createMetamascaraServer(){
const server = express() const server = express()
// ui window // ui window
serveBundle(server, '/ui.js', uiBundle) serveBundle(server, '/ui.js', uiBundle)
server.use(express.static(__dirname+'/../ui/')) server.use(express.static(__dirname + '/../ui/'))
server.use(express.static(__dirname+'/../../dist/chrome')) server.use(express.static(__dirname + '/../../dist/chrome'))
// metamascara // metamascara
serveBundle(server, '/metamascara.js', metamascaraBundle) serveBundle(server, '/metamascara.js', metamascaraBundle)
// proxy // proxy
serveBundle(server, '/proxy/proxy.js', proxyBundle) serveBundle(server, '/proxy/proxy.js', proxyBundle)
server.use('/proxy/', express.static(__dirname+'/../proxy')) server.use('/proxy/', express.static(__dirname + '/../proxy'))
// background // background
serveBundle(server, '/background.js', backgroundBuild) serveBundle(server, '/background.js', backgroundBuild)

View File

@ -7,14 +7,14 @@ module.exports = {
} }
function serveBundle(server, path, bundle){ function serveBundle (server, path, bundle) {
server.get(path, function(req, res){ server.get(path, function (req, res) {
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8') res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
res.send(bundle.latest) res.send(bundle.latest)
}) })
} }
function createBundle(entryPoint){ function createBundle (entryPoint) {
var bundleContainer = {} var bundleContainer = {}
@ -30,8 +30,8 @@ function createBundle(entryPoint){
return bundleContainer return bundleContainer
function bundle() { function bundle () {
bundler.bundle(function(err, result){ bundler.bundle(function (err, result) {
if (err) { if (err) {
console.log(`Bundle failed! (${entryPoint})`) console.log(`Bundle failed! (${entryPoint})`)
console.error(err) console.error(err)

View File

@ -1,72 +1,60 @@
global.window = global global.window = global
const self = global
const pipe = require('pump')
const SwGlobalListener = require('sw-stream/lib/sw-global-listener.js') const SwGlobalListener = require('sw-stream/lib/sw-global-listener.js')
const connectionListener = new SwGlobalListener(self) const connectionListener = new SwGlobalListener(global)
const setupMultiplex = require('../../app/scripts/lib/stream-utils.js').setupMultiplex const setupMultiplex = require('../../app/scripts/lib/stream-utils.js').setupMultiplex
const PortStream = require('../../app/scripts/lib/port-stream.js')
const DbController = require('idb-global') const DbController = require('idb-global')
const SwPlatform = require('../../app/scripts/platforms/sw') const SwPlatform = require('../../app/scripts/platforms/sw')
const MetamaskController = require('../../app/scripts/metamask-controller') const MetamaskController = require('../../app/scripts/metamask-controller')
const extension = {} //require('../../app/scripts/lib/extension')
const storeTransform = require('obs-store/lib/transform')
const Migrator = require('../../app/scripts/lib/migrator/') const Migrator = require('../../app/scripts/lib/migrator/')
const migrations = require('../../app/scripts/migrations/') const migrations = require('../../app/scripts/migrations/')
const firstTimeState = require('../../app/scripts/first-time-state') const firstTimeState = require('../../app/scripts/first-time-state')
const STORAGE_KEY = 'metamask-config' const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = process.env.METAMASK_DEBUG const METAMASK_DEBUG = process.env.METAMASK_DEBUG
let popupIsOpen = false global.metamaskPopupIsOpen = false
let connectedClientCount = 0
const log = require('loglevel') const log = require('loglevel')
global.log = log global.log = log
log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn') log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn')
self.addEventListener('install', function(event) { global.addEventListener('install', function (event) {
event.waitUntil(self.skipWaiting()) event.waitUntil(global.skipWaiting())
}) })
self.addEventListener('activate', function(event) { global.addEventListener('activate', function (event) {
event.waitUntil(self.clients.claim()) event.waitUntil(global.clients.claim())
}) })
console.log('inside:open') log.debug('inside:open')
// // state persistence // // state persistence
let diskStore
const dbController = new DbController({ const dbController = new DbController({
key: STORAGE_KEY, key: STORAGE_KEY,
}) })
loadStateFromPersistence() loadStateFromPersistence()
.then((initState) => setupController(initState)) .then((initState) => setupController(initState))
.then(() => console.log('MetaMask initialization complete.')) .then(() => log.debug('MetaMask initialization complete.'))
.catch((err) => console.error('WHILE SETTING UP:', err)) .catch((err) => console.error('WHILE SETTING UP:', err))
// initialization flow
// //
// State and Persistence // State and Persistence
// //
function loadStateFromPersistence() { async function loadStateFromPersistence () {
// migrations // migrations
let migrator = new Migrator({ migrations }) const migrator = new Migrator({ migrations })
const initialState = migrator.generateInitialState(firstTimeState) const initialState = migrator.generateInitialState(firstTimeState)
dbController.initialState = initialState dbController.initialState = initialState
return dbController.open() const versionedData = await dbController.open()
.then((versionedData) => migrator.migrateData(versionedData)) const migratedData = await migrator.migrateData(versionedData)
.then((versionedData) => { await dbController.put(migratedData)
dbController.put(versionedData) return migratedData.data
return Promise.resolve(versionedData)
})
.then((versionedData) => Promise.resolve(versionedData.data))
} }
function setupController (initState, client) { async function setupController (initState, client) {
// //
// MetaMask Controller // MetaMask Controller
@ -86,19 +74,19 @@ function setupController (initState, client) {
}) })
global.metamaskController = controller global.metamaskController = controller
controller.store.subscribe((state) => { controller.store.subscribe(async (state) => {
versionifyData(state) try {
.then((versionedData) => dbController.put(versionedData)) const versionedData = await versionifyData(state)
.catch((err) => {console.error(err)}) await dbController.put(versionedData)
} catch (e) { console.error('METAMASK Error:', e) }
}) })
function versionifyData(state) {
return dbController.get() async function versionifyData (state) {
.then((rawData) => { const rawData = await dbController.get()
return Promise.resolve({ return {
data: state, data: state,
meta: rawData.meta, meta: rawData.meta,
})} }
)
} }
// //
@ -106,8 +94,7 @@ function setupController (initState, client) {
// //
connectionListener.on('remote', (portStream, messageEvent) => { connectionListener.on('remote', (portStream, messageEvent) => {
console.log('REMOTE CONECTION FOUND***********') log.debug('REMOTE CONECTION FOUND***********')
connectedClientCount += 1
connectRemote(portStream, messageEvent.data.context) connectRemote(portStream, messageEvent.data.context)
}) })
@ -116,7 +103,7 @@ function setupController (initState, client) {
if (isMetaMaskInternalProcess) { if (isMetaMaskInternalProcess) {
// communication with popup // communication with popup
controller.setupTrustedCommunication(connectionStream, 'MetaMask') controller.setupTrustedCommunication(connectionStream, 'MetaMask')
popupIsOpen = true global.metamaskPopupIsOpen = true
} else { } else {
// communication with page // communication with page
setupUntrustedCommunication(connectionStream, context) setupUntrustedCommunication(connectionStream, context)
@ -130,25 +117,14 @@ function setupController (initState, client) {
controller.setupProviderConnection(mx.createStream('provider'), originDomain) controller.setupProviderConnection(mx.createStream('provider'), originDomain)
controller.setupPublicConfig(mx.createStream('publicConfig')) controller.setupPublicConfig(mx.createStream('publicConfig'))
} }
function setupTrustedCommunication (connectionStream, originDomain) {
// setup multiplexing
var mx = setupMultiplex(connectionStream)
// connect features
controller.setupProviderConnection(mx.createStream('provider'), originDomain)
}
//
// User Interface setup
//
return Promise.resolve()
} }
// // this will be useful later but commented out for linting for now (liiiinting)
// function sendMessageToAllClients (message) {
// global.clients.matchAll().then(function (clients) {
// clients.forEach(function (client) {
// client.postMessage(message)
// })
// })
// }
function sendMessageToAllClients (message) {
self.clients.matchAll().then(function(clients) {
clients.forEach(function(client) {
client.postMessage(message)
})
})
}
function noop () {} function noop () {}

View File

@ -2,7 +2,7 @@ const createParentStream = require('iframe-stream').ParentStream
const SWcontroller = require('client-sw-ready-event/lib/sw-client.js') const SWcontroller = require('client-sw-ready-event/lib/sw-client.js')
const SwStream = require('sw-stream/lib/sw-stream.js') const SwStream = require('sw-stream/lib/sw-stream.js')
let intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000 const intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
const background = new SWcontroller({ const background = new SWcontroller({
fileName: '/background.js', fileName: '/background.js',
letBeIdle: false, letBeIdle: false,
@ -12,7 +12,7 @@ const background = new SWcontroller({
const pageStream = createParentStream() const pageStream = createParentStream()
background.on('ready', () => { background.on('ready', () => {
let swStream = SwStream({ const swStream = SwStream({
serviceWorker: background.controller, serviceWorker: background.controller,
context: 'dapp', context: 'dapp',
}) })

View File

@ -17,17 +17,17 @@ var name = 'popup'
window.METAMASK_UI_TYPE = name window.METAMASK_UI_TYPE = name
window.METAMASK_PLATFORM_TYPE = 'mascara' window.METAMASK_PLATFORM_TYPE = 'mascara'
let intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000 const intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
const background = new SWcontroller({ const background = new SWcontroller({
fileName: '/background.js', fileName: '/background.js',
letBeIdle: false, letBeIdle: false,
intervalDelay, intervalDelay,
wakeUpInterval: 20000 wakeUpInterval: 20000,
}) })
// Setup listener for when the service worker is read // Setup listener for when the service worker is read
const connectApp = function (readSw) { const connectApp = function (readSw) {
let connectionStream = SwStream({ const connectionStream = SwStream({
serviceWorker: background.controller, serviceWorker: background.controller,
context: name, context: name,
}) })
@ -57,7 +57,7 @@ background.on('updatefound', windowReload)
background.startWorker() background.startWorker()
function windowReload() { function windowReload () {
if (window.METAMASK_SKIP_RELOAD) return if (window.METAMASK_SKIP_RELOAD) return
window.location.reload() window.location.reload()
} }
@ -66,4 +66,4 @@ function timeout (time) {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, time || 1500) setTimeout(resolve, time || 1500)
}) })
} }

View File

@ -69,8 +69,8 @@
"eth-bin-to-ops": "^1.0.1", "eth-bin-to-ops": "^1.0.1",
"eth-block-tracker": "^2.2.0", "eth-block-tracker": "^2.2.0",
"eth-contract-metadata": "^1.1.4", "eth-contract-metadata": "^1.1.4",
"eth-hd-keyring": "^1.1.1", "eth-hd-keyring": "^1.2.1",
"eth-json-rpc-filters": "^1.2.1", "eth-json-rpc-filters": "^1.2.2",
"eth-keyring-controller": "^2.0.0", "eth-keyring-controller": "^2.0.0",
"eth-phishing-detect": "^1.1.4", "eth-phishing-detect": "^1.1.4",
"eth-query": "^2.1.2", "eth-query": "^2.1.2",

View File

@ -46,7 +46,7 @@ AccountDetailScreen.prototype.render = function () {
var selected = props.address || Object.keys(props.accounts)[0] var selected = props.address || Object.keys(props.accounts)[0]
var checksumAddress = selected && ethUtil.toChecksumAddress(selected) var checksumAddress = selected && ethUtil.toChecksumAddress(selected)
var identity = props.identities[selected] var identity = props.identities[selected]
var account = props.computedBalances[selected] var account = props.accounts[selected]
const { network, conversionRate, currentCurrency } = props const { network, conversionRate, currentCurrency } = props
return ( return (
@ -181,7 +181,7 @@ AccountDetailScreen.prototype.render = function () {
}, [ }, [
h(EthBalance, { h(EthBalance, {
value: account && account.ethBalance, value: account && account.balance,
conversionRate, conversionRate,
currentCurrency, currentCurrency,
style: { style: {

View File

@ -33,7 +33,7 @@ function PendingTx () {
PendingTx.prototype.render = function () { PendingTx.prototype.render = function () {
const props = this.props const props = this.props
const { currentCurrency, blockGasLimit, computedBalances } = props const { currentCurrency, blockGasLimit } = props
const conversionRate = props.conversionRate const conversionRate = props.conversionRate
const txMeta = this.gatherTxMeta() const txMeta = this.gatherTxMeta()
@ -42,8 +42,8 @@ PendingTx.prototype.render = function () {
// Account Details // Account Details
const address = txParams.from || props.selectedAddress const address = txParams.from || props.selectedAddress
const identity = props.identities[address] || { address: address } const identity = props.identities[address] || { address: address }
const account = computedBalances[address] const account = props.accounts[address]
const balance = account ? account.ethBalance : '0x0' const balance = account ? account.balance : '0x0'
// recipient check // recipient check
const isValidAddress = !txParams.to || util.isValidAddress(txParams.to) const isValidAddress = !txParams.to || util.isValidAddress(txParams.to)