@fairmint/canton-node-sdk
Version:
Canton Node SDK
84 lines • 3.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetActiveContracts = void 0;
const core_1 = require("../../../../../core");
const operations_1 = require("../../../schemas/operations");
const endpoint = '/v2/state/active-contracts';
exports.GetActiveContracts = (0, core_1.createApiOperation)({
paramsSchema: operations_1.GetActiveContractsParamsSchema,
method: 'POST',
buildUrl: (params, apiUrl) => {
const baseUrl = `${apiUrl}${endpoint}`;
const queryParams = new URLSearchParams();
if (params.limit !== undefined) {
queryParams.append('limit', params.limit.toString());
}
if (params.streamIdleTimeoutMs !== undefined) {
queryParams.append('stream_idle_timeout_ms', params.streamIdleTimeoutMs.toString());
}
const queryString = queryParams.toString();
return queryString ? `${baseUrl}?${queryString}` : baseUrl;
},
buildRequestData: async (params, client) => {
const requestVerbose = params.verbose === undefined ? true : params.verbose;
// Determine activeAtOffset (default to ledger end if not specified)
let activeAtOffset = params.activeAtOffset;
if (activeAtOffset === undefined) {
const ledgerClient = client;
const ledgerEnd = await ledgerClient.getLedgerEnd({});
activeAtOffset = ledgerEnd.offset;
}
// Build filter structure based on parties and template IDs
let filter = undefined;
if (params.parties && params.parties.length > 0) {
const uniqueParties = Array.from(new Set(params.parties));
const filtersByParty = {};
for (const party of uniqueParties) {
let partyFilter = {};
if (params.templateIds && params.templateIds.length > 0) {
// Create template filters for this party
const cumulative = params.templateIds.map(templateId => ({
identifierFilter: {
TemplateFilter: {
value: {
templateId,
includeCreatedEventBlob: false
}
}
}
}));
partyFilter = { cumulative };
}
else {
// No template filters specified, use empty filter (wildcard)
partyFilter = {};
}
filtersByParty[party] = partyFilter;
}
filter = { filtersByParty };
}
else if (params.templateIds && params.templateIds.length > 0) {
// Template filters for any party
const cumulative = params.templateIds.map(templateId => ({
identifierFilter: {
TemplateFilter: {
value: {
templateId,
includeCreatedEventBlob: false
}
}
}
}));
filter = {
filtersForAnyParty: { cumulative }
};
}
// Build and return the request body explicitly
return {
filter,
verbose: requestVerbose,
activeAtOffset,
};
},
});
//# sourceMappingURL=get-active-contracts.js.map