@metamask/network-controller 24.3.1 → 26.0.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 +43 -1
- package/dist/NetworkController.cjs +65 -123
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +4 -2
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +4 -2
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +66 -124
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/create-auto-managed-network-client.cjs +0 -2
- package/dist/create-auto-managed-network-client.cjs.map +1 -1
- package/dist/create-auto-managed-network-client.d.cts.map +1 -1
- package/dist/create-auto-managed-network-client.d.mts.map +1 -1
- package/dist/create-auto-managed-network-client.mjs +0 -2
- package/dist/create-auto-managed-network-client.mjs.map +1 -1
- package/dist/create-network-client.cjs +45 -36
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.d.cts.map +1 -1
- package/dist/create-network-client.d.mts.map +1 -1
- package/dist/create-network-client.mjs +46 -37
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/rpc-service/rpc-service-chain.cjs.map +1 -1
- package/dist/rpc-service/rpc-service-chain.d.cts +2 -2
- package/dist/rpc-service/rpc-service-chain.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service-chain.d.mts +2 -2
- package/dist/rpc-service/rpc-service-chain.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service-chain.mjs.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.cjs.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.d.cts +1 -1
- package/dist/rpc-service/rpc-service-requestable.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.d.mts +1 -1
- package/dist/rpc-service/rpc-service-requestable.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service-requestable.mjs.map +1 -1
- package/dist/rpc-service/rpc-service.cjs +3 -1
- package/dist/rpc-service/rpc-service.cjs.map +1 -1
- package/dist/rpc-service/rpc-service.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service.mjs +3 -1
- package/dist/rpc-service/rpc-service.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +15 -10
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [26.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add infura supported networks ([#6972](https://github.com/MetaMask/core/pull/6972))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Bump `@metamask/json-rpc-engine` from `^10.1.1` to `^10.2.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
|
|
19
|
+
- Bump `@metamask/eth-json-rpc-provider` from `^5.0.1` to `^6.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
|
|
20
|
+
- Bump `@metamask/eth-json-rpc-middleware` from `^21.0.0` to `^22.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
|
|
21
|
+
- Bump `@metamask/eth-block-tracker` from `^14.0.0` to `^15.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
|
|
22
|
+
- **BREAKING:** Use `InternalProvider` instead of `SafeEventEmitterProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
|
|
23
|
+
- Providers accessible either via network clients or global proxies no longer emit events (or inherit from EventEmitter, for that matter).
|
|
24
|
+
- **BREAKING:** Make `Provider` type more specific ([#7061](https://github.com/MetaMask/core/pull/7061))
|
|
25
|
+
- The `Provider` type is now an `InternalProvider` with a context type of `{ origin: string; skipCache: boolean } & Record<string, unknown>`.
|
|
26
|
+
- **BREAKING:** Stop retrying `undefined` results for methods that include a block tag parameter ([#7001](https://github.com/MetaMask/core/pull/7001))
|
|
27
|
+
- The network client middleware, via `@metamask/eth-json-rpc-middleware`, will now throw an error if it encounters an
|
|
28
|
+
`undefined` result when dispatching a request with a later block number than the originally requested block number.
|
|
29
|
+
- In practice, this should happen rarely if ever.
|
|
30
|
+
- **BREAKING:** Migrate `NetworkClient` to `JsonRpcEngineV2` ([#7065](https://github.com/MetaMask/core/pull/7065))
|
|
31
|
+
- This ought to be unobservable, but we mark it as breaking out of an abundance of caution.
|
|
32
|
+
- **BREAKING:** Update signature of `request` in `AbstractRpcService` and `RpcServiceRequestable` so that the JSON-RPC request must be frozen ([#7138](https://github.com/MetaMask/core/pull/7138))
|
|
33
|
+
- Bump `@metamask/controller-utils` from `^11.15.0` to `^11.16.0` ([#7003](https://github.com/MetaMask/core/pull/7003), [#7202](https://github.com/MetaMask/core/pull/7202))
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- Ensure `networksMetadata` never references old network client IDs ([#7047](https://github.com/MetaMask/core/pull/7047))
|
|
38
|
+
- When removing a network configuration, ensure that metadata for all RPC endpoints in the network configuration are also removed from `networksMetadata`
|
|
39
|
+
- When initializing the controller, remove metadata for RPC endpoints in `networksMetadata` that are not present in a network configuration
|
|
40
|
+
|
|
41
|
+
## [25.0.0]
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6386](https://github.com/MetaMask/core/pull/6386))
|
|
46
|
+
- Previously, `NetworkController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
|
|
47
|
+
- **BREAKING:** Bump `@metamask/error-reporting-service` from `^2.0.0` to `^3.0.0` ([#6962](https://github.com/MetaMask/core/pull/6962))
|
|
48
|
+
- Bump `@metamask/base-controller` from `^8.4.2` to `^9.0.0` ([#6962](https://github.com/MetaMask/core/pull/6962))
|
|
49
|
+
|
|
10
50
|
## [24.3.1]
|
|
11
51
|
|
|
12
52
|
### Changed
|
|
@@ -975,7 +1015,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
975
1015
|
|
|
976
1016
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
977
1017
|
|
|
978
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@
|
|
1018
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@26.0.0...HEAD
|
|
1019
|
+
[26.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@25.0.0...@metamask/network-controller@26.0.0
|
|
1020
|
+
[25.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.3.1...@metamask/network-controller@25.0.0
|
|
979
1021
|
[24.3.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.3.0...@metamask/network-controller@24.3.1
|
|
980
1022
|
[24.3.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.2.2...@metamask/network-controller@24.3.0
|
|
981
1023
|
[24.2.2]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.2.1...@metamask/network-controller@24.2.2
|
|
@@ -81,8 +81,6 @@ var RpcEndpointType;
|
|
|
81
81
|
* @returns The keys of an object, typed according to the type of the object
|
|
82
82
|
* itself.
|
|
83
83
|
*/
|
|
84
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
86
84
|
function knownKeysOf(
|
|
87
85
|
// TODO: Replace `any` with type
|
|
88
86
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -134,10 +132,7 @@ function getDefaultInfuraNetworkConfigurationsByChainId() {
|
|
|
134
132
|
if (constants_1.DEPRECATED_NETWORKS.has(chainId)) {
|
|
135
133
|
return obj;
|
|
136
134
|
}
|
|
137
|
-
const rpcEndpointUrl =
|
|
138
|
-
// This ESLint rule mistakenly produces an error.
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
140
|
-
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`;
|
|
135
|
+
const rpcEndpointUrl = `https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}`;
|
|
141
136
|
const networkConfiguration = {
|
|
142
137
|
blockExplorerUrls: [],
|
|
143
138
|
chainId,
|
|
@@ -337,14 +332,21 @@ function validateInitialState(state) {
|
|
|
337
332
|
*/
|
|
338
333
|
function correctInitialState(state, messenger) {
|
|
339
334
|
const networkConfigurationsSortedByChainId = getNetworkConfigurations(state).sort((a, b) => a.chainId.localeCompare(b.chainId));
|
|
340
|
-
const
|
|
335
|
+
const availableNetworkClientIds = getAvailableNetworkClientIds(networkConfigurationsSortedByChainId);
|
|
336
|
+
const invalidNetworkClientIdsWithMetadata = Object.keys(state.networksMetadata).filter((networkClientId) => !availableNetworkClientIds.includes(networkClientId));
|
|
341
337
|
return (0, immer_1.produce)(state, (newState) => {
|
|
342
|
-
if (!
|
|
338
|
+
if (!availableNetworkClientIds.includes(state.selectedNetworkClientId)) {
|
|
343
339
|
const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];
|
|
344
340
|
const newSelectedNetworkClientId = firstNetworkConfiguration.rpcEndpoints[firstNetworkConfiguration.defaultRpcEndpointIndex].networkClientId;
|
|
345
341
|
messenger.call('ErrorReportingService:captureException', new Error(`\`selectedNetworkClientId\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`));
|
|
346
342
|
newState.selectedNetworkClientId = newSelectedNetworkClientId;
|
|
347
343
|
}
|
|
344
|
+
if (invalidNetworkClientIdsWithMetadata.length > 0) {
|
|
345
|
+
for (const invalidNetworkClientId of invalidNetworkClientIdsWithMetadata) {
|
|
346
|
+
delete newState.networksMetadata[invalidNetworkClientId];
|
|
347
|
+
}
|
|
348
|
+
messenger.call('ErrorReportingService:captureException', new Error('`networksMetadata` had invalid network client IDs, which have been removed'));
|
|
349
|
+
}
|
|
348
350
|
});
|
|
349
351
|
}
|
|
350
352
|
/**
|
|
@@ -388,19 +390,19 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
388
390
|
selectedNetworkClientId: {
|
|
389
391
|
includeInStateLogs: true,
|
|
390
392
|
persist: true,
|
|
391
|
-
|
|
393
|
+
includeInDebugSnapshot: false,
|
|
392
394
|
usedInUi: true,
|
|
393
395
|
},
|
|
394
396
|
networksMetadata: {
|
|
395
397
|
includeInStateLogs: true,
|
|
396
398
|
persist: true,
|
|
397
|
-
|
|
399
|
+
includeInDebugSnapshot: false,
|
|
398
400
|
usedInUi: true,
|
|
399
401
|
},
|
|
400
402
|
networkConfigurationsByChainId: {
|
|
401
403
|
includeInStateLogs: true,
|
|
402
404
|
persist: true,
|
|
403
|
-
|
|
405
|
+
includeInDebugSnapshot: false,
|
|
404
406
|
usedInUi: true,
|
|
405
407
|
},
|
|
406
408
|
},
|
|
@@ -427,54 +429,21 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
427
429
|
__classPrivateFieldSet(this, _NetworkController_isRpcFailoverEnabled, isRpcFailoverEnabled, "f");
|
|
428
430
|
__classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
|
|
429
431
|
__classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
|
|
430
|
-
this.
|
|
431
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
432
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
433
|
-
`${this.name}:getEthQuery`, () => {
|
|
432
|
+
this.messenger.registerActionHandler(`${this.name}:getEthQuery`, () => {
|
|
434
433
|
return __classPrivateFieldGet(this, _NetworkController_ethQuery, "f");
|
|
435
434
|
});
|
|
436
|
-
this.
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
`${this.name}:
|
|
440
|
-
this.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
`${this.name}:
|
|
444
|
-
this.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
`${this.name}:
|
|
448
|
-
this.messagingSystem.registerActionHandler(
|
|
449
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
450
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
451
|
-
`${this.name}:setProviderType`, this.setProviderType.bind(this));
|
|
452
|
-
this.messagingSystem.registerActionHandler(
|
|
453
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
454
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
455
|
-
`${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
|
|
456
|
-
this.messagingSystem.registerActionHandler(
|
|
457
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
458
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
459
|
-
`${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
|
|
460
|
-
this.messagingSystem.registerActionHandler(
|
|
461
|
-
// ESLint is mistaken here; `name` is a string.
|
|
462
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
463
|
-
`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
|
|
464
|
-
this.messagingSystem.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
|
|
465
|
-
this.messagingSystem.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
|
|
466
|
-
this.messagingSystem.registerActionHandler(
|
|
467
|
-
// ESLint is mistaken here; `name` is a string.
|
|
468
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
469
|
-
`${this.name}:addNetwork`, this.addNetwork.bind(this));
|
|
470
|
-
this.messagingSystem.registerActionHandler(
|
|
471
|
-
// ESLint is mistaken here; `name` is a string.
|
|
472
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
473
|
-
`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
|
|
474
|
-
this.messagingSystem.registerActionHandler(
|
|
475
|
-
// ESLint is mistaken here; `name` is a string.
|
|
476
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
477
|
-
`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
|
|
435
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkClientById`, this.getNetworkClientById.bind(this));
|
|
436
|
+
this.messenger.registerActionHandler(`${this.name}:getEIP1559Compatibility`, this.getEIP1559Compatibility.bind(this));
|
|
437
|
+
this.messenger.registerActionHandler(`${this.name}:setActiveNetwork`, this.setActiveNetwork.bind(this));
|
|
438
|
+
this.messenger.registerActionHandler(`${this.name}:setProviderType`, this.setProviderType.bind(this));
|
|
439
|
+
this.messenger.registerActionHandler(`${this.name}:findNetworkClientIdByChainId`, this.findNetworkClientIdByChainId.bind(this));
|
|
440
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkConfigurationByChainId`, this.getNetworkConfigurationByChainId.bind(this));
|
|
441
|
+
this.messenger.registerActionHandler(`${this.name}:getNetworkConfigurationByNetworkClientId`, this.getNetworkConfigurationByNetworkClientId.bind(this));
|
|
442
|
+
this.messenger.registerActionHandler(`${this.name}:getSelectedNetworkClient`, this.getSelectedNetworkClient.bind(this));
|
|
443
|
+
this.messenger.registerActionHandler(`${this.name}:getSelectedChainId`, this.getSelectedChainId.bind(this));
|
|
444
|
+
this.messenger.registerActionHandler(`${this.name}:addNetwork`, this.addNetwork.bind(this));
|
|
445
|
+
this.messenger.registerActionHandler(`${this.name}:removeNetwork`, this.removeNetwork.bind(this));
|
|
446
|
+
this.messenger.registerActionHandler(`${this.name}:updateNetwork`, this.updateNetwork.bind(this));
|
|
478
447
|
}
|
|
479
448
|
/**
|
|
480
449
|
* Enables the RPC failover functionality. That is, if any RPC endpoints are
|
|
@@ -494,6 +463,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
494
463
|
}
|
|
495
464
|
/**
|
|
496
465
|
* Accesses the provider and block tracker for the currently selected network.
|
|
466
|
+
*
|
|
497
467
|
* @returns The proxy and block tracker proxies.
|
|
498
468
|
* @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
|
|
499
469
|
*/
|
|
@@ -549,19 +519,13 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
549
519
|
// This is impossible to reach
|
|
550
520
|
/* istanbul ignore if */
|
|
551
521
|
if (!infuraNetworkClient) {
|
|
552
|
-
throw new Error(
|
|
553
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
554
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
555
|
-
`No Infura network client was found with the ID "${networkClientId}".`);
|
|
522
|
+
throw new Error(`No Infura network client was found with the ID "${networkClientId}".`);
|
|
556
523
|
}
|
|
557
524
|
return infuraNetworkClient;
|
|
558
525
|
}
|
|
559
526
|
const customNetworkClient = autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom][networkClientId];
|
|
560
527
|
if (!customNetworkClient) {
|
|
561
|
-
throw new Error(
|
|
562
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
563
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
564
|
-
`No custom network client was found with the ID "${networkClientId}".`);
|
|
528
|
+
throw new Error(`No custom network client was found with the ID "${networkClientId}".`);
|
|
565
529
|
}
|
|
566
530
|
return customNetworkClient;
|
|
567
531
|
}
|
|
@@ -620,10 +584,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
620
584
|
*/
|
|
621
585
|
async setProviderType(type) {
|
|
622
586
|
if (type === controller_utils_1.NetworkType.rpc) {
|
|
623
|
-
throw new Error(
|
|
624
|
-
// This ESLint rule mistakenly produces an error.
|
|
625
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
626
|
-
`NetworkController - cannot call "setProviderType" with type "${controller_utils_1.NetworkType.rpc}". Use "setActiveNetwork"`);
|
|
587
|
+
throw new Error(`NetworkController - cannot call "setProviderType" with type "${controller_utils_1.NetworkType.rpc}". Use "setActiveNetwork"`);
|
|
627
588
|
}
|
|
628
589
|
if (!(0, controller_utils_1.isInfuraNetworkType)(type)) {
|
|
629
590
|
throw new Error(`Unknown Infura provider type "${String(type)}".`);
|
|
@@ -758,7 +719,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
758
719
|
networkConfigurationToPersist: newNetworkConfiguration,
|
|
759
720
|
});
|
|
760
721
|
});
|
|
761
|
-
this.
|
|
722
|
+
this.messenger.publish(`${controllerName}:networkAdded`, newNetworkConfiguration);
|
|
762
723
|
return newNetworkConfiguration;
|
|
763
724
|
}
|
|
764
725
|
/**
|
|
@@ -916,10 +877,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
916
877
|
networkClientOperation.oldRpcEndpoint.networkClientId ===
|
|
917
878
|
this.state.selectedNetworkClientId);
|
|
918
879
|
})) {
|
|
919
|
-
throw new Error(
|
|
920
|
-
// This ESLint rule mistakenly produces an error.
|
|
921
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
922
|
-
`Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \`replacementSelectedRpcEndpointIndex\` option.`);
|
|
880
|
+
throw new Error(`Could not update network: Cannot update RPC endpoints in such a way that the selected network '${this.state.selectedNetworkClientId}' would be removed without a replacement. Choose a different RPC endpoint as the selected network via the \`replacementSelectedRpcEndpointIndex\` option.`);
|
|
923
881
|
}
|
|
924
882
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_registerNetworkClientsAsNeeded).call(this, {
|
|
925
883
|
networkFields: fields,
|
|
@@ -1008,8 +966,11 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
1008
966
|
mode: 'remove',
|
|
1009
967
|
existingNetworkConfiguration,
|
|
1010
968
|
});
|
|
969
|
+
for (const rpcEndpoint of existingNetworkConfiguration.rpcEndpoints) {
|
|
970
|
+
delete state.networksMetadata[rpcEndpoint.networkClientId];
|
|
971
|
+
}
|
|
1011
972
|
});
|
|
1012
|
-
this.
|
|
973
|
+
this.messenger.publish('NetworkController:networkRemoved', existingNetworkConfiguration);
|
|
1013
974
|
}
|
|
1014
975
|
/**
|
|
1015
976
|
* Assuming that the network has been previously switched, switches to this
|
|
@@ -1026,6 +987,8 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
1026
987
|
*
|
|
1027
988
|
* In-progress requests will not be aborted.
|
|
1028
989
|
*/
|
|
990
|
+
// We're intentionally changing the signature of an extended method.
|
|
991
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
1029
992
|
async destroy() {
|
|
1030
993
|
await __classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")?.destroy();
|
|
1031
994
|
}
|
|
@@ -1101,9 +1064,9 @@ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId
|
|
|
1101
1064
|
* @param options.updateState - Allows for updating state.
|
|
1102
1065
|
*/
|
|
1103
1066
|
async function _NetworkController_refreshNetwork(networkClientId, options = {}) {
|
|
1104
|
-
this.
|
|
1067
|
+
this.messenger.publish('NetworkController:networkWillChange', this.state);
|
|
1105
1068
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, networkClientId, options);
|
|
1106
|
-
this.
|
|
1069
|
+
this.messenger.publish('NetworkController:networkDidChange', this.state);
|
|
1107
1070
|
await this.lookupNetwork();
|
|
1108
1071
|
}, _NetworkController_determineNetworkMetadata =
|
|
1109
1072
|
/**
|
|
@@ -1204,7 +1167,7 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1204
1167
|
const listener = () => {
|
|
1205
1168
|
networkChanged = true;
|
|
1206
1169
|
try {
|
|
1207
|
-
this.
|
|
1170
|
+
this.messenger.unsubscribe('NetworkController:networkDidChange', listener);
|
|
1208
1171
|
}
|
|
1209
1172
|
catch (error) {
|
|
1210
1173
|
// In theory, this `catch` should not be necessary given that this error
|
|
@@ -1224,7 +1187,7 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1224
1187
|
}
|
|
1225
1188
|
}
|
|
1226
1189
|
};
|
|
1227
|
-
this.
|
|
1190
|
+
this.messenger.subscribe('NetworkController:networkDidChange', listener);
|
|
1228
1191
|
const { isInfura, networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, this.state.selectedNetworkClientId);
|
|
1229
1192
|
if (networkChanged) {
|
|
1230
1193
|
// If the network has changed, then `lookupNetwork` either has been or is
|
|
@@ -1232,7 +1195,7 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1232
1195
|
return;
|
|
1233
1196
|
}
|
|
1234
1197
|
try {
|
|
1235
|
-
this.
|
|
1198
|
+
this.messenger.unsubscribe('NetworkController:networkDidChange', listener);
|
|
1236
1199
|
}
|
|
1237
1200
|
catch (error) {
|
|
1238
1201
|
if (!(error instanceof Error) ||
|
|
@@ -1244,17 +1207,17 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1244
1207
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
|
|
1245
1208
|
if (isInfura) {
|
|
1246
1209
|
if (networkStatus === constants_1.NetworkStatus.Available) {
|
|
1247
|
-
this.
|
|
1210
|
+
this.messenger.publish('NetworkController:infuraIsUnblocked');
|
|
1248
1211
|
}
|
|
1249
1212
|
else if (networkStatus === constants_1.NetworkStatus.Blocked) {
|
|
1250
|
-
this.
|
|
1213
|
+
this.messenger.publish('NetworkController:infuraIsBlocked');
|
|
1251
1214
|
}
|
|
1252
1215
|
}
|
|
1253
1216
|
else {
|
|
1254
1217
|
// Always publish infuraIsUnblocked regardless of network status to
|
|
1255
1218
|
// prevent consumers from being stuck in a blocked state if they were
|
|
1256
1219
|
// previously connected to an Infura network that was blocked
|
|
1257
|
-
this.
|
|
1220
|
+
this.messenger.publish('NetworkController:infuraIsUnblocked');
|
|
1258
1221
|
}
|
|
1259
1222
|
}, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
|
|
1260
1223
|
this.update((state) => {
|
|
@@ -1282,6 +1245,8 @@ async function _NetworkController_lookupSelectedNetwork() {
|
|
|
1282
1245
|
return new Promise((resolve, reject) => {
|
|
1283
1246
|
ethQuery.sendAsync({ method: 'eth_getBlockByNumber', params: ['latest', false] }, (error, block) => {
|
|
1284
1247
|
if (error) {
|
|
1248
|
+
// This error comes from JsonRpcEngine, we don't control it.
|
|
1249
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
1285
1250
|
reject(error);
|
|
1286
1251
|
}
|
|
1287
1252
|
else {
|
|
@@ -1321,16 +1286,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1321
1286
|
const existingNetworkConfigurationViaChainId = this.state.networkConfigurationsByChainId[networkFields.chainId];
|
|
1322
1287
|
if (existingNetworkConfigurationViaChainId !== undefined) {
|
|
1323
1288
|
if (existingNetworkConfiguration === null) {
|
|
1324
|
-
throw new Error(
|
|
1325
|
-
// This ESLint rule mistakenly produces an error.
|
|
1326
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1327
|
-
`Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1289
|
+
throw new Error(`Could not add network for chain ${args.networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1328
1290
|
}
|
|
1329
1291
|
else {
|
|
1330
|
-
throw new Error(
|
|
1331
|
-
// This ESLint rule mistakenly produces an error.
|
|
1332
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1333
|
-
`Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1292
|
+
throw new Error(`Cannot move network from chain ${existingNetworkConfiguration.chainId} to ${networkFields.chainId} as another network for that chain already exists ('${existingNetworkConfigurationViaChainId.name}')`);
|
|
1334
1293
|
}
|
|
1335
1294
|
}
|
|
1336
1295
|
}
|
|
@@ -1346,10 +1305,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1346
1305
|
}
|
|
1347
1306
|
for (const rpcEndpointFields of networkFields.rpcEndpoints) {
|
|
1348
1307
|
if (!isValidUrl(rpcEndpointFields.url)) {
|
|
1349
|
-
throw new Error(
|
|
1350
|
-
// This ESLint rule mistakenly produces an error.
|
|
1351
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1352
|
-
`${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
|
|
1308
|
+
throw new Error(`${errorMessagePrefix}: An entry in \`rpcEndpoints\` has invalid URL '${rpcEndpointFields.url}'`);
|
|
1353
1309
|
}
|
|
1354
1310
|
const networkClientId = 'networkClientId' in rpcEndpointFields
|
|
1355
1311
|
? rpcEndpointFields.networkClientId
|
|
@@ -1357,19 +1313,13 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1357
1313
|
if (rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1358
1314
|
networkClientId !== undefined &&
|
|
1359
1315
|
(0, controller_utils_1.isInfuraNetworkType)(networkClientId)) {
|
|
1360
|
-
throw new Error(
|
|
1361
|
-
// This is a string.
|
|
1362
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1363
|
-
`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
|
|
1316
|
+
throw new Error(`${errorMessagePrefix}: Custom RPC endpoint '${rpcEndpointFields.url}' has invalid network client ID '${networkClientId}'`);
|
|
1364
1317
|
}
|
|
1365
1318
|
if (mode === 'update' &&
|
|
1366
1319
|
networkClientId !== undefined &&
|
|
1367
1320
|
rpcEndpointFields.type === RpcEndpointType.Custom &&
|
|
1368
1321
|
!Object.values(autoManagedNetworkClientRegistry).some((networkClientsById) => networkClientId in networkClientsById)) {
|
|
1369
|
-
throw new Error(
|
|
1370
|
-
// This is a string.
|
|
1371
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1372
|
-
`${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
|
|
1322
|
+
throw new Error(`${errorMessagePrefix}: RPC endpoint '${rpcEndpointFields.url}' refers to network client '${networkClientId}' that does not exist`);
|
|
1373
1323
|
}
|
|
1374
1324
|
if (networkFields.rpcEndpoints.some((otherRpcEndpointFields) => otherRpcEndpointFields !== rpcEndpointFields &&
|
|
1375
1325
|
URI.equal(otherRpcEndpointFields.url, rpcEndpointFields.url))) {
|
|
@@ -1383,16 +1333,10 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1383
1333
|
const rpcEndpoint = networkConfiguration.rpcEndpoints.find((existingRpcEndpoint) => URI.equal(rpcEndpointFields.url, existingRpcEndpoint.url));
|
|
1384
1334
|
if (rpcEndpoint) {
|
|
1385
1335
|
if (mode === 'update') {
|
|
1386
|
-
throw new Error(
|
|
1387
|
-
// This ESLint rule mistakenly produces an error.
|
|
1388
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1389
|
-
`Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1336
|
+
throw new Error(`Could not update network to point to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1390
1337
|
}
|
|
1391
1338
|
else {
|
|
1392
|
-
throw new Error(
|
|
1393
|
-
// This ESLint rule mistakenly produces an error.
|
|
1394
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1395
|
-
`Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1339
|
+
throw new Error(`Could not add network that points to same RPC endpoint as existing network for chain ${networkConfiguration.chainId} ('${networkConfiguration.name}')`);
|
|
1396
1340
|
}
|
|
1397
1341
|
}
|
|
1398
1342
|
}
|
|
@@ -1420,12 +1364,8 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1420
1364
|
const infuraChainId = controller_utils_1.ChainId[infuraNetworkName];
|
|
1421
1365
|
if (networkFields.chainId !== infuraChainId) {
|
|
1422
1366
|
throw new Error(mode === 'add'
|
|
1423
|
-
?
|
|
1424
|
-
|
|
1425
|
-
`Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
|
|
1426
|
-
: // This is a string.
|
|
1427
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
1428
|
-
`Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
|
|
1367
|
+
? `Could not add network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`
|
|
1368
|
+
: `Could not update network with chain ID ${networkFields.chainId} and Infura RPC endpoint for '${infuraNetworkNickname}' which represents ${infuraChainId}, as the two conflict`);
|
|
1429
1369
|
}
|
|
1430
1370
|
}
|
|
1431
1371
|
if (networkFields.rpcEndpoints[networkFields.defaultRpcEndpointIndex] ===
|
|
@@ -1469,7 +1409,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1469
1409
|
},
|
|
1470
1410
|
getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
|
|
1471
1411
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1472
|
-
messenger: this.
|
|
1412
|
+
messenger: this.messenger,
|
|
1473
1413
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1474
1414
|
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1475
1415
|
});
|
|
@@ -1485,7 +1425,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1485
1425
|
},
|
|
1486
1426
|
getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
|
|
1487
1427
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1488
|
-
messenger: this.
|
|
1428
|
+
messenger: this.messenger,
|
|
1489
1429
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1490
1430
|
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1491
1431
|
});
|
|
@@ -1545,7 +1485,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1545
1485
|
},
|
|
1546
1486
|
getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
|
|
1547
1487
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1548
|
-
messenger: this.
|
|
1488
|
+
messenger: this.messenger,
|
|
1549
1489
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1550
1490
|
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1551
1491
|
}),
|
|
@@ -1563,7 +1503,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1563
1503
|
},
|
|
1564
1504
|
getRpcServiceOptions: __classPrivateFieldGet(this, _NetworkController_getRpcServiceOptions, "f"),
|
|
1565
1505
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1566
|
-
messenger: this.
|
|
1506
|
+
messenger: this.messenger,
|
|
1567
1507
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1568
1508
|
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1569
1509
|
}),
|
|
@@ -1616,13 +1556,15 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1616
1556
|
__classPrivateFieldGet(this, _NetworkController_providerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider);
|
|
1617
1557
|
}
|
|
1618
1558
|
else {
|
|
1619
|
-
__classPrivateFieldSet(this, _NetworkController_providerProxy, (0, swappable_obj_proxy_1.
|
|
1559
|
+
__classPrivateFieldSet(this, _NetworkController_providerProxy, (0, swappable_obj_proxy_1.createSwappableProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").provider), "f");
|
|
1620
1560
|
}
|
|
1621
1561
|
if (__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f")) {
|
|
1622
1562
|
__classPrivateFieldGet(this, _NetworkController_blockTrackerProxy, "f").setTarget(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker);
|
|
1623
1563
|
}
|
|
1624
1564
|
else {
|
|
1625
|
-
__classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
|
|
1565
|
+
__classPrivateFieldSet(this, _NetworkController_blockTrackerProxy, (0, swappable_obj_proxy_1.createEventEmitterProxy)(__classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f").blockTracker, {
|
|
1566
|
+
eventFilter: 'skipInternal',
|
|
1567
|
+
}), "f");
|
|
1626
1568
|
}
|
|
1627
1569
|
__classPrivateFieldSet(this, _NetworkController_ethQuery, new eth_query_1.default(__classPrivateFieldGet(this, _NetworkController_providerProxy, "f")), "f");
|
|
1628
1570
|
};
|