@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/streams/index.js
CHANGED
|
@@ -607,12 +607,15 @@ async function consumeStreamsEvents(opts) {
|
|
|
607
607
|
const envelope = await fetchPageWithRetry(() => opts.fetchEvents({
|
|
608
608
|
cursor,
|
|
609
609
|
limit: opts.batchSize,
|
|
610
|
+
chain: opts.chain,
|
|
610
611
|
types: opts.types,
|
|
611
612
|
notTypes: opts.notTypes,
|
|
612
613
|
contractId: opts.contractId,
|
|
613
614
|
sender: opts.sender,
|
|
614
615
|
recipient: opts.recipient,
|
|
615
616
|
assetIdentifier: opts.assetIdentifier,
|
|
617
|
+
rune: opts.rune,
|
|
618
|
+
address: opts.address,
|
|
616
619
|
filters: opts.filters
|
|
617
620
|
}), {
|
|
618
621
|
retryCount: opts.retryCount,
|
|
@@ -730,12 +733,15 @@ async function* iterateStreamsBatches(opts) {
|
|
|
730
733
|
const envelope = await opts.fetchEvents({
|
|
731
734
|
cursor,
|
|
732
735
|
limit: opts.batchSize,
|
|
736
|
+
chain: opts.chain,
|
|
733
737
|
types: opts.types,
|
|
734
738
|
notTypes: opts.notTypes,
|
|
735
739
|
contractId: opts.contractId,
|
|
736
740
|
sender: opts.sender,
|
|
737
741
|
recipient: opts.recipient,
|
|
738
742
|
assetIdentifier: opts.assetIdentifier,
|
|
743
|
+
rune: opts.rune,
|
|
744
|
+
address: opts.address,
|
|
739
745
|
filters: opts.filters
|
|
740
746
|
});
|
|
741
747
|
const checkpoint = envelope.next_cursor ?? cursor;
|
|
@@ -768,12 +774,15 @@ async function* streamStreamsEvents(opts) {
|
|
|
768
774
|
const envelope = await opts.fetchEvents({
|
|
769
775
|
cursor,
|
|
770
776
|
limit: opts.batchSize,
|
|
777
|
+
chain: opts.chain,
|
|
771
778
|
types: opts.types,
|
|
772
779
|
notTypes: opts.notTypes,
|
|
773
780
|
contractId: opts.contractId,
|
|
774
781
|
sender: opts.sender,
|
|
775
782
|
recipient: opts.recipient,
|
|
776
783
|
assetIdentifier: opts.assetIdentifier,
|
|
784
|
+
rune: opts.rune,
|
|
785
|
+
address: opts.address,
|
|
777
786
|
filters: opts.filters
|
|
778
787
|
});
|
|
779
788
|
pages++;
|
|
@@ -1033,6 +1042,7 @@ function subscribeStreamsEvents(opts) {
|
|
|
1033
1042
|
while (!controller.signal.aborted) {
|
|
1034
1043
|
try {
|
|
1035
1044
|
const url = `${opts.baseUrl}/v1/streams/events/stream${buildQuery({
|
|
1045
|
+
chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
|
|
1036
1046
|
from_cursor: cursor ?? undefined,
|
|
1037
1047
|
types: params.types,
|
|
1038
1048
|
not_types: params.notTypes,
|
|
@@ -1040,6 +1050,8 @@ function subscribeStreamsEvents(opts) {
|
|
|
1040
1050
|
sender: params.sender,
|
|
1041
1051
|
recipient: params.recipient,
|
|
1042
1052
|
asset_identifier: params.assetIdentifier,
|
|
1053
|
+
rune: params.rune,
|
|
1054
|
+
address: params.address,
|
|
1043
1055
|
filters: params.filters ? JSON.stringify(params.filters) : undefined
|
|
1044
1056
|
})}`;
|
|
1045
1057
|
await readSse({
|
|
@@ -1198,12 +1210,15 @@ function maxCursor(a, b) {
|
|
|
1198
1210
|
}
|
|
1199
1211
|
function streamsFilters(params) {
|
|
1200
1212
|
return {
|
|
1213
|
+
chain: params.chain,
|
|
1201
1214
|
types: params.types,
|
|
1202
1215
|
notTypes: params.notTypes,
|
|
1203
1216
|
contractId: params.contractId,
|
|
1204
1217
|
sender: params.sender,
|
|
1205
1218
|
recipient: params.recipient,
|
|
1206
1219
|
assetIdentifier: params.assetIdentifier,
|
|
1220
|
+
rune: params.rune,
|
|
1221
|
+
address: params.address,
|
|
1207
1222
|
filters: params.filters
|
|
1208
1223
|
};
|
|
1209
1224
|
}
|
|
@@ -1315,9 +1330,15 @@ function createStreamsClient(options) {
|
|
|
1315
1330
|
}
|
|
1316
1331
|
return JSON.parse(text);
|
|
1317
1332
|
}
|
|
1318
|
-
const fetchEvents = listEvents;
|
|
1333
|
+
const fetchEvents = (params) => listEvents(params);
|
|
1334
|
+
function byTxId(txId, opts) {
|
|
1335
|
+
return request(`/v1/streams/events/${encodeURIComponent(txId)}${buildQuery({
|
|
1336
|
+
chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
|
|
1337
|
+
})}`);
|
|
1338
|
+
}
|
|
1319
1339
|
function listReorgs(params) {
|
|
1320
1340
|
return request(`/v1/streams/reorgs${buildQuery({
|
|
1341
|
+
chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
|
|
1321
1342
|
since: params.since,
|
|
1322
1343
|
limit: params.limit
|
|
1323
1344
|
})}`);
|
|
@@ -1327,6 +1348,19 @@ function createStreamsClient(options) {
|
|
|
1327
1348
|
return filters ? JSON.stringify(filters) : undefined;
|
|
1328
1349
|
}
|
|
1329
1350
|
async function listEvents(params = {}) {
|
|
1351
|
+
if (params.chain === "bitcoin") {
|
|
1352
|
+
return request(`/v1/streams/events${buildQuery({
|
|
1353
|
+
chain: "bitcoin",
|
|
1354
|
+
cursor: params.cursor,
|
|
1355
|
+
from_height: params.fromHeight,
|
|
1356
|
+
to_height: params.toHeight,
|
|
1357
|
+
limit: params.limit,
|
|
1358
|
+
types: params.types,
|
|
1359
|
+
not_types: params.notTypes,
|
|
1360
|
+
rune: params.rune,
|
|
1361
|
+
address: params.address
|
|
1362
|
+
})}`);
|
|
1363
|
+
}
|
|
1330
1364
|
return request(`/v1/streams/events${buildQuery({
|
|
1331
1365
|
cursor: params.cursor,
|
|
1332
1366
|
from_height: params.fromHeight,
|
|
@@ -1385,47 +1419,81 @@ function createStreamsClient(options) {
|
|
|
1385
1419
|
wake: params.wake
|
|
1386
1420
|
});
|
|
1387
1421
|
}
|
|
1422
|
+
function consumeBatches(params = {}) {
|
|
1423
|
+
return iterateStreamsBatches({
|
|
1424
|
+
fromCursor: params.cursor,
|
|
1425
|
+
batchSize: params.batchSize ?? 100,
|
|
1426
|
+
intervalMs: params.intervalMs ?? 2000,
|
|
1427
|
+
...streamsFilters(params),
|
|
1428
|
+
signal: params.signal,
|
|
1429
|
+
fetchEvents
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
function streamEvents(params = {}) {
|
|
1433
|
+
return streamStreamsEvents({
|
|
1434
|
+
fromCursor: params.fromCursor,
|
|
1435
|
+
...streamsFilters(params),
|
|
1436
|
+
batchSize: params.batchSize ?? 100,
|
|
1437
|
+
emptyBackoffMs: params.emptyBackoffMs,
|
|
1438
|
+
maxPages: params.maxPages,
|
|
1439
|
+
maxEmptyPolls: params.maxEmptyPolls,
|
|
1440
|
+
signal: params.signal,
|
|
1441
|
+
fetchEvents
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
function subscribeEvents(params) {
|
|
1445
|
+
return subscribeStreamsEvents({
|
|
1446
|
+
baseUrl,
|
|
1447
|
+
headers: authHeaders(),
|
|
1448
|
+
fetchImpl,
|
|
1449
|
+
verify: verifyMode,
|
|
1450
|
+
loadKey: loadKeyFor,
|
|
1451
|
+
reconnectDelayMs: params.reconnectDelayMs,
|
|
1452
|
+
staleAfterMs: params.staleAfterMs,
|
|
1453
|
+
params
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
function consumeBitcoinEvents(params) {
|
|
1457
|
+
return consumeStreamsEvents({
|
|
1458
|
+
fromCursor: params.fromCursor,
|
|
1459
|
+
sink: params.sink,
|
|
1460
|
+
onProgress: params.onProgress,
|
|
1461
|
+
mode: params.mode,
|
|
1462
|
+
finalizedOnly: params.finalizedOnly,
|
|
1463
|
+
chain: "bitcoin",
|
|
1464
|
+
types: params.types,
|
|
1465
|
+
notTypes: params.notTypes,
|
|
1466
|
+
rune: params.rune,
|
|
1467
|
+
address: params.address,
|
|
1468
|
+
batchSize: params.batchSize ?? 100,
|
|
1469
|
+
fetchEvents,
|
|
1470
|
+
fetchReorgs,
|
|
1471
|
+
onBatch: params.onBatch,
|
|
1472
|
+
onReorg: params.onReorg,
|
|
1473
|
+
maxRollbackDepth: params.maxRollbackDepth,
|
|
1474
|
+
emptyBackoffMs: params.emptyBackoffMs,
|
|
1475
|
+
maxPages: params.maxPages,
|
|
1476
|
+
maxEmptyPolls: params.maxEmptyPolls,
|
|
1477
|
+
signal: params.signal,
|
|
1478
|
+
retryCount: params.retryCount,
|
|
1479
|
+
retryDelay: params.retryDelay,
|
|
1480
|
+
onError: params.onError,
|
|
1481
|
+
wake: params.wake
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
function dispatchEventsConsume(params) {
|
|
1485
|
+
if (params.chain === "bitcoin")
|
|
1486
|
+
return consumeBitcoinEvents(params);
|
|
1487
|
+
return consumeEvents(params);
|
|
1488
|
+
}
|
|
1388
1489
|
return {
|
|
1389
|
-
consume
|
|
1390
|
-
return iterateStreamsBatches({
|
|
1391
|
-
fromCursor: params.cursor,
|
|
1392
|
-
batchSize: params.batchSize ?? 100,
|
|
1393
|
-
intervalMs: params.intervalMs ?? 2000,
|
|
1394
|
-
...streamsFilters(params),
|
|
1395
|
-
signal: params.signal,
|
|
1396
|
-
fetchEvents
|
|
1397
|
-
});
|
|
1398
|
-
},
|
|
1490
|
+
consume: consumeBatches,
|
|
1399
1491
|
events: {
|
|
1400
1492
|
list: listEvents,
|
|
1401
|
-
byTxId
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
stream(params = {}) {
|
|
1406
|
-
return streamStreamsEvents({
|
|
1407
|
-
fromCursor: params.fromCursor,
|
|
1408
|
-
...streamsFilters(params),
|
|
1409
|
-
batchSize: params.batchSize ?? 100,
|
|
1410
|
-
emptyBackoffMs: params.emptyBackoffMs,
|
|
1411
|
-
maxPages: params.maxPages,
|
|
1412
|
-
maxEmptyPolls: params.maxEmptyPolls,
|
|
1413
|
-
signal: params.signal,
|
|
1414
|
-
fetchEvents
|
|
1415
|
-
});
|
|
1416
|
-
},
|
|
1417
|
-
subscribe(params) {
|
|
1418
|
-
return subscribeStreamsEvents({
|
|
1419
|
-
baseUrl,
|
|
1420
|
-
headers: authHeaders(),
|
|
1421
|
-
fetchImpl,
|
|
1422
|
-
verify: verifyMode,
|
|
1423
|
-
loadKey: loadKeyFor,
|
|
1424
|
-
reconnectDelayMs: params.reconnectDelayMs,
|
|
1425
|
-
staleAfterMs: params.staleAfterMs,
|
|
1426
|
-
params
|
|
1427
|
-
});
|
|
1428
|
-
},
|
|
1493
|
+
byTxId,
|
|
1494
|
+
consume: dispatchEventsConsume,
|
|
1495
|
+
stream: streamEvents,
|
|
1496
|
+
subscribe: subscribeEvents,
|
|
1429
1497
|
async replay(params) {
|
|
1430
1498
|
const fromCursor = params.from === "genesis" ? null : params.from ?? null;
|
|
1431
1499
|
const fromBlock = fromCursor ? cursorTuple(fromCursor)[0] : 0;
|
|
@@ -1455,18 +1523,16 @@ function createStreamsClient(options) {
|
|
|
1455
1523
|
}
|
|
1456
1524
|
},
|
|
1457
1525
|
blocks: {
|
|
1458
|
-
events(heightOrHash) {
|
|
1459
|
-
return request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events`);
|
|
1460
|
-
}
|
|
1526
|
+
events: (heightOrHash, opts) => request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events${buildQuery({ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined })}`)
|
|
1461
1527
|
},
|
|
1462
1528
|
reorgs: { list: listReorgs },
|
|
1463
1529
|
dumps,
|
|
1464
|
-
canonical(height) {
|
|
1465
|
-
|
|
1466
|
-
},
|
|
1467
|
-
tip() {
|
|
1468
|
-
|
|
1469
|
-
}
|
|
1530
|
+
canonical: (height, opts) => request(`/v1/streams/canonical/${height}${buildQuery({
|
|
1531
|
+
chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
|
|
1532
|
+
})}`),
|
|
1533
|
+
tip: (opts) => request(`/v1/streams/tip${buildQuery({
|
|
1534
|
+
chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
|
|
1535
|
+
})}`)
|
|
1470
1536
|
};
|
|
1471
1537
|
}
|
|
1472
1538
|
|
|
@@ -1498,6 +1564,7 @@ import {
|
|
|
1498
1564
|
|
|
1499
1565
|
// src/streams/types.ts
|
|
1500
1566
|
import {
|
|
1567
|
+
RUNE_EVENT_TYPES,
|
|
1501
1568
|
STREAMS_EVENT_TYPES
|
|
1502
1569
|
} from "@secondlayer/shared/streams-rows";
|
|
1503
1570
|
export {
|
|
@@ -1534,5 +1601,5 @@ export {
|
|
|
1534
1601
|
isStxTransfer
|
|
1535
1602
|
};
|
|
1536
1603
|
|
|
1537
|
-
//# debugId=
|
|
1604
|
+
//# debugId=80C188DCCCC86F1064756E2164756E21
|
|
1538
1605
|
//# sourceMappingURL=index.js.map
|