@qevm/providers 1.0.1

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.
Files changed (114) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +78 -0
  3. package/lib/_version.d.ts +2 -0
  4. package/lib/_version.d.ts.map +1 -0
  5. package/lib/_version.js +5 -0
  6. package/lib/_version.js.map +1 -0
  7. package/lib/alchemy-provider.d.ts +17 -0
  8. package/lib/alchemy-provider.d.ts.map +1 -0
  9. package/lib/alchemy-provider.js +112 -0
  10. package/lib/alchemy-provider.js.map +1 -0
  11. package/lib/ankr-provider.d.ts +10 -0
  12. package/lib/ankr-provider.d.ts.map +1 -0
  13. package/lib/ankr-provider.js +79 -0
  14. package/lib/ankr-provider.js.map +1 -0
  15. package/lib/base-provider.d.ts +156 -0
  16. package/lib/base-provider.d.ts.map +1 -0
  17. package/lib/base-provider.js +2585 -0
  18. package/lib/base-provider.js.map +1 -0
  19. package/lib/browser-ipc-provider.d.ts +3 -0
  20. package/lib/browser-ipc-provider.d.ts.map +1 -0
  21. package/lib/browser-ipc-provider.js +6 -0
  22. package/lib/browser-ipc-provider.js.map +1 -0
  23. package/lib/browser-net.d.ts +2 -0
  24. package/lib/browser-net.d.ts.map +1 -0
  25. package/lib/browser-net.js +6 -0
  26. package/lib/browser-net.js.map +1 -0
  27. package/lib/browser-ws.d.ts +3 -0
  28. package/lib/browser-ws.d.ts.map +1 -0
  29. package/lib/browser-ws.js +22 -0
  30. package/lib/browser-ws.js.map +1 -0
  31. package/lib/cloudflare-provider.d.ts +8 -0
  32. package/lib/cloudflare-provider.d.ts.map +1 -0
  33. package/lib/cloudflare-provider.js +100 -0
  34. package/lib/cloudflare-provider.js.map +1 -0
  35. package/lib/etherscan-provider.d.ts +18 -0
  36. package/lib/etherscan-provider.d.ts.map +1 -0
  37. package/lib/etherscan-provider.js +528 -0
  38. package/lib/etherscan-provider.js.map +1 -0
  39. package/lib/fallback-provider.d.ts +20 -0
  40. package/lib/fallback-provider.d.ts.map +1 -0
  41. package/lib/fallback-provider.js +699 -0
  42. package/lib/fallback-provider.js.map +1 -0
  43. package/lib/formatter.d.ts +60 -0
  44. package/lib/formatter.d.ts.map +1 -0
  45. package/lib/formatter.js +452 -0
  46. package/lib/formatter.js.map +1 -0
  47. package/lib/index.d.ts +23 -0
  48. package/lib/index.d.ts.map +1 -0
  49. package/lib/index.js +97 -0
  50. package/lib/index.js.map +1 -0
  51. package/lib/infura-provider.d.ts +21 -0
  52. package/lib/infura-provider.d.ts.map +1 -0
  53. package/lib/infura-provider.js +141 -0
  54. package/lib/infura-provider.js.map +1 -0
  55. package/lib/ipc-provider.d.ts +8 -0
  56. package/lib/ipc-provider.d.ts.map +1 -0
  57. package/lib/ipc-provider.js +77 -0
  58. package/lib/ipc-provider.js.map +1 -0
  59. package/lib/json-rpc-batch-provider.d.ts +17 -0
  60. package/lib/json-rpc-batch-provider.d.ts.map +1 -0
  61. package/lib/json-rpc-batch-provider.js +99 -0
  62. package/lib/json-rpc-batch-provider.js.map +1 -0
  63. package/lib/json-rpc-provider.d.ts +54 -0
  64. package/lib/json-rpc-provider.d.ts.map +1 -0
  65. package/lib/json-rpc-provider.js +855 -0
  66. package/lib/json-rpc-provider.js.map +1 -0
  67. package/lib/nodesmith-provider.d.ts +7 -0
  68. package/lib/nodesmith-provider.d.ts.map +1 -0
  69. package/lib/nodesmith-provider.js +64 -0
  70. package/lib/nodesmith-provider.js.map +1 -0
  71. package/lib/pocket-provider.d.ts +12 -0
  72. package/lib/pocket-provider.d.ts.map +1 -0
  73. package/lib/pocket-provider.js +98 -0
  74. package/lib/pocket-provider.js.map +1 -0
  75. package/lib/url-json-rpc-provider.d.ts +18 -0
  76. package/lib/url-json-rpc-provider.d.ts.map +1 -0
  77. package/lib/url-json-rpc-provider.js +153 -0
  78. package/lib/url-json-rpc-provider.js.map +1 -0
  79. package/lib/web3-provider.d.ts +28 -0
  80. package/lib/web3-provider.d.ts.map +1 -0
  81. package/lib/web3-provider.js +155 -0
  82. package/lib/web3-provider.js.map +1 -0
  83. package/lib/websocket-provider.d.ts +48 -0
  84. package/lib/websocket-provider.d.ts.map +1 -0
  85. package/lib/websocket-provider.js +384 -0
  86. package/lib/websocket-provider.js.map +1 -0
  87. package/lib/ws.d.ts +3 -0
  88. package/lib/ws.d.ts.map +1 -0
  89. package/lib/ws.js +9 -0
  90. package/lib/ws.js.map +1 -0
  91. package/package.json +57 -0
  92. package/src.ts/_version.ts +1 -0
  93. package/src.ts/alchemy-provider.ts +101 -0
  94. package/src.ts/ankr-provider.ts +68 -0
  95. package/src.ts/base-provider.ts +2216 -0
  96. package/src.ts/browser-ipc-provider.ts +7 -0
  97. package/src.ts/browser-net.ts +3 -0
  98. package/src.ts/browser-ws.ts +21 -0
  99. package/src.ts/cloudflare-provider.ts +42 -0
  100. package/src.ts/etherscan-provider.ts +454 -0
  101. package/src.ts/fallback-provider.ts +654 -0
  102. package/src.ts/formatter.ts +522 -0
  103. package/src.ts/index.ts +178 -0
  104. package/src.ts/infura-provider.ts +143 -0
  105. package/src.ts/ipc-provider.ts +72 -0
  106. package/src.ts/json-rpc-batch-provider.ts +97 -0
  107. package/src.ts/json-rpc-provider.ts +742 -0
  108. package/src.ts/nodesmith-provider.ts +50 -0
  109. package/src.ts/pocket-provider.ts +93 -0
  110. package/src.ts/url-json-rpc-provider.ts +106 -0
  111. package/src.ts/web3-provider.ts +169 -0
  112. package/src.ts/websocket-provider.ts +350 -0
  113. package/src.ts/ws.ts +3 -0
  114. package/thirdparty.d.ts +10 -0
