@@ -17,6 +17,7 @@ import {
17
17
BUILT_IN_NETWORKS ,
18
18
BuiltInNetworkName ,
19
19
} from '@metamask/controller-utils' ;
20
+ import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker' ;
20
21
import EthQuery from '@metamask/eth-query' ;
21
22
import { errorCodes } from '@metamask/rpc-errors' ;
22
23
import { createEventEmitterProxy } from '@metamask/swappable-obj-proxy' ;
@@ -512,11 +513,6 @@ export type NetworkControllerGetNetworkClientByIdAction = {
512
513
handler : NetworkController [ 'getNetworkClientById' ] ;
513
514
} ;
514
515
515
- export type NetworkControllerGetNetworkClientIdByChainIdAction = {
516
- type : `NetworkController:getNetworkClientIdByChainId`;
517
- handler : NetworkController [ 'getNetworkClientIdByChainId' ] ;
518
- } ;
519
-
520
516
export type NetworkControllerGetSelectedNetworkClientAction = {
521
517
type : `NetworkController:getSelectedNetworkClient`;
522
518
handler : NetworkController [ 'getSelectedNetworkClient' ] ;
@@ -592,8 +588,7 @@ export type NetworkControllerActions =
592
588
| NetworkControllerGetNetworkConfigurationByNetworkClientId
593
589
| NetworkControllerAddNetworkAction
594
590
| NetworkControllerRemoveNetworkAction
595
- | NetworkControllerUpdateNetworkAction
596
- | NetworkControllerGetNetworkClientIdByChainIdAction ;
591
+ | NetworkControllerUpdateNetworkAction ;
597
592
598
593
export type NetworkControllerMessenger = RestrictedMessenger <
599
594
typeof controllerName ,
@@ -627,16 +622,23 @@ export type NetworkControllerOptions = {
627
622
*/
628
623
log ?: Logger ;
629
624
/**
630
- * A function that can be used to customize the options passed to a
631
- * RPC service constructed for an RPC endpoint. The object that the function
632
- * should return is the same as {@link RpcServiceOptions}, except that
633
- * `failoverService` and `endpointUrl` are not accepted (as they are filled in
634
- * automatically).
625
+ * A function that can be used to customize a RPC service constructed for an
626
+ * RPC endpoint. The function takes the URL of the endpoint and should return
627
+ * an object with type {@link RpcServiceOptions}, minus `failoverService`
628
+ * and `endpointUrl` (as they are filled in automatically).
635
629
*/
636
630
getRpcServiceOptions : (
637
631
rpcEndpointUrl : string ,
638
632
) => Omit < RpcServiceOptions , 'failoverService' | 'endpointUrl' > ;
639
-
633
+ /**
634
+ * A function that can be used to customize a block tracker constructed for an
635
+ * RPC endpoint. The function takes the URL of the endpoint and should return
636
+ * an object of type {@link PollingBlockTrackerOptions}, minus `provider` (as
637
+ * it is filled in automatically).
638
+ */
639
+ getBlockTrackerOptions ?: (
640
+ rpcEndpointUrl : string ,
641
+ ) => Omit < PollingBlockTrackerOptions , 'provider' > ;
640
642
/**
641
643
* An array of Hex Chain IDs representing the additional networks to be included as default.
642
644
*/
@@ -1086,6 +1088,8 @@ export class NetworkController extends BaseController<
1086
1088
1087
1089
readonly #getRpcServiceOptions: NetworkControllerOptions [ 'getRpcServiceOptions' ] ;
1088
1090
1091
+ readonly #getBlockTrackerOptions: NetworkControllerOptions [ 'getBlockTrackerOptions' ] ;
1092
+
1089
1093
#networkConfigurationsByNetworkClientId: Map <
1090
1094
NetworkClientId ,
1091
1095
NetworkConfiguration
@@ -1103,6 +1107,7 @@ export class NetworkController extends BaseController<
1103
1107
infuraProjectId,
1104
1108
log,
1105
1109
getRpcServiceOptions,
1110
+ getBlockTrackerOptions,
1106
1111
additionalDefaultNetworks,
1107
1112
} = options ;
1108
1113
const initialState = {
@@ -1137,6 +1142,7 @@ export class NetworkController extends BaseController<
1137
1142
this . #infuraProjectId = infuraProjectId ;
1138
1143
this . #log = log ;
1139
1144
this . #getRpcServiceOptions = getRpcServiceOptions ;
1145
+ this . #getBlockTrackerOptions = getBlockTrackerOptions ;
1140
1146
1141
1147
this . #previouslySelectedNetworkClientId =
1142
1148
this . state . selectedNetworkClientId ;
@@ -1161,11 +1167,6 @@ export class NetworkController extends BaseController<
1161
1167
this . getNetworkClientById . bind ( this ) ,
1162
1168
) ;
1163
1169
1164
- this . messagingSystem . registerActionHandler (
1165
- `${ this . name } :getNetworkClientIdByChainId` ,
1166
- this . getNetworkClientIdByChainId . bind ( this ) ,
1167
- ) ;
1168
-
1169
1170
this . messagingSystem . registerActionHandler (
1170
1171
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
1171
1172
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
@@ -1838,16 +1839,6 @@ export class NetworkController extends BaseController<
1838
1839
return this . state . networkConfigurationsByChainId [ chainId ] ;
1839
1840
}
1840
1841
1841
- getNetworkClientIdByChainId ( chainId : Hex ) : NetworkClientId | undefined {
1842
- const networkConfiguration = this . getNetworkConfigurationByChainId ( chainId ) ;
1843
- if ( networkConfiguration ) {
1844
- return networkConfiguration . rpcEndpoints [
1845
- networkConfiguration . defaultRpcEndpointIndex
1846
- ] ?. networkClientId ;
1847
- }
1848
- return undefined ;
1849
- }
1850
-
1851
1842
/**
1852
1843
* Returns the network configuration that contains an RPC endpoint with the
1853
1844
* given network client ID.
@@ -2659,6 +2650,7 @@ export class NetworkController extends BaseController<
2659
2650
ticker : networkFields . nativeCurrency ,
2660
2651
} ,
2661
2652
getRpcServiceOptions : this . #getRpcServiceOptions,
2653
+ getBlockTrackerOptions : this . #getBlockTrackerOptions,
2662
2654
messenger : this . messagingSystem ,
2663
2655
} ) ;
2664
2656
} else {
@@ -2673,6 +2665,7 @@ export class NetworkController extends BaseController<
2673
2665
ticker : networkFields . nativeCurrency ,
2674
2666
} ,
2675
2667
getRpcServiceOptions : this . #getRpcServiceOptions,
2668
+ getBlockTrackerOptions : this . #getBlockTrackerOptions,
2676
2669
messenger : this . messagingSystem ,
2677
2670
} ) ;
2678
2671
}
@@ -2833,6 +2826,7 @@ export class NetworkController extends BaseController<
2833
2826
ticker : networkConfiguration . nativeCurrency ,
2834
2827
} ,
2835
2828
getRpcServiceOptions : this . #getRpcServiceOptions,
2829
+ getBlockTrackerOptions : this . #getBlockTrackerOptions,
2836
2830
messenger : this . messagingSystem ,
2837
2831
} ) ,
2838
2832
] as const ;
@@ -2848,6 +2842,7 @@ export class NetworkController extends BaseController<
2848
2842
ticker : networkConfiguration . nativeCurrency ,
2849
2843
} ,
2850
2844
getRpcServiceOptions : this . #getRpcServiceOptions,
2845
+ getBlockTrackerOptions : this . #getBlockTrackerOptions,
2851
2846
messenger : this . messagingSystem ,
2852
2847
} ) ,
2853
2848
] as const ;
0 commit comments