@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.
- package/README.md +21 -0
- package/dist/index.d.ts +418 -44
- package/dist/index.js +169 -50
- 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 +414 -41
- package/dist/subgraphs/index.js +168 -50
- package/dist/subgraphs/index.js.map +6 -6
- package/package.json +3 -3
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++;
|
|
@@ -1298,7 +1307,27 @@ class Index extends BaseClient {
|
|
|
1298
1307
|
pox5 = {
|
|
1299
1308
|
events: {
|
|
1300
1309
|
list: (params = {}) => this.listPox5Events(params),
|
|
1301
|
-
walk: (params = {}) => this.walkPox5Events(params)
|
|
1310
|
+
walk: (params = {}) => this.walkPox5Events(params),
|
|
1311
|
+
consume: (params) => consumeIndexFeed({
|
|
1312
|
+
...params,
|
|
1313
|
+
fetchPage: ({ cursor, fromHeight, limit }) => this.listPox5Events({
|
|
1314
|
+
...feedFilters(params),
|
|
1315
|
+
cursor,
|
|
1316
|
+
fromHeight,
|
|
1317
|
+
limit,
|
|
1318
|
+
signal: params.signal
|
|
1319
|
+
}),
|
|
1320
|
+
itemsOf: (envelope) => envelope.events
|
|
1321
|
+
})
|
|
1322
|
+
}
|
|
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)
|
|
1302
1331
|
}
|
|
1303
1332
|
};
|
|
1304
1333
|
async listFtTransfers(params = {}) {
|
|
@@ -1533,6 +1562,38 @@ class Index extends BaseClient {
|
|
|
1533
1562
|
async getPoxCycle(rewardCycle) {
|
|
1534
1563
|
return this.requestOrNull("GET", `/v1/index/pox/cycles/${rewardCycle}`);
|
|
1535
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
|
+
}
|
|
1536
1597
|
}
|
|
1537
1598
|
|
|
1538
1599
|
// src/streams/client.ts
|
|
@@ -1772,6 +1833,7 @@ function subscribeStreamsEvents(opts) {
|
|
|
1772
1833
|
while (!controller.signal.aborted) {
|
|
1773
1834
|
try {
|
|
1774
1835
|
const url = `${opts.baseUrl}/v1/streams/events/stream${buildQuery({
|
|
1836
|
+
chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
|
|
1775
1837
|
from_cursor: cursor ?? undefined,
|
|
1776
1838
|
types: params.types,
|
|
1777
1839
|
not_types: params.notTypes,
|
|
@@ -1779,6 +1841,8 @@ function subscribeStreamsEvents(opts) {
|
|
|
1779
1841
|
sender: params.sender,
|
|
1780
1842
|
recipient: params.recipient,
|
|
1781
1843
|
asset_identifier: params.assetIdentifier,
|
|
1844
|
+
rune: params.rune,
|
|
1845
|
+
address: params.address,
|
|
1782
1846
|
filters: params.filters ? JSON.stringify(params.filters) : undefined
|
|
1783
1847
|
})}`;
|
|
1784
1848
|
await readSse({
|
|
@@ -1937,12 +2001,15 @@ function maxCursor(a, b) {
|
|
|
1937
2001
|
}
|
|
1938
2002
|
function streamsFilters(params) {
|
|
1939
2003
|
return {
|
|
2004
|
+
chain: params.chain,
|
|
1940
2005
|
types: params.types,
|
|
1941
2006
|
notTypes: params.notTypes,
|
|
1942
2007
|
contractId: params.contractId,
|
|
1943
2008
|
sender: params.sender,
|
|
1944
2009
|
recipient: params.recipient,
|
|
1945
2010
|
assetIdentifier: params.assetIdentifier,
|
|
2011
|
+
rune: params.rune,
|
|
2012
|
+
address: params.address,
|
|
1946
2013
|
filters: params.filters
|
|
1947
2014
|
};
|
|
1948
2015
|
}
|
|
@@ -2054,9 +2121,15 @@ function createStreamsClient(options) {
|
|
|
2054
2121
|
}
|
|
2055
2122
|
return JSON.parse(text);
|
|
2056
2123
|
}
|
|
2057
|
-
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
|
+
}
|
|
2058
2130
|
function listReorgs(params) {
|
|
2059
2131
|
return request(`/v1/streams/reorgs${buildQuery({
|
|
2132
|
+
chain: params.chain === "bitcoin" ? "bitcoin" : undefined,
|
|
2060
2133
|
since: params.since,
|
|
2061
2134
|
limit: params.limit
|
|
2062
2135
|
})}`);
|
|
@@ -2066,6 +2139,19 @@ function createStreamsClient(options) {
|
|
|
2066
2139
|
return filters ? JSON.stringify(filters) : undefined;
|
|
2067
2140
|
}
|
|
2068
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
|
+
}
|
|
2069
2155
|
return request(`/v1/streams/events${buildQuery({
|
|
2070
2156
|
cursor: params.cursor,
|
|
2071
2157
|
from_height: params.fromHeight,
|
|
@@ -2124,47 +2210,81 @@ function createStreamsClient(options) {
|
|
|
2124
2210
|
wake: params.wake
|
|
2125
2211
|
});
|
|
2126
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
|
+
}
|
|
2127
2280
|
return {
|
|
2128
|
-
consume
|
|
2129
|
-
return iterateStreamsBatches({
|
|
2130
|
-
fromCursor: params.cursor,
|
|
2131
|
-
batchSize: params.batchSize ?? 100,
|
|
2132
|
-
intervalMs: params.intervalMs ?? 2000,
|
|
2133
|
-
...streamsFilters(params),
|
|
2134
|
-
signal: params.signal,
|
|
2135
|
-
fetchEvents
|
|
2136
|
-
});
|
|
2137
|
-
},
|
|
2281
|
+
consume: consumeBatches,
|
|
2138
2282
|
events: {
|
|
2139
2283
|
list: listEvents,
|
|
2140
|
-
byTxId
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
stream(params = {}) {
|
|
2145
|
-
return streamStreamsEvents({
|
|
2146
|
-
fromCursor: params.fromCursor,
|
|
2147
|
-
...streamsFilters(params),
|
|
2148
|
-
batchSize: params.batchSize ?? 100,
|
|
2149
|
-
emptyBackoffMs: params.emptyBackoffMs,
|
|
2150
|
-
maxPages: params.maxPages,
|
|
2151
|
-
maxEmptyPolls: params.maxEmptyPolls,
|
|
2152
|
-
signal: params.signal,
|
|
2153
|
-
fetchEvents
|
|
2154
|
-
});
|
|
2155
|
-
},
|
|
2156
|
-
subscribe(params) {
|
|
2157
|
-
return subscribeStreamsEvents({
|
|
2158
|
-
baseUrl,
|
|
2159
|
-
headers: authHeaders(),
|
|
2160
|
-
fetchImpl,
|
|
2161
|
-
verify: verifyMode,
|
|
2162
|
-
loadKey: loadKeyFor,
|
|
2163
|
-
reconnectDelayMs: params.reconnectDelayMs,
|
|
2164
|
-
staleAfterMs: params.staleAfterMs,
|
|
2165
|
-
params
|
|
2166
|
-
});
|
|
2167
|
-
},
|
|
2284
|
+
byTxId,
|
|
2285
|
+
consume: dispatchEventsConsume,
|
|
2286
|
+
stream: streamEvents,
|
|
2287
|
+
subscribe: subscribeEvents,
|
|
2168
2288
|
async replay(params) {
|
|
2169
2289
|
const fromCursor = params.from === "genesis" ? null : params.from ?? null;
|
|
2170
2290
|
const fromBlock = fromCursor ? cursorTuple(fromCursor)[0] : 0;
|
|
@@ -2194,18 +2314,16 @@ function createStreamsClient(options) {
|
|
|
2194
2314
|
}
|
|
2195
2315
|
},
|
|
2196
2316
|
blocks: {
|
|
2197
|
-
events(heightOrHash) {
|
|
2198
|
-
return request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events`);
|
|
2199
|
-
}
|
|
2317
|
+
events: (heightOrHash, opts) => request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events${buildQuery({ chain: opts?.chain === "bitcoin" ? "bitcoin" : undefined })}`)
|
|
2200
2318
|
},
|
|
2201
2319
|
reorgs: { list: listReorgs },
|
|
2202
2320
|
dumps,
|
|
2203
|
-
canonical(height) {
|
|
2204
|
-
|
|
2205
|
-
},
|
|
2206
|
-
tip() {
|
|
2207
|
-
|
|
2208
|
-
}
|
|
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
|
+
})}`)
|
|
2209
2327
|
};
|
|
2210
2328
|
}
|
|
2211
2329
|
|
|
@@ -3238,6 +3356,7 @@ import {
|
|
|
3238
3356
|
|
|
3239
3357
|
// src/streams/types.ts
|
|
3240
3358
|
import {
|
|
3359
|
+
RUNE_EVENT_TYPES,
|
|
3241
3360
|
STREAMS_EVENT_TYPES
|
|
3242
3361
|
} from "@secondlayer/shared/streams-rows";
|
|
3243
3362
|
// src/clarity.ts
|
|
@@ -3318,5 +3437,5 @@ export {
|
|
|
3318
3437
|
verifyWebhookSignature
|
|
3319
3438
|
};
|
|
3320
3439
|
|
|
3321
|
-
//# debugId=
|
|
3440
|
+
//# debugId=39B36DCFC98F548264756E2164756E21
|
|
3322
3441
|
//# sourceMappingURL=index.js.map
|