Skip to content

Commit 10d07ca

Browse files
committed
Update PocketProvider to newer URL format (#2980).
1 parent f274104 commit 10d07ca

File tree

1 file changed

+24
-75
lines changed

1 file changed

+24
-75
lines changed
+24-75
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

3-
import { Network, Networkish } from "@ethersproject/networks";
4-
import { getStatic } from "@ethersproject/properties";
3+
import { Network } from "@ethersproject/networks";
54
import { ConnectionInfo } from "@ethersproject/web";
65

76
import { Logger } from "@ethersproject/logger";
@@ -10,83 +9,34 @@ const logger = new Logger(version);
109

1110
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
1211

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+
2014

2115
export class PocketProvider extends UrlJsonRpcProvider {
2216
readonly applicationId: string;
2317
readonly applicationSecretKey: string;
2418
readonly loadBalancer: boolean;
2519

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-
5520
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-
6421
const apiKeyObj: { applicationId: string, applicationSecretKey: string, loadBalancer: boolean } = {
6522
applicationId: null,
66-
loadBalancer: false,
23+
loadBalancer: true,
6724
applicationSecretKey: null
6825
};
6926

7027
// Parse applicationId and applicationSecretKey
71-
if (typeof (apiKey) === "string") {
28+
if (apiKey == null) {
29+
apiKeyObj.applicationId = defaultApplicationId;
30+
31+
} else if (typeof (apiKey) === "string") {
7232
apiKeyObj.applicationId = apiKey;
7333

7434
} 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-
8035
apiKeyObj.applicationId = apiKey.applicationId;
8136
apiKeyObj.applicationSecretKey = apiKey.applicationSecretKey;
82-
apiKeyObj.loadBalancer = !!apiKey.loadBalancer;
8337

8438
} else if (apiKey.applicationId) {
85-
logger.assertArgument((typeof (apiKey.applicationId) === "string"),
86-
"apiKey.applicationId must be a string", "apiKey.applicationId", apiKey.applicationId);
87-
8839
apiKeyObj.applicationId = apiKey.applicationId;
89-
apiKeyObj.loadBalancer = !!apiKey.loadBalancer;
9040

9141
} else {
9242
logger.throwArgumentError("unsupported PocketProvider apiKey", "apiKey", apiKey);
@@ -98,17 +48,26 @@ export class PocketProvider extends UrlJsonRpcProvider {
9848
static getUrl(network: Network, apiKey: any): ConnectionInfo {
9949
let host: string = null;
10050
switch (network ? network.name : "unknown") {
51+
case "goerli":
52+
host = "eth-goerli.gateway.pokt.network";
53+
break;
10154
case "homestead":
10255
host = "eth-mainnet.gateway.pokt.network";
10356
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";
10665
break;
10766
case "rinkeby":
10867
host = "eth-rinkeby.gateway.pokt.network";
10968
break;
110-
case "goerli":
111-
host = "eth-goerli.gateway.pokt.network";
69+
case "ropsten":
70+
host = "eth-ropsten.gateway.pokt.network";
11271
break;
11372
default:
11473
logger.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
@@ -117,19 +76,9 @@ export class PocketProvider extends UrlJsonRpcProvider {
11776
});
11877
}
11978

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 }`
13180

132-
// Apply application secret key
81+
const connection: ConnectionInfo = { headers: { }, url };
13382
if (apiKey.applicationSecretKey != null) {
13483
connection.user = "";
13584
connection.password = apiKey.applicationSecretKey
@@ -139,6 +88,6 @@ export class PocketProvider extends UrlJsonRpcProvider {
13988
}
14089

14190
isCommunityResource(): boolean {
142-
return (this.applicationId === defaultApplicationIds[this.network.name]);
91+
return (this.applicationId === defaultApplicationId);
14392
}
14493
}

0 commit comments

Comments
 (0)