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

transactions - always hexprefix txParams on update; fixes #6724

This commit is contained in:
frankiebee 2019-06-19 14:08:54 +02:00
parent 748801f417
commit 5cf5359e78
2 changed files with 6 additions and 8 deletions

View File

@ -17,8 +17,8 @@ module.exports = {
// functions that handle normalizing of that key in txParams // functions that handle normalizing of that key in txParams
const normalizers = { const normalizers = {
from: from => addHexPrefix(from).toLowerCase(), from: (from, LowerCase = true) => LowerCase ? addHexPrefix(from).toLowerCase() : addHexPrefix(from),
to: to => addHexPrefix(to).toLowerCase(), to: (to, LowerCase = true) => LowerCase ? addHexPrefix(to).toLowerCase() : addHexPrefix(to),
nonce: nonce => addHexPrefix(nonce), nonce: nonce => addHexPrefix(nonce),
value: value => addHexPrefix(value), value: value => addHexPrefix(value),
data: data => addHexPrefix(data), data: data => addHexPrefix(data),
@ -31,11 +31,11 @@ const normalizers = {
@param txParams {object} @param txParams {object}
@returns {object} normalized txParams @returns {object} normalized txParams
*/ */
function normalizeTxParams (txParams) { function normalizeTxParams (txParams, LowerCase) {
// apply only keys in the normalizers // apply only keys in the normalizers
const normalizedTxParams = {} const normalizedTxParams = {}
for (const key in normalizers) { 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 return normalizedTxParams
} }

View File

@ -1,11 +1,10 @@
const extend = require('xtend') const extend = require('xtend')
const EventEmitter = require('safe-event-emitter') const EventEmitter = require('safe-event-emitter')
const ObservableStore = require('obs-store') const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const log = require('loglevel') const log = require('loglevel')
const txStateHistoryHelper = require('./lib/tx-state-history-helper') const txStateHistoryHelper = require('./lib/tx-state-history-helper')
const createId = require('../../lib/random-id') 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 TransactionStateManager is responsible for the state of a transaction and
storing the transaction storing the transaction
@ -180,7 +179,7 @@ class TransactionStateManager extends EventEmitter {
if (typeof txMeta.txParams.data === 'undefined') { if (typeof txMeta.txParams.data === 'undefined') {
delete txMeta.txParams.data delete txMeta.txParams.data
} }
txMeta.txParams = normalizeTxParams(txMeta.txParams, false)
this.validateTxParams(txMeta.txParams) this.validateTxParams(txMeta.txParams)
} }
@ -227,7 +226,6 @@ class TransactionStateManager extends EventEmitter {
break break
default: default:
if (typeof value !== 'string') throw new Error(`${key} in txParams is not a string. got: (${value})`) 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 break
} }
}) })