|
|
@ -185,10 +185,10 @@ module.exports = class TransactionController extends EventEmitter { |
|
|
|
|
|
|
|
|
|
|
|
async addUnapprovedTransaction (txParams) { |
|
|
|
async addUnapprovedTransaction (txParams) { |
|
|
|
// validate
|
|
|
|
// validate
|
|
|
|
this._validateTxParams(txParams) |
|
|
|
const normalizedTxParams = this._normalizeTxParams(txParams) |
|
|
|
this._normalizeTxParams(txParams) |
|
|
|
this._validateTxParams(normalizedTxParams) |
|
|
|
// construct txMeta
|
|
|
|
// construct txMeta
|
|
|
|
let txMeta = this.txStateManager.generateTxMeta({txParams}) |
|
|
|
let txMeta = this.txStateManager.generateTxMeta({ txParams: normalizedTxParams }) |
|
|
|
this.addTx(txMeta) |
|
|
|
this.addTx(txMeta) |
|
|
|
this.emit('newUnapprovedTx', txMeta) |
|
|
|
this.emit('newUnapprovedTx', txMeta) |
|
|
|
// add default tx params
|
|
|
|
// add default tx params
|
|
|
@ -315,25 +315,24 @@ module.exports = class TransactionController extends EventEmitter { |
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
_normalizeTxParams (txParams) { |
|
|
|
_normalizeTxParams (txParams) { |
|
|
|
delete txParams.chainId |
|
|
|
// functions that handle normalizing of that key in txParams
|
|
|
|
|
|
|
|
const whiteList = { |
|
|
|
if ( !txParams.to ) { |
|
|
|
from: from => ethUtil.addHexPrefix(from).toLowerCase(), |
|
|
|
delete txParams.to |
|
|
|
to: to => ethUtil.addHexPrefix(txParams.to).toLowerCase(), |
|
|
|
} else { |
|
|
|
nonce: nonce => ethUtil.addHexPrefix(nonce), |
|
|
|
txParams.to = ethUtil.addHexPrefix(txParams.to) |
|
|
|
value: value => ethUtil.addHexPrefix(value), |
|
|
|
} |
|
|
|
data: data => ethUtil.addHexPrefix(data), |
|
|
|
txParams.from = ethUtil.addHexPrefix(txParams.from).toLowerCase() |
|
|
|
gas: gas => ethUtil.addHexPrefix(gas), |
|
|
|
|
|
|
|
gasPrice: gasPrice => ethUtil.addHexPrefix(gasPrice), |
|
|
|
if (!txParams.data) { |
|
|
|
} |
|
|
|
delete txParams.data |
|
|
|
|
|
|
|
} else { |
|
|
|
// apply only keys in the whiteList
|
|
|
|
txParams.data = ethUtil.addHexPrefix(txParams.data) |
|
|
|
const normalizedTxParams = {} |
|
|
|
} |
|
|
|
Object.keys(whiteList).forEach((key) => { |
|
|
|
|
|
|
|
if (txParams[key]) normalizedTxParams[key] = whiteList[key](txParams[key]) |
|
|
|
if (txParams.value) txParams.value = ethUtil.addHexPrefix(txParams.value) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (txParams.gas) txParams.gas = ethUtil.addHexPrefix(txParams.gas) |
|
|
|
return normalizedTxParams |
|
|
|
if (txParams.gasPrice) txParams.gas = ethUtil.addHexPrefix(txParams.gas) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_validateTxParams (txParams) { |
|
|
|
_validateTxParams (txParams) { |
|
|
|