Skip to content

Commit

Permalink
Merge pull request #6728 from MetaMask/i#6724
Browse files Browse the repository at this point in the history
transactions - always hexprefix txParams on update; fixes #6724
  • Loading branch information
danfinlay authored Jun 19, 2019
2 parents 748801f + 5cf5359 commit 3e3deed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/scripts/controllers/transactions/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = {

// functions that handle normalizing of that key in txParams
const normalizers = {
from: from => addHexPrefix(from).toLowerCase(),
to: to => addHexPrefix(to).toLowerCase(),
from: (from, LowerCase = true) => LowerCase ? addHexPrefix(from).toLowerCase() : addHexPrefix(from),
to: (to, LowerCase = true) => LowerCase ? addHexPrefix(to).toLowerCase() : addHexPrefix(to),
nonce: nonce => addHexPrefix(nonce),
value: value => addHexPrefix(value),
data: data => addHexPrefix(data),
Expand All @@ -31,11 +31,11 @@ const normalizers = {
@param txParams {object}
@returns {object} normalized txParams
*/
function normalizeTxParams (txParams) {
function normalizeTxParams (txParams, LowerCase) {
// apply only keys in the normalizers
const normalizedTxParams = {}
for (const key in normalizers) {
if (txParams[key]) normalizedTxParams[key] = normalizers[key](txParams[key])
if (txParams[key]) normalizedTxParams[key] = normalizers[key](txParams[key], LowerCase)
}
return normalizedTxParams
}
Expand Down
6 changes: 2 additions & 4 deletions app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const extend = require('xtend')
const EventEmitter = require('safe-event-emitter')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const log = require('loglevel')
const txStateHistoryHelper = require('./lib/tx-state-history-helper')
const createId = require('../../lib/random-id')
const { getFinalStates } = require('./lib/util')
const { getFinalStates, normalizeTxParams } = require('./lib/util')
/**
TransactionStateManager is responsible for the state of a transaction and
storing the transaction
Expand Down Expand Up @@ -180,7 +179,7 @@ class TransactionStateManager extends EventEmitter {
if (typeof txMeta.txParams.data === 'undefined') {
delete txMeta.txParams.data
}

txMeta.txParams = normalizeTxParams(txMeta.txParams, false)
this.validateTxParams(txMeta.txParams)
}

Expand Down Expand Up @@ -227,7 +226,6 @@ class TransactionStateManager extends EventEmitter {
break
default:
if (typeof value !== 'string') throw new Error(`${key} in txParams is not a string. got: (${value})`)
if (!ethUtil.isHexPrefixed(value)) throw new Error(`${key} in txParams is not hex prefixed. got: (${value})`)
break
}
})
Expand Down

0 comments on commit 3e3deed

Please sign in to comment.