@secondlayer/sdk 6.33.1 → 6.35.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.d.ts +68 -19
- package/dist/index.js +46 -8
- package/dist/index.js.map +6 -6
- package/dist/streams/index.d.ts +28 -3
- package/dist/streams/index.js +13 -4
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +67 -18
- package/dist/subgraphs/index.js +46 -8
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +3 -1
package/dist/subgraphs/index.js
CHANGED
|
@@ -494,6 +494,14 @@ var Cursor = {
|
|
|
494
494
|
function reorgKey(reorg) {
|
|
495
495
|
return `${reorg.detected_at}|${reorg.fork_point_height}|${reorg.new_canonical_tip}`;
|
|
496
496
|
}
|
|
497
|
+
function batchContext(cursor, height, tipHeight) {
|
|
498
|
+
return {
|
|
499
|
+
cursor,
|
|
500
|
+
height,
|
|
501
|
+
tipHeight,
|
|
502
|
+
blocksBehind: height === null ? null : Math.max(0, tipHeight - height)
|
|
503
|
+
};
|
|
504
|
+
}
|
|
497
505
|
async function defaultSleep(ms, signal) {
|
|
498
506
|
if (signal?.aborted)
|
|
499
507
|
return;
|
|
@@ -518,6 +526,7 @@ async function consumeStreamsEvents(opts) {
|
|
|
518
526
|
const handledReorgs = new Set;
|
|
519
527
|
let pages = 0;
|
|
520
528
|
let emptyPolls = 0;
|
|
529
|
+
let height = null;
|
|
521
530
|
while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
|
|
522
531
|
const envelope = await opts.fetchEvents({
|
|
523
532
|
cursor,
|
|
@@ -540,15 +549,15 @@ async function consumeStreamsEvents(opts) {
|
|
|
540
549
|
handledReorgs.add(reorgKey(reorg));
|
|
541
550
|
}
|
|
542
551
|
cursor = rewind;
|
|
552
|
+
height = forkPoint > 0 ? forkPoint - 1 : null;
|
|
543
553
|
emptyPolls = 0;
|
|
544
554
|
continue;
|
|
545
555
|
}
|
|
546
556
|
}
|
|
547
557
|
const emitted = finalizedOnly ? envelope.events.filter((event) => event.finalized) : envelope.events;
|
|
548
558
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
});
|
|
559
|
+
height = emitted.at(-1)?.block_height ?? height;
|
|
560
|
+
const returnedCursor = await opts.onBatch(emitted, envelope, batchContext(checkpoint, height, envelope.tip.block_height));
|
|
552
561
|
const nextCursor = returnedCursor ?? checkpoint;
|
|
553
562
|
if (nextCursor && nextCursor !== cursor) {
|
|
554
563
|
cursor = nextCursor;
|
|
@@ -654,6 +663,7 @@ async function consumeIndexFeed(opts) {
|
|
|
654
663
|
const handledReorgs = new Set;
|
|
655
664
|
let pages = 0;
|
|
656
665
|
let emptyPolls = 0;
|
|
666
|
+
let height = null;
|
|
657
667
|
while (pages < maxPages && emptyPolls < maxEmptyPolls && !opts.signal?.aborted) {
|
|
658
668
|
const envelope = await opts.fetchPage({
|
|
659
669
|
cursor,
|
|
@@ -671,6 +681,7 @@ async function consumeIndexFeed(opts) {
|
|
|
671
681
|
handledReorgs.add(reorg.id);
|
|
672
682
|
}
|
|
673
683
|
cursor = rewind;
|
|
684
|
+
height = forkPoint > 0 ? forkPoint - 1 : null;
|
|
674
685
|
emptyPolls = 0;
|
|
675
686
|
continue;
|
|
676
687
|
}
|
|
@@ -678,9 +689,8 @@ async function consumeIndexFeed(opts) {
|
|
|
678
689
|
const items = opts.itemsOf(envelope);
|
|
679
690
|
const emitted = finalizedOnly ? items.filter((item) => item.block_height <= envelope.tip.finalized_height) : items;
|
|
680
691
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
});
|
|
692
|
+
height = emitted.at(-1)?.block_height ?? height;
|
|
693
|
+
const returnedCursor = await opts.onBatch(emitted, envelope, batchContext(checkpoint, height, envelope.tip.block_height));
|
|
684
694
|
const nextCursor = returnedCursor ?? checkpoint;
|
|
685
695
|
if (nextCursor && nextCursor !== cursor) {
|
|
686
696
|
cursor = nextCursor;
|
|
@@ -797,6 +807,19 @@ class Index extends BaseClient {
|
|
|
797
807
|
deposits: {
|
|
798
808
|
list: (params = {}) => this.listSbtcDeposits(params),
|
|
799
809
|
walk: (params = {}) => this.walkSbtcDeposits(params),
|
|
810
|
+
consume: (params) => consumeIndexFeed({
|
|
811
|
+
...params,
|
|
812
|
+
fetchPage: ({ cursor, fromHeight, limit }) => this.listSbtcDeposits({
|
|
813
|
+
confirmed: params.confirmed,
|
|
814
|
+
sender: params.sender,
|
|
815
|
+
bitcoinTxid: params.bitcoinTxid,
|
|
816
|
+
toHeight: params.toHeight,
|
|
817
|
+
cursor,
|
|
818
|
+
fromHeight,
|
|
819
|
+
limit
|
|
820
|
+
}),
|
|
821
|
+
itemsOf: (envelope) => envelope.deposits
|
|
822
|
+
}),
|
|
800
823
|
get: (bitcoinTxid) => this.getSbtcDeposit(bitcoinTxid)
|
|
801
824
|
},
|
|
802
825
|
withdrawals: {
|
|
@@ -806,7 +829,22 @@ class Index extends BaseClient {
|
|
|
806
829
|
},
|
|
807
830
|
events: {
|
|
808
831
|
list: (params = {}) => this.listSbtcEvents(params),
|
|
809
|
-
walk: (params = {}) => this.walkSbtcEvents(params)
|
|
832
|
+
walk: (params = {}) => this.walkSbtcEvents(params),
|
|
833
|
+
consume: (params) => consumeIndexFeed({
|
|
834
|
+
...params,
|
|
835
|
+
fetchPage: ({ cursor, fromHeight, limit }) => this.listSbtcEvents({
|
|
836
|
+
confirmed: params.confirmed,
|
|
837
|
+
topic: params.topic,
|
|
838
|
+
sender: params.sender,
|
|
839
|
+
requestId: params.requestId,
|
|
840
|
+
bitcoinTxid: params.bitcoinTxid,
|
|
841
|
+
toHeight: params.toHeight,
|
|
842
|
+
cursor,
|
|
843
|
+
fromHeight,
|
|
844
|
+
limit
|
|
845
|
+
}),
|
|
846
|
+
itemsOf: (envelope) => envelope.events
|
|
847
|
+
})
|
|
810
848
|
},
|
|
811
849
|
summary: () => this.getSbtcSummary()
|
|
812
850
|
};
|
|
@@ -1752,5 +1790,5 @@ export {
|
|
|
1752
1790
|
Subgraphs
|
|
1753
1791
|
};
|
|
1754
1792
|
|
|
1755
|
-
//# debugId=
|
|
1793
|
+
//# debugId=C01B0960A474ED8C64756E2164756E21
|
|
1756
1794
|
//# sourceMappingURL=index.js.map
|