Skip to content

Commit 7dbd8b6

Browse files
committed
Added Ethereum testnets support and fixed bugs
1 parent 3d26943 commit 7dbd8b6

35 files changed

+1139
-667
lines changed

docs.wrm/api-keys.wrm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ const provider = ethers.getDefaultProvider(network, {
130130
// projectSecret: YOUR_INFURA_PROJECT_SECRET,
131131
// },
132132
alchemy: YOUR_ALCHEMY_API_KEY,
133-
pocket: YOUR_POCKET_APPLICATION_KEY
133+
pocket_gateway: YOUR_POCKET_APPLICATION_KEY
134134
// Or if using an application secret key:
135-
// pocket: {
135+
// pocket_gateway: {
136136
// applicationId: ,
137137
// applicationSecretKey:
138+
// endpointType: <loadbalancer || application>
138139
// }
139140
});

docs.wrm/api/providers/api-providers.wrm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,24 @@ you also need to specify the ``applicationID`` property.
100100
- ``applicationOrigin``: By specifying this property you are setting the `Origin` header in your request
101101
(remember that browsers will swap this header based on the actual origin of the website loaded).
102102
- ``applicationUserAgent``: By specifying this property you are setting the `User-Agent` header in your request.
103+
- ``endpointType``: By specifying this property you can select to connect via the Pocket Gateway Single Application endpoint or a Load Balancer Endpoint (defaults to Load Balancer)
103104

104105
The //network// and //apiKey// are specified the same as [the constructor](PocketGatewayProvider).
105106

106107
_note: Note: Default API keys
107108
In the event of the //apiKey// not being present in the constructor, a shared ApplicationID will be provided,
108-
which has the capacity of sending up to 1 million requests per day (41,750 per hour).
109+
which has the capacity of sending up to 10 million requests per day (417,500 per hour) for Ethereum Mainnet,
110+
for Ropsten, Rinkeby and G&ouml;rli there's a shared capacity of 1 million requests per day each (41,750 per hour).
109111

110112
For production applications it is highly recommended to register your application on the
111113
[Pocket Gateway](link-pocket-gateway) for your own API key.
112114

113115
_definition: **Supported Networks**
114116

115-
- Homestead (Mainnet Full nodes (Archival Support coming soon))
117+
- Homestead (Mainnet Full nodes (non-Archival Nodes))
118+
- Ropsten (proof-of-work testnet)
119+
- Rinkeby (proof-of-authority testnet)
120+
- G&ouml;rli (clique testnet)
116121

117122
_code: Pocket Gateway Examples @lang<javascript>
118123

@@ -122,6 +127,8 @@ const applicationId = "...";
122127
const applicationSecretKey = "...";
123128
const applicationOrigin = "...";
124129
const applicationUserAgent = "...";
130+
// Endpoint Type can be either application or loadbalancer
131+
const endpointType = "...";
125132
// </hide>
126133

127134
// Connect to mainnet (homestead)
@@ -136,7 +143,8 @@ provider = new PocketGatewayProvider("homestead", {
136143
applicationId: applicationId,
137144
applicationSecretKey: applicationSecretKey,
138145
applicationOrigin: applicationOrigin,
139-
applicationUserAgent: applicationUserAgent
146+
applicationUserAgent: applicationUserAgent,
147+
endpointType: endpointType
140148
});
141149

142150
_subsection: InfuraProvider @<InfuraProvider> @INHERIT<[[UrlJsonRpcProvider]]> @src<providers:class.InfuraProvider>

package-lock.json

Lines changed: 299 additions & 354 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/lib/bin/ethers-asm.js

100644100755
File mode changed.

packages/cli/lib/bin/ethers-ens.js

100644100755
File mode changed.

packages/cli/lib/bin/ethers-ts.js

100644100755
File mode changed.

packages/cli/lib/bin/ethers.js

100644100755
File mode changed.

packages/ethers/dist/ethers.esm.js

