@secondlayer/sdk 13.0.0 → 13.2.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.
@@ -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++;
@@ -1759,7 +1771,27 @@ class Index extends BaseClient {
1759
1771
  pox5 = {
1760
1772
  events: {
1761
1773
  list: (params = {}) => this.listPox5Events(params),
1762
- walk: (params = {}) => this.walkPox5Events(params)
1774
+ walk: (params = {}) => this.walkPox5Events(params),
1775
+ consume: (params) => consumeIndexFeed({
1776
+ ...params,
1777
+ fetchPage: ({ cursor, fromHeight, limit }) => this.listPox5Events({
1778
+ ...feedFilters(params),
1779
+ cursor,
1780
+ fromHeight,
1781
+ limit,
1782
+ signal: params.signal
1783
+ }),
1784
+ itemsOf: (envelope) => envelope.events
1785
+ })
1786
+ }
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)
1763
1795
  }
1764
1796
  };
1765
1797
  async listFtTransfers(params = {}) {
@@ -1994,6 +2026,38 @@ class Index extends BaseClient {
1994
2026
  async getPoxCycle(rewardCycle) {
1995
2027
  return this.requestOrNull("GET", `/v1/index/pox/cycles/${rewardCycle}`);
1996
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
+ }
1997
2061
  }
1998
2062
 
1999
2063
  // src/streams/client.ts
@@ -2212,12 +2276,15 @@ function maxCursor(a, b) {
2212
2276
  }
2213
2277
  function streamsFilters(params) {
2214
2278
  return {
2279
+ chain: params.chain,
2215
2280
  types: params.types,
2216
2281
  notTypes: params.notTypes,
2217
2282
  contractId: params.contractId,
2218
2283
  sender: params.sender,
2219
2284
  recipient: params.recipient,
2220
2285
  assetIdentifier: params.assetIdentifier,
2286
+ rune: params.rune,
2287
+ address: params.address,
2221
2288
  filters: params.filters
2222
2289
  };
2223
2290
  }
@@ -2329,9 +2396,15 @@ function createStreamsClient(options) {
2329
2396
  }
2330
2397
  return JSON.parse(text);
2331
2398
  }
2332
- 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
+ }
2333
2405
  function listReorgs(params) {
2334
2406
  return request(`/v1/streams/reorgs${buildQuery({
2407
+ chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
2335
2408
  since: params.since,
2336
2409
  limit: params.limit
2337
2410
  })}`);
@@ -2341,6 +2414,19 @@ function createStreamsClient(options) {
2341
2414
  return filters ? JSON.stringify(filters) : undefined;
2342
2415
  }
2343
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
+ }
2344
2430
  return request(`/v1/streams/events${buildQuery({
2345
2431
  cursor: params.cursor,
2346
2432
  from_height: params.fromHeight,
@@ -2399,47 +2485,81 @@ function createStreamsClient(options) {
2399
2485
  wake: params.wake
2400
2486
  });
2401
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
+ }
2402
2555
  return {
2403
- consume(params = {}) {
2404
- return iterateStreamsBatches({
2405
- fromCursor: params.cursor,
2406
- batchSize: params.batchSize ?? 100,
2407
- intervalMs: params.intervalMs ?? 2000,
2408
- ...streamsFilters(params),
2409
- signal: params.signal,
2410
- fetchEvents
2411
- });
2412
- },
2556
+ consume: consumeBatches,
2413
2557
  events: {
2414
2558
  list: listEvents,
2415
- byTxId(txId) {
2416
- return request(`/v1/streams/events/${encodeURIComponent(txId)}`);
2417
- },
2418
- consume: consumeEvents,
2419
- stream(params = {}) {
2420
- return streamStreamsEvents({
2421
- fromCursor: params.fromCursor,
2422
- ...streamsFilters(params),
2423
- batchSize: params.batchSize ?? 100,
2424
- emptyBackoffMs: params.emptyBackoffMs,
2425
- maxPages: params.maxPages,
2426
- maxEmptyPolls: params.maxEmptyPolls,
2427
- signal: params.signal,
2428
- fetchEvents
2429
- });
2430
- },
2431
- subscribe(params) {
2432
- return subscribeStreamsEvents({
2433
- baseUrl,
2434
- headers: authHeaders(),
2435
- fetchImpl,
2436
- verify: verifyMode,
2437
- loadKey: loadKeyFor,
2438
- reconnectDelayMs: params.reconnectDelayMs,
2439
- staleAfterMs: params.staleAfterMs,
2440
- params
2441
- });
2442
- },
2559
+ byTxId,
2560
+ consume: dispatchEventsConsume,
2561
+ stream: streamEvents,
2562
+ subscribe: subscribeEvents,
2443
2563
  async replay(params) {
2444
2564
  const fromCursor = params.from === "genesis" ? null : params.from ?? null;
2445
2565
  const fromBlock = fromCursor ? cursorTuple(fromCursor)[0] : 0;
@@ -2469,18 +2589,16 @@ function createStreamsClient(options) {
2469
2589
  }
2470
2590
  },
2471
2591
  blocks: {
2472
- events(heightOrHash) {
2473
- return request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events`);
2474
- }
2592
+ events: (heightOrHash, opts) => request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events${buildQuery({ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined })}`)
2475
2593
  },
2476
2594
  reorgs: { list: listReorgs },
2477
2595
  dumps,
2478
- canonical(height) {
2479
- return request(`/v1/streams/canonical/${height}`);
2480
- },
2481
- tip() {
2482
- return request("/v1/streams/tip");
2483
- }
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
+ })}`)
2484
2602
  };
2485
2603
  }
2486
2604
 
@@ -2679,5 +2797,5 @@ export {
2679
2797
  getSubgraph
2680
2798
  };
2681
2799
 
2682
- //# debugId=022E11732B2A24D564756E2164756E21
2800
+ //# debugId=4FAC4F02875FC38A64756E2164756E21
2683
2801
  //# sourceMappingURL=index.js.map