@covalenthq/client-sdk 0.7.4 → 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 +461 -362
- 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 +68 -13
- package/dist/cjs/util/ApiHelpers.d.ts +1 -1
- package/dist/cjs/util/types/XykServiceTypes.d.ts +52 -13
- package/dist/es/index.js +461 -362
- 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 +68 -13
- package/dist/es/util/ApiHelpers.d.ts +1 -1
- package/dist/es/util/types/XykServiceTypes.d.ts +52 -13
- package/dist/esm/index.js +461 -362
- 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 +68 -13
- package/dist/esm/util/ApiHelpers.d.ts +1 -1
- package/dist/esm/util/types/XykServiceTypes.d.ts +52 -13
- 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 +68 -13
- package/dist/services/XykService.js +128 -83
- 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 +52 -13
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -221,7 +221,7 @@ async function debugOutput(url, responseStatus, startTime) {
|
|
|
221
221
|
}
|
|
222
222
|
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")}`);
|
|
223
223
|
}
|
|
224
|
-
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount) {
|
|
224
|
+
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry) {
|
|
225
225
|
let hasNext = true;
|
|
226
226
|
let response;
|
|
227
227
|
let data;
|
|
@@ -234,20 +234,21 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
|
|
|
234
234
|
if (debug) {
|
|
235
235
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
236
236
|
}
|
|
237
|
+
const link = urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`;
|
|
237
238
|
response = await LIMIT(() => fetch(urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`, {
|
|
238
239
|
headers: {
|
|
239
240
|
"Authorization": `Bearer ${apiKey}`,
|
|
240
241
|
"X-Requested-With": userAgent
|
|
241
242
|
}
|
|
242
243
|
}));
|
|
243
|
-
debugOutput(response.url, response.status
|
|
244
|
-
if (response.status === null || response.status === 429) {
|
|
244
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
245
|
+
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
245
246
|
try {
|
|
246
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
247
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : link));
|
|
247
248
|
}
|
|
248
249
|
catch (error) {
|
|
249
250
|
hasNext = false;
|
|
250
|
-
throw new Error(`An error occurred ${response.status
|
|
251
|
+
throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
else {
|
|
@@ -385,11 +386,12 @@ class NftApprovalSpender {
|
|
|
385
386
|
*
|
|
386
387
|
*/
|
|
387
388
|
class SecurityService {
|
|
388
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
389
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
389
390
|
this.apiKey = apiKey;
|
|
390
391
|
this.debug = debug;
|
|
391
392
|
this.threadCount = threadCount;
|
|
392
393
|
this.is_key_valid = is_key_valid;
|
|
394
|
+
this.enableRetry = enableRetry;
|
|
393
395
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
394
396
|
}
|
|
395
397
|
/**
|
|
@@ -408,6 +410,7 @@ class SecurityService {
|
|
|
408
410
|
while (!success) {
|
|
409
411
|
try {
|
|
410
412
|
const urlParams = new URLSearchParams();
|
|
413
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`;
|
|
411
414
|
if (!this.is_key_valid) {
|
|
412
415
|
return {
|
|
413
416
|
data: null,
|
|
@@ -426,10 +429,10 @@ class SecurityService {
|
|
|
426
429
|
"X-Requested-With": userAgent
|
|
427
430
|
}
|
|
428
431
|
}));
|
|
429
|
-
debugOutput(response.url, response.status
|
|
430
|
-
if (response.status === null || response.status === 429) {
|
|
432
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
433
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
431
434
|
try {
|
|
432
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
435
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
433
436
|
}
|
|
434
437
|
catch (error) {
|
|
435
438
|
success = true;
|
|
@@ -459,8 +462,8 @@ class SecurityService {
|
|
|
459
462
|
return {
|
|
460
463
|
data: null,
|
|
461
464
|
error: true,
|
|
462
|
-
error_code: data ? data.error_code : response.status,
|
|
463
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
465
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
466
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
464
467
|
};
|
|
465
468
|
}
|
|
466
469
|
}
|
|
@@ -480,6 +483,7 @@ class SecurityService {
|
|
|
480
483
|
while (!success) {
|
|
481
484
|
try {
|
|
482
485
|
const urlParams = new URLSearchParams();
|
|
486
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`;
|
|
483
487
|
if (!this.is_key_valid) {
|
|
484
488
|
return {
|
|
485
489
|
data: null,
|
|
@@ -498,10 +502,10 @@ class SecurityService {
|
|
|
498
502
|
"X-Requested-With": userAgent
|
|
499
503
|
}
|
|
500
504
|
}));
|
|
501
|
-
debugOutput(response.url, response.status
|
|
502
|
-
if (response.status === null || response.status === 429) {
|
|
505
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
506
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
503
507
|
try {
|
|
504
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
508
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
505
509
|
}
|
|
506
510
|
catch (error) {
|
|
507
511
|
success = true;
|
|
@@ -531,8 +535,8 @@ class SecurityService {
|
|
|
531
535
|
return {
|
|
532
536
|
data: null,
|
|
533
537
|
error: true,
|
|
534
|
-
error_code: data ? data.error_code : response.status,
|
|
535
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
538
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
539
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
536
540
|
};
|
|
537
541
|
}
|
|
538
542
|
}
|
|
@@ -820,11 +824,12 @@ class NativeBalanceItem {
|
|
|
820
824
|
*
|
|
821
825
|
*/
|
|
822
826
|
class BalanceService {
|
|
823
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
827
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
824
828
|
this.apiKey = apiKey;
|
|
825
829
|
this.debug = debug;
|
|
826
830
|
this.threadCount = threadCount;
|
|
827
831
|
this.is_key_valid = is_key_valid;
|
|
832
|
+
this.enableRetry = enableRetry;
|
|
828
833
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
829
834
|
}
|
|
830
835
|
/**
|
|
@@ -872,6 +877,7 @@ class BalanceService {
|
|
|
872
877
|
if (queryParamOpts?.noNftAssetMetadata !== undefined) {
|
|
873
878
|
urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
|
|
874
879
|
}
|
|
880
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`;
|
|
875
881
|
let startTime;
|
|
876
882
|
if (this.debug) {
|
|
877
883
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -882,10 +888,10 @@ class BalanceService {
|
|
|
882
888
|
"X-Requested-With": userAgent
|
|
883
889
|
}
|
|
884
890
|
}));
|
|
885
|
-
debugOutput(response.url, response.status
|
|
886
|
-
if (response.status === null || response.status === 429) {
|
|
891
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
892
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
887
893
|
try {
|
|
888
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
894
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
889
895
|
}
|
|
890
896
|
catch (error) {
|
|
891
897
|
success = true;
|
|
@@ -915,8 +921,8 @@ class BalanceService {
|
|
|
915
921
|
return {
|
|
916
922
|
data: null,
|
|
917
923
|
error: true,
|
|
918
|
-
error_code: data ? data.error_code : response.status,
|
|
919
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
924
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
925
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
920
926
|
};
|
|
921
927
|
}
|
|
922
928
|
}
|
|
@@ -954,6 +960,7 @@ class BalanceService {
|
|
|
954
960
|
if (queryParamOpts?.days !== undefined) {
|
|
955
961
|
urlParams.append("days", queryParamOpts?.days.toString());
|
|
956
962
|
}
|
|
963
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`;
|
|
957
964
|
let startTime;
|
|
958
965
|
if (this.debug) {
|
|
959
966
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -964,10 +971,10 @@ class BalanceService {
|
|
|
964
971
|
"X-Requested-With": userAgent
|
|
965
972
|
}
|
|
966
973
|
}));
|
|
967
|
-
debugOutput(response.url, response.status
|
|
968
|
-
if (response.status === null || response.status === 429) {
|
|
974
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
975
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
969
976
|
try {
|
|
970
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
977
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
971
978
|
}
|
|
972
979
|
catch (error) {
|
|
973
980
|
success = true;
|
|
@@ -997,8 +1004,8 @@ class BalanceService {
|
|
|
997
1004
|
return {
|
|
998
1005
|
data: null,
|
|
999
1006
|
error: true,
|
|
1000
|
-
error_code: data ? data.error_code : response.status,
|
|
1001
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1007
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1008
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1002
1009
|
};
|
|
1003
1010
|
}
|
|
1004
1011
|
}
|
|
@@ -1045,7 +1052,7 @@ class BalanceService {
|
|
|
1045
1052
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1046
1053
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1047
1054
|
}
|
|
1048
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount)) {
|
|
1055
|
+
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)) {
|
|
1049
1056
|
yield res;
|
|
1050
1057
|
}
|
|
1051
1058
|
success = true;
|
|
@@ -1105,6 +1112,7 @@ class BalanceService {
|
|
|
1105
1112
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1106
1113
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1107
1114
|
}
|
|
1115
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`;
|
|
1108
1116
|
let startTime;
|
|
1109
1117
|
if (this.debug) {
|
|
1110
1118
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1115,10 +1123,10 @@ class BalanceService {
|
|
|
1115
1123
|
"X-Requested-With": userAgent
|
|
1116
1124
|
}
|
|
1117
1125
|
}));
|
|
1118
|
-
debugOutput(response.url, response.status
|
|
1119
|
-
if (response.status === null || response.status === 429) {
|
|
1126
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1127
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1120
1128
|
try {
|
|
1121
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1129
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1122
1130
|
}
|
|
1123
1131
|
catch (error) {
|
|
1124
1132
|
success = true;
|
|
@@ -1148,8 +1156,8 @@ class BalanceService {
|
|
|
1148
1156
|
return {
|
|
1149
1157
|
data: null,
|
|
1150
1158
|
error: true,
|
|
1151
|
-
error_code: data ? data.error_code : response.status,
|
|
1152
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1159
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1160
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1153
1161
|
};
|
|
1154
1162
|
}
|
|
1155
1163
|
}
|
|
@@ -1188,7 +1196,7 @@ class BalanceService {
|
|
|
1188
1196
|
if (queryParamOpts?.date !== undefined) {
|
|
1189
1197
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1190
1198
|
}
|
|
1191
|
-
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)) {
|
|
1199
|
+
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)) {
|
|
1192
1200
|
yield res;
|
|
1193
1201
|
}
|
|
1194
1202
|
success = true;
|
|
@@ -1240,6 +1248,7 @@ class BalanceService {
|
|
|
1240
1248
|
if (queryParamOpts?.date !== undefined) {
|
|
1241
1249
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1242
1250
|
}
|
|
1251
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`;
|
|
1243
1252
|
let startTime;
|
|
1244
1253
|
if (this.debug) {
|
|
1245
1254
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1250,10 +1259,10 @@ class BalanceService {
|
|
|
1250
1259
|
"X-Requested-With": userAgent
|
|
1251
1260
|
}
|
|
1252
1261
|
}));
|
|
1253
|
-
debugOutput(response.url, response.status
|
|
1254
|
-
if (response.status === null || response.status === 429) {
|
|
1262
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1263
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1255
1264
|
try {
|
|
1256
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1265
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1257
1266
|
}
|
|
1258
1267
|
catch (error) {
|
|
1259
1268
|
success = true;
|
|
@@ -1283,8 +1292,8 @@ class BalanceService {
|
|
|
1283
1292
|
return {
|
|
1284
1293
|
data: null,
|
|
1285
1294
|
error: true,
|
|
1286
|
-
error_code: data ? data.error_code : response.status,
|
|
1287
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1295
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1296
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1288
1297
|
};
|
|
1289
1298
|
}
|
|
1290
1299
|
}
|
|
@@ -1342,6 +1351,7 @@ class BalanceService {
|
|
|
1342
1351
|
if (queryParamOpts?.date !== undefined) {
|
|
1343
1352
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1344
1353
|
}
|
|
1354
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`;
|
|
1345
1355
|
let startTime;
|
|
1346
1356
|
if (this.debug) {
|
|
1347
1357
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1352,10 +1362,10 @@ class BalanceService {
|
|
|
1352
1362
|
"X-Requested-With": userAgent
|
|
1353
1363
|
}
|
|
1354
1364
|
}));
|
|
1355
|
-
debugOutput(response.url, response.status
|
|
1356
|
-
if (response.status === null || response.status === 429) {
|
|
1365
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1366
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1357
1367
|
try {
|
|
1358
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1368
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1359
1369
|
}
|
|
1360
1370
|
catch (error) {
|
|
1361
1371
|
success = true;
|
|
@@ -1385,8 +1395,8 @@ class BalanceService {
|
|
|
1385
1395
|
return {
|
|
1386
1396
|
data: null,
|
|
1387
1397
|
error: true,
|
|
1388
|
-
error_code: data ? data.error_code : response.status,
|
|
1389
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1398
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1399
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1390
1400
|
};
|
|
1391
1401
|
}
|
|
1392
1402
|
}
|
|
@@ -1422,6 +1432,7 @@ class BalanceService {
|
|
|
1422
1432
|
if (queryParamOpts?.blockHeight !== undefined) {
|
|
1423
1433
|
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
1424
1434
|
}
|
|
1435
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`;
|
|
1425
1436
|
let startTime;
|
|
1426
1437
|
if (this.debug) {
|
|
1427
1438
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1432,10 +1443,10 @@ class BalanceService {
|
|
|
1432
1443
|
"X-Requested-With": userAgent
|
|
1433
1444
|
}
|
|
1434
1445
|
}));
|
|
1435
|
-
debugOutput(response.url, response.status
|
|
1436
|
-
if (response.status === null || response.status === 429) {
|
|
1446
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1447
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1437
1448
|
try {
|
|
1438
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1449
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1439
1450
|
}
|
|
1440
1451
|
catch (error) {
|
|
1441
1452
|
success = true;
|
|
@@ -1465,8 +1476,8 @@ class BalanceService {
|
|
|
1465
1476
|
return {
|
|
1466
1477
|
data: null,
|
|
1467
1478
|
error: true,
|
|
1468
|
-
error_code: data ? data.error_code : response.status,
|
|
1469
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1479
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1480
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1470
1481
|
};
|
|
1471
1482
|
}
|
|
1472
1483
|
}
|
|
@@ -1694,11 +1705,12 @@ class OtherFees {
|
|
|
1694
1705
|
*
|
|
1695
1706
|
*/
|
|
1696
1707
|
class BaseService {
|
|
1697
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
1708
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
1698
1709
|
this.apiKey = apiKey;
|
|
1699
1710
|
this.debug = debug;
|
|
1700
1711
|
this.threadCount = threadCount;
|
|
1701
1712
|
this.is_key_valid = is_key_valid;
|
|
1713
|
+
this.enableRetry = enableRetry;
|
|
1702
1714
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
1703
1715
|
}
|
|
1704
1716
|
/**
|
|
@@ -1725,6 +1737,7 @@ class BaseService {
|
|
|
1725
1737
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1726
1738
|
};
|
|
1727
1739
|
}
|
|
1740
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`;
|
|
1728
1741
|
let startTime;
|
|
1729
1742
|
if (this.debug) {
|
|
1730
1743
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1735,10 +1748,10 @@ class BaseService {
|
|
|
1735
1748
|
"X-Requested-With": userAgent
|
|
1736
1749
|
}
|
|
1737
1750
|
}));
|
|
1738
|
-
debugOutput(response.url, response.status
|
|
1739
|
-
if (response.status === null || response.status === 429) {
|
|
1751
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1752
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1740
1753
|
try {
|
|
1741
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1754
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1742
1755
|
}
|
|
1743
1756
|
catch (error) {
|
|
1744
1757
|
success = true;
|
|
@@ -1768,8 +1781,8 @@ class BaseService {
|
|
|
1768
1781
|
return {
|
|
1769
1782
|
data: null,
|
|
1770
1783
|
error: true,
|
|
1771
|
-
error_code: data ? data.error_code : response.status,
|
|
1772
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1784
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1785
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1773
1786
|
};
|
|
1774
1787
|
}
|
|
1775
1788
|
}
|
|
@@ -1798,6 +1811,7 @@ class BaseService {
|
|
|
1798
1811
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1799
1812
|
};
|
|
1800
1813
|
}
|
|
1814
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`;
|
|
1801
1815
|
let startTime;
|
|
1802
1816
|
if (this.debug) {
|
|
1803
1817
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1808,10 +1822,10 @@ class BaseService {
|
|
|
1808
1822
|
"X-Requested-With": userAgent
|
|
1809
1823
|
}
|
|
1810
1824
|
}));
|
|
1811
|
-
debugOutput(response.url, response.status
|
|
1812
|
-
if (response.status === null || response.status === 429) {
|
|
1825
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1826
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1813
1827
|
try {
|
|
1814
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1828
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1815
1829
|
}
|
|
1816
1830
|
catch (error) {
|
|
1817
1831
|
success = true;
|
|
@@ -1841,8 +1855,8 @@ class BaseService {
|
|
|
1841
1855
|
return {
|
|
1842
1856
|
data: null,
|
|
1843
1857
|
error: true,
|
|
1844
|
-
error_code: data ? data.error_code : response.status,
|
|
1845
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1858
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1859
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1846
1860
|
};
|
|
1847
1861
|
}
|
|
1848
1862
|
}
|
|
@@ -1874,7 +1888,7 @@ class BaseService {
|
|
|
1874
1888
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1875
1889
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1876
1890
|
}
|
|
1877
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount)) {
|
|
1891
|
+
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)) {
|
|
1878
1892
|
yield res;
|
|
1879
1893
|
}
|
|
1880
1894
|
success = true;
|
|
@@ -1919,6 +1933,7 @@ class BaseService {
|
|
|
1919
1933
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1920
1934
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1921
1935
|
}
|
|
1936
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`;
|
|
1922
1937
|
let startTime;
|
|
1923
1938
|
if (this.debug) {
|
|
1924
1939
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1929,10 +1944,10 @@ class BaseService {
|
|
|
1929
1944
|
"X-Requested-With": userAgent
|
|
1930
1945
|
}
|
|
1931
1946
|
}));
|
|
1932
|
-
debugOutput(response.url, response.status
|
|
1933
|
-
if (response.status === null || response.status === 429) {
|
|
1947
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1948
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1934
1949
|
try {
|
|
1935
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1950
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1936
1951
|
}
|
|
1937
1952
|
catch (error) {
|
|
1938
1953
|
success = true;
|
|
@@ -1962,8 +1977,8 @@ class BaseService {
|
|
|
1962
1977
|
return {
|
|
1963
1978
|
data: null,
|
|
1964
1979
|
error: true,
|
|
1965
|
-
error_code: data ? data.error_code : response.status,
|
|
1966
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1980
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1981
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1967
1982
|
};
|
|
1968
1983
|
}
|
|
1969
1984
|
}
|
|
@@ -2016,6 +2031,7 @@ class BaseService {
|
|
|
2016
2031
|
if (queryParamOpts?.skipDecode !== undefined) {
|
|
2017
2032
|
urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
|
|
2018
2033
|
}
|
|
2034
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`;
|
|
2019
2035
|
let startTime;
|
|
2020
2036
|
if (this.debug) {
|
|
2021
2037
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2026,10 +2042,10 @@ class BaseService {
|
|
|
2026
2042
|
"X-Requested-With": userAgent
|
|
2027
2043
|
}
|
|
2028
2044
|
}));
|
|
2029
|
-
debugOutput(response.url, response.status
|
|
2030
|
-
if (response.status === null || response.status === 429) {
|
|
2045
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2046
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2031
2047
|
try {
|
|
2032
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2048
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2033
2049
|
}
|
|
2034
2050
|
catch (error) {
|
|
2035
2051
|
success = true;
|
|
@@ -2059,8 +2075,8 @@ class BaseService {
|
|
|
2059
2075
|
return {
|
|
2060
2076
|
data: null,
|
|
2061
2077
|
error: true,
|
|
2062
|
-
error_code: data ? data.error_code : response.status,
|
|
2063
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2078
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2079
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2064
2080
|
};
|
|
2065
2081
|
}
|
|
2066
2082
|
}
|
|
@@ -2099,7 +2115,7 @@ class BaseService {
|
|
|
2099
2115
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2100
2116
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2101
2117
|
}
|
|
2102
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
2118
|
+
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)) {
|
|
2103
2119
|
yield res;
|
|
2104
2120
|
}
|
|
2105
2121
|
success = true;
|
|
@@ -2151,6 +2167,7 @@ class BaseService {
|
|
|
2151
2167
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2152
2168
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2153
2169
|
}
|
|
2170
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`;
|
|
2154
2171
|
let startTime;
|
|
2155
2172
|
if (this.debug) {
|
|
2156
2173
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2161,10 +2178,10 @@ class BaseService {
|
|
|
2161
2178
|
"X-Requested-With": userAgent
|
|
2162
2179
|
}
|
|
2163
2180
|
}));
|
|
2164
|
-
debugOutput(response.url, response.status
|
|
2165
|
-
if (response.status === null || response.status === 429) {
|
|
2181
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2182
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2166
2183
|
try {
|
|
2167
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2184
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2168
2185
|
}
|
|
2169
2186
|
catch (error) {
|
|
2170
2187
|
success = true;
|
|
@@ -2194,8 +2211,8 @@ class BaseService {
|
|
|
2194
2211
|
return {
|
|
2195
2212
|
data: null,
|
|
2196
2213
|
error: true,
|
|
2197
|
-
error_code: data ? data.error_code : response.status,
|
|
2198
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2214
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2215
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2199
2216
|
};
|
|
2200
2217
|
}
|
|
2201
2218
|
}
|
|
@@ -2238,7 +2255,7 @@ class BaseService {
|
|
|
2238
2255
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2239
2256
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2240
2257
|
}
|
|
2241
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
2258
|
+
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)) {
|
|
2242
2259
|
yield res;
|
|
2243
2260
|
}
|
|
2244
2261
|
success = true;
|
|
@@ -2294,6 +2311,7 @@ class BaseService {
|
|
|
2294
2311
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2295
2312
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2296
2313
|
}
|
|
2314
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`;
|
|
2297
2315
|
let startTime;
|
|
2298
2316
|
if (this.debug) {
|
|
2299
2317
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2304,10 +2322,10 @@ class BaseService {
|
|
|
2304
2322
|
"X-Requested-With": userAgent
|
|
2305
2323
|
}
|
|
2306
2324
|
}));
|
|
2307
|
-
debugOutput(response.url, response.status
|
|
2308
|
-
if (response.status === null || response.status === 429) {
|
|
2325
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2326
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2309
2327
|
try {
|
|
2310
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2328
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2311
2329
|
}
|
|
2312
2330
|
catch (error) {
|
|
2313
2331
|
success = true;
|
|
@@ -2337,8 +2355,8 @@ class BaseService {
|
|
|
2337
2355
|
return {
|
|
2338
2356
|
data: null,
|
|
2339
2357
|
error: true,
|
|
2340
|
-
error_code: data ? data.error_code : response.status,
|
|
2341
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2358
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2359
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2342
2360
|
};
|
|
2343
2361
|
}
|
|
2344
2362
|
}
|
|
@@ -2369,16 +2387,17 @@ class BaseService {
|
|
|
2369
2387
|
if (this.debug) {
|
|
2370
2388
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
2371
2389
|
}
|
|
2390
|
+
const url = `https://api.covalenthq.com/v1/chains/?${urlParams}`;
|
|
2372
2391
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
|
|
2373
2392
|
headers: {
|
|
2374
2393
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2375
2394
|
"X-Requested-With": userAgent
|
|
2376
2395
|
}
|
|
2377
2396
|
}));
|
|
2378
|
-
debugOutput(response.url, response.status
|
|
2379
|
-
if (response.status === null || response.status === 429) {
|
|
2397
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2398
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2380
2399
|
try {
|
|
2381
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2400
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2382
2401
|
}
|
|
2383
2402
|
catch (error) {
|
|
2384
2403
|
success = true;
|
|
@@ -2408,8 +2427,8 @@ class BaseService {
|
|
|
2408
2427
|
return {
|
|
2409
2428
|
data: null,
|
|
2410
2429
|
error: true,
|
|
2411
|
-
error_code: data ? data.error_code : response.status,
|
|
2412
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2430
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2431
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2413
2432
|
};
|
|
2414
2433
|
}
|
|
2415
2434
|
}
|
|
@@ -2436,6 +2455,7 @@ class BaseService {
|
|
|
2436
2455
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
2437
2456
|
};
|
|
2438
2457
|
}
|
|
2458
|
+
const url = `https://api.covalenthq.com/v1/chains/status/?${urlParams}`;
|
|
2439
2459
|
let startTime;
|
|
2440
2460
|
if (this.debug) {
|
|
2441
2461
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2446,10 +2466,10 @@ class BaseService {
|
|
|
2446
2466
|
"X-Requested-With": userAgent
|
|
2447
2467
|
}
|
|
2448
2468
|
}));
|
|
2449
|
-
debugOutput(response.url, response.status
|
|
2450
|
-
if (response.status === null || response.status === 429) {
|
|
2469
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2470
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2451
2471
|
try {
|
|
2452
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2472
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2453
2473
|
}
|
|
2454
2474
|
catch (error) {
|
|
2455
2475
|
success = true;
|
|
@@ -2479,8 +2499,8 @@ class BaseService {
|
|
|
2479
2499
|
return {
|
|
2480
2500
|
data: null,
|
|
2481
2501
|
error: true,
|
|
2482
|
-
error_code: data ? data.error_code : response.status,
|
|
2483
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2502
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2503
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2484
2504
|
};
|
|
2485
2505
|
}
|
|
2486
2506
|
}
|
|
@@ -2513,6 +2533,7 @@ class BaseService {
|
|
|
2513
2533
|
if (queryParamOpts?.testnets !== undefined) {
|
|
2514
2534
|
urlParams.append("testnets", queryParamOpts?.testnets.toString());
|
|
2515
2535
|
}
|
|
2536
|
+
const url = `https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`;
|
|
2516
2537
|
let startTime;
|
|
2517
2538
|
if (this.debug) {
|
|
2518
2539
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2523,10 +2544,10 @@ class BaseService {
|
|
|
2523
2544
|
"X-Requested-With": userAgent
|
|
2524
2545
|
}
|
|
2525
2546
|
}));
|
|
2526
|
-
debugOutput(response.url, response.status
|
|
2527
|
-
if (response.status === null || response.status === 429) {
|
|
2547
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2548
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2528
2549
|
try {
|
|
2529
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2550
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2530
2551
|
}
|
|
2531
2552
|
catch (error) {
|
|
2532
2553
|
success = true;
|
|
@@ -2556,8 +2577,8 @@ class BaseService {
|
|
|
2556
2577
|
return {
|
|
2557
2578
|
data: null,
|
|
2558
2579
|
error: true,
|
|
2559
|
-
error_code: data ? data.error_code : response.status,
|
|
2560
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2580
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2581
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2561
2582
|
};
|
|
2562
2583
|
}
|
|
2563
2584
|
}
|
|
@@ -2589,6 +2610,7 @@ class BaseService {
|
|
|
2589
2610
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
2590
2611
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
2591
2612
|
}
|
|
2613
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`;
|
|
2592
2614
|
let startTime;
|
|
2593
2615
|
if (this.debug) {
|
|
2594
2616
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2599,17 +2621,17 @@ class BaseService {
|
|
|
2599
2621
|
"X-Requested-With": userAgent
|
|
2600
2622
|
}
|
|
2601
2623
|
}));
|
|
2602
|
-
debugOutput(response.url, response.status, startTime);
|
|
2603
|
-
if (response.status === 429) {
|
|
2624
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2625
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2604
2626
|
try {
|
|
2605
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2627
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2606
2628
|
}
|
|
2607
2629
|
catch (error) {
|
|
2608
2630
|
success = true;
|
|
2609
2631
|
return {
|
|
2610
2632
|
data: null,
|
|
2611
2633
|
error: true,
|
|
2612
|
-
error_code: response.status,
|
|
2634
|
+
error_code: response.status ?? 429,
|
|
2613
2635
|
error_message: error.message
|
|
2614
2636
|
};
|
|
2615
2637
|
}
|
|
@@ -2632,8 +2654,8 @@ class BaseService {
|
|
|
2632
2654
|
return {
|
|
2633
2655
|
data: null,
|
|
2634
2656
|
error: true,
|
|
2635
|
-
error_code: data ? data.error_code : response.status,
|
|
2636
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2657
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2658
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2637
2659
|
};
|
|
2638
2660
|
}
|
|
2639
2661
|
}
|
|
@@ -2962,11 +2984,12 @@ class MarketFloorPriceItem {
|
|
|
2962
2984
|
*
|
|
2963
2985
|
*/
|
|
2964
2986
|
class NftService {
|
|
2965
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
2987
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
2966
2988
|
this.apiKey = apiKey;
|
|
2967
2989
|
this.debug = debug;
|
|
2968
2990
|
this.threadCount = threadCount;
|
|
2969
2991
|
this.is_key_valid = is_key_valid;
|
|
2992
|
+
this.enableRetry = enableRetry;
|
|
2970
2993
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
2971
2994
|
}
|
|
2972
2995
|
/**
|
|
@@ -2998,7 +3021,7 @@ class NftService {
|
|
|
2998
3021
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
2999
3022
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3000
3023
|
}
|
|
3001
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
|
|
3024
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry)) {
|
|
3002
3025
|
yield res;
|
|
3003
3026
|
}
|
|
3004
3027
|
success = true;
|
|
@@ -3045,6 +3068,7 @@ class NftService {
|
|
|
3045
3068
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3046
3069
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3047
3070
|
}
|
|
3071
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`;
|
|
3048
3072
|
let startTime;
|
|
3049
3073
|
if (this.debug) {
|
|
3050
3074
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3055,10 +3079,10 @@ class NftService {
|
|
|
3055
3079
|
"X-Requested-With": userAgent
|
|
3056
3080
|
}
|
|
3057
3081
|
}));
|
|
3058
|
-
debugOutput(response.url, response.status
|
|
3059
|
-
if (response.status === null || response.status === 429) {
|
|
3082
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3083
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3060
3084
|
try {
|
|
3061
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3085
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3062
3086
|
}
|
|
3063
3087
|
catch (error) {
|
|
3064
3088
|
success = true;
|
|
@@ -3088,8 +3112,8 @@ class NftService {
|
|
|
3088
3112
|
return {
|
|
3089
3113
|
data: null,
|
|
3090
3114
|
error: true,
|
|
3091
|
-
error_code: data ? data.error_code : response.status,
|
|
3092
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3115
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3116
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3093
3117
|
};
|
|
3094
3118
|
}
|
|
3095
3119
|
}
|
|
@@ -3131,6 +3155,7 @@ class NftService {
|
|
|
3131
3155
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3132
3156
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3133
3157
|
}
|
|
3158
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`;
|
|
3134
3159
|
let startTime;
|
|
3135
3160
|
if (this.debug) {
|
|
3136
3161
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3141,10 +3166,10 @@ class NftService {
|
|
|
3141
3166
|
"X-Requested-With": userAgent
|
|
3142
3167
|
}
|
|
3143
3168
|
}));
|
|
3144
|
-
debugOutput(response.url, response.status
|
|
3145
|
-
if (response.status === null || response.status === 429) {
|
|
3169
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3170
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3146
3171
|
try {
|
|
3147
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3172
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3148
3173
|
}
|
|
3149
3174
|
catch (error) {
|
|
3150
3175
|
success = true;
|
|
@@ -3174,8 +3199,8 @@ class NftService {
|
|
|
3174
3199
|
return {
|
|
3175
3200
|
data: null,
|
|
3176
3201
|
error: true,
|
|
3177
|
-
error_code: data ? data.error_code : response.status,
|
|
3178
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3202
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3203
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3179
3204
|
};
|
|
3180
3205
|
}
|
|
3181
3206
|
}
|
|
@@ -3222,7 +3247,7 @@ class NftService {
|
|
|
3222
3247
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3223
3248
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3224
3249
|
}
|
|
3225
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
|
|
3250
|
+
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)) {
|
|
3226
3251
|
yield res;
|
|
3227
3252
|
}
|
|
3228
3253
|
success = true;
|
|
@@ -3282,6 +3307,7 @@ class NftService {
|
|
|
3282
3307
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3283
3308
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3284
3309
|
}
|
|
3310
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`;
|
|
3285
3311
|
let startTime;
|
|
3286
3312
|
if (this.debug) {
|
|
3287
3313
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3292,10 +3318,10 @@ class NftService {
|
|
|
3292
3318
|
"X-Requested-With": userAgent
|
|
3293
3319
|
}
|
|
3294
3320
|
}));
|
|
3295
|
-
debugOutput(response.url, response.status
|
|
3296
|
-
if (response.status === null || response.status === 429) {
|
|
3321
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3322
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3297
3323
|
try {
|
|
3298
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3324
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3299
3325
|
}
|
|
3300
3326
|
catch (error) {
|
|
3301
3327
|
success = true;
|
|
@@ -3325,8 +3351,8 @@ class NftService {
|
|
|
3325
3351
|
return {
|
|
3326
3352
|
data: null,
|
|
3327
3353
|
error: true,
|
|
3328
|
-
error_code: data ? data.error_code : response.status,
|
|
3329
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3354
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3355
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3330
3356
|
};
|
|
3331
3357
|
}
|
|
3332
3358
|
}
|
|
@@ -3365,6 +3391,7 @@ class NftService {
|
|
|
3365
3391
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3366
3392
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3367
3393
|
}
|
|
3394
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`;
|
|
3368
3395
|
let startTime;
|
|
3369
3396
|
if (this.debug) {
|
|
3370
3397
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3375,10 +3402,10 @@ class NftService {
|
|
|
3375
3402
|
"X-Requested-With": userAgent
|
|
3376
3403
|
}
|
|
3377
3404
|
}));
|
|
3378
|
-
debugOutput(response.url, response.status
|
|
3379
|
-
if (response.status === null || response.status === 429) {
|
|
3405
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3406
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3380
3407
|
try {
|
|
3381
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3408
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3382
3409
|
}
|
|
3383
3410
|
catch (error) {
|
|
3384
3411
|
success = true;
|
|
@@ -3408,8 +3435,8 @@ class NftService {
|
|
|
3408
3435
|
return {
|
|
3409
3436
|
data: null,
|
|
3410
3437
|
error: true,
|
|
3411
|
-
error_code: data ? data.error_code : response.status,
|
|
3412
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3438
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3439
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3413
3440
|
};
|
|
3414
3441
|
}
|
|
3415
3442
|
}
|
|
@@ -3444,6 +3471,7 @@ class NftService {
|
|
|
3444
3471
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3445
3472
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3446
3473
|
}
|
|
3474
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`;
|
|
3447
3475
|
let startTime;
|
|
3448
3476
|
if (this.debug) {
|
|
3449
3477
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3454,10 +3482,10 @@ class NftService {
|
|
|
3454
3482
|
"X-Requested-With": userAgent
|
|
3455
3483
|
}
|
|
3456
3484
|
}));
|
|
3457
|
-
debugOutput(response.url, response.status
|
|
3458
|
-
if (response.status === null || response.status === 429) {
|
|
3485
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3486
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3459
3487
|
try {
|
|
3460
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3488
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3461
3489
|
}
|
|
3462
3490
|
catch (error) {
|
|
3463
3491
|
success = true;
|
|
@@ -3487,8 +3515,8 @@ class NftService {
|
|
|
3487
3515
|
return {
|
|
3488
3516
|
data: null,
|
|
3489
3517
|
error: true,
|
|
3490
|
-
error_code: data ? data.error_code : response.status,
|
|
3491
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3518
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3519
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3492
3520
|
};
|
|
3493
3521
|
}
|
|
3494
3522
|
}
|
|
@@ -3517,6 +3545,7 @@ class NftService {
|
|
|
3517
3545
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3518
3546
|
};
|
|
3519
3547
|
}
|
|
3548
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`;
|
|
3520
3549
|
let startTime;
|
|
3521
3550
|
if (this.debug) {
|
|
3522
3551
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3527,10 +3556,10 @@ class NftService {
|
|
|
3527
3556
|
"X-Requested-With": userAgent
|
|
3528
3557
|
}
|
|
3529
3558
|
}));
|
|
3530
|
-
debugOutput(response.url, response.status
|
|
3531
|
-
if (response.status === null || response.status === 429) {
|
|
3559
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3560
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3532
3561
|
try {
|
|
3533
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3562
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3534
3563
|
}
|
|
3535
3564
|
catch (error) {
|
|
3536
3565
|
success = true;
|
|
@@ -3560,8 +3589,8 @@ class NftService {
|
|
|
3560
3589
|
return {
|
|
3561
3590
|
data: null,
|
|
3562
3591
|
error: true,
|
|
3563
|
-
error_code: data ? data.error_code : response.status,
|
|
3564
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3592
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3593
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3565
3594
|
};
|
|
3566
3595
|
}
|
|
3567
3596
|
}
|
|
@@ -3591,6 +3620,7 @@ class NftService {
|
|
|
3591
3620
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3592
3621
|
};
|
|
3593
3622
|
}
|
|
3623
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`;
|
|
3594
3624
|
let startTime;
|
|
3595
3625
|
if (this.debug) {
|
|
3596
3626
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3601,10 +3631,10 @@ class NftService {
|
|
|
3601
3631
|
"X-Requested-With": userAgent
|
|
3602
3632
|
}
|
|
3603
3633
|
}));
|
|
3604
|
-
debugOutput(response.url, response.status
|
|
3605
|
-
if (response.status === null || response.status === 429) {
|
|
3634
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3635
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3606
3636
|
try {
|
|
3607
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3637
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3608
3638
|
}
|
|
3609
3639
|
catch (error) {
|
|
3610
3640
|
success = true;
|
|
@@ -3634,8 +3664,8 @@ class NftService {
|
|
|
3634
3664
|
return {
|
|
3635
3665
|
data: null,
|
|
3636
3666
|
error: true,
|
|
3637
|
-
error_code: data ? data.error_code : response.status,
|
|
3638
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3667
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3668
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3639
3669
|
};
|
|
3640
3670
|
}
|
|
3641
3671
|
}
|
|
@@ -3664,6 +3694,7 @@ class NftService {
|
|
|
3664
3694
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3665
3695
|
};
|
|
3666
3696
|
}
|
|
3697
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`;
|
|
3667
3698
|
let startTime;
|
|
3668
3699
|
if (this.debug) {
|
|
3669
3700
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3674,10 +3705,10 @@ class NftService {
|
|
|
3674
3705
|
"X-Requested-With": userAgent
|
|
3675
3706
|
}
|
|
3676
3707
|
}));
|
|
3677
|
-
debugOutput(response.url, response.status
|
|
3678
|
-
if (response.status === null || response.status === 429) {
|
|
3708
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3709
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3679
3710
|
try {
|
|
3680
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3711
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3681
3712
|
}
|
|
3682
3713
|
catch (error) {
|
|
3683
3714
|
success = true;
|
|
@@ -3707,8 +3738,8 @@ class NftService {
|
|
|
3707
3738
|
return {
|
|
3708
3739
|
data: null,
|
|
3709
3740
|
error: true,
|
|
3710
|
-
error_code: data ? data.error_code : response.status,
|
|
3711
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3741
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3742
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3712
3743
|
};
|
|
3713
3744
|
}
|
|
3714
3745
|
}
|
|
@@ -3738,6 +3769,7 @@ class NftService {
|
|
|
3738
3769
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3739
3770
|
};
|
|
3740
3771
|
}
|
|
3772
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`;
|
|
3741
3773
|
let startTime;
|
|
3742
3774
|
if (this.debug) {
|
|
3743
3775
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3748,10 +3780,10 @@ class NftService {
|
|
|
3748
3780
|
"X-Requested-With": userAgent
|
|
3749
3781
|
}
|
|
3750
3782
|
}));
|
|
3751
|
-
debugOutput(response.url, response.status
|
|
3752
|
-
if (response.status === null || response.status === 429) {
|
|
3783
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3784
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3753
3785
|
try {
|
|
3754
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3786
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3755
3787
|
}
|
|
3756
3788
|
catch (error) {
|
|
3757
3789
|
success = true;
|
|
@@ -3781,8 +3813,8 @@ class NftService {
|
|
|
3781
3813
|
return {
|
|
3782
3814
|
data: null,
|
|
3783
3815
|
error: true,
|
|
3784
|
-
error_code: data ? data.error_code : response.status,
|
|
3785
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3816
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3817
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3786
3818
|
};
|
|
3787
3819
|
}
|
|
3788
3820
|
}
|
|
@@ -3813,6 +3845,7 @@ class NftService {
|
|
|
3813
3845
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3814
3846
|
};
|
|
3815
3847
|
}
|
|
3848
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`;
|
|
3816
3849
|
let startTime;
|
|
3817
3850
|
if (this.debug) {
|
|
3818
3851
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3823,10 +3856,10 @@ class NftService {
|
|
|
3823
3856
|
"X-Requested-With": userAgent
|
|
3824
3857
|
}
|
|
3825
3858
|
}));
|
|
3826
|
-
debugOutput(response.url, response.status
|
|
3827
|
-
if (response.status === null || response.status === 429) {
|
|
3859
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3860
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3828
3861
|
try {
|
|
3829
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3862
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3830
3863
|
}
|
|
3831
3864
|
catch (error) {
|
|
3832
3865
|
success = true;
|
|
@@ -3856,8 +3889,8 @@ class NftService {
|
|
|
3856
3889
|
return {
|
|
3857
3890
|
data: null,
|
|
3858
3891
|
error: true,
|
|
3859
|
-
error_code: data ? data.error_code : response.status,
|
|
3860
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3892
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3893
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3861
3894
|
};
|
|
3862
3895
|
}
|
|
3863
3896
|
}
|
|
@@ -3895,6 +3928,7 @@ class NftService {
|
|
|
3895
3928
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
3896
3929
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
3897
3930
|
}
|
|
3931
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`;
|
|
3898
3932
|
let startTime;
|
|
3899
3933
|
if (this.debug) {
|
|
3900
3934
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3905,10 +3939,10 @@ class NftService {
|
|
|
3905
3939
|
"X-Requested-With": userAgent
|
|
3906
3940
|
}
|
|
3907
3941
|
}));
|
|
3908
|
-
debugOutput(response.url, response.status
|
|
3909
|
-
if (response.status === null || response.status === 429) {
|
|
3942
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3943
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3910
3944
|
try {
|
|
3911
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3945
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3912
3946
|
}
|
|
3913
3947
|
catch (error) {
|
|
3914
3948
|
success = true;
|
|
@@ -3938,8 +3972,8 @@ class NftService {
|
|
|
3938
3972
|
return {
|
|
3939
3973
|
data: null,
|
|
3940
3974
|
error: true,
|
|
3941
|
-
error_code: data ? data.error_code : response.status,
|
|
3942
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3975
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3976
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3943
3977
|
};
|
|
3944
3978
|
}
|
|
3945
3979
|
}
|
|
@@ -3977,6 +4011,7 @@ class NftService {
|
|
|
3977
4011
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
3978
4012
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
3979
4013
|
}
|
|
4014
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`;
|
|
3980
4015
|
let startTime;
|
|
3981
4016
|
if (this.debug) {
|
|
3982
4017
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3987,10 +4022,10 @@ class NftService {
|
|
|
3987
4022
|
"X-Requested-With": userAgent
|
|
3988
4023
|
}
|
|
3989
4024
|
}));
|
|
3990
|
-
debugOutput(response.url, response.status
|
|
3991
|
-
if (response.status === null || response.status === 429) {
|
|
4025
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4026
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3992
4027
|
try {
|
|
3993
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4028
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3994
4029
|
}
|
|
3995
4030
|
catch (error) {
|
|
3996
4031
|
success = true;
|
|
@@ -4020,8 +4055,8 @@ class NftService {
|
|
|
4020
4055
|
return {
|
|
4021
4056
|
data: null,
|
|
4022
4057
|
error: true,
|
|
4023
|
-
error_code: data ? data.error_code : response.status,
|
|
4024
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4058
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4059
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4025
4060
|
};
|
|
4026
4061
|
}
|
|
4027
4062
|
}
|
|
@@ -4059,6 +4094,7 @@ class NftService {
|
|
|
4059
4094
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
4060
4095
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
4061
4096
|
}
|
|
4097
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`;
|
|
4062
4098
|
let startTime;
|
|
4063
4099
|
if (this.debug) {
|
|
4064
4100
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -4069,10 +4105,10 @@ class NftService {
|
|
|
4069
4105
|
"X-Requested-With": userAgent
|
|
4070
4106
|
}
|
|
4071
4107
|
}));
|
|
4072
|
-
debugOutput(response.url, response.status
|
|
4073
|
-
if (response.status === null || response.status === 429) {
|
|
4108
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4109
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4074
4110
|
try {
|
|
4075
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4111
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4076
4112
|
}
|
|
4077
4113
|
catch (error) {
|
|
4078
4114
|
success = true;
|
|
@@ -4102,8 +4138,8 @@ class NftService {
|
|
|
4102
4138
|
return {
|
|
4103
4139
|
data: null,
|
|
4104
4140
|
error: true,
|
|
4105
|
-
error_code: data ? data.error_code : response.status,
|
|
4106
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4141
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4142
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4107
4143
|
};
|
|
4108
4144
|
}
|
|
4109
4145
|
}
|
|
@@ -4129,10 +4165,10 @@ class Price {
|
|
|
4129
4165
|
this.date = data.date && data.date !== null ? dateFns.parseISO(data.date.toString()) : null;
|
|
4130
4166
|
this.price = data.price;
|
|
4131
4167
|
this.pretty_price = data.pretty_price;
|
|
4132
|
-
this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$
|
|
4168
|
+
this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$2(data.contract_metadata) : null;
|
|
4133
4169
|
}
|
|
4134
4170
|
}
|
|
4135
|
-
let ContractMetadata$
|
|
4171
|
+
let ContractMetadata$2 = class ContractMetadata {
|
|
4136
4172
|
constructor(data) {
|
|
4137
4173
|
this.contract_decimals = data.contract_decimals;
|
|
4138
4174
|
this.contract_name = data.contract_name;
|
|
@@ -4143,11 +4179,12 @@ let ContractMetadata$1 = class ContractMetadata {
|
|
|
4143
4179
|
}
|
|
4144
4180
|
};
|
|
4145
4181
|
class PricingService {
|
|
4146
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
4182
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
4147
4183
|
this.apiKey = apiKey;
|
|
4148
4184
|
this.debug = debug;
|
|
4149
4185
|
this.threadCount = threadCount;
|
|
4150
4186
|
this.is_key_valid = is_key_valid;
|
|
4187
|
+
this.enableRetry = enableRetry;
|
|
4151
4188
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
4152
4189
|
}
|
|
4153
4190
|
/**
|
|
@@ -4188,6 +4225,7 @@ class PricingService {
|
|
|
4188
4225
|
if (queryParamOpts?.pricesAtAsc !== undefined) {
|
|
4189
4226
|
urlParams.append("prices-at-asc", queryParamOpts?.pricesAtAsc.toString());
|
|
4190
4227
|
}
|
|
4228
|
+
const url = `https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`;
|
|
4191
4229
|
let startTime;
|
|
4192
4230
|
if (this.debug) {
|
|
4193
4231
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -4198,10 +4236,10 @@ class PricingService {
|
|
|
4198
4236
|
"X-Requested-With": userAgent
|
|
4199
4237
|
}
|
|
4200
4238
|
}));
|
|
4201
|
-
debugOutput(response.url, response.status
|
|
4202
|
-
if (response.status === null || response.status === 429) {
|
|
4239
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4240
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4203
4241
|
try {
|
|
4204
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4242
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4205
4243
|
}
|
|
4206
4244
|
catch (error) {
|
|
4207
4245
|
success = true;
|
|
@@ -4235,8 +4273,8 @@ class PricingService {
|
|
|
4235
4273
|
return {
|
|
4236
4274
|
data: null,
|
|
4237
4275
|
error: true,
|
|
4238
|
-
error_code: data ? data.error_code : response.status,
|
|
4239
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4276
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4277
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4240
4278
|
};
|
|
4241
4279
|
}
|
|
4242
4280
|
}
|
|
@@ -4274,7 +4312,7 @@ class Transaction {
|
|
|
4274
4312
|
this.gas_quote = data.gas_quote;
|
|
4275
4313
|
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
4276
4314
|
this.gas_quote_rate = data.gas_quote_rate;
|
|
4277
|
-
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
4315
|
+
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata$1(data.gas_metadata) : null;
|
|
4278
4316
|
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
|
|
4279
4317
|
this.dex_details = data.dex_details && data.dex_details !== null ? data.dex_details.map((itemData) => new DexReport(itemData)) : null;
|
|
4280
4318
|
this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? data.nft_sale_details.map((itemData) => new NftSalesReport(itemData)) : null;
|
|
@@ -4283,7 +4321,7 @@ class Transaction {
|
|
|
4283
4321
|
this.safe_details = data.safe_details && data.safe_details !== null ? data.safe_details.map((itemData) => new SafeDetails(itemData)) : null;
|
|
4284
4322
|
}
|
|
4285
4323
|
}
|
|
4286
|
-
class ContractMetadata {
|
|
4324
|
+
let ContractMetadata$1 = class ContractMetadata {
|
|
4287
4325
|
constructor(data) {
|
|
4288
4326
|
this.contract_decimals = data.contract_decimals;
|
|
4289
4327
|
this.contract_name = data.contract_name;
|
|
@@ -4292,7 +4330,7 @@ class ContractMetadata {
|
|
|
4292
4330
|
this.supports_erc = data.supports_erc;
|
|
4293
4331
|
this.logo_url = data.logo_url;
|
|
4294
4332
|
}
|
|
4295
|
-
}
|
|
4333
|
+
};
|
|
4296
4334
|
class Explorer {
|
|
4297
4335
|
constructor(data) {
|
|
4298
4336
|
this.label = data.label;
|
|
@@ -4457,11 +4495,12 @@ class Param {
|
|
|
4457
4495
|
}
|
|
4458
4496
|
}
|
|
4459
4497
|
class RecentTransactionsResponse {
|
|
4460
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4498
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4461
4499
|
this._debug = _debug;
|
|
4462
4500
|
this._apiKey = _apiKey;
|
|
4463
4501
|
this._threadCount = _threadCount;
|
|
4464
4502
|
this._urlParams = _urlParams;
|
|
4503
|
+
this._enableRetry = _enableRetry;
|
|
4465
4504
|
this.address = data.address;
|
|
4466
4505
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4467
4506
|
this.quote_currency = data.quote_currency;
|
|
@@ -4492,16 +4531,17 @@ class RecentTransactionsResponse {
|
|
|
4492
4531
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4493
4532
|
};
|
|
4494
4533
|
}
|
|
4534
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4495
4535
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4496
4536
|
headers: {
|
|
4497
4537
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4498
4538
|
"X-Requested-With": userAgent
|
|
4499
4539
|
}
|
|
4500
4540
|
}));
|
|
4501
|
-
debugOutput(response.url, response.status
|
|
4502
|
-
if (response.status === null || response.status === 429) {
|
|
4541
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4542
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4503
4543
|
try {
|
|
4504
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4544
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4505
4545
|
}
|
|
4506
4546
|
catch (error) {
|
|
4507
4547
|
success = true;
|
|
@@ -4516,7 +4556,7 @@ class RecentTransactionsResponse {
|
|
|
4516
4556
|
else {
|
|
4517
4557
|
data = await response.json();
|
|
4518
4558
|
}
|
|
4519
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4559
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4520
4560
|
checkAndModifyResponse(dataClass);
|
|
4521
4561
|
success = true;
|
|
4522
4562
|
return {
|
|
@@ -4531,8 +4571,8 @@ class RecentTransactionsResponse {
|
|
|
4531
4571
|
return {
|
|
4532
4572
|
data: null,
|
|
4533
4573
|
error: true,
|
|
4534
|
-
error_code: data ? data.error_code : response.status,
|
|
4535
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4574
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4575
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4536
4576
|
};
|
|
4537
4577
|
}
|
|
4538
4578
|
}
|
|
@@ -4558,16 +4598,17 @@ class RecentTransactionsResponse {
|
|
|
4558
4598
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4559
4599
|
};
|
|
4560
4600
|
}
|
|
4601
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4561
4602
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4562
4603
|
headers: {
|
|
4563
4604
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4564
4605
|
"X-Requested-With": userAgent
|
|
4565
4606
|
}
|
|
4566
4607
|
}));
|
|
4567
|
-
debugOutput(response.url, response.status
|
|
4568
|
-
if (response.status === null || response.status === 429) {
|
|
4608
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4609
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4569
4610
|
try {
|
|
4570
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4611
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4571
4612
|
}
|
|
4572
4613
|
catch (error) {
|
|
4573
4614
|
success = true;
|
|
@@ -4582,7 +4623,7 @@ class RecentTransactionsResponse {
|
|
|
4582
4623
|
else {
|
|
4583
4624
|
data = await response.json();
|
|
4584
4625
|
}
|
|
4585
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4626
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4586
4627
|
checkAndModifyResponse(dataClass);
|
|
4587
4628
|
success = true;
|
|
4588
4629
|
return {
|
|
@@ -4597,8 +4638,8 @@ class RecentTransactionsResponse {
|
|
|
4597
4638
|
return {
|
|
4598
4639
|
data: null,
|
|
4599
4640
|
error: true,
|
|
4600
|
-
error_code: data ? data.error_code : response.status,
|
|
4601
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4641
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4642
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4602
4643
|
};
|
|
4603
4644
|
}
|
|
4604
4645
|
}
|
|
@@ -4642,11 +4683,12 @@ class TransactionSummary {
|
|
|
4642
4683
|
}
|
|
4643
4684
|
}
|
|
4644
4685
|
class TransactionsResponse {
|
|
4645
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4686
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4646
4687
|
this._debug = _debug;
|
|
4647
4688
|
this._apiKey = _apiKey;
|
|
4648
4689
|
this._threadCount = _threadCount;
|
|
4649
4690
|
this._urlParams = _urlParams;
|
|
4691
|
+
this._enableRetry = _enableRetry;
|
|
4650
4692
|
this.address = data.address;
|
|
4651
4693
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4652
4694
|
this.quote_currency = data.quote_currency;
|
|
@@ -4677,16 +4719,17 @@ class TransactionsResponse {
|
|
|
4677
4719
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4678
4720
|
};
|
|
4679
4721
|
}
|
|
4722
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4680
4723
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4681
4724
|
headers: {
|
|
4682
4725
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4683
4726
|
"X-Requested-With": userAgent
|
|
4684
4727
|
}
|
|
4685
4728
|
}));
|
|
4686
|
-
debugOutput(response.url, response.status
|
|
4687
|
-
if (response.status === null || response.status === 429) {
|
|
4729
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4730
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4688
4731
|
try {
|
|
4689
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4732
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4690
4733
|
}
|
|
4691
4734
|
catch (error) {
|
|
4692
4735
|
success = true;
|
|
@@ -4701,7 +4744,7 @@ class TransactionsResponse {
|
|
|
4701
4744
|
else {
|
|
4702
4745
|
data = await response.json();
|
|
4703
4746
|
}
|
|
4704
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4747
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4705
4748
|
checkAndModifyResponse(dataClass);
|
|
4706
4749
|
success = true;
|
|
4707
4750
|
return {
|
|
@@ -4716,8 +4759,8 @@ class TransactionsResponse {
|
|
|
4716
4759
|
return {
|
|
4717
4760
|
data: null,
|
|
4718
4761
|
error: true,
|
|
4719
|
-
error_code: data ? data.error_code : response.status,
|
|
4720
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4762
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4763
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4721
4764
|
};
|
|
4722
4765
|
}
|
|
4723
4766
|
}
|
|
@@ -4743,16 +4786,17 @@ class TransactionsResponse {
|
|
|
4743
4786
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4744
4787
|
};
|
|
4745
4788
|
}
|
|
4789
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4746
4790
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4747
4791
|
headers: {
|
|
4748
4792
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4749
4793
|
"X-Requested-With": userAgent
|
|
4750
4794
|
}
|
|
4751
4795
|
}));
|
|
4752
|
-
debugOutput(response.url, response.status
|
|
4753
|
-
if (response.status === null || response.status === 429) {
|
|
4796
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4797
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4754
4798
|
try {
|
|
4755
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4799
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4756
4800
|
}
|
|
4757
4801
|
catch (error) {
|
|
4758
4802
|
success = true;
|
|
@@ -4767,7 +4811,7 @@ class TransactionsResponse {
|
|
|
4767
4811
|
else {
|
|
4768
4812
|
data = await response.json();
|
|
4769
4813
|
}
|
|
4770
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4814
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4771
4815
|
checkAndModifyResponse(dataClass);
|
|
4772
4816
|
success = true;
|
|
4773
4817
|
return {
|
|
@@ -4782,19 +4826,20 @@ class TransactionsResponse {
|
|
|
4782
4826
|
return {
|
|
4783
4827
|
data: null,
|
|
4784
4828
|
error: true,
|
|
4785
|
-
error_code: data ? data.error_code : response.status,
|
|
4786
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4829
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4830
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4787
4831
|
};
|
|
4788
4832
|
}
|
|
4789
4833
|
}
|
|
4790
4834
|
}
|
|
4791
4835
|
}
|
|
4792
4836
|
class TransactionsTimeBucketResponse {
|
|
4793
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4837
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4794
4838
|
this._debug = _debug;
|
|
4795
4839
|
this._apiKey = _apiKey;
|
|
4796
4840
|
this._threadCount = _threadCount;
|
|
4797
4841
|
this._urlParams = _urlParams;
|
|
4842
|
+
this._enableRetry = _enableRetry;
|
|
4798
4843
|
this.address = data.address;
|
|
4799
4844
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4800
4845
|
this.quote_currency = data.quote_currency;
|
|
@@ -4826,16 +4871,17 @@ class TransactionsTimeBucketResponse {
|
|
|
4826
4871
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4827
4872
|
};
|
|
4828
4873
|
}
|
|
4874
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4829
4875
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4830
4876
|
headers: {
|
|
4831
4877
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4832
4878
|
"X-Requested-With": userAgent
|
|
4833
4879
|
}
|
|
4834
4880
|
}));
|
|
4835
|
-
debugOutput(response.url, response.status
|
|
4836
|
-
if (response.status === null || response.status === 429) {
|
|
4881
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4882
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4837
4883
|
try {
|
|
4838
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4884
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4839
4885
|
}
|
|
4840
4886
|
catch (error) {
|
|
4841
4887
|
success = true;
|
|
@@ -4850,7 +4896,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4850
4896
|
else {
|
|
4851
4897
|
data = await response.json();
|
|
4852
4898
|
}
|
|
4853
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4899
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4854
4900
|
checkAndModifyResponse(dataClass);
|
|
4855
4901
|
success = true;
|
|
4856
4902
|
return {
|
|
@@ -4865,8 +4911,8 @@ class TransactionsTimeBucketResponse {
|
|
|
4865
4911
|
return {
|
|
4866
4912
|
data: null,
|
|
4867
4913
|
error: true,
|
|
4868
|
-
error_code: data ? data.error_code : response.status,
|
|
4869
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4914
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4915
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4870
4916
|
};
|
|
4871
4917
|
}
|
|
4872
4918
|
}
|
|
@@ -4892,16 +4938,17 @@ class TransactionsTimeBucketResponse {
|
|
|
4892
4938
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4893
4939
|
};
|
|
4894
4940
|
}
|
|
4941
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4895
4942
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4896
4943
|
headers: {
|
|
4897
4944
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4898
4945
|
"X-Requested-With": userAgent
|
|
4899
4946
|
}
|
|
4900
4947
|
}));
|
|
4901
|
-
debugOutput(response.url, response.status
|
|
4902
|
-
if (response.status === null || response.status === 429) {
|
|
4948
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4949
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4903
4950
|
try {
|
|
4904
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4951
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4905
4952
|
}
|
|
4906
4953
|
catch (error) {
|
|
4907
4954
|
success = true;
|
|
@@ -4916,7 +4963,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4916
4963
|
else {
|
|
4917
4964
|
data = await response.json();
|
|
4918
4965
|
}
|
|
4919
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4966
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4920
4967
|
checkAndModifyResponse(dataClass);
|
|
4921
4968
|
success = true;
|
|
4922
4969
|
return {
|
|
@@ -4931,8 +4978,8 @@ class TransactionsTimeBucketResponse {
|
|
|
4931
4978
|
return {
|
|
4932
4979
|
data: null,
|
|
4933
4980
|
error: true,
|
|
4934
|
-
error_code: data ? data.error_code : response.status,
|
|
4935
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4981
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4982
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4936
4983
|
};
|
|
4937
4984
|
}
|
|
4938
4985
|
}
|
|
@@ -4942,7 +4989,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4942
4989
|
* Transactions APIs
|
|
4943
4990
|
*
|
|
4944
4991
|
*/
|
|
4945
|
-
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
4992
|
+
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry) {
|
|
4946
4993
|
let hasNext = true;
|
|
4947
4994
|
let response;
|
|
4948
4995
|
let data;
|
|
@@ -4960,14 +5007,14 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
|
4960
5007
|
"X-Requested-With": userAgent
|
|
4961
5008
|
}
|
|
4962
5009
|
}));
|
|
4963
|
-
debugOutput(response.url, response.status
|
|
4964
|
-
if (response.status === null || response.status === 429) {
|
|
5010
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5011
|
+
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4965
5012
|
try {
|
|
4966
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
5013
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`));
|
|
4967
5014
|
}
|
|
4968
5015
|
catch (error) {
|
|
4969
5016
|
hasNext = false;
|
|
4970
|
-
throw new Error(`An error occurred ${response.status}: ${error.message}`);
|
|
5017
|
+
throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
|
|
4971
5018
|
}
|
|
4972
5019
|
}
|
|
4973
5020
|
else {
|
|
@@ -4999,11 +5046,12 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
|
4999
5046
|
}
|
|
5000
5047
|
}
|
|
5001
5048
|
class TransactionService {
|
|
5002
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
5049
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
5003
5050
|
this.apiKey = apiKey;
|
|
5004
5051
|
this.debug = debug;
|
|
5005
5052
|
this.threadCount = threadCount;
|
|
5006
5053
|
this.is_key_valid = is_key_valid;
|
|
5054
|
+
this.enableRetry = enableRetry;
|
|
5007
5055
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
5008
5056
|
}
|
|
5009
5057
|
/**
|
|
@@ -5059,16 +5107,17 @@ class TransactionService {
|
|
|
5059
5107
|
if (this.debug) {
|
|
5060
5108
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5061
5109
|
}
|
|
5110
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
|
|
5062
5111
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
5063
5112
|
headers: {
|
|
5064
5113
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5065
5114
|
"X-Requested-With": userAgent
|
|
5066
5115
|
}
|
|
5067
5116
|
}));
|
|
5068
|
-
debugOutput(response.url, response.status
|
|
5069
|
-
if (response.status === null || response.status === 429) {
|
|
5117
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5118
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5070
5119
|
try {
|
|
5071
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5120
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5072
5121
|
}
|
|
5073
5122
|
catch (error) {
|
|
5074
5123
|
success = true;
|
|
@@ -5098,8 +5147,8 @@ class TransactionService {
|
|
|
5098
5147
|
return {
|
|
5099
5148
|
data: null,
|
|
5100
5149
|
error: true,
|
|
5101
|
-
error_code: data ? data.error_code : response.status,
|
|
5102
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5150
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5151
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5103
5152
|
};
|
|
5104
5153
|
}
|
|
5105
5154
|
}
|
|
@@ -5138,7 +5187,7 @@ class TransactionService {
|
|
|
5138
5187
|
if (queryParamOpts?.withSafe !== undefined) {
|
|
5139
5188
|
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5140
5189
|
}
|
|
5141
|
-
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
|
|
5190
|
+
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry)) {
|
|
5142
5191
|
yield tx;
|
|
5143
5192
|
}
|
|
5144
5193
|
success = true;
|
|
@@ -5194,16 +5243,17 @@ class TransactionService {
|
|
|
5194
5243
|
if (this.debug) {
|
|
5195
5244
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5196
5245
|
}
|
|
5246
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
|
|
5197
5247
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
5198
5248
|
headers: {
|
|
5199
5249
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5200
5250
|
"X-Requested-With": userAgent
|
|
5201
5251
|
}
|
|
5202
5252
|
}));
|
|
5203
|
-
debugOutput(response.url, response.status
|
|
5204
|
-
if (response.status === null || response.status === 429) {
|
|
5253
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5254
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5205
5255
|
try {
|
|
5206
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5256
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5207
5257
|
}
|
|
5208
5258
|
catch (error) {
|
|
5209
5259
|
success = true;
|
|
@@ -5218,7 +5268,7 @@ class TransactionService {
|
|
|
5218
5268
|
else {
|
|
5219
5269
|
data = await response.json();
|
|
5220
5270
|
}
|
|
5221
|
-
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5271
|
+
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5222
5272
|
checkAndModifyResponse(dataClass);
|
|
5223
5273
|
success = true;
|
|
5224
5274
|
return {
|
|
@@ -5233,8 +5283,8 @@ class TransactionService {
|
|
|
5233
5283
|
return {
|
|
5234
5284
|
data: null,
|
|
5235
5285
|
error: true,
|
|
5236
|
-
error_code: data ? data.error_code : response.status,
|
|
5237
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5286
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5287
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5238
5288
|
};
|
|
5239
5289
|
}
|
|
5240
5290
|
}
|
|
@@ -5280,16 +5330,17 @@ class TransactionService {
|
|
|
5280
5330
|
if (this.debug) {
|
|
5281
5331
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5282
5332
|
}
|
|
5333
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
|
|
5283
5334
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
|
|
5284
5335
|
headers: {
|
|
5285
5336
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5286
5337
|
"X-Requested-With": userAgent
|
|
5287
5338
|
}
|
|
5288
5339
|
}));
|
|
5289
|
-
debugOutput(response.url, response.status
|
|
5290
|
-
if (response.status === null || response.status === 429) {
|
|
5340
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5341
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5291
5342
|
try {
|
|
5292
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5343
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5293
5344
|
}
|
|
5294
5345
|
catch (error) {
|
|
5295
5346
|
success = true;
|
|
@@ -5319,8 +5370,8 @@ class TransactionService {
|
|
|
5319
5370
|
return {
|
|
5320
5371
|
data: null,
|
|
5321
5372
|
error: true,
|
|
5322
|
-
error_code: data ? data.error_code : response.status,
|
|
5323
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5373
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5374
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5324
5375
|
};
|
|
5325
5376
|
}
|
|
5326
5377
|
}
|
|
@@ -5353,16 +5404,17 @@ class TransactionService {
|
|
|
5353
5404
|
if (this.debug) {
|
|
5354
5405
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5355
5406
|
}
|
|
5407
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
|
|
5356
5408
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
|
|
5357
5409
|
headers: {
|
|
5358
5410
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5359
5411
|
"X-Requested-With": userAgent
|
|
5360
5412
|
}
|
|
5361
5413
|
}));
|
|
5362
|
-
debugOutput(response.url, response.status
|
|
5363
|
-
if (response.status === null || response.status === 429) {
|
|
5414
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5415
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5364
5416
|
try {
|
|
5365
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5417
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5366
5418
|
}
|
|
5367
5419
|
catch (error) {
|
|
5368
5420
|
success = true;
|
|
@@ -5392,8 +5444,8 @@ class TransactionService {
|
|
|
5392
5444
|
return {
|
|
5393
5445
|
data: null,
|
|
5394
5446
|
error: true,
|
|
5395
|
-
error_code: data ? data.error_code : response.status,
|
|
5396
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5447
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5448
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5397
5449
|
};
|
|
5398
5450
|
}
|
|
5399
5451
|
}
|
|
@@ -5442,16 +5494,17 @@ class TransactionService {
|
|
|
5442
5494
|
if (this.debug) {
|
|
5443
5495
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5444
5496
|
}
|
|
5497
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
|
|
5445
5498
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
5446
5499
|
headers: {
|
|
5447
5500
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5448
5501
|
"X-Requested-With": userAgent
|
|
5449
5502
|
}
|
|
5450
5503
|
}));
|
|
5451
|
-
debugOutput(response.url, response.status
|
|
5452
|
-
if (response.status === null || response.status === 429) {
|
|
5504
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5505
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5453
5506
|
try {
|
|
5454
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5507
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5455
5508
|
}
|
|
5456
5509
|
catch (error) {
|
|
5457
5510
|
success = true;
|
|
@@ -5466,7 +5519,7 @@ class TransactionService {
|
|
|
5466
5519
|
else {
|
|
5467
5520
|
data = await response.json();
|
|
5468
5521
|
}
|
|
5469
|
-
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5522
|
+
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5470
5523
|
checkAndModifyResponse(dataClass);
|
|
5471
5524
|
success = true;
|
|
5472
5525
|
return {
|
|
@@ -5481,8 +5534,8 @@ class TransactionService {
|
|
|
5481
5534
|
return {
|
|
5482
5535
|
data: null,
|
|
5483
5536
|
error: true,
|
|
5484
|
-
error_code: data ? data.error_code : response.status,
|
|
5485
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5537
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5538
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5486
5539
|
};
|
|
5487
5540
|
}
|
|
5488
5541
|
}
|
|
@@ -5527,16 +5580,17 @@ class TransactionService {
|
|
|
5527
5580
|
if (this.debug) {
|
|
5528
5581
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5529
5582
|
}
|
|
5583
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
|
|
5530
5584
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
5531
5585
|
headers: {
|
|
5532
5586
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5533
5587
|
"X-Requested-With": userAgent
|
|
5534
5588
|
}
|
|
5535
5589
|
}));
|
|
5536
|
-
debugOutput(response.url, response.status
|
|
5537
|
-
if (response.status === null || response.status === 429) {
|
|
5590
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5591
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5538
5592
|
try {
|
|
5539
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5593
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5540
5594
|
}
|
|
5541
5595
|
catch (error) {
|
|
5542
5596
|
success = true;
|
|
@@ -5551,7 +5605,7 @@ class TransactionService {
|
|
|
5551
5605
|
else {
|
|
5552
5606
|
data = await response.json();
|
|
5553
5607
|
}
|
|
5554
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5608
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5555
5609
|
checkAndModifyResponse(dataClass);
|
|
5556
5610
|
success = true;
|
|
5557
5611
|
return {
|
|
@@ -5566,8 +5620,8 @@ class TransactionService {
|
|
|
5566
5620
|
return {
|
|
5567
5621
|
data: null,
|
|
5568
5622
|
error: true,
|
|
5569
|
-
error_code: data ? data.error_code : response.status,
|
|
5570
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5623
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5624
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5571
5625
|
};
|
|
5572
5626
|
}
|
|
5573
5627
|
}
|
|
@@ -5763,6 +5817,7 @@ class PoolsDexDataItem {
|
|
|
5763
5817
|
this.volume_24h_quote = data.volume_24h_quote;
|
|
5764
5818
|
this.volume_7d_quote = data.volume_7d_quote;
|
|
5765
5819
|
this.fee_24h_quote = data.fee_24h_quote;
|
|
5820
|
+
this.annualized_fee = data.annualized_fee;
|
|
5766
5821
|
this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
|
|
5767
5822
|
this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
|
|
5768
5823
|
this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
|
|
@@ -5805,6 +5860,7 @@ class UniswapLikeToken {
|
|
|
5805
5860
|
this.logo_url = data.logo_url;
|
|
5806
5861
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5807
5862
|
this.quote = data.quote;
|
|
5863
|
+
this.pretty_quote = data.pretty_quote;
|
|
5808
5864
|
this.quote_rate = data.quote_rate;
|
|
5809
5865
|
}
|
|
5810
5866
|
}
|
|
@@ -5816,6 +5872,7 @@ class UniswapLikeTokenWithSupply {
|
|
|
5816
5872
|
this.logo_url = data.logo_url;
|
|
5817
5873
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5818
5874
|
this.quote = data.quote;
|
|
5875
|
+
this.pretty_quote = data.pretty_quote;
|
|
5819
5876
|
this.quote_rate = data.quote_rate;
|
|
5820
5877
|
this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
|
|
5821
5878
|
}
|
|
@@ -5883,22 +5940,45 @@ class ExchangeTransaction {
|
|
|
5883
5940
|
this.tx_hash = data.tx_hash;
|
|
5884
5941
|
this.act = data.act;
|
|
5885
5942
|
this.address = data.address;
|
|
5886
|
-
this.
|
|
5887
|
-
this.
|
|
5888
|
-
this.
|
|
5889
|
-
this.
|
|
5890
|
-
this.
|
|
5943
|
+
this.amount_0 = data.amount_0;
|
|
5944
|
+
this.amount_1 = data.amount_1;
|
|
5945
|
+
this.amount_0_in = data.amount_0_in;
|
|
5946
|
+
this.amount_0_out = data.amount_0_out;
|
|
5947
|
+
this.amount_1_in = data.amount_1_in;
|
|
5948
|
+
this.amount_1_out = data.amount_1_out;
|
|
5891
5949
|
this.to_address = data.to_address;
|
|
5892
5950
|
this.from_address = data.from_address;
|
|
5893
5951
|
this.sender_address = data.sender_address;
|
|
5894
5952
|
this.total_quote = data.total_quote;
|
|
5895
5953
|
this.pretty_total_quote = data.pretty_total_quote;
|
|
5954
|
+
this.value = data.value && data.value !== null ? BigInt(data.value) : null;
|
|
5955
|
+
this.value_quote = data.value_quote;
|
|
5956
|
+
this.pretty_value_quote = data.pretty_value_quote;
|
|
5957
|
+
this.gas_offered = data.gas_offered;
|
|
5958
|
+
this.gas_spent = data.gas_spent;
|
|
5959
|
+
this.gas_price = data.gas_price;
|
|
5960
|
+
this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
|
|
5961
|
+
this.gas_quote = data.gas_quote;
|
|
5962
|
+
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
5963
|
+
this.gas_quote_rate = data.gas_quote_rate;
|
|
5964
|
+
this.quote_currency = data.quote_currency;
|
|
5896
5965
|
this.token_0_quote_rate = data.token_0_quote_rate;
|
|
5897
5966
|
this.token_1_quote_rate = data.token_1_quote_rate;
|
|
5967
|
+
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
5898
5968
|
this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
|
|
5899
5969
|
this.token_1 = data.token_1 && data.token_1 !== null ? new PoolToken(data.token_1) : null;
|
|
5900
5970
|
}
|
|
5901
5971
|
}
|
|
5972
|
+
class ContractMetadata {
|
|
5973
|
+
constructor(data) {
|
|
5974
|
+
this.contract_decimals = data.contract_decimals;
|
|
5975
|
+
this.contract_name = data.contract_name;
|
|
5976
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
5977
|
+
this.contract_address = data.contract_address;
|
|
5978
|
+
this.supports_erc = data.supports_erc;
|
|
5979
|
+
this.logo_url = data.logo_url;
|
|
5980
|
+
}
|
|
5981
|
+
}
|
|
5902
5982
|
class PoolToken {
|
|
5903
5983
|
constructor(data) {
|
|
5904
5984
|
this.contract_decimals = data.contract_decimals;
|
|
@@ -5942,13 +6022,15 @@ class UniswapLikeEcosystemCharts {
|
|
|
5942
6022
|
this.chain_id = data.chain_id;
|
|
5943
6023
|
this.quote_currency = data.quote_currency;
|
|
5944
6024
|
this.gas_token_price_quote = data.gas_token_price_quote;
|
|
5945
|
-
this.
|
|
5946
|
-
this.
|
|
5947
|
-
this.
|
|
5948
|
-
this.
|
|
5949
|
-
this.
|
|
5950
|
-
this.
|
|
5951
|
-
this.
|
|
6025
|
+
this.total_swaps_24h = data.total_swaps_24h;
|
|
6026
|
+
this.total_active_pairs_7d = data.total_active_pairs_7d;
|
|
6027
|
+
this.total_fees_24h = data.total_fees_24h;
|
|
6028
|
+
this.pretty_gas_token_price_quote = data.pretty_gas_token_price_quote;
|
|
6029
|
+
this.pretty_total_fees_24h = data.pretty_total_fees_24h;
|
|
6030
|
+
this.volume_chart_7d = data.volume_chart_7d && data.volume_chart_7d !== null ? data.volume_chart_7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
|
|
6031
|
+
this.volume_chart_30d = data.volume_chart_30d && data.volume_chart_30d !== null ? data.volume_chart_30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
|
|
6032
|
+
this.liquidity_chart_7d = data.liquidity_chart_7d && data.liquidity_chart_7d !== null ? data.liquidity_chart_7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
|
|
6033
|
+
this.liquidity_chart_30d = data.liquidity_chart_30d && data.liquidity_chart_30d !== null ? data.liquidity_chart_30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
|
|
5952
6034
|
}
|
|
5953
6035
|
}
|
|
5954
6036
|
class VolumeEcosystemChart {
|
|
@@ -5958,6 +6040,7 @@ class VolumeEcosystemChart {
|
|
|
5958
6040
|
this.dt = data.dt && data.dt !== null ? dateFns.parseISO(data.dt.toString()) : null;
|
|
5959
6041
|
this.quote_currency = data.quote_currency;
|
|
5960
6042
|
this.volume_quote = data.volume_quote;
|
|
6043
|
+
this.pretty_volume_quote = data.pretty_volume_quote;
|
|
5961
6044
|
this.swap_count_24 = data.swap_count_24;
|
|
5962
6045
|
}
|
|
5963
6046
|
}
|
|
@@ -5968,6 +6051,7 @@ class LiquidityEcosystemChart {
|
|
|
5968
6051
|
this.dt = data.dt && data.dt !== null ? dateFns.parseISO(data.dt.toString()) : null;
|
|
5969
6052
|
this.quote_currency = data.quote_currency;
|
|
5970
6053
|
this.liquidity_quote = data.liquidity_quote;
|
|
6054
|
+
this.pretty_liquidity_quote = data.pretty_liquidity_quote;
|
|
5971
6055
|
}
|
|
5972
6056
|
}
|
|
5973
6057
|
class HealthDataResponse {
|
|
@@ -5992,11 +6076,12 @@ class HealthData {
|
|
|
5992
6076
|
*
|
|
5993
6077
|
*/
|
|
5994
6078
|
class XykService {
|
|
5995
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
6079
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
5996
6080
|
this.apiKey = apiKey;
|
|
5997
6081
|
this.debug = debug;
|
|
5998
6082
|
this.threadCount = threadCount;
|
|
5999
6083
|
this.is_key_valid = is_key_valid;
|
|
6084
|
+
this.enableRetry = enableRetry;
|
|
6000
6085
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
6001
6086
|
}
|
|
6002
6087
|
/**
|
|
@@ -6015,6 +6100,7 @@ class XykService {
|
|
|
6015
6100
|
while (!success) {
|
|
6016
6101
|
try {
|
|
6017
6102
|
const urlParams = new URLSearchParams();
|
|
6103
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
|
|
6018
6104
|
if (!this.is_key_valid) {
|
|
6019
6105
|
return {
|
|
6020
6106
|
data: null,
|
|
@@ -6033,10 +6119,10 @@ class XykService {
|
|
|
6033
6119
|
"X-Requested-With": userAgent
|
|
6034
6120
|
}
|
|
6035
6121
|
}));
|
|
6036
|
-
debugOutput(response.url, response.status
|
|
6037
|
-
if (response.status === null || response.status === 429) {
|
|
6122
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6123
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6038
6124
|
try {
|
|
6039
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6125
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6040
6126
|
}
|
|
6041
6127
|
catch (error) {
|
|
6042
6128
|
success = true;
|
|
@@ -6066,8 +6152,8 @@ class XykService {
|
|
|
6066
6152
|
return {
|
|
6067
6153
|
data: null,
|
|
6068
6154
|
error: true,
|
|
6069
|
-
error_code: data ? data.error_code : response.status,
|
|
6070
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6155
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6156
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6071
6157
|
};
|
|
6072
6158
|
}
|
|
6073
6159
|
}
|
|
@@ -6088,6 +6174,7 @@ class XykService {
|
|
|
6088
6174
|
while (!success) {
|
|
6089
6175
|
try {
|
|
6090
6176
|
const urlParams = new URLSearchParams();
|
|
6177
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`;
|
|
6091
6178
|
if (!this.is_key_valid) {
|
|
6092
6179
|
return {
|
|
6093
6180
|
data: null,
|
|
@@ -6106,10 +6193,10 @@ class XykService {
|
|
|
6106
6193
|
"X-Requested-With": userAgent
|
|
6107
6194
|
}
|
|
6108
6195
|
}));
|
|
6109
|
-
debugOutput(response.url, response.status
|
|
6110
|
-
if (response.status === null || response.status === 429) {
|
|
6196
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6197
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6111
6198
|
try {
|
|
6112
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6199
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6113
6200
|
}
|
|
6114
6201
|
catch (error) {
|
|
6115
6202
|
success = true;
|
|
@@ -6139,8 +6226,8 @@ class XykService {
|
|
|
6139
6226
|
return {
|
|
6140
6227
|
data: null,
|
|
6141
6228
|
error: true,
|
|
6142
|
-
error_code: data ? data.error_code : response.status,
|
|
6143
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6229
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6230
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6144
6231
|
};
|
|
6145
6232
|
}
|
|
6146
6233
|
}
|
|
@@ -6162,6 +6249,7 @@ class XykService {
|
|
|
6162
6249
|
while (!success) {
|
|
6163
6250
|
try {
|
|
6164
6251
|
const urlParams = new URLSearchParams();
|
|
6252
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`;
|
|
6165
6253
|
if (!this.is_key_valid) {
|
|
6166
6254
|
return {
|
|
6167
6255
|
data: null,
|
|
@@ -6180,10 +6268,10 @@ class XykService {
|
|
|
6180
6268
|
"X-Requested-With": userAgent
|
|
6181
6269
|
}
|
|
6182
6270
|
}));
|
|
6183
|
-
debugOutput(response.url, response.status
|
|
6184
|
-
if (response.status === null || response.status === 429) {
|
|
6271
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6272
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6185
6273
|
try {
|
|
6186
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6274
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6187
6275
|
}
|
|
6188
6276
|
catch (error) {
|
|
6189
6277
|
success = true;
|
|
@@ -6213,8 +6301,8 @@ class XykService {
|
|
|
6213
6301
|
return {
|
|
6214
6302
|
data: null,
|
|
6215
6303
|
error: true,
|
|
6216
|
-
error_code: data ? data.error_code : response.status,
|
|
6217
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6304
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6305
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6218
6306
|
};
|
|
6219
6307
|
}
|
|
6220
6308
|
}
|
|
@@ -6252,6 +6340,7 @@ class XykService {
|
|
|
6252
6340
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6253
6341
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6254
6342
|
}
|
|
6343
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
|
|
6255
6344
|
let startTime;
|
|
6256
6345
|
if (this.debug) {
|
|
6257
6346
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6262,10 +6351,10 @@ class XykService {
|
|
|
6262
6351
|
"X-Requested-With": userAgent
|
|
6263
6352
|
}
|
|
6264
6353
|
}));
|
|
6265
|
-
debugOutput(response.url, response.status
|
|
6266
|
-
if (response.status === null || response.status === 429) {
|
|
6354
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6355
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6267
6356
|
try {
|
|
6268
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6357
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6269
6358
|
}
|
|
6270
6359
|
catch (error) {
|
|
6271
6360
|
success = true;
|
|
@@ -6295,8 +6384,8 @@ class XykService {
|
|
|
6295
6384
|
return {
|
|
6296
6385
|
data: null,
|
|
6297
6386
|
error: true,
|
|
6298
|
-
error_code: data ? data.error_code : response.status,
|
|
6299
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6387
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6388
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6300
6389
|
};
|
|
6301
6390
|
}
|
|
6302
6391
|
}
|
|
@@ -6326,6 +6415,7 @@ class XykService {
|
|
|
6326
6415
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6327
6416
|
};
|
|
6328
6417
|
}
|
|
6418
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`;
|
|
6329
6419
|
let startTime;
|
|
6330
6420
|
if (this.debug) {
|
|
6331
6421
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6336,10 +6426,10 @@ class XykService {
|
|
|
6336
6426
|
"X-Requested-With": userAgent
|
|
6337
6427
|
}
|
|
6338
6428
|
}));
|
|
6339
|
-
debugOutput(response.url, response.status
|
|
6340
|
-
if (response.status === null || response.status === 429) {
|
|
6429
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6430
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6341
6431
|
try {
|
|
6342
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6432
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6343
6433
|
}
|
|
6344
6434
|
catch (error) {
|
|
6345
6435
|
success = true;
|
|
@@ -6369,8 +6459,8 @@ class XykService {
|
|
|
6369
6459
|
return {
|
|
6370
6460
|
data: null,
|
|
6371
6461
|
error: true,
|
|
6372
|
-
error_code: data ? data.error_code : response.status,
|
|
6373
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6462
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6463
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6374
6464
|
};
|
|
6375
6465
|
}
|
|
6376
6466
|
}
|
|
@@ -6412,6 +6502,7 @@ class XykService {
|
|
|
6412
6502
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6413
6503
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6414
6504
|
}
|
|
6505
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
|
|
6415
6506
|
let startTime;
|
|
6416
6507
|
if (this.debug) {
|
|
6417
6508
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6422,10 +6513,10 @@ class XykService {
|
|
|
6422
6513
|
"X-Requested-With": userAgent
|
|
6423
6514
|
}
|
|
6424
6515
|
}));
|
|
6425
|
-
debugOutput(response.url, response.status
|
|
6426
|
-
if (response.status === null || response.status === 429) {
|
|
6516
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6517
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6427
6518
|
try {
|
|
6428
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6519
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6429
6520
|
}
|
|
6430
6521
|
catch (error) {
|
|
6431
6522
|
success = true;
|
|
@@ -6455,8 +6546,8 @@ class XykService {
|
|
|
6455
6546
|
return {
|
|
6456
6547
|
data: null,
|
|
6457
6548
|
error: true,
|
|
6458
|
-
error_code: data ? data.error_code : response.status,
|
|
6459
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6549
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6550
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6460
6551
|
};
|
|
6461
6552
|
}
|
|
6462
6553
|
}
|
|
@@ -6485,6 +6576,7 @@ class XykService {
|
|
|
6485
6576
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6486
6577
|
};
|
|
6487
6578
|
}
|
|
6579
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`;
|
|
6488
6580
|
let startTime;
|
|
6489
6581
|
if (this.debug) {
|
|
6490
6582
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6495,10 +6587,10 @@ class XykService {
|
|
|
6495
6587
|
"X-Requested-With": userAgent
|
|
6496
6588
|
}
|
|
6497
6589
|
}));
|
|
6498
|
-
debugOutput(response.url, response.status
|
|
6499
|
-
if (response.status === null || response.status === 429) {
|
|
6590
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6591
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6500
6592
|
try {
|
|
6501
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6593
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6502
6594
|
}
|
|
6503
6595
|
catch (error) {
|
|
6504
6596
|
success = true;
|
|
@@ -6528,8 +6620,8 @@ class XykService {
|
|
|
6528
6620
|
return {
|
|
6529
6621
|
data: null,
|
|
6530
6622
|
error: true,
|
|
6531
|
-
error_code: data ? data.error_code : response.status,
|
|
6532
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6623
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6624
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6533
6625
|
};
|
|
6534
6626
|
}
|
|
6535
6627
|
}
|
|
@@ -6556,6 +6648,7 @@ class XykService {
|
|
|
6556
6648
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6557
6649
|
};
|
|
6558
6650
|
}
|
|
6651
|
+
const url = `https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`;
|
|
6559
6652
|
let startTime;
|
|
6560
6653
|
if (this.debug) {
|
|
6561
6654
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6566,10 +6659,10 @@ class XykService {
|
|
|
6566
6659
|
"X-Requested-With": userAgent
|
|
6567
6660
|
}
|
|
6568
6661
|
}));
|
|
6569
|
-
debugOutput(response.url, response.status
|
|
6570
|
-
if (response.status === null || response.status === 429) {
|
|
6662
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6663
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6571
6664
|
try {
|
|
6572
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6665
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6573
6666
|
}
|
|
6574
6667
|
catch (error) {
|
|
6575
6668
|
success = true;
|
|
@@ -6599,8 +6692,8 @@ class XykService {
|
|
|
6599
6692
|
return {
|
|
6600
6693
|
data: null,
|
|
6601
6694
|
error: true,
|
|
6602
|
-
error_code: data ? data.error_code : response.status,
|
|
6603
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6695
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6696
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6604
6697
|
};
|
|
6605
6698
|
}
|
|
6606
6699
|
}
|
|
@@ -6630,6 +6723,7 @@ class XykService {
|
|
|
6630
6723
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6631
6724
|
};
|
|
6632
6725
|
}
|
|
6726
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`;
|
|
6633
6727
|
let startTime;
|
|
6634
6728
|
if (this.debug) {
|
|
6635
6729
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6640,10 +6734,10 @@ class XykService {
|
|
|
6640
6734
|
"X-Requested-With": userAgent
|
|
6641
6735
|
}
|
|
6642
6736
|
}));
|
|
6643
|
-
debugOutput(response.url, response.status
|
|
6644
|
-
if (response.status === null || response.status === 429) {
|
|
6737
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6738
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6645
6739
|
try {
|
|
6646
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6740
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6647
6741
|
}
|
|
6648
6742
|
catch (error) {
|
|
6649
6743
|
success = true;
|
|
@@ -6673,8 +6767,8 @@ class XykService {
|
|
|
6673
6767
|
return {
|
|
6674
6768
|
data: null,
|
|
6675
6769
|
error: true,
|
|
6676
|
-
error_code: data ? data.error_code : response.status,
|
|
6677
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6770
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6771
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6678
6772
|
};
|
|
6679
6773
|
}
|
|
6680
6774
|
}
|
|
@@ -6704,6 +6798,7 @@ class XykService {
|
|
|
6704
6798
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6705
6799
|
};
|
|
6706
6800
|
}
|
|
6801
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`;
|
|
6707
6802
|
let startTime;
|
|
6708
6803
|
if (this.debug) {
|
|
6709
6804
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6714,10 +6809,10 @@ class XykService {
|
|
|
6714
6809
|
"X-Requested-With": userAgent
|
|
6715
6810
|
}
|
|
6716
6811
|
}));
|
|
6717
|
-
debugOutput(response.url, response.status
|
|
6718
|
-
if (response.status === null || response.status === 429) {
|
|
6812
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6813
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6719
6814
|
try {
|
|
6720
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6815
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6721
6816
|
}
|
|
6722
6817
|
catch (error) {
|
|
6723
6818
|
success = true;
|
|
@@ -6747,8 +6842,8 @@ class XykService {
|
|
|
6747
6842
|
return {
|
|
6748
6843
|
data: null,
|
|
6749
6844
|
error: true,
|
|
6750
|
-
error_code: data ? data.error_code : response.status,
|
|
6751
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6845
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6846
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6752
6847
|
};
|
|
6753
6848
|
}
|
|
6754
6849
|
}
|
|
@@ -6778,6 +6873,7 @@ class XykService {
|
|
|
6778
6873
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6779
6874
|
};
|
|
6780
6875
|
}
|
|
6876
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
|
|
6781
6877
|
let startTime;
|
|
6782
6878
|
if (this.debug) {
|
|
6783
6879
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6788,10 +6884,10 @@ class XykService {
|
|
|
6788
6884
|
"X-Requested-With": userAgent
|
|
6789
6885
|
}
|
|
6790
6886
|
}));
|
|
6791
|
-
debugOutput(response.url, response.status
|
|
6792
|
-
if (response.status === null || response.status === 429) {
|
|
6887
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6888
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6793
6889
|
try {
|
|
6794
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6890
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6795
6891
|
}
|
|
6796
6892
|
catch (error) {
|
|
6797
6893
|
success = true;
|
|
@@ -6821,8 +6917,8 @@ class XykService {
|
|
|
6821
6917
|
return {
|
|
6822
6918
|
data: null,
|
|
6823
6919
|
error: true,
|
|
6824
|
-
error_code: data ? data.error_code : response.status,
|
|
6825
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6920
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6921
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6826
6922
|
};
|
|
6827
6923
|
}
|
|
6828
6924
|
}
|
|
@@ -6852,6 +6948,7 @@ class XykService {
|
|
|
6852
6948
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6853
6949
|
};
|
|
6854
6950
|
}
|
|
6951
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
|
|
6855
6952
|
let startTime;
|
|
6856
6953
|
if (this.debug) {
|
|
6857
6954
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6862,10 +6959,10 @@ class XykService {
|
|
|
6862
6959
|
"X-Requested-With": userAgent
|
|
6863
6960
|
}
|
|
6864
6961
|
}));
|
|
6865
|
-
debugOutput(response.url, response.status
|
|
6866
|
-
if (response.status === null || response.status === 429) {
|
|
6962
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6963
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6867
6964
|
try {
|
|
6868
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6965
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6869
6966
|
}
|
|
6870
6967
|
catch (error) {
|
|
6871
6968
|
success = true;
|
|
@@ -6895,8 +6992,8 @@ class XykService {
|
|
|
6895
6992
|
return {
|
|
6896
6993
|
data: null,
|
|
6897
6994
|
error: true,
|
|
6898
|
-
error_code: data ? data.error_code : response.status,
|
|
6899
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6995
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6996
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6900
6997
|
};
|
|
6901
6998
|
}
|
|
6902
6999
|
}
|
|
@@ -6925,6 +7022,7 @@ class XykService {
|
|
|
6925
7022
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6926
7023
|
};
|
|
6927
7024
|
}
|
|
7025
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`;
|
|
6928
7026
|
let startTime;
|
|
6929
7027
|
if (this.debug) {
|
|
6930
7028
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6935,10 +7033,10 @@ class XykService {
|
|
|
6935
7033
|
"X-Requested-With": userAgent
|
|
6936
7034
|
}
|
|
6937
7035
|
}));
|
|
6938
|
-
debugOutput(response.url, response.status
|
|
6939
|
-
if (response.status === null || response.status === 429) {
|
|
7036
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7037
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6940
7038
|
try {
|
|
6941
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7039
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6942
7040
|
}
|
|
6943
7041
|
catch (error) {
|
|
6944
7042
|
success = true;
|
|
@@ -6968,8 +7066,8 @@ class XykService {
|
|
|
6968
7066
|
return {
|
|
6969
7067
|
data: null,
|
|
6970
7068
|
error: true,
|
|
6971
|
-
error_code: data ? data.error_code : response.status,
|
|
6972
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7069
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7070
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6973
7071
|
};
|
|
6974
7072
|
}
|
|
6975
7073
|
}
|
|
@@ -6998,6 +7096,7 @@ class XykService {
|
|
|
6998
7096
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6999
7097
|
};
|
|
7000
7098
|
}
|
|
7099
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`;
|
|
7001
7100
|
let startTime;
|
|
7002
7101
|
if (this.debug) {
|
|
7003
7102
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -7008,10 +7107,10 @@ class XykService {
|
|
|
7008
7107
|
"X-Requested-With": userAgent
|
|
7009
7108
|
}
|
|
7010
7109
|
}));
|
|
7011
|
-
debugOutput(response.url, response.status
|
|
7012
|
-
if (response.status === null || response.status === 429) {
|
|
7110
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7111
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7013
7112
|
try {
|
|
7014
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7113
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7015
7114
|
}
|
|
7016
7115
|
catch (error) {
|
|
7017
7116
|
success = true;
|
|
@@ -7041,30 +7140,30 @@ class XykService {
|
|
|
7041
7140
|
return {
|
|
7042
7141
|
data: null,
|
|
7043
7142
|
error: true,
|
|
7044
|
-
error_code: data ? data.error_code : response.status,
|
|
7045
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7143
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7144
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7046
7145
|
};
|
|
7047
7146
|
}
|
|
7048
7147
|
}
|
|
7049
7148
|
}
|
|
7050
7149
|
}
|
|
7051
7150
|
|
|
7052
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.7.
|
|
7151
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.7.6";
|
|
7053
7152
|
/**
|
|
7054
7153
|
* CovalentClient Class
|
|
7055
7154
|
*/
|
|
7056
7155
|
class CovalentClient {
|
|
7057
7156
|
constructor(apiKey, settings) {
|
|
7058
|
-
const { debug = false, threadCount = 3 } = settings || {};
|
|
7157
|
+
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7059
7158
|
const validator = new ApiKeyValidator(apiKey);
|
|
7060
7159
|
this._is_key_valid = validator.isValidApiKey();
|
|
7061
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7062
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7063
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7064
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7065
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7066
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7067
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7160
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7161
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7162
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7163
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7164
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7165
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7166
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7068
7167
|
}
|
|
7069
7168
|
}
|
|
7070
7169
|
/**
|
|
@@ -7075,16 +7174,16 @@ class CovalentClient {
|
|
|
7075
7174
|
*/
|
|
7076
7175
|
class Client {
|
|
7077
7176
|
constructor(apiKey, settings) {
|
|
7078
|
-
const { debug = false, threadCount = 3 } = settings || {};
|
|
7177
|
+
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7079
7178
|
const validator = new ApiKeyValidator(apiKey);
|
|
7080
7179
|
this._is_key_valid = validator.isValidApiKey();
|
|
7081
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7082
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7083
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7084
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7085
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7086
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7087
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7180
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7181
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7182
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7183
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7184
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7185
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7186
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7088
7187
|
}
|
|
7089
7188
|
}
|
|
7090
7189
|
|