From 2964536093c863a81959b496e86949c979fe2441 Mon Sep 17 00:00:00 2001 From: Zachary Belford Date: Tue, 27 Jun 2023 18:59:59 -0700 Subject: [PATCH] Added support for eth_createAccessList and sendTransaction support for it --- .../controllers/permissions/specifications.js | 1 + .../controllers/transactions/lib/util.js | 21 +++++++++++++++-- .../controllers/transactions/tx-gas-utils.js | 23 +++++++++++++++++-- .../transactions/tx-state-manager.js | 1 + 4 files changed, 42 insertions(+), 4 deletions(-) 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`);