Merge branch 'dev' into TearDownOnDisconnect

feature/default_network_editable
kumavis 8 years ago committed by GitHub
commit 4c1b7700ad
  1. 1
      CHANGELOG.md
  2. 22
      app/scripts/keyring-controller.js
  3. 30
      app/scripts/metamask-controller.js
  4. 12
      app/scripts/transaction-manager.js

@ -4,6 +4,7 @@
- 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.
- Implement replay attack protections allowed by EIP 155.
- Fix bug where sometimes loading account data would fail by querying a future block. - Fix bug where sometimes loading account data would fail by querying a future block.
## 2.14.1 2016-12-20 ## 2.14.1 2016-12-20

@ -316,20 +316,16 @@ module.exports = class KeyringController extends EventEmitter {
// //
// This method signs tx and returns a promise for // This method signs tx and returns a promise for
// TX Manager to update the state after signing // TX Manager to update the state after signing
signTransaction (ethTx, selectedAddress, txId, cb) {
try {
const address = normalize(selectedAddress)
return this.getKeyringForAccount(address)
.then((keyring) => {
return keyring.signTransaction(address, ethTx)
}).then((tx) => {
this.emit(`${txId}:signed`, {tx, txId, cb})
})
} catch (e) {
cb(e)
}
}
signTransaction (ethTx, selectedAddress, txId) {
const address = normalize(selectedAddress)
return this.getKeyringForAccount(address)
.then((keyring) => {
return keyring.signTransaction(address, ethTx)
}).then((tx) => {
return {tx, txId}
})
}
// Add Unconfirmed Message // Add Unconfirmed Message
// @object msgParams // @object msgParams
// @function cb // @function cb

@ -184,10 +184,23 @@ module.exports = class MetamaskController extends EventEmitter {
}, },
// tx signing // tx signing
approveTransaction: this.newUnsignedTransaction.bind(this), approveTransaction: this.newUnsignedTransaction.bind(this),
signTransaction: (...args) => { signTransaction: (txParams, cb) => {
this.setupSigningListners(...args) this.txManager.formatTxForSigining(txParams)
this.txManager.formatTxForSigining(...args) .then(({ethTx, address, txId}) => {
this.sendUpdate() return this.keyringController.signTransaction(ethTx, address, txId)
})
.then(({tx, txId}) => {
return this.txManager.resolveSignedTransaction({tx, txId})
})
.then((rawTx) => {
cb(null, rawTx)
this.sendUpdate()
this.txManager.emit(`${txParams.metamaskId}:signingComplete`)
})
.catch((err) => {
console.error(err)
cb(err)
})
}, },
// msg signing // msg signing
@ -265,13 +278,6 @@ module.exports = class MetamaskController extends EventEmitter {
}) })
} }
setupSigningListners (txParams) {
var txId = txParams.metamaskId
// apply event listeners for signing and formating events
this.txManager.once(`${txId}:formatted`, this.keyringController.signTransaction.bind(this.keyringController))
this.keyringController.once(`${txId}:signed`, this.txManager.resolveSignedTransaction.bind(this.txManager))
}
enforceTxValidations (txParams) { enforceTxValidations (txParams) {
if (('value' in txParams) && txParams.value.indexOf('-') === 0) { if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
const msg = `Invalid transaction value of ${txParams.value} not a positive number.` const msg = `Invalid transaction value of ${txParams.value} not a positive number.`
@ -452,7 +458,7 @@ module.exports = class MetamaskController extends EventEmitter {
return this.state.network return this.state.network
} }
markAccountsFound(cb) { markAccountsFound (cb) {
this.configManager.setLostAccounts([]) this.configManager.setLostAccounts([])
this.sendUpdate() this.sendUpdate()
cb(null, this.getState()) cb(null, this.getState())

@ -128,7 +128,7 @@ module.exports = class TransactionManager extends EventEmitter {
approveTransaction (txId, cb = warn) { approveTransaction (txId, cb = warn) {
this.setTxStatusSigned(txId) this.setTxStatusSigned(txId)
cb() this.once(`${txId}:signingComplete`, cb)
} }
cancelTransaction (txId, cb = warn) { cancelTransaction (txId, cb = warn) {
@ -137,7 +137,7 @@ module.exports = class TransactionManager extends EventEmitter {
} }
// formats txParams so the keyringController can sign it // formats txParams so the keyringController can sign it
formatTxForSigining (txParams, cb) { formatTxForSigining (txParams) {
var address = txParams.from var address = txParams.from
var metaTx = this.getTx(txParams.metamaskId) var metaTx = this.getTx(txParams.metamaskId)
var gasMultiplier = metaTx.gasMultiplier var gasMultiplier = metaTx.gasMultiplier
@ -153,9 +153,8 @@ module.exports = class TransactionManager extends EventEmitter {
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas) txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
txParams.nonce = normalize(txParams.nonce) txParams.nonce = normalize(txParams.nonce)
const ethTx = new Transaction(txParams) const ethTx = new Transaction(txParams)
var txId = txParams.metamaskId
// listener is assigned in metamaskController return Promise.resolve({ethTx, address, txId})
this.emit(`${txParams.metamaskId}:formatted`, ethTx, address, txParams.metamaskId, cb)
} }
// receives a signed tx object and updates the tx hash // receives a signed tx object and updates the tx hash
@ -167,7 +166,8 @@ module.exports = class TransactionManager extends EventEmitter {
metaTx.hash = txHash metaTx.hash = txHash
this.updateTx(metaTx) this.updateTx(metaTx)
var rawTx = ethUtil.bufferToHex(tx.serialize()) var rawTx = ethUtil.bufferToHex(tx.serialize())
cb(null, rawTx) return Promise.resolve(rawTx)
} }
/* /*

Loading…
Cancel
Save