@secondlayer/sdk 6.2.0 → 6.3.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,197 @@ 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
+ };
483
674
  declare class Index extends BaseClient {
484
675
  constructor(options?: Partial<SecondLayerOptions>);
485
676
  readonly ftTransfers: {
@@ -499,6 +690,31 @@ declare class Index extends BaseClient {
499
690
  list: (params?: ContractCallsListParams) => Promise<ContractCallsEnvelope>
500
691
  walk: (params?: ContractCallsWalkParams) => AsyncIterable<IndexContractCall>
501
692
  };
693
+ /** Canonical block-hash map — sync only the current canonical chain. */
694
+ readonly canonical: {
695
+ list: (params?: CanonicalListParams) => Promise<CanonicalEnvelope>
696
+ walk: (params?: CanonicalWalkParams) => AsyncIterable<IndexCanonicalBlock>
697
+ };
698
+ /** Canonical blocks: paginated `list`/`walk`, plus `get` by height or hash
699
+ * (resolves to null on 404). */
700
+ readonly blocks: {
701
+ list: (params?: BlocksListParams) => Promise<BlocksEnvelope>
702
+ walk: (params?: BlocksWalkParams) => AsyncIterable<IndexBlock>
703
+ get: (ref: string | number) => Promise<BlockEnvelope | null>
704
+ };
705
+ /** Full transaction documents: paginated `list`/`walk`, plus `get` by tx_id
706
+ * (resolves to null on 404). */
707
+ readonly transactions: {
708
+ list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
709
+ walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
710
+ get: (txId: string) => Promise<TransactionEnvelope | null>
711
+ };
712
+ /** Decoded PoX-4 stacking actions. Empty (with a `notes` hint) when the
713
+ * platform's PoX-4 decoder is disabled. */
714
+ readonly stacking: {
715
+ list: (params?: StackingListParams) => Promise<StackingEnvelope>
716
+ walk: (params?: StackingWalkParams) => AsyncIterable<IndexStackingAction>
717
+ };
502
718
  private listFtTransfers;
503
719
  private listNftTransfers;
504
720
  private walkFtTransfers;
@@ -507,6 +723,16 @@ declare class Index extends BaseClient {
507
723
  private walkEvents;
508
724
  private listContractCalls;
509
725
  private walkContractCalls;
726
+ private listCanonical;
727
+ private walkCanonical;
728
+ private listBlocks;
729
+ private getBlock;
730
+ private walkBlocks;
731
+ private listTransactions;
732
+ private getTransaction;
733
+ private walkTransactions;
734
+ private listStacking;
735
+ private walkStacking;
510
736
  }
511
737
  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
738
  type StreamsEventType = (typeof STREAMS_EVENT_TYPES)[number];
@@ -489,6 +489,24 @@ 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
+ };
492
510
  async listFtTransfers(params = {}) {
493
511
  return this.request("GET", `/v1/index/ft-transfers${buildQuery({
494
512
  cursor: params.cursor,
@@ -640,6 +658,166 @@ class Index extends BaseClient {
640
658
  firstPage = false;
641
659
  }
642
660
  }
661
+ async listCanonical(params = {}) {
662
+ return this.request("GET", `/v1/index/canonical${buildQuery({
663
+ cursor: params.cursor,
664
+ from_cursor: params.fromCursor,
665
+ limit: params.limit,
666
+ from_height: params.fromHeight,
667
+ to_height: params.toHeight
668
+ })}`);
669
+ }
670
+ async* walkCanonical(params = {}) {
671
+ const batchSize = params.batchSize ?? 200;
672
+ let cursor = params.cursor ?? params.fromCursor ?? null;
673
+ let firstPage = true;
674
+ while (!params.signal?.aborted) {
675
+ const envelope = await this.listCanonical({
676
+ ...params,
677
+ limit: batchSize,
678
+ cursor: firstPage ? params.cursor : cursor,
679
+ fromCursor: firstPage ? params.fromCursor : undefined,
680
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
681
+ });
682
+ for (const block of envelope.canonical) {
683
+ if (params.signal?.aborted)
684
+ return;
685
+ yield block;
686
+ }
687
+ const nextCursor = envelope.next_cursor;
688
+ if (!nextCursor || nextCursor === cursor || envelope.canonical.length < batchSize) {
689
+ return;
690
+ }
691
+ cursor = nextCursor;
692
+ firstPage = false;
693
+ }
694
+ }
695
+ async listBlocks(params = {}) {
696
+ return this.request("GET", `/v1/index/blocks${buildQuery({
697
+ cursor: params.cursor,
698
+ from_cursor: params.fromCursor,
699
+ limit: params.limit,
700
+ from_height: params.fromHeight,
701
+ to_height: params.toHeight
702
+ })}`);
703
+ }
704
+ async getBlock(ref) {
705
+ try {
706
+ return await this.request("GET", `/v1/index/blocks/${encodeURIComponent(String(ref))}`);
707
+ } catch (err) {
708
+ if (err instanceof ApiError && err.status === 404)
709
+ return null;
710
+ throw err;
711
+ }
712
+ }
713
+ async* walkBlocks(params = {}) {
714
+ const batchSize = params.batchSize ?? 200;
715
+ let cursor = params.cursor ?? params.fromCursor ?? null;
716
+ let firstPage = true;
717
+ while (!params.signal?.aborted) {
718
+ const envelope = await this.listBlocks({
719
+ ...params,
720
+ limit: batchSize,
721
+ cursor: firstPage ? params.cursor : cursor,
722
+ fromCursor: firstPage ? params.fromCursor : undefined,
723
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
724
+ });
725
+ for (const block of envelope.blocks) {
726
+ if (params.signal?.aborted)
727
+ return;
728
+ yield block;
729
+ }
730
+ const nextCursor = envelope.next_cursor;
731
+ if (!nextCursor || nextCursor === cursor || envelope.blocks.length < batchSize) {
732
+ return;
733
+ }
734
+ cursor = nextCursor;
735
+ firstPage = false;
736
+ }
737
+ }
738
+ async listTransactions(params = {}) {
739
+ return this.request("GET", `/v1/index/transactions${buildQuery({
740
+ cursor: params.cursor,
741
+ from_cursor: params.fromCursor,
742
+ limit: params.limit,
743
+ type: params.type,
744
+ sender: params.sender,
745
+ contract_id: params.contractId,
746
+ from_height: params.fromHeight,
747
+ to_height: params.toHeight
748
+ })}`);
749
+ }
750
+ async getTransaction(txId) {
751
+ try {
752
+ return await this.request("GET", `/v1/index/transactions/${encodeURIComponent(txId)}`);
753
+ } catch (err) {
754
+ if (err instanceof ApiError && err.status === 404)
755
+ return null;
756
+ throw err;
757
+ }
758
+ }
759
+ async* walkTransactions(params = {}) {
760
+ const batchSize = params.batchSize ?? 200;
761
+ let cursor = params.cursor ?? params.fromCursor ?? null;
762
+ let firstPage = true;
763
+ while (!params.signal?.aborted) {
764
+ const envelope = await this.listTransactions({
765
+ ...params,
766
+ limit: batchSize,
767
+ cursor: firstPage ? params.cursor : cursor,
768
+ fromCursor: firstPage ? params.fromCursor : undefined,
769
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
770
+ });
771
+ for (const tx of envelope.transactions) {
772
+ if (params.signal?.aborted)
773
+ return;
774
+ yield tx;
775
+ }
776
+ const nextCursor = envelope.next_cursor;
777
+ if (!nextCursor || nextCursor === cursor || envelope.transactions.length < batchSize) {
778
+ return;
779
+ }
780
+ cursor = nextCursor;
781
+ firstPage = false;
782
+ }
783
+ }
784
+ async listStacking(params = {}) {
785
+ return this.request("GET", `/v1/index/stacking${buildQuery({
786
+ cursor: params.cursor,
787
+ from_cursor: params.fromCursor,
788
+ limit: params.limit,
789
+ function_name: params.functionName,
790
+ stacker: params.stacker,
791
+ caller: params.caller,
792
+ from_height: params.fromHeight,
793
+ to_height: params.toHeight
794
+ })}`);
795
+ }
796
+ async* walkStacking(params = {}) {
797
+ const batchSize = params.batchSize ?? 200;
798
+ let cursor = params.cursor ?? params.fromCursor ?? null;
799
+ let firstPage = true;
800
+ while (!params.signal?.aborted) {
801
+ const envelope = await this.listStacking({
802
+ ...params,
803
+ limit: batchSize,
804
+ cursor: firstPage ? params.cursor : cursor,
805
+ fromCursor: firstPage ? params.fromCursor : undefined,
806
+ fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
807
+ });
808
+ for (const action of envelope.stacking) {
809
+ if (params.signal?.aborted)
810
+ return;
811
+ yield action;
812
+ }
813
+ const nextCursor = envelope.next_cursor;
814
+ if (!nextCursor || nextCursor === cursor || envelope.stacking.length < batchSize) {
815
+ return;
816
+ }
817
+ cursor = nextCursor;
818
+ firstPage = false;
819
+ }
820
+ }
643
821
  }
644
822
 
645
823
  // src/streams/client.ts
@@ -1187,5 +1365,5 @@ export {
1187
1365
  Subgraphs
1188
1366
  };
1189
1367
 
1190
- //# debugId=9C60733D992A531964756E2164756E21
1368
+ //# debugId=FB43A1FE14236F0664756E2164756E21
1191
1369
  //# sourceMappingURL=index.js.map