@covalenthq/client-sdk 0.7.5 → 0.7.6
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 +20 -0
- package/dist/cjs/index.js +455 -357
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +2 -1
- package/dist/cjs/services/BaseService.d.ts +2 -1
- package/dist/cjs/services/CovalentClient.d.ts +4 -2
- package/dist/cjs/services/NftService.d.ts +2 -1
- package/dist/cjs/services/PricingService.d.ts +2 -1
- package/dist/cjs/services/SecurityService.d.ts +2 -1
- package/dist/cjs/services/TransactionService.d.ts +8 -4
- package/dist/cjs/services/XykService.d.ts +62 -8
- package/dist/cjs/util/ApiHelpers.d.ts +1 -1
- package/dist/cjs/util/types/XykServiceTypes.d.ts +46 -8
- package/dist/es/index.js +455 -357
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +2 -1
- package/dist/es/services/BaseService.d.ts +2 -1
- package/dist/es/services/CovalentClient.d.ts +4 -2
- package/dist/es/services/NftService.d.ts +2 -1
- package/dist/es/services/PricingService.d.ts +2 -1
- package/dist/es/services/SecurityService.d.ts +2 -1
- package/dist/es/services/TransactionService.d.ts +8 -4
- package/dist/es/services/XykService.d.ts +62 -8
- package/dist/es/util/ApiHelpers.d.ts +1 -1
- package/dist/es/util/types/XykServiceTypes.d.ts +46 -8
- package/dist/esm/index.js +455 -357
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +2 -1
- package/dist/esm/services/BaseService.d.ts +2 -1
- package/dist/esm/services/CovalentClient.d.ts +4 -2
- package/dist/esm/services/NftService.d.ts +2 -1
- package/dist/esm/services/PricingService.d.ts +2 -1
- package/dist/esm/services/SecurityService.d.ts +2 -1
- package/dist/esm/services/TransactionService.d.ts +8 -4
- package/dist/esm/services/XykService.d.ts +62 -8
- package/dist/esm/util/ApiHelpers.d.ts +1 -1
- package/dist/esm/util/types/XykServiceTypes.d.ts +46 -8
- package/dist/services/BalanceService.d.ts +2 -1
- package/dist/services/BalanceService.js +40 -33
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +2 -1
- package/dist/services/BaseService.js +66 -55
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +4 -2
- package/dist/services/CovalentClient.js +17 -17
- package/dist/services/CovalentClient.js.map +1 -1
- package/dist/services/NftService.d.ts +2 -1
- package/dist/services/NftService.js +82 -68
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +2 -1
- package/dist/services/PricingService.js +8 -6
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +2 -1
- package/dist/services/SecurityService.js +14 -11
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +8 -4
- package/dist/services/TransactionService.js +95 -79
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +62 -8
- package/dist/services/XykService.js +122 -78
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +1 -1
- package/dist/util/ApiHelpers.js +6 -5
- package/dist/util/ApiHelpers.js.map +1 -1
- package/dist/util/types/XykServiceTypes.d.ts +46 -8
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -219,7 +219,7 @@ async function debugOutput(url, responseStatus, startTime) {
|
|
|
219
219
|
}
|
|
220
220
|
console.log(`${chalk.red("[DEBUG]")}` + " |" + ` Request URL: ${chalk.yellow(url)}` + " |" + ` Response code: ${responseStatus !== 200 ? chalk.red(responseStatus) : chalk.green(responseStatus)}` + " |" + ` Response time: ${chalk.cyan(elapsedTime.toFixed(2) + "ms")}`);
|
|
221
221
|
}
|
|
222
|
-
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount) {
|
|
222
|
+
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry) {
|
|
223
223
|
let hasNext = true;
|
|
224
224
|
let response;
|
|
225
225
|
let data;
|
|
@@ -232,20 +232,21 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
|
|
|
232
232
|
if (debug) {
|
|
233
233
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
234
234
|
}
|
|
235
|
+
const link = urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`;
|
|
235
236
|
response = await LIMIT(() => fetch(urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`, {
|
|
236
237
|
headers: {
|
|
237
238
|
"Authorization": `Bearer ${apiKey}`,
|
|
238
239
|
"X-Requested-With": userAgent
|
|
239
240
|
}
|
|
240
241
|
}));
|
|
241
|
-
debugOutput(response.url, response.status
|
|
242
|
-
if (response.status === null || response.status === 429) {
|
|
242
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
243
|
+
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
243
244
|
try {
|
|
244
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
245
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : link));
|
|
245
246
|
}
|
|
246
247
|
catch (error) {
|
|
247
248
|
hasNext = false;
|
|
248
|
-
throw new Error(`An error occurred ${response.status
|
|
249
|
+
throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
252
|
else {
|
|
@@ -383,11 +384,12 @@ class NftApprovalSpender {
|
|
|
383
384
|
*
|
|
384
385
|
*/
|
|
385
386
|
class SecurityService {
|
|
386
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
387
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
387
388
|
this.apiKey = apiKey;
|
|
388
389
|
this.debug = debug;
|
|
389
390
|
this.threadCount = threadCount;
|
|
390
391
|
this.is_key_valid = is_key_valid;
|
|
392
|
+
this.enableRetry = enableRetry;
|
|
391
393
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
392
394
|
}
|
|
393
395
|
/**
|
|
@@ -406,6 +408,7 @@ class SecurityService {
|
|
|
406
408
|
while (!success) {
|
|
407
409
|
try {
|
|
408
410
|
const urlParams = new URLSearchParams();
|
|
411
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`;
|
|
409
412
|
if (!this.is_key_valid) {
|
|
410
413
|
return {
|
|
411
414
|
data: null,
|
|
@@ -424,10 +427,10 @@ class SecurityService {
|
|
|
424
427
|
"X-Requested-With": userAgent
|
|
425
428
|
}
|
|
426
429
|
}));
|
|
427
|
-
debugOutput(response.url, response.status
|
|
428
|
-
if (response.status === null || response.status === 429) {
|
|
430
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
431
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
429
432
|
try {
|
|
430
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
433
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
431
434
|
}
|
|
432
435
|
catch (error) {
|
|
433
436
|
success = true;
|
|
@@ -457,8 +460,8 @@ class SecurityService {
|
|
|
457
460
|
return {
|
|
458
461
|
data: null,
|
|
459
462
|
error: true,
|
|
460
|
-
error_code: data ? data.error_code : response.status,
|
|
461
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
463
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
464
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
462
465
|
};
|
|
463
466
|
}
|
|
464
467
|
}
|
|
@@ -478,6 +481,7 @@ class SecurityService {
|
|
|
478
481
|
while (!success) {
|
|
479
482
|
try {
|
|
480
483
|
const urlParams = new URLSearchParams();
|
|
484
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`;
|
|
481
485
|
if (!this.is_key_valid) {
|
|
482
486
|
return {
|
|
483
487
|
data: null,
|
|
@@ -496,10 +500,10 @@ class SecurityService {
|
|
|
496
500
|
"X-Requested-With": userAgent
|
|
497
501
|
}
|
|
498
502
|
}));
|
|
499
|
-
debugOutput(response.url, response.status
|
|
500
|
-
if (response.status === null || response.status === 429) {
|
|
503
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
504
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
501
505
|
try {
|
|
502
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
506
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
503
507
|
}
|
|
504
508
|
catch (error) {
|
|
505
509
|
success = true;
|
|
@@ -529,8 +533,8 @@ class SecurityService {
|
|
|
529
533
|
return {
|
|
530
534
|
data: null,
|
|
531
535
|
error: true,
|
|
532
|
-
error_code: data ? data.error_code : response.status,
|
|
533
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
536
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
537
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
534
538
|
};
|
|
535
539
|
}
|
|
536
540
|
}
|
|
@@ -818,11 +822,12 @@ class NativeBalanceItem {
|
|
|
818
822
|
*
|
|
819
823
|
*/
|
|
820
824
|
class BalanceService {
|
|
821
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
825
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
822
826
|
this.apiKey = apiKey;
|
|
823
827
|
this.debug = debug;
|
|
824
828
|
this.threadCount = threadCount;
|
|
825
829
|
this.is_key_valid = is_key_valid;
|
|
830
|
+
this.enableRetry = enableRetry;
|
|
826
831
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
827
832
|
}
|
|
828
833
|
/**
|
|
@@ -870,6 +875,7 @@ class BalanceService {
|
|
|
870
875
|
if (queryParamOpts?.noNftAssetMetadata !== undefined) {
|
|
871
876
|
urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
|
|
872
877
|
}
|
|
878
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`;
|
|
873
879
|
let startTime;
|
|
874
880
|
if (this.debug) {
|
|
875
881
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -880,10 +886,10 @@ class BalanceService {
|
|
|
880
886
|
"X-Requested-With": userAgent
|
|
881
887
|
}
|
|
882
888
|
}));
|
|
883
|
-
debugOutput(response.url, response.status
|
|
884
|
-
if (response.status === null || response.status === 429) {
|
|
889
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
890
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
885
891
|
try {
|
|
886
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
892
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
887
893
|
}
|
|
888
894
|
catch (error) {
|
|
889
895
|
success = true;
|
|
@@ -913,8 +919,8 @@ class BalanceService {
|
|
|
913
919
|
return {
|
|
914
920
|
data: null,
|
|
915
921
|
error: true,
|
|
916
|
-
error_code: data ? data.error_code : response.status,
|
|
917
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
922
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
923
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
918
924
|
};
|
|
919
925
|
}
|
|
920
926
|
}
|
|
@@ -952,6 +958,7 @@ class BalanceService {
|
|
|
952
958
|
if (queryParamOpts?.days !== undefined) {
|
|
953
959
|
urlParams.append("days", queryParamOpts?.days.toString());
|
|
954
960
|
}
|
|
961
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`;
|
|
955
962
|
let startTime;
|
|
956
963
|
if (this.debug) {
|
|
957
964
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -962,10 +969,10 @@ class BalanceService {
|
|
|
962
969
|
"X-Requested-With": userAgent
|
|
963
970
|
}
|
|
964
971
|
}));
|
|
965
|
-
debugOutput(response.url, response.status
|
|
966
|
-
if (response.status === null || response.status === 429) {
|
|
972
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
973
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
967
974
|
try {
|
|
968
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
975
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
969
976
|
}
|
|
970
977
|
catch (error) {
|
|
971
978
|
success = true;
|
|
@@ -995,8 +1002,8 @@ class BalanceService {
|
|
|
995
1002
|
return {
|
|
996
1003
|
data: null,
|
|
997
1004
|
error: true,
|
|
998
|
-
error_code: data ? data.error_code : response.status,
|
|
999
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1005
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1006
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1000
1007
|
};
|
|
1001
1008
|
}
|
|
1002
1009
|
}
|
|
@@ -1043,7 +1050,7 @@ class BalanceService {
|
|
|
1043
1050
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1044
1051
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1045
1052
|
}
|
|
1046
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount)) {
|
|
1053
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount, this.enableRetry)) {
|
|
1047
1054
|
yield res;
|
|
1048
1055
|
}
|
|
1049
1056
|
success = true;
|
|
@@ -1103,6 +1110,7 @@ class BalanceService {
|
|
|
1103
1110
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1104
1111
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1105
1112
|
}
|
|
1113
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`;
|
|
1106
1114
|
let startTime;
|
|
1107
1115
|
if (this.debug) {
|
|
1108
1116
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1113,10 +1121,10 @@ class BalanceService {
|
|
|
1113
1121
|
"X-Requested-With": userAgent
|
|
1114
1122
|
}
|
|
1115
1123
|
}));
|
|
1116
|
-
debugOutput(response.url, response.status
|
|
1117
|
-
if (response.status === null || response.status === 429) {
|
|
1124
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1125
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1118
1126
|
try {
|
|
1119
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1127
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1120
1128
|
}
|
|
1121
1129
|
catch (error) {
|
|
1122
1130
|
success = true;
|
|
@@ -1146,8 +1154,8 @@ class BalanceService {
|
|
|
1146
1154
|
return {
|
|
1147
1155
|
data: null,
|
|
1148
1156
|
error: true,
|
|
1149
|
-
error_code: data ? data.error_code : response.status,
|
|
1150
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1157
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1158
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1151
1159
|
};
|
|
1152
1160
|
}
|
|
1153
1161
|
}
|
|
@@ -1186,7 +1194,7 @@ class BalanceService {
|
|
|
1186
1194
|
if (queryParamOpts?.date !== undefined) {
|
|
1187
1195
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1188
1196
|
}
|
|
1189
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount)) {
|
|
1197
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount, this.enableRetry)) {
|
|
1190
1198
|
yield res;
|
|
1191
1199
|
}
|
|
1192
1200
|
success = true;
|
|
@@ -1238,6 +1246,7 @@ class BalanceService {
|
|
|
1238
1246
|
if (queryParamOpts?.date !== undefined) {
|
|
1239
1247
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1240
1248
|
}
|
|
1249
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`;
|
|
1241
1250
|
let startTime;
|
|
1242
1251
|
if (this.debug) {
|
|
1243
1252
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1248,10 +1257,10 @@ class BalanceService {
|
|
|
1248
1257
|
"X-Requested-With": userAgent
|
|
1249
1258
|
}
|
|
1250
1259
|
}));
|
|
1251
|
-
debugOutput(response.url, response.status
|
|
1252
|
-
if (response.status === null || response.status === 429) {
|
|
1260
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1261
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1253
1262
|
try {
|
|
1254
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1263
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1255
1264
|
}
|
|
1256
1265
|
catch (error) {
|
|
1257
1266
|
success = true;
|
|
@@ -1281,8 +1290,8 @@ class BalanceService {
|
|
|
1281
1290
|
return {
|
|
1282
1291
|
data: null,
|
|
1283
1292
|
error: true,
|
|
1284
|
-
error_code: data ? data.error_code : response.status,
|
|
1285
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1293
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1294
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1286
1295
|
};
|
|
1287
1296
|
}
|
|
1288
1297
|
}
|
|
@@ -1340,6 +1349,7 @@ class BalanceService {
|
|
|
1340
1349
|
if (queryParamOpts?.date !== undefined) {
|
|
1341
1350
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1342
1351
|
}
|
|
1352
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`;
|
|
1343
1353
|
let startTime;
|
|
1344
1354
|
if (this.debug) {
|
|
1345
1355
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1350,10 +1360,10 @@ class BalanceService {
|
|
|
1350
1360
|
"X-Requested-With": userAgent
|
|
1351
1361
|
}
|
|
1352
1362
|
}));
|
|
1353
|
-
debugOutput(response.url, response.status
|
|
1354
|
-
if (response.status === null || response.status === 429) {
|
|
1363
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1364
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1355
1365
|
try {
|
|
1356
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1366
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1357
1367
|
}
|
|
1358
1368
|
catch (error) {
|
|
1359
1369
|
success = true;
|
|
@@ -1383,8 +1393,8 @@ class BalanceService {
|
|
|
1383
1393
|
return {
|
|
1384
1394
|
data: null,
|
|
1385
1395
|
error: true,
|
|
1386
|
-
error_code: data ? data.error_code : response.status,
|
|
1387
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1396
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1397
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1388
1398
|
};
|
|
1389
1399
|
}
|
|
1390
1400
|
}
|
|
@@ -1420,6 +1430,7 @@ class BalanceService {
|
|
|
1420
1430
|
if (queryParamOpts?.blockHeight !== undefined) {
|
|
1421
1431
|
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
1422
1432
|
}
|
|
1433
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`;
|
|
1423
1434
|
let startTime;
|
|
1424
1435
|
if (this.debug) {
|
|
1425
1436
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1430,10 +1441,10 @@ class BalanceService {
|
|
|
1430
1441
|
"X-Requested-With": userAgent
|
|
1431
1442
|
}
|
|
1432
1443
|
}));
|
|
1433
|
-
debugOutput(response.url, response.status
|
|
1434
|
-
if (response.status === null || response.status === 429) {
|
|
1444
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1445
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1435
1446
|
try {
|
|
1436
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1447
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1437
1448
|
}
|
|
1438
1449
|
catch (error) {
|
|
1439
1450
|
success = true;
|
|
@@ -1463,8 +1474,8 @@ class BalanceService {
|
|
|
1463
1474
|
return {
|
|
1464
1475
|
data: null,
|
|
1465
1476
|
error: true,
|
|
1466
|
-
error_code: data ? data.error_code : response.status,
|
|
1467
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1477
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1478
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1468
1479
|
};
|
|
1469
1480
|
}
|
|
1470
1481
|
}
|
|
@@ -1692,11 +1703,12 @@ class OtherFees {
|
|
|
1692
1703
|
*
|
|
1693
1704
|
*/
|
|
1694
1705
|
class BaseService {
|
|
1695
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
1706
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
1696
1707
|
this.apiKey = apiKey;
|
|
1697
1708
|
this.debug = debug;
|
|
1698
1709
|
this.threadCount = threadCount;
|
|
1699
1710
|
this.is_key_valid = is_key_valid;
|
|
1711
|
+
this.enableRetry = enableRetry;
|
|
1700
1712
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
1701
1713
|
}
|
|
1702
1714
|
/**
|
|
@@ -1723,6 +1735,7 @@ class BaseService {
|
|
|
1723
1735
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1724
1736
|
};
|
|
1725
1737
|
}
|
|
1738
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`;
|
|
1726
1739
|
let startTime;
|
|
1727
1740
|
if (this.debug) {
|
|
1728
1741
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1733,10 +1746,10 @@ class BaseService {
|
|
|
1733
1746
|
"X-Requested-With": userAgent
|
|
1734
1747
|
}
|
|
1735
1748
|
}));
|
|
1736
|
-
debugOutput(response.url, response.status
|
|
1737
|
-
if (response.status === null || response.status === 429) {
|
|
1749
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1750
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1738
1751
|
try {
|
|
1739
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1752
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1740
1753
|
}
|
|
1741
1754
|
catch (error) {
|
|
1742
1755
|
success = true;
|
|
@@ -1766,8 +1779,8 @@ class BaseService {
|
|
|
1766
1779
|
return {
|
|
1767
1780
|
data: null,
|
|
1768
1781
|
error: true,
|
|
1769
|
-
error_code: data ? data.error_code : response.status,
|
|
1770
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1782
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1783
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1771
1784
|
};
|
|
1772
1785
|
}
|
|
1773
1786
|
}
|
|
@@ -1796,6 +1809,7 @@ class BaseService {
|
|
|
1796
1809
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1797
1810
|
};
|
|
1798
1811
|
}
|
|
1812
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`;
|
|
1799
1813
|
let startTime;
|
|
1800
1814
|
if (this.debug) {
|
|
1801
1815
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1806,10 +1820,10 @@ class BaseService {
|
|
|
1806
1820
|
"X-Requested-With": userAgent
|
|
1807
1821
|
}
|
|
1808
1822
|
}));
|
|
1809
|
-
debugOutput(response.url, response.status
|
|
1810
|
-
if (response.status === null || response.status === 429) {
|
|
1823
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1824
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1811
1825
|
try {
|
|
1812
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1826
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1813
1827
|
}
|
|
1814
1828
|
catch (error) {
|
|
1815
1829
|
success = true;
|
|
@@ -1839,8 +1853,8 @@ class BaseService {
|
|
|
1839
1853
|
return {
|
|
1840
1854
|
data: null,
|
|
1841
1855
|
error: true,
|
|
1842
|
-
error_code: data ? data.error_code : response.status,
|
|
1843
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1856
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1857
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1844
1858
|
};
|
|
1845
1859
|
}
|
|
1846
1860
|
}
|
|
@@ -1872,7 +1886,7 @@ class BaseService {
|
|
|
1872
1886
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1873
1887
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1874
1888
|
}
|
|
1875
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount)) {
|
|
1889
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount, this.enableRetry)) {
|
|
1876
1890
|
yield res;
|
|
1877
1891
|
}
|
|
1878
1892
|
success = true;
|
|
@@ -1917,6 +1931,7 @@ class BaseService {
|
|
|
1917
1931
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1918
1932
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1919
1933
|
}
|
|
1934
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`;
|
|
1920
1935
|
let startTime;
|
|
1921
1936
|
if (this.debug) {
|
|
1922
1937
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1927,10 +1942,10 @@ class BaseService {
|
|
|
1927
1942
|
"X-Requested-With": userAgent
|
|
1928
1943
|
}
|
|
1929
1944
|
}));
|
|
1930
|
-
debugOutput(response.url, response.status
|
|
1931
|
-
if (response.status === null || response.status === 429) {
|
|
1945
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1946
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1932
1947
|
try {
|
|
1933
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1948
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1934
1949
|
}
|
|
1935
1950
|
catch (error) {
|
|
1936
1951
|
success = true;
|
|
@@ -1960,8 +1975,8 @@ class BaseService {
|
|
|
1960
1975
|
return {
|
|
1961
1976
|
data: null,
|
|
1962
1977
|
error: true,
|
|
1963
|
-
error_code: data ? data.error_code : response.status,
|
|
1964
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1978
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1979
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1965
1980
|
};
|
|
1966
1981
|
}
|
|
1967
1982
|
}
|
|
@@ -2014,6 +2029,7 @@ class BaseService {
|
|
|
2014
2029
|
if (queryParamOpts?.skipDecode !== undefined) {
|
|
2015
2030
|
urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
|
|
2016
2031
|
}
|
|
2032
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`;
|
|
2017
2033
|
let startTime;
|
|
2018
2034
|
if (this.debug) {
|
|
2019
2035
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2024,10 +2040,10 @@ class BaseService {
|
|
|
2024
2040
|
"X-Requested-With": userAgent
|
|
2025
2041
|
}
|
|
2026
2042
|
}));
|
|
2027
|
-
debugOutput(response.url, response.status
|
|
2028
|
-
if (response.status === null || response.status === 429) {
|
|
2043
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2044
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2029
2045
|
try {
|
|
2030
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2046
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2031
2047
|
}
|
|
2032
2048
|
catch (error) {
|
|
2033
2049
|
success = true;
|
|
@@ -2057,8 +2073,8 @@ class BaseService {
|
|
|
2057
2073
|
return {
|
|
2058
2074
|
data: null,
|
|
2059
2075
|
error: true,
|
|
2060
|
-
error_code: data ? data.error_code : response.status,
|
|
2061
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2076
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2077
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2062
2078
|
};
|
|
2063
2079
|
}
|
|
2064
2080
|
}
|
|
@@ -2097,7 +2113,7 @@ class BaseService {
|
|
|
2097
2113
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2098
2114
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2099
2115
|
}
|
|
2100
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
2116
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry)) {
|
|
2101
2117
|
yield res;
|
|
2102
2118
|
}
|
|
2103
2119
|
success = true;
|
|
@@ -2149,6 +2165,7 @@ class BaseService {
|
|
|
2149
2165
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2150
2166
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2151
2167
|
}
|
|
2168
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`;
|
|
2152
2169
|
let startTime;
|
|
2153
2170
|
if (this.debug) {
|
|
2154
2171
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2159,10 +2176,10 @@ class BaseService {
|
|
|
2159
2176
|
"X-Requested-With": userAgent
|
|
2160
2177
|
}
|
|
2161
2178
|
}));
|
|
2162
|
-
debugOutput(response.url, response.status
|
|
2163
|
-
if (response.status === null || response.status === 429) {
|
|
2179
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2180
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2164
2181
|
try {
|
|
2165
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2182
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2166
2183
|
}
|
|
2167
2184
|
catch (error) {
|
|
2168
2185
|
success = true;
|
|
@@ -2192,8 +2209,8 @@ class BaseService {
|
|
|
2192
2209
|
return {
|
|
2193
2210
|
data: null,
|
|
2194
2211
|
error: true,
|
|
2195
|
-
error_code: data ? data.error_code : response.status,
|
|
2196
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2212
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2213
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2197
2214
|
};
|
|
2198
2215
|
}
|
|
2199
2216
|
}
|
|
@@ -2236,7 +2253,7 @@ class BaseService {
|
|
|
2236
2253
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2237
2254
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2238
2255
|
}
|
|
2239
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
2256
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry)) {
|
|
2240
2257
|
yield res;
|
|
2241
2258
|
}
|
|
2242
2259
|
success = true;
|
|
@@ -2292,6 +2309,7 @@ class BaseService {
|
|
|
2292
2309
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2293
2310
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2294
2311
|
}
|
|
2312
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`;
|
|
2295
2313
|
let startTime;
|
|
2296
2314
|
if (this.debug) {
|
|
2297
2315
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2302,10 +2320,10 @@ class BaseService {
|
|
|
2302
2320
|
"X-Requested-With": userAgent
|
|
2303
2321
|
}
|
|
2304
2322
|
}));
|
|
2305
|
-
debugOutput(response.url, response.status
|
|
2306
|
-
if (response.status === null || response.status === 429) {
|
|
2323
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2324
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2307
2325
|
try {
|
|
2308
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2326
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2309
2327
|
}
|
|
2310
2328
|
catch (error) {
|
|
2311
2329
|
success = true;
|
|
@@ -2335,8 +2353,8 @@ class BaseService {
|
|
|
2335
2353
|
return {
|
|
2336
2354
|
data: null,
|
|
2337
2355
|
error: true,
|
|
2338
|
-
error_code: data ? data.error_code : response.status,
|
|
2339
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2356
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2357
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2340
2358
|
};
|
|
2341
2359
|
}
|
|
2342
2360
|
}
|
|
@@ -2367,16 +2385,17 @@ class BaseService {
|
|
|
2367
2385
|
if (this.debug) {
|
|
2368
2386
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
2369
2387
|
}
|
|
2388
|
+
const url = `https://api.covalenthq.com/v1/chains/?${urlParams}`;
|
|
2370
2389
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
|
|
2371
2390
|
headers: {
|
|
2372
2391
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2373
2392
|
"X-Requested-With": userAgent
|
|
2374
2393
|
}
|
|
2375
2394
|
}));
|
|
2376
|
-
debugOutput(response.url, response.status
|
|
2377
|
-
if (response.status === null || response.status === 429) {
|
|
2395
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2396
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2378
2397
|
try {
|
|
2379
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2398
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2380
2399
|
}
|
|
2381
2400
|
catch (error) {
|
|
2382
2401
|
success = true;
|
|
@@ -2406,8 +2425,8 @@ class BaseService {
|
|
|
2406
2425
|
return {
|
|
2407
2426
|
data: null,
|
|
2408
2427
|
error: true,
|
|
2409
|
-
error_code: data ? data.error_code : response.status,
|
|
2410
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2428
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2429
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2411
2430
|
};
|
|
2412
2431
|
}
|
|
2413
2432
|
}
|
|
@@ -2434,6 +2453,7 @@ class BaseService {
|
|
|
2434
2453
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
2435
2454
|
};
|
|
2436
2455
|
}
|
|
2456
|
+
const url = `https://api.covalenthq.com/v1/chains/status/?${urlParams}`;
|
|
2437
2457
|
let startTime;
|
|
2438
2458
|
if (this.debug) {
|
|
2439
2459
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2444,10 +2464,10 @@ class BaseService {
|
|
|
2444
2464
|
"X-Requested-With": userAgent
|
|
2445
2465
|
}
|
|
2446
2466
|
}));
|
|
2447
|
-
debugOutput(response.url, response.status
|
|
2448
|
-
if (response.status === null || response.status === 429) {
|
|
2467
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2468
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2449
2469
|
try {
|
|
2450
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2470
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2451
2471
|
}
|
|
2452
2472
|
catch (error) {
|
|
2453
2473
|
success = true;
|
|
@@ -2477,8 +2497,8 @@ class BaseService {
|
|
|
2477
2497
|
return {
|
|
2478
2498
|
data: null,
|
|
2479
2499
|
error: true,
|
|
2480
|
-
error_code: data ? data.error_code : response.status,
|
|
2481
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2500
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2501
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2482
2502
|
};
|
|
2483
2503
|
}
|
|
2484
2504
|
}
|
|
@@ -2511,6 +2531,7 @@ class BaseService {
|
|
|
2511
2531
|
if (queryParamOpts?.testnets !== undefined) {
|
|
2512
2532
|
urlParams.append("testnets", queryParamOpts?.testnets.toString());
|
|
2513
2533
|
}
|
|
2534
|
+
const url = `https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`;
|
|
2514
2535
|
let startTime;
|
|
2515
2536
|
if (this.debug) {
|
|
2516
2537
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2521,10 +2542,10 @@ class BaseService {
|
|
|
2521
2542
|
"X-Requested-With": userAgent
|
|
2522
2543
|
}
|
|
2523
2544
|
}));
|
|
2524
|
-
debugOutput(response.url, response.status
|
|
2525
|
-
if (response.status === null || response.status === 429) {
|
|
2545
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2546
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2526
2547
|
try {
|
|
2527
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2548
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2528
2549
|
}
|
|
2529
2550
|
catch (error) {
|
|
2530
2551
|
success = true;
|
|
@@ -2554,8 +2575,8 @@ class BaseService {
|
|
|
2554
2575
|
return {
|
|
2555
2576
|
data: null,
|
|
2556
2577
|
error: true,
|
|
2557
|
-
error_code: data ? data.error_code : response.status,
|
|
2558
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2578
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2579
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2559
2580
|
};
|
|
2560
2581
|
}
|
|
2561
2582
|
}
|
|
@@ -2587,6 +2608,7 @@ class BaseService {
|
|
|
2587
2608
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
2588
2609
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
2589
2610
|
}
|
|
2611
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`;
|
|
2590
2612
|
let startTime;
|
|
2591
2613
|
if (this.debug) {
|
|
2592
2614
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2597,17 +2619,17 @@ class BaseService {
|
|
|
2597
2619
|
"X-Requested-With": userAgent
|
|
2598
2620
|
}
|
|
2599
2621
|
}));
|
|
2600
|
-
debugOutput(response.url, response.status, startTime);
|
|
2601
|
-
if (response.status === 429) {
|
|
2622
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2623
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2602
2624
|
try {
|
|
2603
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2625
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2604
2626
|
}
|
|
2605
2627
|
catch (error) {
|
|
2606
2628
|
success = true;
|
|
2607
2629
|
return {
|
|
2608
2630
|
data: null,
|
|
2609
2631
|
error: true,
|
|
2610
|
-
error_code: response.status,
|
|
2632
|
+
error_code: response.status ?? 429,
|
|
2611
2633
|
error_message: error.message
|
|
2612
2634
|
};
|
|
2613
2635
|
}
|
|
@@ -2630,8 +2652,8 @@ class BaseService {
|
|
|
2630
2652
|
return {
|
|
2631
2653
|
data: null,
|
|
2632
2654
|
error: true,
|
|
2633
|
-
error_code: data ? data.error_code : response.status,
|
|
2634
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2655
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2656
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2635
2657
|
};
|
|
2636
2658
|
}
|
|
2637
2659
|
}
|
|
@@ -2960,11 +2982,12 @@ class MarketFloorPriceItem {
|
|
|
2960
2982
|
*
|
|
2961
2983
|
*/
|
|
2962
2984
|
class NftService {
|
|
2963
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
2985
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
2964
2986
|
this.apiKey = apiKey;
|
|
2965
2987
|
this.debug = debug;
|
|
2966
2988
|
this.threadCount = threadCount;
|
|
2967
2989
|
this.is_key_valid = is_key_valid;
|
|
2990
|
+
this.enableRetry = enableRetry;
|
|
2968
2991
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
2969
2992
|
}
|
|
2970
2993
|
/**
|
|
@@ -2996,7 +3019,7 @@ class NftService {
|
|
|
2996
3019
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
2997
3020
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
2998
3021
|
}
|
|
2999
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
|
|
3022
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry)) {
|
|
3000
3023
|
yield res;
|
|
3001
3024
|
}
|
|
3002
3025
|
success = true;
|
|
@@ -3043,6 +3066,7 @@ class NftService {
|
|
|
3043
3066
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3044
3067
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3045
3068
|
}
|
|
3069
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`;
|
|
3046
3070
|
let startTime;
|
|
3047
3071
|
if (this.debug) {
|
|
3048
3072
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3053,10 +3077,10 @@ class NftService {
|
|
|
3053
3077
|
"X-Requested-With": userAgent
|
|
3054
3078
|
}
|
|
3055
3079
|
}));
|
|
3056
|
-
debugOutput(response.url, response.status
|
|
3057
|
-
if (response.status === null || response.status === 429) {
|
|
3080
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3081
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3058
3082
|
try {
|
|
3059
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3083
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3060
3084
|
}
|
|
3061
3085
|
catch (error) {
|
|
3062
3086
|
success = true;
|
|
@@ -3086,8 +3110,8 @@ class NftService {
|
|
|
3086
3110
|
return {
|
|
3087
3111
|
data: null,
|
|
3088
3112
|
error: true,
|
|
3089
|
-
error_code: data ? data.error_code : response.status,
|
|
3090
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3113
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3114
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3091
3115
|
};
|
|
3092
3116
|
}
|
|
3093
3117
|
}
|
|
@@ -3129,6 +3153,7 @@ class NftService {
|
|
|
3129
3153
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3130
3154
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3131
3155
|
}
|
|
3156
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`;
|
|
3132
3157
|
let startTime;
|
|
3133
3158
|
if (this.debug) {
|
|
3134
3159
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3139,10 +3164,10 @@ class NftService {
|
|
|
3139
3164
|
"X-Requested-With": userAgent
|
|
3140
3165
|
}
|
|
3141
3166
|
}));
|
|
3142
|
-
debugOutput(response.url, response.status
|
|
3143
|
-
if (response.status === null || response.status === 429) {
|
|
3167
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3168
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3144
3169
|
try {
|
|
3145
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3170
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3146
3171
|
}
|
|
3147
3172
|
catch (error) {
|
|
3148
3173
|
success = true;
|
|
@@ -3172,8 +3197,8 @@ class NftService {
|
|
|
3172
3197
|
return {
|
|
3173
3198
|
data: null,
|
|
3174
3199
|
error: true,
|
|
3175
|
-
error_code: data ? data.error_code : response.status,
|
|
3176
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3200
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3201
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3177
3202
|
};
|
|
3178
3203
|
}
|
|
3179
3204
|
}
|
|
@@ -3220,7 +3245,7 @@ class NftService {
|
|
|
3220
3245
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3221
3246
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3222
3247
|
}
|
|
3223
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
|
|
3248
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount, this.enableRetry)) {
|
|
3224
3249
|
yield res;
|
|
3225
3250
|
}
|
|
3226
3251
|
success = true;
|
|
@@ -3280,6 +3305,7 @@ class NftService {
|
|
|
3280
3305
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3281
3306
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3282
3307
|
}
|
|
3308
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`;
|
|
3283
3309
|
let startTime;
|
|
3284
3310
|
if (this.debug) {
|
|
3285
3311
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3290,10 +3316,10 @@ class NftService {
|
|
|
3290
3316
|
"X-Requested-With": userAgent
|
|
3291
3317
|
}
|
|
3292
3318
|
}));
|
|
3293
|
-
debugOutput(response.url, response.status
|
|
3294
|
-
if (response.status === null || response.status === 429) {
|
|
3319
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3320
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3295
3321
|
try {
|
|
3296
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3322
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3297
3323
|
}
|
|
3298
3324
|
catch (error) {
|
|
3299
3325
|
success = true;
|
|
@@ -3323,8 +3349,8 @@ class NftService {
|
|
|
3323
3349
|
return {
|
|
3324
3350
|
data: null,
|
|
3325
3351
|
error: true,
|
|
3326
|
-
error_code: data ? data.error_code : response.status,
|
|
3327
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3352
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3353
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3328
3354
|
};
|
|
3329
3355
|
}
|
|
3330
3356
|
}
|
|
@@ -3363,6 +3389,7 @@ class NftService {
|
|
|
3363
3389
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3364
3390
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3365
3391
|
}
|
|
3392
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`;
|
|
3366
3393
|
let startTime;
|
|
3367
3394
|
if (this.debug) {
|
|
3368
3395
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3373,10 +3400,10 @@ class NftService {
|
|
|
3373
3400
|
"X-Requested-With": userAgent
|
|
3374
3401
|
}
|
|
3375
3402
|
}));
|
|
3376
|
-
debugOutput(response.url, response.status
|
|
3377
|
-
if (response.status === null || response.status === 429) {
|
|
3403
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3404
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3378
3405
|
try {
|
|
3379
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3406
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3380
3407
|
}
|
|
3381
3408
|
catch (error) {
|
|
3382
3409
|
success = true;
|
|
@@ -3406,8 +3433,8 @@ class NftService {
|
|
|
3406
3433
|
return {
|
|
3407
3434
|
data: null,
|
|
3408
3435
|
error: true,
|
|
3409
|
-
error_code: data ? data.error_code : response.status,
|
|
3410
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3436
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3437
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3411
3438
|
};
|
|
3412
3439
|
}
|
|
3413
3440
|
}
|
|
@@ -3442,6 +3469,7 @@ class NftService {
|
|
|
3442
3469
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3443
3470
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3444
3471
|
}
|
|
3472
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`;
|
|
3445
3473
|
let startTime;
|
|
3446
3474
|
if (this.debug) {
|
|
3447
3475
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3452,10 +3480,10 @@ class NftService {
|
|
|
3452
3480
|
"X-Requested-With": userAgent
|
|
3453
3481
|
}
|
|
3454
3482
|
}));
|
|
3455
|
-
debugOutput(response.url, response.status
|
|
3456
|
-
if (response.status === null || response.status === 429) {
|
|
3483
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3484
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3457
3485
|
try {
|
|
3458
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3486
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3459
3487
|
}
|
|
3460
3488
|
catch (error) {
|
|
3461
3489
|
success = true;
|
|
@@ -3485,8 +3513,8 @@ class NftService {
|
|
|
3485
3513
|
return {
|
|
3486
3514
|
data: null,
|
|
3487
3515
|
error: true,
|
|
3488
|
-
error_code: data ? data.error_code : response.status,
|
|
3489
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3516
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3517
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3490
3518
|
};
|
|
3491
3519
|
}
|
|
3492
3520
|
}
|
|
@@ -3515,6 +3543,7 @@ class NftService {
|
|
|
3515
3543
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3516
3544
|
};
|
|
3517
3545
|
}
|
|
3546
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`;
|
|
3518
3547
|
let startTime;
|
|
3519
3548
|
if (this.debug) {
|
|
3520
3549
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3525,10 +3554,10 @@ class NftService {
|
|
|
3525
3554
|
"X-Requested-With": userAgent
|
|
3526
3555
|
}
|
|
3527
3556
|
}));
|
|
3528
|
-
debugOutput(response.url, response.status
|
|
3529
|
-
if (response.status === null || response.status === 429) {
|
|
3557
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3558
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3530
3559
|
try {
|
|
3531
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3560
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3532
3561
|
}
|
|
3533
3562
|
catch (error) {
|
|
3534
3563
|
success = true;
|
|
@@ -3558,8 +3587,8 @@ class NftService {
|
|
|
3558
3587
|
return {
|
|
3559
3588
|
data: null,
|
|
3560
3589
|
error: true,
|
|
3561
|
-
error_code: data ? data.error_code : response.status,
|
|
3562
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3590
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3591
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3563
3592
|
};
|
|
3564
3593
|
}
|
|
3565
3594
|
}
|
|
@@ -3589,6 +3618,7 @@ class NftService {
|
|
|
3589
3618
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3590
3619
|
};
|
|
3591
3620
|
}
|
|
3621
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`;
|
|
3592
3622
|
let startTime;
|
|
3593
3623
|
if (this.debug) {
|
|
3594
3624
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3599,10 +3629,10 @@ class NftService {
|
|
|
3599
3629
|
"X-Requested-With": userAgent
|
|
3600
3630
|
}
|
|
3601
3631
|
}));
|
|
3602
|
-
debugOutput(response.url, response.status
|
|
3603
|
-
if (response.status === null || response.status === 429) {
|
|
3632
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3633
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3604
3634
|
try {
|
|
3605
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3635
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3606
3636
|
}
|
|
3607
3637
|
catch (error) {
|
|
3608
3638
|
success = true;
|
|
@@ -3632,8 +3662,8 @@ class NftService {
|
|
|
3632
3662
|
return {
|
|
3633
3663
|
data: null,
|
|
3634
3664
|
error: true,
|
|
3635
|
-
error_code: data ? data.error_code : response.status,
|
|
3636
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3665
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3666
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3637
3667
|
};
|
|
3638
3668
|
}
|
|
3639
3669
|
}
|
|
@@ -3662,6 +3692,7 @@ class NftService {
|
|
|
3662
3692
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3663
3693
|
};
|
|
3664
3694
|
}
|
|
3695
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`;
|
|
3665
3696
|
let startTime;
|
|
3666
3697
|
if (this.debug) {
|
|
3667
3698
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3672,10 +3703,10 @@ class NftService {
|
|
|
3672
3703
|
"X-Requested-With": userAgent
|
|
3673
3704
|
}
|
|
3674
3705
|
}));
|
|
3675
|
-
debugOutput(response.url, response.status
|
|
3676
|
-
if (response.status === null || response.status === 429) {
|
|
3706
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3707
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3677
3708
|
try {
|
|
3678
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3709
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3679
3710
|
}
|
|
3680
3711
|
catch (error) {
|
|
3681
3712
|
success = true;
|
|
@@ -3705,8 +3736,8 @@ class NftService {
|
|
|
3705
3736
|
return {
|
|
3706
3737
|
data: null,
|
|
3707
3738
|
error: true,
|
|
3708
|
-
error_code: data ? data.error_code : response.status,
|
|
3709
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3739
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3740
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3710
3741
|
};
|
|
3711
3742
|
}
|
|
3712
3743
|
}
|
|
@@ -3736,6 +3767,7 @@ class NftService {
|
|
|
3736
3767
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3737
3768
|
};
|
|
3738
3769
|
}
|
|
3770
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`;
|
|
3739
3771
|
let startTime;
|
|
3740
3772
|
if (this.debug) {
|
|
3741
3773
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3746,10 +3778,10 @@ class NftService {
|
|
|
3746
3778
|
"X-Requested-With": userAgent
|
|
3747
3779
|
}
|
|
3748
3780
|
}));
|
|
3749
|
-
debugOutput(response.url, response.status
|
|
3750
|
-
if (response.status === null || response.status === 429) {
|
|
3781
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3782
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3751
3783
|
try {
|
|
3752
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3784
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3753
3785
|
}
|
|
3754
3786
|
catch (error) {
|
|
3755
3787
|
success = true;
|
|
@@ -3779,8 +3811,8 @@ class NftService {
|
|
|
3779
3811
|
return {
|
|
3780
3812
|
data: null,
|
|
3781
3813
|
error: true,
|
|
3782
|
-
error_code: data ? data.error_code : response.status,
|
|
3783
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3814
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3815
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3784
3816
|
};
|
|
3785
3817
|
}
|
|
3786
3818
|
}
|
|
@@ -3811,6 +3843,7 @@ class NftService {
|
|
|
3811
3843
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3812
3844
|
};
|
|
3813
3845
|
}
|
|
3846
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`;
|
|
3814
3847
|
let startTime;
|
|
3815
3848
|
if (this.debug) {
|
|
3816
3849
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3821,10 +3854,10 @@ class NftService {
|
|
|
3821
3854
|
"X-Requested-With": userAgent
|
|
3822
3855
|
}
|
|
3823
3856
|
}));
|
|
3824
|
-
debugOutput(response.url, response.status
|
|
3825
|
-
if (response.status === null || response.status === 429) {
|
|
3857
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3858
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3826
3859
|
try {
|
|
3827
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3860
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3828
3861
|
}
|
|
3829
3862
|
catch (error) {
|
|
3830
3863
|
success = true;
|
|
@@ -3854,8 +3887,8 @@ class NftService {
|
|
|
3854
3887
|
return {
|
|
3855
3888
|
data: null,
|
|
3856
3889
|
error: true,
|
|
3857
|
-
error_code: data ? data.error_code : response.status,
|
|
3858
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3890
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3891
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3859
3892
|
};
|
|
3860
3893
|
}
|
|
3861
3894
|
}
|
|
@@ -3893,6 +3926,7 @@ class NftService {
|
|
|
3893
3926
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
3894
3927
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
3895
3928
|
}
|
|
3929
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`;
|
|
3896
3930
|
let startTime;
|
|
3897
3931
|
if (this.debug) {
|
|
3898
3932
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3903,10 +3937,10 @@ class NftService {
|
|
|
3903
3937
|
"X-Requested-With": userAgent
|
|
3904
3938
|
}
|
|
3905
3939
|
}));
|
|
3906
|
-
debugOutput(response.url, response.status
|
|
3907
|
-
if (response.status === null || response.status === 429) {
|
|
3940
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3941
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3908
3942
|
try {
|
|
3909
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3943
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3910
3944
|
}
|
|
3911
3945
|
catch (error) {
|
|
3912
3946
|
success = true;
|
|
@@ -3936,8 +3970,8 @@ class NftService {
|
|
|
3936
3970
|
return {
|
|
3937
3971
|
data: null,
|
|
3938
3972
|
error: true,
|
|
3939
|
-
error_code: data ? data.error_code : response.status,
|
|
3940
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3973
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3974
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3941
3975
|
};
|
|
3942
3976
|
}
|
|
3943
3977
|
}
|
|
@@ -3975,6 +4009,7 @@ class NftService {
|
|
|
3975
4009
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
3976
4010
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
3977
4011
|
}
|
|
4012
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`;
|
|
3978
4013
|
let startTime;
|
|
3979
4014
|
if (this.debug) {
|
|
3980
4015
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3985,10 +4020,10 @@ class NftService {
|
|
|
3985
4020
|
"X-Requested-With": userAgent
|
|
3986
4021
|
}
|
|
3987
4022
|
}));
|
|
3988
|
-
debugOutput(response.url, response.status
|
|
3989
|
-
if (response.status === null || response.status === 429) {
|
|
4023
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4024
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3990
4025
|
try {
|
|
3991
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4026
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3992
4027
|
}
|
|
3993
4028
|
catch (error) {
|
|
3994
4029
|
success = true;
|
|
@@ -4018,8 +4053,8 @@ class NftService {
|
|
|
4018
4053
|
return {
|
|
4019
4054
|
data: null,
|
|
4020
4055
|
error: true,
|
|
4021
|
-
error_code: data ? data.error_code : response.status,
|
|
4022
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4056
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4057
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4023
4058
|
};
|
|
4024
4059
|
}
|
|
4025
4060
|
}
|
|
@@ -4057,6 +4092,7 @@ class NftService {
|
|
|
4057
4092
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
4058
4093
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
4059
4094
|
}
|
|
4095
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`;
|
|
4060
4096
|
let startTime;
|
|
4061
4097
|
if (this.debug) {
|
|
4062
4098
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -4067,10 +4103,10 @@ class NftService {
|
|
|
4067
4103
|
"X-Requested-With": userAgent
|
|
4068
4104
|
}
|
|
4069
4105
|
}));
|
|
4070
|
-
debugOutput(response.url, response.status
|
|
4071
|
-
if (response.status === null || response.status === 429) {
|
|
4106
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4107
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4072
4108
|
try {
|
|
4073
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4109
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4074
4110
|
}
|
|
4075
4111
|
catch (error) {
|
|
4076
4112
|
success = true;
|
|
@@ -4100,8 +4136,8 @@ class NftService {
|
|
|
4100
4136
|
return {
|
|
4101
4137
|
data: null,
|
|
4102
4138
|
error: true,
|
|
4103
|
-
error_code: data ? data.error_code : response.status,
|
|
4104
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4139
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4140
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4105
4141
|
};
|
|
4106
4142
|
}
|
|
4107
4143
|
}
|
|
@@ -4127,10 +4163,10 @@ class Price {
|
|
|
4127
4163
|
this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
|
|
4128
4164
|
this.price = data.price;
|
|
4129
4165
|
this.pretty_price = data.pretty_price;
|
|
4130
|
-
this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$
|
|
4166
|
+
this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$2(data.contract_metadata) : null;
|
|
4131
4167
|
}
|
|
4132
4168
|
}
|
|
4133
|
-
let ContractMetadata$
|
|
4169
|
+
let ContractMetadata$2 = class ContractMetadata {
|
|
4134
4170
|
constructor(data) {
|
|
4135
4171
|
this.contract_decimals = data.contract_decimals;
|
|
4136
4172
|
this.contract_name = data.contract_name;
|
|
@@ -4141,11 +4177,12 @@ let ContractMetadata$1 = class ContractMetadata {
|
|
|
4141
4177
|
}
|
|
4142
4178
|
};
|
|
4143
4179
|
class PricingService {
|
|
4144
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
4180
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
4145
4181
|
this.apiKey = apiKey;
|
|
4146
4182
|
this.debug = debug;
|
|
4147
4183
|
this.threadCount = threadCount;
|
|
4148
4184
|
this.is_key_valid = is_key_valid;
|
|
4185
|
+
this.enableRetry = enableRetry;
|
|
4149
4186
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
4150
4187
|
}
|
|
4151
4188
|
/**
|
|
@@ -4186,6 +4223,7 @@ class PricingService {
|
|
|
4186
4223
|
if (queryParamOpts?.pricesAtAsc !== undefined) {
|
|
4187
4224
|
urlParams.append("prices-at-asc", queryParamOpts?.pricesAtAsc.toString());
|
|
4188
4225
|
}
|
|
4226
|
+
const url = `https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`;
|
|
4189
4227
|
let startTime;
|
|
4190
4228
|
if (this.debug) {
|
|
4191
4229
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -4196,10 +4234,10 @@ class PricingService {
|
|
|
4196
4234
|
"X-Requested-With": userAgent
|
|
4197
4235
|
}
|
|
4198
4236
|
}));
|
|
4199
|
-
debugOutput(response.url, response.status
|
|
4200
|
-
if (response.status === null || response.status === 429) {
|
|
4237
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4238
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4201
4239
|
try {
|
|
4202
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4240
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4203
4241
|
}
|
|
4204
4242
|
catch (error) {
|
|
4205
4243
|
success = true;
|
|
@@ -4233,8 +4271,8 @@ class PricingService {
|
|
|
4233
4271
|
return {
|
|
4234
4272
|
data: null,
|
|
4235
4273
|
error: true,
|
|
4236
|
-
error_code: data ? data.error_code : response.status,
|
|
4237
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4274
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4275
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4238
4276
|
};
|
|
4239
4277
|
}
|
|
4240
4278
|
}
|
|
@@ -4272,7 +4310,7 @@ class Transaction {
|
|
|
4272
4310
|
this.gas_quote = data.gas_quote;
|
|
4273
4311
|
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
4274
4312
|
this.gas_quote_rate = data.gas_quote_rate;
|
|
4275
|
-
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
4313
|
+
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata$1(data.gas_metadata) : null;
|
|
4276
4314
|
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
|
|
4277
4315
|
this.dex_details = data.dex_details && data.dex_details !== null ? data.dex_details.map((itemData) => new DexReport(itemData)) : null;
|
|
4278
4316
|
this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? data.nft_sale_details.map((itemData) => new NftSalesReport(itemData)) : null;
|
|
@@ -4281,7 +4319,7 @@ class Transaction {
|
|
|
4281
4319
|
this.safe_details = data.safe_details && data.safe_details !== null ? data.safe_details.map((itemData) => new SafeDetails(itemData)) : null;
|
|
4282
4320
|
}
|
|
4283
4321
|
}
|
|
4284
|
-
class ContractMetadata {
|
|
4322
|
+
let ContractMetadata$1 = class ContractMetadata {
|
|
4285
4323
|
constructor(data) {
|
|
4286
4324
|
this.contract_decimals = data.contract_decimals;
|
|
4287
4325
|
this.contract_name = data.contract_name;
|
|
@@ -4290,7 +4328,7 @@ class ContractMetadata {
|
|
|
4290
4328
|
this.supports_erc = data.supports_erc;
|
|
4291
4329
|
this.logo_url = data.logo_url;
|
|
4292
4330
|
}
|
|
4293
|
-
}
|
|
4331
|
+
};
|
|
4294
4332
|
class Explorer {
|
|
4295
4333
|
constructor(data) {
|
|
4296
4334
|
this.label = data.label;
|
|
@@ -4455,11 +4493,12 @@ class Param {
|
|
|
4455
4493
|
}
|
|
4456
4494
|
}
|
|
4457
4495
|
class RecentTransactionsResponse {
|
|
4458
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4496
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4459
4497
|
this._debug = _debug;
|
|
4460
4498
|
this._apiKey = _apiKey;
|
|
4461
4499
|
this._threadCount = _threadCount;
|
|
4462
4500
|
this._urlParams = _urlParams;
|
|
4501
|
+
this._enableRetry = _enableRetry;
|
|
4463
4502
|
this.address = data.address;
|
|
4464
4503
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4465
4504
|
this.quote_currency = data.quote_currency;
|
|
@@ -4490,16 +4529,17 @@ class RecentTransactionsResponse {
|
|
|
4490
4529
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4491
4530
|
};
|
|
4492
4531
|
}
|
|
4532
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4493
4533
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4494
4534
|
headers: {
|
|
4495
4535
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4496
4536
|
"X-Requested-With": userAgent
|
|
4497
4537
|
}
|
|
4498
4538
|
}));
|
|
4499
|
-
debugOutput(response.url, response.status
|
|
4500
|
-
if (response.status === null || response.status === 429) {
|
|
4539
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4540
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4501
4541
|
try {
|
|
4502
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4542
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4503
4543
|
}
|
|
4504
4544
|
catch (error) {
|
|
4505
4545
|
success = true;
|
|
@@ -4514,7 +4554,7 @@ class RecentTransactionsResponse {
|
|
|
4514
4554
|
else {
|
|
4515
4555
|
data = await response.json();
|
|
4516
4556
|
}
|
|
4517
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4557
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4518
4558
|
checkAndModifyResponse(dataClass);
|
|
4519
4559
|
success = true;
|
|
4520
4560
|
return {
|
|
@@ -4529,8 +4569,8 @@ class RecentTransactionsResponse {
|
|
|
4529
4569
|
return {
|
|
4530
4570
|
data: null,
|
|
4531
4571
|
error: true,
|
|
4532
|
-
error_code: data ? data.error_code : response.status,
|
|
4533
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4572
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4573
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4534
4574
|
};
|
|
4535
4575
|
}
|
|
4536
4576
|
}
|
|
@@ -4556,16 +4596,17 @@ class RecentTransactionsResponse {
|
|
|
4556
4596
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4557
4597
|
};
|
|
4558
4598
|
}
|
|
4599
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4559
4600
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4560
4601
|
headers: {
|
|
4561
4602
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4562
4603
|
"X-Requested-With": userAgent
|
|
4563
4604
|
}
|
|
4564
4605
|
}));
|
|
4565
|
-
debugOutput(response.url, response.status
|
|
4566
|
-
if (response.status === null || response.status === 429) {
|
|
4606
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4607
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4567
4608
|
try {
|
|
4568
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4609
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4569
4610
|
}
|
|
4570
4611
|
catch (error) {
|
|
4571
4612
|
success = true;
|
|
@@ -4580,7 +4621,7 @@ class RecentTransactionsResponse {
|
|
|
4580
4621
|
else {
|
|
4581
4622
|
data = await response.json();
|
|
4582
4623
|
}
|
|
4583
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4624
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4584
4625
|
checkAndModifyResponse(dataClass);
|
|
4585
4626
|
success = true;
|
|
4586
4627
|
return {
|
|
@@ -4595,8 +4636,8 @@ class RecentTransactionsResponse {
|
|
|
4595
4636
|
return {
|
|
4596
4637
|
data: null,
|
|
4597
4638
|
error: true,
|
|
4598
|
-
error_code: data ? data.error_code : response.status,
|
|
4599
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4639
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4640
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4600
4641
|
};
|
|
4601
4642
|
}
|
|
4602
4643
|
}
|
|
@@ -4640,11 +4681,12 @@ class TransactionSummary {
|
|
|
4640
4681
|
}
|
|
4641
4682
|
}
|
|
4642
4683
|
class TransactionsResponse {
|
|
4643
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4684
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4644
4685
|
this._debug = _debug;
|
|
4645
4686
|
this._apiKey = _apiKey;
|
|
4646
4687
|
this._threadCount = _threadCount;
|
|
4647
4688
|
this._urlParams = _urlParams;
|
|
4689
|
+
this._enableRetry = _enableRetry;
|
|
4648
4690
|
this.address = data.address;
|
|
4649
4691
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4650
4692
|
this.quote_currency = data.quote_currency;
|
|
@@ -4675,16 +4717,17 @@ class TransactionsResponse {
|
|
|
4675
4717
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4676
4718
|
};
|
|
4677
4719
|
}
|
|
4720
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4678
4721
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4679
4722
|
headers: {
|
|
4680
4723
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4681
4724
|
"X-Requested-With": userAgent
|
|
4682
4725
|
}
|
|
4683
4726
|
}));
|
|
4684
|
-
debugOutput(response.url, response.status
|
|
4685
|
-
if (response.status === null || response.status === 429) {
|
|
4727
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4728
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4686
4729
|
try {
|
|
4687
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4730
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4688
4731
|
}
|
|
4689
4732
|
catch (error) {
|
|
4690
4733
|
success = true;
|
|
@@ -4699,7 +4742,7 @@ class TransactionsResponse {
|
|
|
4699
4742
|
else {
|
|
4700
4743
|
data = await response.json();
|
|
4701
4744
|
}
|
|
4702
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4745
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4703
4746
|
checkAndModifyResponse(dataClass);
|
|
4704
4747
|
success = true;
|
|
4705
4748
|
return {
|
|
@@ -4714,8 +4757,8 @@ class TransactionsResponse {
|
|
|
4714
4757
|
return {
|
|
4715
4758
|
data: null,
|
|
4716
4759
|
error: true,
|
|
4717
|
-
error_code: data ? data.error_code : response.status,
|
|
4718
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4760
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4761
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4719
4762
|
};
|
|
4720
4763
|
}
|
|
4721
4764
|
}
|
|
@@ -4741,16 +4784,17 @@ class TransactionsResponse {
|
|
|
4741
4784
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4742
4785
|
};
|
|
4743
4786
|
}
|
|
4787
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4744
4788
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4745
4789
|
headers: {
|
|
4746
4790
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4747
4791
|
"X-Requested-With": userAgent
|
|
4748
4792
|
}
|
|
4749
4793
|
}));
|
|
4750
|
-
debugOutput(response.url, response.status
|
|
4751
|
-
if (response.status === null || response.status === 429) {
|
|
4794
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4795
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4752
4796
|
try {
|
|
4753
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4797
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4754
4798
|
}
|
|
4755
4799
|
catch (error) {
|
|
4756
4800
|
success = true;
|
|
@@ -4765,7 +4809,7 @@ class TransactionsResponse {
|
|
|
4765
4809
|
else {
|
|
4766
4810
|
data = await response.json();
|
|
4767
4811
|
}
|
|
4768
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4812
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4769
4813
|
checkAndModifyResponse(dataClass);
|
|
4770
4814
|
success = true;
|
|
4771
4815
|
return {
|
|
@@ -4780,19 +4824,20 @@ class TransactionsResponse {
|
|
|
4780
4824
|
return {
|
|
4781
4825
|
data: null,
|
|
4782
4826
|
error: true,
|
|
4783
|
-
error_code: data ? data.error_code : response.status,
|
|
4784
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4827
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4828
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4785
4829
|
};
|
|
4786
4830
|
}
|
|
4787
4831
|
}
|
|
4788
4832
|
}
|
|
4789
4833
|
}
|
|
4790
4834
|
class TransactionsTimeBucketResponse {
|
|
4791
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4835
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4792
4836
|
this._debug = _debug;
|
|
4793
4837
|
this._apiKey = _apiKey;
|
|
4794
4838
|
this._threadCount = _threadCount;
|
|
4795
4839
|
this._urlParams = _urlParams;
|
|
4840
|
+
this._enableRetry = _enableRetry;
|
|
4796
4841
|
this.address = data.address;
|
|
4797
4842
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4798
4843
|
this.quote_currency = data.quote_currency;
|
|
@@ -4824,16 +4869,17 @@ class TransactionsTimeBucketResponse {
|
|
|
4824
4869
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4825
4870
|
};
|
|
4826
4871
|
}
|
|
4872
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4827
4873
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4828
4874
|
headers: {
|
|
4829
4875
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4830
4876
|
"X-Requested-With": userAgent
|
|
4831
4877
|
}
|
|
4832
4878
|
}));
|
|
4833
|
-
debugOutput(response.url, response.status
|
|
4834
|
-
if (response.status === null || response.status === 429) {
|
|
4879
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4880
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4835
4881
|
try {
|
|
4836
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4882
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4837
4883
|
}
|
|
4838
4884
|
catch (error) {
|
|
4839
4885
|
success = true;
|
|
@@ -4848,7 +4894,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4848
4894
|
else {
|
|
4849
4895
|
data = await response.json();
|
|
4850
4896
|
}
|
|
4851
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4897
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4852
4898
|
checkAndModifyResponse(dataClass);
|
|
4853
4899
|
success = true;
|
|
4854
4900
|
return {
|
|
@@ -4863,8 +4909,8 @@ class TransactionsTimeBucketResponse {
|
|
|
4863
4909
|
return {
|
|
4864
4910
|
data: null,
|
|
4865
4911
|
error: true,
|
|
4866
|
-
error_code: data ? data.error_code : response.status,
|
|
4867
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4912
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4913
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4868
4914
|
};
|
|
4869
4915
|
}
|
|
4870
4916
|
}
|
|
@@ -4890,16 +4936,17 @@ class TransactionsTimeBucketResponse {
|
|
|
4890
4936
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4891
4937
|
};
|
|
4892
4938
|
}
|
|
4939
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4893
4940
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4894
4941
|
headers: {
|
|
4895
4942
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4896
4943
|
"X-Requested-With": userAgent
|
|
4897
4944
|
}
|
|
4898
4945
|
}));
|
|
4899
|
-
debugOutput(response.url, response.status
|
|
4900
|
-
if (response.status === null || response.status === 429) {
|
|
4946
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4947
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4901
4948
|
try {
|
|
4902
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4949
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4903
4950
|
}
|
|
4904
4951
|
catch (error) {
|
|
4905
4952
|
success = true;
|
|
@@ -4914,7 +4961,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4914
4961
|
else {
|
|
4915
4962
|
data = await response.json();
|
|
4916
4963
|
}
|
|
4917
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4964
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4918
4965
|
checkAndModifyResponse(dataClass);
|
|
4919
4966
|
success = true;
|
|
4920
4967
|
return {
|
|
@@ -4929,8 +4976,8 @@ class TransactionsTimeBucketResponse {
|
|
|
4929
4976
|
return {
|
|
4930
4977
|
data: null,
|
|
4931
4978
|
error: true,
|
|
4932
|
-
error_code: data ? data.error_code : response.status,
|
|
4933
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4979
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4980
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4934
4981
|
};
|
|
4935
4982
|
}
|
|
4936
4983
|
}
|
|
@@ -4940,7 +4987,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4940
4987
|
* Transactions APIs
|
|
4941
4988
|
*
|
|
4942
4989
|
*/
|
|
4943
|
-
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
4990
|
+
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry) {
|
|
4944
4991
|
let hasNext = true;
|
|
4945
4992
|
let response;
|
|
4946
4993
|
let data;
|
|
@@ -4958,14 +5005,14 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
|
4958
5005
|
"X-Requested-With": userAgent
|
|
4959
5006
|
}
|
|
4960
5007
|
}));
|
|
4961
|
-
debugOutput(response.url, response.status
|
|
4962
|
-
if (response.status === null || response.status === 429) {
|
|
5008
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5009
|
+
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4963
5010
|
try {
|
|
4964
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
5011
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`));
|
|
4965
5012
|
}
|
|
4966
5013
|
catch (error) {
|
|
4967
5014
|
hasNext = false;
|
|
4968
|
-
throw new Error(`An error occurred ${response.status}: ${error.message}`);
|
|
5015
|
+
throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
|
|
4969
5016
|
}
|
|
4970
5017
|
}
|
|
4971
5018
|
else {
|
|
@@ -4997,11 +5044,12 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
|
4997
5044
|
}
|
|
4998
5045
|
}
|
|
4999
5046
|
class TransactionService {
|
|
5000
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
5047
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
5001
5048
|
this.apiKey = apiKey;
|
|
5002
5049
|
this.debug = debug;
|
|
5003
5050
|
this.threadCount = threadCount;
|
|
5004
5051
|
this.is_key_valid = is_key_valid;
|
|
5052
|
+
this.enableRetry = enableRetry;
|
|
5005
5053
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
5006
5054
|
}
|
|
5007
5055
|
/**
|
|
@@ -5057,16 +5105,17 @@ class TransactionService {
|
|
|
5057
5105
|
if (this.debug) {
|
|
5058
5106
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5059
5107
|
}
|
|
5108
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
|
|
5060
5109
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
5061
5110
|
headers: {
|
|
5062
5111
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5063
5112
|
"X-Requested-With": userAgent
|
|
5064
5113
|
}
|
|
5065
5114
|
}));
|
|
5066
|
-
debugOutput(response.url, response.status
|
|
5067
|
-
if (response.status === null || response.status === 429) {
|
|
5115
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5116
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5068
5117
|
try {
|
|
5069
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5118
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5070
5119
|
}
|
|
5071
5120
|
catch (error) {
|
|
5072
5121
|
success = true;
|
|
@@ -5096,8 +5145,8 @@ class TransactionService {
|
|
|
5096
5145
|
return {
|
|
5097
5146
|
data: null,
|
|
5098
5147
|
error: true,
|
|
5099
|
-
error_code: data ? data.error_code : response.status,
|
|
5100
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5148
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5149
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5101
5150
|
};
|
|
5102
5151
|
}
|
|
5103
5152
|
}
|
|
@@ -5136,7 +5185,7 @@ class TransactionService {
|
|
|
5136
5185
|
if (queryParamOpts?.withSafe !== undefined) {
|
|
5137
5186
|
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5138
5187
|
}
|
|
5139
|
-
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
|
|
5188
|
+
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry)) {
|
|
5140
5189
|
yield tx;
|
|
5141
5190
|
}
|
|
5142
5191
|
success = true;
|
|
@@ -5192,16 +5241,17 @@ class TransactionService {
|
|
|
5192
5241
|
if (this.debug) {
|
|
5193
5242
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5194
5243
|
}
|
|
5244
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
|
|
5195
5245
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
5196
5246
|
headers: {
|
|
5197
5247
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5198
5248
|
"X-Requested-With": userAgent
|
|
5199
5249
|
}
|
|
5200
5250
|
}));
|
|
5201
|
-
debugOutput(response.url, response.status
|
|
5202
|
-
if (response.status === null || response.status === 429) {
|
|
5251
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5252
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5203
5253
|
try {
|
|
5204
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5254
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5205
5255
|
}
|
|
5206
5256
|
catch (error) {
|
|
5207
5257
|
success = true;
|
|
@@ -5216,7 +5266,7 @@ class TransactionService {
|
|
|
5216
5266
|
else {
|
|
5217
5267
|
data = await response.json();
|
|
5218
5268
|
}
|
|
5219
|
-
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5269
|
+
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5220
5270
|
checkAndModifyResponse(dataClass);
|
|
5221
5271
|
success = true;
|
|
5222
5272
|
return {
|
|
@@ -5231,8 +5281,8 @@ class TransactionService {
|
|
|
5231
5281
|
return {
|
|
5232
5282
|
data: null,
|
|
5233
5283
|
error: true,
|
|
5234
|
-
error_code: data ? data.error_code : response.status,
|
|
5235
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5284
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5285
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5236
5286
|
};
|
|
5237
5287
|
}
|
|
5238
5288
|
}
|
|
@@ -5278,16 +5328,17 @@ class TransactionService {
|
|
|
5278
5328
|
if (this.debug) {
|
|
5279
5329
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5280
5330
|
}
|
|
5331
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
|
|
5281
5332
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
|
|
5282
5333
|
headers: {
|
|
5283
5334
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5284
5335
|
"X-Requested-With": userAgent
|
|
5285
5336
|
}
|
|
5286
5337
|
}));
|
|
5287
|
-
debugOutput(response.url, response.status
|
|
5288
|
-
if (response.status === null || response.status === 429) {
|
|
5338
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5339
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5289
5340
|
try {
|
|
5290
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5341
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5291
5342
|
}
|
|
5292
5343
|
catch (error) {
|
|
5293
5344
|
success = true;
|
|
@@ -5317,8 +5368,8 @@ class TransactionService {
|
|
|
5317
5368
|
return {
|
|
5318
5369
|
data: null,
|
|
5319
5370
|
error: true,
|
|
5320
|
-
error_code: data ? data.error_code : response.status,
|
|
5321
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5371
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5372
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5322
5373
|
};
|
|
5323
5374
|
}
|
|
5324
5375
|
}
|
|
@@ -5351,16 +5402,17 @@ class TransactionService {
|
|
|
5351
5402
|
if (this.debug) {
|
|
5352
5403
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5353
5404
|
}
|
|
5405
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
|
|
5354
5406
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
|
|
5355
5407
|
headers: {
|
|
5356
5408
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5357
5409
|
"X-Requested-With": userAgent
|
|
5358
5410
|
}
|
|
5359
5411
|
}));
|
|
5360
|
-
debugOutput(response.url, response.status
|
|
5361
|
-
if (response.status === null || response.status === 429) {
|
|
5412
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5413
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5362
5414
|
try {
|
|
5363
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5415
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5364
5416
|
}
|
|
5365
5417
|
catch (error) {
|
|
5366
5418
|
success = true;
|
|
@@ -5390,8 +5442,8 @@ class TransactionService {
|
|
|
5390
5442
|
return {
|
|
5391
5443
|
data: null,
|
|
5392
5444
|
error: true,
|
|
5393
|
-
error_code: data ? data.error_code : response.status,
|
|
5394
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5445
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5446
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5395
5447
|
};
|
|
5396
5448
|
}
|
|
5397
5449
|
}
|
|
@@ -5440,16 +5492,17 @@ class TransactionService {
|
|
|
5440
5492
|
if (this.debug) {
|
|
5441
5493
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5442
5494
|
}
|
|
5495
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
|
|
5443
5496
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
5444
5497
|
headers: {
|
|
5445
5498
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5446
5499
|
"X-Requested-With": userAgent
|
|
5447
5500
|
}
|
|
5448
5501
|
}));
|
|
5449
|
-
debugOutput(response.url, response.status
|
|
5450
|
-
if (response.status === null || response.status === 429) {
|
|
5502
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5503
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5451
5504
|
try {
|
|
5452
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5505
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5453
5506
|
}
|
|
5454
5507
|
catch (error) {
|
|
5455
5508
|
success = true;
|
|
@@ -5464,7 +5517,7 @@ class TransactionService {
|
|
|
5464
5517
|
else {
|
|
5465
5518
|
data = await response.json();
|
|
5466
5519
|
}
|
|
5467
|
-
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5520
|
+
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5468
5521
|
checkAndModifyResponse(dataClass);
|
|
5469
5522
|
success = true;
|
|
5470
5523
|
return {
|
|
@@ -5479,8 +5532,8 @@ class TransactionService {
|
|
|
5479
5532
|
return {
|
|
5480
5533
|
data: null,
|
|
5481
5534
|
error: true,
|
|
5482
|
-
error_code: data ? data.error_code : response.status,
|
|
5483
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5535
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5536
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5484
5537
|
};
|
|
5485
5538
|
}
|
|
5486
5539
|
}
|
|
@@ -5525,16 +5578,17 @@ class TransactionService {
|
|
|
5525
5578
|
if (this.debug) {
|
|
5526
5579
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5527
5580
|
}
|
|
5581
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
|
|
5528
5582
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
5529
5583
|
headers: {
|
|
5530
5584
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5531
5585
|
"X-Requested-With": userAgent
|
|
5532
5586
|
}
|
|
5533
5587
|
}));
|
|
5534
|
-
debugOutput(response.url, response.status
|
|
5535
|
-
if (response.status === null || response.status === 429) {
|
|
5588
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5589
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5536
5590
|
try {
|
|
5537
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5591
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5538
5592
|
}
|
|
5539
5593
|
catch (error) {
|
|
5540
5594
|
success = true;
|
|
@@ -5549,7 +5603,7 @@ class TransactionService {
|
|
|
5549
5603
|
else {
|
|
5550
5604
|
data = await response.json();
|
|
5551
5605
|
}
|
|
5552
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5606
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5553
5607
|
checkAndModifyResponse(dataClass);
|
|
5554
5608
|
success = true;
|
|
5555
5609
|
return {
|
|
@@ -5564,8 +5618,8 @@ class TransactionService {
|
|
|
5564
5618
|
return {
|
|
5565
5619
|
data: null,
|
|
5566
5620
|
error: true,
|
|
5567
|
-
error_code: data ? data.error_code : response.status,
|
|
5568
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5621
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5622
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5569
5623
|
};
|
|
5570
5624
|
}
|
|
5571
5625
|
}
|
|
@@ -5761,6 +5815,7 @@ class PoolsDexDataItem {
|
|
|
5761
5815
|
this.volume_24h_quote = data.volume_24h_quote;
|
|
5762
5816
|
this.volume_7d_quote = data.volume_7d_quote;
|
|
5763
5817
|
this.fee_24h_quote = data.fee_24h_quote;
|
|
5818
|
+
this.annualized_fee = data.annualized_fee;
|
|
5764
5819
|
this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
|
|
5765
5820
|
this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
|
|
5766
5821
|
this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
|
|
@@ -5803,6 +5858,7 @@ class UniswapLikeToken {
|
|
|
5803
5858
|
this.logo_url = data.logo_url;
|
|
5804
5859
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5805
5860
|
this.quote = data.quote;
|
|
5861
|
+
this.pretty_quote = data.pretty_quote;
|
|
5806
5862
|
this.quote_rate = data.quote_rate;
|
|
5807
5863
|
}
|
|
5808
5864
|
}
|
|
@@ -5814,6 +5870,7 @@ class UniswapLikeTokenWithSupply {
|
|
|
5814
5870
|
this.logo_url = data.logo_url;
|
|
5815
5871
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5816
5872
|
this.quote = data.quote;
|
|
5873
|
+
this.pretty_quote = data.pretty_quote;
|
|
5817
5874
|
this.quote_rate = data.quote_rate;
|
|
5818
5875
|
this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
|
|
5819
5876
|
}
|
|
@@ -5892,12 +5949,34 @@ class ExchangeTransaction {
|
|
|
5892
5949
|
this.sender_address = data.sender_address;
|
|
5893
5950
|
this.total_quote = data.total_quote;
|
|
5894
5951
|
this.pretty_total_quote = data.pretty_total_quote;
|
|
5952
|
+
this.value = data.value && data.value !== null ? BigInt(data.value) : null;
|
|
5953
|
+
this.value_quote = data.value_quote;
|
|
5954
|
+
this.pretty_value_quote = data.pretty_value_quote;
|
|
5955
|
+
this.gas_offered = data.gas_offered;
|
|
5956
|
+
this.gas_spent = data.gas_spent;
|
|
5957
|
+
this.gas_price = data.gas_price;
|
|
5958
|
+
this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
|
|
5959
|
+
this.gas_quote = data.gas_quote;
|
|
5960
|
+
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
5961
|
+
this.gas_quote_rate = data.gas_quote_rate;
|
|
5962
|
+
this.quote_currency = data.quote_currency;
|
|
5895
5963
|
this.token_0_quote_rate = data.token_0_quote_rate;
|
|
5896
5964
|
this.token_1_quote_rate = data.token_1_quote_rate;
|
|
5965
|
+
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
5897
5966
|
this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
|
|
5898
5967
|
this.token_1 = data.token_1 && data.token_1 !== null ? new PoolToken(data.token_1) : null;
|
|
5899
5968
|
}
|
|
5900
5969
|
}
|
|
5970
|
+
class ContractMetadata {
|
|
5971
|
+
constructor(data) {
|
|
5972
|
+
this.contract_decimals = data.contract_decimals;
|
|
5973
|
+
this.contract_name = data.contract_name;
|
|
5974
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
5975
|
+
this.contract_address = data.contract_address;
|
|
5976
|
+
this.supports_erc = data.supports_erc;
|
|
5977
|
+
this.logo_url = data.logo_url;
|
|
5978
|
+
}
|
|
5979
|
+
}
|
|
5901
5980
|
class PoolToken {
|
|
5902
5981
|
constructor(data) {
|
|
5903
5982
|
this.contract_decimals = data.contract_decimals;
|
|
@@ -5941,13 +6020,15 @@ class UniswapLikeEcosystemCharts {
|
|
|
5941
6020
|
this.chain_id = data.chain_id;
|
|
5942
6021
|
this.quote_currency = data.quote_currency;
|
|
5943
6022
|
this.gas_token_price_quote = data.gas_token_price_quote;
|
|
5944
|
-
this.
|
|
5945
|
-
this.
|
|
5946
|
-
this.
|
|
5947
|
-
this.
|
|
5948
|
-
this.
|
|
5949
|
-
this.
|
|
5950
|
-
this.
|
|
6023
|
+
this.total_swaps_24h = data.total_swaps_24h;
|
|
6024
|
+
this.total_active_pairs_7d = data.total_active_pairs_7d;
|
|
6025
|
+
this.total_fees_24h = data.total_fees_24h;
|
|
6026
|
+
this.pretty_gas_token_price_quote = data.pretty_gas_token_price_quote;
|
|
6027
|
+
this.pretty_total_fees_24h = data.pretty_total_fees_24h;
|
|
6028
|
+
this.volume_chart_7d = data.volume_chart_7d && data.volume_chart_7d !== null ? data.volume_chart_7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
|
|
6029
|
+
this.volume_chart_30d = data.volume_chart_30d && data.volume_chart_30d !== null ? data.volume_chart_30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
|
|
6030
|
+
this.liquidity_chart_7d = data.liquidity_chart_7d && data.liquidity_chart_7d !== null ? data.liquidity_chart_7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
|
|
6031
|
+
this.liquidity_chart_30d = data.liquidity_chart_30d && data.liquidity_chart_30d !== null ? data.liquidity_chart_30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
|
|
5951
6032
|
}
|
|
5952
6033
|
}
|
|
5953
6034
|
class VolumeEcosystemChart {
|
|
@@ -5957,6 +6038,7 @@ class VolumeEcosystemChart {
|
|
|
5957
6038
|
this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
|
|
5958
6039
|
this.quote_currency = data.quote_currency;
|
|
5959
6040
|
this.volume_quote = data.volume_quote;
|
|
6041
|
+
this.pretty_volume_quote = data.pretty_volume_quote;
|
|
5960
6042
|
this.swap_count_24 = data.swap_count_24;
|
|
5961
6043
|
}
|
|
5962
6044
|
}
|
|
@@ -5967,6 +6049,7 @@ class LiquidityEcosystemChart {
|
|
|
5967
6049
|
this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
|
|
5968
6050
|
this.quote_currency = data.quote_currency;
|
|
5969
6051
|
this.liquidity_quote = data.liquidity_quote;
|
|
6052
|
+
this.pretty_liquidity_quote = data.pretty_liquidity_quote;
|
|
5970
6053
|
}
|
|
5971
6054
|
}
|
|
5972
6055
|
class HealthDataResponse {
|
|
@@ -5991,11 +6074,12 @@ class HealthData {
|
|
|
5991
6074
|
*
|
|
5992
6075
|
*/
|
|
5993
6076
|
class XykService {
|
|
5994
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
6077
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
5995
6078
|
this.apiKey = apiKey;
|
|
5996
6079
|
this.debug = debug;
|
|
5997
6080
|
this.threadCount = threadCount;
|
|
5998
6081
|
this.is_key_valid = is_key_valid;
|
|
6082
|
+
this.enableRetry = enableRetry;
|
|
5999
6083
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
6000
6084
|
}
|
|
6001
6085
|
/**
|
|
@@ -6014,6 +6098,7 @@ class XykService {
|
|
|
6014
6098
|
while (!success) {
|
|
6015
6099
|
try {
|
|
6016
6100
|
const urlParams = new URLSearchParams();
|
|
6101
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
|
|
6017
6102
|
if (!this.is_key_valid) {
|
|
6018
6103
|
return {
|
|
6019
6104
|
data: null,
|
|
@@ -6032,10 +6117,10 @@ class XykService {
|
|
|
6032
6117
|
"X-Requested-With": userAgent
|
|
6033
6118
|
}
|
|
6034
6119
|
}));
|
|
6035
|
-
debugOutput(response.url, response.status
|
|
6036
|
-
if (response.status === null || response.status === 429) {
|
|
6120
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6121
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6037
6122
|
try {
|
|
6038
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6123
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6039
6124
|
}
|
|
6040
6125
|
catch (error) {
|
|
6041
6126
|
success = true;
|
|
@@ -6065,8 +6150,8 @@ class XykService {
|
|
|
6065
6150
|
return {
|
|
6066
6151
|
data: null,
|
|
6067
6152
|
error: true,
|
|
6068
|
-
error_code: data ? data.error_code : response.status,
|
|
6069
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6153
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6154
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6070
6155
|
};
|
|
6071
6156
|
}
|
|
6072
6157
|
}
|
|
@@ -6087,6 +6172,7 @@ class XykService {
|
|
|
6087
6172
|
while (!success) {
|
|
6088
6173
|
try {
|
|
6089
6174
|
const urlParams = new URLSearchParams();
|
|
6175
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`;
|
|
6090
6176
|
if (!this.is_key_valid) {
|
|
6091
6177
|
return {
|
|
6092
6178
|
data: null,
|
|
@@ -6105,10 +6191,10 @@ class XykService {
|
|
|
6105
6191
|
"X-Requested-With": userAgent
|
|
6106
6192
|
}
|
|
6107
6193
|
}));
|
|
6108
|
-
debugOutput(response.url, response.status
|
|
6109
|
-
if (response.status === null || response.status === 429) {
|
|
6194
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6195
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6110
6196
|
try {
|
|
6111
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6197
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6112
6198
|
}
|
|
6113
6199
|
catch (error) {
|
|
6114
6200
|
success = true;
|
|
@@ -6138,8 +6224,8 @@ class XykService {
|
|
|
6138
6224
|
return {
|
|
6139
6225
|
data: null,
|
|
6140
6226
|
error: true,
|
|
6141
|
-
error_code: data ? data.error_code : response.status,
|
|
6142
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6227
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6228
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6143
6229
|
};
|
|
6144
6230
|
}
|
|
6145
6231
|
}
|
|
@@ -6161,6 +6247,7 @@ class XykService {
|
|
|
6161
6247
|
while (!success) {
|
|
6162
6248
|
try {
|
|
6163
6249
|
const urlParams = new URLSearchParams();
|
|
6250
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`;
|
|
6164
6251
|
if (!this.is_key_valid) {
|
|
6165
6252
|
return {
|
|
6166
6253
|
data: null,
|
|
@@ -6179,10 +6266,10 @@ class XykService {
|
|
|
6179
6266
|
"X-Requested-With": userAgent
|
|
6180
6267
|
}
|
|
6181
6268
|
}));
|
|
6182
|
-
debugOutput(response.url, response.status
|
|
6183
|
-
if (response.status === null || response.status === 429) {
|
|
6269
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6270
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6184
6271
|
try {
|
|
6185
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6272
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6186
6273
|
}
|
|
6187
6274
|
catch (error) {
|
|
6188
6275
|
success = true;
|
|
@@ -6212,8 +6299,8 @@ class XykService {
|
|
|
6212
6299
|
return {
|
|
6213
6300
|
data: null,
|
|
6214
6301
|
error: true,
|
|
6215
|
-
error_code: data ? data.error_code : response.status,
|
|
6216
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6302
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6303
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6217
6304
|
};
|
|
6218
6305
|
}
|
|
6219
6306
|
}
|
|
@@ -6251,6 +6338,7 @@ class XykService {
|
|
|
6251
6338
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6252
6339
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6253
6340
|
}
|
|
6341
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
|
|
6254
6342
|
let startTime;
|
|
6255
6343
|
if (this.debug) {
|
|
6256
6344
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6261,10 +6349,10 @@ class XykService {
|
|
|
6261
6349
|
"X-Requested-With": userAgent
|
|
6262
6350
|
}
|
|
6263
6351
|
}));
|
|
6264
|
-
debugOutput(response.url, response.status
|
|
6265
|
-
if (response.status === null || response.status === 429) {
|
|
6352
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6353
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6266
6354
|
try {
|
|
6267
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6355
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6268
6356
|
}
|
|
6269
6357
|
catch (error) {
|
|
6270
6358
|
success = true;
|
|
@@ -6294,8 +6382,8 @@ class XykService {
|
|
|
6294
6382
|
return {
|
|
6295
6383
|
data: null,
|
|
6296
6384
|
error: true,
|
|
6297
|
-
error_code: data ? data.error_code : response.status,
|
|
6298
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6385
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6386
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6299
6387
|
};
|
|
6300
6388
|
}
|
|
6301
6389
|
}
|
|
@@ -6325,6 +6413,7 @@ class XykService {
|
|
|
6325
6413
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6326
6414
|
};
|
|
6327
6415
|
}
|
|
6416
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`;
|
|
6328
6417
|
let startTime;
|
|
6329
6418
|
if (this.debug) {
|
|
6330
6419
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6335,10 +6424,10 @@ class XykService {
|
|
|
6335
6424
|
"X-Requested-With": userAgent
|
|
6336
6425
|
}
|
|
6337
6426
|
}));
|
|
6338
|
-
debugOutput(response.url, response.status
|
|
6339
|
-
if (response.status === null || response.status === 429) {
|
|
6427
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6428
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6340
6429
|
try {
|
|
6341
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6430
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6342
6431
|
}
|
|
6343
6432
|
catch (error) {
|
|
6344
6433
|
success = true;
|
|
@@ -6368,8 +6457,8 @@ class XykService {
|
|
|
6368
6457
|
return {
|
|
6369
6458
|
data: null,
|
|
6370
6459
|
error: true,
|
|
6371
|
-
error_code: data ? data.error_code : response.status,
|
|
6372
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6460
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6461
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6373
6462
|
};
|
|
6374
6463
|
}
|
|
6375
6464
|
}
|
|
@@ -6411,6 +6500,7 @@ class XykService {
|
|
|
6411
6500
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6412
6501
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6413
6502
|
}
|
|
6503
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
|
|
6414
6504
|
let startTime;
|
|
6415
6505
|
if (this.debug) {
|
|
6416
6506
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6421,10 +6511,10 @@ class XykService {
|
|
|
6421
6511
|
"X-Requested-With": userAgent
|
|
6422
6512
|
}
|
|
6423
6513
|
}));
|
|
6424
|
-
debugOutput(response.url, response.status
|
|
6425
|
-
if (response.status === null || response.status === 429) {
|
|
6514
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6515
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6426
6516
|
try {
|
|
6427
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6517
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6428
6518
|
}
|
|
6429
6519
|
catch (error) {
|
|
6430
6520
|
success = true;
|
|
@@ -6454,8 +6544,8 @@ class XykService {
|
|
|
6454
6544
|
return {
|
|
6455
6545
|
data: null,
|
|
6456
6546
|
error: true,
|
|
6457
|
-
error_code: data ? data.error_code : response.status,
|
|
6458
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6547
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6548
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6459
6549
|
};
|
|
6460
6550
|
}
|
|
6461
6551
|
}
|
|
@@ -6484,6 +6574,7 @@ class XykService {
|
|
|
6484
6574
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6485
6575
|
};
|
|
6486
6576
|
}
|
|
6577
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`;
|
|
6487
6578
|
let startTime;
|
|
6488
6579
|
if (this.debug) {
|
|
6489
6580
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6494,10 +6585,10 @@ class XykService {
|
|
|
6494
6585
|
"X-Requested-With": userAgent
|
|
6495
6586
|
}
|
|
6496
6587
|
}));
|
|
6497
|
-
debugOutput(response.url, response.status
|
|
6498
|
-
if (response.status === null || response.status === 429) {
|
|
6588
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6589
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6499
6590
|
try {
|
|
6500
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6591
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6501
6592
|
}
|
|
6502
6593
|
catch (error) {
|
|
6503
6594
|
success = true;
|
|
@@ -6527,8 +6618,8 @@ class XykService {
|
|
|
6527
6618
|
return {
|
|
6528
6619
|
data: null,
|
|
6529
6620
|
error: true,
|
|
6530
|
-
error_code: data ? data.error_code : response.status,
|
|
6531
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6621
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6622
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6532
6623
|
};
|
|
6533
6624
|
}
|
|
6534
6625
|
}
|
|
@@ -6555,6 +6646,7 @@ class XykService {
|
|
|
6555
6646
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6556
6647
|
};
|
|
6557
6648
|
}
|
|
6649
|
+
const url = `https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`;
|
|
6558
6650
|
let startTime;
|
|
6559
6651
|
if (this.debug) {
|
|
6560
6652
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6565,10 +6657,10 @@ class XykService {
|
|
|
6565
6657
|
"X-Requested-With": userAgent
|
|
6566
6658
|
}
|
|
6567
6659
|
}));
|
|
6568
|
-
debugOutput(response.url, response.status
|
|
6569
|
-
if (response.status === null || response.status === 429) {
|
|
6660
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6661
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6570
6662
|
try {
|
|
6571
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6663
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6572
6664
|
}
|
|
6573
6665
|
catch (error) {
|
|
6574
6666
|
success = true;
|
|
@@ -6598,8 +6690,8 @@ class XykService {
|
|
|
6598
6690
|
return {
|
|
6599
6691
|
data: null,
|
|
6600
6692
|
error: true,
|
|
6601
|
-
error_code: data ? data.error_code : response.status,
|
|
6602
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6693
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6694
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6603
6695
|
};
|
|
6604
6696
|
}
|
|
6605
6697
|
}
|
|
@@ -6629,6 +6721,7 @@ class XykService {
|
|
|
6629
6721
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6630
6722
|
};
|
|
6631
6723
|
}
|
|
6724
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`;
|
|
6632
6725
|
let startTime;
|
|
6633
6726
|
if (this.debug) {
|
|
6634
6727
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6639,10 +6732,10 @@ class XykService {
|
|
|
6639
6732
|
"X-Requested-With": userAgent
|
|
6640
6733
|
}
|
|
6641
6734
|
}));
|
|
6642
|
-
debugOutput(response.url, response.status
|
|
6643
|
-
if (response.status === null || response.status === 429) {
|
|
6735
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6736
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6644
6737
|
try {
|
|
6645
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6738
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6646
6739
|
}
|
|
6647
6740
|
catch (error) {
|
|
6648
6741
|
success = true;
|
|
@@ -6672,8 +6765,8 @@ class XykService {
|
|
|
6672
6765
|
return {
|
|
6673
6766
|
data: null,
|
|
6674
6767
|
error: true,
|
|
6675
|
-
error_code: data ? data.error_code : response.status,
|
|
6676
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6768
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6769
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6677
6770
|
};
|
|
6678
6771
|
}
|
|
6679
6772
|
}
|
|
@@ -6703,6 +6796,7 @@ class XykService {
|
|
|
6703
6796
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6704
6797
|
};
|
|
6705
6798
|
}
|
|
6799
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`;
|
|
6706
6800
|
let startTime;
|
|
6707
6801
|
if (this.debug) {
|
|
6708
6802
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6713,10 +6807,10 @@ class XykService {
|
|
|
6713
6807
|
"X-Requested-With": userAgent
|
|
6714
6808
|
}
|
|
6715
6809
|
}));
|
|
6716
|
-
debugOutput(response.url, response.status
|
|
6717
|
-
if (response.status === null || response.status === 429) {
|
|
6810
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6811
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6718
6812
|
try {
|
|
6719
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6813
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6720
6814
|
}
|
|
6721
6815
|
catch (error) {
|
|
6722
6816
|
success = true;
|
|
@@ -6746,8 +6840,8 @@ class XykService {
|
|
|
6746
6840
|
return {
|
|
6747
6841
|
data: null,
|
|
6748
6842
|
error: true,
|
|
6749
|
-
error_code: data ? data.error_code : response.status,
|
|
6750
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6843
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6844
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6751
6845
|
};
|
|
6752
6846
|
}
|
|
6753
6847
|
}
|
|
@@ -6777,6 +6871,7 @@ class XykService {
|
|
|
6777
6871
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6778
6872
|
};
|
|
6779
6873
|
}
|
|
6874
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
|
|
6780
6875
|
let startTime;
|
|
6781
6876
|
if (this.debug) {
|
|
6782
6877
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6787,10 +6882,10 @@ class XykService {
|
|
|
6787
6882
|
"X-Requested-With": userAgent
|
|
6788
6883
|
}
|
|
6789
6884
|
}));
|
|
6790
|
-
debugOutput(response.url, response.status
|
|
6791
|
-
if (response.status === null || response.status === 429) {
|
|
6885
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6886
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6792
6887
|
try {
|
|
6793
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6888
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6794
6889
|
}
|
|
6795
6890
|
catch (error) {
|
|
6796
6891
|
success = true;
|
|
@@ -6820,8 +6915,8 @@ class XykService {
|
|
|
6820
6915
|
return {
|
|
6821
6916
|
data: null,
|
|
6822
6917
|
error: true,
|
|
6823
|
-
error_code: data ? data.error_code : response.status,
|
|
6824
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6918
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6919
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6825
6920
|
};
|
|
6826
6921
|
}
|
|
6827
6922
|
}
|
|
@@ -6851,6 +6946,7 @@ class XykService {
|
|
|
6851
6946
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6852
6947
|
};
|
|
6853
6948
|
}
|
|
6949
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
|
|
6854
6950
|
let startTime;
|
|
6855
6951
|
if (this.debug) {
|
|
6856
6952
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6861,10 +6957,10 @@ class XykService {
|
|
|
6861
6957
|
"X-Requested-With": userAgent
|
|
6862
6958
|
}
|
|
6863
6959
|
}));
|
|
6864
|
-
debugOutput(response.url, response.status
|
|
6865
|
-
if (response.status === null || response.status === 429) {
|
|
6960
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6961
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6866
6962
|
try {
|
|
6867
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6963
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6868
6964
|
}
|
|
6869
6965
|
catch (error) {
|
|
6870
6966
|
success = true;
|
|
@@ -6894,8 +6990,8 @@ class XykService {
|
|
|
6894
6990
|
return {
|
|
6895
6991
|
data: null,
|
|
6896
6992
|
error: true,
|
|
6897
|
-
error_code: data ? data.error_code : response.status,
|
|
6898
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6993
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6994
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6899
6995
|
};
|
|
6900
6996
|
}
|
|
6901
6997
|
}
|
|
@@ -6924,6 +7020,7 @@ class XykService {
|
|
|
6924
7020
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6925
7021
|
};
|
|
6926
7022
|
}
|
|
7023
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`;
|
|
6927
7024
|
let startTime;
|
|
6928
7025
|
if (this.debug) {
|
|
6929
7026
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6934,10 +7031,10 @@ class XykService {
|
|
|
6934
7031
|
"X-Requested-With": userAgent
|
|
6935
7032
|
}
|
|
6936
7033
|
}));
|
|
6937
|
-
debugOutput(response.url, response.status
|
|
6938
|
-
if (response.status === null || response.status === 429) {
|
|
7034
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7035
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6939
7036
|
try {
|
|
6940
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7037
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6941
7038
|
}
|
|
6942
7039
|
catch (error) {
|
|
6943
7040
|
success = true;
|
|
@@ -6967,8 +7064,8 @@ class XykService {
|
|
|
6967
7064
|
return {
|
|
6968
7065
|
data: null,
|
|
6969
7066
|
error: true,
|
|
6970
|
-
error_code: data ? data.error_code : response.status,
|
|
6971
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7067
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7068
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6972
7069
|
};
|
|
6973
7070
|
}
|
|
6974
7071
|
}
|
|
@@ -6997,6 +7094,7 @@ class XykService {
|
|
|
6997
7094
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6998
7095
|
};
|
|
6999
7096
|
}
|
|
7097
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`;
|
|
7000
7098
|
let startTime;
|
|
7001
7099
|
if (this.debug) {
|
|
7002
7100
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -7007,10 +7105,10 @@ class XykService {
|
|
|
7007
7105
|
"X-Requested-With": userAgent
|
|
7008
7106
|
}
|
|
7009
7107
|
}));
|
|
7010
|
-
debugOutput(response.url, response.status
|
|
7011
|
-
if (response.status === null || response.status === 429) {
|
|
7108
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7109
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7012
7110
|
try {
|
|
7013
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7111
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7014
7112
|
}
|
|
7015
7113
|
catch (error) {
|
|
7016
7114
|
success = true;
|
|
@@ -7040,30 +7138,30 @@ class XykService {
|
|
|
7040
7138
|
return {
|
|
7041
7139
|
data: null,
|
|
7042
7140
|
error: true,
|
|
7043
|
-
error_code: data ? data.error_code : response.status,
|
|
7044
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7141
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7142
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7045
7143
|
};
|
|
7046
7144
|
}
|
|
7047
7145
|
}
|
|
7048
7146
|
}
|
|
7049
7147
|
}
|
|
7050
7148
|
|
|
7051
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.7.
|
|
7149
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.7.6";
|
|
7052
7150
|
/**
|
|
7053
7151
|
* CovalentClient Class
|
|
7054
7152
|
*/
|
|
7055
7153
|
class CovalentClient {
|
|
7056
7154
|
constructor(apiKey, settings) {
|
|
7057
|
-
const { debug = false, threadCount = 3 } = settings || {};
|
|
7155
|
+
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7058
7156
|
const validator = new ApiKeyValidator(apiKey);
|
|
7059
7157
|
this._is_key_valid = validator.isValidApiKey();
|
|
7060
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7061
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7062
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7063
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7064
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7065
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7066
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7158
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7159
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7160
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7161
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7162
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7163
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7164
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7067
7165
|
}
|
|
7068
7166
|
}
|
|
7069
7167
|
/**
|
|
@@ -7074,16 +7172,16 @@ class CovalentClient {
|
|
|
7074
7172
|
*/
|
|
7075
7173
|
class Client {
|
|
7076
7174
|
constructor(apiKey, settings) {
|
|
7077
|
-
const { debug = false, threadCount = 3 } = settings || {};
|
|
7175
|
+
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7078
7176
|
const validator = new ApiKeyValidator(apiKey);
|
|
7079
7177
|
this._is_key_valid = validator.isValidApiKey();
|
|
7080
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7081
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7082
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7083
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7084
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7085
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7086
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7178
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7179
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7180
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7181
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7182
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7183
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7184
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7087
7185
|
}
|
|
7088
7186
|
}
|
|
7089
7187
|
|