@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.
@@ -480,6 +480,252 @@ type ContractCallsWalkParams = Omit<ContractCallsListParams, "limit"> & {
480
480
  batchSize?: number
481
481
  signal?: AbortSignal
482
482
  };
483
+ /** One canonical block in the sync map. Lean by design — block + parent hash
484
+ * for chain linkage, burn anchor for Bitcoin confirmations. Use `blocks` for
485
+ * the full block resource. */
486
+ type IndexCanonicalBlock = {
487
+ cursor: string
488
+ block_height: number
489
+ block_hash: string
490
+ parent_hash: string
491
+ burn_block_height: number
492
+ burn_block_hash: string | null
493
+ };
494
+ type CanonicalEnvelope = {
495
+ canonical: IndexCanonicalBlock[]
496
+ next_cursor: string | null
497
+ tip: IndexTip
498
+ };
499
+ type CanonicalListParams = {
500
+ cursor?: string | null
501
+ fromCursor?: string | null
502
+ limit?: number
503
+ fromHeight?: number
504
+ toHeight?: number
505
+ };
506
+ type CanonicalWalkParams = Omit<CanonicalListParams, "limit"> & {
507
+ batchSize?: number
508
+ signal?: AbortSignal
509
+ };
510
+ /** A block resource. Metadata is intentionally thin — only chain-linkage and
511
+ * burn-anchor fields are persisted (no miner / tx_count / signer). */
512
+ type IndexBlock = {
513
+ cursor: string
514
+ block_height: number
515
+ block_hash: string
516
+ parent_hash: string
517
+ burn_block_height: number
518
+ burn_block_hash: string | null
519
+ block_time: string | null
520
+ canonical: boolean
521
+ };
522
+ type BlocksEnvelope = {
523
+ blocks: IndexBlock[]
524
+ next_cursor: string | null
525
+ tip: IndexTip
526
+ };
527
+ type BlockEnvelope = {
528
+ block: IndexBlock
529
+ tip: IndexTip
530
+ };
531
+ type BlocksListParams = {
532
+ cursor?: string | null
533
+ fromCursor?: string | null
534
+ limit?: number
535
+ fromHeight?: number
536
+ toHeight?: number
537
+ };
538
+ type BlocksWalkParams = Omit<BlocksListParams, "limit"> & {
539
+ batchSize?: number
540
+ signal?: AbortSignal
541
+ };
542
+ type IndexPostCondition = {
543
+ type: "stx"
544
+ principal: string
545
+ condition_code: number
546
+ condition_code_name: string | null
547
+ amount: string
548
+ } | {
549
+ type: "ft"
550
+ principal: string
551
+ asset_identifier: string
552
+ condition_code: number
553
+ condition_code_name: string | null
554
+ amount: string
555
+ } | {
556
+ type: "nft"
557
+ principal: string
558
+ asset_identifier: string
559
+ asset_value: unknown
560
+ condition_code: number
561
+ condition_code_name: string | null
562
+ };
563
+ /** Full transaction document: columnar fields plus `raw_tx`-decoded enrichment.
564
+ * Payload sub-objects are present only for the matching `tx_type`; enrichment
565
+ * fields are null when `raw_tx` isn't decodable (e.g. burnchain ops). */
566
+ type IndexTransaction = {
567
+ cursor: string
568
+ tx_id: string
569
+ block_height: number
570
+ block_time?: string | null
571
+ tx_index: number
572
+ tx_type: string
573
+ sender: string
574
+ status: string
575
+ fee: string | null
576
+ nonce: string | null
577
+ sponsored: boolean | null
578
+ anchor_mode: string | null
579
+ post_condition_mode: string | null
580
+ post_conditions: IndexPostCondition[]
581
+ contract_call?: {
582
+ contract_id: string
583
+ function_name: string
584
+ function_args: unknown[]
585
+ result: unknown
586
+ result_hex: string | null
587
+ }
588
+ token_transfer?: {
589
+ recipient: string
590
+ amount: string
591
+ memo: string
592
+ }
593
+ smart_contract?: {
594
+ contract_id: string | null
595
+ clarity_version: number | null
596
+ }
597
+ coinbase?: {
598
+ alt_recipient: string | null
599
+ }
600
+ tenure_change?: {
601
+ cause: number
602
+ }
603
+ };
604
+ type TransactionsEnvelope = {
605
+ transactions: IndexTransaction[]
606
+ next_cursor: string | null
607
+ tip: IndexTip
608
+ reorgs: never[]
609
+ };
610
+ type TransactionEnvelope = {
611
+ transaction: IndexTransaction
612
+ tip: IndexTip
613
+ };
614
+ type TransactionsListParams = {
615
+ cursor?: string | null
616
+ fromCursor?: string | null
617
+ limit?: number
618
+ type?: string
619
+ sender?: string
620
+ contractId?: string
621
+ fromHeight?: number
622
+ toHeight?: number
623
+ };
624
+ type TransactionsWalkParams = Omit<TransactionsListParams, "limit"> & {
625
+ batchSize?: number
626
+ signal?: AbortSignal
627
+ };
628
+ /** A decoded PoX-4 stacking action (one per stacking contract call). */
629
+ type IndexStackingAction = {
630
+ cursor: string
631
+ block_height: number
632
+ block_time?: string | null
633
+ burn_block_height: number
634
+ tx_id: string
635
+ tx_index: number
636
+ function_name: string
637
+ caller: string
638
+ stacker: string | null
639
+ delegate_to: string | null
640
+ amount_ustx: string | null
641
+ lock_period: number | null
642
+ pox_addr: {
643
+ version: number | null
644
+ hashbytes: string | null
645
+ btc: string | null
646
+ }
647
+ start_cycle: number | null
648
+ end_cycle: number | null
649
+ reward_cycle: number | null
650
+ signer_key: string | null
651
+ result_ok: boolean
652
+ };
653
+ type StackingEnvelope = {
654
+ stacking: IndexStackingAction[]
655
+ next_cursor: string | null
656
+ tip: IndexTip
657
+ /** Present only when the PoX-4 decoder is disabled, explaining an empty feed. */
658
+ notes?: string
659
+ };
660
+ type StackingListParams = {
661
+ cursor?: string | null
662
+ fromCursor?: string | null
663
+ limit?: number
664
+ functionName?: string
665
+ stacker?: string
666
+ caller?: string
667
+ fromHeight?: number
668
+ toHeight?: number
669
+ };
670
+ type StackingWalkParams = Omit<StackingListParams, "limit"> & {
671
+ batchSize?: number
672
+ signal?: AbortSignal
673
+ };
674
+ /** A pending (unconfirmed) transaction. Like a transaction document but
675
+ * pre-chain — no block_height/tx_index/result/events — with `received_at` and
676
+ * a sequence cursor instead of a block position. */
677
+ type IndexMempoolTransaction = {
678
+ cursor: string
679
+ tx_id: string
680
+ tx_type: string
681
+ sender: string
682
+ received_at?: string | null
683
+ fee: string | null
684
+ nonce: string | null
685
+ sponsored: boolean | null
686
+ anchor_mode: string | null
687
+ post_condition_mode: string | null
688
+ post_conditions: IndexPostCondition[]
689
+ contract_call?: {
690
+ contract_id: string
691
+ function_name: string
692
+ function_args: unknown[]
693
+ }
694
+ token_transfer?: {
695
+ recipient: string
696
+ amount: string
697
+ memo: string
698
+ }
699
+ smart_contract?: {
700
+ clarity_version: number | null
701
+ }
702
+ coinbase?: {
703
+ alt_recipient: string | null
704
+ }
705
+ tenure_change?: {
706
+ cause: number
707
+ }
708
+ };
709
+ type MempoolEnvelope = {
710
+ mempool: IndexMempoolTransaction[]
711
+ next_cursor: string | null
712
+ tip: IndexTip
713
+ };
714
+ type MempoolTransactionEnvelope = {
715
+ transaction: IndexMempoolTransaction
716
+ tip: IndexTip
717
+ };
718
+ type MempoolListParams = {
719
+ cursor?: string | null
720
+ fromCursor?: string | null
721
+ limit?: number
722
+ sender?: string
723
+ type?: string
724
+ };
725
+ type MempoolWalkParams = Omit<MempoolListParams, "limit"> & {
726
+ batchSize?: number
727
+ signal?: AbortSignal
728
+ };
483
729
  declare class Index extends BaseClient {
484
730
  constructor(options?: Partial<SecondLayerOptions>);
485
731
  readonly ftTransfers: {
@@ -499,6 +745,38 @@ declare class Index extends BaseClient {
499
745
  list: (params?: ContractCallsListParams) => Promise<ContractCallsEnvelope>
500
746
  walk: (params?: ContractCallsWalkParams) => AsyncIterable<IndexContractCall>
501
747
  };
748
+ /** Canonical block-hash map — sync only the current canonical chain. */
749
+ readonly canonical: {
750
+ list: (params?: CanonicalListParams) => Promise<CanonicalEnvelope>
751
+ walk: (params?: CanonicalWalkParams) => AsyncIterable<IndexCanonicalBlock>
752
+ };
753
+ /** Canonical blocks: paginated `list`/`walk`, plus `get` by height or hash
754
+ * (resolves to null on 404). */
755
+ readonly blocks: {
756
+ list: (params?: BlocksListParams) => Promise<BlocksEnvelope>
757
+ walk: (params?: BlocksWalkParams) => AsyncIterable<IndexBlock>
758
+ get: (ref: string | number) => Promise<BlockEnvelope | null>
759
+ };
760
+ /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
761
+ * (resolves to null on 404). */
762
+ readonly transactions: {
763
+ list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
764
+ walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
765
+ get: (txId: string) => Promise<TransactionEnvelope | null>
766
+ };
767
+ /** Decoded PoX-4 stacking actions. Empty (with a `notes` hint) when the
768
+ * platform's PoX-4 decoder is disabled. */
769
+ readonly stacking: {
770
+ list: (params?: StackingListParams) => Promise<StackingEnvelope>
771
+ walk: (params?: StackingWalkParams) => AsyncIterable<IndexStackingAction>
772
+ };
773
+ /** Pending (unconfirmed) transactions: paginated `list`/`walk`, plus `get` by
774
+ * tx_id (resolves to null when the tx has confirmed or dropped). */
775
+ readonly mempool: {
776
+ list: (params?: MempoolListParams) => Promise<MempoolEnvelope>
777
+ walk: (params?: MempoolWalkParams) => AsyncIterable<IndexMempoolTransaction>
778
+ get: (txId: string) => Promise<MempoolTransactionEnvelope | null>
779
+ };
502
780
  private listFtTransfers;
503
781
  private listNftTransfers;
504
782
  private walkFtTransfers;
@@ -507,6 +785,19 @@ declare class Index extends BaseClient {
507
785
  private walkEvents;
508
786
  private listContractCalls;
509
787
  private walkContractCalls;
788
+ private listCanonical;
789
+ private walkCanonical;
790
+ private listBlocks;
791
+ private getBlock;
792
+ private walkBlocks;
793
+ private listTransactions;
794
+ private getTransaction;
795
+ private walkTransactions;
796
+ private listStacking;
797
+ private walkStacking;
798
+ private listMempool;
799
+ private getMempoolTx;
800
+ private walkMempool;
510
801
  }
511
802
  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"];
512
803
  type StreamsEventType = (typeof STREAMS_EVENT_TYPES)[number];
@@ -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
@@ -1187,5 +1412,5 @@ export {
1187
1412
  Subgraphs
1188
1413
  };
1189
1414
 
1190
- //# debugId=9C60733D992A531964756E2164756E21
1415
+ //# debugId=7E918A66EC7A1E1864756E2164756E21
1191
1416
  //# sourceMappingURL=index.js.map