2018-04-06 03:05:03 +02:00
|
|
|
// next version number
|
|
|
|
const version = 25
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
normalizes txParams on unconfirmed txs
|
|
|
|
|
|
|
|
*/
|
2020-01-09 04:34:58 +01:00
|
|
|
import ethUtil from 'ethereumjs-util'
|
2018-04-06 03:05:03 +02:00
|
|
|
|
2020-01-29 18:14:33 +01:00
|
|
|
import { cloneDeep } from 'lodash'
|
2020-01-09 04:34:58 +01:00
|
|
|
|
|
|
|
export default {
|
2018-04-06 03:05:03 +02:00
|
|
|
version,
|
|
|
|
|
|
|
|
migrate: async function (originalVersionedData) {
|
2020-01-29 18:14:33 +01:00
|
|
|
const versionedData = cloneDeep(originalVersionedData)
|
2018-04-06 03:05:03 +02:00
|
|
|
versionedData.meta.version = version
|
|
|
|
const state = versionedData.data
|
|
|
|
const newState = transformState(state)
|
|
|
|
versionedData.data = newState
|
|
|
|
return versionedData
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
function transformState (state) {
|
|
|
|
const newState = state
|
|
|
|
|
|
|
|
if (newState.TransactionController) {
|
|
|
|
if (newState.TransactionController.transactions) {
|
|
|
|
const transactions = newState.TransactionController.transactions
|
|
|
|
newState.TransactionController.transactions = transactions.map((txMeta) => {
|
2019-11-20 01:03:20 +01:00
|
|
|
if (txMeta.status !== 'unapproved') {
|
|
|
|
return txMeta
|
|
|
|
}
|
2018-04-06 03:05:03 +02:00
|
|
|
txMeta.txParams = normalizeTxParams(txMeta.txParams)
|
|
|
|
return txMeta
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newState
|
|
|
|
}
|
|
|
|
|
|
|
|
function normalizeTxParams (txParams) {
|
|
|
|
// functions that handle normalizing of that key in txParams
|
|
|
|
const whiteList = {
|
|
|
|
from: from => ethUtil.addHexPrefix(from).toLowerCase(),
|
2019-05-08 21:51:33 +02:00
|
|
|
to: () => ethUtil.addHexPrefix(txParams.to).toLowerCase(),
|
2018-04-06 03:05:03 +02:00
|
|
|
nonce: nonce => ethUtil.addHexPrefix(nonce),
|
|
|
|
value: value => ethUtil.addHexPrefix(value),
|
|
|
|
data: data => ethUtil.addHexPrefix(data),
|
|
|
|
gas: gas => ethUtil.addHexPrefix(gas),
|
|
|
|
gasPrice: gasPrice => ethUtil.addHexPrefix(gasPrice),
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply only keys in the whiteList
|
|
|
|
const normalizedTxParams = {}
|
|
|
|
Object.keys(whiteList).forEach((key) => {
|
2019-11-20 01:03:20 +01:00
|
|
|
if (txParams[key]) {
|
|
|
|
normalizedTxParams[key] = whiteList[key](txParams[key])
|
|
|
|
}
|
2018-04-06 03:05:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return normalizedTxParams
|
|
|
|
}
|