@secondlayer/sdk 13.1.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/index.d.ts +466 -65
- package/dist/index.js +157 -49
- package/dist/index.js.map +9 -9
- package/dist/streams/index.d.ts +220 -43
- package/dist/streams/index.js +116 -49
- package/dist/streams/index.js.map +7 -7
- package/dist/subgraphs/index.d.ts +462 -62
- package/dist/subgraphs/index.js +156 -49
- package/dist/subgraphs/index.js.map +6 -6
- package/package.json +4 -4
package/dist/subgraphs/index.js
CHANGED
|
@@ -467,6 +467,7 @@ function subscribeStreamsEvents(opts) {
|
|
|
467
467
|
while (!controller.signal.aborted) {
|
|
468
468
|
try {
|
|
469
469
|
const url = `${opts.baseUrl}/v1/streams/events/stream${buildQuery({
|
|
470
|
+
chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
|
|
470
471
|
from_cursor: cursor ?? undefined,
|
|
471
472
|
types: params.types,
|
|
472
473
|
not_types: params.notTypes,
|
|
@@ -474,6 +475,8 @@ function subscribeStreamsEvents(opts) {
|
|
|
474
475
|
sender: params.sender,
|
|
475
476
|
recipient: params.recipient,
|
|
476
477
|
asset_identifier: params.assetIdentifier,
|
|
478
|
+
rune: params.rune,
|
|
479
|
+
address: params.address,
|
|
477
480
|
filters: params.filters ? JSON.stringify(params.filters) : undefined
|
|
478
481
|
})}`;
|
|
479
482
|
await readSse({
|
|
@@ -1325,12 +1328,15 @@ async function consumeStreamsEvents(opts) {
|
|
|
1325
1328
|
const envelope = await fetchPageWithRetry(() => opts.fetchEvents({
|
|
1326
1329
|
cursor,
|
|
1327
1330
|
limit: opts.batchSize,
|
|
1331
|
+
chain: opts.chain,
|
|
1328
1332
|
types: opts.types,
|
|
1329
1333
|
notTypes: opts.notTypes,
|
|
1330
1334
|
contractId: opts.contractId,
|
|
1331
1335
|
sender: opts.sender,
|
|
1332
1336
|
recipient: opts.recipient,
|
|
1333
1337
|
assetIdentifier: opts.assetIdentifier,
|
|
1338
|
+
rune: opts.rune,
|
|
1339
|
+
address: opts.address,
|
|
1334
1340
|
filters: opts.filters
|
|
1335
1341
|
}), {
|
|
1336
1342
|
retryCount: opts.retryCount,
|
|
@@ -1448,12 +1454,15 @@ async function* iterateStreamsBatches(opts) {
|
|
|
1448
1454
|
const envelope = await opts.fetchEvents({
|
|
1449
1455
|
cursor,
|
|
1450
1456
|
limit: opts.batchSize,
|
|
1457
|
+
chain: opts.chain,
|
|
1451
1458
|
types: opts.types,
|
|
1452
1459
|
notTypes: opts.notTypes,
|
|
1453
1460
|
contractId: opts.contractId,
|
|
1454
1461
|
sender: opts.sender,
|
|
1455
1462
|
recipient: opts.recipient,
|
|
1456
1463
|
assetIdentifier: opts.assetIdentifier,
|
|
1464
|
+
rune: opts.rune,
|
|
1465
|
+
address: opts.address,
|
|
1457
1466
|
filters: opts.filters
|
|
1458
1467
|
});
|
|
1459
1468
|
const checkpoint = envelope.next_cursor ?? cursor;
|
|
@@ -1486,12 +1495,15 @@ async function* streamStreamsEvents(opts) {
|
|
|
1486
1495
|
const envelope = await opts.fetchEvents({
|
|
1487
1496
|
cursor,
|
|
1488
1497
|
limit: opts.batchSize,
|
|
1498
|
+
chain: opts.chain,
|
|
1489
1499
|
types: opts.types,
|
|
1490
1500
|
notTypes: opts.notTypes,
|
|
1491
1501
|
contractId: opts.contractId,
|
|
1492
1502
|
sender: opts.sender,
|
|
1493
1503
|
recipient: opts.recipient,
|
|
1494
1504
|
assetIdentifier: opts.assetIdentifier,
|
|
1505
|
+
rune: opts.rune,
|
|
1506
|
+
address: opts.address,
|
|
1495
1507
|
filters: opts.filters
|
|
1496
1508
|
});
|
|
1497
1509
|
pages++;
|
|
@@ -1773,6 +1785,15 @@ class Index extends BaseClient {
|
|
|
1773
1785
|
})
|
|
1774
1786
|
}
|
|
1775
1787
|
};
|
|
1788
|
+
runes = {
|
|
1789
|
+
list: (params = {}) => this.listRunes(params),
|
|
1790
|
+
get: (rune) => this.getRune(rune),
|
|
1791
|
+
balances: (params) => this.listRuneBalances(params),
|
|
1792
|
+
activity: {
|
|
1793
|
+
list: (params = {}) => this.listRuneActivity(params),
|
|
1794
|
+
walk: (params = {}) => this.walkRuneActivity(params)
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1776
1797
|
async listFtTransfers(params = {}) {
|
|
1777
1798
|
return this.request("GET", `/v1/index/ft-transfers${buildQuery({
|
|
1778
1799
|
...indexPageQuery(params),
|
|
@@ -2005,6 +2026,38 @@ class Index extends BaseClient {
|
|
|
2005
2026
|
async getPoxCycle(rewardCycle) {
|
|
2006
2027
|
return this.requestOrNull("GET", `/v1/index/pox/cycles/${rewardCycle}`);
|
|
2007
2028
|
}
|
|
2029
|
+
async listRunes(params = {}) {
|
|
2030
|
+
return this.request("GET", `/v1/index/runes${buildQuery({
|
|
2031
|
+
search: params.search,
|
|
2032
|
+
sort: params.sort,
|
|
2033
|
+
cursor: params.cursor,
|
|
2034
|
+
limit: params.limit
|
|
2035
|
+
})}`, undefined, { signal: params.signal });
|
|
2036
|
+
}
|
|
2037
|
+
async getRune(rune) {
|
|
2038
|
+
return this.requestOrNull("GET", `/v1/index/runes/${encodeURIComponent(rune)}`);
|
|
2039
|
+
}
|
|
2040
|
+
async listRuneActivity(params = {}) {
|
|
2041
|
+
return this.request("GET", `/v1/index/runes/activity${buildQuery({
|
|
2042
|
+
...indexPageQuery(params),
|
|
2043
|
+
rune: params.rune,
|
|
2044
|
+
address: params.address,
|
|
2045
|
+
kind: params.kind,
|
|
2046
|
+
txid: params.txid
|
|
2047
|
+
})}`, undefined, { signal: params.signal });
|
|
2048
|
+
}
|
|
2049
|
+
walkRuneActivity(params = {}) {
|
|
2050
|
+
return this.keysetWalk(params, (page) => this.listRuneActivity({ ...params, ...page }), (e) => e.events);
|
|
2051
|
+
}
|
|
2052
|
+
async listRuneBalances(params) {
|
|
2053
|
+
return this.request("GET", `/v1/index/runes/balances${buildQuery({
|
|
2054
|
+
address: params.address,
|
|
2055
|
+
outpoint: params.outpoint,
|
|
2056
|
+
rune: params.rune,
|
|
2057
|
+
cursor: params.cursor,
|
|
2058
|
+
limit: params.limit
|
|
2059
|
+
})}`, undefined, { signal: params.signal });
|
|
2060
|
+
}
|
|
2008
2061
|
}
|
|
2009
2062
|
|
|
2010
2063
|
// src/streams/client.ts
|
|
@@ -2223,12 +2276,15 @@ function maxCursor(a, b) {
|
|
|
2223
2276
|
}
|
|
2224
2277
|
function streamsFilters(params) {
|
|
2225
2278
|
return {
|
|
2279
|
+
chain: params.chain,
|
|
2226
2280
|
types: params.types,
|
|
2227
2281
|
notTypes: params.notTypes,
|
|
2228
2282
|
contractId: params.contractId,
|
|
2229
2283
|
sender: params.sender,
|
|
2230
2284
|
recipient: params.recipient,
|
|
2231
2285
|
assetIdentifier: params.assetIdentifier,
|
|
2286
|
+
rune: params.rune,
|
|
2287
|
+
address: params.address,
|
|
2232
2288
|
filters: params.filters
|
|
2233
2289
|
};
|
|
2234
2290
|
}
|
|
@@ -2340,9 +2396,15 @@ function createStreamsClient(options) {
|
|
|
2340
2396
|
}
|
|
2341
2397
|
return JSON.parse(text);
|
|
2342
2398
|
}
|
|
2343
|
-
const fetchEvents = listEvents;
|
|
2399
|
+
const fetchEvents = (params) => listEvents(params);
|
|
2400
|
+
function byTxId(txId, opts) {
|
|
2401
|
+
return request(`/v1/streams/events/${encodeURIComponent(txId)}${buildQuery({
|
|
2402
|
+
chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
|
|
2403
|
+
})}`);
|
|
2404
|
+
}
|
|
2344
2405
|
function listReorgs(params) {
|
|
2345
2406
|
return request(`/v1/streams/reorgs${buildQuery({
|
|
2407
|
+
chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
|
|
2346
2408
|
since: params.since,
|
|
2347
2409
|
limit: params.limit
|
|
2348
2410
|
})}`);
|
|
@@ -2352,6 +2414,19 @@ function createStreamsClient(options) {
|
|
|
2352
2414
|
return filters ? JSON.stringify(filters) : undefined;
|
|
2353
2415
|
}
|
|
2354
2416
|
async function listEvents(params = {}) {
|
|
2417
|
+
if (params.chain === "bitcoin") {
|
|
2418
|
+
return request(`/v1/streams/events${buildQuery({
|
|
2419
|
+
chain: "bitcoin",
|
|
2420
|
+
cursor: params.cursor,
|
|
2421
|
+
from_height: params.fromHeight,
|
|
2422
|
+
to_height: params.toHeight,
|
|
2423
|
+
limit: params.limit,
|
|
2424
|
+
types: params.types,
|
|
2425
|
+
not_types: params.notTypes,
|
|
2426
|
+
rune: params.rune,
|
|
2427
|
+
address: params.address
|
|
2428
|
+
})}`);
|
|
2429
|
+
}
|
|
2355
2430
|
return request(`/v1/streams/events${buildQuery({
|
|
2356
2431
|
cursor: params.cursor,
|
|
2357
2432
|
from_height: params.fromHeight,
|
|
@@ -2410,47 +2485,81 @@ function createStreamsClient(options) {
|
|
|
2410
2485
|
wake: params.wake
|
|
2411
2486
|
});
|
|
2412
2487
|
}
|
|
2488
|
+
function consumeBatches(params = {}) {
|
|
2489
|
+
return iterateStreamsBatches({
|
|
2490
|
+
fromCursor: params.cursor,
|
|
2491
|
+
batchSize: params.batchSize ?? 100,
|
|
2492
|
+
intervalMs: params.intervalMs ?? 2000,
|
|
2493
|
+
...streamsFilters(params),
|
|
2494
|
+
signal: params.signal,
|
|
2495
|
+
fetchEvents
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
function streamEvents(params = {}) {
|
|
2499
|
+
return streamStreamsEvents({
|
|
2500
|
+
fromCursor: params.fromCursor,
|
|
2501
|
+
...streamsFilters(params),
|
|
2502
|
+
batchSize: params.batchSize ?? 100,
|
|
2503
|
+
emptyBackoffMs: params.emptyBackoffMs,
|
|
2504
|
+
maxPages: params.maxPages,
|
|
2505
|
+
maxEmptyPolls: params.maxEmptyPolls,
|
|
2506
|
+
signal: params.signal,
|
|
2507
|
+
fetchEvents
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
function subscribeEvents(params) {
|
|
2511
|
+
return subscribeStreamsEvents({
|
|
2512
|
+
baseUrl,
|
|
2513
|
+
headers: authHeaders(),
|
|
2514
|
+
fetchImpl,
|
|
2515
|
+
verify: verifyMode,
|
|
2516
|
+
loadKey: loadKeyFor,
|
|
2517
|
+
reconnectDelayMs: params.reconnectDelayMs,
|
|
2518
|
+
staleAfterMs: params.staleAfterMs,
|
|
2519
|
+
params
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
function consumeBitcoinEvents(params) {
|
|
2523
|
+
return consumeStreamsEvents({
|
|
2524
|
+
fromCursor: params.fromCursor,
|
|
2525
|
+
sink: params.sink,
|
|
2526
|
+
onProgress: params.onProgress,
|
|
2527
|
+
mode: params.mode,
|
|
2528
|
+
finalizedOnly: params.finalizedOnly,
|
|
2529
|
+
chain: "bitcoin",
|
|
2530
|
+
types: params.types,
|
|
2531
|
+
notTypes: params.notTypes,
|
|
2532
|
+
rune: params.rune,
|
|
2533
|
+
address: params.address,
|
|
2534
|
+
batchSize: params.batchSize ?? 100,
|
|
2535
|
+
fetchEvents,
|
|
2536
|
+
fetchReorgs,
|
|
2537
|
+
onBatch: params.onBatch,
|
|
2538
|
+
onReorg: params.onReorg,
|
|
2539
|
+
maxRollbackDepth: params.maxRollbackDepth,
|
|
2540
|
+
emptyBackoffMs: params.emptyBackoffMs,
|
|
2541
|
+
maxPages: params.maxPages,
|
|
2542
|
+
maxEmptyPolls: params.maxEmptyPolls,
|
|
2543
|
+
signal: params.signal,
|
|
2544
|
+
retryCount: params.retryCount,
|
|
2545
|
+
retryDelay: params.retryDelay,
|
|
2546
|
+
onError: params.onError,
|
|
2547
|
+
wake: params.wake
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
function dispatchEventsConsume(params) {
|
|
2551
|
+
if (params.chain === "bitcoin")
|
|
2552
|
+
return consumeBitcoinEvents(params);
|
|
2553
|
+
return consumeEvents(params);
|
|
2554
|
+
}
|
|
2413
2555
|
return {
|
|
2414
|
-
consume
|
|
2415
|
-
return iterateStreamsBatches({
|
|
2416
|
-
fromCursor: params.cursor,
|
|
2417
|
-
batchSize: params.batchSize ?? 100,
|
|
2418
|
-
intervalMs: params.intervalMs ?? 2000,
|
|
2419
|
-
...streamsFilters(params),
|
|
2420
|
-
signal: params.signal,
|
|
2421
|
-
fetchEvents
|
|
2422
|
-
});
|
|
2423
|
-
},
|
|
2556
|
+
consume: consumeBatches,
|
|
2424
2557
|
events: {
|
|
2425
2558
|
list: listEvents,
|
|
2426
|
-
byTxId
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
stream(params = {}) {
|
|
2431
|
-
return streamStreamsEvents({
|
|
2432
|
-
fromCursor: params.fromCursor,
|
|
2433
|
-
...streamsFilters(params),
|
|
2434
|
-
batchSize: params.batchSize ?? 100,
|
|
2435
|
-
emptyBackoffMs: params.emptyBackoffMs,
|
|
2436
|
-
maxPages: params.maxPages,
|
|
2437
|
-
maxEmptyPolls: params.maxEmptyPolls,
|
|
2438
|
-
signal: params.signal,
|
|
2439
|
-
fetchEvents
|
|
2440
|
-
});
|
|
2441
|
-
},
|
|
2442
|
-
subscribe(params) {
|
|
2443
|
-
return subscribeStreamsEvents({
|
|
2444
|
-
baseUrl,
|
|
2445
|
-
headers: authHeaders(),
|
|
2446
|
-
fetchImpl,
|
|
2447
|
-
verify: verifyMode,
|
|
2448
|
-
loadKey: loadKeyFor,
|
|
2449
|
-
reconnectDelayMs: params.reconnectDelayMs,
|
|
2450
|
-
staleAfterMs: params.staleAfterMs,
|
|
2451
|
-
params
|
|
2452
|
-
});
|
|
2453
|
-
},
|
|
2559
|
+
byTxId,
|
|
2560
|
+
consume: dispatchEventsConsume,
|
|
2561
|
+
stream: streamEvents,
|
|
2562
|
+
subscribe: subscribeEvents,
|
|
2454
2563
|
async replay(params) {
|
|
2455
2564
|
const fromCursor = params.from === "genesis" ? null : params.from ?? null;
|
|
2456
2565
|
const fromBlock = fromCursor ? cursorTuple(fromCursor)[0] : 0;
|
|
@@ -2480,18 +2589,16 @@ function createStreamsClient(options) {
|
|
|
2480
2589
|
}
|
|
2481
2590
|
},
|
|
2482
2591
|
blocks: {
|
|
2483
|
-
events(heightOrHash) {
|
|
2484
|
-
return request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events`);
|
|
2485
|
-
}
|
|
2592
|
+
events: (heightOrHash, opts) => request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events${buildQuery({ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined })}`)
|
|
2486
2593
|
},
|
|
2487
2594
|
reorgs: { list: listReorgs },
|
|
2488
2595
|
dumps,
|
|
2489
|
-
canonical(height) {
|
|
2490
|
-
|
|
2491
|
-
},
|
|
2492
|
-
tip() {
|
|
2493
|
-
|
|
2494
|
-
}
|
|
2596
|
+
canonical: (height, opts) => request(`/v1/streams/canonical/${height}${buildQuery({
|
|
2597
|
+
chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
|
|
2598
|
+
})}`),
|
|
2599
|
+
tip: (opts) => request(`/v1/streams/tip${buildQuery({
|
|
2600
|
+
chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
|
|
2601
|
+
})}`)
|
|
2495
2602
|
};
|
|
2496
2603
|
}
|
|
2497
2604
|
|
|
@@ -2690,5 +2797,5 @@ export {
|
|
|
2690
2797
|
getSubgraph
|
|
2691
2798
|
};
|
|
2692
2799
|
|
|
2693
|
-
//# debugId=
|
|
2800
|
+
//# debugId=4FAC4F02875FC38A64756E2164756E21
|
|
2694
2801
|
//# sourceMappingURL=index.js.map
|