@@ -0,0 +1,522 @@
1
+ "use strict";
2
+
3
+ import { Block, TransactionReceipt, TransactionResponse } from "@qevm/abstract-provider";
4
+ import { getAddress, getContractAddress } from "@qevm/address";
5
+ import { BigNumber } from "@ethersproject/bignumber";
6
+ import { hexDataLength, hexDataSlice, hexValue, hexZeroPad, isHexString } from "@qevm/bytes";
7
+ import { AddressZero } from "@ethersproject/constants";
8
+ import { shallowCopy } from "@ethersproject/properties";
9
+ import { AccessList, accessListify, parse as parseTransaction } from "@qevm/transactions";
10
+
11
+ import { Logger } from "@ethersproject/logger";
12
+ import { version } from "./_version";
13
+ const logger = new Logger(version);
14
+
15
+ export type FormatFunc = (value: any) => any;
16
+
17
+ export type FormatFuncs = { [ key: string ]: FormatFunc };
18
+
19
+ export type Formats = {
20
+ transaction: FormatFuncs,
21
+ transactionRequest: FormatFuncs,
22
+ receipt: FormatFuncs,
23
+ receiptLog: FormatFuncs,
24
+ block: FormatFuncs,
25
+ blockWithTransactions: FormatFuncs,
26
+ filter: FormatFuncs,
27
+ filterLog: FormatFuncs,
28
+ };
29
+
30
+ export class Formatter {
31
+ readonly formats: Formats;
32
+
33
+ constructor() {
34
+ this.formats = this.getDefaultFormats();
35
+ }
36
+
37
+ getDefaultFormats(): Formats {
38
+ const formats: Formats = <Formats>({ });
39
+
40
+ const address = this.address.bind(this);
41
+ const bigNumber = this.bigNumber.bind(this);
42
+ const blockTag = this.blockTag.bind(this);
43
+ const data = this.data.bind(this);
44
+ const hash = this.hash.bind(this);
45
+ const hex = this.hex.bind(this);
46
+ const number = this.number.bind(this);
47
+ const type = this.type.bind(this);
48
+
49
+ const strictData = (v: any) => { return this.data(v, true); };
50
+
51
+ formats.transaction = {
52
+ hash: hash,
53
+
54
+ type: type,
55
+ accessList: Formatter.allowNull(this.accessList.bind(this), null),
56
+
57
+ blockHash: Formatter.allowNull(hash, null),
58
+ blockNumber: Formatter.allowNull(number, null),
59
+ transactionIndex: Formatter.allowNull(number, null),
60
+
61
+ confirmations: Formatter.allowNull(number, null),
62
+
63
+ from: address,
64
+
65
+ // either (gasPrice) or (maxPriorityFeePerGas + maxFeePerGas)
66
+ // must be set
67
+ gasPrice: Formatter.allowNull(bigNumber),
68
+ maxPriorityFeePerGas: Formatter.allowNull(bigNumber),
69
+ maxFeePerGas: Formatter.allowNull(bigNumber),
70
+
71
+ gasLimit: bigNumber,
72
+ to: Formatter.allowNull(address, null),
73
+ value: bigNumber,
74
+ nonce: number,
75
+ data: data,
76
+
77
+ r: Formatter.allowNull(this.uint256),
78
+ s: Formatter.allowNull(this.uint256),
79
+ v: Formatter.allowNull(number),
80
+
81
+ creates: Formatter.allowNull(address, null),
82
+
83
+ raw: Formatter.allowNull(data),
84
+ };
85
+
86
+ formats.transactionRequest = {
87
+ from: Formatter.allowNull(address),
88
+ nonce: Formatter.allowNull(number),
89
+ gasLimit: Formatter.allowNull(bigNumber),
90
+ gasPrice: Formatter.allowNull(bigNumber),
91
+ maxPriorityFeePerGas: Formatter.allowNull(bigNumber),
92
+ maxFeePerGas: Formatter.allowNull(bigNumber),
93
+ to: Formatter.allowNull(address),
94
+ value: Formatter.allowNull(bigNumber),
95
+ data: Formatter.allowNull(strictData),
96
+ type: Formatter.allowNull(number),
97
+ accessList: Formatter.allowNull(this.accessList.bind(this), null),
98
+ };
99
+
100
+ formats.receiptLog = {
101
+ transactionIndex: number,
102
+ blockNumber: number,
103
+ transactionHash: hash,
104
+ address: address,
105
+ topics: Formatter.arrayOf(hash),
106
+ data: data,
107
+ logIndex: number,
108
+ blockHash: hash,
109
+ };
110
+
111
+ formats.receipt = {
112
+ to: Formatter.allowNull(this.address, null),
113
+ from: Formatter.allowNull(this.address, null),
114
+ contractAddress: Formatter.allowNull(address, null),
115
+ transactionIndex: number,
116
+ // should be allowNull(hash), but broken-EIP-658 support is handled in receipt
117
+ root: Formatter.allowNull(hex),
118
+ gasUsed: bigNumber,
119
+ logsBloom: Formatter.allowNull(data),// @TODO: should this be data?
120
+ blockHash: hash,
121
+ transactionHash: hash,
122
+ logs: Formatter.arrayOf(this.receiptLog.bind(this)),
123
+ blockNumber: number,
124
+ confirmations: Formatter.allowNull(number, null),
125
+ cumulativeGasUsed: bigNumber,
126
+ effectiveGasPrice: Formatter.allowNull(bigNumber),
127
+ status: Formatter.allowNull(number),
128
+ type: type
129
+ };
130
+
131
+ formats.block = {
132
+ hash: Formatter.allowNull(hash),
133
+ parentHash: hash,
134
+ number: number,
135
+
136
+ timestamp: number,
137
+ nonce: Formatter.allowNull(hex),
138
+ difficulty: this.difficulty.bind(this),
139
+
140
+ gasLimit: bigNumber,
141
+ gasUsed: bigNumber,
142
+
143
+ miner: Formatter.allowNull(address),
144
+ extraData: data,
145
+
146
+ transactions: Formatter.allowNull(Formatter.arrayOf(hash)),
147
+
148
+ baseFeePerGas: Formatter.allowNull(bigNumber)
149
+ };
150
+
151
+ formats.blockWithTransactions = shallowCopy(formats.block);
152
+ formats.blockWithTransactions.transactions = Formatter.allowNull(Formatter.arrayOf(this.transactionResponse.bind(this)));
153
+
154
+ formats.filter = {
155
+ fromBlock: Formatter.allowNull(blockTag, undefined),
156
+ toBlock: Formatter.allowNull(blockTag, undefined),
157
+ blockHash: Formatter.allowNull(hash, undefined),
158
+ address: Formatter.allowNull(address, undefined),
159
+ topics: Formatter.allowNull(this.topics.bind(this), undefined),
160
+ };
161
+
162
+ formats.filterLog = {
163
+ blockNumber: Formatter.allowNull(number),
164
+ blockHash: Formatter.allowNull(hash),
165
+ transactionIndex: number,
166
+
167
+ removed: Formatter.allowNull(this.boolean.bind(this)),
168
+
169
+ address: address,
170
+ data: Formatter.allowFalsish(data, "0x"),
171
+
172
+ topics: Formatter.arrayOf(hash),
173
+
174
+ transactionHash: hash,
175
+ logIndex: number,
176
+ };
177
+
178
+ return formats;
179
+ }
180
+
181
+ accessList(accessList: Array<any>): AccessList {
182
+ return accessListify(accessList || []);
183
+ }
184
+
185
+ // Requires a BigNumberish that is within the IEEE754 safe integer range; returns a number
186
+ // Strict! Used on input.
187
+ number(number: any): number {
188
+ if (number === "0x") { return 0; }
189
+ return BigNumber.from(number).toNumber();
190
+ }
191
+
192
+ type(number: any): number {
193
+ if (number === "0x" || number == null) { return 0; }
194
+ return BigNumber.from(number).toNumber();
195
+ }
196
+
197
+ // Strict! Used on input.
198
+ bigNumber(value: any): BigNumber {
199
+ return BigNumber.from(value);
200
+ }
201
+
202
+ // Requires a boolean, "true" or "false"; returns a boolean
203
+ boolean(value: any): boolean {
204
+ if (typeof(value) === "boolean") { return value; }
205
+ if (typeof(value) === "string") {
206
+ value = value.toLowerCase();
207
+ if (value === "true") { return true; }
208
+ if (value === "false") { return false; }
209
+ }
210
+ throw new Error("invalid boolean - " + value);
211
+ }
212
+
213
+ hex(value: any, strict?: boolean): string {
214
+ if (typeof(value) === "string") {
215
+ if (!strict && value.substring(0, 2) !== "0x") { value = "0x" + value; }
216
+ if (isHexString(value)) {
217
+ return value.toLowerCase();
218
+ }
219
+ }
220
+ return logger.throwArgumentError("invalid hash", "value", value);
221
+ }
222
+
223
+ data(value: any, strict?: boolean): string {
224
+ const result = this.hex(value, strict);
225
+ if ((result.length % 2) !== 0) {
226
+ throw new Error("invalid data; odd-length - " + value);
227
+ }
228
+ return result;
229
+ }
230
+
231
+ // Requires an address
232
+ // Strict! Used on input.
233
+ address(value: any): string {
234
+ return getAddress(value);
235
+ }
236
+
237
+ callAddress(value: any): string {
238
+ if (!isHexString(value, 32)) { return null; }
239
+ const address = getAddress(hexDataSlice(value, 12));
240
+ return (address === AddressZero) ? null: address;
241
+ }
242
+
243
+ contractAddress(value: any): string {
244
+ return getContractAddress(value);
245
+ }
246
+
247
+ // Strict! Used on input.
248
+ blockTag(blockTag: any): string {
249
+ if (blockTag == null) { return "latest"; }
250
+
251
+ if (blockTag === "earliest") { return "0x0"; }
252
+
253
+ switch (blockTag) {
254
+ case "earliest": return "0x0";
255
+ case "latest": case "pending": case "safe": case "finalized":
256
+ return blockTag;
257
+ }
258
+
259
+ if (typeof(blockTag) === "number" || isHexString(blockTag)) {
260
+ return hexValue(<number | string>blockTag);
261
+ }
262
+
263
+ throw new Error("invalid blockTag");
264
+ }
265
+
266
+ // Requires a hash, optionally requires 0x prefix; returns prefixed lowercase hash.
267
+ hash(value: any, strict?: boolean): string {
268
+ const result = this.hex(value, strict);
269
+ if (hexDataLength(result) !== 32) {
270
+ return logger.throwArgumentError("invalid hash", "value", value);
271
+ }
272
+ return result;
273
+ }
274
+
275
+ // Returns the difficulty as a number, or if too large (i.e. PoA network) null
276
+ difficulty(value: any): number {
277
+ if (value == null) { return null; }
278
+
279
+ const v = BigNumber.from(value);
280
+
281
+ try {
282
+ return v.toNumber();
283
+ } catch (error) { }
284
+
285
+ return null;
286
+ }
287
+
288
+ uint256(value: any): string {
289
+ if (!isHexString(value)) {
290
+ throw new Error("invalid uint256");
291
+ }
292
+ return hexZeroPad(value, 32);
293
+ }
294
+
295
+ _block(value: any, format: any): Block {
296
+ if (value.author != null && value.miner == null) {
297
+ value.miner = value.author;
298
+ }
299
+ // The difficulty may need to come from _difficulty in recursed blocks
300
+ const difficulty = (value._difficulty != null) ? value._difficulty: value.difficulty;
301
+ const result = Formatter.check(format, value);
302
+ result._difficulty = ((difficulty == null) ? null: BigNumber.from(difficulty));
303
+ return result;
304
+ }
305
+
306
+ block(value: any): Block {
307
+ return this._block(value, this.formats.block);
308
+ }
309
+
310
+ blockWithTransactions(value: any): Block {
311
+ return this._block(value, this.formats.blockWithTransactions);
312
+ }
313
+
314
+ // Strict! Used on input.
315
+ transactionRequest(value: any): any {
316
+ return Formatter.check(this.formats.transactionRequest, value);
317
+ }
318
+
319
+ transactionResponse(transaction: any): TransactionResponse {
320
+
321
+ // Rename gas to gasLimit
322
+ if (transaction.gas != null && transaction.gasLimit == null) {
323
+ transaction.gasLimit = transaction.gas;
324
+ }
325
+
326
+ // Some clients (TestRPC) do strange things like return 0x0 for the
327
+ // 0 address; correct this to be a real address
328
+ if (transaction.to && BigNumber.from(transaction.to).isZero()) {
329
+ transaction.to = "0x0000000000000000000000000000000000000000";
330
+ }
331
+
332
+ // Rename input to data
333
+ if (transaction.input != null && transaction.data == null) {
334
+ transaction.data = transaction.input;
335
+ }
336
+
337
+ // If to and creates are empty, populate the creates from the transaction
338
+ if (transaction.to == null && transaction.creates == null) {
339
+ transaction.creates = this.contractAddress(transaction);
340
+ }
341
+
342
+ if ((transaction.type === 1 || transaction.type === 2)&& transaction.accessList == null) {
343
+ transaction.accessList = [ ];
344
+ }
345
+
346
+ const result: TransactionResponse = Formatter.check(this.formats.transaction, transaction);
347
+
348
+ if (transaction.chainId != null) {
349
+ let chainId = transaction.chainId;
350
+
351
+ if (isHexString(chainId)) {
352
+ chainId = BigNumber.from(chainId).toNumber();
353
+ }
354
+
355
+ result.chainId = chainId;
356
+
357
+ } else {
358
+ let chainId = transaction.networkId;
359
+
360
+ // geth-etc returns chainId
361
+ if (chainId == null) {
362
+ chainId = transaction.chainId;
363
+ }
364
+
365
+ if (isHexString(chainId)) {
366
+ chainId = BigNumber.from(chainId).toNumber();
367
+ }
368
+
369
+ if (typeof(chainId) !== "number") {
370
+ chainId = 0;
371
+ }
372
+
373
+ if (typeof(chainId) !== "number") { chainId = 0; }
374
+
375
+ result.chainId = chainId;
376
+ }
377
+
378
+ // 0x0000... should actually be null
379
+ if (result.blockHash && result.blockHash.replace(/0/g, "") === "x") {
380
+ result.blockHash = null;
381
+ }
382
+
383
+ return result;
384
+ }
385
+
386
+ transaction(value: any): any {
387
+ return parseTransaction(value);
388
+ }
389
+
390
+ receiptLog(value: any): any {
391
+ return Formatter.check(this.formats.receiptLog, value);
392
+ }
393
+
394
+ receipt(value: any): TransactionReceipt {
395
+ const result: TransactionReceipt = Formatter.check(this.formats.receipt, value);
396
+
397
+ // RSK incorrectly implemented EIP-658, so we munge things a bit here for it
398
+ if (result.root != null) {
399
+ if (result.root.length <= 4) {
400
+ // Could be 0x00, 0x0, 0x01 or 0x1
401
+ const value = BigNumber.from(result.root).toNumber();
402
+ if (value === 0 || value === 1) {
403
+ // Make sure if both are specified, they match
404
+ if (result.status != null && (result.status !== value)) {
405
+ logger.throwArgumentError("alt-root-status/status mismatch", "value", { root: result.root, status: result.status });
406
+ }
407
+ result.status = value;
408
+ delete result.root;
409
+ } else {
410
+ logger.throwArgumentError("invalid alt-root-status", "value.root", result.root);
411
+ }
412
+ } else if (result.root.length !== 66) {
413
+ // Must be a valid bytes32
414
+ logger.throwArgumentError("invalid root hash", "value.root", result.root);
415
+ }
416
+ }
417
+
418
+ if (result.status != null) {
419
+ result.byzantium = true;
420
+ }
421
+
422
+ return result;
423
+ }
424
+
425
+ topics(value: any): any {
426
+ if (Array.isArray(value)) {
427
+ return value.map((v) => this.topics(v));
428
+
429
+ } else if (value != null) {
430
+ return this.hash(value, true);
431
+ }
432
+
433
+ return null;
434
+ }
435
+
436
+ filter(value: any): any {
437
+ return Formatter.check(this.formats.filter, value);
438
+ }
439
+
440
+ filterLog(value: any): any {
441
+ return Formatter.check(this.formats.filterLog, value);
442
+ }
443
+
444
+ static check(format: { [ name: string ]: FormatFunc }, object: any): any {
445
+ const result: any = {};
446
+ for (const key in format) {
447
+ try {
448
+ const value = format[key](object[key]);
449
+ if (value !== undefined) { result[key] = value; }
450
+ } catch (error) {
451
+ error.checkKey = key;
452
+ error.checkValue = object[key];
453
+ throw error;
454
+ }
455
+ }
456
+ return result;
457
+ }
458
+
459
+ // if value is null-ish, nullValue is returned
460
+ static allowNull(format: FormatFunc, nullValue?: any): FormatFunc {
461
+ return (function(value: any) {
462
+ if (value == null) { return nullValue; }
463
+ return format(value);
464
+ });
465
+ }
466
+
467
+ // If value is false-ish, replaceValue is returned
468
+ static allowFalsish(format: FormatFunc, replaceValue: any): FormatFunc {
469
+ return (function(value: any) {
470
+ if (!value) { return replaceValue; }
471
+ return format(value);
472
+ });
473
+ }
474
+
475
+ // Requires an Array satisfying check
476
+ static arrayOf(format: FormatFunc): FormatFunc {
477
+ return (function(array: any): Array<any> {
478
+ if (!Array.isArray(array)) { throw new Error("not an array"); }
479
+
480
+ const result: any = [];
481
+
482
+ array.forEach(function(value) {
483
+ result.push(format(value));
484
+ });
485
+
486
+ return result;
487
+ });
488
+ }
489
+ }
490
+
491
+ export interface CommunityResourcable {
492
+ isCommunityResource(): boolean;
493
+ }
494
+
495
+ export function isCommunityResourcable(value: any): value is CommunityResourcable {
496
+ return (value && typeof(value.isCommunityResource) === "function");
497
+ }
498
+
499
+ export function isCommunityResource(value: any): boolean {
500
+ return (isCommunityResourcable(value) && value.isCommunityResource());
501
+ }
502
+
503
+ // Show the throttle message only once
504
+ let throttleMessage = false;
505
+ export function showThrottleMessage() {
506
+ if (throttleMessage) { return; }
507
+ throttleMessage = true;
508
+
509
+ console.log("========= NOTICE =========")
510
+ console.log("Request-Rate Exceeded (this message will not be repeated)");
511
+ console.log("");
512
+ console.log("The default API keys for each service are provided as a highly-throttled,");
513
+ console.log("community resource for low-traffic projects and early prototyping.");
514
+ console.log("");
515
+ console.log("While your application will continue to function, we highly recommended");
516
+ console.log("signing up for your own API keys to improve performance, increase your");
517
+ console.log("request rate/limit and enable other perks, such as metrics and advanced APIs.");
518
+ console.log("");
519
+ console.log("For more details: https:/\/docs.ethers.io/api-keys/");
520
+ console.log("==========================");
521
+ }
522
+
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ import {
4
+ Block,
5
+ BlockTag,
6
+ EventType,
7
+ FeeData,
8
+ Filter,
9
+ Log,
10
+ Listener,
11
+ Provider,
12
+ TransactionReceipt,
13
+ TransactionRequest,
14
+ TransactionResponse
15
+ } from "@qevm/abstract-provider";
16
+
17
+ import { getNetwork } from "@ethersproject/networks";
18
+ import { Network, Networkish } from "@ethersproject/networks";
19
+
20
+ import { BaseProvider, EnsProvider, EnsResolver, Resolver } from "./base-provider";
21
+
22
+ import { AlchemyProvider, AlchemyWebSocketProvider } from "./alchemy-provider";
23
+ import { AnkrProvider } from "./ankr-provider";
24
+ import { CloudflareProvider } from "./cloudflare-provider";
25
+ import { EtherscanProvider } from "./etherscan-provider";
26
+ import { FallbackProvider, FallbackProviderConfig } from "./fallback-provider";
27
+ import { IpcProvider } from "./ipc-provider";
28
+ import { InfuraProvider, InfuraWebSocketProvider } from "./infura-provider";
29
+ import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
30
+ import { JsonRpcBatchProvider } from "./json-rpc-batch-provider";
31
+ import { NodesmithProvider } from "./nodesmith-provider";
32
+ import { PocketProvider } from "./pocket-provider";
33
+ import { StaticJsonRpcProvider, UrlJsonRpcProvider } from "./url-json-rpc-provider";
34
+ import { Web3Provider } from "./web3-provider";
35
+ import { WebSocketProvider } from "./websocket-provider";
36
+ import { ExternalProvider, JsonRpcFetchFunc } from "./web3-provider";
37
+
38
+ import { CommunityResourcable, Formatter, isCommunityResourcable, isCommunityResource, showThrottleMessage } from "./formatter";
39
+
40
+ import { Logger } from "@ethersproject/logger";
41
+ import { version } from "./_version";
42
+ const logger = new Logger(version);
43
+
44
+ ////////////////////////
45
+ // Helper Functions
46
+
47
+ function getDefaultProvider(network?: Networkish, options?: any): BaseProvider {
48
+ if (network == null) { network = "homestead"; }
49
+
50
+ // If passed a URL, figure out the right type of provider based on the scheme
51
+ if (typeof(network) === "string") {
52
+ // @TODO: Add support for IpcProvider; maybe if it ends in ".ipc"?
53
+
54
+ // Handle http and ws (and their secure variants)
55
+ const match = network.match(/^(ws|http)s?:/i);
56
+ if (match) {
57
+ switch (match[1].toLowerCase()) {
58
+ case "http": case "https":
59
+ return new JsonRpcProvider(network);
60
+ case "ws": case "wss":
61
+ return new WebSocketProvider(network);
62
+ default:
63
+ logger.throwArgumentError("unsupported URL scheme", "network", network);
64
+ }
65
+ }
66
+ }
67
+
68
+ const n = getNetwork(network);
69
+ if (!n || !n._defaultProvider) {
70
+ logger.throwError("unsupported getDefaultProvider network", Logger.errors.NETWORK_ERROR, {
71
+ operation: "getDefaultProvider",
72
+ network: network
73
+ });
74
+ }
75
+
76
+ return n._defaultProvider({
77
+ FallbackProvider,
78
+
79
+ AlchemyProvider,
80
+ AnkrProvider,
81
+ CloudflareProvider,
82
+ EtherscanProvider,
83
+ InfuraProvider,
84
+ JsonRpcProvider,
85
+ NodesmithProvider,
86
+ PocketProvider,
87
+ Web3Provider,
88
+
89
+ IpcProvider,
90
+ }, options);
91
+ }
92
+
93
+ ////////////////////////
94
+ // Exports
95
+
96
+ export {
97
+
98
+ // Abstract Providers (or Abstract-ish)
99
+ Provider,
100
+ BaseProvider,
101
+
102
+ Resolver,
103
+
104
+ UrlJsonRpcProvider,
105
+
106
+ ///////////////////////
107
+ // Concrete Providers
108
+
109
+ FallbackProvider,
110
+
111
+ AlchemyProvider,
112
+ AlchemyWebSocketProvider,
113
+ AnkrProvider,
114
+ CloudflareProvider,
115
+ EtherscanProvider,
116
+ InfuraProvider,
117
+ InfuraWebSocketProvider,
118
+ JsonRpcProvider,
119
+ JsonRpcBatchProvider,
120
+ NodesmithProvider,
121
+ PocketProvider,
122
+ StaticJsonRpcProvider,
123
+ Web3Provider,
124
+ WebSocketProvider,
125
+
126
+ IpcProvider,
127
+
128
+
129
+ ///////////////////////
130
+ // Signer
131
+
132
+ JsonRpcSigner,
133
+
134
+
135
+ ///////////////////////
136
+ // Functions
137
+
138
+ getDefaultProvider,
139
+ getNetwork,
140
+ isCommunityResource,
141
+ isCommunityResourcable,
142
+ showThrottleMessage,
143
+
144
+
145
+ ///////////////////////
146
+ // Objects
147
+
148
+ Formatter,
149
+
150
+
151
+ ///////////////////////
152
+ // Types
153
+
154
+ Block,
155
+ BlockTag,
156
+ EventType,
157
+ FeeData,
158
+ Filter,
159
+ Log,
160
+ Listener,
161
+ TransactionReceipt,
162
+ TransactionRequest,
163
+ TransactionResponse,
164
+
165
+ ExternalProvider,
166
+ JsonRpcFetchFunc,
167
+
168
+ FallbackProviderConfig,
169
+
170
+ Network,
171
+ Networkish,
172
+
173
+ EnsProvider,
174
+ EnsResolver,
175
+
176
+ CommunityResourcable
177
+ };
178
+