mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #2699 from MetaMask/patch-2
Allow Dapps to Specify Nonce
This commit is contained in:
commit
d39eb37042
@ -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.
|
||||
|
@ -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",
|
||||
|
@ -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')
|
||||
|
@ -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}`)
|
||||
|
Loading…
Reference in New Issue
Block a user