@fairmint/canton-node-sdk
Version:
Canton Node SDK
86 lines • 3.67 kB
TypeScript
import { z } from 'zod';
import type { LedgerJsonApiClient } from '../../../LedgerJsonApiClient.generated';
import { type JsCantonErrorSchema, type WsCantonErrorSchema } from '../../../schemas/api/errors';
import { type JsUpdateSchema, type WsUpdateSchema } from '../../../schemas/api/updates';
/**
* The `TransactionShape` enum defines the event shape for `Transaction`s and can have two different flavors AcsDelta
* and LedgerEffects.
*
* ```protobuf
* enum TransactionShape {
* TRANSACTION_SHAPE_ACS_DELTA = 1;
* TRANSACTION_SHAPE_LEDGER_EFFECTS = 2;
* }
* ```
*
* - AcsDelta
*
* The transaction shape that is sufficient to maintain an accurate ACS view. This translates to create and archive
* events. The field witness_parties in events are populated as stakeholders, transaction filter will apply
* accordingly.
* - LedgerEffects
*
* The transaction shape that allows maintaining an ACS and also conveys detailed information about all exercises. This
* translates to create, consuming exercise and non-consuming exercise. The field witness_parties in events are
* populated as cumulative informees, transaction filter will apply accordingly.
*/
export declare enum TransactionShape {
TRANSACTION_SHAPE_ACS_DELTA = "TRANSACTION_SHAPE_ACS_DELTA",
TRANSACTION_SHAPE_LEDGER_EFFECTS = "TRANSACTION_SHAPE_LEDGER_EFFECTS"
}
declare const SubscribeToUpdatesParamsSchema: z.ZodObject<{
parties: z.ZodOptional<z.ZodArray<z.ZodString>>;
templateIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
includeCreatedEventBlob: z.ZodOptional<z.ZodBoolean>;
beginExclusive: z.ZodOptional<z.ZodNumber>;
endInclusive: z.ZodOptional<z.ZodNumber>;
includeReassignments: z.ZodOptional<z.ZodBoolean>;
includeTopologyEvents: z.ZodOptional<z.ZodBoolean>;
transactionShape: z.ZodOptional<z.ZodEnum<typeof TransactionShape>>;
}, z.core.$strip>;
export type SubscribeToUpdatesParams = z.infer<typeof SubscribeToUpdatesParamsSchema> & {
/** Optional per-message callback to consume updates as they arrive. */
onMessage?: (message: UpdatesWsMessage) => void;
};
export type UpdatesWsMessage = {
update: z.infer<typeof JsUpdateSchema>;
} | {
update: z.infer<typeof WsUpdateSchema>;
} | z.infer<typeof JsCantonErrorSchema> | z.infer<typeof WsCantonErrorSchema>;
/**
* Subscribes to ledger updates via WebSocket connection.
*
* Supports two modes of operation:
*
* 1. **Bounded subscription**: Specify both `beginExclusive` and `endInclusive` to fetch a specific range of historical
* transactions. The connection closes after reaching `endInclusive`.
* 2. **Persistent streaming**: Specify only `beginExclusive` (or omit both) to create a long-lived WebSocket connection
* that streams real-time updates indefinitely. The connection remains open until manually closed via the returned
* subscription object or an error occurs.
*
* @example
* ```typescript
* // Bounded subscription (historical data)
* await client.subscribeToUpdates({
* beginExclusive: 1000,
* endInclusive: 2000,
* parties: ['party1'],
* onMessage: (msg) => console.log(msg)
* });
*
* // Persistent streaming (real-time updates)
* await client.subscribeToUpdates({
* beginExclusive: 2000,
* // endInclusive omitted - connection stays open
* parties: ['party1'],
* onMessage: (msg) => console.log(msg)
* });
* ```;
*/
export declare class SubscribeToUpdates {
private readonly client;
constructor(client: LedgerJsonApiClient);
connect(params: SubscribeToUpdatesParams): Promise<void>;
}
export {};
//# sourceMappingURL=subscribe-to-updates.d.ts.map