1
1
"use strict" ;
2
2
3
- import { Network , Networkish } from "@ethersproject/networks" ;
4
- import { getStatic } from "@ethersproject/properties" ;
3
+ import { Network } from "@ethersproject/networks" ;
5
4
import { ConnectionInfo } from "@ethersproject/web" ;
6
5
7
6
import { Logger } from "@ethersproject/logger" ;
@@ -10,83 +9,34 @@ const logger = new Logger(version);
10
9
11
10
import { UrlJsonRpcProvider } from "./url-json-rpc-provider" ;
12
11
13
- // These are load-balancer-based application IDs
14
- const defaultApplicationIds : Record < string , string > = {
15
- homestead : "6004bcd10040261633ade990" ,
16
- ropsten : "6004bd4d0040261633ade991" ,
17
- rinkeby : "6004bda20040261633ade994" ,
18
- goerli : "6004bd860040261633ade992" ,
19
- } ;
12
+ const defaultApplicationId = "62e1ad51b37b8e00394bda3b" ;
13
+
20
14
21
15
export class PocketProvider extends UrlJsonRpcProvider {
22
16
readonly applicationId : string ;
23
17
readonly applicationSecretKey : string ;
24
18
readonly loadBalancer : boolean ;
25
19
26
- constructor ( network ?: Networkish , apiKey ?: any ) {
27
- // We need a bit of creativity in the constructor because
28
- // Pocket uses different default API keys based on the network
29
-
30
- if ( apiKey == null ) {
31
- const n = getStatic < ( network : Networkish ) => Network > ( new . target , "getNetwork" ) ( network ) ;
32
- if ( n ) {
33
- const applicationId = defaultApplicationIds [ n . name ] ;
34
- if ( applicationId ) {
35
- apiKey = {
36
- applicationId : applicationId ,
37
- loadBalancer : true
38
- } ;
39
- }
40
- }
41
-
42
- // If there was any issue above, we don't know this network
43
- if ( apiKey == null ) {
44
- logger . throwError ( "unsupported network" , Logger . errors . INVALID_ARGUMENT , {
45
- argument : "network" ,
46
- value : network
47
- } ) ;
48
- }
49
-
50
- }
51
-
52
- super ( network , apiKey ) ;
53
- }
54
-
55
20
static getApiKey ( apiKey : any ) : any {
56
- // Most API Providers allow null to get the default configuration, but
57
- // Pocket requires the network to decide the default provider, so we
58
- // rely on hijacking the constructor to add a sensible default for us
59
-
60
- if ( apiKey == null ) {
61
- logger . throwArgumentError ( "PocketProvider.getApiKey does not support null apiKey" , "apiKey" , apiKey ) ;
62
- }
63
-
64
21
const apiKeyObj : { applicationId : string , applicationSecretKey : string , loadBalancer : boolean } = {
65
22
applicationId : null ,
66
- loadBalancer : false ,
23
+ loadBalancer : true ,
67
24
applicationSecretKey : null
68
25
} ;
69
26
70
27
// Parse applicationId and applicationSecretKey
71
- if ( typeof ( apiKey ) === "string" ) {
28
+ if ( apiKey == null ) {
29
+ apiKeyObj . applicationId = defaultApplicationId ;
30
+
31
+ } else if ( typeof ( apiKey ) === "string" ) {
72
32
apiKeyObj . applicationId = apiKey ;
73
33
74
34
} else if ( apiKey . applicationSecretKey != null ) {
75
- logger . assertArgument ( ( typeof ( apiKey . applicationId ) === "string" ) ,
76
- "applicationSecretKey requires an applicationId" , "applicationId" , apiKey . applicationId ) ;
77
- logger . assertArgument ( ( typeof ( apiKey . applicationSecretKey ) === "string" ) ,
78
- "invalid applicationSecretKey" , "applicationSecretKey" , "[REDACTED]" ) ;
79
-
80
35
apiKeyObj . applicationId = apiKey . applicationId ;
81
36
apiKeyObj . applicationSecretKey = apiKey . applicationSecretKey ;
82
- apiKeyObj . loadBalancer = ! ! apiKey . loadBalancer ;
83
37
84
38
} else if ( apiKey . applicationId ) {
85
- logger . assertArgument ( ( typeof ( apiKey . applicationId ) === "string" ) ,
86
- "apiKey.applicationId must be a string" , "apiKey.applicationId" , apiKey . applicationId ) ;
87
-
88
39
apiKeyObj . applicationId = apiKey . applicationId ;
89
- apiKeyObj . loadBalancer = ! ! apiKey . loadBalancer ;
90
40
91
41
} else {
92
42
logger . throwArgumentError ( "unsupported PocketProvider apiKey" , "apiKey" , apiKey ) ;
@@ -98,17 +48,26 @@ export class PocketProvider extends UrlJsonRpcProvider {
98
48
static getUrl ( network : Network , apiKey : any ) : ConnectionInfo {
99
49
let host : string = null ;
100
50
switch ( network ? network . name : "unknown" ) {
51
+ case "goerli" :
52
+ host = "eth-goerli.gateway.pokt.network" ;
53
+ break ;
101
54
case "homestead" :
102
55
host = "eth-mainnet.gateway.pokt.network" ;
103
56
break ;
104
- case "ropsten" :
105
- host = "eth-ropsten.gateway.pokt.network" ;
57
+ case "kovan" :
58
+ host = "poa-kovan.gateway.pokt.network" ;
59
+ break ;
60
+ case "matic" :
61
+ host = "poly-mainnet.gateway.pokt.network" ;
62
+ break ;
63
+ case "maticmum" :
64
+ host = "polygon-mumbai-rpc.gateway.pokt.network" ;
106
65
break ;
107
66
case "rinkeby" :
108
67
host = "eth-rinkeby.gateway.pokt.network" ;
109
68
break ;
110
- case "goerli " :
111
- host = "eth-goerli .gateway.pokt.network" ;
69
+ case "ropsten " :
70
+ host = "eth-ropsten .gateway.pokt.network" ;
112
71
break ;
113
72
default :
114
73
logger . throwError ( "unsupported network" , Logger . errors . INVALID_ARGUMENT , {
@@ -117,19 +76,9 @@ export class PocketProvider extends UrlJsonRpcProvider {
117
76
} ) ;
118
77
}
119
78
120
- let url = null ;
121
- if ( apiKey . loadBalancer ) {
122
- url = `https:/\/${ host } /v1/lb/${ apiKey . applicationId } `
123
- } else {
124
- url = `https:/\/${ host } /v1/${ apiKey . applicationId } `
125
- }
126
-
127
- const connection : ConnectionInfo = { url } ;
128
-
129
- // Initialize empty headers
130
- connection . headers = { }
79
+ const url = `https:/\/${ host } /v1/lb/${ apiKey . applicationId } `
131
80
132
- // Apply application secret key
81
+ const connection : ConnectionInfo = { headers : { } , url } ;
133
82
if ( apiKey . applicationSecretKey != null ) {
134
83
connection . user = "" ;
135
84
connection . password = apiKey . applicationSecretKey
@@ -139,6 +88,6 @@ export class PocketProvider extends UrlJsonRpcProvider {
139
88
}
140
89
141
90
isCommunityResource ( ) : boolean {
142
- return ( this . applicationId === defaultApplicationIds [ this . network . name ] ) ;
91
+ return ( this . applicationId === defaultApplicationId ) ;
143
92
}
144
93
}
0 commit comments