@covalenthq/client-sdk 0.0.2 → 0.0.4
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/dist/ApprovalService.js +22 -33
- package/dist/ApprovalService.js.map +1 -1
- package/dist/BalancesService.js +157 -176
- package/dist/BalancesService.js.map +1 -1
- package/dist/BaseService.js +169 -192
- package/dist/BaseService.js.map +1 -1
- package/dist/LogEventService.js +40 -51
- package/dist/LogEventService.js.map +1 -1
- package/dist/NameResolverService.js +22 -33
- package/dist/NameResolverService.js.map +1 -1
- package/dist/NftService.js +292 -323
- package/dist/NftService.js.map +1 -1
- package/dist/PricingService.js +31 -42
- package/dist/PricingService.js.map +1 -1
- package/dist/TransactionsService.d.ts +1 -1
- package/dist/TransactionsService.js +286 -295
- package/dist/TransactionsService.js.map +1 -1
- package/dist/XykService.js +242 -273
- package/dist/XykService.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.TransactionsService = void 0;
|
|
13
4
|
const baseDelayMs = 1000; // Base delay in milliseconds
|
|
5
|
+
async function* paginateEndpoint(url, apiKey, urlsParams) {
|
|
6
|
+
let hasNext = true;
|
|
7
|
+
let retryCount = 0;
|
|
8
|
+
while (hasNext) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(`${url}?${urlsParams}`, {
|
|
11
|
+
headers: {
|
|
12
|
+
"Authorization": `Bearer ${apiKey}`
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const data = await response.json();
|
|
16
|
+
if (data.error && data.error_code === 429) {
|
|
17
|
+
retryCount++;
|
|
18
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
19
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
yield data;
|
|
23
|
+
if (data.data.links.prev === null) {
|
|
24
|
+
hasNext = false;
|
|
25
|
+
}
|
|
26
|
+
url = data.data.links.prev || "";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
14
34
|
class TransactionsService {
|
|
15
35
|
constructor(apiKey) {
|
|
16
36
|
this.apiKey = apiKey;
|
|
@@ -26,50 +46,48 @@ class TransactionsService {
|
|
|
26
46
|
* @param {boolean} withLending - Decoded lending details including protocol (e.g. Aave), event (e.g. 'deposit') and tokens involved with prices. Additional 0.05 credits charged if data available.
|
|
27
47
|
*
|
|
28
48
|
*/
|
|
29
|
-
getTransaction(chainName, txHash, quoteCurrency, noLogs, withDex, withNftSales, withLending) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
urlParams.append("with-dex", withDex.toString());
|
|
44
|
-
}
|
|
45
|
-
if (withNftSales !== undefined) {
|
|
46
|
-
urlParams.append("with-nft-sales", withNftSales.toString());
|
|
47
|
-
}
|
|
48
|
-
if (withLending !== undefined) {
|
|
49
|
-
urlParams.append("with-lending", withLending.toString());
|
|
50
|
-
}
|
|
51
|
-
const response = yield fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
52
|
-
headers: {
|
|
53
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
const data = yield response.json();
|
|
57
|
-
if (data.error && data.error_code === 429) {
|
|
58
|
-
retryCount++;
|
|
59
|
-
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
60
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
success = true;
|
|
64
|
-
return data;
|
|
65
|
-
}
|
|
49
|
+
async getTransaction(chainName, txHash, quoteCurrency, noLogs, withDex, withNftSales, withLending) {
|
|
50
|
+
let retryCount = 0;
|
|
51
|
+
let success = false;
|
|
52
|
+
while (!success) {
|
|
53
|
+
try {
|
|
54
|
+
const urlParams = new URLSearchParams();
|
|
55
|
+
if (quoteCurrency !== undefined) {
|
|
56
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
57
|
+
}
|
|
58
|
+
if (noLogs !== undefined) {
|
|
59
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
60
|
+
}
|
|
61
|
+
if (withDex !== undefined) {
|
|
62
|
+
urlParams.append("with-dex", withDex.toString());
|
|
66
63
|
}
|
|
67
|
-
|
|
64
|
+
if (withNftSales !== undefined) {
|
|
65
|
+
urlParams.append("with-nft-sales", withNftSales.toString());
|
|
66
|
+
}
|
|
67
|
+
if (withLending !== undefined) {
|
|
68
|
+
urlParams.append("with-lending", withLending.toString());
|
|
69
|
+
}
|
|
70
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
71
|
+
headers: {
|
|
72
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
if (data.error && data.error_code === 429) {
|
|
77
|
+
retryCount++;
|
|
78
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
68
82
|
success = true;
|
|
69
|
-
return
|
|
83
|
+
return data;
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
|
-
|
|
86
|
+
catch (error) {
|
|
87
|
+
success = true;
|
|
88
|
+
return error.message;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
73
91
|
}
|
|
74
92
|
/**
|
|
75
93
|
*
|
|
@@ -80,44 +98,42 @@ class TransactionsService {
|
|
|
80
98
|
* @param {boolean} blockSignedAtAsc - Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
|
|
81
99
|
*
|
|
82
100
|
*/
|
|
83
|
-
getTransactionsForAddress(chainName, walletAddress, quoteCurrency, noLogs, blockSignedAtAsc) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
92
|
-
}
|
|
93
|
-
if (noLogs !== undefined) {
|
|
94
|
-
urlParams.append("no-logs", noLogs.toString());
|
|
95
|
-
}
|
|
96
|
-
if (blockSignedAtAsc !== undefined) {
|
|
97
|
-
urlParams.append("block-signed-at-asc", blockSignedAtAsc.toString());
|
|
98
|
-
}
|
|
99
|
-
const response = yield fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v2/?${urlParams}`, {
|
|
100
|
-
headers: {
|
|
101
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const data = yield response.json();
|
|
105
|
-
if (data.error && data.error_code === 429) {
|
|
106
|
-
retryCount++;
|
|
107
|
-
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
108
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
success = true;
|
|
112
|
-
return data;
|
|
113
|
-
}
|
|
101
|
+
async getTransactionsForAddress(chainName, walletAddress, quoteCurrency, noLogs, blockSignedAtAsc) {
|
|
102
|
+
let retryCount = 0;
|
|
103
|
+
let success = false;
|
|
104
|
+
while (!success) {
|
|
105
|
+
try {
|
|
106
|
+
const urlParams = new URLSearchParams();
|
|
107
|
+
if (quoteCurrency !== undefined) {
|
|
108
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
114
109
|
}
|
|
115
|
-
|
|
110
|
+
if (noLogs !== undefined) {
|
|
111
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
112
|
+
}
|
|
113
|
+
if (blockSignedAtAsc !== undefined) {
|
|
114
|
+
urlParams.append("block-signed-at-asc", blockSignedAtAsc.toString());
|
|
115
|
+
}
|
|
116
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v2/?${urlParams}`, {
|
|
117
|
+
headers: {
|
|
118
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const data = await response.json();
|
|
122
|
+
if (data.error && data.error_code === 429) {
|
|
123
|
+
retryCount++;
|
|
124
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
116
128
|
success = true;
|
|
117
|
-
return
|
|
129
|
+
return data;
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
|
-
|
|
132
|
+
catch (error) {
|
|
133
|
+
success = true;
|
|
134
|
+
return error.message;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
121
137
|
}
|
|
122
138
|
/**
|
|
123
139
|
*
|
|
@@ -127,41 +143,28 @@ class TransactionsService {
|
|
|
127
143
|
* @param {boolean} noLogs - Omit log events.
|
|
128
144
|
*
|
|
129
145
|
*/
|
|
130
|
-
getRecentTransactionsForAddress(chainName, walletAddress, quoteCurrency, noLogs) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
139
|
-
}
|
|
140
|
-
if (noLogs !== undefined) {
|
|
141
|
-
urlParams.append("no-logs", noLogs.toString());
|
|
142
|
-
}
|
|
143
|
-
const response = yield fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
144
|
-
headers: {
|
|
145
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
const data = yield response.json();
|
|
149
|
-
if (data.error && data.error_code === 429) {
|
|
150
|
-
retryCount++;
|
|
151
|
-
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
152
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
success = true;
|
|
156
|
-
return data;
|
|
157
|
-
}
|
|
146
|
+
async *getRecentTransactionsForAddress(chainName, walletAddress, quoteCurrency, noLogs) {
|
|
147
|
+
let retryCount = 0;
|
|
148
|
+
let success = false;
|
|
149
|
+
while (!success) {
|
|
150
|
+
try {
|
|
151
|
+
const urlParams = new URLSearchParams();
|
|
152
|
+
if (quoteCurrency !== undefined) {
|
|
153
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
158
154
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return error.message;
|
|
155
|
+
if (noLogs !== undefined) {
|
|
156
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
162
157
|
}
|
|
158
|
+
for await (const response of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams)) {
|
|
159
|
+
yield response;
|
|
160
|
+
}
|
|
161
|
+
success = true;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
success = true;
|
|
165
|
+
return error.message;
|
|
163
166
|
}
|
|
164
|
-
}
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
/**
|
|
167
170
|
*
|
|
@@ -172,41 +175,39 @@ class TransactionsService {
|
|
|
172
175
|
* @param {boolean} noLogs - Omit log events.
|
|
173
176
|
*
|
|
174
177
|
*/
|
|
175
|
-
getTransactionsForAddressV3(chainName, walletAddress, page, quoteCurrency, noLogs) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
urlParams.append("no-logs", noLogs.toString());
|
|
187
|
-
}
|
|
188
|
-
const response = yield fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
189
|
-
headers: {
|
|
190
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
const data = yield response.json();
|
|
194
|
-
if (data.error && data.error_code === 429) {
|
|
195
|
-
retryCount++;
|
|
196
|
-
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
197
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
success = true;
|
|
201
|
-
return data;
|
|
202
|
-
}
|
|
178
|
+
async getTransactionsForAddressV3(chainName, walletAddress, page, quoteCurrency, noLogs) {
|
|
179
|
+
let retryCount = 0;
|
|
180
|
+
let success = false;
|
|
181
|
+
while (!success) {
|
|
182
|
+
try {
|
|
183
|
+
const urlParams = new URLSearchParams();
|
|
184
|
+
if (quoteCurrency !== undefined) {
|
|
185
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
186
|
+
}
|
|
187
|
+
if (noLogs !== undefined) {
|
|
188
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
203
189
|
}
|
|
204
|
-
|
|
190
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
191
|
+
headers: {
|
|
192
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
const data = await response.json();
|
|
196
|
+
if (data.error && data.error_code === 429) {
|
|
197
|
+
retryCount++;
|
|
198
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
199
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
205
202
|
success = true;
|
|
206
|
-
return
|
|
203
|
+
return data;
|
|
207
204
|
}
|
|
208
205
|
}
|
|
209
|
-
|
|
206
|
+
catch (error) {
|
|
207
|
+
success = true;
|
|
208
|
+
return error.message;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
210
211
|
}
|
|
211
212
|
/**
|
|
212
213
|
*
|
|
@@ -217,41 +218,39 @@ class TransactionsService {
|
|
|
217
218
|
* @param {boolean} noLogs - Omit log events.
|
|
218
219
|
*
|
|
219
220
|
*/
|
|
220
|
-
getTimeBucketTransactionsForAddress(chainName, walletAddress, timeBucket, quoteCurrency, noLogs) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
229
|
-
}
|
|
230
|
-
if (noLogs !== undefined) {
|
|
231
|
-
urlParams.append("no-logs", noLogs.toString());
|
|
232
|
-
}
|
|
233
|
-
const response = yield fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
234
|
-
headers: {
|
|
235
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
const data = yield response.json();
|
|
239
|
-
if (data.error && data.error_code === 429) {
|
|
240
|
-
retryCount++;
|
|
241
|
-
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
242
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
success = true;
|
|
246
|
-
return data;
|
|
247
|
-
}
|
|
221
|
+
async getTimeBucketTransactionsForAddress(chainName, walletAddress, timeBucket, quoteCurrency, noLogs) {
|
|
222
|
+
let retryCount = 0;
|
|
223
|
+
let success = false;
|
|
224
|
+
while (!success) {
|
|
225
|
+
try {
|
|
226
|
+
const urlParams = new URLSearchParams();
|
|
227
|
+
if (quoteCurrency !== undefined) {
|
|
228
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
248
229
|
}
|
|
249
|
-
|
|
230
|
+
if (noLogs !== undefined) {
|
|
231
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
232
|
+
}
|
|
233
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
234
|
+
headers: {
|
|
235
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
const data = await response.json();
|
|
239
|
+
if (data.error && data.error_code === 429) {
|
|
240
|
+
retryCount++;
|
|
241
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
242
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
250
245
|
success = true;
|
|
251
|
-
return
|
|
246
|
+
return data;
|
|
252
247
|
}
|
|
253
248
|
}
|
|
254
|
-
|
|
249
|
+
catch (error) {
|
|
250
|
+
success = true;
|
|
251
|
+
return error.message;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
255
254
|
}
|
|
256
255
|
/**
|
|
257
256
|
*
|
|
@@ -261,41 +260,39 @@ class TransactionsService {
|
|
|
261
260
|
* @param {boolean} noLogs - Omit log events.
|
|
262
261
|
*
|
|
263
262
|
*/
|
|
264
|
-
getEarliestTimeBucketTransactionsForAddress(chainName, walletAddress, quoteCurrency, noLogs) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
success = true;
|
|
290
|
-
return data;
|
|
291
|
-
}
|
|
263
|
+
async getEarliestTimeBucketTransactionsForAddress(chainName, walletAddress, quoteCurrency, noLogs) {
|
|
264
|
+
let retryCount = 0;
|
|
265
|
+
let success = false;
|
|
266
|
+
while (!success) {
|
|
267
|
+
try {
|
|
268
|
+
const urlParams = new URLSearchParams();
|
|
269
|
+
if (quoteCurrency !== undefined) {
|
|
270
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
271
|
+
}
|
|
272
|
+
if (noLogs !== undefined) {
|
|
273
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
274
|
+
}
|
|
275
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/?${urlParams}`, {
|
|
276
|
+
headers: {
|
|
277
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
const data = await response.json();
|
|
281
|
+
if (data.error && data.error_code === 429) {
|
|
282
|
+
retryCount++;
|
|
283
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
284
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
292
285
|
}
|
|
293
|
-
|
|
286
|
+
else {
|
|
294
287
|
success = true;
|
|
295
|
-
return
|
|
288
|
+
return data;
|
|
296
289
|
}
|
|
297
290
|
}
|
|
298
|
-
|
|
291
|
+
catch (error) {
|
|
292
|
+
success = true;
|
|
293
|
+
return error.message;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
299
296
|
}
|
|
300
297
|
/**
|
|
301
298
|
*
|
|
@@ -306,41 +303,39 @@ class TransactionsService {
|
|
|
306
303
|
* @param {boolean} noLogs - Omit log events.
|
|
307
304
|
*
|
|
308
305
|
*/
|
|
309
|
-
getTransactionsForBlockByPage(chainName, blockHeight, page, quoteCurrency, noLogs) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
318
|
-
}
|
|
319
|
-
if (noLogs !== undefined) {
|
|
320
|
-
urlParams.append("no-logs", noLogs.toString());
|
|
321
|
-
}
|
|
322
|
-
const response = yield fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
323
|
-
headers: {
|
|
324
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
const data = yield response.json();
|
|
328
|
-
if (data.error && data.error_code === 429) {
|
|
329
|
-
retryCount++;
|
|
330
|
-
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
331
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
success = true;
|
|
335
|
-
return data;
|
|
336
|
-
}
|
|
306
|
+
async getTransactionsForBlockByPage(chainName, blockHeight, page, quoteCurrency, noLogs) {
|
|
307
|
+
let retryCount = 0;
|
|
308
|
+
let success = false;
|
|
309
|
+
while (!success) {
|
|
310
|
+
try {
|
|
311
|
+
const urlParams = new URLSearchParams();
|
|
312
|
+
if (quoteCurrency !== undefined) {
|
|
313
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
337
314
|
}
|
|
338
|
-
|
|
315
|
+
if (noLogs !== undefined) {
|
|
316
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
317
|
+
}
|
|
318
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
319
|
+
headers: {
|
|
320
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
const data = await response.json();
|
|
324
|
+
if (data.error && data.error_code === 429) {
|
|
325
|
+
retryCount++;
|
|
326
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
327
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
339
330
|
success = true;
|
|
340
|
-
return
|
|
331
|
+
return data;
|
|
341
332
|
}
|
|
342
333
|
}
|
|
343
|
-
|
|
334
|
+
catch (error) {
|
|
335
|
+
success = true;
|
|
336
|
+
return error.message;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
344
339
|
}
|
|
345
340
|
/**
|
|
346
341
|
*
|
|
@@ -350,41 +345,39 @@ class TransactionsService {
|
|
|
350
345
|
* @param {boolean} noLogs - Omit log events.
|
|
351
346
|
*
|
|
352
347
|
*/
|
|
353
|
-
getTransactionsForBlock(chainName, blockHeight, quoteCurrency, noLogs) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
success = true;
|
|
379
|
-
return data;
|
|
380
|
-
}
|
|
348
|
+
async getTransactionsForBlock(chainName, blockHeight, quoteCurrency, noLogs) {
|
|
349
|
+
let retryCount = 0;
|
|
350
|
+
let success = false;
|
|
351
|
+
while (!success) {
|
|
352
|
+
try {
|
|
353
|
+
const urlParams = new URLSearchParams();
|
|
354
|
+
if (quoteCurrency !== undefined) {
|
|
355
|
+
urlParams.append("quote-currency", quoteCurrency.toString());
|
|
356
|
+
}
|
|
357
|
+
if (noLogs !== undefined) {
|
|
358
|
+
urlParams.append("no-logs", noLogs.toString());
|
|
359
|
+
}
|
|
360
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
|
|
361
|
+
headers: {
|
|
362
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
const data = await response.json();
|
|
366
|
+
if (data.error && data.error_code === 429) {
|
|
367
|
+
retryCount++;
|
|
368
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
369
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
381
370
|
}
|
|
382
|
-
|
|
371
|
+
else {
|
|
383
372
|
success = true;
|
|
384
|
-
return
|
|
373
|
+
return data;
|
|
385
374
|
}
|
|
386
375
|
}
|
|
387
|
-
|
|
376
|
+
catch (error) {
|
|
377
|
+
success = true;
|
|
378
|
+
return error.message;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
388
381
|
}
|
|
389
382
|
/**
|
|
390
383
|
*
|
|
@@ -392,35 +385,33 @@ class TransactionsService {
|
|
|
392
385
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
393
386
|
*
|
|
394
387
|
*/
|
|
395
|
-
getTransactionSummary(chainName, walletAddress) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
yield new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
success = true;
|
|
415
|
-
return data;
|
|
416
|
-
}
|
|
388
|
+
async getTransactionSummary(chainName, walletAddress) {
|
|
389
|
+
let retryCount = 0;
|
|
390
|
+
let success = false;
|
|
391
|
+
while (!success) {
|
|
392
|
+
try {
|
|
393
|
+
const urlParams = new URLSearchParams();
|
|
394
|
+
const response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
|
|
395
|
+
headers: {
|
|
396
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
const data = await response.json();
|
|
400
|
+
if (data.error && data.error_code === 429) {
|
|
401
|
+
retryCount++;
|
|
402
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
403
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
417
404
|
}
|
|
418
|
-
|
|
405
|
+
else {
|
|
419
406
|
success = true;
|
|
420
|
-
return
|
|
407
|
+
return data;
|
|
421
408
|
}
|
|
422
409
|
}
|
|
423
|
-
|
|
410
|
+
catch (error) {
|
|
411
|
+
success = true;
|
|
412
|
+
return error.message;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
424
415
|
}
|
|
425
416
|
}
|
|
426
417
|
exports.TransactionsService = TransactionsService;
|