@metamask/network-controller 11.0.0 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -2
- package/dist/NetworkController.d.ts +53 -17
- package/dist/NetworkController.d.ts.map +1 -1
- package/dist/NetworkController.js +71 -26
- package/dist/NetworkController.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [12.1.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add `getNetworkClientById` ([#1562](https://github.com/MetaMask/core/pull/1562))
|
|
12
|
+
- Add `findNetworkClientIdByChainId` ([#1571](https://github.com/MetaMask/core/pull/1571))
|
|
13
|
+
|
|
14
|
+
## [12.0.0]
|
|
15
|
+
### Added
|
|
16
|
+
- Add `NetworksMetadata` type ([#1559](https://github.com/MetaMask/core/pull/1559))
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **BREAKING:** Remove `NetworkDetails` type in favor of `NetworkMetadata` ([#1559](https://github.com/MetaMask/core/pull/1559))
|
|
20
|
+
- This new type includes `NetworkDetails` plus a `status` property
|
|
21
|
+
- **BREAKING:** Add `networksMetadata` to state ([#1559](https://github.com/MetaMask/core/pull/1559))
|
|
22
|
+
- Consumers will need to add a migration. The data for this property can be constructed by looping over the values in `InfuraNetworkType` from `@metamask/controller-utils` plus the network configuration IDs in the state property `networkConfigurations` and setting each value to `{ status: "unknown", EIPS: {} }`.
|
|
23
|
+
- **BREAKING:** Add `selectedNetworkClientId` to state ([#1548](https://github.com/MetaMask/core/pull/1548))
|
|
24
|
+
- Consumers will need to add a migration. This property should be set to either `providerConfig.type` or `providerConfig.id`.
|
|
25
|
+
- Update `getEIP1559Compatibility` to return `undefined` when the latest block is unavailable ([#1457](https://github.com/MetaMask/core/pull/1457))
|
|
26
|
+
- Replace `eth-query` ^2.1.2 with `@metamask/eth-query` ^3.0.1 ([#1546](https://github.com/MetaMask/core/pull/1546))
|
|
27
|
+
|
|
28
|
+
### Removed
|
|
29
|
+
- **BREAKING:** Remove `networkDetails` from state ([#1559](https://github.com/MetaMask/core/pull/1559))
|
|
30
|
+
- The data in this state property has been merged into the new `networksMetadata` state property; each value in this object contains an `EIPS` property.
|
|
31
|
+
|
|
9
32
|
## [11.0.0]
|
|
10
33
|
### Changed
|
|
11
34
|
- **BREAKING**: Require `ticker` to be included in the `providerConfig` state ([#1495](https://github.com/MetaMask/core/pull/1495))
|
|
@@ -14,7 +37,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
14
37
|
- Bump @metamask/eth-json-rpc-infura from 8.1.0 to 8.1.1 ([#1517](https://github.com/MetaMask/core/pull/1517))
|
|
15
38
|
- Remove unnecessary `babel-runtime` dependency ([#1504](https://github.com/MetaMask/core/pull/1504))
|
|
16
39
|
|
|
17
|
-
|
|
18
40
|
## [10.3.1]
|
|
19
41
|
### Changed
|
|
20
42
|
- Bump `@metamask/eth-json-rpc-infura` dependency from ^8.0.0 to ^8.1.0
|
|
@@ -214,7 +236,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
214
236
|
|
|
215
237
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
216
238
|
|
|
217
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@
|
|
239
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@12.1.0...HEAD
|
|
240
|
+
[12.1.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@12.0.0...@metamask/network-controller@12.1.0
|
|
241
|
+
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@11.0.0...@metamask/network-controller@12.0.0
|
|
218
242
|
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@10.3.1...@metamask/network-controller@11.0.0
|
|
219
243
|
[10.3.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@10.3.0...@metamask/network-controller@10.3.1
|
|
220
244
|
[10.3.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@10.2.0...@metamask/network-controller@10.3.0
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
2
|
import { BaseControllerV2 } from '@metamask/base-controller';
|
|
3
3
|
import { InfuraNetworkType, NetworkType } from '@metamask/controller-utils';
|
|
4
|
+
import EthQuery from '@metamask/eth-query';
|
|
4
5
|
import type { SwappableProxy } from '@metamask/swappable-obj-proxy';
|
|
5
6
|
import type { Hex } from '@metamask/utils';
|
|
6
|
-
import EthQuery from 'eth-query';
|
|
7
7
|
import type { Patch } from 'immer';
|
|
8
8
|
import { NetworkStatus } from './constants';
|
|
9
9
|
import type { AutoManagedNetworkClient, ProxyWithAccessibleTarget } from './create-auto-managed-network-client';
|
|
@@ -34,16 +34,19 @@ export declare type Block = {
|
|
|
34
34
|
baseFeePerGas?: string;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
|
-
* Information about
|
|
38
|
-
* only used to capture whether a network supports EIP-1559.
|
|
37
|
+
* Information about a network not held by any other part of state.
|
|
39
38
|
*/
|
|
40
|
-
export declare type
|
|
39
|
+
export declare type NetworkMetadata = {
|
|
41
40
|
/**
|
|
42
41
|
* EIPs supported by the network.
|
|
43
42
|
*/
|
|
44
43
|
EIPS: {
|
|
45
44
|
[eipNumber: number]: boolean;
|
|
46
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Indicates the availability of the network
|
|
48
|
+
*/
|
|
49
|
+
status: NetworkStatus;
|
|
47
50
|
};
|
|
48
51
|
/**
|
|
49
52
|
* Custom RPC network information
|
|
@@ -83,6 +86,24 @@ declare type NetworkConfigurations = Record<NetworkConfigurationId, NetworkConfi
|
|
|
83
86
|
* itself.
|
|
84
87
|
*/
|
|
85
88
|
export declare function knownKeysOf<K extends PropertyKey>(object: Partial<Record<K, any>>): K[];
|
|
89
|
+
/**
|
|
90
|
+
* The string that uniquely identifies an Infura network client.
|
|
91
|
+
*/
|
|
92
|
+
declare type BuiltInNetworkClientId = InfuraNetworkType;
|
|
93
|
+
/**
|
|
94
|
+
* The string that uniquely identifies a custom network client.
|
|
95
|
+
*/
|
|
96
|
+
declare type CustomNetworkClientId = string;
|
|
97
|
+
/**
|
|
98
|
+
* The string that uniquely identifies a network client.
|
|
99
|
+
*/
|
|
100
|
+
declare type NetworkClientId = BuiltInNetworkClientId | CustomNetworkClientId;
|
|
101
|
+
/**
|
|
102
|
+
* Information about networks not held by any other part of state.
|
|
103
|
+
*/
|
|
104
|
+
export declare type NetworksMetadata = {
|
|
105
|
+
[networkClientId: NetworkClientId]: NetworkMetadata;
|
|
106
|
+
};
|
|
86
107
|
/**
|
|
87
108
|
* The network ID of a network.
|
|
88
109
|
*/
|
|
@@ -97,11 +118,11 @@ export declare type NetworkId = `${number}`;
|
|
|
97
118
|
* @property networkConfigurations - the full list of configured networks either preloaded or added by the user.
|
|
98
119
|
*/
|
|
99
120
|
export declare type NetworkState = {
|
|
121
|
+
selectedNetworkClientId: NetworkClientId;
|
|
100
122
|
networkId: NetworkId | null;
|
|
101
|
-
networkStatus: NetworkStatus;
|
|
102
123
|
providerConfig: ProviderConfig;
|
|
103
|
-
networkDetails: NetworkDetails;
|
|
104
124
|
networkConfigurations: NetworkConfigurations;
|
|
125
|
+
networksMetadata: NetworksMetadata;
|
|
105
126
|
};
|
|
106
127
|
declare const name = "NetworkController";
|
|
107
128
|
/**
|
|
@@ -182,14 +203,6 @@ export declare type NetworkControllerOptions = {
|
|
|
182
203
|
};
|
|
183
204
|
export declare const defaultState: NetworkState;
|
|
184
205
|
declare type NetworkConfigurationId = string;
|
|
185
|
-
/**
|
|
186
|
-
* The string that uniquely identifies an Infura network client.
|
|
187
|
-
*/
|
|
188
|
-
declare type BuiltInNetworkClientId = InfuraNetworkType;
|
|
189
|
-
/**
|
|
190
|
-
* The string that uniquely identifies a custom network client.
|
|
191
|
-
*/
|
|
192
|
-
declare type CustomNetworkClientId = string;
|
|
193
206
|
/**
|
|
194
207
|
* The collection of auto-managed network clients that map to Infura networks.
|
|
195
208
|
*/
|
|
@@ -221,7 +234,23 @@ export declare class NetworkController extends BaseControllerV2<typeof name, Net
|
|
|
221
234
|
*
|
|
222
235
|
* @returns The list of known network clients.
|
|
223
236
|
*/
|
|
224
|
-
|
|
237
|
+
getNetworkClientRegistry(): AutoManagedBuiltInNetworkClientRegistry & AutoManagedCustomNetworkClientRegistry;
|
|
238
|
+
/**
|
|
239
|
+
* Returns the Infura network client with the given ID.
|
|
240
|
+
*
|
|
241
|
+
* @param infuraNetworkClientId - An Infura network client ID.
|
|
242
|
+
* @returns The Infura network client.
|
|
243
|
+
* @throws If an Infura network client does not exist with the given ID.
|
|
244
|
+
*/
|
|
245
|
+
getNetworkClientById(infuraNetworkClientId: BuiltInNetworkClientId): AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;
|
|
246
|
+
/**
|
|
247
|
+
* Returns the custom network client with the given ID.
|
|
248
|
+
*
|
|
249
|
+
* @param customNetworkClientId - A custom network client ID.
|
|
250
|
+
* @returns The custom network client.
|
|
251
|
+
* @throws If a custom network client does not exist with the given ID.
|
|
252
|
+
*/
|
|
253
|
+
getNetworkClientById(customNetworkClientId: CustomNetworkClientId): AutoManagedNetworkClient<CustomNetworkClientConfiguration>;
|
|
225
254
|
/**
|
|
226
255
|
* Populates the network clients and establishes the initial network based on
|
|
227
256
|
* the provider configuration in state.
|
|
@@ -257,9 +286,9 @@ export declare class NetworkController extends BaseControllerV2<typeof name, Net
|
|
|
257
286
|
* appropriately.
|
|
258
287
|
*
|
|
259
288
|
* @returns A promise that resolves to true if the network supports EIP-1559
|
|
260
|
-
*
|
|
289
|
+
* , false otherwise, or `undefined` if unable to determine the compatibility.
|
|
261
290
|
*/
|
|
262
|
-
getEIP1559Compatibility(): Promise<boolean>;
|
|
291
|
+
getEIP1559Compatibility(): Promise<boolean | undefined>;
|
|
263
292
|
/**
|
|
264
293
|
* Re-initializes the provider and block tracker for the current network.
|
|
265
294
|
*/
|
|
@@ -325,6 +354,13 @@ export declare class NetworkController extends BaseControllerV2<typeof name, Net
|
|
|
325
354
|
loadBackup({ networkConfigurations, }: {
|
|
326
355
|
networkConfigurations: NetworkState['networkConfigurations'];
|
|
327
356
|
}): void;
|
|
357
|
+
/**
|
|
358
|
+
* Searches for a network configuration ID with the given ChainID and returns it.
|
|
359
|
+
*
|
|
360
|
+
* @param chainId - ChainId to search for
|
|
361
|
+
* @returns networkClientId of the network configuration with the given chainId
|
|
362
|
+
*/
|
|
363
|
+
findNetworkClientIdByChainId(chainId: Hex): NetworkClientId;
|
|
328
364
|
}
|
|
329
365
|
export {};
|
|
330
366
|
//# sourceMappingURL=NetworkController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkController.d.ts","sourceRoot":"","sources":["../src/NetworkController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAKL,iBAAiB,EACjB,WAAW,EAEZ,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"NetworkController.d.ts","sourceRoot":"","sources":["../src/NetworkController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAKL,iBAAiB,EACjB,WAAW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M;IAqDrD;;;;;;;OAOG;IACG,uBAAuB;IAwC7B;;OAEG;IACG,eAAe;IAKrB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,0BAA0B,CAC9B,oBAAoB,EAAE,oBAAoB,EAC1C,EACE,QAAQ,EACR,MAAM,EACN,SAAiB,GAClB,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,GACA,OAAO,CAAC,MAAM,CAAC;IAuGlB;;;;;;;;;OASG;IACH,0BAA0B,CAAC,sBAAsB,EAAE,MAAM;IAuBzD;;;;OAIG;IACG,0BAA0B;IAUhC;;;;OAIG;IACG,OAAO;IAIb;;;;;OAKG;IACH,UAAU,CAAC,EACT,qBAAqB,GACtB,EAAE;QACD,qBAAqB,EAAE,YAAY,CAAC,uBAAuB,CAAC,CAAC;KAC9D,GAAG,IAAI;IASR;;;;;OAKG;IACH,4BAA4B,CAAC,OAAO,EAAE,GAAG,GAAG,eAAe;CA2P5D"}
|
|
@@ -27,10 +27,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
27
27
|
exports.NetworkController = exports.defaultState = exports.knownKeysOf = void 0;
|
|
28
28
|
const base_controller_1 = require("@metamask/base-controller");
|
|
29
29
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
30
|
+
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
30
31
|
const swappable_obj_proxy_1 = require("@metamask/swappable-obj-proxy");
|
|
31
32
|
const utils_1 = require("@metamask/utils");
|
|
32
33
|
const assert_1 = require("assert");
|
|
33
|
-
const eth_query_1 = __importDefault(require("eth-query"));
|
|
34
34
|
const eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
35
35
|
const uuid_1 = require("uuid");
|
|
36
36
|
const constants_1 = require("./constants");
|
|
@@ -209,16 +209,14 @@ function validateCustomProviderConfig(providerConfig) {
|
|
|
209
209
|
}
|
|
210
210
|
const name = 'NetworkController';
|
|
211
211
|
exports.defaultState = {
|
|
212
|
+
selectedNetworkClientId: controller_utils_1.NetworkType.mainnet,
|
|
212
213
|
networkId: null,
|
|
213
|
-
networkStatus: constants_1.NetworkStatus.Unknown,
|
|
214
214
|
providerConfig: {
|
|
215
215
|
type: controller_utils_1.NetworkType.mainnet,
|
|
216
216
|
chainId: controller_utils_1.ChainId.mainnet,
|
|
217
217
|
ticker: controller_utils_1.NetworksTicker.mainnet,
|
|
218
218
|
},
|
|
219
|
-
|
|
220
|
-
EIPS: {},
|
|
221
|
-
},
|
|
219
|
+
networksMetadata: {},
|
|
222
220
|
networkConfigurations: {},
|
|
223
221
|
};
|
|
224
222
|
/**
|
|
@@ -229,15 +227,15 @@ class NetworkController extends base_controller_1.BaseControllerV2 {
|
|
|
229
227
|
super({
|
|
230
228
|
name,
|
|
231
229
|
metadata: {
|
|
232
|
-
|
|
230
|
+
selectedNetworkClientId: {
|
|
233
231
|
persist: true,
|
|
234
232
|
anonymous: false,
|
|
235
233
|
},
|
|
236
|
-
|
|
234
|
+
networkId: {
|
|
237
235
|
persist: true,
|
|
238
236
|
anonymous: false,
|
|
239
237
|
},
|
|
240
|
-
|
|
238
|
+
networksMetadata: {
|
|
241
239
|
persist: true,
|
|
242
240
|
anonymous: false,
|
|
243
241
|
},
|
|
@@ -294,10 +292,28 @@ class NetworkController extends base_controller_1.BaseControllerV2 {
|
|
|
294
292
|
*
|
|
295
293
|
* @returns The list of known network clients.
|
|
296
294
|
*/
|
|
297
|
-
|
|
295
|
+
getNetworkClientRegistry() {
|
|
298
296
|
const autoManagedNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated).call(this);
|
|
299
297
|
return Object.assign({}, autoManagedNetworkClientRegistry[types_1.NetworkClientType.Infura], autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom]);
|
|
300
298
|
}
|
|
299
|
+
getNetworkClientById(networkClientId) {
|
|
300
|
+
if (!networkClientId) {
|
|
301
|
+
throw new Error('No network client ID was provided.');
|
|
302
|
+
}
|
|
303
|
+
const autoManagedNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated).call(this);
|
|
304
|
+
if (isInfuraProviderType(networkClientId)) {
|
|
305
|
+
const infuraNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Infura][networkClientId];
|
|
306
|
+
if (!infuraNetworkClient) {
|
|
307
|
+
throw new Error(`No Infura network client was found with the ID "${networkClientId}".`);
|
|
308
|
+
}
|
|
309
|
+
return infuraNetworkClient;
|
|
310
|
+
}
|
|
311
|
+
const customNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom][networkClientId];
|
|
312
|
+
if (!customNetworkClient) {
|
|
313
|
+
throw new Error(`No custom network client was found with the ID "${networkClientId}".`);
|
|
314
|
+
}
|
|
315
|
+
return customNetworkClient;
|
|
316
|
+
}
|
|
301
317
|
/**
|
|
302
318
|
* Populates the network clients and establishes the initial network based on
|
|
303
319
|
* the provider configuration in state.
|
|
@@ -381,12 +397,13 @@ class NetworkController extends base_controller_1.BaseControllerV2 {
|
|
|
381
397
|
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
382
398
|
this.update((state) => {
|
|
383
399
|
state.networkId = updatedNetworkId;
|
|
384
|
-
|
|
400
|
+
const meta = state.networksMetadata[state.selectedNetworkClientId];
|
|
401
|
+
meta.status = updatedNetworkStatus;
|
|
385
402
|
if (updatedIsEIP1559Compatible === undefined) {
|
|
386
|
-
delete
|
|
403
|
+
delete meta.EIPS[1559];
|
|
387
404
|
}
|
|
388
405
|
else {
|
|
389
|
-
|
|
406
|
+
meta.EIPS[1559] = updatedIsEIP1559Compatible;
|
|
390
407
|
}
|
|
391
408
|
});
|
|
392
409
|
if (isInfura) {
|
|
@@ -463,20 +480,23 @@ class NetworkController extends base_controller_1.BaseControllerV2 {
|
|
|
463
480
|
* appropriately.
|
|
464
481
|
*
|
|
465
482
|
* @returns A promise that resolves to true if the network supports EIP-1559
|
|
466
|
-
*
|
|
483
|
+
* , false otherwise, or `undefined` if unable to determine the compatibility.
|
|
467
484
|
*/
|
|
468
485
|
getEIP1559Compatibility() {
|
|
469
486
|
return __awaiter(this, void 0, void 0, function* () {
|
|
470
|
-
const { EIPS } = this.state.networkDetails;
|
|
471
|
-
if (EIPS[1559] !== undefined) {
|
|
472
|
-
return EIPS[1559];
|
|
473
|
-
}
|
|
474
487
|
if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
|
|
475
488
|
return false;
|
|
476
489
|
}
|
|
490
|
+
const { EIPS } = this.state.networksMetadata[this.state.selectedNetworkClientId];
|
|
491
|
+
if (EIPS[1559] !== undefined) {
|
|
492
|
+
return EIPS[1559];
|
|
493
|
+
}
|
|
477
494
|
const isEIP1559Compatible = yield __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this);
|
|
478
495
|
this.update((state) => {
|
|
479
|
-
|
|
496
|
+
if (isEIP1559Compatible !== undefined) {
|
|
497
|
+
state.networksMetadata[state.selectedNetworkClientId].EIPS[1559] =
|
|
498
|
+
isEIP1559Compatible;
|
|
499
|
+
}
|
|
480
500
|
});
|
|
481
501
|
return isEIP1559Compatible;
|
|
482
502
|
});
|
|
@@ -644,6 +664,20 @@ class NetworkController extends base_controller_1.BaseControllerV2 {
|
|
|
644
664
|
state.networkConfigurations = Object.assign(Object.assign({}, state.networkConfigurations), networkConfigurations);
|
|
645
665
|
});
|
|
646
666
|
}
|
|
667
|
+
/**
|
|
668
|
+
* Searches for a network configuration ID with the given ChainID and returns it.
|
|
669
|
+
*
|
|
670
|
+
* @param chainId - ChainId to search for
|
|
671
|
+
* @returns networkClientId of the network configuration with the given chainId
|
|
672
|
+
*/
|
|
673
|
+
findNetworkClientIdByChainId(chainId) {
|
|
674
|
+
const networkClients = this.getNetworkClientRegistry();
|
|
675
|
+
const networkClientEntry = Object.entries(networkClients).find(([_, networkClient]) => networkClient.configuration.chainId === chainId);
|
|
676
|
+
if (networkClientEntry === undefined) {
|
|
677
|
+
throw new Error("Couldn't find networkClientId for chainId");
|
|
678
|
+
}
|
|
679
|
+
return networkClientEntry[0];
|
|
680
|
+
}
|
|
647
681
|
}
|
|
648
682
|
exports.NetworkController = NetworkController;
|
|
649
683
|
_NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId = new WeakMap(), _NetworkController_trackMetaMetricsEvent = new WeakMap(), _NetworkController_previousProviderConfig = new WeakMap(), _NetworkController_providerProxy = new WeakMap(), _NetworkController_provider = new WeakMap(), _NetworkController_blockTrackerProxy = new WeakMap(), _NetworkController_autoManagedNetworkClientRegistry = new WeakMap(), _NetworkController_instances = new WeakSet(), _NetworkController_refreshNetwork = function _NetworkController_refreshNetwork() {
|
|
@@ -651,10 +685,6 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
651
685
|
this.messagingSystem.publish('NetworkController:networkWillChange');
|
|
652
686
|
this.update((state) => {
|
|
653
687
|
state.networkId = null;
|
|
654
|
-
state.networkStatus = constants_1.NetworkStatus.Unknown;
|
|
655
|
-
state.networkDetails = {
|
|
656
|
-
EIPS: {},
|
|
657
|
-
};
|
|
658
688
|
});
|
|
659
689
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this);
|
|
660
690
|
this.messagingSystem.publish('NetworkController:networkDidChange');
|
|
@@ -696,7 +726,10 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
696
726
|
}, _NetworkController_determineEIP1559Compatibility = function _NetworkController_determineEIP1559Compatibility() {
|
|
697
727
|
return __awaiter(this, void 0, void 0, function* () {
|
|
698
728
|
const latestBlock = yield __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_getLatestBlock).call(this);
|
|
699
|
-
|
|
729
|
+
if (!latestBlock) {
|
|
730
|
+
return undefined;
|
|
731
|
+
}
|
|
732
|
+
return latestBlock.baseFeePerGas !== undefined;
|
|
700
733
|
});
|
|
701
734
|
}, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated = function _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated() {
|
|
702
735
|
var _a;
|
|
@@ -725,6 +758,7 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
725
758
|
type: types_1.NetworkClientType.Infura,
|
|
726
759
|
network,
|
|
727
760
|
infuraProjectId: __classPrivateFieldGet(this, _NetworkController_infuraProjectId, "f"),
|
|
761
|
+
chainId: controller_utils_1.BUILT_IN_NETWORKS[network].chainId,
|
|
728
762
|
};
|
|
729
763
|
return [
|
|
730
764
|
types_1.NetworkClientType.Infura,
|
|
@@ -776,11 +810,13 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
776
810
|
}
|
|
777
811
|
const { providerConfig } = this.state;
|
|
778
812
|
let autoManagedNetworkClient;
|
|
813
|
+
let networkClientId;
|
|
779
814
|
if (isInfuraProviderConfig(providerConfig)) {
|
|
780
815
|
const networkClientType = types_1.NetworkClientType.Infura;
|
|
781
|
-
|
|
816
|
+
networkClientId = buildInfuraNetworkClientId(providerConfig);
|
|
782
817
|
const builtInNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClientRegistry, "f")[networkClientType];
|
|
783
|
-
autoManagedNetworkClient =
|
|
818
|
+
autoManagedNetworkClient =
|
|
819
|
+
builtInNetworkClientRegistry[networkClientId];
|
|
784
820
|
if (!autoManagedNetworkClient) {
|
|
785
821
|
throw new Error(`Could not find custom network matching ${networkClientId}`);
|
|
786
822
|
}
|
|
@@ -788,7 +824,7 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
788
824
|
else if (isCustomProviderConfig(providerConfig)) {
|
|
789
825
|
validateCustomProviderConfig(providerConfig);
|
|
790
826
|
const networkClientType = types_1.NetworkClientType.Custom;
|
|
791
|
-
|
|
827
|
+
networkClientId = buildCustomNetworkClientId(providerConfig, this.state.networkConfigurations);
|
|
792
828
|
const customNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClientRegistry, "f")[networkClientType];
|
|
793
829
|
autoManagedNetworkClient = customNetworkClientRegistry[networkClientId];
|
|
794
830
|
if (!autoManagedNetworkClient) {
|
|
@@ -798,6 +834,15 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
798
834
|
else {
|
|
799
835
|
throw new Error('Could not determine type of provider config');
|
|
800
836
|
}
|
|
837
|
+
this.update((state) => {
|
|
838
|
+
state.selectedNetworkClientId = networkClientId;
|
|
839
|
+
if (state.networksMetadata[networkClientId] === undefined) {
|
|
840
|
+
state.networksMetadata[networkClientId] = {
|
|
841
|
+
status: constants_1.NetworkStatus.Unknown,
|
|
842
|
+
EIPS: {},
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
});
|
|
801
846
|
const { provider, blockTracker } = autoManagedNetworkClient;
|
|
802
847
|
if (__classPrivateFieldGet(this, _NetworkController_providerProxy, "f")) {
|
|
803
848
|
__classPrivateFieldGet(this, _NetworkController_providerProxy, "f").setTarget(provider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkController.js","sourceRoot":"","sources":["../src/NetworkController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+DAA6D;AAC7D,iEAQoC;AACpC,uEAAwE;AAGxE,2CAKyB;AACzB,mCAA0C;AAC1C,0DAAiC;AACjC,mDAA4C;AAE5C,+BAAoC;AAEpC,2CAAgE;AAKhE,6FAAsF;AACtF,qCAA6D;AAC7D,mCAA4C;AAS5C,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,mBAAmB,CAAC,CAAC;AAmEnE;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CACzB,MAA+B;IAE/B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AC;QACF,MAAM,2BAA2B,GAC/B,uBAAA,IAAI,2DAAkC,CAAC,iBAAiB,CAAC,CAAC;QAC5D,wBAAwB,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;QACxE,IAAI,CAAC,wBAAwB,EAAE;YAC7B,MAAM,IAAI,KAAK,CACb,4CAA4C,eAAe,EAAE,CAC9D,CAAC;SACH;KACF;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;IAED,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,wBAAwB,CAAC;IAE5D,IAAI,uBAAA,IAAI,wCAAe,EAAE;QACvB,uBAAA,IAAI,wCAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;KACzC;SAAM;QACL,uBAAA,IAAI,oCAAkB,IAAA,6CAAuB,EAAC,QAAQ,CAAC,MAAA,CAAC;KACzD;IACD,uBAAA,IAAI,+BAAa,QAAQ,MAAA,CAAC;IAE1B,IAAI,uBAAA,IAAI,4CAAmB,EAAE;QAC3B,uBAAA,IAAI,4CAAmB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACL,uBAAA,IAAI,wCAAsB,IAAA,6CAAuB,EAAC,YAAY,EAAE;YAC9D,WAAW,EAAE,cAAc;SAC5B,CAAC,MAAA,CAAC;KACJ;IAED,uBAAA,IAAI,+BAAa,IAAI,mBAAQ,CAAC,uBAAA,IAAI,wCAAe,CAAC,MAAA,CAAC;AACrD,CAAC","sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseControllerV2 } from '@metamask/base-controller';\nimport {\n BUILT_IN_NETWORKS,\n convertHexToDecimal,\n NetworksTicker,\n ChainId,\n InfuraNetworkType,\n NetworkType,\n isSafeChainId,\n} from '@metamask/controller-utils';\nimport { createEventEmitterProxy } from '@metamask/swappable-obj-proxy';\nimport type { SwappableProxy } from '@metamask/swappable-obj-proxy';\nimport type { Hex } from '@metamask/utils';\nimport {\n assertIsStrictHexString,\n hasProperty,\n isPlainObject,\n isStrictHexString,\n} from '@metamask/utils';\nimport { strict as assert } from 'assert';\nimport EthQuery from 'eth-query';\nimport { errorCodes } from 'eth-rpc-errors';\nimport type { Patch } from 'immer';\nimport { v4 as random } from 'uuid';\n\nimport { INFURA_BLOCKED_KEY, NetworkStatus } from './constants';\nimport type {\n AutoManagedNetworkClient,\n ProxyWithAccessibleTarget,\n} from './create-auto-managed-network-client';\nimport { createAutoManagedNetworkClient } from './create-auto-managed-network-client';\nimport { projectLogger, createModuleLogger } from './logger';\nimport { NetworkClientType } from './types';\nimport type {\n BlockTracker,\n Provider,\n CustomNetworkClientConfiguration,\n InfuraNetworkClientConfiguration,\n NetworkClientConfiguration,\n} from './types';\n\nconst log = createModuleLogger(projectLogger, 'NetworkController');\n\n/**\n * @type ProviderConfig\n *\n * Configuration passed to web3-provider-engine\n * @property rpcUrl - RPC target URL.\n * @property type - Human-readable network name.\n * @property chainId - Network ID as per EIP-155.\n * @property ticker - Currency ticker.\n * @property nickname - Personalized network name.\n * @property id - Network Configuration Id.\n */\nexport type ProviderConfig = {\n rpcUrl?: string;\n type: NetworkType;\n chainId: Hex;\n ticker: string;\n nickname?: string;\n rpcPrefs?: { blockExplorerUrl?: string };\n id?: NetworkConfigurationId;\n};\n\nexport type Block = {\n baseFeePerGas?: string;\n};\n\n/**\n * Information about the network not held by any other part of state. Currently\n * only used to capture whether a network supports EIP-1559.\n */\nexport type NetworkDetails = {\n /**\n * EIPs supported by the network.\n */\n EIPS: {\n [eipNumber: number]: boolean;\n };\n};\n\n/**\n * Custom RPC network information\n *\n * @property rpcUrl - RPC target URL.\n * @property chainId - Network ID as per EIP-155\n * @property nickname - Personalized network name.\n * @property ticker - Currency ticker.\n * @property rpcPrefs - Personalized preferences.\n */\nexport type NetworkConfiguration = {\n rpcUrl: string;\n chainId: Hex;\n ticker: string;\n nickname?: string;\n rpcPrefs?: {\n blockExplorerUrl: string;\n };\n};\n\n/**\n * The collection of network configurations in state.\n */\ntype NetworkConfigurations = Record<\n NetworkConfigurationId,\n NetworkConfiguration & { id: NetworkConfigurationId }\n>;\n\n/**\n * `Object.keys()` is intentionally generic: it returns the keys of an object,\n * but it cannot make guarantees about the contents of that object, so the type\n * of the keys is merely `string[]`. While this is technically accurate, it is\n * also unnecessary if we have an object that we own and whose contents are\n * known exactly.\n *\n * TODO: Move to @metamask/utils.\n *\n * @param object - The object.\n * @returns The keys of an object, typed according to the type of the object\n * itself.\n */\nexport function knownKeysOf<K extends PropertyKey>(\n object: Partial<Record<K, any>>,\n) {\n return Object.keys(object) as K[];\n}\n\n/**\n * Asserts that the given value is of the given type if the given validation\n * function returns a truthy result.\n *\n * @param value - The value to validate.\n * @param validate - A function used to validate that the value is of the given\n * type. Takes the `value` as an argument and is expected to return true or\n * false.\n * @param message - The message to throw if the function does not return a\n * truthy result.\n * @throws if the function does not return a truthy result.\n */\nfunction assertOfType<Type>(\n value: unknown,\n validate: (value: unknown) => boolean,\n message: string,\n): asserts value is Type {\n assert.ok(validate(value), message);\n}\n\n/**\n * Returns a portion of the given object with only the given keys.\n *\n * @param object - An object.\n * @param keys - The keys to pick from the object.\n * @returns the portion of the object.\n */\nfunction pick<Obj extends Record<any, any>, Keys extends keyof Obj>(\n object: Obj,\n keys: Keys[],\n): Pick<Obj, Keys> {\n const pickedObject = keys.reduce<Partial<Pick<Obj, Keys>>>(\n (finalObject, key) => {\n return { ...finalObject, [key]: object[key] };\n },\n {},\n );\n assertOfType<Pick<Obj, Keys>>(\n pickedObject,\n () => keys.every((key) => key in pickedObject),\n 'The reduce did not produce an object with all of the desired keys.',\n );\n return pickedObject;\n}\n\n/**\n * Convert the given value into a valid network ID. The ID is accepted\n * as either a number, a decimal string, or a 0x-prefixed hex string.\n *\n * @param value - The network ID to convert, in an unknown format.\n * @returns A valid network ID (as a decimal string)\n * @throws If the given value cannot be safely parsed.\n */\nfunction convertNetworkId(value: unknown): NetworkId {\n if (typeof value === 'number' && !Number.isNaN(value)) {\n return `${value}`;\n } else if (isStrictHexString(value)) {\n return `${convertHexToDecimal(value)}`;\n } else if (typeof value === 'string' && /^\\d+$/u.test(value)) {\n return value as NetworkId;\n }\n throw new Error(`Cannot parse as a valid network ID: '${value}'`);\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `code` property, such as an instance of Error.\n *\n * TODO: Move this to @metamask/utils.\n *\n * @param error - The object to check.\n * @returns True if `error` has a `code`, false otherwise.\n */\nfunction isErrorWithCode(error: unknown): error is { code: string | number } {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n\n/**\n * Returns whether the given argument is a type that our Infura middleware\n * recognizes.\n *\n * @param type - A type to compare.\n * @returns True or false, depending on whether the given type is one that our\n * Infura middleware recognizes.\n */\nfunction isInfuraProviderType(type: string): type is InfuraNetworkType {\n return Object.keys(InfuraNetworkType).includes(type);\n}\n\n/**\n * Builds an identifier for an Infura network client for lookup purposes.\n *\n * @param infuraNetworkOrProviderConfig - The name of an Infura network or a\n * provider config.\n * @returns The built identifier.\n */\nfunction buildInfuraNetworkClientId(\n infuraNetworkOrProviderConfig:\n | InfuraNetworkType\n | (ProviderConfig & { type: InfuraNetworkType }),\n): BuiltInNetworkClientId {\n if (typeof infuraNetworkOrProviderConfig === 'string') {\n return infuraNetworkOrProviderConfig;\n }\n return infuraNetworkOrProviderConfig.type;\n}\n\n/**\n * Builds an identifier for a custom network client for lookup purposes.\n *\n * @param args - This function can be called two ways:\n * 1. The ID of a network configuration.\n * 2. A provider config and a set of network configurations.\n * @returns The built identifier.\n */\nfunction buildCustomNetworkClientId(\n ...args:\n | [NetworkConfigurationId]\n | [\n ProviderConfig & { type: typeof NetworkType.rpc; rpcUrl: string },\n NetworkConfigurations,\n ]\n): CustomNetworkClientId {\n if (args.length === 1) {\n return args[0];\n }\n const [{ id, rpcUrl }, networkConfigurations] = args;\n if (id === undefined) {\n const matchingNetworkConfiguration = Object.values(\n networkConfigurations,\n ).find((networkConfiguration) => {\n return networkConfiguration.rpcUrl === rpcUrl.toLowerCase();\n });\n if (matchingNetworkConfiguration) {\n return matchingNetworkConfiguration.id;\n }\n return rpcUrl.toLowerCase();\n }\n return id;\n}\n\n/**\n * Returns whether the given provider config refers to an Infura network.\n *\n * @param providerConfig - The provider config.\n * @returns True if the provider config refers to an Infura network, false\n * otherwise.\n */\nfunction isInfuraProviderConfig(\n providerConfig: ProviderConfig,\n): providerConfig is ProviderConfig & { type: InfuraNetworkType } {\n return isInfuraProviderType(providerConfig.type);\n}\n\n/**\n * Returns whether the given provider config refers to an Infura network.\n *\n * @param providerConfig - The provider config.\n * @returns True if the provider config refers to an Infura network, false\n * otherwise.\n */\nfunction isCustomProviderConfig(\n providerConfig: ProviderConfig,\n): providerConfig is ProviderConfig & { type: typeof NetworkType.rpc } {\n return providerConfig.type === NetworkType.rpc;\n}\n\n/**\n * As a provider config represents the settings that are used to interface with\n * an RPC endpoint, it must have both a chain ID and an RPC URL if it represents\n * a custom network. These properties _should_ be set as they are validated in\n * the UI when a user adds a custom network, but just to be safe we validate\n * them here.\n *\n * In addition, historically the `rpcUrl` property on the ProviderConfig type\n * has been optional, even though it should not be. Making this non-optional\n * would be a breaking change, so this function types the provider config\n * correctly so that we don't have to check `rpcUrl` in other places.\n *\n * @param providerConfig - A provider config.\n * @throws if the provider config does not have a chain ID or an RPC URL.\n */\nfunction validateCustomProviderConfig(\n providerConfig: ProviderConfig & { type: typeof NetworkType.rpc },\n): asserts providerConfig is typeof providerConfig & { rpcUrl: string } {\n if (providerConfig.chainId === undefined) {\n throw new Error('chainId must be provided for custom RPC endpoints');\n }\n if (providerConfig.rpcUrl === undefined) {\n throw new Error('rpcUrl must be provided for custom RPC endpoints');\n }\n}\n\n/**\n * The network ID of a network.\n */\nexport type NetworkId = `${number}`;\n\n/**\n * @type NetworkState\n *\n * Network controller state\n * @property network - Network ID as per net_version of the currently connected network\n * @property providerConfig - RPC URL and network name provider settings of the currently connected network\n * @property properties - an additional set of network properties for the currently connected network\n * @property networkConfigurations - the full list of configured networks either preloaded or added by the user.\n */\nexport type NetworkState = {\n networkId: NetworkId | null;\n networkStatus: NetworkStatus;\n providerConfig: ProviderConfig;\n networkDetails: NetworkDetails;\n networkConfigurations: NetworkConfigurations;\n};\n\nconst name = 'NetworkController';\n\n/**\n * Represents the block tracker for the currently selected network. (Note that\n * this is a proxy around a proxy: the inner one exists so that the block\n * tracker doesn't have to exist until it's used, and the outer one exists so\n * that the currently selected network can change without consumers needing to\n * refresh the object reference to that network.)\n */\nexport type BlockTrackerProxy = SwappableProxy<\n ProxyWithAccessibleTarget<BlockTracker>\n>;\n\n/**\n * Represents the provider for the currently selected network. (Note that this\n * is a proxy around a proxy: the inner one exists so that the provider doesn't\n * have to exist until it's used, and the outer one exists so that the currently\n * selected network can change without consumers needing to refresh the object\n * reference to that network.)\n */\nexport type ProviderProxy = SwappableProxy<ProxyWithAccessibleTarget<Provider>>;\n\nexport type NetworkControllerStateChangeEvent = {\n type: `NetworkController:stateChange`;\n payload: [NetworkState, Patch[]];\n};\n\n/**\n * `networkWillChange` is published when the current network is about to be\n * switched, but the new provider has not been created and no state changes have\n * occurred yet.\n */\nexport type NetworkControllerNetworkWillChangeEvent = {\n type: 'NetworkController:networkWillChange';\n payload: [];\n};\n\n/**\n * `networkDidChange` is published after a provider has been created for a newly\n * switched network (but before the network has been confirmed to be available).\n */\nexport type NetworkControllerNetworkDidChangeEvent = {\n type: 'NetworkController:networkDidChange';\n payload: [];\n};\n\n/**\n * `infuraIsBlocked` is published after the network is switched to an Infura\n * network, but when Infura returns an error blocking the user based on their\n * location.\n */\nexport type NetworkControllerInfuraIsBlockedEvent = {\n type: 'NetworkController:infuraIsBlocked';\n payload: [];\n};\n\n/**\n * `infuraIsBlocked` is published either after the network is switched to an\n * Infura network and Infura does not return an error blocking the user based on\n * their location, or the network is switched to a non-Infura network.\n */\nexport type NetworkControllerInfuraIsUnblockedEvent = {\n type: 'NetworkController:infuraIsUnblocked';\n payload: [];\n};\n\nexport type NetworkControllerEvents =\n | NetworkControllerStateChangeEvent\n | NetworkControllerNetworkWillChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | NetworkControllerInfuraIsBlockedEvent\n | NetworkControllerInfuraIsUnblockedEvent;\n\nexport type NetworkControllerGetStateAction = {\n type: `NetworkController:getState`;\n handler: () => NetworkState;\n};\n\nexport type NetworkControllerGetProviderConfigAction = {\n type: `NetworkController:getProviderConfig`;\n handler: () => ProviderConfig;\n};\n\nexport type NetworkControllerGetEthQueryAction = {\n type: `NetworkController:getEthQuery`;\n handler: () => EthQuery | undefined;\n};\n\nexport type NetworkControllerActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetProviderConfigAction\n | NetworkControllerGetEthQueryAction;\n\nexport type NetworkControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n NetworkControllerActions,\n NetworkControllerEvents,\n string,\n string\n>;\n\nexport type NetworkControllerOptions = {\n messenger: NetworkControllerMessenger;\n trackMetaMetricsEvent: () => void;\n infuraProjectId: string;\n state?: Partial<NetworkState>;\n};\n\nexport const defaultState: NetworkState = {\n networkId: null,\n networkStatus: NetworkStatus.Unknown,\n providerConfig: {\n type: NetworkType.mainnet,\n chainId: ChainId.mainnet,\n ticker: NetworksTicker.mainnet,\n },\n networkDetails: {\n EIPS: {},\n },\n networkConfigurations: {},\n};\n\ntype MetaMetricsEventPayload = {\n event: string;\n category: string;\n referrer?: { url: string };\n actionId?: number;\n environmentType?: string;\n properties?: unknown;\n sensitiveProperties?: unknown;\n revenue?: number;\n currency?: string;\n value?: number;\n};\n\ntype NetworkConfigurationId = string;\n\n/**\n * The string that uniquely identifies an Infura network client.\n */\ntype BuiltInNetworkClientId = InfuraNetworkType;\n\n/**\n * The string that uniquely identifies a custom network client.\n */\ntype CustomNetworkClientId = string;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\ntype AutoManagedBuiltInNetworkClientRegistry = Record<\n BuiltInNetworkClientId,\n AutoManagedNetworkClient<InfuraNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\ntype AutoManagedCustomNetworkClientRegistry = Record<\n CustomNetworkClientId,\n AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks\n * as well as custom networks that users have added.\n */\ntype AutoManagedNetworkClientRegistry = {\n [NetworkClientType.Infura]: AutoManagedBuiltInNetworkClientRegistry;\n [NetworkClientType.Custom]: AutoManagedCustomNetworkClientRegistry;\n};\n\n/**\n * Controller that creates and manages an Ethereum network provider.\n */\nexport class NetworkController extends BaseControllerV2<\n typeof name,\n NetworkState,\n NetworkControllerMessenger\n> {\n #ethQuery?: EthQuery;\n\n #infuraProjectId: string;\n\n #trackMetaMetricsEvent: (event: MetaMetricsEventPayload) => void;\n\n #previousProviderConfig: ProviderConfig;\n\n #providerProxy: ProviderProxy | undefined;\n\n #provider: ProxyWithAccessibleTarget<Provider> | undefined;\n\n #blockTrackerProxy: BlockTrackerProxy | undefined;\n\n #autoManagedNetworkClientRegistry?: AutoManagedNetworkClientRegistry;\n\n constructor({\n messenger,\n state,\n infuraProjectId,\n trackMetaMetricsEvent,\n }: NetworkControllerOptions) {\n super({\n name,\n metadata: {\n networkId: {\n persist: true,\n anonymous: false,\n },\n networkStatus: {\n persist: true,\n anonymous: false,\n },\n networkDetails: {\n persist: true,\n anonymous: false,\n },\n providerConfig: {\n persist: true,\n anonymous: false,\n },\n networkConfigurations: {\n persist: true,\n anonymous: false,\n },\n },\n messenger,\n state: { ...defaultState, ...state },\n });\n if (!infuraProjectId || typeof infuraProjectId !== 'string') {\n throw new Error('Invalid Infura project ID');\n }\n this.#infuraProjectId = infuraProjectId;\n this.#trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.messagingSystem.registerActionHandler(\n `${this.name}:getProviderConfig`,\n () => {\n return this.state.providerConfig;\n },\n );\n\n this.messagingSystem.registerActionHandler(\n `${this.name}:getEthQuery`,\n () => {\n return this.#ethQuery;\n },\n );\n\n this.#previousProviderConfig = this.state.providerConfig;\n }\n\n /**\n * Accesses the provider and block tracker for the currently selected network.\n *\n * @returns The proxy and block tracker proxies.\n */\n getProviderAndBlockTracker(): {\n provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>> | undefined;\n blockTracker:\n | SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>\n | undefined;\n } {\n return {\n provider: this.#providerProxy,\n blockTracker: this.#blockTrackerProxy,\n };\n }\n\n /**\n * Returns all of the network clients that have been created so far, keyed by\n * their identifier in the network client registry. This collection represents\n * not only built-in networks but also any custom networks that consumers have\n * added.\n *\n * @returns The list of known network clients.\n */\n getNetworkClientsById(): AutoManagedBuiltInNetworkClientRegistry &\n AutoManagedCustomNetworkClientRegistry {\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n return Object.assign(\n {},\n autoManagedNetworkClientRegistry[NetworkClientType.Infura],\n autoManagedNetworkClientRegistry[NetworkClientType.Custom],\n );\n }\n\n /**\n * Executes a series of steps to apply the changes to the provider config:\n *\n * 1. Notifies subscribers that the network is about to change.\n * 2. Clears state associated with the current network.\n * 3. Looks up a known and preinitialized network client matching the provider\n * config and re-points the provider and block tracker proxy to it.\n * 4. Notifies subscribers that the network has changed.\n */\n async #refreshNetwork() {\n this.messagingSystem.publish('NetworkController:networkWillChange');\n this.update((state) => {\n state.networkId = null;\n state.networkStatus = NetworkStatus.Unknown;\n state.networkDetails = {\n EIPS: {},\n };\n });\n this.#applyNetworkSelection();\n this.messagingSystem.publish('NetworkController:networkDidChange');\n await this.lookupNetwork();\n }\n\n /**\n * Populates the network clients and establishes the initial network based on\n * the provider configuration in state.\n */\n async initializeProvider() {\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.#applyNetworkSelection();\n await this.lookupNetwork();\n }\n\n /**\n * Fetches the network ID for the network, ensuring that it is a hex string.\n *\n * @returns A promise that either resolves to the network ID, or rejects with\n * an error.\n * @throws If the network ID of the network is not a valid hex string.\n */\n async #getNetworkId(): Promise<NetworkId> {\n const possibleNetworkId = await new Promise<string>((resolve, reject) => {\n if (!this.#ethQuery) {\n throw new Error('Provider has not been initialized');\n }\n\n this.#ethQuery.sendAsync(\n { method: 'net_version' },\n (error: unknown, result?: unknown) => {\n if (error) {\n reject(error);\n } else {\n // TODO: Validate this type\n resolve(result as string);\n }\n },\n );\n });\n\n return convertNetworkId(possibleNetworkId);\n }\n\n /**\n * Performs side effects after switching to a network. If the network is\n * available, updates the network state with the network ID of the network and\n * stores whether the network supports EIP-1559; otherwise clears said\n * information about the network that may have been previously stored.\n *\n * @fires infuraIsBlocked if the network is Infura-supported and is blocking\n * requests.\n * @fires infuraIsUnblocked if the network is Infura-supported and is not\n * blocking requests, or if the network is not Infura-supported.\n */\n async lookupNetwork() {\n if (!this.#ethQuery) {\n return;\n }\n\n const isInfura = isInfuraProviderConfig(this.state.providerConfig);\n\n let networkChanged = false;\n const listener = () => {\n networkChanged = true;\n this.messagingSystem.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n };\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n\n let updatedNetworkStatus: NetworkStatus;\n let updatedNetworkId: NetworkId | null = null;\n let updatedIsEIP1559Compatible: boolean | undefined;\n\n try {\n const [networkId, isEIP1559Compatible] = await Promise.all([\n this.#getNetworkId(),\n this.#determineEIP1559Compatibility(),\n ]);\n updatedNetworkStatus = NetworkStatus.Available;\n updatedNetworkId = networkId;\n updatedIsEIP1559Compatible = isEIP1559Compatible;\n } catch (error) {\n if (isErrorWithCode(error)) {\n let responseBody;\n if (\n isInfura &&\n hasProperty(error, 'message') &&\n typeof error.message === 'string'\n ) {\n try {\n responseBody = JSON.parse(error.message);\n } catch {\n // error.message must not be JSON\n }\n }\n\n if (\n isPlainObject(responseBody) &&\n responseBody.error === INFURA_BLOCKED_KEY\n ) {\n updatedNetworkStatus = NetworkStatus.Blocked;\n } else if (error.code === errorCodes.rpc.internal) {\n updatedNetworkStatus = NetworkStatus.Unknown;\n } else {\n updatedNetworkStatus = NetworkStatus.Unavailable;\n }\n } else {\n log('NetworkController - could not determine network status', error);\n updatedNetworkStatus = NetworkStatus.Unknown;\n }\n }\n\n if (networkChanged) {\n // If the network has changed, then `lookupNetwork` either has been or is\n // in the process of being called, so we don't need to go further.\n return;\n }\n this.messagingSystem.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n\n this.update((state) => {\n state.networkId = updatedNetworkId;\n state.networkStatus = updatedNetworkStatus;\n if (updatedIsEIP1559Compatible === undefined) {\n delete state.networkDetails.EIPS[1559];\n } else {\n state.networkDetails.EIPS[1559] = updatedIsEIP1559Compatible;\n }\n });\n\n if (isInfura) {\n if (updatedNetworkStatus === NetworkStatus.Available) {\n this.messagingSystem.publish('NetworkController:infuraIsUnblocked');\n } else if (updatedNetworkStatus === NetworkStatus.Blocked) {\n this.messagingSystem.publish('NetworkController:infuraIsBlocked');\n }\n } else {\n // Always publish infuraIsUnblocked regardless of network status to\n // prevent consumers from being stuck in a blocked state if they were\n // previously connected to an Infura network that was blocked\n this.messagingSystem.publish('NetworkController:infuraIsUnblocked');\n }\n }\n\n /**\n * Convenience method to update provider network type settings.\n *\n * @param type - Human readable network name.\n */\n async setProviderType(type: InfuraNetworkType) {\n assert.notStrictEqual(\n type,\n NetworkType.rpc,\n `NetworkController - cannot call \"setProviderType\" with type \"${NetworkType.rpc}\". Use \"setActiveNetwork\"`,\n );\n assert.ok(\n isInfuraProviderType(type),\n `Unknown Infura provider type \"${type}\".`,\n );\n\n this.#previousProviderConfig = this.state.providerConfig;\n\n // If testnet the ticker symbol should use a testnet prefix\n const ticker =\n type in NetworksTicker && NetworksTicker[type].length > 0\n ? NetworksTicker[type]\n : 'ETH';\n\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.update((state) => {\n state.providerConfig.type = type;\n state.providerConfig.ticker = ticker;\n state.providerConfig.chainId = ChainId[type];\n state.providerConfig.rpcPrefs = BUILT_IN_NETWORKS[type].rpcPrefs;\n state.providerConfig.rpcUrl = undefined;\n state.providerConfig.nickname = undefined;\n state.providerConfig.id = undefined;\n });\n await this.#refreshNetwork();\n }\n\n /**\n * Convenience method to update provider RPC settings.\n *\n * @param networkConfigurationId - The unique id for the network configuration to set as the active provider.\n */\n async setActiveNetwork(networkConfigurationId: string) {\n this.#previousProviderConfig = this.state.providerConfig;\n\n const targetNetwork =\n this.state.networkConfigurations[networkConfigurationId];\n\n if (!targetNetwork) {\n throw new Error(\n `networkConfigurationId ${networkConfigurationId} does not match a configured networkConfiguration`,\n );\n }\n\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.update((state) => {\n state.providerConfig.type = NetworkType.rpc;\n state.providerConfig.rpcUrl = targetNetwork.rpcUrl;\n state.providerConfig.chainId = targetNetwork.chainId;\n state.providerConfig.ticker = targetNetwork.ticker;\n state.providerConfig.nickname = targetNetwork.nickname;\n state.providerConfig.rpcPrefs = targetNetwork.rpcPrefs;\n state.providerConfig.id = targetNetwork.id;\n });\n\n await this.#refreshNetwork();\n }\n\n /**\n * Fetches the latest block for the network.\n *\n * @returns A promise that either resolves to the block header or null if\n * there is no latest block, or rejects with an error.\n */\n #getLatestBlock(): Promise<Block> {\n return new Promise((resolve, reject) => {\n if (!this.#ethQuery) {\n throw new Error('Provider has not been initialized');\n }\n\n this.#ethQuery.sendAsync(\n { method: 'eth_getBlockByNumber', params: ['latest', false] },\n (error: unknown, block?: unknown) => {\n if (error) {\n reject(error);\n } else {\n // TODO: Validate this type\n resolve(block as Block);\n }\n },\n );\n });\n }\n\n /**\n * Determines whether the network supports EIP-1559 by checking whether the\n * latest block has a `baseFeePerGas` property, then updates state\n * appropriately.\n *\n * @returns A promise that resolves to true if the network supports EIP-1559\n * and false otherwise.\n */\n async getEIP1559Compatibility() {\n const { EIPS } = this.state.networkDetails;\n\n if (EIPS[1559] !== undefined) {\n return EIPS[1559];\n }\n\n if (!this.#ethQuery) {\n return false;\n }\n\n const isEIP1559Compatible = await this.#determineEIP1559Compatibility();\n this.update((state) => {\n state.networkDetails.EIPS[1559] = isEIP1559Compatible;\n });\n return isEIP1559Compatible;\n }\n\n /**\n * Retrieves the latest block from the currently selected network; if the\n * block has a `baseFeePerGas` property, then we know that the network\n * supports EIP-1559; otherwise it doesn't.\n *\n * @returns A promise that resolves to true if the network supports EIP-1559\n * and false otherwise.\n */\n async #determineEIP1559Compatibility(): Promise<boolean> {\n const latestBlock = await this.#getLatestBlock();\n return latestBlock?.baseFeePerGas !== undefined;\n }\n\n /**\n * Re-initializes the provider and block tracker for the current network.\n */\n async resetConnection() {\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n await this.#refreshNetwork();\n }\n\n /**\n * Adds a new custom network or updates the information for an existing\n * network.\n *\n * This may involve updating the `networkConfigurations` property in\n * state as well and/or adding a new network client to the network client\n * registry. The `rpcUrl` and `chainId` of the given object are used to\n * determine which action to take:\n *\n * - If the `rpcUrl` corresponds to an existing network configuration\n * (case-insensitively), then it is overwritten with the object. Furthermore,\n * if the `chainId` is different from the existing network configuration, then\n * the existing network client is replaced with a new one.\n * - If the `rpcUrl` does not correspond to an existing network configuration\n * (case-insensitively), then the object is used to add a new network\n * configuration along with a new network client.\n *\n * @param networkConfiguration - The network configuration to add or update.\n * @param options - Additional configuration options.\n * @param options.referrer - Used to create a metrics event; the site from which the call originated, or 'metamask' for internal calls.\n * @param options.source - Used to create a metrics event; where the event originated (i.e. from a dapp or from the network form).\n * @param options.setActive - If true, switches to the network upon adding or updating it (default: false).\n * @returns The ID for the added or updated network configuration.\n */\n async upsertNetworkConfiguration(\n networkConfiguration: NetworkConfiguration,\n {\n referrer,\n source,\n setActive = false,\n }: {\n referrer: string;\n source: string;\n setActive?: boolean;\n },\n ): Promise<string> {\n const sanitizedNetworkConfiguration: NetworkConfiguration = pick(\n networkConfiguration,\n ['rpcUrl', 'chainId', 'ticker', 'nickname', 'rpcPrefs'],\n );\n const { rpcUrl, chainId, ticker } = sanitizedNetworkConfiguration;\n\n assertIsStrictHexString(chainId);\n if (!isSafeChainId(chainId)) {\n throw new Error(\n `Invalid chain ID \"${chainId}\": numerical value greater than max safe value.`,\n );\n }\n if (!rpcUrl) {\n throw new Error(\n 'An rpcUrl is required to add or update network configuration',\n );\n }\n if (!referrer || !source) {\n throw new Error(\n 'referrer and source are required arguments for adding or updating a network configuration',\n );\n }\n try {\n new URL(rpcUrl);\n } catch (e: any) {\n if (e.message.includes('Invalid URL')) {\n throw new Error('rpcUrl must be a valid URL');\n }\n }\n if (!ticker) {\n throw new Error(\n 'A ticker is required to add or update networkConfiguration',\n );\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n const existingNetworkConfiguration = Object.values(\n this.state.networkConfigurations,\n ).find(\n (networkConfig) =>\n networkConfig.rpcUrl.toLowerCase() === rpcUrl.toLowerCase(),\n );\n const upsertedNetworkConfigurationId = existingNetworkConfiguration\n ? existingNetworkConfiguration.id\n : random();\n const networkClientId = buildCustomNetworkClientId(\n upsertedNetworkConfigurationId,\n );\n\n this.update((state) => {\n state.networkConfigurations[upsertedNetworkConfigurationId] = {\n id: upsertedNetworkConfigurationId,\n ...sanitizedNetworkConfiguration,\n };\n });\n\n const customNetworkClientRegistry =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom];\n const existingAutoManagedNetworkClient =\n customNetworkClientRegistry[networkClientId];\n const shouldDestroyExistingNetworkClient =\n existingAutoManagedNetworkClient &&\n existingAutoManagedNetworkClient.configuration.chainId !== chainId;\n if (shouldDestroyExistingNetworkClient) {\n existingAutoManagedNetworkClient.destroy();\n }\n if (\n !existingAutoManagedNetworkClient ||\n shouldDestroyExistingNetworkClient\n ) {\n customNetworkClientRegistry[networkClientId] =\n createAutoManagedNetworkClient({\n type: NetworkClientType.Custom,\n chainId,\n rpcUrl,\n });\n }\n\n if (!existingNetworkConfiguration) {\n this.#trackMetaMetricsEvent({\n event: 'Custom Network Added',\n category: 'Network',\n referrer: {\n url: referrer,\n },\n properties: {\n chain_id: chainId,\n symbol: ticker,\n source,\n },\n });\n }\n\n if (setActive) {\n await this.setActiveNetwork(upsertedNetworkConfigurationId);\n }\n\n return upsertedNetworkConfigurationId;\n }\n\n /**\n * Removes a custom network from state.\n *\n * This involves updating the `networkConfigurations` property in state as\n * well and removing the network client that corresponds to the network from\n * the client registry.\n *\n * @param networkConfigurationId - The ID of an existing network\n * configuration.\n */\n removeNetworkConfiguration(networkConfigurationId: string) {\n if (!this.state.networkConfigurations[networkConfigurationId]) {\n throw new Error(\n `networkConfigurationId ${networkConfigurationId} does not match a configured networkConfiguration`,\n );\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n const networkClientId = buildCustomNetworkClientId(networkConfigurationId);\n\n this.update((state) => {\n delete state.networkConfigurations[networkConfigurationId];\n });\n\n const customNetworkClientRegistry =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom];\n const existingAutoManagedNetworkClient =\n customNetworkClientRegistry[networkClientId];\n existingAutoManagedNetworkClient.destroy();\n delete customNetworkClientRegistry[networkClientId];\n }\n\n /**\n * Switches to the previously selected network, assuming that there is one\n * (if not and `initializeProvider` has not been previously called, then this\n * method is equivalent to calling `resetConnection`).\n */\n async rollbackToPreviousProvider() {\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.update((state) => {\n state.providerConfig = this.#previousProviderConfig;\n });\n\n await this.#refreshNetwork();\n }\n\n /**\n * Deactivates the controller, stopping any ongoing polling.\n *\n * In-progress requests will not be aborted.\n */\n async destroy() {\n await this.#blockTrackerProxy?.destroy();\n }\n\n /**\n * Updates the controller using the given backup data.\n *\n * @param backup - The data that has been backed up.\n * @param backup.networkConfigurations - Network configurations in the backup.\n */\n loadBackup({\n networkConfigurations,\n }: {\n networkConfigurations: NetworkState['networkConfigurations'];\n }): void {\n this.update((state) => {\n state.networkConfigurations = {\n ...state.networkConfigurations,\n ...networkConfigurations,\n };\n });\n }\n\n /**\n * Before accessing or switching the network, the registry of network clients\n * needs to be populated. Otherwise, `#applyNetworkSelection` and\n * `getNetworkClients` will throw an error. This method checks to see if the\n * population step has happened yet, and if not, makes it happen.\n *\n * @returns The populated network client registry.\n */\n #ensureAutoManagedNetworkClientRegistryPopulated(): AutoManagedNetworkClientRegistry {\n const autoManagedNetworkClientRegistry =\n this.#autoManagedNetworkClientRegistry ??\n this.#createAutoManagedNetworkClientRegistry();\n this.#autoManagedNetworkClientRegistry = autoManagedNetworkClientRegistry;\n return autoManagedNetworkClientRegistry;\n }\n\n /**\n * Constructs the registry of network clients based on the set of built-in\n * networks as well as the custom networks in state.\n *\n * @returns The network clients keyed by ID.\n */\n #createAutoManagedNetworkClientRegistry(): AutoManagedNetworkClientRegistry {\n return [\n ...this.#buildIdentifiedInfuraNetworkClientConfigurations(),\n ...this.#buildIdentifiedCustomNetworkClientConfigurations(),\n ...this.#buildIdentifiedNetworkClientConfigurationsFromProviderConfig(),\n ].reduce(\n (\n registry,\n [networkClientType, networkClientId, networkClientConfiguration],\n ) => {\n const autoManagedNetworkClient = createAutoManagedNetworkClient(\n networkClientConfiguration,\n );\n if (networkClientId in registry[networkClientType]) {\n return registry;\n }\n return {\n ...registry,\n [networkClientType]: {\n ...registry[networkClientType],\n [networkClientId]: autoManagedNetworkClient,\n },\n };\n },\n {\n [NetworkClientType.Infura]: {},\n [NetworkClientType.Custom]: {},\n },\n ) as AutoManagedNetworkClientRegistry;\n }\n\n /**\n * Constructs the list of network clients for built-in networks (that is,\n * the subset of the networks we know Infura supports that consumers do not\n * need to explicitly add).\n *\n * @returns The network clients.\n */\n #buildIdentifiedInfuraNetworkClientConfigurations(): [\n NetworkClientType.Infura,\n BuiltInNetworkClientId,\n InfuraNetworkClientConfiguration,\n ][] {\n return knownKeysOf(InfuraNetworkType).map((network) => {\n const networkClientId = buildInfuraNetworkClientId(network);\n const networkClientConfiguration: InfuraNetworkClientConfiguration = {\n type: NetworkClientType.Infura,\n network,\n infuraProjectId: this.#infuraProjectId,\n };\n return [\n NetworkClientType.Infura,\n networkClientId,\n networkClientConfiguration,\n ];\n });\n }\n\n /**\n * Constructs the list of network clients for custom networks (that is, those\n * which consumers have added via `networkConfigurations`).\n *\n * @returns The network clients.\n */\n #buildIdentifiedCustomNetworkClientConfigurations(): [\n NetworkClientType.Custom,\n CustomNetworkClientId,\n CustomNetworkClientConfiguration,\n ][] {\n return Object.entries(this.state.networkConfigurations).map(\n ([networkConfigurationId, networkConfiguration]) => {\n if (networkConfiguration.chainId === undefined) {\n throw new Error('chainId must be provided for custom RPC endpoints');\n }\n if (networkConfiguration.rpcUrl === undefined) {\n throw new Error('rpcUrl must be provided for custom RPC endpoints');\n }\n const networkClientId = buildCustomNetworkClientId(\n networkConfigurationId,\n );\n const networkClientConfiguration: CustomNetworkClientConfiguration = {\n type: NetworkClientType.Custom,\n chainId: networkConfiguration.chainId,\n rpcUrl: networkConfiguration.rpcUrl,\n };\n return [\n NetworkClientType.Custom,\n networkClientId,\n networkClientConfiguration,\n ];\n },\n );\n }\n\n /**\n * Converts the provider config object in state to a network client\n * configuration object.\n *\n * @returns The network client config.\n * @throws If the provider config is of type \"rpc\" and lacks either a\n * `chainId` or an `rpcUrl`.\n */\n #buildIdentifiedNetworkClientConfigurationsFromProviderConfig():\n | [\n [\n NetworkClientType.Custom,\n CustomNetworkClientId,\n CustomNetworkClientConfiguration,\n ],\n ]\n | [] {\n const { providerConfig } = this.state;\n\n if (isCustomProviderConfig(providerConfig)) {\n validateCustomProviderConfig(providerConfig);\n const networkClientId = buildCustomNetworkClientId(\n providerConfig,\n this.state.networkConfigurations,\n );\n const networkClientConfiguration: CustomNetworkClientConfiguration = {\n chainId: providerConfig.chainId,\n rpcUrl: providerConfig.rpcUrl,\n type: NetworkClientType.Custom,\n };\n return [\n [NetworkClientType.Custom, networkClientId, networkClientConfiguration],\n ];\n }\n\n if (isInfuraProviderConfig(providerConfig)) {\n return [];\n }\n\n throw new Error(`Unrecognized network type: '${providerConfig.type}'`);\n }\n\n /**\n * Uses the information in the provider config object to look up a known and\n * preinitialized network client. Once a network client is found, updates the\n * provider and block tracker proxy to point to those from the network client,\n * then finally creates an EthQuery that points to the provider proxy.\n *\n * @throws If no network client could be found matching the current provider\n * config.\n */\n #applyNetworkSelection() {\n if (!this.#autoManagedNetworkClientRegistry) {\n throw new Error(\n 'initializeProvider must be called first in order to switch the network',\n );\n }\n\n const { providerConfig } = this.state;\n\n let autoManagedNetworkClient: AutoManagedNetworkClient<NetworkClientConfiguration>;\n\n if (isInfuraProviderConfig(providerConfig)) {\n const networkClientType = NetworkClientType.Infura;\n const networkClientId = buildInfuraNetworkClientId(providerConfig);\n const builtInNetworkClientRegistry =\n this.#autoManagedNetworkClientRegistry[networkClientType];\n autoManagedNetworkClient = builtInNetworkClientRegistry[networkClientId];\n if (!autoManagedNetworkClient) {\n throw new Error(\n `Could not find custom network matching ${networkClientId}`,\n );\n }\n } else if (isCustomProviderConfig(providerConfig)) {\n validateCustomProviderConfig(providerConfig);\n const networkClientType = NetworkClientType.Custom;\n const networkClientId = buildCustomNetworkClientId(\n providerConfig,\n this.state.networkConfigurations,\n );\n const customNetworkClientRegistry =\n this.#autoManagedNetworkClientRegistry[networkClientType];\n autoManagedNetworkClient = customNetworkClientRegistry[networkClientId];\n if (!autoManagedNetworkClient) {\n throw new Error(\n `Could not find built-in network matching ${networkClientId}`,\n );\n }\n } else {\n throw new Error('Could not determine type of provider config');\n }\n\n const { provider, blockTracker } = autoManagedNetworkClient;\n\n if (this.#providerProxy) {\n this.#providerProxy.setTarget(provider);\n } else {\n this.#providerProxy = createEventEmitterProxy(provider);\n }\n this.#provider = provider;\n\n if (this.#blockTrackerProxy) {\n this.#blockTrackerProxy.setTarget(blockTracker);\n } else {\n this.#blockTrackerProxy = createEventEmitterProxy(blockTracker, {\n eventFilter: 'skipInternal',\n });\n }\n\n this.#ethQuery = new EthQuery(this.#providerProxy);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"N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C,QAAQ,CAAC,CAAC;KACzC;SAAM;QACL,uBAAA,IAAI,oCAAkB,IAAA,6CAAuB,EAAC,QAAQ,CAAC,MAAA,CAAC;KACzD;IACD,uBAAA,IAAI,+BAAa,QAAQ,MAAA,CAAC;IAE1B,IAAI,uBAAA,IAAI,4CAAmB,EAAE;QAC3B,uBAAA,IAAI,4CAAmB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACL,uBAAA,IAAI,wCAAsB,IAAA,6CAAuB,EAAC,YAAY,EAAE;YAC9D,WAAW,EAAE,cAAc;SAC5B,CAAC,MAAA,CAAC;KACJ;IAED,uBAAA,IAAI,+BAAa,IAAI,mBAAQ,CAAC,uBAAA,IAAI,wCAAe,CAAC,MAAA,CAAC;AACrD,CAAC","sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseControllerV2 } from '@metamask/base-controller';\nimport {\n BUILT_IN_NETWORKS,\n convertHexToDecimal,\n NetworksTicker,\n ChainId,\n InfuraNetworkType,\n NetworkType,\n isSafeChainId,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport { createEventEmitterProxy } from '@metamask/swappable-obj-proxy';\nimport type { SwappableProxy } from '@metamask/swappable-obj-proxy';\nimport type { Hex } from '@metamask/utils';\nimport {\n assertIsStrictHexString,\n hasProperty,\n isPlainObject,\n isStrictHexString,\n} from '@metamask/utils';\nimport { strict as assert } from 'assert';\nimport { errorCodes } from 'eth-rpc-errors';\nimport type { Patch } from 'immer';\nimport { v4 as random } from 'uuid';\n\nimport { INFURA_BLOCKED_KEY, NetworkStatus } from './constants';\nimport type {\n AutoManagedNetworkClient,\n ProxyWithAccessibleTarget,\n} from './create-auto-managed-network-client';\nimport { createAutoManagedNetworkClient } from './create-auto-managed-network-client';\nimport { projectLogger, createModuleLogger } from './logger';\nimport { NetworkClientType } from './types';\nimport type {\n BlockTracker,\n Provider,\n CustomNetworkClientConfiguration,\n InfuraNetworkClientConfiguration,\n NetworkClientConfiguration,\n} from './types';\n\nconst log = createModuleLogger(projectLogger, 'NetworkController');\n\n/**\n * @type ProviderConfig\n *\n * Configuration passed to web3-provider-engine\n * @property rpcUrl - RPC target URL.\n * @property type - Human-readable network name.\n * @property chainId - Network ID as per EIP-155.\n * @property ticker - Currency ticker.\n * @property nickname - Personalized network name.\n * @property id - Network Configuration Id.\n */\nexport type ProviderConfig = {\n rpcUrl?: string;\n type: NetworkType;\n chainId: Hex;\n ticker: string;\n nickname?: string;\n rpcPrefs?: { blockExplorerUrl?: string };\n id?: NetworkConfigurationId;\n};\n\nexport type Block = {\n baseFeePerGas?: string;\n};\n\n/**\n * Information about a network not held by any other part of state.\n */\nexport type NetworkMetadata = {\n /**\n * EIPs supported by the network.\n */\n EIPS: {\n [eipNumber: number]: boolean;\n };\n /**\n * Indicates the availability of the network\n */\n status: NetworkStatus;\n};\n\n/**\n * Custom RPC network information\n *\n * @property rpcUrl - RPC target URL.\n * @property chainId - Network ID as per EIP-155\n * @property nickname - Personalized network name.\n * @property ticker - Currency ticker.\n * @property rpcPrefs - Personalized preferences.\n */\nexport type NetworkConfiguration = {\n rpcUrl: string;\n chainId: Hex;\n ticker: string;\n nickname?: string;\n rpcPrefs?: {\n blockExplorerUrl: string;\n };\n};\n\n/**\n * The collection of network configurations in state.\n */\ntype NetworkConfigurations = Record<\n NetworkConfigurationId,\n NetworkConfiguration & { id: NetworkConfigurationId }\n>;\n\n/**\n * `Object.keys()` is intentionally generic: it returns the keys of an object,\n * but it cannot make guarantees about the contents of that object, so the type\n * of the keys is merely `string[]`. While this is technically accurate, it is\n * also unnecessary if we have an object that we own and whose contents are\n * known exactly.\n *\n * TODO: Move to @metamask/utils.\n *\n * @param object - The object.\n * @returns The keys of an object, typed according to the type of the object\n * itself.\n */\nexport function knownKeysOf<K extends PropertyKey>(\n object: Partial<Record<K, any>>,\n) {\n return Object.keys(object) as K[];\n}\n\n/**\n * Asserts that the given value is of the given type if the given validation\n * function returns a truthy result.\n *\n * @param value - The value to validate.\n * @param validate - A function used to validate that the value is of the given\n * type. Takes the `value` as an argument and is expected to return true or\n * false.\n * @param message - The message to throw if the function does not return a\n * truthy result.\n * @throws if the function does not return a truthy result.\n */\nfunction assertOfType<Type>(\n value: unknown,\n validate: (value: unknown) => boolean,\n message: string,\n): asserts value is Type {\n assert.ok(validate(value), message);\n}\n\n/**\n * Returns a portion of the given object with only the given keys.\n *\n * @param object - An object.\n * @param keys - The keys to pick from the object.\n * @returns the portion of the object.\n */\nfunction pick<Obj extends Record<any, any>, Keys extends keyof Obj>(\n object: Obj,\n keys: Keys[],\n): Pick<Obj, Keys> {\n const pickedObject = keys.reduce<Partial<Pick<Obj, Keys>>>(\n (finalObject, key) => {\n return { ...finalObject, [key]: object[key] };\n },\n {},\n );\n assertOfType<Pick<Obj, Keys>>(\n pickedObject,\n () => keys.every((key) => key in pickedObject),\n 'The reduce did not produce an object with all of the desired keys.',\n );\n return pickedObject;\n}\n\n/**\n * Convert the given value into a valid network ID. The ID is accepted\n * as either a number, a decimal string, or a 0x-prefixed hex string.\n *\n * @param value - The network ID to convert, in an unknown format.\n * @returns A valid network ID (as a decimal string)\n * @throws If the given value cannot be safely parsed.\n */\nfunction convertNetworkId(value: unknown): NetworkId {\n if (typeof value === 'number' && !Number.isNaN(value)) {\n return `${value}`;\n } else if (isStrictHexString(value)) {\n return `${convertHexToDecimal(value)}`;\n } else if (typeof value === 'string' && /^\\d+$/u.test(value)) {\n return value as NetworkId;\n }\n throw new Error(`Cannot parse as a valid network ID: '${value}'`);\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `code` property, such as an instance of Error.\n *\n * TODO: Move this to @metamask/utils.\n *\n * @param error - The object to check.\n * @returns True if `error` has a `code`, false otherwise.\n */\nfunction isErrorWithCode(error: unknown): error is { code: string | number } {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n\n/**\n * Returns whether the given argument is a type that our Infura middleware\n * recognizes.\n *\n * @param type - A type to compare.\n * @returns True or false, depending on whether the given type is one that our\n * Infura middleware recognizes.\n */\nfunction isInfuraProviderType(type: string): type is InfuraNetworkType {\n return Object.keys(InfuraNetworkType).includes(type);\n}\n\n/**\n * Builds an identifier for an Infura network client for lookup purposes.\n *\n * @param infuraNetworkOrProviderConfig - The name of an Infura network or a\n * provider config.\n * @returns The built identifier.\n */\nfunction buildInfuraNetworkClientId(\n infuraNetworkOrProviderConfig:\n | InfuraNetworkType\n | (ProviderConfig & { type: InfuraNetworkType }),\n): BuiltInNetworkClientId {\n if (typeof infuraNetworkOrProviderConfig === 'string') {\n return infuraNetworkOrProviderConfig;\n }\n return infuraNetworkOrProviderConfig.type;\n}\n\n/**\n * Builds an identifier for a custom network client for lookup purposes.\n *\n * @param args - This function can be called two ways:\n * 1. The ID of a network configuration.\n * 2. A provider config and a set of network configurations.\n * @returns The built identifier.\n */\nfunction buildCustomNetworkClientId(\n ...args:\n | [NetworkConfigurationId]\n | [\n ProviderConfig & { type: typeof NetworkType.rpc; rpcUrl: string },\n NetworkConfigurations,\n ]\n): CustomNetworkClientId {\n if (args.length === 1) {\n return args[0];\n }\n const [{ id, rpcUrl }, networkConfigurations] = args;\n if (id === undefined) {\n const matchingNetworkConfiguration = Object.values(\n networkConfigurations,\n ).find((networkConfiguration) => {\n return networkConfiguration.rpcUrl === rpcUrl.toLowerCase();\n });\n if (matchingNetworkConfiguration) {\n return matchingNetworkConfiguration.id;\n }\n return rpcUrl.toLowerCase();\n }\n return id;\n}\n\n/**\n * Returns whether the given provider config refers to an Infura network.\n *\n * @param providerConfig - The provider config.\n * @returns True if the provider config refers to an Infura network, false\n * otherwise.\n */\nfunction isInfuraProviderConfig(\n providerConfig: ProviderConfig,\n): providerConfig is ProviderConfig & { type: InfuraNetworkType } {\n return isInfuraProviderType(providerConfig.type);\n}\n\n/**\n * Returns whether the given provider config refers to an Infura network.\n *\n * @param providerConfig - The provider config.\n * @returns True if the provider config refers to an Infura network, false\n * otherwise.\n */\nfunction isCustomProviderConfig(\n providerConfig: ProviderConfig,\n): providerConfig is ProviderConfig & { type: typeof NetworkType.rpc } {\n return providerConfig.type === NetworkType.rpc;\n}\n\n/**\n * As a provider config represents the settings that are used to interface with\n * an RPC endpoint, it must have both a chain ID and an RPC URL if it represents\n * a custom network. These properties _should_ be set as they are validated in\n * the UI when a user adds a custom network, but just to be safe we validate\n * them here.\n *\n * In addition, historically the `rpcUrl` property on the ProviderConfig type\n * has been optional, even though it should not be. Making this non-optional\n * would be a breaking change, so this function types the provider config\n * correctly so that we don't have to check `rpcUrl` in other places.\n *\n * @param providerConfig - A provider config.\n * @throws if the provider config does not have a chain ID or an RPC URL.\n */\nfunction validateCustomProviderConfig(\n providerConfig: ProviderConfig & { type: typeof NetworkType.rpc },\n): asserts providerConfig is typeof providerConfig & { rpcUrl: string } {\n if (providerConfig.chainId === undefined) {\n throw new Error('chainId must be provided for custom RPC endpoints');\n }\n if (providerConfig.rpcUrl === undefined) {\n throw new Error('rpcUrl must be provided for custom RPC endpoints');\n }\n}\n/**\n * The string that uniquely identifies an Infura network client.\n */\ntype BuiltInNetworkClientId = InfuraNetworkType;\n\n/**\n * The string that uniquely identifies a custom network client.\n */\ntype CustomNetworkClientId = string;\n\n/**\n * The string that uniquely identifies a network client.\n */\ntype NetworkClientId = BuiltInNetworkClientId | CustomNetworkClientId;\n\n/**\n * Information about networks not held by any other part of state.\n */\nexport type NetworksMetadata = {\n [networkClientId: NetworkClientId]: NetworkMetadata;\n};\n\n/**\n * The network ID of a network.\n */\nexport type NetworkId = `${number}`;\n\n/**\n * @type NetworkState\n *\n * Network controller state\n * @property network - Network ID as per net_version of the currently connected network\n * @property providerConfig - RPC URL and network name provider settings of the currently connected network\n * @property properties - an additional set of network properties for the currently connected network\n * @property networkConfigurations - the full list of configured networks either preloaded or added by the user.\n */\nexport type NetworkState = {\n selectedNetworkClientId: NetworkClientId;\n networkId: NetworkId | null;\n providerConfig: ProviderConfig;\n networkConfigurations: NetworkConfigurations;\n networksMetadata: NetworksMetadata;\n};\n\nconst name = 'NetworkController';\n\n/**\n * Represents the block tracker for the currently selected network. (Note that\n * this is a proxy around a proxy: the inner one exists so that the block\n * tracker doesn't have to exist until it's used, and the outer one exists so\n * that the currently selected network can change without consumers needing to\n * refresh the object reference to that network.)\n */\nexport type BlockTrackerProxy = SwappableProxy<\n ProxyWithAccessibleTarget<BlockTracker>\n>;\n\n/**\n * Represents the provider for the currently selected network. (Note that this\n * is a proxy around a proxy: the inner one exists so that the provider doesn't\n * have to exist until it's used, and the outer one exists so that the currently\n * selected network can change without consumers needing to refresh the object\n * reference to that network.)\n */\nexport type ProviderProxy = SwappableProxy<ProxyWithAccessibleTarget<Provider>>;\n\nexport type NetworkControllerStateChangeEvent = {\n type: `NetworkController:stateChange`;\n payload: [NetworkState, Patch[]];\n};\n\n/**\n * `networkWillChange` is published when the current network is about to be\n * switched, but the new provider has not been created and no state changes have\n * occurred yet.\n */\nexport type NetworkControllerNetworkWillChangeEvent = {\n type: 'NetworkController:networkWillChange';\n payload: [];\n};\n\n/**\n * `networkDidChange` is published after a provider has been created for a newly\n * switched network (but before the network has been confirmed to be available).\n */\nexport type NetworkControllerNetworkDidChangeEvent = {\n type: 'NetworkController:networkDidChange';\n payload: [];\n};\n\n/**\n * `infuraIsBlocked` is published after the network is switched to an Infura\n * network, but when Infura returns an error blocking the user based on their\n * location.\n */\nexport type NetworkControllerInfuraIsBlockedEvent = {\n type: 'NetworkController:infuraIsBlocked';\n payload: [];\n};\n\n/**\n * `infuraIsBlocked` is published either after the network is switched to an\n * Infura network and Infura does not return an error blocking the user based on\n * their location, or the network is switched to a non-Infura network.\n */\nexport type NetworkControllerInfuraIsUnblockedEvent = {\n type: 'NetworkController:infuraIsUnblocked';\n payload: [];\n};\n\nexport type NetworkControllerEvents =\n | NetworkControllerStateChangeEvent\n | NetworkControllerNetworkWillChangeEvent\n | NetworkControllerNetworkDidChangeEvent\n | NetworkControllerInfuraIsBlockedEvent\n | NetworkControllerInfuraIsUnblockedEvent;\n\nexport type NetworkControllerGetStateAction = {\n type: `NetworkController:getState`;\n handler: () => NetworkState;\n};\n\nexport type NetworkControllerGetProviderConfigAction = {\n type: `NetworkController:getProviderConfig`;\n handler: () => ProviderConfig;\n};\n\nexport type NetworkControllerGetEthQueryAction = {\n type: `NetworkController:getEthQuery`;\n handler: () => EthQuery | undefined;\n};\n\nexport type NetworkControllerActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetProviderConfigAction\n | NetworkControllerGetEthQueryAction;\n\nexport type NetworkControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n NetworkControllerActions,\n NetworkControllerEvents,\n string,\n string\n>;\n\nexport type NetworkControllerOptions = {\n messenger: NetworkControllerMessenger;\n trackMetaMetricsEvent: () => void;\n infuraProjectId: string;\n state?: Partial<NetworkState>;\n};\n\nexport const defaultState: NetworkState = {\n selectedNetworkClientId: NetworkType.mainnet,\n networkId: null,\n providerConfig: {\n type: NetworkType.mainnet,\n chainId: ChainId.mainnet,\n ticker: NetworksTicker.mainnet,\n },\n networksMetadata: {},\n networkConfigurations: {},\n};\n\ntype MetaMetricsEventPayload = {\n event: string;\n category: string;\n referrer?: { url: string };\n actionId?: number;\n environmentType?: string;\n properties?: unknown;\n sensitiveProperties?: unknown;\n revenue?: number;\n currency?: string;\n value?: number;\n};\n\ntype NetworkConfigurationId = string;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\ntype AutoManagedBuiltInNetworkClientRegistry = Record<\n BuiltInNetworkClientId,\n AutoManagedNetworkClient<InfuraNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks.\n */\ntype AutoManagedCustomNetworkClientRegistry = Record<\n CustomNetworkClientId,\n AutoManagedNetworkClient<CustomNetworkClientConfiguration>\n>;\n\n/**\n * The collection of auto-managed network clients that map to Infura networks\n * as well as custom networks that users have added.\n */\ntype AutoManagedNetworkClientRegistry = {\n [NetworkClientType.Infura]: AutoManagedBuiltInNetworkClientRegistry;\n [NetworkClientType.Custom]: AutoManagedCustomNetworkClientRegistry;\n};\n\n/**\n * Controller that creates and manages an Ethereum network provider.\n */\nexport class NetworkController extends BaseControllerV2<\n typeof name,\n NetworkState,\n NetworkControllerMessenger\n> {\n #ethQuery?: EthQuery;\n\n #infuraProjectId: string;\n\n #trackMetaMetricsEvent: (event: MetaMetricsEventPayload) => void;\n\n #previousProviderConfig: ProviderConfig;\n\n #providerProxy: ProviderProxy | undefined;\n\n #provider: ProxyWithAccessibleTarget<Provider> | undefined;\n\n #blockTrackerProxy: BlockTrackerProxy | undefined;\n\n #autoManagedNetworkClientRegistry?: AutoManagedNetworkClientRegistry;\n\n constructor({\n messenger,\n state,\n infuraProjectId,\n trackMetaMetricsEvent,\n }: NetworkControllerOptions) {\n super({\n name,\n metadata: {\n selectedNetworkClientId: {\n persist: true,\n anonymous: false,\n },\n networkId: {\n persist: true,\n anonymous: false,\n },\n networksMetadata: {\n persist: true,\n anonymous: false,\n },\n providerConfig: {\n persist: true,\n anonymous: false,\n },\n networkConfigurations: {\n persist: true,\n anonymous: false,\n },\n },\n messenger,\n state: { ...defaultState, ...state },\n });\n if (!infuraProjectId || typeof infuraProjectId !== 'string') {\n throw new Error('Invalid Infura project ID');\n }\n this.#infuraProjectId = infuraProjectId;\n this.#trackMetaMetricsEvent = trackMetaMetricsEvent;\n this.messagingSystem.registerActionHandler(\n `${this.name}:getProviderConfig`,\n () => {\n return this.state.providerConfig;\n },\n );\n\n this.messagingSystem.registerActionHandler(\n `${this.name}:getEthQuery`,\n () => {\n return this.#ethQuery;\n },\n );\n\n this.#previousProviderConfig = this.state.providerConfig;\n }\n\n /**\n * Accesses the provider and block tracker for the currently selected network.\n *\n * @returns The proxy and block tracker proxies.\n */\n getProviderAndBlockTracker(): {\n provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>> | undefined;\n blockTracker:\n | SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>\n | undefined;\n } {\n return {\n provider: this.#providerProxy,\n blockTracker: this.#blockTrackerProxy,\n };\n }\n\n /**\n * Returns all of the network clients that have been created so far, keyed by\n * their identifier in the network client registry. This collection represents\n * not only built-in networks but also any custom networks that consumers have\n * added.\n *\n * @returns The list of known network clients.\n */\n getNetworkClientRegistry(): AutoManagedBuiltInNetworkClientRegistry &\n AutoManagedCustomNetworkClientRegistry {\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n return Object.assign(\n {},\n autoManagedNetworkClientRegistry[NetworkClientType.Infura],\n autoManagedNetworkClientRegistry[NetworkClientType.Custom],\n );\n }\n\n /**\n * Returns the Infura network client with the given ID.\n *\n * @param infuraNetworkClientId - An Infura network client ID.\n * @returns The Infura network client.\n * @throws If an Infura network client does not exist with the given ID.\n */\n getNetworkClientById(\n infuraNetworkClientId: BuiltInNetworkClientId,\n ): AutoManagedNetworkClient<InfuraNetworkClientConfiguration>;\n\n /**\n * Returns the custom network client with the given ID.\n *\n * @param customNetworkClientId - A custom network client ID.\n * @returns The custom network client.\n * @throws If a custom network client does not exist with the given ID.\n */\n getNetworkClientById(\n customNetworkClientId: CustomNetworkClientId,\n ): AutoManagedNetworkClient<CustomNetworkClientConfiguration>;\n\n getNetworkClientById(\n networkClientId: NetworkClientId,\n ): AutoManagedNetworkClient<NetworkClientConfiguration> {\n if (!networkClientId) {\n throw new Error('No network client ID was provided.');\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n if (isInfuraProviderType(networkClientId)) {\n const infuraNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Infura][\n networkClientId\n ];\n if (!infuraNetworkClient) {\n throw new Error(\n `No Infura network client was found with the ID \"${networkClientId}\".`,\n );\n }\n return infuraNetworkClient;\n }\n\n const customNetworkClient =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom][\n networkClientId\n ];\n if (!customNetworkClient) {\n throw new Error(\n `No custom network client was found with the ID \"${networkClientId}\".`,\n );\n }\n return customNetworkClient;\n }\n\n /**\n * Executes a series of steps to apply the changes to the provider config:\n *\n * 1. Notifies subscribers that the network is about to change.\n * 2. Looks up a known and preinitialized network client matching the provider\n * config and re-points the provider and block tracker proxy to it.\n * 3. Notifies subscribers that the network has changed.\n */\n async #refreshNetwork() {\n this.messagingSystem.publish('NetworkController:networkWillChange');\n this.update((state) => {\n state.networkId = null;\n });\n this.#applyNetworkSelection();\n this.messagingSystem.publish('NetworkController:networkDidChange');\n await this.lookupNetwork();\n }\n\n /**\n * Populates the network clients and establishes the initial network based on\n * the provider configuration in state.\n */\n async initializeProvider() {\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.#applyNetworkSelection();\n await this.lookupNetwork();\n }\n\n /**\n * Fetches the network ID for the network, ensuring that it is a hex string.\n *\n * @returns A promise that either resolves to the network ID, or rejects with\n * an error.\n * @throws If the network ID of the network is not a valid hex string.\n */\n async #getNetworkId(): Promise<NetworkId> {\n const possibleNetworkId = await new Promise<string>((resolve, reject) => {\n if (!this.#ethQuery) {\n throw new Error('Provider has not been initialized');\n }\n\n this.#ethQuery.sendAsync(\n { method: 'net_version' },\n (error: unknown, result?: unknown) => {\n if (error) {\n reject(error);\n } else {\n // TODO: Validate this type\n resolve(result as string);\n }\n },\n );\n });\n\n return convertNetworkId(possibleNetworkId);\n }\n\n /**\n * Performs side effects after switching to a network. If the network is\n * available, updates the network state with the network ID of the network and\n * stores whether the network supports EIP-1559; otherwise clears said\n * information about the network that may have been previously stored.\n *\n * @fires infuraIsBlocked if the network is Infura-supported and is blocking\n * requests.\n * @fires infuraIsUnblocked if the network is Infura-supported and is not\n * blocking requests, or if the network is not Infura-supported.\n */\n async lookupNetwork() {\n if (!this.#ethQuery) {\n return;\n }\n\n const isInfura = isInfuraProviderConfig(this.state.providerConfig);\n\n let networkChanged = false;\n const listener = () => {\n networkChanged = true;\n this.messagingSystem.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n };\n this.messagingSystem.subscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n\n let updatedNetworkStatus: NetworkStatus;\n let updatedNetworkId: NetworkId | null = null;\n let updatedIsEIP1559Compatible: boolean | undefined;\n\n try {\n const [networkId, isEIP1559Compatible] = await Promise.all([\n this.#getNetworkId(),\n this.#determineEIP1559Compatibility(),\n ]);\n updatedNetworkStatus = NetworkStatus.Available;\n updatedNetworkId = networkId;\n updatedIsEIP1559Compatible = isEIP1559Compatible;\n } catch (error) {\n if (isErrorWithCode(error)) {\n let responseBody;\n if (\n isInfura &&\n hasProperty(error, 'message') &&\n typeof error.message === 'string'\n ) {\n try {\n responseBody = JSON.parse(error.message);\n } catch {\n // error.message must not be JSON\n }\n }\n\n if (\n isPlainObject(responseBody) &&\n responseBody.error === INFURA_BLOCKED_KEY\n ) {\n updatedNetworkStatus = NetworkStatus.Blocked;\n } else if (error.code === errorCodes.rpc.internal) {\n updatedNetworkStatus = NetworkStatus.Unknown;\n } else {\n updatedNetworkStatus = NetworkStatus.Unavailable;\n }\n } else {\n log('NetworkController - could not determine network status', error);\n updatedNetworkStatus = NetworkStatus.Unknown;\n }\n }\n\n if (networkChanged) {\n // If the network has changed, then `lookupNetwork` either has been or is\n // in the process of being called, so we don't need to go further.\n return;\n }\n this.messagingSystem.unsubscribe(\n 'NetworkController:networkDidChange',\n listener,\n );\n\n this.update((state) => {\n state.networkId = updatedNetworkId;\n const meta = state.networksMetadata[state.selectedNetworkClientId];\n meta.status = updatedNetworkStatus;\n if (updatedIsEIP1559Compatible === undefined) {\n delete meta.EIPS[1559];\n } else {\n meta.EIPS[1559] = updatedIsEIP1559Compatible;\n }\n });\n\n if (isInfura) {\n if (updatedNetworkStatus === NetworkStatus.Available) {\n this.messagingSystem.publish('NetworkController:infuraIsUnblocked');\n } else if (updatedNetworkStatus === NetworkStatus.Blocked) {\n this.messagingSystem.publish('NetworkController:infuraIsBlocked');\n }\n } else {\n // Always publish infuraIsUnblocked regardless of network status to\n // prevent consumers from being stuck in a blocked state if they were\n // previously connected to an Infura network that was blocked\n this.messagingSystem.publish('NetworkController:infuraIsUnblocked');\n }\n }\n\n /**\n * Convenience method to update provider network type settings.\n *\n * @param type - Human readable network name.\n */\n async setProviderType(type: InfuraNetworkType) {\n assert.notStrictEqual(\n type,\n NetworkType.rpc,\n `NetworkController - cannot call \"setProviderType\" with type \"${NetworkType.rpc}\". Use \"setActiveNetwork\"`,\n );\n assert.ok(\n isInfuraProviderType(type),\n `Unknown Infura provider type \"${type}\".`,\n );\n\n this.#previousProviderConfig = this.state.providerConfig;\n\n // If testnet the ticker symbol should use a testnet prefix\n const ticker =\n type in NetworksTicker && NetworksTicker[type].length > 0\n ? NetworksTicker[type]\n : 'ETH';\n\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.update((state) => {\n state.providerConfig.type = type;\n state.providerConfig.ticker = ticker;\n state.providerConfig.chainId = ChainId[type];\n state.providerConfig.rpcPrefs = BUILT_IN_NETWORKS[type].rpcPrefs;\n state.providerConfig.rpcUrl = undefined;\n state.providerConfig.nickname = undefined;\n state.providerConfig.id = undefined;\n });\n await this.#refreshNetwork();\n }\n\n /**\n * Convenience method to update provider RPC settings.\n *\n * @param networkConfigurationId - The unique id for the network configuration to set as the active provider.\n */\n async setActiveNetwork(networkConfigurationId: string) {\n this.#previousProviderConfig = this.state.providerConfig;\n\n const targetNetwork =\n this.state.networkConfigurations[networkConfigurationId];\n\n if (!targetNetwork) {\n throw new Error(\n `networkConfigurationId ${networkConfigurationId} does not match a configured networkConfiguration`,\n );\n }\n\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.update((state) => {\n state.providerConfig.type = NetworkType.rpc;\n state.providerConfig.rpcUrl = targetNetwork.rpcUrl;\n state.providerConfig.chainId = targetNetwork.chainId;\n state.providerConfig.ticker = targetNetwork.ticker;\n state.providerConfig.nickname = targetNetwork.nickname;\n state.providerConfig.rpcPrefs = targetNetwork.rpcPrefs;\n state.providerConfig.id = targetNetwork.id;\n });\n\n await this.#refreshNetwork();\n }\n\n /**\n * Fetches the latest block for the network.\n *\n * @returns A promise that either resolves to the block header or null if\n * there is no latest block, or rejects with an error.\n */\n #getLatestBlock(): Promise<Block> {\n return new Promise((resolve, reject) => {\n if (!this.#ethQuery) {\n throw new Error('Provider has not been initialized');\n }\n\n this.#ethQuery.sendAsync(\n { method: 'eth_getBlockByNumber', params: ['latest', false] },\n (error: unknown, block?: unknown) => {\n if (error) {\n reject(error);\n } else {\n // TODO: Validate this type\n resolve(block as Block);\n }\n },\n );\n });\n }\n\n /**\n * Determines whether the network supports EIP-1559 by checking whether the\n * latest block has a `baseFeePerGas` property, then updates state\n * appropriately.\n *\n * @returns A promise that resolves to true if the network supports EIP-1559\n * , false otherwise, or `undefined` if unable to determine the compatibility.\n */\n async getEIP1559Compatibility() {\n if (!this.#ethQuery) {\n return false;\n }\n\n const { EIPS } =\n this.state.networksMetadata[this.state.selectedNetworkClientId];\n\n if (EIPS[1559] !== undefined) {\n return EIPS[1559];\n }\n\n const isEIP1559Compatible = await this.#determineEIP1559Compatibility();\n this.update((state) => {\n if (isEIP1559Compatible !== undefined) {\n state.networksMetadata[state.selectedNetworkClientId].EIPS[1559] =\n isEIP1559Compatible;\n }\n });\n return isEIP1559Compatible;\n }\n\n /**\n * Retrieves and checks the latest block from the currently selected\n * network; if the block has a `baseFeePerGas` property, then we know\n * that the network supports EIP-1559; otherwise it doesn't.\n *\n * @returns A promise that resolves to `true` if the network supports EIP-1559,\n * `false` otherwise, or `undefined` if unable to retrieve the last block.\n */\n async #determineEIP1559Compatibility(): Promise<boolean | undefined> {\n const latestBlock = await this.#getLatestBlock();\n\n if (!latestBlock) {\n return undefined;\n }\n\n return latestBlock.baseFeePerGas !== undefined;\n }\n\n /**\n * Re-initializes the provider and block tracker for the current network.\n */\n async resetConnection() {\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n await this.#refreshNetwork();\n }\n\n /**\n * Adds a new custom network or updates the information for an existing\n * network.\n *\n * This may involve updating the `networkConfigurations` property in\n * state as well and/or adding a new network client to the network client\n * registry. The `rpcUrl` and `chainId` of the given object are used to\n * determine which action to take:\n *\n * - If the `rpcUrl` corresponds to an existing network configuration\n * (case-insensitively), then it is overwritten with the object. Furthermore,\n * if the `chainId` is different from the existing network configuration, then\n * the existing network client is replaced with a new one.\n * - If the `rpcUrl` does not correspond to an existing network configuration\n * (case-insensitively), then the object is used to add a new network\n * configuration along with a new network client.\n *\n * @param networkConfiguration - The network configuration to add or update.\n * @param options - Additional configuration options.\n * @param options.referrer - Used to create a metrics event; the site from which the call originated, or 'metamask' for internal calls.\n * @param options.source - Used to create a metrics event; where the event originated (i.e. from a dapp or from the network form).\n * @param options.setActive - If true, switches to the network upon adding or updating it (default: false).\n * @returns The ID for the added or updated network configuration.\n */\n async upsertNetworkConfiguration(\n networkConfiguration: NetworkConfiguration,\n {\n referrer,\n source,\n setActive = false,\n }: {\n referrer: string;\n source: string;\n setActive?: boolean;\n },\n ): Promise<string> {\n const sanitizedNetworkConfiguration: NetworkConfiguration = pick(\n networkConfiguration,\n ['rpcUrl', 'chainId', 'ticker', 'nickname', 'rpcPrefs'],\n );\n const { rpcUrl, chainId, ticker } = sanitizedNetworkConfiguration;\n\n assertIsStrictHexString(chainId);\n if (!isSafeChainId(chainId)) {\n throw new Error(\n `Invalid chain ID \"${chainId}\": numerical value greater than max safe value.`,\n );\n }\n if (!rpcUrl) {\n throw new Error(\n 'An rpcUrl is required to add or update network configuration',\n );\n }\n if (!referrer || !source) {\n throw new Error(\n 'referrer and source are required arguments for adding or updating a network configuration',\n );\n }\n try {\n new URL(rpcUrl);\n } catch (e: any) {\n if (e.message.includes('Invalid URL')) {\n throw new Error('rpcUrl must be a valid URL');\n }\n }\n if (!ticker) {\n throw new Error(\n 'A ticker is required to add or update networkConfiguration',\n );\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n const existingNetworkConfiguration = Object.values(\n this.state.networkConfigurations,\n ).find(\n (networkConfig) =>\n networkConfig.rpcUrl.toLowerCase() === rpcUrl.toLowerCase(),\n );\n const upsertedNetworkConfigurationId = existingNetworkConfiguration\n ? existingNetworkConfiguration.id\n : random();\n const networkClientId = buildCustomNetworkClientId(\n upsertedNetworkConfigurationId,\n );\n\n this.update((state) => {\n state.networkConfigurations[upsertedNetworkConfigurationId] = {\n id: upsertedNetworkConfigurationId,\n ...sanitizedNetworkConfiguration,\n };\n });\n\n const customNetworkClientRegistry =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom];\n const existingAutoManagedNetworkClient =\n customNetworkClientRegistry[networkClientId];\n const shouldDestroyExistingNetworkClient =\n existingAutoManagedNetworkClient &&\n existingAutoManagedNetworkClient.configuration.chainId !== chainId;\n if (shouldDestroyExistingNetworkClient) {\n existingAutoManagedNetworkClient.destroy();\n }\n if (\n !existingAutoManagedNetworkClient ||\n shouldDestroyExistingNetworkClient\n ) {\n customNetworkClientRegistry[networkClientId] =\n createAutoManagedNetworkClient({\n type: NetworkClientType.Custom,\n chainId,\n rpcUrl,\n });\n }\n\n if (!existingNetworkConfiguration) {\n this.#trackMetaMetricsEvent({\n event: 'Custom Network Added',\n category: 'Network',\n referrer: {\n url: referrer,\n },\n properties: {\n chain_id: chainId,\n symbol: ticker,\n source,\n },\n });\n }\n\n if (setActive) {\n await this.setActiveNetwork(upsertedNetworkConfigurationId);\n }\n\n return upsertedNetworkConfigurationId;\n }\n\n /**\n * Removes a custom network from state.\n *\n * This involves updating the `networkConfigurations` property in state as\n * well and removing the network client that corresponds to the network from\n * the client registry.\n *\n * @param networkConfigurationId - The ID of an existing network\n * configuration.\n */\n removeNetworkConfiguration(networkConfigurationId: string) {\n if (!this.state.networkConfigurations[networkConfigurationId]) {\n throw new Error(\n `networkConfigurationId ${networkConfigurationId} does not match a configured networkConfiguration`,\n );\n }\n\n const autoManagedNetworkClientRegistry =\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n const networkClientId = buildCustomNetworkClientId(networkConfigurationId);\n\n this.update((state) => {\n delete state.networkConfigurations[networkConfigurationId];\n });\n\n const customNetworkClientRegistry =\n autoManagedNetworkClientRegistry[NetworkClientType.Custom];\n const existingAutoManagedNetworkClient =\n customNetworkClientRegistry[networkClientId];\n existingAutoManagedNetworkClient.destroy();\n delete customNetworkClientRegistry[networkClientId];\n }\n\n /**\n * Switches to the previously selected network, assuming that there is one\n * (if not and `initializeProvider` has not been previously called, then this\n * method is equivalent to calling `resetConnection`).\n */\n async rollbackToPreviousProvider() {\n this.#ensureAutoManagedNetworkClientRegistryPopulated();\n\n this.update((state) => {\n state.providerConfig = this.#previousProviderConfig;\n });\n\n await this.#refreshNetwork();\n }\n\n /**\n * Deactivates the controller, stopping any ongoing polling.\n *\n * In-progress requests will not be aborted.\n */\n async destroy() {\n await this.#blockTrackerProxy?.destroy();\n }\n\n /**\n * Updates the controller using the given backup data.\n *\n * @param backup - The data that has been backed up.\n * @param backup.networkConfigurations - Network configurations in the backup.\n */\n loadBackup({\n networkConfigurations,\n }: {\n networkConfigurations: NetworkState['networkConfigurations'];\n }): void {\n this.update((state) => {\n state.networkConfigurations = {\n ...state.networkConfigurations,\n ...networkConfigurations,\n };\n });\n }\n\n /**\n * Searches for a network configuration ID with the given ChainID and returns it.\n *\n * @param chainId - ChainId to search for\n * @returns networkClientId of the network configuration with the given chainId\n */\n findNetworkClientIdByChainId(chainId: Hex): NetworkClientId {\n const networkClients = this.getNetworkClientRegistry();\n const networkClientEntry = Object.entries(networkClients).find(\n ([_, networkClient]) => networkClient.configuration.chainId === chainId,\n );\n if (networkClientEntry === undefined) {\n throw new Error(\"Couldn't find networkClientId for chainId\");\n }\n return networkClientEntry[0];\n }\n\n /**\n * Before accessing or switching the network, the registry of network clients\n * needs to be populated. Otherwise, `#applyNetworkSelection` and\n * `getNetworkClientRegistry` will throw an error. This method checks to see if the\n * population step has happened yet, and if not, makes it happen.\n *\n * @returns The populated network client registry.\n */\n #ensureAutoManagedNetworkClientRegistryPopulated(): AutoManagedNetworkClientRegistry {\n const autoManagedNetworkClientRegistry =\n this.#autoManagedNetworkClientRegistry ??\n this.#createAutoManagedNetworkClientRegistry();\n this.#autoManagedNetworkClientRegistry = autoManagedNetworkClientRegistry;\n return autoManagedNetworkClientRegistry;\n }\n\n /**\n * Constructs the registry of network clients based on the set of built-in\n * networks as well as the custom networks in state.\n *\n * @returns The network clients keyed by ID.\n */\n #createAutoManagedNetworkClientRegistry(): AutoManagedNetworkClientRegistry {\n return [\n ...this.#buildIdentifiedInfuraNetworkClientConfigurations(),\n ...this.#buildIdentifiedCustomNetworkClientConfigurations(),\n ...this.#buildIdentifiedNetworkClientConfigurationsFromProviderConfig(),\n ].reduce(\n (\n registry,\n [networkClientType, networkClientId, networkClientConfiguration],\n ) => {\n const autoManagedNetworkClient = createAutoManagedNetworkClient(\n networkClientConfiguration,\n );\n if (networkClientId in registry[networkClientType]) {\n return registry;\n }\n return {\n ...registry,\n [networkClientType]: {\n ...registry[networkClientType],\n [networkClientId]: autoManagedNetworkClient,\n },\n };\n },\n {\n [NetworkClientType.Infura]: {},\n [NetworkClientType.Custom]: {},\n },\n ) as AutoManagedNetworkClientRegistry;\n }\n\n /**\n * Constructs the list of network clients for built-in networks (that is,\n * the subset of the networks we know Infura supports that consumers do not\n * need to explicitly add).\n *\n * @returns The network clients.\n */\n #buildIdentifiedInfuraNetworkClientConfigurations(): [\n NetworkClientType.Infura,\n BuiltInNetworkClientId,\n InfuraNetworkClientConfiguration,\n ][] {\n return knownKeysOf(InfuraNetworkType).map((network) => {\n const networkClientId = buildInfuraNetworkClientId(network);\n const networkClientConfiguration: InfuraNetworkClientConfiguration = {\n type: NetworkClientType.Infura,\n network,\n infuraProjectId: this.#infuraProjectId,\n chainId: BUILT_IN_NETWORKS[network].chainId,\n };\n return [\n NetworkClientType.Infura,\n networkClientId,\n networkClientConfiguration,\n ];\n });\n }\n\n /**\n * Constructs the list of network clients for custom networks (that is, those\n * which consumers have added via `networkConfigurations`).\n *\n * @returns The network clients.\n */\n #buildIdentifiedCustomNetworkClientConfigurations(): [\n NetworkClientType.Custom,\n CustomNetworkClientId,\n CustomNetworkClientConfiguration,\n ][] {\n return Object.entries(this.state.networkConfigurations).map(\n ([networkConfigurationId, networkConfiguration]) => {\n if (networkConfiguration.chainId === undefined) {\n throw new Error('chainId must be provided for custom RPC endpoints');\n }\n if (networkConfiguration.rpcUrl === undefined) {\n throw new Error('rpcUrl must be provided for custom RPC endpoints');\n }\n const networkClientId = buildCustomNetworkClientId(\n networkConfigurationId,\n );\n const networkClientConfiguration: CustomNetworkClientConfiguration = {\n type: NetworkClientType.Custom,\n chainId: networkConfiguration.chainId,\n rpcUrl: networkConfiguration.rpcUrl,\n };\n return [\n NetworkClientType.Custom,\n networkClientId,\n networkClientConfiguration,\n ];\n },\n );\n }\n\n /**\n * Converts the provider config object in state to a network client\n * configuration object.\n *\n * @returns The network client config.\n * @throws If the provider config is of type \"rpc\" and lacks either a\n * `chainId` or an `rpcUrl`.\n */\n #buildIdentifiedNetworkClientConfigurationsFromProviderConfig():\n | [\n [\n NetworkClientType.Custom,\n CustomNetworkClientId,\n CustomNetworkClientConfiguration,\n ],\n ]\n | [] {\n const { providerConfig } = this.state;\n\n if (isCustomProviderConfig(providerConfig)) {\n validateCustomProviderConfig(providerConfig);\n const networkClientId = buildCustomNetworkClientId(\n providerConfig,\n this.state.networkConfigurations,\n );\n const networkClientConfiguration: CustomNetworkClientConfiguration = {\n chainId: providerConfig.chainId,\n rpcUrl: providerConfig.rpcUrl,\n type: NetworkClientType.Custom,\n };\n return [\n [NetworkClientType.Custom, networkClientId, networkClientConfiguration],\n ];\n }\n\n if (isInfuraProviderConfig(providerConfig)) {\n return [];\n }\n\n throw new Error(`Unrecognized network type: '${providerConfig.type}'`);\n }\n\n /**\n * Uses the information in the provider config object to look up a known and\n * preinitialized network client. Once a network client is found, updates the\n * provider and block tracker proxy to point to those from the network client,\n * then finally creates an EthQuery that points to the provider proxy.\n *\n * @throws If no network client could be found matching the current provider\n * config.\n */\n #applyNetworkSelection() {\n if (!this.#autoManagedNetworkClientRegistry) {\n throw new Error(\n 'initializeProvider must be called first in order to switch the network',\n );\n }\n\n const { providerConfig } = this.state;\n\n let autoManagedNetworkClient: AutoManagedNetworkClient<NetworkClientConfiguration>;\n\n let networkClientId: NetworkClientId;\n if (isInfuraProviderConfig(providerConfig)) {\n const networkClientType = NetworkClientType.Infura;\n networkClientId = buildInfuraNetworkClientId(providerConfig);\n const builtInNetworkClientRegistry =\n this.#autoManagedNetworkClientRegistry[networkClientType];\n autoManagedNetworkClient =\n builtInNetworkClientRegistry[networkClientId as BuiltInNetworkClientId];\n if (!autoManagedNetworkClient) {\n throw new Error(\n `Could not find custom network matching ${networkClientId}`,\n );\n }\n } else if (isCustomProviderConfig(providerConfig)) {\n validateCustomProviderConfig(providerConfig);\n const networkClientType = NetworkClientType.Custom;\n networkClientId = buildCustomNetworkClientId(\n providerConfig,\n this.state.networkConfigurations,\n );\n const customNetworkClientRegistry =\n this.#autoManagedNetworkClientRegistry[networkClientType];\n autoManagedNetworkClient = customNetworkClientRegistry[networkClientId];\n if (!autoManagedNetworkClient) {\n throw new Error(\n `Could not find built-in network matching ${networkClientId}`,\n );\n }\n } else {\n throw new Error('Could not determine type of provider config');\n }\n\n this.update((state) => {\n state.selectedNetworkClientId = networkClientId;\n if (state.networksMetadata[networkClientId] === undefined) {\n state.networksMetadata[networkClientId] = {\n status: NetworkStatus.Unknown,\n EIPS: {},\n };\n }\n });\n\n const { provider, blockTracker } = autoManagedNetworkClient;\n\n if (this.#providerProxy) {\n this.#providerProxy.setTarget(provider);\n } else {\n this.#providerProxy = createEventEmitterProxy(provider);\n }\n this.#provider = provider;\n\n if (this.#blockTrackerProxy) {\n this.#blockTrackerProxy.setTarget(blockTracker);\n } else {\n this.#blockTrackerProxy = createEventEmitterProxy(blockTracker, {\n eventFilter: 'skipInternal',\n });\n }\n\n this.#ethQuery = new EthQuery(this.#providerProxy);\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './NetworkController';
|
|
2
2
|
export * from './constants';
|
|
3
3
|
export type { BlockTracker, Provider } from './types';
|
|
4
|
+
export type { NetworkClientConfiguration } from './types';
|
|
5
|
+
export { NetworkClientType } from './types';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,YAAY,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.NetworkClientType = void 0;
|
|
17
18
|
__exportStar(require("./NetworkController"), exports);
|
|
18
19
|
__exportStar(require("./constants"), exports);
|
|
20
|
+
var types_1 = require("./types");
|
|
21
|
+
Object.defineProperty(exports, "NetworkClientType", { enumerable: true, get: function () { return types_1.NetworkClientType; } });
|
|
19
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,8CAA4B;AAG5B,iCAA4C;AAAnC,0GAAA,iBAAiB,OAAA","sourcesContent":["export * from './NetworkController';\nexport * from './constants';\nexport type { BlockTracker, Provider } from './types';\nexport type { NetworkClientConfiguration } from './types';\nexport { NetworkClientType } from './types';\n"]}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,oBAAY,QAAQ,GAAG,wBAAwB,CAAC;AAEhD,oBAAY,YAAY,GAAG,mBAAmB,CAAC;AAE/C;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED;;;GAGG;AACH,oBAAY,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,oBAAY,gCAAgC,GAAG;IAC7C,OAAO,EAAE,iBAAiB,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,oBAAY,0BAA0B,GAClC,gCAAgC,GAChC,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,oBAAY,QAAQ,GAAG,wBAAwB,CAAC;AAEhD,oBAAY,YAAY,GAAG,mBAAmB,CAAC;AAE/C;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED;;;GAGG;AACH,oBAAY,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,oBAAY,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,iBAAiB,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,oBAAY,0BAA0B,GAClC,gCAAgC,GAChC,gCAAgC,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,sCAAiB,CAAA;AACnB,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport type { Hex } from '@metamask/utils';\nimport type { PollingBlockTracker } from 'eth-block-tracker';\n\nexport type Provider = SafeEventEmitterProvider;\n\nexport type BlockTracker = PollingBlockTracker;\n\n/**\n * The type of network client that can be created.\n */\nexport enum NetworkClientType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * A configuration object that can be used to create a client for a custom\n * network.\n */\nexport type CustomNetworkClientConfiguration = {\n chainId: Hex;\n rpcUrl: string;\n type: NetworkClientType.Custom;\n};\n\n/**\n * A configuration object that can be used to create a client for an Infura\n * network.\n */\nexport type InfuraNetworkClientConfiguration = {\n network: InfuraNetworkType;\n infuraProjectId: string;\n type: NetworkClientType.Infura;\n};\n\n/**\n * A configuration object that can be used to create a client for a network.\n */\nexport type NetworkClientConfiguration =\n | CustomNetworkClientConfiguration\n | InfuraNetworkClientConfiguration;\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,sCAAiB,CAAA;AACnB,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport type { Hex } from '@metamask/utils';\nimport type { PollingBlockTracker } from 'eth-block-tracker';\n\nexport type Provider = SafeEventEmitterProvider;\n\nexport type BlockTracker = PollingBlockTracker;\n\n/**\n * The type of network client that can be created.\n */\nexport enum NetworkClientType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * A configuration object that can be used to create a client for a custom\n * network.\n */\nexport type CustomNetworkClientConfiguration = {\n chainId: Hex;\n rpcUrl: string;\n type: NetworkClientType.Custom;\n};\n\n/**\n * A configuration object that can be used to create a client for an Infura\n * network.\n */\nexport type InfuraNetworkClientConfiguration = {\n chainId: Hex;\n network: InfuraNetworkType;\n infuraProjectId: string;\n type: NetworkClientType.Infura;\n};\n\n/**\n * A configuration object that can be used to create a client for a network.\n */\nexport type NetworkClientConfiguration =\n | CustomNetworkClientConfiguration\n | InfuraNetworkClientConfiguration;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/network-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "Provides an interface to the currently selected network via a MetaMask-compatible provider object",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@metamask/base-controller": "^3.2.0",
|
|
33
|
-
"@metamask/controller-utils": "^4.3.
|
|
33
|
+
"@metamask/controller-utils": "^4.3.1",
|
|
34
34
|
"@metamask/eth-json-rpc-infura": "^8.1.1",
|
|
35
35
|
"@metamask/eth-json-rpc-middleware": "^11.0.0",
|
|
36
36
|
"@metamask/eth-json-rpc-provider": "^1.0.0",
|
|
37
|
+
"@metamask/eth-query": "^3.0.1",
|
|
37
38
|
"@metamask/swappable-obj-proxy": "^2.1.0",
|
|
38
39
|
"@metamask/utils": "^6.2.0",
|
|
39
40
|
"async-mutex": "^0.2.6",
|
|
40
41
|
"eth-block-tracker": "^7.0.1",
|
|
41
|
-
"eth-query": "^2.1.2",
|
|
42
42
|
"eth-rpc-errors": "^4.0.2",
|
|
43
43
|
"immer": "^9.0.6",
|
|
44
44
|
"json-rpc-engine": "^6.1.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"jest": "^27.5.1",
|
|
55
55
|
"jest-when": "^3.4.2",
|
|
56
56
|
"lodash": "^4.17.21",
|
|
57
|
-
"nock": "^13.
|
|
57
|
+
"nock": "^13.3.1",
|
|
58
58
|
"sinon": "^9.2.4",
|
|
59
59
|
"ts-jest": "^27.1.4",
|
|
60
60
|
"typedoc": "^0.22.15",
|