Lines changed: 187 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16833,6 +16833,12 @@ function ethDefaultProvider(network) {
1683316833
}
1683416834
catch (error) { }
1683516835
}
16836+
if (providers.PocketGatewayProvider) {
16837+
try {
16838+
providerList.push(new providers.PocketGatewayProvider(network, options.pocket_gateway));
16839+
}
16840+
catch (error) { }
16841+
}
1683616842
if (providers.CloudflareProvider) {
1683716843
try {
1683816844
providerList.push(new providers.CloudflareProvider(network));
@@ -21428,62 +21434,6 @@ class NodesmithProvider extends UrlJsonRpcProvider {
2142821434

2142921435
"use strict";
2143021436
const logger$D = new Logger(version$m);
21431-
const defaultApplicationId = "5f7f8547b90218002e9ce9dd";
21432-
class PocketProvider extends UrlJsonRpcProvider {
21433-
static getApiKey(apiKey) {
21434-
const apiKeyObj = {
21435-
applicationId: defaultApplicationId,
21436-
applicationSecretKey: null
21437-
};
21438-
if (apiKey == null) {
21439-
return apiKeyObj;
21440-
}
21441-
// Parse applicationId and applicationSecretKey
21442-
if (typeof (apiKey) === "string") {
21443-
apiKeyObj.applicationId = apiKey;
21444-
}
21445-
else if (apiKey.applicationSecretKey != null) {
21446-
logger$D.assertArgument((typeof (apiKey.applicationId) === "string"), "applicationSecretKey requires an applicationId", "applicationId", apiKey.applicationId);
21447-
logger$D.assertArgument((typeof (apiKey.applicationSecretKey) === "string"), "invalid applicationSecretKey", "applicationSecretKey", "[REDACTED]");
21448-
apiKeyObj.applicationId = apiKey.applicationId;
21449-
apiKeyObj.applicationSecretKey = apiKey.applicationSecretKey;
21450-
}
21451-
else if (apiKey.applicationId) {
21452-
apiKeyObj.applicationId = apiKey.applicationId;
21453-
}
21454-
return apiKeyObj;
21455-
}
21456-
static getUrl(network, apiKey) {
21457-
let host = null;
21458-
switch (network ? network.name : "unknown") {
21459-
case "homestead":
21460-
host = "eth-mainnet.gateway.pokt.network";
21461-
break;
21462-
default:
21463-
logger$D.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
21464-
argument: "network",
21465-
value: network
21466-
});
21467-
}
21468-
const connection = {
21469-
url: (`https:/\/${host}/v1/${apiKey.applicationId}`),
21470-
};
21471-
// Initialize empty headers
21472-
connection.headers = {};
21473-
// Apply application secret key
21474-
if (apiKey.applicationSecretKey != null) {
21475-
connection.user = "";
21476-
connection.password = apiKey.applicationSecretKey;
21477-
}
21478-
return connection;
21479-
}
21480-
isCommunityResource() {
21481-
return (this.applicationId === defaultApplicationId);
21482-
}
21483-
}
21484-
21485-
"use strict";
21486-
const logger$E = new Logger(version$m);
2148721437
let _nextId = 1;
2148821438
function buildWeb3LegacyFetcher(provider, sendFunc) {
2148921439
return function (method, params) {
@@ -21531,9 +21481,9 @@ function buildEip1193Fetcher(provider) {
2153121481
}
2153221482
class Web3Provider extends JsonRpcProvider {
2153321483
constructor(provider, network) {
21534-
logger$E.checkNew(new.target, Web3Provider);
21484+
logger$D.checkNew(new.target, Web3Provider);
2153521485
if (provider == null) {
21536-
logger$E.throwArgumentError("missing provider", "provider", provider);
21486+
logger$D.throwArgumentError("missing provider", "provider", provider);
2153721487
}
2153821488
let path = null;
2153921489
let jsonRpcFetchFunc = null;
@@ -21561,7 +21511,7 @@ class Web3Provider extends JsonRpcProvider {
2156121511
jsonRpcFetchFunc = buildWeb3LegacyFetcher(provider, provider.send.bind(provider));
2156221512
}
2156321513
else {
21564-
logger$E.throwArgumentError("unsupported provider", "provider", provider);
21514+
logger$D.throwArgumentError("unsupported provider", "provider", provider);
2156521515
}
2156621516
if (!path) {
2156721517
path = "unknown:";
@@ -21576,6 +21526,182 @@ class Web3Provider extends JsonRpcProvider {
2157621526
}
2157721527
}
2157821528

21529+
"use strict";
21530+
const logger$E = new Logger(version$m);
21531+
const defaultApplicationId = "defaultApp";
21532+
const defaultLoadBalancer = "defaultLB";
21533+
var EndpointType;
21534+
(function (EndpointType) {
21535+
EndpointType["LoadBalancer"] = "LoadBalancer";
21536+
EndpointType["Application"] = "Application";
21537+
})(EndpointType || (EndpointType = {}));
21538+
class PocketGatewayProvider extends UrlJsonRpcProvider {
21539+
static getApiKey(apiKey) {
21540+
let apiKeyObj = PocketApiKeyObject.build(apiKey);
21541+
return apiKeyObj;
21542+
}
21543+
static getUrl(network, apiKey) {
21544+
let host = null;
21545+
switch (network ? network.name : "unknown") {
21546+
case "homestead":
21547+
host = "eth-mainnet.gateway.pokt.network";
21548+
break;
21549+
case "mainnet":
21550+
host = "eth-mainnet.gateway.pokt.network";
21551+
break;
21552+
case "ropsten":
21553+
host = "eth-ropsten.gateway.pokt.network";
21554+
break;
21555+
case "goerli":
21556+
host = "eth-ropsten.gateway.pokt.network";
21557+
break;
21558+
case "rinkeby":
21559+
host = "eth-rinkeby.gateway.pokt.network";
21560+
break;
21561+
default:
21562+
logger$E.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
21563+
argument: "network",
21564+
value: network
21565+
});
21566+
}
21567+
const connection = {
21568+
url: PocketApiKeyObject.getUrl(apiKey, host),
21569+
};
21570+
// Initialize empty headers
21571+
connection.headers = {};
21572+
// Apply application secret key
21573+
if (apiKey.applicationSecretKey != null) {
21574+
connection.user = "";
21575+
connection.password = apiKey.applicationSecretKey;
21576+
}
21577+
return connection;
21578+
}
21579+
isCommunityResource() {
21580+
if (typeof (this.apiKey) === "string") {
21581+
return (this.apiKey === defaultApplicationId || this.apiKey === defaultLoadBalancer);
21582+
}
21583+
else if (typeof (this.apiKey) === "object") {
21584+
return (this.apiKey.applicationId === defaultApplicationId || this.apiKey.applicationId === defaultLoadBalancer);
21585+
}
21586+
return true;
21587+
}
21588+
}
21589+
class PocketApiKeyObject {
21590+
constructor() {
21591+
this.applicationId = defaultLoadBalancer;
21592+
this.endpointType = EndpointType.LoadBalancer;
21593+
this.applicationSecretKey = null;
21594+
this.applicationOrigin = null;
21595+
this.applicationUserAgent = null;
21596+
}
21597+
static build(apiKey) {
21598+
if (apiKey == null)
21599+
return new PocketApiKeyObject();
21600+
var apiKeyObj = new PocketApiKeyObject();
21601+
// Parse Origin
21602+
if (typeof (apiKey.applicationOrigin) === "string") {
21603+
apiKeyObj.applicationOrigin = apiKey.applicationOrigin;
21604+
}
21605+
// Parse User Agent
21606+
if (typeof (apiKey.applicationUserAgent) === "string") {
21607+
apiKeyObj.applicationUserAgent = apiKey.applicationUserAgent;
21608+
}
21609+
if (typeof (apiKey.endpointType) === "string") {
21610+
switch (apiKey.endpointType.toLowerCase()) {
21611+
case "application":
21612+
apiKeyObj.endpointType = EndpointType.Application;
21613+
apiKeyObj.applicationId = defaultApplicationId;
21614+
break;
21615+
default:
21616+
apiKeyObj.endpointType = EndpointType.LoadBalancer;
21617+
apiKeyObj.applicationId = defaultLoadBalancer;
21618+
break;
21619+
}
21620+
}
21621+
switch (true) {
21622+
case typeof (apiKey) === "string":
21623+
apiKeyObj.applicationId = apiKey;
21624+
break;
21625+
case apiKey.applicationSecretKey != null:
21626+
logger$E.assertArgument((typeof (apiKey.applicationId) === "string"), "applicationSecretKey requires an applicationId", "applicationId", apiKey.applicationId);
21627+
logger$E.assertArgument((typeof (apiKey.applicationSecretKey) === "string"), "invalid applicationSecretKey", "applicationSecretKey", "[*********]");
21628+
apiKeyObj.applicationId = apiKey.applicationId;
21629+
apiKeyObj.applicationSecretKey = apiKey.applicationSecretKey;
21630+
break;
21631+
case apiKey !== null && typeof (apiKey.applicationId) === "string":
21632+
apiKeyObj.applicationId = apiKey.applicationId;
21633+
break;
21634+
}
21635+
return apiKeyObj;
21636+
}
21637+
static getDefaultAppForHost(host) {
21638+
let defaultAppId = null;
21639+
switch (host) {
21640+
case "eth-mainnet.gateway.pokt.network":
21641+
defaultAppId = "6004b7060aea5b606775f4d9";
21642+
break;
21643+
case "eth-ropsten.gateway.pokt.network":
21644+
defaultAppId = "6004b9aa0aea5b606775f4de";
21645+
break;
21646+
case "eth-goerli.gateway.pokt.network":
21647+
defaultAppId = "6004b9e30aea5b606775f4df";
21648+
break;
21649+
case "eth-rinkeby.gateway.pokt.network":
21650+
defaultAppId = "6004ba310aea5b606775f4e0";
21651+
break;
21652+
default:
21653+
logger$E.throwError("unsupported host for default app", Logger.errors.INVALID_ARGUMENT, {
21654+
argument: "host",
21655+
value: host
21656+
});
21657+
}
21658+
return defaultAppId;
21659+
}
21660+
static getDefaultLoadBalancerForHost(host) {
21661+
let defaultLbId = null;
21662+
switch (host) {
21663+
case "eth-mainnet.gateway.pokt.network":
21664+
defaultLbId = "6004bcd10040261633ade990";
21665+
break;
21666+
case "eth-ropsten.gateway.pokt.network":
21667+
defaultLbId = "6004bd4d0040261633ade991";
21668+
break;
21669+
case "eth-goerli.gateway.pokt.network":
21670+
defaultLbId = "6004bd860040261633ade992";
21671+
break;
21672+
case "eth-rinkeby.gateway.pokt.network":
21673+
defaultLbId = "6004bda20040261633ade994";
21674+
break;
21675+
default:
21676+
logger$E.throwError("unsupported host for default app", Logger.errors.INVALID_ARGUMENT, {
21677+
argument: "host",
21678+
value: host
21679+
});
21680+
}
21681+
return defaultLbId;
21682+
}
21683+
static getUrl(apiKey, host) {
21684+
var appId = null;
21685+
if (apiKey.applicationId === defaultLoadBalancer) {
21686+
appId = PocketApiKeyObject.getDefaultLoadBalancerForHost(host);
21687+
}
21688+
else {
21689+
appId = apiKey.applicationId;
21690+
}
21691+
var url = ("https:/" + "/" + host + "/v1/lb/" + appId);
21692+
if (typeof (apiKey.endpointType) === "string" && apiKey.endpointType.toLowerCase() === "application") {
21693+
if (appId === defaultApplicationId) {
21694+
appId = PocketApiKeyObject.getDefaultAppForHost(host);
21695+
}
21696+
else {
21697+
appId = apiKey.applicationId;
21698+
}
21699+
url = ("https:/" + "/" + host + "/v1/" + appId);
21700+
}
21701+
return url;
21702+
}
21703+
}
21704+
2157921705
"use strict";
2158021706
const logger$F = new Logger(version$m);
2158121707
////////////////////////
@@ -21615,8 +21741,8 @@ function getDefaultProvider(network, options) {
2161521741
InfuraProvider,
2161621742
JsonRpcProvider,
2161721743
NodesmithProvider,
21618-
PocketProvider,
2161921744
Web3Provider,
21745+
PocketGatewayProvider,
2162021746
IpcProvider,
2162121747
}, options);
2162221748
}
@@ -21636,10 +21762,10 @@ var index$3 = /*#__PURE__*/Object.freeze({
2163621762
InfuraWebSocketProvider: InfuraWebSocketProvider,
2163721763
JsonRpcProvider: JsonRpcProvider,
2163821764
NodesmithProvider: NodesmithProvider,
21639-
PocketProvider: PocketProvider,
2164021765
StaticJsonRpcProvider: StaticJsonRpcProvider,
2164121766
Web3Provider: Web3Provider,
2164221767
WebSocketProvider: WebSocketProvider,
21768+
PocketGatewayProvider: PocketGatewayProvider,
2164321769
IpcProvider: IpcProvider,
2164421770
JsonRpcSigner: JsonRpcSigner,
2164521771
getDefaultProvider: getDefaultProvider,

packages/ethers/dist/ethers.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ethers/dist/ethers.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ethers/dist/ethers.esm.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)