aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-12-08 07:34:56 +0800
committerGitHub <noreply@github.com>2017-12-08 07:34:56 +0800
commitd39eb370423e2a2cdd41c47b92796c0d4c829b3b (patch)
tree06ec6c8b8e1cbaa4c5767399c4d65b1f5935799f
parent6553ba132d6f1aa889d9052dac021cefcd708cad (diff)
parenta91200fd08b429c81d4096de17cdd9066a632ade (diff)
downloadtangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.tar
tangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.tar.gz
tangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.tar.bz2
tangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.tar.lz
tangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.tar.xz
tangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.tar.zst
tangerine-wallet-browser-d39eb370423e2a2cdd41c47b92796c0d4c829b3b.zip
Merge pull request #2699 from MetaMask/patch-2v3.13.1
Allow Dapps to Specify Nonce
-rw-r--r--CHANGELOG.md4
-rw-r--r--app/manifest.json2
-rw-r--r--app/scripts/controllers/transactions.js22
-rw-r--r--app/scripts/lib/tx-state-manager.js2
4 files changed, 21 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index faffb8a2d..ea7e1cc8d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Current Master
+## 3.13.1 2017-12-7
+
+- Allow Dapps to specify a transaction nonce, allowing dapps to propose resubmit and force-cancel transactions.
+
## 3.13.0 2017-12-7
- Allow resubmitting transactions that are taking long to complete.
diff --git a/app/manifest.json b/app/manifest.json
index aa23f85ff..e95e75f6d 100644
--- a/app/manifest.json
+++ b/app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "MetaMask",
"short_name": "Metamask",
- "version": "3.13.0",
+ "version": "3.13.1",
"manifest_version": 2,
"author": "https://metamask.io",
"description": "Ethereum Browser Extension",
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 685db6269..f95b5e39a 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -138,18 +138,20 @@ module.exports = class TransactionController extends EventEmitter {
async newUnapprovedTransaction (txParams) {
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
- const txMeta = await this.addUnapprovedTransaction(txParams)
- this.emit('newUnapprovedTx', txMeta)
+ const initialTxMeta = await this.addUnapprovedTransaction(txParams)
+ this.emit('newUnapprovedTx', initialTxMeta)
// listen for tx completion (success, fail)
return new Promise((resolve, reject) => {
- this.txStateManager.once(`${txMeta.id}:finished`, (completedTx) => {
- switch (completedTx.status) {
+ this.txStateManager.once(`${initialTxMeta.id}:finished`, (finishedTxMeta) => {
+ switch (finishedTxMeta.status) {
case 'submitted':
- return resolve(completedTx.hash)
+ return resolve(finishedTxMeta.hash)
case 'rejected':
return reject(new Error('MetaMask Tx Signature: User denied transaction signature.'))
+ case 'failed':
+ return reject(new Error(finishedTxMeta.err.message))
default:
- return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(completedTx.txParams)}`))
+ return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))
}
})
})
@@ -177,6 +179,7 @@ module.exports = class TransactionController extends EventEmitter {
const txParams = txMeta.txParams
// ensure value
txMeta.gasPriceSpecified = Boolean(txParams.gasPrice)
+ txMeta.nonceSpecified = Boolean(txParams.nonce)
const gasPrice = txParams.gasPrice || await this.query.gasPrice()
txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16))
txParams.value = txParams.value || '0x0'
@@ -207,7 +210,12 @@ module.exports = class TransactionController extends EventEmitter {
// wait for a nonce
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
// add nonce to txParams
- txMeta.txParams.nonce = ethUtil.addHexPrefix(nonceLock.nextNonce.toString(16))
+ const nonce = txMeta.nonceSpecified ? txMeta.txParams.nonce : nonceLock.nextNonce
+ if (nonce > nonceLock.nextNonce) {
+ const message = `Specified nonce may not be larger than account's next valid nonce.`
+ throw new Error(message)
+ }
+ txMeta.txParams.nonce = ethUtil.addHexPrefix(nonce.toString(16))
// add nonce debugging information to txMeta
txMeta.nonceDetails = nonceLock.nonceDetails
this.txStateManager.updateTx(txMeta, 'transactions#approveTransaction')
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index cc441c584..a8ef39891 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -240,7 +240,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
txMeta.status = status
this.emit(`${txMeta.id}:${status}`, txId)
this.emit(`tx:status-update`, txId, status)
- if (status === 'submitted' || status === 'rejected') {
+ if (['submitted', 'rejected', 'failed'].includes(status)) {
this.emit(`${txMeta.id}:finished`, txMeta)
}
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)