Skip to content

Commit

Permalink
Added support for eth_createAccessList and sendTransaction support fo…
Browse files Browse the repository at this point in the history
…r it
  • Loading branch information
BelfordZ committed Jul 17, 2023
1 parent 343cde9 commit 2964536
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/scripts/controllers/permissions/specifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const unrestrictedMethods = Object.freeze([
'eth_coinbase',
'eth_decrypt',
'eth_estimateGas',
'eth_createAccessList',
'eth_feeHistory',
'eth_gasPrice',
'eth_getBalance',
Expand Down
21 changes: 19 additions & 2 deletions app/scripts/controllers/transactions/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions app/scripts/controllers/transactions/tx-gas-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit 2964536

Please sign in to comment.