@secondlayer/sdk 13.1.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.
package/dist/index.js CHANGED
@@ -864,12 +864,15 @@ async function consumeStreamsEvents(opts) {
864
864
  const envelope = await fetchPageWithRetry(() => opts.fetchEvents({
865
865
  cursor,
866
866
  limit: opts.batchSize,
867
+ chain: opts.chain,
867
868
  types: opts.types,
868
869
  notTypes: opts.notTypes,
869
870
  contractId: opts.contractId,
870
871
  sender: opts.sender,
871
872
  recipient: opts.recipient,
872
873
  assetIdentifier: opts.assetIdentifier,
874
+ rune: opts.rune,
875
+ address: opts.address,
873
876
  filters: opts.filters
874
877
  }), {
875
878
  retryCount: opts.retryCount,
@@ -987,12 +990,15 @@ async function* iterateStreamsBatches(opts) {
987
990
  const envelope = await opts.fetchEvents({
988
991
  cursor,
989
992
  limit: opts.batchSize,
993
+ chain: opts.chain,
990
994
  types: opts.types,
991
995
  notTypes: opts.notTypes,
992
996
  contractId: opts.contractId,
993
997
  sender: opts.sender,
994
998
  recipient: opts.recipient,
995
999
  assetIdentifier: opts.assetIdentifier,
1000
+ rune: opts.rune,
1001
+ address: opts.address,
996
1002
  filters: opts.filters
997
1003
  });
998
1004
  const checkpoint = envelope.next_cursor ?? cursor;
@@ -1025,12 +1031,15 @@ async function* streamStreamsEvents(opts) {
1025
1031
  const envelope = await opts.fetchEvents({
1026
1032
  cursor,
1027
1033
  limit: opts.batchSize,
1034
+ chain: opts.chain,
1028
1035
  types: opts.types,
1029
1036
  notTypes: opts.notTypes,
1030
1037
  contractId: opts.contractId,
1031
1038
  sender: opts.sender,
1032
1039
  recipient: opts.recipient,
1033
1040
  assetIdentifier: opts.assetIdentifier,
1041
+ rune: opts.rune,
1042
+ address: opts.address,
1034
1043
  filters: opts.filters
1035
1044
  });
1036
1045
  pages++;
@@ -1312,6 +1321,15 @@ class Index extends BaseClient {
1312
1321
  })
1313
1322
  }
1314
1323
  };
1324
+ runes = {
1325
+ list: (params = {}) => this.listRunes(params),
1326
+ get: (rune) => this.getRune(rune),
1327
+ balances: (params) => this.listRuneBalances(params),
1328
+ activity: {
1329
+ list: (params = {}) => this.listRuneActivity(params),
1330
+ walk: (params = {}) => this.walkRuneActivity(params)
1331
+ }
1332
+ };
1315
1333
  async listFtTransfers(params = {}) {
1316
1334
  return this.request("GET", `/v1/index/ft-transfers${buildQuery({
1317
1335
  ...indexPageQuery(params),
@@ -1544,6 +1562,38 @@ class Index extends BaseClient {
1544
1562
  async getPoxCycle(rewardCycle) {
1545
1563
  return this.requestOrNull("GET", `/v1/index/pox/cycles/${rewardCycle}`);
1546
1564
  }
1565
+ async listRunes(params = {}) {
1566
+ return this.request("GET", `/v1/index/runes${buildQuery({
1567
+ search: params.search,
1568
+ sort: params.sort,
1569
+ cursor: params.cursor,
1570
+ limit: params.limit
1571
+ })}`, undefined, { signal: params.signal });
1572
+ }
1573
+ async getRune(rune) {
1574
+ return this.requestOrNull("GET", `/v1/index/runes/${encodeURIComponent(rune)}`);
1575
+ }
1576
+ async listRuneActivity(params = {}) {
1577
+ return this.request("GET", `/v1/index/runes/activity${buildQuery({
1578
+ ...indexPageQuery(params),
1579
+ rune: params.rune,
1580
+ address: params.address,
1581
+ kind: params.kind,
1582
+ txid: params.txid
1583
+ })}`, undefined, { signal: params.signal });
1584
+ }
1585
+ walkRuneActivity(params = {}) {
1586
+ return this.keysetWalk(params, (page) => this.listRuneActivity({ ...params, ...page }), (e) => e.events);
1587
+ }
1588
+ async listRuneBalances(params) {
1589
+ return this.request("GET", `/v1/index/runes/balances${buildQuery({
1590
+ address: params.address,
1591
+ outpoint: params.outpoint,
1592
+ rune: params.rune,
1593
+ cursor: params.cursor,
1594
+ limit: params.limit
1595
+ })}`, undefined, { signal: params.signal });
1596
+ }
1547
1597
  }
1548
1598
 
1549
1599
  // src/streams/client.ts
@@ -1783,6 +1833,7 @@ function subscribeStreamsEvents(opts) {
1783
1833
  while (!controller.signal.aborted) {
1784
1834
  try {
1785
1835
  const url = `${opts.baseUrl}/v1/streams/events/stream${buildQuery({
1836
+ chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
1786
1837
  from_cursor: cursor ?? undefined,
1787
1838
  types: params.types,
1788
1839
  not_types: params.notTypes,
@@ -1790,6 +1841,8 @@ function subscribeStreamsEvents(opts) {
1790
1841
  sender: params.sender,
1791
1842
  recipient: params.recipient,
1792
1843
  asset_identifier: params.assetIdentifier,
1844
+ rune: params.rune,
1845
+ address: params.address,
1793
1846
  filters: params.filters ? JSON.stringify(params.filters) : undefined
1794
1847
  })}`;
1795
1848
  await readSse({
@@ -1948,12 +2001,15 @@ function maxCursor(a, b) {
1948
2001
  }
1949
2002
  function streamsFilters(params) {
1950
2003
  return {
2004
+ chain: params.chain,
1951
2005
  types: params.types,
1952
2006
  notTypes: params.notTypes,
1953
2007
  contractId: params.contractId,
1954
2008
  sender: params.sender,
1955
2009
  recipient: params.recipient,
1956
2010
  assetIdentifier: params.assetIdentifier,
2011
+ rune: params.rune,
2012
+ address: params.address,
1957
2013
  filters: params.filters
1958
2014
  };
1959
2015
  }
@@ -2065,9 +2121,15 @@ function createStreamsClient(options) {
2065
2121
  }
2066
2122
  return JSON.parse(text);
2067
2123
  }
2068
- const fetchEvents = listEvents;
2124
+ const fetchEvents = (params) => listEvents(params);
2125
+ function byTxId(txId, opts) {
2126
+ return request(`/v1/streams/events/${encodeURIComponent(txId)}${buildQuery({
2127
+ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
2128
+ })}`);
2129
+ }
2069
2130
  function listReorgs(params) {
2070
2131
  return request(`/v1/streams/reorgs${buildQuery({
2132
+ chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
2071
2133
  since: params.since,
2072
2134
  limit: params.limit
2073
2135
  })}`);
@@ -2077,6 +2139,19 @@ function createStreamsClient(options) {
2077
2139
  return filters ? JSON.stringify(filters) : undefined;
2078
2140
  }
2079
2141
  async function listEvents(params = {}) {
2142
+ if (params.chain === "bitcoin") {
2143
+ return request(`/v1/streams/events${buildQuery({
2144
+ chain: "bitcoin",
2145
+ cursor: params.cursor,
2146
+ from_height: params.fromHeight,
2147
+ to_height: params.toHeight,
2148
+ limit: params.limit,
2149
+ types: params.types,
2150
+ not_types: params.notTypes,
2151
+ rune: params.rune,
2152
+ address: params.address
2153
+ })}`);
2154
+ }
2080
2155
  return request(`/v1/streams/events${buildQuery({
2081
2156
  cursor: params.cursor,
2082
2157
  from_height: params.fromHeight,
@@ -2135,47 +2210,81 @@ function createStreamsClient(options) {
2135
2210
  wake: params.wake
2136
2211
  });
2137
2212
  }
2213
+ function consumeBatches(params = {}) {
2214
+ return iterateStreamsBatches({
2215
+ fromCursor: params.cursor,
2216
+ batchSize: params.batchSize ?? 100,
2217
+ intervalMs: params.intervalMs ?? 2000,
2218
+ ...streamsFilters(params),
2219
+ signal: params.signal,
2220
+ fetchEvents
2221
+ });
2222
+ }
2223
+ function streamEvents(params = {}) {
2224
+ return streamStreamsEvents({
2225
+ fromCursor: params.fromCursor,
2226
+ ...streamsFilters(params),
2227
+ batchSize: params.batchSize ?? 100,
2228
+ emptyBackoffMs: params.emptyBackoffMs,
2229
+ maxPages: params.maxPages,
2230
+ maxEmptyPolls: params.maxEmptyPolls,
2231
+ signal: params.signal,
2232
+ fetchEvents
2233
+ });
2234
+ }
2235
+ function subscribeEvents(params) {
2236
+ return subscribeStreamsEvents({
2237
+ baseUrl,
2238
+ headers: authHeaders(),
2239
+ fetchImpl,
2240
+ verify: verifyMode,
2241
+ loadKey: loadKeyFor,
2242
+ reconnectDelayMs: params.reconnectDelayMs,
2243
+ staleAfterMs: params.staleAfterMs,
2244
+ params
2245
+ });
2246
+ }
2247
+ function consumeBitcoinEvents(params) {
2248
+ return consumeStreamsEvents({
2249
+ fromCursor: params.fromCursor,
2250
+ sink: params.sink,
2251
+ onProgress: params.onProgress,
2252
+ mode: params.mode,
2253
+ finalizedOnly: params.finalizedOnly,
2254
+ chain: "bitcoin",
2255
+ types: params.types,
2256
+ notTypes: params.notTypes,
2257
+ rune: params.rune,
2258
+ address: params.address,
2259
+ batchSize: params.batchSize ?? 100,
2260
+ fetchEvents,
2261
+ fetchReorgs,
2262
+ onBatch: params.onBatch,
2263
+ onReorg: params.onReorg,
2264
+ maxRollbackDepth: params.maxRollbackDepth,
2265
+ emptyBackoffMs: params.emptyBackoffMs,
2266
+ maxPages: params.maxPages,
2267
+ maxEmptyPolls: params.maxEmptyPolls,
2268
+ signal: params.signal,
2269
+ retryCount: params.retryCount,
2270
+ retryDelay: params.retryDelay,
2271
+ onError: params.onError,
2272
+ wake: params.wake
2273
+ });
2274
+ }
2275
+ function dispatchEventsConsume(params) {
2276
+ if (params.chain === "bitcoin")
2277
+ return consumeBitcoinEvents(params);
2278
+ return consumeEvents(params);
2279
+ }
2138
2280
  return {
2139
- consume(params = {}) {
2140
- return iterateStreamsBatches({
2141
- fromCursor: params.cursor,
2142
- batchSize: params.batchSize ?? 100,
2143
- intervalMs: params.intervalMs ?? 2000,
2144
- ...streamsFilters(params),
2145
- signal: params.signal,
2146
- fetchEvents
2147
- });
2148
- },
2281
+ consume: consumeBatches,
2149
2282
  events: {
2150
2283
  list: listEvents,
2151
- byTxId(txId) {
2152
- return request(`/v1/streams/events/${encodeURIComponent(txId)}`);
2153
- },
2154
- consume: consumeEvents,
2155
- stream(params = {}) {
2156
- return streamStreamsEvents({
2157
- fromCursor: params.fromCursor,
2158
- ...streamsFilters(params),
2159
- batchSize: params.batchSize ?? 100,
2160
- emptyBackoffMs: params.emptyBackoffMs,
2161
- maxPages: params.maxPages,
2162
- maxEmptyPolls: params.maxEmptyPolls,
2163
- signal: params.signal,
2164
- fetchEvents
2165
- });
2166
- },
2167
- subscribe(params) {
2168
- return subscribeStreamsEvents({
2169
- baseUrl,
2170
- headers: authHeaders(),
2171
- fetchImpl,
2172
- verify: verifyMode,
2173
- loadKey: loadKeyFor,
2174
- reconnectDelayMs: params.reconnectDelayMs,
2175
- staleAfterMs: params.staleAfterMs,
2176
- params
2177
- });
2178
- },
2284
+ byTxId,
2285
+ consume: dispatchEventsConsume,
2286
+ stream: streamEvents,
2287
+ subscribe: subscribeEvents,
2179
2288
  async replay(params) {
2180
2289
  const fromCursor = params.from === "genesis" ? null : params.from ?? null;
2181
2290
  const fromBlock = fromCursor ? cursorTuple(fromCursor)[0] : 0;
@@ -2205,18 +2314,16 @@ function createStreamsClient(options) {
2205
2314
  }
2206
2315
  },
2207
2316
  blocks: {
2208
- events(heightOrHash) {
2209
- return request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events`);
2210
- }
2317
+ events: (heightOrHash, opts) => request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events${buildQuery({ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined })}`)
2211
2318
  },
2212
2319
  reorgs: { list: listReorgs },
2213
2320
  dumps,
2214
- canonical(height) {
2215
- return request(`/v1/streams/canonical/${height}`);
2216
- },
2217
- tip() {
2218
- return request("/v1/streams/tip");
2219
- }
2321
+ canonical: (height, opts) => request(`/v1/streams/canonical/${height}${buildQuery({
2322
+ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
2323
+ })}`),
2324
+ tip: (opts) => request(`/v1/streams/tip${buildQuery({
2325
+ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined
2326
+ })}`)
2220
2327
  };
2221
2328
  }
2222
2329
 
@@ -3249,6 +3356,7 @@ import {
3249
3356
 
3250
3357
  // src/streams/types.ts
3251
3358
  import {
3359
+ RUNE_EVENT_TYPES,
3252
3360
  STREAMS_EVENT_TYPES
3253
3361
  } from "@secondlayer/shared/streams-rows";
3254
3362
  // src/clarity.ts
@@ -3329,5 +3437,5 @@ export {
3329
3437
  verifyWebhookSignature
3330
3438
  };
3331
3439
 
3332
- //# debugId=1F94BF09D6F6250664756E2164756E21
3440
+ //# debugId=39B36DCFC98F548264756E2164756E21
3333
3441
  //# sourceMappingURL=index.js.map