@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/index.d.ts
CHANGED
|
@@ -574,9 +574,34 @@ type StreamsEventsSubscribeParams = {
|
|
|
574
574
|
* It is the position to advance to: `next_cursor` normally, or the last
|
|
575
575
|
* finalized event when `finalizedOnly` is set.
|
|
576
576
|
*/
|
|
577
|
-
|
|
577
|
+
/**
|
|
578
|
+
* What the loop knows at the end of a page, handed to `onBatch`.
|
|
579
|
+
*
|
|
580
|
+
* `cursor` is the position to commit. The rest answers "how far along am I,
|
|
581
|
+
* and am I still moving" — the question every deployed consumer has to expose
|
|
582
|
+
* for a health check.
|
|
583
|
+
*
|
|
584
|
+
* Progress is reported here rather than left to callers because only the loop
|
|
585
|
+
* can get it right: `height` has to survive empty pages (normal at the tip)
|
|
586
|
+
* and has to roll back to `fork_point_height - 1` after a reorg rewind.
|
|
587
|
+
* Deriving it from `cursor` is wrong — `Cursor.atHeight` encodes the foot of a
|
|
588
|
+
* block as `${height - 1}:<sentinel>`, so a rewound cursor parses to a
|
|
589
|
+
* position that was never reached.
|
|
590
|
+
*/
|
|
591
|
+
type ConsumerBatchContext = {
|
|
592
|
+
/** Checkpoint to commit alongside your rows. */
|
|
578
593
|
cursor: string | null
|
|
579
|
-
|
|
594
|
+
/** Highest canonical block the sweep has reached. `null` before the first
|
|
595
|
+
* row of a fresh consume. */
|
|
596
|
+
height: number | null
|
|
597
|
+
/** Chain tip as of this page's read. */
|
|
598
|
+
tipHeight: number
|
|
599
|
+
/** `tipHeight - height`, floored at 0. `null` until `height` is known. */
|
|
600
|
+
blocksBehind: number | null
|
|
601
|
+
};
|
|
602
|
+
/** @deprecated Use {@link ConsumerBatchContext} — the Index and Streams loops
|
|
603
|
+
* share one shape now. Kept as an alias so existing annotations compile. */
|
|
604
|
+
type StreamsBatchContext = ConsumerBatchContext;
|
|
580
605
|
/**
|
|
581
606
|
* The checkpoint for a reorg rollback. Persist `cursor` (the rewind position)
|
|
582
607
|
* inside the same transaction as your rollback so the two commit atomically.
|
|
@@ -843,9 +868,7 @@ type IndexConsumeOptions<
|
|
|
843
868
|
* never reorgs, so `onReorg` is skipped entirely. */
|
|
844
869
|
finalizedOnly?: boolean
|
|
845
870
|
batchSize?: number
|
|
846
|
-
onBatch: (items: TItem[], envelope: TEnvelope, ctx:
|
|
847
|
-
cursor: string | null
|
|
848
|
-
}) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
871
|
+
onBatch: (items: TItem[], envelope: TEnvelope, ctx: ConsumerBatchContext) => void | string | null | undefined | Promise<void> | Promise<string | null | undefined>
|
|
849
872
|
onReorg?: (reorg: IndexReorg, ctx: {
|
|
850
873
|
cursor: string
|
|
851
874
|
}) => Promise<void> | void
|
|
@@ -1084,19 +1107,27 @@ type IndexPrint = IndexEventBase & {
|
|
|
1084
1107
|
/** Decoded chain event, discriminated by `event_type`. */
|
|
1085
1108
|
type IndexEvent = IndexFtTransfer | IndexNftTransfer | IndexStxTransfer | IndexStxMint | IndexStxBurn | IndexStxLock | IndexFtMint | IndexFtBurn | IndexNftMint | IndexNftBurn | IndexPrint;
|
|
1086
1109
|
type IndexEventType = IndexEvent["event_type"];
|
|
1087
|
-
type EventsEnvelope = {
|
|
1088
|
-
events:
|
|
1110
|
+
type EventsEnvelope<T extends IndexEventType = IndexEventType> = {
|
|
1111
|
+
events: IndexEventOf<T>[]
|
|
1089
1112
|
next_cursor: string | null
|
|
1090
1113
|
tip: IndexTip
|
|
1091
1114
|
reorgs: IndexReorg[]
|
|
1092
1115
|
};
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1116
|
+
/** The single decoded-event member matching one `event_type` literal.
|
|
1117
|
+
* `IndexEventOf<"ft_transfer">` is `IndexFtTransfer`. */
|
|
1118
|
+
type IndexEventOf<T extends IndexEventType> = Extract<IndexEvent, {
|
|
1119
|
+
event_type: T
|
|
1120
|
+
}>;
|
|
1121
|
+
type EventsListParams<T extends IndexEventType = IndexEventType> = {
|
|
1122
|
+
/** Required. One of the decoded event types. Passing a literal narrows the
|
|
1123
|
+
* rows every surface hands back to that event's own shape. */
|
|
1124
|
+
eventType: T
|
|
1096
1125
|
cursor?: string | null
|
|
1097
1126
|
fromCursor?: string | null
|
|
1098
1127
|
limit?: number
|
|
1099
|
-
|
|
1128
|
+
/** One id, or several to scope the sweep to a set of contracts (max 20).
|
|
1129
|
+
* Mutually exclusive with `trait`. */
|
|
1130
|
+
contractId?: string | readonly string[]
|
|
1100
1131
|
assetIdentifier?: string
|
|
1101
1132
|
sender?: string
|
|
1102
1133
|
recipient?: string
|
|
@@ -1111,11 +1142,11 @@ type EventsListParams = {
|
|
|
1111
1142
|
* the only source of the submitting sender. */
|
|
1112
1143
|
txContext?: boolean
|
|
1113
1144
|
};
|
|
1114
|
-
type EventsWalkParams = Omit<EventsListParams
|
|
1145
|
+
type EventsWalkParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "limit"> & {
|
|
1115
1146
|
batchSize?: number
|
|
1116
1147
|
signal?: AbortSignal
|
|
1117
1148
|
};
|
|
1118
|
-
type EventsConsumeParams = Omit<EventsListParams
|
|
1149
|
+
type EventsConsumeParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexEventOf<T>, EventsEnvelope<T>>;
|
|
1119
1150
|
type IndexContractCall = {
|
|
1120
1151
|
cursor: string
|
|
1121
1152
|
block_height: number
|
|
@@ -1140,7 +1171,9 @@ type ContractCallsListParams = {
|
|
|
1140
1171
|
cursor?: string | null
|
|
1141
1172
|
fromCursor?: string | null
|
|
1142
1173
|
limit?: number
|
|
1143
|
-
|
|
1174
|
+
/** One id, or several to scope the sweep to a set of contracts (max 20).
|
|
1175
|
+
* Mutually exclusive with `trait`. */
|
|
1176
|
+
contractId?: string | readonly string[]
|
|
1144
1177
|
functionName?: string
|
|
1145
1178
|
sender?: string
|
|
1146
1179
|
fromHeight?: number
|
|
@@ -1626,12 +1659,21 @@ type SbtcEventsWalkParams = Omit<SbtcEventsListParams, "limit"> & {
|
|
|
1626
1659
|
batchSize?: number
|
|
1627
1660
|
signal?: AbortSignal
|
|
1628
1661
|
};
|
|
1662
|
+
type SbtcEventsConsumeParams = Omit<SbtcEventsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcEvent, SbtcEventsEnvelope>;
|
|
1663
|
+
type SbtcDepositsConsumeParams = Omit<SbtcDepositsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcDeposit, SbtcDepositsEnvelope>;
|
|
1629
1664
|
/** `index.sbtc` — the decoded sBTC peg surface (deposits, withdrawals, raw
|
|
1630
1665
|
* events, scoreboard). The only productized decoded sBTC peg feed on Stacks. */
|
|
1631
1666
|
interface SbtcResource {
|
|
1632
1667
|
deposits: {
|
|
1633
1668
|
list(params?: SbtcDepositsListParams): Promise<SbtcDepositsEnvelope>
|
|
1634
1669
|
walk(params?: SbtcDepositsWalkParams): AsyncIterable<IndexSbtcDeposit>
|
|
1670
|
+
/** Checkpointed sweep of completed deposits — append-only, so safe to
|
|
1671
|
+
* mirror. See {@link IndexConsumeOptions}. */
|
|
1672
|
+
consume(params: SbtcDepositsConsumeParams): Promise<{
|
|
1673
|
+
cursor: string | null
|
|
1674
|
+
pages: number
|
|
1675
|
+
emptyPolls: number
|
|
1676
|
+
}>
|
|
1635
1677
|
/** Fetch a completed deposit by Bitcoin txid; 404 → null. */
|
|
1636
1678
|
get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
|
|
1637
1679
|
};
|
|
@@ -1644,6 +1686,13 @@ interface SbtcResource {
|
|
|
1644
1686
|
events: {
|
|
1645
1687
|
list(params?: SbtcEventsListParams): Promise<SbtcEventsEnvelope>
|
|
1646
1688
|
walk(params?: SbtcEventsWalkParams): AsyncIterable<IndexSbtcEvent>
|
|
1689
|
+
/** Checkpointed sweep of the raw peg event log — append-only across all
|
|
1690
|
+
* six topics. See {@link IndexConsumeOptions}. */
|
|
1691
|
+
consume(params: SbtcEventsConsumeParams): Promise<{
|
|
1692
|
+
cursor: string | null
|
|
1693
|
+
pages: number
|
|
1694
|
+
emptyPolls: number
|
|
1695
|
+
}>
|
|
1647
1696
|
};
|
|
1648
1697
|
/** The peg scoreboard — a single all-time aggregate (no pagination). */
|
|
1649
1698
|
summary(): Promise<SbtcSummaryEnvelope>;
|
|
@@ -1786,10 +1835,10 @@ interface NftTransfersResource {
|
|
|
1786
1835
|
}
|
|
1787
1836
|
/** `index.events` — callable shorthand for `.list()`; `eventType` is required. */
|
|
1788
1837
|
interface IndexEventsResource {
|
|
1789
|
-
(params: EventsListParams): Promise<EventsEnvelope
|
|
1790
|
-
list(params: EventsListParams): Promise<EventsEnvelope
|
|
1791
|
-
walk(params: EventsWalkParams): AsyncIterable<
|
|
1792
|
-
consume(params: EventsConsumeParams): Promise<{
|
|
1838
|
+
<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1839
|
+
list<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1840
|
+
walk<T extends IndexEventType>(params: EventsWalkParams<T>): AsyncIterable<IndexEventOf<T>>;
|
|
1841
|
+
consume<T extends IndexEventType>(params: EventsConsumeParams<T>): Promise<{
|
|
1793
1842
|
cursor: string | null
|
|
1794
1843
|
pages: number
|
|
1795
1844
|
emptyPolls: number
|
|
@@ -2846,4 +2895,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
2846
2895
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
2847
2896
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
2848
2897
|
declare function decodeClarityValue(hex: string): unknown;
|
|
2849
|
-
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, selectOffer, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, createX402Client, createStreamsClient, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SelectOfferOptions, SecondLayerOptions, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
|
2898
|
+
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, selectOffer, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, createX402Client, createStreamsClient, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SelectOfferOptions, SecondLayerOptions, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
package/dist/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
|
};
|
|
@@ -2458,5 +2496,5 @@ export {
|
|
|
2458
2496
|
ApiError
|
|
2459
2497
|
};
|
|
2460
2498
|
|
|
2461
|
-
//# debugId=
|
|
2499
|
+
//# debugId=D5B171025CDFC80A64756E2164756E21
|
|
2462
2500
|
//# sourceMappingURL=index.js.map
|