mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Make EIP1559 compatibility in tx controller also require account type support (#11616)
This commit is contained in:
parent
9a81b826c5
commit
7c86727c16
@ -95,7 +95,10 @@ export default class TransactionController extends EventEmitter {
|
||||
this.networkStore = opts.networkStore || new ObservableStore({});
|
||||
this._getCurrentChainId = opts.getCurrentChainId;
|
||||
this.getProviderConfig = opts.getProviderConfig;
|
||||
this.getEIP1559Compatibility = opts.getEIP1559Compatibility;
|
||||
this._getCurrentNetworkEIP1559Compatibility =
|
||||
opts.getCurrentNetworkEIP1559Compatibility;
|
||||
this._getCurrentAccountEIP1559Compatibility =
|
||||
opts.getCurrentAccountEIP1559Compatibility;
|
||||
this.preferencesStore = opts.preferencesStore || new ObservableStore({});
|
||||
this.provider = opts.provider;
|
||||
this.getPermittedAccounts = opts.getPermittedAccounts;
|
||||
@ -177,6 +180,14 @@ export default class TransactionController extends EventEmitter {
|
||||
return integerChainId;
|
||||
}
|
||||
|
||||
async getEIP1559Compatibility(fromAddress) {
|
||||
const currentNetworkIsCompatible = await this._getCurrentNetworkEIP1559Compatibility();
|
||||
const fromAccountIsCompatible = this._getCurrentAccountEIP1559Compatibility(
|
||||
fromAddress,
|
||||
);
|
||||
return currentNetworkIsCompatible && fromAccountIsCompatible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ethereumjs/tx uses @ethereumjs/common as a configuration tool for
|
||||
* specifying which chain, network, hardfork and EIPs to support for
|
||||
@ -185,9 +196,9 @@ export default class TransactionController extends EventEmitter {
|
||||
* transaction type to use.
|
||||
* @returns {Common} common configuration object
|
||||
*/
|
||||
async getCommonConfiguration() {
|
||||
async getCommonConfiguration(fromAddress) {
|
||||
const { type, nickname: name } = this.getProviderConfig();
|
||||
const supportsEIP1559 = await this.getEIP1559Compatibility();
|
||||
const supportsEIP1559 = await this.getEIP1559Compatibility(fromAddress);
|
||||
|
||||
// This logic below will have to be updated each time a hardfork happens
|
||||
// that carries with it a new Transaction type. It is inconsequential for
|
||||
@ -739,7 +750,7 @@ export default class TransactionController extends EventEmitter {
|
||||
};
|
||||
// sign tx
|
||||
const fromAddress = txParams.from;
|
||||
const common = await this.getCommonConfiguration();
|
||||
const common = await this.getCommonConfiguration(txParams.from);
|
||||
const unsignedEthTx = TransactionFactory.fromTxData(txParams, { common });
|
||||
const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress);
|
||||
|
||||
|
@ -51,6 +51,8 @@ describe('Transaction Controller', function () {
|
||||
},
|
||||
networkStore: new ObservableStore(currentNetworkId),
|
||||
getEIP1559Compatibility: () => Promise.resolve(true),
|
||||
getCurrentNetworkEIP1559Compatibility: () => Promise.resolve(true),
|
||||
getCurrentAccountEIP1559Compatibility: () => true,
|
||||
txHistoryLimit: 10,
|
||||
blockTracker: blockTrackerStub,
|
||||
signTransaction: (ethTx) =>
|
||||
|
@ -401,9 +401,12 @@ export default class MetamaskController extends EventEmitter {
|
||||
getProviderConfig: this.networkController.getProviderConfig.bind(
|
||||
this.networkController,
|
||||
),
|
||||
getEIP1559Compatibility: this.networkController.getEIP1559Compatibility.bind(
|
||||
getCurrentNetworkEIP1559Compatibility: this.networkController.getEIP1559Compatibility.bind(
|
||||
this.networkController,
|
||||
),
|
||||
getCurrentAccountEIP1559Compatibility: this.getCurrentAccountEIP1559Compatibility.bind(
|
||||
this,
|
||||
),
|
||||
networkStore: this.networkController.networkStore,
|
||||
getCurrentChainId: this.networkController.getCurrentChainId.bind(
|
||||
this.networkController,
|
||||
@ -2037,11 +2040,10 @@ export default class MetamaskController extends EventEmitter {
|
||||
* client utilities for EIP-1559
|
||||
* @returns {boolean} true if the keyring type supports EIP-1559
|
||||
*/
|
||||
getCurrentAccountEIP1559Compatibility() {
|
||||
const selectedAddress = this.preferencesController.getSelectedAddress();
|
||||
const keyring = this.keyringController.getKeyringForAccount(
|
||||
selectedAddress,
|
||||
);
|
||||
getCurrentAccountEIP1559Compatibility(fromAddress) {
|
||||
const address =
|
||||
fromAddress || this.preferencesController.getSelectedAddress();
|
||||
const keyring = this.keyringController.getKeyringForAccount(address);
|
||||
return (
|
||||
keyring.type !== KEYRING_TYPES.LEDGER &&
|
||||
keyring.type !== KEYRING_TYPES.TREZOR
|
||||
|
Loading…
x
Reference in New Issue
Block a user