@metamask/network-controller 24.1.0 → 24.2.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 +27 -1
- package/dist/NetworkController.cjs +211 -202
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +62 -21
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +62 -21
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +211 -202
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/create-auto-managed-network-client.cjs +3 -1
- package/dist/create-auto-managed-network-client.cjs.map +1 -1
- package/dist/create-auto-managed-network-client.d.cts +4 -1
- package/dist/create-auto-managed-network-client.d.cts.map +1 -1
- package/dist/create-auto-managed-network-client.d.mts +4 -1
- package/dist/create-auto-managed-network-client.d.mts.map +1 -1
- package/dist/create-auto-managed-network-client.mjs +3 -1
- package/dist/create-auto-managed-network-client.mjs.map +1 -1
- package/dist/create-network-client.cjs +3 -1
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.d.cts +4 -1
- package/dist/create-network-client.d.cts.map +1 -1
- package/dist/create-network-client.d.mts +4 -1
- package/dist/create-network-client.d.mts.map +1 -1
- package/dist/create-network-client.mjs +3 -1
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/rpc-service/rpc-service.cjs +17 -3
- package/dist/rpc-service/rpc-service.cjs.map +1 -1
- package/dist/rpc-service/rpc-service.d.cts +5 -0
- package/dist/rpc-service/rpc-service.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service.d.mts +5 -0
- package/dist/rpc-service/rpc-service.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service.mjs +19 -5
- package/dist/rpc-service/rpc-service.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [24.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6525](https://github.com/MetaMask/core/pull/6525))
|
|
15
|
+
- Add `lookupNetwork` option to `initializeProvider`, to allow for skipping the request used to populate metadata for the globally selected network ([#6575](https://github.com/MetaMask/core/pull/6575), [#6607](https://github.com/MetaMask/core/pull/6607))
|
|
16
|
+
- If `lookupNetwork` is set to `false`, the function is fully synchronous, and does not return a promise.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Bump `@metamask/controller-utils` from `^11.12.0` to `^11.14.0` ([#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629))
|
|
21
|
+
- Bump `@metamask/base-controller` from `^8.1.0` to `^8.4.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632))
|
|
22
|
+
- Rephrase "circuit broken" errors so they are more user-friendly ([#6423](https://github.com/MetaMask/core/pull/6423))
|
|
23
|
+
- These are errors produced when a request is made to an RPC endpoint after it returns too many consecutive 5xx responses and the underlying circuit is open.
|
|
24
|
+
- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
|
|
25
|
+
- Bump `@metamask/json-rpc-engine` from `^10.0.3` to `^10.1.0` ([#6678](https://github.com/MetaMask/core/pull/6678))
|
|
26
|
+
- Bump `@metamask/eth-json-rpc-provider` from `^4.1.8` to `^5.0.0` ([#6678](https://github.com/MetaMask/core/pull/6678))
|
|
27
|
+
|
|
28
|
+
### Deprecated
|
|
29
|
+
|
|
30
|
+
- Deprecate `lookupNetworkByClientId` ([#6308](https://github.com/MetaMask/core/pull/6308))
|
|
31
|
+
- `lookupNetwork` already supports passing in a network client ID; please use this going forward instead.
|
|
32
|
+
|
|
10
33
|
## [24.1.0]
|
|
11
34
|
|
|
12
35
|
### Added
|
|
@@ -18,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
18
41
|
|
|
19
42
|
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.1.0` ([#6284](https://github.com/MetaMask/core/pull/6284))
|
|
20
43
|
- Bump `@metamask/controller-utils` from `^11.11.0` to `^11.12.0` ([#6303](https://github.com/MetaMask/core/pull/6303))
|
|
44
|
+
- This effectively changes the `onDegraded` property on `AbstractRpcService` so that the event listener payload may be an object with either a `endpointUrl` property, `error` + `endpointUrl` properties, or `value` + `endpointUrl` properties
|
|
45
|
+
- **NOTE:** Although `error` and `value` are new, optional properties, this change makes an inadvertent breaking change to the signature of the event listener due to how TypeScript compares function types. We have conciously decided not to re-release this change under a major version, so be advised.
|
|
21
46
|
|
|
22
47
|
## [24.0.1]
|
|
23
48
|
|
|
@@ -917,7 +942,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
917
942
|
|
|
918
943
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
919
944
|
|
|
920
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.
|
|
945
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.2.0...HEAD
|
|
946
|
+
[24.2.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.1.0...@metamask/network-controller@24.2.0
|
|
921
947
|
[24.1.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.0.1...@metamask/network-controller@24.1.0
|
|
922
948
|
[24.0.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@24.0.0...@metamask/network-controller@24.0.1
|
|
923
949
|
[24.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.6.0...@metamask/network-controller@24.0.0
|
|
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
|
-
var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_isRpcFailoverEnabled, _NetworkController_updateRpcFailoverEnabled, _NetworkController_refreshNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
|
|
39
|
+
var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_getRpcServiceOptions, _NetworkController_getBlockTrackerOptions, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_isRpcFailoverEnabled, _NetworkController_updateRpcFailoverEnabled, _NetworkController_refreshNetwork, _NetworkController_determineNetworkMetadata, _NetworkController_lookupGivenNetwork, _NetworkController_lookupSelectedNetwork, _NetworkController_updateMetadataForNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.NetworkController = exports.selectAvailableNetworkClientIds = exports.getAvailableNetworkClientIds = exports.selectNetworkConfigurations = exports.getNetworkConfigurations = exports.getDefaultNetworkControllerState = exports.knownKeysOf = exports.RpcEndpointType = void 0;
|
|
42
42
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -386,16 +386,22 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
386
386
|
name: controllerName,
|
|
387
387
|
metadata: {
|
|
388
388
|
selectedNetworkClientId: {
|
|
389
|
+
includeInStateLogs: true,
|
|
389
390
|
persist: true,
|
|
390
391
|
anonymous: false,
|
|
392
|
+
usedInUi: true,
|
|
391
393
|
},
|
|
392
394
|
networksMetadata: {
|
|
395
|
+
includeInStateLogs: true,
|
|
393
396
|
persist: true,
|
|
394
397
|
anonymous: false,
|
|
398
|
+
usedInUi: true,
|
|
395
399
|
},
|
|
396
400
|
networkConfigurationsByChainId: {
|
|
401
|
+
includeInStateLogs: true,
|
|
397
402
|
persist: true,
|
|
398
403
|
anonymous: false,
|
|
404
|
+
usedInUi: true,
|
|
399
405
|
},
|
|
400
406
|
},
|
|
401
407
|
messenger,
|
|
@@ -559,221 +565,52 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
559
565
|
}
|
|
560
566
|
return customNetworkClient;
|
|
561
567
|
}
|
|
562
|
-
|
|
563
|
-
* Ensures that network clients for Infura and custom RPC endpoints have been
|
|
564
|
-
* created. Then, consulting state, initializes and establishes the currently
|
|
565
|
-
* selected network client.
|
|
566
|
-
*/
|
|
567
|
-
async initializeProvider() {
|
|
568
|
+
initializeProvider({ lookupNetwork = true, } = {}) {
|
|
568
569
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, this.state.selectedNetworkClientId);
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Refreshes the network meta with EIP-1559 support and the network status
|
|
573
|
-
* based on the given network client ID.
|
|
574
|
-
*
|
|
575
|
-
* @param networkClientId - The ID of the network client to update.
|
|
576
|
-
*/
|
|
577
|
-
async lookupNetworkByClientId(networkClientId) {
|
|
578
|
-
const isInfura = (0, controller_utils_1.isInfuraNetworkType)(networkClientId);
|
|
579
|
-
let updatedNetworkStatus;
|
|
580
|
-
let updatedIsEIP1559Compatible;
|
|
581
|
-
try {
|
|
582
|
-
updatedIsEIP1559Compatible =
|
|
583
|
-
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
|
|
584
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Available;
|
|
570
|
+
if (lookupNetwork) {
|
|
571
|
+
return this.lookupNetwork();
|
|
585
572
|
}
|
|
586
|
-
|
|
587
|
-
debugLog('NetworkController: lookupNetworkByClientId: ', error);
|
|
588
|
-
// TODO: mock ethQuery.sendAsync to throw error without error code
|
|
589
|
-
/* istanbul ignore else */
|
|
590
|
-
if (isErrorWithCode(error)) {
|
|
591
|
-
let responseBody;
|
|
592
|
-
if (isInfura &&
|
|
593
|
-
(0, utils_1.hasProperty)(error, 'message') &&
|
|
594
|
-
typeof error.message === 'string') {
|
|
595
|
-
try {
|
|
596
|
-
responseBody = JSON.parse(error.message);
|
|
597
|
-
}
|
|
598
|
-
catch {
|
|
599
|
-
// error.message must not be JSON
|
|
600
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: json parse error: ', error);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
if ((0, utils_1.isPlainObject)(responseBody) &&
|
|
604
|
-
responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
|
|
605
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Blocked;
|
|
606
|
-
}
|
|
607
|
-
else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
|
|
608
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
|
|
609
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: rpc internal error: ', error);
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Unavailable;
|
|
613
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: ', error);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
else if (typeof Error !== 'undefined' &&
|
|
617
|
-
(0, utils_1.hasProperty)(error, 'message') &&
|
|
618
|
-
typeof error.message === 'string' &&
|
|
619
|
-
error.message.includes('No custom network client was found with the ID')) {
|
|
620
|
-
throw error;
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
debugLog('NetworkController - could not determine network status', error);
|
|
624
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
|
|
625
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetworkByClientId: ', error);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
this.update((state) => {
|
|
629
|
-
if (state.networksMetadata[networkClientId] === undefined) {
|
|
630
|
-
state.networksMetadata[networkClientId] = {
|
|
631
|
-
status: constants_1.NetworkStatus.Unknown,
|
|
632
|
-
EIPS: {},
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
const meta = state.networksMetadata[networkClientId];
|
|
636
|
-
meta.status = updatedNetworkStatus;
|
|
637
|
-
if (updatedIsEIP1559Compatible === undefined) {
|
|
638
|
-
delete meta.EIPS[1559];
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
meta.EIPS[1559] = updatedIsEIP1559Compatible;
|
|
642
|
-
}
|
|
643
|
-
});
|
|
573
|
+
return undefined;
|
|
644
574
|
}
|
|
645
575
|
/**
|
|
646
|
-
*
|
|
647
|
-
* state:
|
|
576
|
+
* Uses a request for the latest block to gather the following information on
|
|
577
|
+
* the given or selected network, persisting it to state:
|
|
648
578
|
*
|
|
649
|
-
* - The status
|
|
650
|
-
*
|
|
651
|
-
* -
|
|
579
|
+
* - The connectivity status: whether it is available, geo-blocked (Infura
|
|
580
|
+
* only), unavailable, or unknown
|
|
581
|
+
* - The capabilities status: whether it supports EIP-1559, whether it does
|
|
582
|
+
* not, or whether it is unknown
|
|
652
583
|
*
|
|
653
|
-
*
|
|
654
|
-
* being collected. If that is the case, no metadata for the (now previously)
|
|
655
|
-
* selected network will be updated.
|
|
656
|
-
*
|
|
657
|
-
* @param networkClientId - The ID of the network client to update.
|
|
584
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
658
585
|
* If no ID is provided, uses the currently selected network.
|
|
659
586
|
*/
|
|
660
587
|
async lookupNetwork(networkClientId) {
|
|
661
588
|
if (networkClientId) {
|
|
662
|
-
await this.
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
const isInfura = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClient, "f")?.configuration.type ===
|
|
669
|
-
types_1.NetworkClientType.Infura;
|
|
670
|
-
let networkChanged = false;
|
|
671
|
-
const listener = () => {
|
|
672
|
-
networkChanged = true;
|
|
673
|
-
try {
|
|
674
|
-
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
675
|
-
}
|
|
676
|
-
catch (error) {
|
|
677
|
-
// In theory, this `catch` should not be necessary given that this error
|
|
678
|
-
// would occur "inside" of the call to `#determineEIP1559Compatibility`
|
|
679
|
-
// below and so it should be caught by the `try`/`catch` below (it is
|
|
680
|
-
// impossible to reproduce in tests for that reason). However, somehow
|
|
681
|
-
// it occurs within Mobile and so we have to add our own `try`/`catch`
|
|
682
|
-
// here.
|
|
683
|
-
/* istanbul ignore next */
|
|
684
|
-
if (!(error instanceof Error) ||
|
|
685
|
-
error.message !==
|
|
686
|
-
'Subscription not found for event: NetworkController:networkDidChange') {
|
|
687
|
-
// Again, this error should not happen and is impossible to reproduce
|
|
688
|
-
// in tests.
|
|
689
|
-
/* istanbul ignore next */
|
|
690
|
-
throw error;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
|
|
695
|
-
let updatedNetworkStatus;
|
|
696
|
-
let updatedIsEIP1559Compatible;
|
|
697
|
-
try {
|
|
698
|
-
const isEIP1559Compatible = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, this.state.selectedNetworkClientId);
|
|
699
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Available;
|
|
700
|
-
updatedIsEIP1559Compatible = isEIP1559Compatible;
|
|
701
|
-
}
|
|
702
|
-
catch (error) {
|
|
703
|
-
// TODO: mock ethQuery.sendAsync to throw error without error code
|
|
704
|
-
/* istanbul ignore else */
|
|
705
|
-
if (isErrorWithCode(error)) {
|
|
706
|
-
let responseBody;
|
|
707
|
-
if (isInfura &&
|
|
708
|
-
(0, utils_1.hasProperty)(error, 'message') &&
|
|
709
|
-
typeof error.message === 'string') {
|
|
710
|
-
try {
|
|
711
|
-
responseBody = JSON.parse(error.message);
|
|
712
|
-
}
|
|
713
|
-
catch (parseError) {
|
|
714
|
-
// error.message must not be JSON
|
|
715
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error', parseError);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
if ((0, utils_1.isPlainObject)(responseBody) &&
|
|
719
|
-
responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
|
|
720
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Blocked;
|
|
721
|
-
}
|
|
722
|
-
else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
|
|
723
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
|
|
724
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error', error);
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
727
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Unavailable;
|
|
728
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
else {
|
|
732
|
-
debugLog('NetworkController - could not determine network status', error);
|
|
733
|
-
updatedNetworkStatus = constants_1.NetworkStatus.Unknown;
|
|
734
|
-
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (networkChanged) {
|
|
738
|
-
// If the network has changed, then `lookupNetwork` either has been or is
|
|
739
|
-
// in the process of being called, so we don't need to go further.
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
try {
|
|
743
|
-
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
744
|
-
}
|
|
745
|
-
catch (error) {
|
|
746
|
-
if (!(error instanceof Error) ||
|
|
747
|
-
error.message !==
|
|
748
|
-
'Subscription not found for event: NetworkController:networkDidChange') {
|
|
749
|
-
throw error;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
this.update((state) => {
|
|
753
|
-
const meta = state.networksMetadata[state.selectedNetworkClientId];
|
|
754
|
-
meta.status = updatedNetworkStatus;
|
|
755
|
-
if (updatedIsEIP1559Compatible === undefined) {
|
|
756
|
-
delete meta.EIPS[1559];
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
meta.EIPS[1559] = updatedIsEIP1559Compatible;
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
if (isInfura) {
|
|
763
|
-
if (updatedNetworkStatus === constants_1.NetworkStatus.Available) {
|
|
764
|
-
this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
|
|
765
|
-
}
|
|
766
|
-
else if (updatedNetworkStatus === constants_1.NetworkStatus.Blocked) {
|
|
767
|
-
this.messagingSystem.publish('NetworkController:infuraIsBlocked');
|
|
768
|
-
}
|
|
589
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
|
|
769
590
|
}
|
|
770
591
|
else {
|
|
771
|
-
|
|
772
|
-
// prevent consumers from being stuck in a blocked state if they were
|
|
773
|
-
// previously connected to an Infura network that was blocked
|
|
774
|
-
this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
|
|
592
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupSelectedNetwork).call(this);
|
|
775
593
|
}
|
|
776
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Uses a request for the latest block to gather the following information on
|
|
597
|
+
* the given network, persisting it to state:
|
|
598
|
+
*
|
|
599
|
+
* - The connectivity status: whether the network is available, geo-blocked
|
|
600
|
+
* (Infura only), unavailable, or unknown
|
|
601
|
+
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
602
|
+
* whether it does not, or whether it is unknown
|
|
603
|
+
*
|
|
604
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
605
|
+
* @deprecated Please use `lookupNetwork` and pass a network client ID
|
|
606
|
+
* instead. This method will be removed in a future major version.
|
|
607
|
+
*/
|
|
608
|
+
// We are planning on removing this so we aren't interested in testing this
|
|
609
|
+
// right now.
|
|
610
|
+
/* istanbul ignore next */
|
|
611
|
+
async lookupNetworkByClientId(networkClientId) {
|
|
612
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_lookupGivenNetwork).call(this, networkClientId);
|
|
613
|
+
}
|
|
777
614
|
/**
|
|
778
615
|
* Convenience method to update provider network type settings.
|
|
779
616
|
*
|
|
@@ -1268,6 +1105,174 @@ async function _NetworkController_refreshNetwork(networkClientId, options = {})
|
|
|
1268
1105
|
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this, networkClientId, options);
|
|
1269
1106
|
this.messagingSystem.publish('NetworkController:networkDidChange', this.state);
|
|
1270
1107
|
await this.lookupNetwork();
|
|
1108
|
+
}, _NetworkController_determineNetworkMetadata =
|
|
1109
|
+
/**
|
|
1110
|
+
* Uses a request for the latest block to gather the following information on
|
|
1111
|
+
* the given network:
|
|
1112
|
+
*
|
|
1113
|
+
* - The connectivity status: whether it is available, geo-blocked (Infura
|
|
1114
|
+
* only), unavailable, or unknown
|
|
1115
|
+
* - The capabilities status: whether it supports EIP-1559, whether it does
|
|
1116
|
+
* not, or whether it is unknown
|
|
1117
|
+
*
|
|
1118
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
1119
|
+
* If no ID is provided, uses the currently selected network.
|
|
1120
|
+
* @returns The resulting metadata for the network.
|
|
1121
|
+
*/
|
|
1122
|
+
async function _NetworkController_determineNetworkMetadata(networkClientId) {
|
|
1123
|
+
// Force TypeScript to use one of the two overloads explicitly
|
|
1124
|
+
const networkClient = (0, controller_utils_1.isInfuraNetworkType)(networkClientId)
|
|
1125
|
+
? this.getNetworkClientById(networkClientId)
|
|
1126
|
+
: this.getNetworkClientById(networkClientId);
|
|
1127
|
+
const isInfura = networkClient.configuration.type === types_1.NetworkClientType.Infura;
|
|
1128
|
+
let networkStatus;
|
|
1129
|
+
let isEIP1559Compatible;
|
|
1130
|
+
try {
|
|
1131
|
+
isEIP1559Compatible =
|
|
1132
|
+
await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this, networkClientId);
|
|
1133
|
+
networkStatus = constants_1.NetworkStatus.Available;
|
|
1134
|
+
}
|
|
1135
|
+
catch (error) {
|
|
1136
|
+
debugLog('NetworkController: lookupNetwork: ', error);
|
|
1137
|
+
if (isErrorWithCode(error)) {
|
|
1138
|
+
let responseBody;
|
|
1139
|
+
if (isInfura &&
|
|
1140
|
+
(0, utils_1.hasProperty)(error, 'message') &&
|
|
1141
|
+
typeof error.message === 'string') {
|
|
1142
|
+
try {
|
|
1143
|
+
responseBody = JSON.parse(error.message);
|
|
1144
|
+
}
|
|
1145
|
+
catch {
|
|
1146
|
+
// error.message must not be JSON
|
|
1147
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: json parse error: ', error);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
if ((0, utils_1.isPlainObject)(responseBody) &&
|
|
1151
|
+
responseBody.error === constants_1.INFURA_BLOCKED_KEY) {
|
|
1152
|
+
networkStatus = constants_1.NetworkStatus.Blocked;
|
|
1153
|
+
}
|
|
1154
|
+
else if (error.code === rpc_errors_1.errorCodes.rpc.internal) {
|
|
1155
|
+
networkStatus = constants_1.NetworkStatus.Unknown;
|
|
1156
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: rpc internal error: ', error);
|
|
1157
|
+
}
|
|
1158
|
+
else {
|
|
1159
|
+
networkStatus = constants_1.NetworkStatus.Unavailable;
|
|
1160
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
debugLog('NetworkController - could not determine network status', error);
|
|
1165
|
+
networkStatus = constants_1.NetworkStatus.Unknown;
|
|
1166
|
+
__classPrivateFieldGet(this, _NetworkController_log, "f")?.warn('NetworkController: lookupNetwork: ', error);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return { isInfura, networkStatus, isEIP1559Compatible };
|
|
1170
|
+
}, _NetworkController_lookupGivenNetwork =
|
|
1171
|
+
/**
|
|
1172
|
+
* Uses a request for the latest block to gather the following information on
|
|
1173
|
+
* the given network, persisting it to state:
|
|
1174
|
+
*
|
|
1175
|
+
* - The connectivity status: whether the network is available, geo-blocked
|
|
1176
|
+
* (Infura only), unavailable, or unknown
|
|
1177
|
+
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
1178
|
+
* whether it does not, or whether it is unknown
|
|
1179
|
+
*
|
|
1180
|
+
* @param networkClientId - The ID of the network client to inspect.
|
|
1181
|
+
*/
|
|
1182
|
+
async function _NetworkController_lookupGivenNetwork(networkClientId) {
|
|
1183
|
+
const { networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, networkClientId);
|
|
1184
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, networkClientId, networkStatus, isEIP1559Compatible);
|
|
1185
|
+
}, _NetworkController_lookupSelectedNetwork =
|
|
1186
|
+
/**
|
|
1187
|
+
* Uses a request for the latest block to gather the following information on
|
|
1188
|
+
* the currently selected network, persisting it to state:
|
|
1189
|
+
*
|
|
1190
|
+
* - The connectivity status: whether the network is available, geo-blocked
|
|
1191
|
+
* (Infura only), unavailable, or unknown
|
|
1192
|
+
* - The feature compatibility status: whether the network supports EIP-1559,
|
|
1193
|
+
* whether it does not, or whether it is unknown
|
|
1194
|
+
*
|
|
1195
|
+
* Note that it is possible for the current network to be switched while this
|
|
1196
|
+
* method is running. If that is the case, it will exit early (as this method
|
|
1197
|
+
* will also run for the new network).
|
|
1198
|
+
*/
|
|
1199
|
+
async function _NetworkController_lookupSelectedNetwork() {
|
|
1200
|
+
if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
let networkChanged = false;
|
|
1204
|
+
const listener = () => {
|
|
1205
|
+
networkChanged = true;
|
|
1206
|
+
try {
|
|
1207
|
+
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
1208
|
+
}
|
|
1209
|
+
catch (error) {
|
|
1210
|
+
// In theory, this `catch` should not be necessary given that this error
|
|
1211
|
+
// would occur "inside" of the call to `#determineEIP1559Compatibility`
|
|
1212
|
+
// below and so it should be caught by the `try`/`catch` below (it is
|
|
1213
|
+
// impossible to reproduce in tests for that reason). However, somehow
|
|
1214
|
+
// it occurs within Mobile and so we have to add our own `try`/`catch`
|
|
1215
|
+
// here.
|
|
1216
|
+
/* istanbul ignore next */
|
|
1217
|
+
if (!(error instanceof Error) ||
|
|
1218
|
+
error.message !==
|
|
1219
|
+
'Subscription not found for event: NetworkController:networkDidChange') {
|
|
1220
|
+
// Again, this error should not happen and is impossible to reproduce
|
|
1221
|
+
// in tests.
|
|
1222
|
+
/* istanbul ignore next */
|
|
1223
|
+
throw error;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
|
|
1228
|
+
const { isInfura, networkStatus, isEIP1559Compatible } = await __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineNetworkMetadata).call(this, this.state.selectedNetworkClientId);
|
|
1229
|
+
if (networkChanged) {
|
|
1230
|
+
// If the network has changed, then `lookupNetwork` either has been or is
|
|
1231
|
+
// in the process of being called, so we don't need to go further.
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
try {
|
|
1235
|
+
this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
|
|
1236
|
+
}
|
|
1237
|
+
catch (error) {
|
|
1238
|
+
if (!(error instanceof Error) ||
|
|
1239
|
+
error.message !==
|
|
1240
|
+
'Subscription not found for event: NetworkController:networkDidChange') {
|
|
1241
|
+
throw error;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
__classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_updateMetadataForNetwork).call(this, this.state.selectedNetworkClientId, networkStatus, isEIP1559Compatible);
|
|
1245
|
+
if (isInfura) {
|
|
1246
|
+
if (networkStatus === constants_1.NetworkStatus.Available) {
|
|
1247
|
+
this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
|
|
1248
|
+
}
|
|
1249
|
+
else if (networkStatus === constants_1.NetworkStatus.Blocked) {
|
|
1250
|
+
this.messagingSystem.publish('NetworkController:infuraIsBlocked');
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
else {
|
|
1254
|
+
// Always publish infuraIsUnblocked regardless of network status to
|
|
1255
|
+
// prevent consumers from being stuck in a blocked state if they were
|
|
1256
|
+
// previously connected to an Infura network that was blocked
|
|
1257
|
+
this.messagingSystem.publish('NetworkController:infuraIsUnblocked');
|
|
1258
|
+
}
|
|
1259
|
+
}, _NetworkController_updateMetadataForNetwork = function _NetworkController_updateMetadataForNetwork(networkClientId, networkStatus, isEIP1559Compatible) {
|
|
1260
|
+
this.update((state) => {
|
|
1261
|
+
if (state.networksMetadata[networkClientId] === undefined) {
|
|
1262
|
+
state.networksMetadata[networkClientId] = {
|
|
1263
|
+
status: constants_1.NetworkStatus.Unknown,
|
|
1264
|
+
EIPS: {},
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
const meta = state.networksMetadata[networkClientId];
|
|
1268
|
+
meta.status = networkStatus;
|
|
1269
|
+
if (isEIP1559Compatible === undefined) {
|
|
1270
|
+
delete meta.EIPS[1559];
|
|
1271
|
+
}
|
|
1272
|
+
else {
|
|
1273
|
+
meta.EIPS[1559] = isEIP1559Compatible;
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1271
1276
|
}, _NetworkController_getLatestBlock = function _NetworkController_getLatestBlock(networkClientId) {
|
|
1272
1277
|
if (networkClientId === undefined) {
|
|
1273
1278
|
networkClientId = this.state.selectedNetworkClientId;
|
|
@@ -1466,6 +1471,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1466
1471
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1467
1472
|
messenger: this.messagingSystem,
|
|
1468
1473
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1474
|
+
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1469
1475
|
});
|
|
1470
1476
|
}
|
|
1471
1477
|
else {
|
|
@@ -1481,6 +1487,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1481
1487
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1482
1488
|
messenger: this.messagingSystem,
|
|
1483
1489
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1490
|
+
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1484
1491
|
});
|
|
1485
1492
|
}
|
|
1486
1493
|
}
|
|
@@ -1540,6 +1547,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1540
1547
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1541
1548
|
messenger: this.messagingSystem,
|
|
1542
1549
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1550
|
+
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1543
1551
|
}),
|
|
1544
1552
|
];
|
|
1545
1553
|
}
|
|
@@ -1557,6 +1565,7 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
|
|
|
1557
1565
|
getBlockTrackerOptions: __classPrivateFieldGet(this, _NetworkController_getBlockTrackerOptions, "f"),
|
|
1558
1566
|
messenger: this.messagingSystem,
|
|
1559
1567
|
isRpcFailoverEnabled: __classPrivateFieldGet(this, _NetworkController_isRpcFailoverEnabled, "f"),
|
|
1568
|
+
logger: __classPrivateFieldGet(this, _NetworkController_log, "f"),
|
|
1560
1569
|
}),
|
|
1561
1570
|
];
|
|
1562
1571
|
});
|