diff --git a/app/scripts/controllers/permissions/specifications.js b/app/scripts/controllers/permissions/specifications.js index 42f685bfbf2e..f33aaa91006e 100644 --- a/app/scripts/controllers/permissions/specifications.js +++ b/app/scripts/controllers/permissions/specifications.js @@ -221,6 +221,7 @@ export const unrestrictedMethods = Object.freeze([ 'eth_coinbase', 'eth_decrypt', 'eth_estimateGas', + 'eth_createAccessList', 'eth_feeHistory', 'eth_gasPrice', 'eth_getBalance', diff --git a/app/scripts/controllers/transactions/lib/util.js b/app/scripts/controllers/transactions/lib/util.js index 378b6b9cf59d..afd8465fa8e6 100644 --- a/app/scripts/controllers/transactions/lib/util.js +++ b/app/scripts/controllers/transactions/lib/util.js @@ -9,6 +9,7 @@ import { import { isEIP1559Transaction } from '../../../../../shared/modules/transaction.utils'; import { isValidHexAddress } from '../../../../../shared/modules/hexstring-utils'; +const identity = (x) => x; const normalizers = { from: addHexPrefix, to: (to, lowerCase) => @@ -21,8 +22,9 @@ const normalizers = { maxFeePerGas: addHexPrefix, maxPriorityFeePerGas: addHexPrefix, type: addHexPrefix, - estimateSuggested: (estimate) => estimate, - estimateUsed: (estimate) => estimate, + estimateSuggested: identity, + estimateUsed: identity, + accessList: identity, }; export function normalizeAndValidateTxParams(txParams, lowerCase = true) { @@ -224,12 +226,27 @@ export function validateTxParams(txParams, eip1559Compatibility = true) { validateInputData(value); ensureFieldIsString(txParams, 'data'); break; + case 'accessList': + validateAccessList(value); + break; default: ensureFieldIsString(txParams, key); } }); } +/** + * + * @param {*} value + */ +export function validateAccessList(value) { + if (value instanceof Array === false) { + throw ethErrors.rpc.invalidParams( + `Invalid transaction params: accessList must be an array of access entries`, + ); + } +} + /** * * @param {*} value diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js index 006de767ff33..899acde9c7ed 100644 --- a/app/scripts/controllers/transactions/tx-gas-utils.js +++ b/app/scripts/controllers/transactions/tx-gas-utils.js @@ -76,8 +76,27 @@ export default class TxGasUtil { delete txParams.maxFeePerGas; delete txParams.maxPriorityFeePerGas; - // estimate tx gas requirements - return await this.query.estimateGas(txParams); + // dont use ethjs-query here because it will blow up about accessList + if (txParams.accessList) { + return await new Promise((resolve, reject) => { + this.query.rpc.currentProvider.sendAsync( + { + id: '1', + jsonrpc: '2.0', + method: 'eth_estimateGas', + params: [txParams, 'latest'], + }, + (err, { result, error }) => { + if (error || err) { + reject(error); + } else { + resolve(result); + } + }, + ); + }); + } + return this.query.estimateGas(txParams); } /** diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js index 20e142c6c052..202e4a1602af 100644 --- a/app/scripts/controllers/transactions/tx-state-manager.js +++ b/app/scripts/controllers/transactions/tx-state-manager.js @@ -242,6 +242,7 @@ export default class TransactionStateManager extends EventEmitter { if (txMeta.txParams) { txMeta.txParams = normalizeAndValidateTxParams(txMeta.txParams, false); } + console.log('add transaction, post normalization', txMeta.txParams); this.once(`${txMeta.id}:signed`, () => { this.removeAllListeners(`${txMeta.id}:rejected`);