@covalenthq/client-sdk 0.2.4 → 0.2.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 -5
- package/dist/services/BalanceService.d.ts +90 -74
- package/dist/services/BalanceService.js +91 -151
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +70 -76
- package/dist/services/BaseService.js +80 -162
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/Client.d.ts +8 -2
- package/dist/services/Client.js +5 -2
- package/dist/services/Client.js.map +1 -1
- package/dist/services/NftService.d.ts +66 -40
- package/dist/services/NftService.js +68 -135
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +13 -4
- package/dist/services/PricingService.js +11 -10
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +1 -7
- package/dist/services/SecurityService.js +1 -4
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +39 -22
- package/dist/services/TransactionService.js +34 -34
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +1 -7
- package/dist/services/XykService.js +1 -4
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +3 -0
- package/dist/util/ApiHelpers.js +59 -1
- package/dist/util/ApiHelpers.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Chains } from "./Client";
|
|
1
|
+
import { Chains, Response } from "./Client";
|
|
2
2
|
declare class BlockResponse {
|
|
3
3
|
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
4
4
|
updated_at: Date;
|
|
@@ -35,30 +35,6 @@ declare class ResolvedAddressItem {
|
|
|
35
35
|
name: string;
|
|
36
36
|
constructor(data: ResolvedAddressItem);
|
|
37
37
|
}
|
|
38
|
-
declare class BlockHeightsResponse {
|
|
39
|
-
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
40
|
-
updated_at: Date;
|
|
41
|
-
/** * The requested chain ID eg: `1`. */
|
|
42
|
-
chain_id: number;
|
|
43
|
-
/** * The requested chain name eg: `eth-mainnet`. */
|
|
44
|
-
chain_name: string;
|
|
45
|
-
/** * List of response items. */
|
|
46
|
-
items: Block[];
|
|
47
|
-
/** * Pagination metadata. */
|
|
48
|
-
pagination: Pagination;
|
|
49
|
-
constructor(data: BlockHeightsResponse);
|
|
50
|
-
}
|
|
51
|
-
declare class Pagination {
|
|
52
|
-
/** * True is there is another page. */
|
|
53
|
-
has_more: boolean;
|
|
54
|
-
/** * The requested page number. */
|
|
55
|
-
page_number: number;
|
|
56
|
-
/** * The requested number of items on the current page. */
|
|
57
|
-
page_size: number;
|
|
58
|
-
/** * The total number of items across all pages for this request. */
|
|
59
|
-
total_count: number;
|
|
60
|
-
constructor(data: Pagination);
|
|
61
|
-
}
|
|
62
38
|
declare class GetLogsResponse {
|
|
63
39
|
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
64
40
|
updated_at: Date;
|
|
@@ -110,19 +86,6 @@ declare class Param {
|
|
|
110
86
|
value: string;
|
|
111
87
|
constructor(data: Param);
|
|
112
88
|
}
|
|
113
|
-
declare class LogEventsByAddressResponse {
|
|
114
|
-
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
115
|
-
updated_at: Date;
|
|
116
|
-
/** * The requested chain ID eg: `1`. */
|
|
117
|
-
chain_id: number;
|
|
118
|
-
/** * The requested chain name eg: `eth-mainnet`. */
|
|
119
|
-
chain_name: string;
|
|
120
|
-
/** * List of response items. */
|
|
121
|
-
items: LogEvent[];
|
|
122
|
-
/** * Pagination metadata. */
|
|
123
|
-
pagination: Pagination;
|
|
124
|
-
constructor(data: LogEventsByAddressResponse);
|
|
125
|
-
}
|
|
126
89
|
declare class LogEvent {
|
|
127
90
|
/** * The block signed timestamp in UTC. */
|
|
128
91
|
block_signed_at: Date;
|
|
@@ -146,19 +109,6 @@ declare class LogEvent {
|
|
|
146
109
|
decoded: DecodedItem;
|
|
147
110
|
constructor(data: LogEvent);
|
|
148
111
|
}
|
|
149
|
-
declare class LogEventsByTopicHashResponse {
|
|
150
|
-
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
151
|
-
updated_at: Date;
|
|
152
|
-
/** * The requested chain ID eg: `1`. */
|
|
153
|
-
chain_id: number;
|
|
154
|
-
/** * The requested chain name eg: `eth-mainnet`. */
|
|
155
|
-
chain_name: string;
|
|
156
|
-
/** * List of response items. */
|
|
157
|
-
items: LogEvent[];
|
|
158
|
-
/** * Pagination metadata. */
|
|
159
|
-
pagination: Pagination;
|
|
160
|
-
constructor(data: LogEventsByTopicHashResponse);
|
|
161
|
-
}
|
|
162
112
|
declare class AllChainsResponse {
|
|
163
113
|
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
164
114
|
updated_at: Date;
|
|
@@ -221,16 +171,52 @@ declare class ChainStatusItem {
|
|
|
221
171
|
has_data: boolean;
|
|
222
172
|
constructor(data: ChainStatusItem);
|
|
223
173
|
}
|
|
174
|
+
export interface GetBlockHeightsQueryParamOpts {
|
|
175
|
+
/** * Number of items per page. Omitting this parameter defaults to 100. */
|
|
176
|
+
pageSize?: number;
|
|
177
|
+
/** * 0-indexed page number to begin pagination. */
|
|
178
|
+
pageNumber?: number;
|
|
179
|
+
}
|
|
180
|
+
export interface GetLogsQueryParamOpts {
|
|
181
|
+
/** * The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`. */
|
|
182
|
+
startingBlock?: number;
|
|
183
|
+
/** * The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`. */
|
|
184
|
+
endingBlock?: string;
|
|
185
|
+
/** * The address of the log events sender contract. */
|
|
186
|
+
address?: string;
|
|
187
|
+
/** * The topic hash(es) to retrieve logs with. */
|
|
188
|
+
topics?: string;
|
|
189
|
+
/** * The block hash to retrieve logs for. */
|
|
190
|
+
blockHash?: string;
|
|
191
|
+
/** * Omit decoded log events. */
|
|
192
|
+
skipDecode?: boolean;
|
|
193
|
+
}
|
|
194
|
+
export interface GetLogEventsByAddressQueryParamOpts {
|
|
195
|
+
/** * The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`. */
|
|
196
|
+
startingBlock?: number;
|
|
197
|
+
/** * The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`. */
|
|
198
|
+
endingBlock?: string;
|
|
199
|
+
/** * Number of items per page. Omitting this parameter defaults to 100. */
|
|
200
|
+
pageSize?: number;
|
|
201
|
+
/** * 0-indexed page number to begin pagination. */
|
|
202
|
+
pageNumber?: number;
|
|
203
|
+
}
|
|
204
|
+
export interface GetLogEventsByTopicHashQueryParamOpts {
|
|
205
|
+
/** * The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`. */
|
|
206
|
+
startingBlock?: number;
|
|
207
|
+
/** * The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`. */
|
|
208
|
+
endingBlock?: string;
|
|
209
|
+
/** * Additional topic hash(es) to filter on - padded & unpadded address fields are supported. */
|
|
210
|
+
secondaryTopics?: string;
|
|
211
|
+
/** * Number of items per page. Omitting this parameter defaults to 100. */
|
|
212
|
+
pageSize?: number;
|
|
213
|
+
/** * 0-indexed page number to begin pagination. */
|
|
214
|
+
pageNumber?: number;
|
|
215
|
+
}
|
|
224
216
|
/**
|
|
225
217
|
* Class A - Base
|
|
226
218
|
*
|
|
227
219
|
*/
|
|
228
|
-
export declare class Response<T> {
|
|
229
|
-
data: T;
|
|
230
|
-
error: boolean;
|
|
231
|
-
error_code: number;
|
|
232
|
-
error_message: string;
|
|
233
|
-
}
|
|
234
220
|
export declare class BaseService {
|
|
235
221
|
private apiKey;
|
|
236
222
|
constructor(apiKey: string);
|
|
@@ -251,51 +237,59 @@ export declare class BaseService {
|
|
|
251
237
|
/**
|
|
252
238
|
*
|
|
253
239
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
254
|
-
* @param {
|
|
255
|
-
* @param {
|
|
240
|
+
* @param {string} startDate - The start date in YYYY-MM-DD format.
|
|
241
|
+
* @param {string} endDate - The end date in YYYY-MM-DD format.
|
|
242
|
+
* @param {GetBlockHeightsQueryParamOpts} queryParamOpts
|
|
243
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
244
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
256
245
|
*
|
|
257
246
|
*/
|
|
258
|
-
getBlockHeights(chainName: Chains, startDate: string, endDate: string):
|
|
247
|
+
getBlockHeights(chainName: Chains, startDate: string, endDate: string, queryParamOpts?: GetBlockHeightsQueryParamOpts): AsyncIterable<Block>;
|
|
259
248
|
/**
|
|
260
249
|
*
|
|
261
250
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
262
|
-
* @param {
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
251
|
+
* @param {GetLogsQueryParamOpts} queryParamOpts
|
|
252
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
253
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
254
|
+
* - `address`: The address of the log events sender contract.
|
|
255
|
+
* - `topics`: The topic hash(es) to retrieve logs with.
|
|
256
|
+
* - `blockHash`: The block hash to retrieve logs for.
|
|
257
|
+
* - `skipDecode`: Omit decoded log events.
|
|
268
258
|
*
|
|
269
259
|
*/
|
|
270
|
-
getLogs(chainName: Chains,
|
|
260
|
+
getLogs(chainName: Chains, queryParamOpts?: GetLogsQueryParamOpts): Promise<Response<GetLogsResponse>>;
|
|
271
261
|
/**
|
|
272
262
|
*
|
|
273
263
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
274
264
|
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
275
|
-
* @param {
|
|
276
|
-
*
|
|
265
|
+
* @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
|
|
266
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
267
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
268
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
269
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
277
270
|
*
|
|
278
271
|
*/
|
|
279
|
-
getLogEventsByAddress(chainName: Chains, contractAddress: string,
|
|
272
|
+
getLogEventsByAddress(chainName: Chains, contractAddress: string, queryParamOpts?: GetLogEventsByAddressQueryParamOpts): AsyncIterable<LogEvent>;
|
|
280
273
|
/**
|
|
281
274
|
*
|
|
282
275
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
283
276
|
* @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
|
|
284
|
-
* @param {
|
|
285
|
-
*
|
|
286
|
-
*
|
|
277
|
+
* @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
|
|
278
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
279
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
280
|
+
* - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported.
|
|
281
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
282
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
287
283
|
*
|
|
288
284
|
*/
|
|
289
|
-
getLogEventsByTopicHash(chainName: Chains, topicHash: string,
|
|
285
|
+
getLogEventsByTopicHash(chainName: Chains, topicHash: string, queryParamOpts?: GetLogEventsByTopicHashQueryParamOpts): AsyncIterable<LogEvent>;
|
|
290
286
|
/**
|
|
291
287
|
*
|
|
292
|
-
|
|
293
288
|
*
|
|
294
289
|
*/
|
|
295
290
|
getAllChains(): Promise<Response<AllChainsResponse>>;
|
|
296
291
|
/**
|
|
297
292
|
*
|
|
298
|
-
|
|
299
293
|
*
|
|
300
294
|
*/
|
|
301
295
|
getAllChainStatus(): Promise<Response<AllChainsStatusResponse>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseService =
|
|
3
|
+
exports.BaseService = void 0;
|
|
4
4
|
const Client_1 = require("./Client");
|
|
5
5
|
const ApiHelpers_1 = require("../util/ApiHelpers");
|
|
6
6
|
const date_fns_1 = require("date-fns");
|
|
@@ -175,9 +175,6 @@ class ChainStatusItem {
|
|
|
175
175
|
* Class A - Base
|
|
176
176
|
*
|
|
177
177
|
*/
|
|
178
|
-
class Response {
|
|
179
|
-
}
|
|
180
|
-
exports.Response = Response;
|
|
181
178
|
class BaseService {
|
|
182
179
|
constructor(apiKey) {
|
|
183
180
|
this.apiKey = apiKey;
|
|
@@ -301,74 +298,49 @@ class BaseService {
|
|
|
301
298
|
/**
|
|
302
299
|
*
|
|
303
300
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
304
|
-
* @param {
|
|
305
|
-
* @param {
|
|
301
|
+
* @param {string} startDate - The start date in YYYY-MM-DD format.
|
|
302
|
+
* @param {string} endDate - The end date in YYYY-MM-DD format.
|
|
303
|
+
* @param {GetBlockHeightsQueryParamOpts} queryParamOpts
|
|
304
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
305
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
306
306
|
*
|
|
307
307
|
*/
|
|
308
|
-
async getBlockHeights(chainName, startDate, endDate) {
|
|
308
|
+
async *getBlockHeights(chainName, startDate, endDate, queryParamOpts) {
|
|
309
309
|
let success = false;
|
|
310
|
-
let
|
|
311
|
-
let response;
|
|
312
|
-
const backoff = new backoff_1.ExponentialBackoff();
|
|
310
|
+
let res;
|
|
313
311
|
while (!success) {
|
|
314
312
|
try {
|
|
315
313
|
const urlParams = new URLSearchParams();
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
319
|
-
"X-Requested-With": Client_1.userAgent
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
data = await response.json();
|
|
323
|
-
if (data.error && data.error_code === 429) {
|
|
324
|
-
try {
|
|
325
|
-
await backoff.backOff();
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
success = true;
|
|
329
|
-
return {
|
|
330
|
-
data: null,
|
|
331
|
-
error: data.error,
|
|
332
|
-
error_code: data ? data.error_code : response.status,
|
|
333
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
334
|
-
};
|
|
335
|
-
}
|
|
314
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
315
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
336
316
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
340
|
-
success = true;
|
|
341
|
-
return {
|
|
342
|
-
data: dataClass,
|
|
343
|
-
error: data.error,
|
|
344
|
-
error_code: data ? data.error_code : response.status,
|
|
345
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
346
|
-
};
|
|
317
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
318
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
347
319
|
}
|
|
320
|
+
for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block)) {
|
|
321
|
+
yield res;
|
|
322
|
+
}
|
|
323
|
+
success = true;
|
|
348
324
|
}
|
|
349
325
|
catch (error) {
|
|
350
326
|
success = true;
|
|
351
|
-
return
|
|
352
|
-
data: null,
|
|
353
|
-
error: true,
|
|
354
|
-
error_code: data ? data.error_code : response.status,
|
|
355
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
356
|
-
};
|
|
327
|
+
return res;
|
|
357
328
|
}
|
|
358
329
|
}
|
|
359
330
|
}
|
|
360
331
|
/**
|
|
361
332
|
*
|
|
362
333
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
363
|
-
* @param {
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
334
|
+
* @param {GetLogsQueryParamOpts} queryParamOpts
|
|
335
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
336
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
337
|
+
* - `address`: The address of the log events sender contract.
|
|
338
|
+
* - `topics`: The topic hash(es) to retrieve logs with.
|
|
339
|
+
* - `blockHash`: The block hash to retrieve logs for.
|
|
340
|
+
* - `skipDecode`: Omit decoded log events.
|
|
369
341
|
*
|
|
370
342
|
*/
|
|
371
|
-
async getLogs(chainName,
|
|
343
|
+
async getLogs(chainName, queryParamOpts) {
|
|
372
344
|
let success = false;
|
|
373
345
|
let data;
|
|
374
346
|
let response;
|
|
@@ -376,23 +348,23 @@ class BaseService {
|
|
|
376
348
|
while (!success) {
|
|
377
349
|
try {
|
|
378
350
|
const urlParams = new URLSearchParams();
|
|
379
|
-
if (startingBlock !== undefined) {
|
|
380
|
-
urlParams.append("starting-block", startingBlock.toString());
|
|
351
|
+
if (queryParamOpts?.startingBlock !== undefined) {
|
|
352
|
+
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
381
353
|
}
|
|
382
|
-
if (endingBlock !== undefined) {
|
|
383
|
-
urlParams.append("ending-block", endingBlock.toString());
|
|
354
|
+
if (queryParamOpts?.endingBlock !== undefined) {
|
|
355
|
+
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
384
356
|
}
|
|
385
|
-
if (address !== undefined) {
|
|
386
|
-
urlParams.append("address", address.toString());
|
|
357
|
+
if (queryParamOpts?.address !== undefined) {
|
|
358
|
+
urlParams.append("address", queryParamOpts?.address.toString());
|
|
387
359
|
}
|
|
388
|
-
if (topics !== undefined) {
|
|
389
|
-
urlParams.append("topics", topics.toString());
|
|
360
|
+
if (queryParamOpts?.topics !== undefined) {
|
|
361
|
+
urlParams.append("topics", queryParamOpts?.topics.toString());
|
|
390
362
|
}
|
|
391
|
-
if (blockHash !== undefined) {
|
|
392
|
-
urlParams.append("block-hash", blockHash.toString());
|
|
363
|
+
if (queryParamOpts?.blockHash !== undefined) {
|
|
364
|
+
urlParams.append("block-hash", queryParamOpts?.blockHash.toString());
|
|
393
365
|
}
|
|
394
|
-
if (skipDecode !== undefined) {
|
|
395
|
-
urlParams.append("skip-decode", skipDecode.toString());
|
|
366
|
+
if (queryParamOpts?.skipDecode !== undefined) {
|
|
367
|
+
urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
|
|
396
368
|
}
|
|
397
369
|
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
|
|
398
370
|
headers: {
|
|
@@ -442,65 +414,39 @@ class BaseService {
|
|
|
442
414
|
*
|
|
443
415
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
444
416
|
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
445
|
-
* @param {
|
|
446
|
-
*
|
|
417
|
+
* @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
|
|
418
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
419
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
420
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
421
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
447
422
|
*
|
|
448
423
|
*/
|
|
449
|
-
async getLogEventsByAddress(chainName, contractAddress,
|
|
424
|
+
async *getLogEventsByAddress(chainName, contractAddress, queryParamOpts) {
|
|
450
425
|
let success = false;
|
|
451
|
-
let
|
|
452
|
-
let response;
|
|
453
|
-
const backoff = new backoff_1.ExponentialBackoff();
|
|
426
|
+
let res;
|
|
454
427
|
while (!success) {
|
|
455
428
|
try {
|
|
456
429
|
const urlParams = new URLSearchParams();
|
|
457
|
-
if (startingBlock !== undefined) {
|
|
458
|
-
urlParams.append("starting-block", startingBlock.toString());
|
|
430
|
+
if (queryParamOpts?.startingBlock !== undefined) {
|
|
431
|
+
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
459
432
|
}
|
|
460
|
-
if (endingBlock !== undefined) {
|
|
461
|
-
urlParams.append("ending-block", endingBlock.toString());
|
|
433
|
+
if (queryParamOpts?.endingBlock !== undefined) {
|
|
434
|
+
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
462
435
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
466
|
-
"X-Requested-With": Client_1.userAgent
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
data = await response.json();
|
|
470
|
-
if (data.error && data.error_code === 429) {
|
|
471
|
-
try {
|
|
472
|
-
await backoff.backOff();
|
|
473
|
-
}
|
|
474
|
-
catch (error) {
|
|
475
|
-
success = true;
|
|
476
|
-
return {
|
|
477
|
-
data: null,
|
|
478
|
-
error: data.error,
|
|
479
|
-
error_code: data ? data.error_code : response.status,
|
|
480
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
481
|
-
};
|
|
482
|
-
}
|
|
436
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
437
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
483
438
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
487
|
-
success = true;
|
|
488
|
-
return {
|
|
489
|
-
data: dataClass,
|
|
490
|
-
error: data.error,
|
|
491
|
-
error_code: data ? data.error_code : response.status,
|
|
492
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
493
|
-
};
|
|
439
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
440
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
494
441
|
}
|
|
442
|
+
for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent)) {
|
|
443
|
+
yield res;
|
|
444
|
+
}
|
|
445
|
+
success = true;
|
|
495
446
|
}
|
|
496
447
|
catch (error) {
|
|
497
448
|
success = true;
|
|
498
|
-
return
|
|
499
|
-
data: null,
|
|
500
|
-
error: true,
|
|
501
|
-
error_code: data ? data.error_code : response.status,
|
|
502
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
503
|
-
};
|
|
449
|
+
return res;
|
|
504
450
|
}
|
|
505
451
|
}
|
|
506
452
|
}
|
|
@@ -508,75 +454,48 @@ class BaseService {
|
|
|
508
454
|
*
|
|
509
455
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
510
456
|
* @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
|
|
511
|
-
* @param {
|
|
512
|
-
*
|
|
513
|
-
*
|
|
457
|
+
* @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
|
|
458
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
459
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
460
|
+
* - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported.
|
|
461
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
462
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
514
463
|
*
|
|
515
464
|
*/
|
|
516
|
-
async getLogEventsByTopicHash(chainName, topicHash,
|
|
465
|
+
async *getLogEventsByTopicHash(chainName, topicHash, queryParamOpts) {
|
|
517
466
|
let success = false;
|
|
518
|
-
let
|
|
519
|
-
let response;
|
|
520
|
-
const backoff = new backoff_1.ExponentialBackoff();
|
|
467
|
+
let res;
|
|
521
468
|
while (!success) {
|
|
522
469
|
try {
|
|
523
470
|
const urlParams = new URLSearchParams();
|
|
524
|
-
if (startingBlock !== undefined) {
|
|
525
|
-
urlParams.append("starting-block", startingBlock.toString());
|
|
471
|
+
if (queryParamOpts?.startingBlock !== undefined) {
|
|
472
|
+
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
526
473
|
}
|
|
527
|
-
if (endingBlock !== undefined) {
|
|
528
|
-
urlParams.append("ending-block", endingBlock.toString());
|
|
474
|
+
if (queryParamOpts?.endingBlock !== undefined) {
|
|
475
|
+
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
529
476
|
}
|
|
530
|
-
if (secondaryTopics !== undefined) {
|
|
531
|
-
urlParams.append("secondary-topics", secondaryTopics.toString());
|
|
477
|
+
if (queryParamOpts?.secondaryTopics !== undefined) {
|
|
478
|
+
urlParams.append("secondary-topics", queryParamOpts?.secondaryTopics.toString());
|
|
532
479
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
536
|
-
"X-Requested-With": Client_1.userAgent
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
data = await response.json();
|
|
540
|
-
if (data.error && data.error_code === 429) {
|
|
541
|
-
try {
|
|
542
|
-
await backoff.backOff();
|
|
543
|
-
}
|
|
544
|
-
catch (error) {
|
|
545
|
-
success = true;
|
|
546
|
-
return {
|
|
547
|
-
data: null,
|
|
548
|
-
error: data.error,
|
|
549
|
-
error_code: data ? data.error_code : response.status,
|
|
550
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
551
|
-
};
|
|
552
|
-
}
|
|
480
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
481
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
553
482
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
data: dataClass,
|
|
560
|
-
error: data.error,
|
|
561
|
-
error_code: data ? data.error_code : response.status,
|
|
562
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
563
|
-
};
|
|
483
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
484
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
485
|
+
}
|
|
486
|
+
for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent)) {
|
|
487
|
+
yield res;
|
|
564
488
|
}
|
|
489
|
+
success = true;
|
|
565
490
|
}
|
|
566
491
|
catch (error) {
|
|
567
492
|
success = true;
|
|
568
|
-
return
|
|
569
|
-
data: null,
|
|
570
|
-
error: true,
|
|
571
|
-
error_code: data ? data.error_code : response.status,
|
|
572
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
573
|
-
};
|
|
493
|
+
return res;
|
|
574
494
|
}
|
|
575
495
|
}
|
|
576
496
|
}
|
|
577
497
|
/**
|
|
578
498
|
*
|
|
579
|
-
|
|
580
499
|
*
|
|
581
500
|
*/
|
|
582
501
|
async getAllChains() {
|
|
@@ -633,7 +552,6 @@ class BaseService {
|
|
|
633
552
|
}
|
|
634
553
|
/**
|
|
635
554
|
*
|
|
636
|
-
|
|
637
555
|
*
|
|
638
556
|
*/
|
|
639
557
|
async getAllChainStatus() {
|