@covalenthq/client-sdk 0.7.6 → 0.8.0
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.
- package/README.md +5 -0
- package/dist/cjs/index.js +815 -181
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +14 -13
- package/dist/cjs/services/BaseService.d.ts +12 -11
- package/dist/cjs/services/CovalentClient.d.ts +5 -3
- package/dist/cjs/services/NftService.d.ts +18 -17
- package/dist/cjs/services/PricingService.d.ts +4 -3
- package/dist/cjs/services/SecurityService.d.ts +5 -4
- package/dist/cjs/services/TransactionService.d.ts +79 -12
- package/dist/cjs/services/XykService.d.ts +226 -15
- package/dist/cjs/util/ApiHelpers.d.ts +2 -1
- package/dist/cjs/util/backoff.d.ts +2 -1
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/cjs/util/types/XykServiceTypes.d.ts +114 -0
- package/dist/es/index.js +815 -181
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +14 -13
- package/dist/es/services/BaseService.d.ts +12 -11
- package/dist/es/services/CovalentClient.d.ts +5 -3
- package/dist/es/services/NftService.d.ts +18 -17
- package/dist/es/services/PricingService.d.ts +4 -3
- package/dist/es/services/SecurityService.d.ts +5 -4
- package/dist/es/services/TransactionService.d.ts +79 -12
- package/dist/es/services/XykService.d.ts +226 -15
- package/dist/es/util/ApiHelpers.d.ts +2 -1
- package/dist/es/util/backoff.d.ts +2 -1
- package/dist/es/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/es/util/types/XykServiceTypes.d.ts +114 -0
- package/dist/esm/index.js +815 -181
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +14 -13
- package/dist/esm/services/BaseService.d.ts +12 -11
- package/dist/esm/services/CovalentClient.d.ts +5 -3
- package/dist/esm/services/NftService.d.ts +18 -17
- package/dist/esm/services/PricingService.d.ts +4 -3
- package/dist/esm/services/SecurityService.d.ts +5 -4
- package/dist/esm/services/TransactionService.d.ts +79 -12
- package/dist/esm/services/XykService.d.ts +226 -15
- package/dist/esm/util/ApiHelpers.d.ts +2 -1
- package/dist/esm/util/backoff.d.ts +2 -1
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/esm/util/types/XykServiceTypes.d.ts +114 -0
- package/dist/services/BalanceService.d.ts +14 -13
- package/dist/services/BalanceService.js +16 -15
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +12 -11
- package/dist/services/BaseService.js +25 -24
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +5 -3
- package/dist/services/CovalentClient.js +17 -17
- package/dist/services/CovalentClient.js.map +1 -1
- package/dist/services/NftService.d.ts +18 -17
- package/dist/services/NftService.js +30 -29
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +4 -3
- package/dist/services/PricingService.js +4 -3
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +5 -4
- package/dist/services/SecurityService.js +6 -5
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +79 -12
- package/dist/services/TransactionService.js +369 -41
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +226 -15
- package/dist/services/XykService.js +335 -34
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +2 -1
- package/dist/util/ApiHelpers.js +3 -3
- package/dist/util/ApiHelpers.js.map +1 -1
- package/dist/util/backoff.d.ts +2 -1
- package/dist/util/backoff.js +3 -3
- package/dist/util/backoff.js.map +1 -1
- package/dist/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/util/types/XykServiceTypes.d.ts +114 -0
- package/package.json +1 -1
|
@@ -218,12 +218,13 @@ class Param {
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
class RecentTransactionsResponse {
|
|
221
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
221
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
222
222
|
this._debug = _debug;
|
|
223
223
|
this._apiKey = _apiKey;
|
|
224
224
|
this._threadCount = _threadCount;
|
|
225
225
|
this._urlParams = _urlParams;
|
|
226
226
|
this._enableRetry = _enableRetry;
|
|
227
|
+
this._source = _source;
|
|
227
228
|
this.address = data.address;
|
|
228
229
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
229
230
|
this.quote_currency = data.quote_currency;
|
|
@@ -258,13 +259,13 @@ class RecentTransactionsResponse {
|
|
|
258
259
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
259
260
|
headers: {
|
|
260
261
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
261
|
-
"X-Requested-With": userAgent
|
|
262
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
262
263
|
}
|
|
263
264
|
}));
|
|
264
265
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
265
266
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
266
267
|
try {
|
|
267
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
268
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
268
269
|
}
|
|
269
270
|
catch (error) {
|
|
270
271
|
success = true;
|
|
@@ -279,7 +280,7 @@ class RecentTransactionsResponse {
|
|
|
279
280
|
else {
|
|
280
281
|
data = await response.json();
|
|
281
282
|
}
|
|
282
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
283
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
283
284
|
checkAndModifyResponse(dataClass);
|
|
284
285
|
success = true;
|
|
285
286
|
return {
|
|
@@ -325,13 +326,13 @@ class RecentTransactionsResponse {
|
|
|
325
326
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
326
327
|
headers: {
|
|
327
328
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
328
|
-
"X-Requested-With": userAgent
|
|
329
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
329
330
|
}
|
|
330
331
|
}));
|
|
331
332
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
332
333
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
333
334
|
try {
|
|
334
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
335
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
335
336
|
}
|
|
336
337
|
catch (error) {
|
|
337
338
|
success = true;
|
|
@@ -346,7 +347,7 @@ class RecentTransactionsResponse {
|
|
|
346
347
|
else {
|
|
347
348
|
data = await response.json();
|
|
348
349
|
}
|
|
349
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
350
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
350
351
|
checkAndModifyResponse(dataClass);
|
|
351
352
|
success = true;
|
|
352
353
|
return {
|
|
@@ -374,6 +375,155 @@ class PaginationLinks {
|
|
|
374
375
|
this.next = data.next;
|
|
375
376
|
}
|
|
376
377
|
}
|
|
378
|
+
class TransactionsBlockPageResponse {
|
|
379
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
380
|
+
this._debug = _debug;
|
|
381
|
+
this._apiKey = _apiKey;
|
|
382
|
+
this._threadCount = _threadCount;
|
|
383
|
+
this._urlParams = _urlParams;
|
|
384
|
+
this._enableRetry = _enableRetry;
|
|
385
|
+
this._source = _source;
|
|
386
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
387
|
+
this.chain_id = data.chain_id;
|
|
388
|
+
this.chain_name = data.chain_name;
|
|
389
|
+
this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
|
|
390
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
|
|
391
|
+
}
|
|
392
|
+
async prev() {
|
|
393
|
+
let success = false;
|
|
394
|
+
let data;
|
|
395
|
+
let response;
|
|
396
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
397
|
+
const LIMIT = pLimit(this._threadCount);
|
|
398
|
+
while (!success) {
|
|
399
|
+
try {
|
|
400
|
+
let startTime;
|
|
401
|
+
if (this._debug) {
|
|
402
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
403
|
+
}
|
|
404
|
+
if (this.links.prev === null) {
|
|
405
|
+
success = true;
|
|
406
|
+
return {
|
|
407
|
+
data: null,
|
|
408
|
+
error: true,
|
|
409
|
+
error_code: 400,
|
|
410
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
414
|
+
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
415
|
+
headers: {
|
|
416
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
417
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
418
|
+
}
|
|
419
|
+
}));
|
|
420
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
421
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
422
|
+
try {
|
|
423
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
success = true;
|
|
427
|
+
return {
|
|
428
|
+
data: null,
|
|
429
|
+
error: true,
|
|
430
|
+
error_code: response.status ?? 429,
|
|
431
|
+
error_message: error.message
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
data = await response.json();
|
|
437
|
+
}
|
|
438
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
439
|
+
checkAndModifyResponse(dataClass);
|
|
440
|
+
success = true;
|
|
441
|
+
return {
|
|
442
|
+
data: dataClass,
|
|
443
|
+
error: data.error,
|
|
444
|
+
error_code: data ? data.error_code : response.status,
|
|
445
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
success = true;
|
|
450
|
+
return {
|
|
451
|
+
data: null,
|
|
452
|
+
error: true,
|
|
453
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
454
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
async next() {
|
|
460
|
+
let success = false;
|
|
461
|
+
let data;
|
|
462
|
+
let response;
|
|
463
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
464
|
+
const LIMIT = pLimit(this._threadCount);
|
|
465
|
+
while (!success) {
|
|
466
|
+
try {
|
|
467
|
+
let startTime;
|
|
468
|
+
if (this._debug) {
|
|
469
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
470
|
+
}
|
|
471
|
+
if (this.links.next === null) {
|
|
472
|
+
success = true;
|
|
473
|
+
return {
|
|
474
|
+
data: null,
|
|
475
|
+
error: true,
|
|
476
|
+
error_code: 400,
|
|
477
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
481
|
+
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
482
|
+
headers: {
|
|
483
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
484
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
485
|
+
}
|
|
486
|
+
}));
|
|
487
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
488
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
489
|
+
try {
|
|
490
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
491
|
+
}
|
|
492
|
+
catch (error) {
|
|
493
|
+
success = true;
|
|
494
|
+
return {
|
|
495
|
+
data: null,
|
|
496
|
+
error: true,
|
|
497
|
+
error_code: response.status ?? 429,
|
|
498
|
+
error_message: error.message
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
data = await response.json();
|
|
504
|
+
}
|
|
505
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
506
|
+
checkAndModifyResponse(dataClass);
|
|
507
|
+
success = true;
|
|
508
|
+
return {
|
|
509
|
+
data: dataClass,
|
|
510
|
+
error: data.error,
|
|
511
|
+
error_code: data ? data.error_code : response.status,
|
|
512
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
success = true;
|
|
517
|
+
return {
|
|
518
|
+
data: null,
|
|
519
|
+
error: true,
|
|
520
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
521
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
377
527
|
class TransactionsBlockResponse {
|
|
378
528
|
constructor(data) {
|
|
379
529
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
@@ -406,12 +556,13 @@ class TransactionSummary {
|
|
|
406
556
|
}
|
|
407
557
|
}
|
|
408
558
|
class TransactionsResponse {
|
|
409
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
559
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
410
560
|
this._debug = _debug;
|
|
411
561
|
this._apiKey = _apiKey;
|
|
412
562
|
this._threadCount = _threadCount;
|
|
413
563
|
this._urlParams = _urlParams;
|
|
414
564
|
this._enableRetry = _enableRetry;
|
|
565
|
+
this._source = _source;
|
|
415
566
|
this.address = data.address;
|
|
416
567
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
417
568
|
this.quote_currency = data.quote_currency;
|
|
@@ -446,13 +597,13 @@ class TransactionsResponse {
|
|
|
446
597
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
447
598
|
headers: {
|
|
448
599
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
449
|
-
"X-Requested-With": userAgent
|
|
600
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
450
601
|
}
|
|
451
602
|
}));
|
|
452
603
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
453
604
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
454
605
|
try {
|
|
455
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
606
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
456
607
|
}
|
|
457
608
|
catch (error) {
|
|
458
609
|
success = true;
|
|
@@ -467,7 +618,7 @@ class TransactionsResponse {
|
|
|
467
618
|
else {
|
|
468
619
|
data = await response.json();
|
|
469
620
|
}
|
|
470
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
621
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
471
622
|
checkAndModifyResponse(dataClass);
|
|
472
623
|
success = true;
|
|
473
624
|
return {
|
|
@@ -513,13 +664,13 @@ class TransactionsResponse {
|
|
|
513
664
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
514
665
|
headers: {
|
|
515
666
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
516
|
-
"X-Requested-With": userAgent
|
|
667
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
517
668
|
}
|
|
518
669
|
}));
|
|
519
670
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
520
671
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
521
672
|
try {
|
|
522
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
673
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
523
674
|
}
|
|
524
675
|
catch (error) {
|
|
525
676
|
success = true;
|
|
@@ -534,7 +685,7 @@ class TransactionsResponse {
|
|
|
534
685
|
else {
|
|
535
686
|
data = await response.json();
|
|
536
687
|
}
|
|
537
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
688
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
538
689
|
checkAndModifyResponse(dataClass);
|
|
539
690
|
success = true;
|
|
540
691
|
return {
|
|
@@ -557,12 +708,13 @@ class TransactionsResponse {
|
|
|
557
708
|
}
|
|
558
709
|
}
|
|
559
710
|
class TransactionsTimeBucketResponse {
|
|
560
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
711
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
561
712
|
this._debug = _debug;
|
|
562
713
|
this._apiKey = _apiKey;
|
|
563
714
|
this._threadCount = _threadCount;
|
|
564
715
|
this._urlParams = _urlParams;
|
|
565
716
|
this._enableRetry = _enableRetry;
|
|
717
|
+
this._source = _source;
|
|
566
718
|
this.address = data.address;
|
|
567
719
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
568
720
|
this.quote_currency = data.quote_currency;
|
|
@@ -598,13 +750,13 @@ class TransactionsTimeBucketResponse {
|
|
|
598
750
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
599
751
|
headers: {
|
|
600
752
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
601
|
-
"X-Requested-With": userAgent
|
|
753
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
602
754
|
}
|
|
603
755
|
}));
|
|
604
756
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
605
757
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
606
758
|
try {
|
|
607
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
759
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
608
760
|
}
|
|
609
761
|
catch (error) {
|
|
610
762
|
success = true;
|
|
@@ -619,7 +771,7 @@ class TransactionsTimeBucketResponse {
|
|
|
619
771
|
else {
|
|
620
772
|
data = await response.json();
|
|
621
773
|
}
|
|
622
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
774
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
623
775
|
checkAndModifyResponse(dataClass);
|
|
624
776
|
success = true;
|
|
625
777
|
return {
|
|
@@ -665,13 +817,13 @@ class TransactionsTimeBucketResponse {
|
|
|
665
817
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
666
818
|
headers: {
|
|
667
819
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
668
|
-
"X-Requested-With": userAgent
|
|
820
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
669
821
|
}
|
|
670
822
|
}));
|
|
671
823
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
672
824
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
673
825
|
try {
|
|
674
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
826
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
675
827
|
}
|
|
676
828
|
catch (error) {
|
|
677
829
|
success = true;
|
|
@@ -686,7 +838,7 @@ class TransactionsTimeBucketResponse {
|
|
|
686
838
|
else {
|
|
687
839
|
data = await response.json();
|
|
688
840
|
}
|
|
689
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
841
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
690
842
|
checkAndModifyResponse(dataClass);
|
|
691
843
|
success = true;
|
|
692
844
|
return {
|
|
@@ -712,7 +864,7 @@ class TransactionsTimeBucketResponse {
|
|
|
712
864
|
* Transactions APIs
|
|
713
865
|
*
|
|
714
866
|
*/
|
|
715
|
-
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry) {
|
|
867
|
+
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
|
|
716
868
|
let hasNext = true;
|
|
717
869
|
let response;
|
|
718
870
|
let data;
|
|
@@ -727,13 +879,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, en
|
|
|
727
879
|
response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
|
|
728
880
|
headers: {
|
|
729
881
|
"Authorization": `Bearer ${apiKey}`,
|
|
730
|
-
"X-Requested-With": userAgent
|
|
882
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
731
883
|
}
|
|
732
884
|
}));
|
|
733
885
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
734
886
|
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
735
887
|
try {
|
|
736
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}
|
|
888
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
|
|
737
889
|
}
|
|
738
890
|
catch (error) {
|
|
739
891
|
hasNext = false;
|
|
@@ -769,12 +921,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, en
|
|
|
769
921
|
}
|
|
770
922
|
}
|
|
771
923
|
export class TransactionService {
|
|
772
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
924
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
773
925
|
this.apiKey = apiKey;
|
|
774
926
|
this.debug = debug;
|
|
775
927
|
this.threadCount = threadCount;
|
|
776
928
|
this.is_key_valid = is_key_valid;
|
|
777
929
|
this.enableRetry = enableRetry;
|
|
930
|
+
this.source = source;
|
|
778
931
|
this.LIMIT = pLimit(this.threadCount);
|
|
779
932
|
}
|
|
780
933
|
/**
|
|
@@ -834,13 +987,13 @@ export class TransactionService {
|
|
|
834
987
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
835
988
|
headers: {
|
|
836
989
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
837
|
-
"X-Requested-With": userAgent
|
|
990
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
838
991
|
}
|
|
839
992
|
}));
|
|
840
993
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
841
994
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
842
995
|
try {
|
|
843
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
996
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
844
997
|
}
|
|
845
998
|
catch (error) {
|
|
846
999
|
success = true;
|
|
@@ -910,7 +1063,7 @@ export class TransactionService {
|
|
|
910
1063
|
if (queryParamOpts?.withSafe !== undefined) {
|
|
911
1064
|
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
912
1065
|
}
|
|
913
|
-
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry)) {
|
|
1066
|
+
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
914
1067
|
yield tx;
|
|
915
1068
|
}
|
|
916
1069
|
success = true;
|
|
@@ -970,13 +1123,13 @@ export class TransactionService {
|
|
|
970
1123
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
971
1124
|
headers: {
|
|
972
1125
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
973
|
-
"X-Requested-With": userAgent
|
|
1126
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
974
1127
|
}
|
|
975
1128
|
}));
|
|
976
1129
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
977
1130
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
978
1131
|
try {
|
|
979
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1132
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
980
1133
|
}
|
|
981
1134
|
catch (error) {
|
|
982
1135
|
success = true;
|
|
@@ -991,7 +1144,7 @@ export class TransactionService {
|
|
|
991
1144
|
else {
|
|
992
1145
|
data = await response.json();
|
|
993
1146
|
}
|
|
994
|
-
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
1147
|
+
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
995
1148
|
checkAndModifyResponse(dataClass);
|
|
996
1149
|
success = true;
|
|
997
1150
|
return {
|
|
@@ -1057,13 +1210,13 @@ export class TransactionService {
|
|
|
1057
1210
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
|
|
1058
1211
|
headers: {
|
|
1059
1212
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1060
|
-
"X-Requested-With": userAgent
|
|
1213
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1061
1214
|
}
|
|
1062
1215
|
}));
|
|
1063
1216
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1064
1217
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1065
1218
|
try {
|
|
1066
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1219
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1067
1220
|
}
|
|
1068
1221
|
catch (error) {
|
|
1069
1222
|
success = true;
|
|
@@ -1131,13 +1284,13 @@ export class TransactionService {
|
|
|
1131
1284
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
|
|
1132
1285
|
headers: {
|
|
1133
1286
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1134
|
-
"X-Requested-With": userAgent
|
|
1287
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1135
1288
|
}
|
|
1136
1289
|
}));
|
|
1137
1290
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1138
1291
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1139
1292
|
try {
|
|
1140
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1293
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1141
1294
|
}
|
|
1142
1295
|
catch (error) {
|
|
1143
1296
|
success = true;
|
|
@@ -1221,13 +1374,13 @@ export class TransactionService {
|
|
|
1221
1374
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
1222
1375
|
headers: {
|
|
1223
1376
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1224
|
-
"X-Requested-With": userAgent
|
|
1377
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1225
1378
|
}
|
|
1226
1379
|
}));
|
|
1227
1380
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1228
1381
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1229
1382
|
try {
|
|
1230
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1383
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1231
1384
|
}
|
|
1232
1385
|
catch (error) {
|
|
1233
1386
|
success = true;
|
|
@@ -1242,7 +1395,7 @@ export class TransactionService {
|
|
|
1242
1395
|
else {
|
|
1243
1396
|
data = await response.json();
|
|
1244
1397
|
}
|
|
1245
|
-
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
1398
|
+
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
1246
1399
|
checkAndModifyResponse(dataClass);
|
|
1247
1400
|
success = true;
|
|
1248
1401
|
return {
|
|
@@ -1307,13 +1460,13 @@ export class TransactionService {
|
|
|
1307
1460
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
1308
1461
|
headers: {
|
|
1309
1462
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1310
|
-
"X-Requested-With": userAgent
|
|
1463
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1311
1464
|
}
|
|
1312
1465
|
}));
|
|
1313
1466
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1314
1467
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1315
1468
|
try {
|
|
1316
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1469
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1317
1470
|
}
|
|
1318
1471
|
catch (error) {
|
|
1319
1472
|
success = true;
|
|
@@ -1328,7 +1481,182 @@ export class TransactionService {
|
|
|
1328
1481
|
else {
|
|
1329
1482
|
data = await response.json();
|
|
1330
1483
|
}
|
|
1331
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
1484
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
1485
|
+
checkAndModifyResponse(dataClass);
|
|
1486
|
+
success = true;
|
|
1487
|
+
return {
|
|
1488
|
+
data: dataClass,
|
|
1489
|
+
error: data.error,
|
|
1490
|
+
error_code: data ? data.error_code : response.status,
|
|
1491
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
catch (error) {
|
|
1495
|
+
success = true;
|
|
1496
|
+
return {
|
|
1497
|
+
data: null,
|
|
1498
|
+
error: true,
|
|
1499
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1500
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
*
|
|
1507
|
+
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
1508
|
+
*
|
|
1509
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1510
|
+
* @param {string} blockHash - The requested block hash.
|
|
1511
|
+
* @param {number} page - The requested 0-indexed page number.
|
|
1512
|
+
* @param {GetTransactionsForBlockHashByPageQueryParamOpts} queryParamOpts
|
|
1513
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1514
|
+
* - `noLogs`: Omit log events.
|
|
1515
|
+
* - `withSafe`: Include safe details.
|
|
1516
|
+
*
|
|
1517
|
+
*/
|
|
1518
|
+
async getTransactionsForBlockHashByPage(chainName, blockHash, page, queryParamOpts) {
|
|
1519
|
+
let success = false;
|
|
1520
|
+
let data;
|
|
1521
|
+
let response;
|
|
1522
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1523
|
+
while (!success) {
|
|
1524
|
+
try {
|
|
1525
|
+
const urlParams = new URLSearchParams();
|
|
1526
|
+
if (!this.is_key_valid) {
|
|
1527
|
+
return {
|
|
1528
|
+
data: null,
|
|
1529
|
+
error: true,
|
|
1530
|
+
error_code: 401,
|
|
1531
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
1535
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
1536
|
+
}
|
|
1537
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
1538
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
1539
|
+
}
|
|
1540
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
1541
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
1542
|
+
}
|
|
1543
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`;
|
|
1544
|
+
let startTime;
|
|
1545
|
+
if (this.debug) {
|
|
1546
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1547
|
+
}
|
|
1548
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
1549
|
+
headers: {
|
|
1550
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
1551
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1552
|
+
}
|
|
1553
|
+
}));
|
|
1554
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1555
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1556
|
+
try {
|
|
1557
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1558
|
+
}
|
|
1559
|
+
catch (error) {
|
|
1560
|
+
success = true;
|
|
1561
|
+
return {
|
|
1562
|
+
data: null,
|
|
1563
|
+
error: true,
|
|
1564
|
+
error_code: response.status ?? 429,
|
|
1565
|
+
error_message: error.message
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
data = await response.json();
|
|
1571
|
+
}
|
|
1572
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
1573
|
+
checkAndModifyResponse(dataClass);
|
|
1574
|
+
success = true;
|
|
1575
|
+
return {
|
|
1576
|
+
data: dataClass,
|
|
1577
|
+
error: data.error,
|
|
1578
|
+
error_code: data ? data.error_code : response.status,
|
|
1579
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
catch (error) {
|
|
1583
|
+
success = true;
|
|
1584
|
+
return {
|
|
1585
|
+
data: null,
|
|
1586
|
+
error: true,
|
|
1587
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1588
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
*
|
|
1595
|
+
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
1596
|
+
*
|
|
1597
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1598
|
+
* @param {string} blockHash - The requested block hash.
|
|
1599
|
+
* @param {GetTransactionsForBlockHashQueryParamOpts} queryParamOpts
|
|
1600
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1601
|
+
* - `noLogs`: Omit log events.
|
|
1602
|
+
* - `withSafe`: Include safe details.
|
|
1603
|
+
*
|
|
1604
|
+
*/
|
|
1605
|
+
async getTransactionsForBlockHash(chainName, blockHash, queryParamOpts) {
|
|
1606
|
+
let success = false;
|
|
1607
|
+
let data;
|
|
1608
|
+
let response;
|
|
1609
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1610
|
+
while (!success) {
|
|
1611
|
+
try {
|
|
1612
|
+
const urlParams = new URLSearchParams();
|
|
1613
|
+
if (!this.is_key_valid) {
|
|
1614
|
+
return {
|
|
1615
|
+
data: null,
|
|
1616
|
+
error: true,
|
|
1617
|
+
error_code: 401,
|
|
1618
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
1622
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
1623
|
+
}
|
|
1624
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
1625
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
1626
|
+
}
|
|
1627
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
1628
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
1629
|
+
}
|
|
1630
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`;
|
|
1631
|
+
let startTime;
|
|
1632
|
+
if (this.debug) {
|
|
1633
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1634
|
+
}
|
|
1635
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`, {
|
|
1636
|
+
headers: {
|
|
1637
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
1638
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1639
|
+
}
|
|
1640
|
+
}));
|
|
1641
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1642
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1643
|
+
try {
|
|
1644
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1645
|
+
}
|
|
1646
|
+
catch (error) {
|
|
1647
|
+
success = true;
|
|
1648
|
+
return {
|
|
1649
|
+
data: null,
|
|
1650
|
+
error: true,
|
|
1651
|
+
error_code: response.status ?? 429,
|
|
1652
|
+
error_message: error.message
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
else {
|
|
1657
|
+
data = await response.json();
|
|
1658
|
+
}
|
|
1659
|
+
const dataClass = new TransactionsBlockResponse(data.data);
|
|
1332
1660
|
checkAndModifyResponse(dataClass);
|
|
1333
1661
|
success = true;
|
|
1334
1662
|
return {
|