@secondlayer/sdk 6.2.1 → 6.4.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 CHANGED
@@ -485,6 +485,252 @@ type ContractCallsWalkParams = Omit<ContractCallsListParams, "limit"> & {
485
485
  batchSize?: number
486
486
  signal?: AbortSignal
487
487
  };
488
+ /** One canonical block in the sync map. Lean by design — block + parent hash
489
+ * for chain linkage, burn anchor for Bitcoin confirmations. Use `blocks` for
490
+ * the full block resource. */
491
+ type IndexCanonicalBlock = {
492
+ cursor: string
493
+ block_height: number
494
+ block_hash: string
495
+ parent_hash: string
496
+ burn_block_height: number
497
+ burn_block_hash: string | null
498
+ };
499
+ type CanonicalEnvelope = {
500
+ canonical: IndexCanonicalBlock[]
501
+ next_cursor: string | null
502
+ tip: IndexTip
503
+ };
504
+ type CanonicalListParams = {
505
+ cursor?: string | null
506
+ fromCursor?: string | null
507
+ limit?: number
508
+ fromHeight?: number
509
+ toHeight?: number
510
+ };
511
+ type CanonicalWalkParams = Omit<CanonicalListParams, "limit"> & {
512
+ batchSize?: number
513
+ signal?: AbortSignal
514
+ };
515
+ /** A block resource. Metadata is intentionally thin — only chain-linkage and
516
+ * burn-anchor fields are persisted (no miner / tx_count / signer). */
517
+ type IndexBlock = {
518
+ cursor: string
519
+ block_height: number
520
+ block_hash: string
521
+ parent_hash: string
522
+ burn_block_height: number
523
+ burn_block_hash: string | null
524
+ block_time: string | null
525
+ canonical: boolean
526
+ };
527
+ type BlocksEnvelope = {
528
+ blocks: IndexBlock[]
529
+ next_cursor: string | null
530
+ tip: IndexTip
531
+ };
532
+ type BlockEnvelope = {
533
+ block: IndexBlock
534
+ tip: IndexTip
535
+ };
536
+ type BlocksListParams = {
537
+ cursor?: string | null
538
+ fromCursor?: string | null
539
+ limit?: number
540
+ fromHeight?: number
541
+ toHeight?: number
542
+ };
543
+ type BlocksWalkParams = Omit<BlocksListParams, "limit"> & {
544
+ batchSize?: number
545
+ signal?: AbortSignal
546
+ };
547
+ type IndexPostCondition = {
548
+ type: "stx"
549
+ principal: string
550
+ condition_code: number
551
+ condition_code_name: string | null
552
+ amount: string
553
+ } | {
554
+ type: "ft"
555
+ principal: string
556
+ asset_identifier: string
557
+ condition_code: number
558
+ condition_code_name: string | null
559
+ amount: string
560
+ } | {
561
+ type: "nft"
562
+ principal: string
563
+ asset_identifier: string
564
+ asset_value: unknown
565
+ condition_code: number
566
+ condition_code_name: string | null
567
+ };
568
+ /** Full transaction document: columnar fields plus `raw_tx`-decoded enrichment.
569
+ * Payload sub-objects are present only for the matching `tx_type`; enrichment
570
+ * fields are null when `raw_tx` isn't decodable (e.g. burnchain ops). */
571
+ type IndexTransaction = {
572
+ cursor: string
573
+ tx_id: string
574
+ block_height: number
575
+ block_time?: string | null
576
+ tx_index: number
577
+ tx_type: string
578
+ sender: string
579
+ status: string
580
+ fee: string | null
581
+ nonce: string | null
582
+ sponsored: boolean | null
583
+ anchor_mode: string | null
584
+ post_condition_mode: string | null
585
+ post_conditions: IndexPostCondition[]
586
+ contract_call?: {
587
+ contract_id: string
588
+ function_name: string
589
+ function_args: unknown[]
590
+ result: unknown
591
+ result_hex: string | null
592
+ }
593
+ token_transfer?: {
594
+ recipient: string
595
+ amount: string
596
+ memo: string
597
+ }
598
+ smart_contract?: {
599
+ contract_id: string | null
600
+ clarity_version: number | null
601
+ }
602
+ coinbase?: {
603
+ alt_recipient: string | null
604
+ }
605
+ tenure_change?: {
606
+ cause: number
607
+ }
608
+ };
609
+ type TransactionsEnvelope = {
610
+ transactions: IndexTransaction[]
611
+ next_cursor: string | null
612
+ tip: IndexTip
613
+ reorgs: never[]
614
+ };
615
+ type TransactionEnvelope = {
616
+ transaction: IndexTransaction
617
+ tip: IndexTip
618
+ };
619
+ type TransactionsListParams = {
620
+ cursor?: string | null
621
+ fromCursor?: string | null
622
+ limit?: number
623
+ type?: string
624
+ sender?: string
625
+ contractId?: string
626
+ fromHeight?: number
627
+ toHeight?: number
628
+ };
629
+ type TransactionsWalkParams = Omit<TransactionsListParams, "limit"> & {
630
+ batchSize?: number
631
+ signal?: AbortSignal
632
+ };
633
+ /** A decoded PoX-4 stacking action (one per stacking contract call). */
634
+ type IndexStackingAction = {
635
+ cursor: string
636
+ block_height: number
637
+ block_time?: string | null
638
+ burn_block_height: number
639
+ tx_id: string
640
+ tx_index: number
641
+ function_name: string
642
+ caller: string
643
+ stacker: string | null
644
+ delegate_to: string | null
645
+ amount_ustx: string | null
646
+ lock_period: number | null
647
+ pox_addr: {
648
+ version: number | null
649
+ hashbytes: string | null
650
+ btc: string | null
651
+ }
652
+ start_cycle: number | null
653
+ end_cycle: number | null
654
+ reward_cycle: number | null
655
+ signer_key: string | null
656
+ result_ok: boolean
657
+ };
658
+ type StackingEnvelope = {
659
+ stacking: IndexStackingAction[]
660
+ next_cursor: string | null
661
+ tip: IndexTip
662
+ /** Present only when the PoX-4 decoder is disabled, explaining an empty feed. */
663
+ notes?: string
664
+ };
665
+ type StackingListParams = {
666
+ cursor?: string | null
667
+ fromCursor?: string | null
668
+ limit?: number
669
+ functionName?: string
670
+ stacker?: string
671
+ caller?: string
672
+ fromHeight?: number
673
+ toHeight?: number
674
+ };
675
+ type StackingWalkParams = Omit<StackingListParams, "limit"> & {
676
+ batchSize?: number
677
+ signal?: AbortSignal
678
+ };
679
+ /** A pending (unconfirmed) transaction. Like a transaction document but
680
+ * pre-chain — no block_height/tx_index/result/events — with `received_at` and
681
+ * a sequence cursor instead of a block position. */
682
+ type IndexMempoolTransaction = {
683
+ cursor: string
684
+ tx_id: string
685
+ tx_type: string
686
+ sender: string
687
+ received_at?: string | null
688
+ fee: string | null
689
+ nonce: string | null
690
+ sponsored: boolean | null
691
+ anchor_mode: string | null
692
+ post_condition_mode: string | null
693
+ post_conditions: IndexPostCondition[]
694
+ contract_call?: {
695
+ contract_id: string
696
+ function_name: string
697
+ function_args: unknown[]
698
+ }
699
+ token_transfer?: {
700
+ recipient: string
701
+ amount: string
702
+ memo: string
703
+ }
704
+ smart_contract?: {
705
+ clarity_version: number | null
706
+ }
707
+ coinbase?: {
708
+ alt_recipient: string | null
709
+ }
710
+ tenure_change?: {
711
+ cause: number
712
+ }
713
+ };
714
+ type MempoolEnvelope = {
715
+ mempool: IndexMempoolTransaction[]
716
+ next_cursor: string | null
717
+ tip: IndexTip
718
+ };
719
+ type MempoolTransactionEnvelope = {
720
+ transaction: IndexMempoolTransaction
721
+ tip: IndexTip
722
+ };
723
+ type MempoolListParams = {
724
+ cursor?: string | null
725
+ fromCursor?: string | null
726
+ limit?: number
727
+ sender?: string
728
+ type?: string
729
+ };
730
+ type MempoolWalkParams = Omit<MempoolListParams, "limit"> & {
731
+ batchSize?: number
732
+ signal?: AbortSignal
733
+ };
488
734
  declare class Index extends BaseClient {
489
735
  constructor(options?: Partial<SecondLayerOptions>);
490
736
  readonly ftTransfers: {
@@ -504,6 +750,38 @@ declare class Index extends BaseClient {
504
750
  list: (params?: ContractCallsListParams) => Promise<ContractCallsEnvelope>
505
751
  walk: (params?: ContractCallsWalkParams) => AsyncIterable<IndexContractCall>
506
752
  };
753
+ /** Canonical block-hash map — sync only the current canonical chain. */
754
+ readonly canonical: {
755
+ list: (params?: CanonicalListParams) => Promise<CanonicalEnvelope>
756
+ walk: (params?: CanonicalWalkParams) => AsyncIterable<IndexCanonicalBlock>
757
+ };
758
+ /** Canonical blocks: paginated `list`/`walk`, plus `get` by height or hash
759
+ * (resolves to null on 404). */
760
+ readonly blocks: {
761
+ list: (params?: BlocksListParams) => Promise<BlocksEnvelope>
762
+ walk: (params?: BlocksWalkParams) => AsyncIterable<IndexBlock>
763
+ get: (ref: string | number) => Promise<BlockEnvelope | null>
764
+ };
765
+ /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
766
+ * (resolves to null on 404). */
767
+ readonly transactions: {
768
+ list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
769
+ walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
770
+ get: (txId: string) => Promise<TransactionEnvelope | null>
771
+ };
772
+ /** Decoded PoX-4 stacking actions. Empty (with a `notes` hint) when the
773
+ * platform's PoX-4 decoder is disabled. */
774
+ readonly stacking: {
775
+ list: (params?: StackingListParams) => Promise<StackingEnvelope>
776
+ walk: (params?: StackingWalkParams) => AsyncIterable<IndexStackingAction>
777
+ };
778
+ /** Pending (unconfirmed) transactions: paginated `list`/`walk`, plus `get` by
779
+ * tx_id (resolves to null when the tx has confirmed or dropped). */
780
+ readonly mempool: {
781
+ list: (params?: MempoolListParams) => Promise<MempoolEnvelope>
782
+ walk: (params?: MempoolWalkParams) => AsyncIterable<IndexMempoolTransaction>
783
+ get: (txId: string) => Promise<MempoolTransactionEnvelope | null>
784
+ };
507
785
  private listFtTransfers;
508
786
  private listNftTransfers;
509
787
  private walkFtTransfers;
@@ -512,6 +790,19 @@ declare class Index extends BaseClient {
512
790
  private walkEvents;
513
791
  private listContractCalls;
514
792
  private walkContractCalls;
793
+ private listCanonical;
794
+ private walkCanonical;
795
+ private listBlocks;
796
+ private getBlock;
797
+ private walkBlocks;
798
+ private listTransactions;
799
+ private getTransaction;
800
+ private walkTransactions;
801
+ private listStacking;
802
+ private walkStacking;
803
+ private listMempool;
804
+ private getMempoolTx;
805
+ private walkMempool;
515
806
  }
516
807
  declare const STREAMS_EVENT_TYPES: readonly ["stx_transfer", "stx_mint", "stx_burn", "stx_lock", "ft_transfer", "ft_mint", "ft_burn", "nft_transfer", "nft_mint", "nft_burn", "print"];
517
808
  type StreamsEventType = (typeof STREAMS_EVENT_TYPES)[number];
@@ -1329,4 +1620,4 @@ declare function toJsonSafe(value: unknown): unknown;
1329
1620
  /** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
1330
1621
  * buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
1331
1622
  declare function decodeClarityValue(hex: string): unknown;
1332
- export { verifyWebhookSignature, toJsonSafe, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, IndexTip, IndexEventType, IndexEvent, IndexContractCall, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, 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, Datasets, DatasetRow, CursorListParams, CursorEnvelope, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, CURSOR_SLUGS, AuthError, ApiError };
1623
+ export { verifyWebhookSignature, toJsonSafe, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StackingWalkParams, StackingListParams, StackingEnvelope, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexTransaction, IndexTip, IndexStackingAction, IndexPostCondition, IndexMempoolTransaction, IndexEventType, IndexEvent, IndexContractCall, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, 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, Datasets, DatasetRow, CursorListParams, CursorEnvelope, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, CURSOR_SLUGS, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiError };
package/dist/index.js CHANGED
@@ -489,6 +489,29 @@ class Index extends BaseClient {
489
489
  list: (params = {}) => this.listContractCalls(params),
490
490
  walk: (params = {}) => this.walkContractCalls(params)
491
491
  };
492
+ canonical = {
493
+ list: (params = {}) => this.listCanonical(params),
494
+ walk: (params = {}) => this.walkCanonical(params)
495
+ };
496
+ blocks = {
497
+ list: (params = {}) => this.listBlocks(params),
498
+ walk: (params = {}) => this.walkBlocks(params),
499
+ get: (ref) => this.getBlock(ref)
500
+ };
501
+ transactions = {
502
+ list: (params = {}) => this.listTransactions(params),
503
+ walk: (params = {}) => this.walkTransactions(params),
504
+ get: (txId) => this.getTransaction(txId)
505
+ };
506
+ stacking = {
507
+ list: (params = {}) => this.listStacking(params),
508
+ walk: (params = {}) => this.walkStacking(params)
509
+ };
510
+ mempool = {
511
+ list: (params = {}) => this.listMempool(params),
512
+ walk: (params = {}) => this.walkMempool(params),
513
+ get: (txId) => this.getMempoolTx(txId)
514
+ };
492
515
  async listFtTransfers(params = {}) {
493
516
  return this.request("GET", `/v1/index/ft-transfers${buildQuery({
494
517
  cursor: params.cursor,
@@ -640,6 +663,208 @@ class Index extends BaseClient {
640
663
  firstPage = false;
641
664
  }
642
665
  }
666
+ async listCanonical(params = {}) {
667
+ return this.request("GET", `/v1/index/canonical${buildQuery({
668
+ cursor: params.cursor,
669
+ from_cursor: params.fromCursor,
670
+ limit: params.limit,
671
+ from_height: params.fromHeight,
672
+ to_height: params.toHeight
673
+ })}`);
674
+ }
675
+ async* walkCanonical(params = {}) {
676
+ const batchSize = params.batchSize ?? 200;
677
+ let cursor = params.cursor ?? params.fromCursor ?? null;
678
+ let firstPage = true;
679
+ while (!params.signal?.aborted) {
680
+ const envelope = await this.listCanonical({
681
+ ...params,
682
+ limit: batchSize,
683
+ cursor: firstPage ? params.cursor : cursor,
684
+ fromCursor: firstPage ? params.fromCursor : undefined,
685
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
686
+ });
687
+ for (const block of envelope.canonical) {
688
+ if (params.signal?.aborted)
689
+ return;
690
+ yield block;
691
+ }
692
+ const nextCursor = envelope.next_cursor;
693
+ if (!nextCursor || nextCursor === cursor || envelope.canonical.length < batchSize) {
694
+ return;
695
+ }
696
+ cursor = nextCursor;
697
+ firstPage = false;
698
+ }
699
+ }
700
+ async listBlocks(params = {}) {
701
+ return this.request("GET", `/v1/index/blocks${buildQuery({
702
+ cursor: params.cursor,
703
+ from_cursor: params.fromCursor,
704
+ limit: params.limit,
705
+ from_height: params.fromHeight,
706
+ to_height: params.toHeight
707
+ })}`);
708
+ }
709
+ async getBlock(ref) {
710
+ try {
711
+ return await this.request("GET", `/v1/index/blocks/${encodeURIComponent(String(ref))}`);
712
+ } catch (err) {
713
+ if (err instanceof ApiError && err.status === 404)
714
+ return null;
715
+ throw err;
716
+ }
717
+ }
718
+ async* walkBlocks(params = {}) {
719
+ const batchSize = params.batchSize ?? 200;
720
+ let cursor = params.cursor ?? params.fromCursor ?? null;
721
+ let firstPage = true;
722
+ while (!params.signal?.aborted) {
723
+ const envelope = await this.listBlocks({
724
+ ...params,
725
+ limit: batchSize,
726
+ cursor: firstPage ? params.cursor : cursor,
727
+ fromCursor: firstPage ? params.fromCursor : undefined,
728
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
729
+ });
730
+ for (const block of envelope.blocks) {
731
+ if (params.signal?.aborted)
732
+ return;
733
+ yield block;
734
+ }
735
+ const nextCursor = envelope.next_cursor;
736
+ if (!nextCursor || nextCursor === cursor || envelope.blocks.length < batchSize) {
737
+ return;
738
+ }
739
+ cursor = nextCursor;
740
+ firstPage = false;
741
+ }
742
+ }
743
+ async listTransactions(params = {}) {
744
+ return this.request("GET", `/v1/index/transactions${buildQuery({
745
+ cursor: params.cursor,
746
+ from_cursor: params.fromCursor,
747
+ limit: params.limit,
748
+ type: params.type,
749
+ sender: params.sender,
750
+ contract_id: params.contractId,
751
+ from_height: params.fromHeight,
752
+ to_height: params.toHeight
753
+ })}`);
754
+ }
755
+ async getTransaction(txId) {
756
+ try {
757
+ return await this.request("GET", `/v1/index/transactions/${encodeURIComponent(txId)}`);
758
+ } catch (err) {
759
+ if (err instanceof ApiError && err.status === 404)
760
+ return null;
761
+ throw err;
762
+ }
763
+ }
764
+ async* walkTransactions(params = {}) {
765
+ const batchSize = params.batchSize ?? 200;
766
+ let cursor = params.cursor ?? params.fromCursor ?? null;
767
+ let firstPage = true;
768
+ while (!params.signal?.aborted) {
769
+ const envelope = await this.listTransactions({
770
+ ...params,
771
+ limit: batchSize,
772
+ cursor: firstPage ? params.cursor : cursor,
773
+ fromCursor: firstPage ? params.fromCursor : undefined,
774
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
775
+ });
776
+ for (const tx of envelope.transactions) {
777
+ if (params.signal?.aborted)
778
+ return;
779
+ yield tx;
780
+ }
781
+ const nextCursor = envelope.next_cursor;
782
+ if (!nextCursor || nextCursor === cursor || envelope.transactions.length < batchSize) {
783
+ return;
784
+ }
785
+ cursor = nextCursor;
786
+ firstPage = false;
787
+ }
788
+ }
789
+ async listStacking(params = {}) {
790
+ return this.request("GET", `/v1/index/stacking${buildQuery({
791
+ cursor: params.cursor,
792
+ from_cursor: params.fromCursor,
793
+ limit: params.limit,
794
+ function_name: params.functionName,
795
+ stacker: params.stacker,
796
+ caller: params.caller,
797
+ from_height: params.fromHeight,
798
+ to_height: params.toHeight
799
+ })}`);
800
+ }
801
+ async* walkStacking(params = {}) {
802
+ const batchSize = params.batchSize ?? 200;
803
+ let cursor = params.cursor ?? params.fromCursor ?? null;
804
+ let firstPage = true;
805
+ while (!params.signal?.aborted) {
806
+ const envelope = await this.listStacking({
807
+ ...params,
808
+ limit: batchSize,
809
+ cursor: firstPage ? params.cursor : cursor,
810
+ fromCursor: firstPage ? params.fromCursor : undefined,
811
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
812
+ });
813
+ for (const action of envelope.stacking) {
814
+ if (params.signal?.aborted)
815
+ return;
816
+ yield action;
817
+ }
818
+ const nextCursor = envelope.next_cursor;
819
+ if (!nextCursor || nextCursor === cursor || envelope.stacking.length < batchSize) {
820
+ return;
821
+ }
822
+ cursor = nextCursor;
823
+ firstPage = false;
824
+ }
825
+ }
826
+ async listMempool(params = {}) {
827
+ return this.request("GET", `/v1/index/mempool${buildQuery({
828
+ cursor: params.cursor,
829
+ from_cursor: params.fromCursor,
830
+ limit: params.limit,
831
+ sender: params.sender,
832
+ type: params.type
833
+ })}`);
834
+ }
835
+ async getMempoolTx(txId) {
836
+ try {
837
+ return await this.request("GET", `/v1/index/mempool/${encodeURIComponent(txId)}`);
838
+ } catch (err) {
839
+ if (err instanceof ApiError && err.status === 404)
840
+ return null;
841
+ throw err;
842
+ }
843
+ }
844
+ async* walkMempool(params = {}) {
845
+ const batchSize = params.batchSize ?? 200;
846
+ let cursor = params.cursor ?? params.fromCursor ?? null;
847
+ let firstPage = true;
848
+ while (!params.signal?.aborted) {
849
+ const envelope = await this.listMempool({
850
+ ...params,
851
+ limit: batchSize,
852
+ cursor: firstPage ? params.cursor : cursor,
853
+ fromCursor: firstPage ? params.fromCursor : undefined
854
+ });
855
+ for (const tx of envelope.mempool) {
856
+ if (params.signal?.aborted)
857
+ return;
858
+ yield tx;
859
+ }
860
+ const nextCursor = envelope.next_cursor;
861
+ if (!nextCursor || nextCursor === cursor || envelope.mempool.length < batchSize) {
862
+ return;
863
+ }
864
+ cursor = nextCursor;
865
+ firstPage = false;
866
+ }
867
+ }
643
868
  }
644
869
 
645
870
  // src/streams/client.ts
@@ -1563,5 +1788,5 @@ export {
1563
1788
  ApiError
1564
1789
  };
1565
1790
 
1566
- //# debugId=C7330C1F713D815864756E2164756E21
1791
+ //# debugId=795A191B3E98A82E64756E2164756E21
1567
1792
  //# sourceMappingURL=index.js.map