@canton-network/core-ledger-client
Advanced tools
+1
-724
@@ -6,3 +6,2 @@ 'use strict'; | ||
| var coreLedgerProto = require('@canton-network/core-ledger-proto'); | ||
| var typescriptLruCache = require('typescript-lru-cache'); | ||
@@ -152,478 +151,2 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
| // src/acs/acs-container.ts | ||
| var ACS_UPDATE_CONFIG = { | ||
| // How many events do we accumulate before we prune (compact) the ACS history - set to 0 to enable to compact all events, which is more efficient as long as application always ask for increasing (or equal) offsets | ||
| maxEventsBeforePrune: 150, | ||
| // When we compact the ACS history, we keep all events within this offset delta of the last seen update offset - set 0 to allow to compact everything | ||
| safeOffsetDeltaForPrune: 200, | ||
| // How many updates do we fetch at once when fetching updates - if there are more updates, we will fetch again until we have caught up (returned data is always complete to the requested endInclusive offset - even if that means multiple fetches) | ||
| maxUpdatesToFetch: 100, | ||
| // Timeout for receiving the first element from the WebSocket stream when reading the ACS - if this timeout is reached before the first element is returned, we fall back to HTTP | ||
| // lower values will make the UI more responsive in case of problems, but may lead to unnecessary fallbacks | ||
| wsTimeoutBeforeFirstElement: 1e4 | ||
| }; | ||
| if (typeof window !== "undefined") { | ||
| window["ACS_UPDATE_CONFIG"] = ACS_UPDATE_CONFIG; | ||
| } | ||
| var ACSContainer = class _ACSContainer { | ||
| constructor(orginalContainer = null, settings = { includeCreatedEventBlob: true }) { | ||
| __publicField(this, "acsSet", null); | ||
| __publicField(this, "settings"); | ||
| this.acsSet = orginalContainer ? orginalContainer.acsSet : null; | ||
| this.settings = settings; | ||
| } | ||
| async update(offset, key, api, wsSupport) { | ||
| if (this.acsSet === null) { | ||
| const acs = await this.readACS(offset, key, api, wsSupport); | ||
| this.acsSet = acs; | ||
| return _ACSContainer.calculateAt(acs, offset); | ||
| } | ||
| if (this.acsSet.acsOffset > offset) { | ||
| this.acsSet = null; | ||
| return this.update(offset, key, api); | ||
| } | ||
| if (this.acsSet.updates.length >= ACS_UPDATE_CONFIG.maxEventsBeforePrune) { | ||
| this.acsSet = await _ACSContainer.compact(this.acsSet); | ||
| } | ||
| const updates = await _ACSContainer.updateContracts( | ||
| this.acsSet.lastUpdateOffset, | ||
| offset, | ||
| this.createEventFormat(key), | ||
| api | ||
| ); | ||
| const [newEvents, newOffset] = _ACSContainer.extractEvents( | ||
| this.acsSet.lastUpdateOffset, | ||
| updates | ||
| ); | ||
| if (newOffset > this.acsSet.lastUpdateOffset) { | ||
| this.acsSet = { | ||
| ...this.acsSet, | ||
| lastUpdateOffset: newOffset, | ||
| updates: this.acsSet.updates.concat(newEvents) | ||
| }; | ||
| } | ||
| if (updates.length >= ACS_UPDATE_CONFIG.maxUpdatesToFetch) { | ||
| return this.update(offset, key, api); | ||
| } | ||
| this.acsSet = { | ||
| ...this.acsSet, | ||
| lastUpdateOffset: offset | ||
| // we have caught up | ||
| }; | ||
| return _ACSContainer.calculateAt(this.acsSet, offset); | ||
| } | ||
| static calculateAt(acs, offset) { | ||
| if (acs.acsOffset > offset) { | ||
| return Promise.reject( | ||
| Error( | ||
| // This should never happen as we check this before calling calculateAt | ||
| `Cannot calculate ACS at offset ${offset} when initial ACS is at ${acs.acsOffset}` | ||
| ) | ||
| ); | ||
| } | ||
| const addedContracts = []; | ||
| const removedContractIds = /* @__PURE__ */ new Set(); | ||
| acs.updates.forEach((update) => { | ||
| if (update.offset <= offset) { | ||
| if (update.created) { | ||
| const createdEv = update.created; | ||
| const activeContract = { | ||
| workflowId: update.workflowId ?? "", | ||
| contractEntry: { | ||
| JsActiveContract: { | ||
| createdEvent: createdEv, | ||
| synchronizerId: update.synchronizerId ?? "", | ||
| reassignmentCounter: 0 | ||
| } | ||
| } | ||
| }; | ||
| addedContracts.push(activeContract); | ||
| } else if (update.archivedContractId) { | ||
| removedContractIds.add(update.archivedContractId); | ||
| } | ||
| } | ||
| }); | ||
| const createdContracts = acs.initialAcs.concat(addedContracts); | ||
| const result = createdContracts.filter(({ contractEntry }) => { | ||
| if (!contractEntry) { | ||
| return false; | ||
| } | ||
| const id = "JsActiveContract" in contractEntry ? contractEntry.JsActiveContract?.createdEvent?.contractId ?? "" : ""; | ||
| return !removedContractIds.has(id); | ||
| }); | ||
| return Promise.resolve(result); | ||
| } | ||
| static extractEvents(fromOffset, updates) { | ||
| const newEvents = []; | ||
| let newOffset = fromOffset; | ||
| updates.forEach((update) => { | ||
| if (!update || !update.update) { | ||
| return; | ||
| } | ||
| if ("Transaction" in update.update) { | ||
| const transaction = update.update.Transaction; | ||
| const trOffset = transaction?.value?.offset; | ||
| if (trOffset && trOffset > newOffset) { | ||
| const events = transaction?.value?.events ?? []; | ||
| events.forEach((event) => { | ||
| if (!event) { | ||
| return; | ||
| } | ||
| if ("CreatedEvent" in event) { | ||
| const acUpdate = { | ||
| created: event.CreatedEvent, | ||
| archivedContractId: null, | ||
| offset: trOffset, | ||
| workflowId: transaction?.value?.workflowId ?? null, | ||
| synchronizerId: transaction?.value?.synchronizerId ?? null | ||
| }; | ||
| newEvents.push(acUpdate); | ||
| newOffset = trOffset; | ||
| } else if ("ArchivedEvent" in event) { | ||
| const archivedEvent = event.ArchivedEvent; | ||
| const acUpdate = { | ||
| created: null, | ||
| archivedContractId: archivedEvent?.contractId ?? null, | ||
| offset: trOffset, | ||
| workflowId: transaction?.value?.workflowId ?? null, | ||
| synchronizerId: transaction?.value?.synchronizerId ?? null | ||
| }; | ||
| newEvents.push(acUpdate); | ||
| newOffset = trOffset; | ||
| } | ||
| }); | ||
| } | ||
| } else if ("OffsetCheckpoint" in update.update) { | ||
| const checkpoint = update.update.OffsetCheckpoint; | ||
| const offset = checkpoint?.value?.offset; | ||
| if (offset) { | ||
| newOffset = offset; | ||
| } | ||
| } else { | ||
| console.log( | ||
| `ACS Update got unknown update type: ${JSON.stringify(update.update)}` | ||
| ); | ||
| } | ||
| }); | ||
| return [newEvents, newOffset]; | ||
| } | ||
| static async updateContracts(startOffset, endOffset, eventFormat, api) { | ||
| const request = { | ||
| beginExclusive: startOffset, | ||
| endInclusive: endOffset, | ||
| updateFormat: { | ||
| includeTransactions: { | ||
| eventFormat, | ||
| transactionShape: "TRANSACTION_SHAPE_ACS_DELTA" | ||
| } | ||
| }, | ||
| verbose: false | ||
| }; | ||
| const params = { | ||
| query: { | ||
| limit: ACS_UPDATE_CONFIG.maxUpdatesToFetch, | ||
| stream_idle_timeout_ms: 1e3 | ||
| } | ||
| }; | ||
| return api.postWithRetry( | ||
| "/v2/updates/flats", | ||
| request, | ||
| defaultRetryableOptions, | ||
| params | ||
| ); | ||
| } | ||
| static async compact(acs) { | ||
| const newAcsOffset = Math.max( | ||
| acs.acsOffset, | ||
| acs.lastUpdateOffset - ACS_UPDATE_CONFIG.safeOffsetDeltaForPrune | ||
| ); | ||
| if (newAcsOffset > acs.acsOffset) { | ||
| const responses = await _ACSContainer.calculateAt(acs, newAcsOffset); | ||
| return { | ||
| acsOffset: newAcsOffset, | ||
| initialAcs: responses, | ||
| lastUpdateOffset: acs.lastUpdateOffset, | ||
| updates: acs.updates.filter( | ||
| (update) => update.offset > newAcsOffset | ||
| ) | ||
| }; | ||
| } | ||
| return acs; | ||
| } | ||
| async readACS(offset, key, api, wsSupport) { | ||
| if (wsSupport && wsSupport.enabled()) { | ||
| return this.readACSUsingWs(offset, key, wsSupport).catch(() => { | ||
| console.log("Falling back to HTTP for ACS read"); | ||
| return this.readHttpACS(offset, key, api); | ||
| }); | ||
| } | ||
| return this.readHttpACS(offset, key, api); | ||
| } | ||
| async readHttpACS(offset, key, api) { | ||
| const format = this.createEventFormat(key); | ||
| const acs = await api.postWithRetry( | ||
| "/v2/state/active-contracts", | ||
| { | ||
| activeAtOffset: offset, | ||
| verbose: false, | ||
| eventFormat: format | ||
| }, | ||
| defaultRetryableOptions | ||
| ); | ||
| return { | ||
| acsOffset: offset, | ||
| initialAcs: acs, | ||
| lastUpdateOffset: offset, | ||
| updates: [] | ||
| }; | ||
| } | ||
| readACSUsingWs(offset, key, wsSupport) { | ||
| const wsACSURL = `${wsSupport.baseUrl}/v2/state/active-contracts`; | ||
| const format = this.createEventFormat(key); | ||
| const request = { | ||
| activeAtOffset: offset, | ||
| verbose: false, | ||
| eventFormat: format | ||
| }; | ||
| return new Promise((resolve, reject) => { | ||
| const ws = new WebSocket(wsACSURL, wsSupport.extractProtocols()); | ||
| const results = []; | ||
| let finished = false; | ||
| let error = null; | ||
| setTimeout(() => { | ||
| if (!finished && !error && results.length === 0) { | ||
| error = Error( | ||
| `No data received from WebSocket ${wsACSURL} within ${ACS_UPDATE_CONFIG.wsTimeoutBeforeFirstElement}ms` | ||
| ); | ||
| wsSupport.reportError(error); | ||
| reject(error); | ||
| ws.close(); | ||
| } | ||
| }, ACS_UPDATE_CONFIG.wsTimeoutBeforeFirstElement); | ||
| ws.onopen = () => { | ||
| ws.send(JSON.stringify(request)); | ||
| }; | ||
| ws.onmessage = (event) => { | ||
| try { | ||
| const data = JSON.parse( | ||
| event.data | ||
| ); | ||
| results.push(data); | ||
| } catch (err) { | ||
| console.error("Invalid JSON:", err); | ||
| } | ||
| }; | ||
| ws.onerror = () => { | ||
| error = new Error("WebSocket error"); | ||
| wsSupport.reportError(error); | ||
| reject(error); | ||
| }; | ||
| ws.onclose = () => { | ||
| finished = true; | ||
| if (!error) { | ||
| wsSupport.reportSuccess(); | ||
| resolve({ | ||
| acsOffset: offset, | ||
| initialAcs: results, | ||
| lastUpdateOffset: offset, | ||
| updates: [] | ||
| }); | ||
| } | ||
| }; | ||
| }); | ||
| } | ||
| createInterfaceFilter(interfaceId) { | ||
| return { | ||
| cumulative: [ | ||
| { | ||
| identifierFilter: { | ||
| InterfaceFilter: { | ||
| value: { | ||
| interfaceId, | ||
| includeInterfaceView: true, | ||
| includeCreatedEventBlob: this.settings.includeCreatedEventBlob | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| createTemplateFilter(templateId) { | ||
| return { | ||
| cumulative: [ | ||
| { | ||
| identifierFilter: { | ||
| TemplateFilter: { | ||
| value: { | ||
| templateId, | ||
| includeCreatedEventBlob: this.settings.includeCreatedEventBlob | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| createEventFormat(key) { | ||
| const cumulativeFilter = key.templateId ? this.createTemplateFilter(key.templateId) : this.createInterfaceFilter(key.interfaceId ?? ""); | ||
| if (key.party) { | ||
| if (!key.interfaceId && !key.templateId) { | ||
| return { | ||
| filtersByParty: { | ||
| [key.party]: {} | ||
| }, | ||
| verbose: false | ||
| }; | ||
| } | ||
| return { | ||
| filtersByParty: { | ||
| [key.party]: cumulativeFilter | ||
| }, | ||
| verbose: false | ||
| }; | ||
| } | ||
| return { | ||
| filtersForAnyParty: cumulativeFilter, | ||
| verbose: false | ||
| }; | ||
| } | ||
| }; | ||
| var DEFAULT_MAX_CACHE_SIZE = 100; | ||
| var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3; | ||
| var SharedACSCache = new typescriptLruCache.LRUCache({ | ||
| maxSize: DEFAULT_MAX_CACHE_SIZE, | ||
| entryExpirationTimeInMS: DEFAULT_ENTRY_EXPIRATION_TIME, | ||
| onEntryEvicted: (entry) => { | ||
| console.debug(`${entry} has expired`); | ||
| SharedACSCacheStats.evictions++; | ||
| } | ||
| }); | ||
| var SharedACSCacheStats = { | ||
| hits: 0, | ||
| misses: 0, | ||
| evictions: 0, | ||
| totalLookupTime: 0, | ||
| totalCacheServeTime: 0 | ||
| }; | ||
| // src/acs/acs-helper.ts | ||
| var ACSHelper = class _ACSHelper { | ||
| constructor(apiInstance, _logger, options, sharedCache) { | ||
| __publicField(this, "contractsSet"); | ||
| __publicField(this, "apiInstance"); | ||
| __publicField(this, "wsSupport"); | ||
| __publicField(this, "logger"); | ||
| __publicField(this, "includeCreatedEventBlob"); | ||
| __publicField(this, "totalCacheServeTime", 0); | ||
| this.contractsSet = sharedCache ?? new typescriptLruCache.LRUCache({ | ||
| maxSize: options?.maxCacheSize ?? DEFAULT_MAX_CACHE_SIZE, | ||
| entryExpirationTimeInMS: options?.entryExpirationTime ?? DEFAULT_ENTRY_EXPIRATION_TIME, | ||
| // 10 minutes | ||
| onEntryEvicted: (entry) => { | ||
| this.logger.debug( | ||
| `entry ${entry.key} isExpired = ${entry.isExpired}. evicting entry.` | ||
| ); | ||
| SharedACSCacheStats.evictions++; | ||
| } | ||
| }); | ||
| this.apiInstance = apiInstance; | ||
| this.wsSupport = options?.wsSupport; | ||
| this.logger = _logger.child({ component: "ACSHelper" }); | ||
| this.includeCreatedEventBlob = options?.includeCreatedEventBlob ?? true; | ||
| } | ||
| getCacheStats() { | ||
| const totalCalls = SharedACSCacheStats.hits + SharedACSCacheStats.misses; | ||
| const hitRate = totalCalls ? SharedACSCacheStats.hits / totalCalls * 100 : 0; | ||
| const avgLookupTime = totalCalls > 0 ? SharedACSCacheStats.totalLookupTime / totalCalls : 0; | ||
| return { | ||
| totalCalls, | ||
| hits: SharedACSCacheStats.hits, | ||
| misses: SharedACSCacheStats.misses, | ||
| evictions: SharedACSCacheStats.evictions, | ||
| cacheSize: this.contractsSet.size, | ||
| hitRate: hitRate.toFixed(2) + "%", | ||
| averageLookupTime: avgLookupTime.toFixed(3) + " ms", | ||
| cacheServeTime: SharedACSCacheStats.totalCacheServeTime.toFixed(3) | ||
| }; | ||
| } | ||
| static createKey(party, templateId, interfaceId) { | ||
| return { party, templateId, interfaceId }; | ||
| } | ||
| static keyToString(key, ledgerBaseUrl) { | ||
| return `${ledgerBaseUrl}_${key.party ? key.party : "ANY"}_T:${key.templateId ?? "()"}_I:${key.interfaceId ?? "()"}`; | ||
| } | ||
| findACSContainer(key) { | ||
| const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href); | ||
| const start = performance.now(); | ||
| const existing = this.contractsSet.get(keyStr); | ||
| const end = performance.now(); | ||
| SharedACSCacheStats.totalLookupTime += end - start; | ||
| if (existing) { | ||
| SharedACSCacheStats.hits++; | ||
| this.logger.debug("cache hit"); | ||
| return existing; | ||
| } | ||
| this.logger.debug("cache miss"); | ||
| SharedACSCacheStats.misses++; | ||
| const newContainer = new ACSContainer(void 0, { | ||
| includeCreatedEventBlob: this.includeCreatedEventBlob | ||
| }); | ||
| this.contractsSet.set(keyStr, newContainer); | ||
| return newContainer; | ||
| } | ||
| async updateSingleKey(offset, key) { | ||
| const start = performance.now(); | ||
| const container = this.findACSContainer(key); | ||
| const result = await container.update( | ||
| offset, | ||
| key, | ||
| this.apiInstance, | ||
| this.wsSupport | ||
| ); | ||
| const end = performance.now(); | ||
| const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href); | ||
| if (this.contractsSet.has(keyStr)) { | ||
| SharedACSCacheStats.totalCacheServeTime += end - start; | ||
| } | ||
| return result; | ||
| } | ||
| async queryAcsByKeys(offset, keys) { | ||
| const result = []; | ||
| for (const key of keys) { | ||
| const contracts = await this.updateSingleKey(offset, key); | ||
| result.push(...contracts); | ||
| } | ||
| return result; | ||
| } | ||
| async activeContractsForTemplates(offset, parties, templateIds) { | ||
| const keys = parties.flatMap( | ||
| (party) => templateIds.map( | ||
| (templateId) => _ACSHelper.createKey(party, templateId, void 0) | ||
| ) | ||
| ); | ||
| return this.queryAcsByKeys(offset, keys); | ||
| } | ||
| async activeContractsForInterfaces(offset, parties, interfaceIds) { | ||
| const keys = parties.flatMap( | ||
| (party) => interfaceIds.map( | ||
| (interfaceId) => _ACSHelper.createKey(party, void 0, interfaceId) | ||
| ) | ||
| ); | ||
| return this.queryAcsByKeys(offset, keys); | ||
| } | ||
| async activeContractsForTemplate(offset, partyFilter, templateId) { | ||
| return this.updateSingleKey( | ||
| offset, | ||
| _ACSHelper.createKey(partyFilter, templateId, void 0) | ||
| ); | ||
| } | ||
| async activeContractsForInterface(offset, partyFilter, interfaceId) { | ||
| return this.updateSingleKey( | ||
| offset, | ||
| _ACSHelper.createKey(partyFilter, void 0, interfaceId) | ||
| ); | ||
| } | ||
| }; | ||
| // src/ledger-client.ts | ||
@@ -636,4 +159,3 @@ var supportedVersions = coreLedgerClientTypes.supportedLedgerApiVersions; | ||
| accessTokenProvider, | ||
| version, | ||
| acsHelperOptions | ||
| version | ||
| }) { | ||
@@ -645,3 +167,2 @@ // privately manage the active connected version and associated client codegen | ||
| __publicField(this, "accessTokenProvider"); | ||
| __publicField(this, "acsHelper"); | ||
| __publicField(this, "logger"); | ||
@@ -673,8 +194,2 @@ __publicField(this, "synchronizerId"); | ||
| this.baseUrl = baseUrl; | ||
| this.acsHelper = new ACSHelper( | ||
| this, | ||
| logger, | ||
| acsHelperOptions, | ||
| SharedACSCache | ||
| ); | ||
| } | ||
@@ -934,195 +449,2 @@ get currentClient() { | ||
| } | ||
| /* | ||
| if limit is provided, this function performs a one-time query. Automatically splits into multiple `/v2/updates` calls with `continueUntilCompletion` on. | ||
| if limit is omitted, results may be served from the ACS cache | ||
| current cache design doesn't support limiting queries because updates/deltas for the acs at offset x will be incorrect | ||
| TODO: expose query mode vs subscribe mode to call queryActiveContracts vs subscribeActiveContracts | ||
| */ | ||
| async activeContracts(options) { | ||
| const { | ||
| offset, | ||
| templateIds, | ||
| parties, | ||
| interfaceIds, | ||
| limit, | ||
| continueUntilCompletion | ||
| } = options; | ||
| if (continueUntilCompletion) { | ||
| const filter2 = this.buildActiveContractFilter(options); | ||
| return await this.fetchActiveContractsUntilComplete( | ||
| filter2, | ||
| limit ?? 200 | ||
| ); | ||
| } | ||
| const hasLimit = typeof limit === "number"; | ||
| if (hasLimit) { | ||
| const filter2 = this.buildActiveContractFilter(options); | ||
| return await this.postWithRetry( | ||
| "/v2/state/active-contracts", | ||
| filter2, | ||
| defaultRetryableOptions, | ||
| { query: { limit: limit.toString() } } | ||
| ); | ||
| } | ||
| this.logger.debug(options, "options for active contracts"); | ||
| const hasParties = Array.isArray(parties) && parties.length > 0; | ||
| if (templateIds?.length && hasParties) { | ||
| return this.acsHelper.activeContractsForTemplates( | ||
| offset, | ||
| parties, | ||
| templateIds | ||
| ); | ||
| } | ||
| if (interfaceIds?.length && hasParties) { | ||
| return this.acsHelper.activeContractsForInterfaces( | ||
| offset, | ||
| parties, | ||
| interfaceIds | ||
| ); | ||
| } | ||
| const filter = this.buildActiveContractFilter(options); | ||
| this.logger.debug("falling back to post request"); | ||
| return await this.postWithRetry( | ||
| "/v2/state/active-contracts", | ||
| filter, | ||
| defaultRetryableOptions | ||
| ); | ||
| } | ||
| /** | ||
| * Fetches active contracts by splitting requests into multiple `/v2/updates` calls. | ||
| * Should only be used when the number of contracts exceeds http-list-max-elements-limit (200 by default). | ||
| * For limits at or below http-list-max-elements-limit, use a single `/v2/state/active-contracts` call instead. | ||
| * @param activeContractsArgs The request parameters for active contracts query | ||
| * @returns A promise that resolves to an array of active contract responses | ||
| * @private | ||
| */ | ||
| async fetchActiveContractsUntilComplete(activeContractsArgs, limit) { | ||
| const ledgerEnd = await this.getWithRetry("/v2/state/ledger-end"); | ||
| const bodyRequest = { | ||
| beginExclusive: 0, | ||
| endInclusive: ledgerEnd.offset, | ||
| verbose: false, | ||
| updateFormat: {} | ||
| }; | ||
| if (!activeContractsArgs.filter) | ||
| bodyRequest.filter = activeContractsArgs.filter; | ||
| let currentOffset = 0; | ||
| const allContractsData = /* @__PURE__ */ new Map(); | ||
| const exercisedContracts = /* @__PURE__ */ new Set(); | ||
| while (currentOffset < ledgerEnd.offset) { | ||
| bodyRequest.beginExclusive = currentOffset; | ||
| const results = (await this.postWithRetry( | ||
| "/v2/updates", | ||
| bodyRequest, | ||
| defaultRetryableOptions, | ||
| { | ||
| query: { limit: limit.toString() } | ||
| } | ||
| )).filter(({ update }) => update && "Transaction" in update).map(({ update }) => { | ||
| if (update && "Transaction" in update) { | ||
| return update.Transaction.value; | ||
| } | ||
| throw new Error("Expected Transaction update"); | ||
| }).map((data) => { | ||
| const exercisedEvents = data.events?.filter( | ||
| (event) => !!event && "ExercisedEvent" in event | ||
| ).map( | ||
| (event) => event.ExercisedEvent | ||
| ).filter((event) => !!event).filter((event) => !!event.consuming); | ||
| const createdEvents = data.events?.filter((event) => !!event && "CreatedEvent" in event).map( | ||
| (event) => event.CreatedEvent | ||
| ).filter((event) => !!event).filter( | ||
| (event) => Object.keys( | ||
| activeContractsArgs.filter?.filtersByParty ?? {} | ||
| ).includes( | ||
| event.createArgument?.owner ?? "" | ||
| ) | ||
| ); | ||
| exercisedEvents?.forEach((event) => { | ||
| if (event.contractId) | ||
| exercisedContracts.add(event.contractId); | ||
| }); | ||
| createdEvents?.forEach((event) => { | ||
| if (!event.contractId) return; | ||
| allContractsData.set(event.contractId, { | ||
| workflowId: data.workflowId, | ||
| contractEntry: { | ||
| JsActiveContract: { | ||
| synchronizerId: data.synchronizerId, | ||
| createdEvent: event, | ||
| reassignmentCounter: data.offset | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| currentOffset = Math.max(currentOffset, data.offset); | ||
| return true; | ||
| }); | ||
| if (!results.length) currentOffset++; | ||
| } | ||
| exercisedContracts.forEach((cid) => { | ||
| allContractsData.delete(cid); | ||
| }); | ||
| return Array.from(allContractsData.values()); | ||
| } | ||
| buildActiveContractFilter(options) { | ||
| const filter = { | ||
| eventFormat: { | ||
| filtersByParty: {}, | ||
| verbose: false | ||
| }, | ||
| activeAtOffset: options?.offset | ||
| }; | ||
| const buildTemplateFilter = (templateIds) => { | ||
| if (!templateIds) return []; | ||
| return [ | ||
| { | ||
| identifierFilter: { | ||
| TemplateFilter: { | ||
| value: { | ||
| templateId: templateIds[0], | ||
| includeCreatedEventBlob: true | ||
| //TODO: figure out if this should be configurable | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ]; | ||
| }; | ||
| const buildInterfaceFilter = (interfaceIds) => { | ||
| if (!interfaceIds) return []; | ||
| return [ | ||
| { | ||
| identifierFilter: { | ||
| InterfaceFilter: { | ||
| value: { | ||
| interfaceId: interfaceIds[0], | ||
| includeCreatedEventBlob: true, | ||
| //TODO: figure out if this should be configurable | ||
| includeInterfaceView: true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ]; | ||
| }; | ||
| this.logger.info(options, "active contract query options"); | ||
| if (options?.filterByParty && options.parties && options.parties.length > 0) { | ||
| const cumulativeFilter = options?.templateIds && !options?.interfaceIds ? buildTemplateFilter(options.templateIds) : options?.interfaceIds && !options?.templateIds ? buildInterfaceFilter(options.interfaceIds) : []; | ||
| for (const party of options.parties) { | ||
| filter.filter.filtersByParty[party] = { | ||
| cumulative: cumulativeFilter | ||
| }; | ||
| } | ||
| } else if (options?.templateIds) { | ||
| filter.filter.filtersForAnyParty = { | ||
| cumulative: buildTemplateFilter(options.templateIds) | ||
| }; | ||
| } else if (options?.interfaceIds) { | ||
| filter.filter.filtersForAnyParty = { | ||
| cumulative: buildInterfaceFilter(options.templateIds) | ||
| }; | ||
| } | ||
| return filter; | ||
| } | ||
| // Retrieve an (arbitrary) synchronizer id from the validator. | ||
@@ -1184,5 +506,2 @@ // This synchronizer id is cached for the remainder of this object's life. | ||
| } | ||
| getCacheStats() { | ||
| return this.acsHelper.getCacheStats(); | ||
| } | ||
| async patch(path, body, params, additionalOptions) { | ||
@@ -1213,45 +532,3 @@ const options = { body, params, ...additionalOptions }; | ||
| // src/acs/ws-support.ts | ||
| var INITIAL_BACKOFF_MS = 1e3; | ||
| var MAX_BACKOFF_MS = 10 * 60 * 1e3; | ||
| var WSSupportWithBackOffSwitch = class { | ||
| constructor(extractProtocols, baseUrl) { | ||
| this.extractProtocols = extractProtocols; | ||
| this.baseUrl = baseUrl; | ||
| __publicField(this, "backOffUntil", null); | ||
| __publicField(this, "backOffDurationMs", INITIAL_BACKOFF_MS); | ||
| } | ||
| enabled() { | ||
| if (this.backOffUntil === null) { | ||
| return true; | ||
| } | ||
| const now = Date.now(); | ||
| if (now >= this.backOffUntil) { | ||
| this.backOffUntil = null; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| reportError(error) { | ||
| console.error("WebSocket error reported:", error); | ||
| const now = Date.now(); | ||
| if (this.backOffUntil !== null && now - this.backOffUntil < 500) { | ||
| return; | ||
| } | ||
| this.backOffUntil = Date.now() + this.backOffDurationMs; | ||
| this.backOffDurationMs = Math.min( | ||
| this.backOffDurationMs * 1.6, | ||
| MAX_BACKOFF_MS | ||
| ); | ||
| } | ||
| reportSuccess() { | ||
| this.backOffUntil = null; | ||
| this.backOffDurationMs = INITIAL_BACKOFF_MS; | ||
| } | ||
| }; | ||
| exports.ACSContainer = ACSContainer; | ||
| exports.ACS_UPDATE_CONFIG = ACS_UPDATE_CONFIG; | ||
| exports.LedgerClient = LedgerClient; | ||
| exports.WSSupportWithBackOffSwitch = WSSupportWithBackOffSwitch; | ||
| exports.asJsCantonError = asJsCantonError; | ||
@@ -1258,0 +535,0 @@ exports.awaitCompletion = awaitCompletion; |
+0
-2
| export * from './ledger-client.js'; | ||
| export * from './acs/acs-container.js'; | ||
| export * from './acs/ws-support.js'; | ||
| export { awaitCompletion, promiseWithTimeout, isJsCantonError, asJsCantonError, JsCantonError, JSContractEntry, defaultRetryableOptions, } from './ledger-api-utils.js'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,uBAAuB,GAC1B,MAAM,uBAAuB,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,uBAAuB,GAC1B,MAAM,uBAAuB,CAAA"} |
+2
-722
| import { supportedLedgerApiVersions } from '@canton-network/core-ledger-client-types'; | ||
| import createClient from 'openapi-fetch'; | ||
| import { ErrorInfo, RetryInfo } from '@canton-network/core-ledger-proto'; | ||
| import { LRUCache } from 'typescript-lru-cache'; | ||
@@ -145,478 +144,2 @@ var __defProp = Object.defineProperty; | ||
| // src/acs/acs-container.ts | ||
| var ACS_UPDATE_CONFIG = { | ||
| // How many events do we accumulate before we prune (compact) the ACS history - set to 0 to enable to compact all events, which is more efficient as long as application always ask for increasing (or equal) offsets | ||
| maxEventsBeforePrune: 150, | ||
| // When we compact the ACS history, we keep all events within this offset delta of the last seen update offset - set 0 to allow to compact everything | ||
| safeOffsetDeltaForPrune: 200, | ||
| // How many updates do we fetch at once when fetching updates - if there are more updates, we will fetch again until we have caught up (returned data is always complete to the requested endInclusive offset - even if that means multiple fetches) | ||
| maxUpdatesToFetch: 100, | ||
| // Timeout for receiving the first element from the WebSocket stream when reading the ACS - if this timeout is reached before the first element is returned, we fall back to HTTP | ||
| // lower values will make the UI more responsive in case of problems, but may lead to unnecessary fallbacks | ||
| wsTimeoutBeforeFirstElement: 1e4 | ||
| }; | ||
| if (typeof window !== "undefined") { | ||
| window["ACS_UPDATE_CONFIG"] = ACS_UPDATE_CONFIG; | ||
| } | ||
| var ACSContainer = class _ACSContainer { | ||
| constructor(orginalContainer = null, settings = { includeCreatedEventBlob: true }) { | ||
| __publicField(this, "acsSet", null); | ||
| __publicField(this, "settings"); | ||
| this.acsSet = orginalContainer ? orginalContainer.acsSet : null; | ||
| this.settings = settings; | ||
| } | ||
| async update(offset, key, api, wsSupport) { | ||
| if (this.acsSet === null) { | ||
| const acs = await this.readACS(offset, key, api, wsSupport); | ||
| this.acsSet = acs; | ||
| return _ACSContainer.calculateAt(acs, offset); | ||
| } | ||
| if (this.acsSet.acsOffset > offset) { | ||
| this.acsSet = null; | ||
| return this.update(offset, key, api); | ||
| } | ||
| if (this.acsSet.updates.length >= ACS_UPDATE_CONFIG.maxEventsBeforePrune) { | ||
| this.acsSet = await _ACSContainer.compact(this.acsSet); | ||
| } | ||
| const updates = await _ACSContainer.updateContracts( | ||
| this.acsSet.lastUpdateOffset, | ||
| offset, | ||
| this.createEventFormat(key), | ||
| api | ||
| ); | ||
| const [newEvents, newOffset] = _ACSContainer.extractEvents( | ||
| this.acsSet.lastUpdateOffset, | ||
| updates | ||
| ); | ||
| if (newOffset > this.acsSet.lastUpdateOffset) { | ||
| this.acsSet = { | ||
| ...this.acsSet, | ||
| lastUpdateOffset: newOffset, | ||
| updates: this.acsSet.updates.concat(newEvents) | ||
| }; | ||
| } | ||
| if (updates.length >= ACS_UPDATE_CONFIG.maxUpdatesToFetch) { | ||
| return this.update(offset, key, api); | ||
| } | ||
| this.acsSet = { | ||
| ...this.acsSet, | ||
| lastUpdateOffset: offset | ||
| // we have caught up | ||
| }; | ||
| return _ACSContainer.calculateAt(this.acsSet, offset); | ||
| } | ||
| static calculateAt(acs, offset) { | ||
| if (acs.acsOffset > offset) { | ||
| return Promise.reject( | ||
| Error( | ||
| // This should never happen as we check this before calling calculateAt | ||
| `Cannot calculate ACS at offset ${offset} when initial ACS is at ${acs.acsOffset}` | ||
| ) | ||
| ); | ||
| } | ||
| const addedContracts = []; | ||
| const removedContractIds = /* @__PURE__ */ new Set(); | ||
| acs.updates.forEach((update) => { | ||
| if (update.offset <= offset) { | ||
| if (update.created) { | ||
| const createdEv = update.created; | ||
| const activeContract = { | ||
| workflowId: update.workflowId ?? "", | ||
| contractEntry: { | ||
| JsActiveContract: { | ||
| createdEvent: createdEv, | ||
| synchronizerId: update.synchronizerId ?? "", | ||
| reassignmentCounter: 0 | ||
| } | ||
| } | ||
| }; | ||
| addedContracts.push(activeContract); | ||
| } else if (update.archivedContractId) { | ||
| removedContractIds.add(update.archivedContractId); | ||
| } | ||
| } | ||
| }); | ||
| const createdContracts = acs.initialAcs.concat(addedContracts); | ||
| const result = createdContracts.filter(({ contractEntry }) => { | ||
| if (!contractEntry) { | ||
| return false; | ||
| } | ||
| const id = "JsActiveContract" in contractEntry ? contractEntry.JsActiveContract?.createdEvent?.contractId ?? "" : ""; | ||
| return !removedContractIds.has(id); | ||
| }); | ||
| return Promise.resolve(result); | ||
| } | ||
| static extractEvents(fromOffset, updates) { | ||
| const newEvents = []; | ||
| let newOffset = fromOffset; | ||
| updates.forEach((update) => { | ||
| if (!update || !update.update) { | ||
| return; | ||
| } | ||
| if ("Transaction" in update.update) { | ||
| const transaction = update.update.Transaction; | ||
| const trOffset = transaction?.value?.offset; | ||
| if (trOffset && trOffset > newOffset) { | ||
| const events = transaction?.value?.events ?? []; | ||
| events.forEach((event) => { | ||
| if (!event) { | ||
| return; | ||
| } | ||
| if ("CreatedEvent" in event) { | ||
| const acUpdate = { | ||
| created: event.CreatedEvent, | ||
| archivedContractId: null, | ||
| offset: trOffset, | ||
| workflowId: transaction?.value?.workflowId ?? null, | ||
| synchronizerId: transaction?.value?.synchronizerId ?? null | ||
| }; | ||
| newEvents.push(acUpdate); | ||
| newOffset = trOffset; | ||
| } else if ("ArchivedEvent" in event) { | ||
| const archivedEvent = event.ArchivedEvent; | ||
| const acUpdate = { | ||
| created: null, | ||
| archivedContractId: archivedEvent?.contractId ?? null, | ||
| offset: trOffset, | ||
| workflowId: transaction?.value?.workflowId ?? null, | ||
| synchronizerId: transaction?.value?.synchronizerId ?? null | ||
| }; | ||
| newEvents.push(acUpdate); | ||
| newOffset = trOffset; | ||
| } | ||
| }); | ||
| } | ||
| } else if ("OffsetCheckpoint" in update.update) { | ||
| const checkpoint = update.update.OffsetCheckpoint; | ||
| const offset = checkpoint?.value?.offset; | ||
| if (offset) { | ||
| newOffset = offset; | ||
| } | ||
| } else { | ||
| console.log( | ||
| `ACS Update got unknown update type: ${JSON.stringify(update.update)}` | ||
| ); | ||
| } | ||
| }); | ||
| return [newEvents, newOffset]; | ||
| } | ||
| static async updateContracts(startOffset, endOffset, eventFormat, api) { | ||
| const request = { | ||
| beginExclusive: startOffset, | ||
| endInclusive: endOffset, | ||
| updateFormat: { | ||
| includeTransactions: { | ||
| eventFormat, | ||
| transactionShape: "TRANSACTION_SHAPE_ACS_DELTA" | ||
| } | ||
| }, | ||
| verbose: false | ||
| }; | ||
| const params = { | ||
| query: { | ||
| limit: ACS_UPDATE_CONFIG.maxUpdatesToFetch, | ||
| stream_idle_timeout_ms: 1e3 | ||
| } | ||
| }; | ||
| return api.postWithRetry( | ||
| "/v2/updates/flats", | ||
| request, | ||
| defaultRetryableOptions, | ||
| params | ||
| ); | ||
| } | ||
| static async compact(acs) { | ||
| const newAcsOffset = Math.max( | ||
| acs.acsOffset, | ||
| acs.lastUpdateOffset - ACS_UPDATE_CONFIG.safeOffsetDeltaForPrune | ||
| ); | ||
| if (newAcsOffset > acs.acsOffset) { | ||
| const responses = await _ACSContainer.calculateAt(acs, newAcsOffset); | ||
| return { | ||
| acsOffset: newAcsOffset, | ||
| initialAcs: responses, | ||
| lastUpdateOffset: acs.lastUpdateOffset, | ||
| updates: acs.updates.filter( | ||
| (update) => update.offset > newAcsOffset | ||
| ) | ||
| }; | ||
| } | ||
| return acs; | ||
| } | ||
| async readACS(offset, key, api, wsSupport) { | ||
| if (wsSupport && wsSupport.enabled()) { | ||
| return this.readACSUsingWs(offset, key, wsSupport).catch(() => { | ||
| console.log("Falling back to HTTP for ACS read"); | ||
| return this.readHttpACS(offset, key, api); | ||
| }); | ||
| } | ||
| return this.readHttpACS(offset, key, api); | ||
| } | ||
| async readHttpACS(offset, key, api) { | ||
| const format = this.createEventFormat(key); | ||
| const acs = await api.postWithRetry( | ||
| "/v2/state/active-contracts", | ||
| { | ||
| activeAtOffset: offset, | ||
| verbose: false, | ||
| eventFormat: format | ||
| }, | ||
| defaultRetryableOptions | ||
| ); | ||
| return { | ||
| acsOffset: offset, | ||
| initialAcs: acs, | ||
| lastUpdateOffset: offset, | ||
| updates: [] | ||
| }; | ||
| } | ||
| readACSUsingWs(offset, key, wsSupport) { | ||
| const wsACSURL = `${wsSupport.baseUrl}/v2/state/active-contracts`; | ||
| const format = this.createEventFormat(key); | ||
| const request = { | ||
| activeAtOffset: offset, | ||
| verbose: false, | ||
| eventFormat: format | ||
| }; | ||
| return new Promise((resolve, reject) => { | ||
| const ws = new WebSocket(wsACSURL, wsSupport.extractProtocols()); | ||
| const results = []; | ||
| let finished = false; | ||
| let error = null; | ||
| setTimeout(() => { | ||
| if (!finished && !error && results.length === 0) { | ||
| error = Error( | ||
| `No data received from WebSocket ${wsACSURL} within ${ACS_UPDATE_CONFIG.wsTimeoutBeforeFirstElement}ms` | ||
| ); | ||
| wsSupport.reportError(error); | ||
| reject(error); | ||
| ws.close(); | ||
| } | ||
| }, ACS_UPDATE_CONFIG.wsTimeoutBeforeFirstElement); | ||
| ws.onopen = () => { | ||
| ws.send(JSON.stringify(request)); | ||
| }; | ||
| ws.onmessage = (event) => { | ||
| try { | ||
| const data = JSON.parse( | ||
| event.data | ||
| ); | ||
| results.push(data); | ||
| } catch (err) { | ||
| console.error("Invalid JSON:", err); | ||
| } | ||
| }; | ||
| ws.onerror = () => { | ||
| error = new Error("WebSocket error"); | ||
| wsSupport.reportError(error); | ||
| reject(error); | ||
| }; | ||
| ws.onclose = () => { | ||
| finished = true; | ||
| if (!error) { | ||
| wsSupport.reportSuccess(); | ||
| resolve({ | ||
| acsOffset: offset, | ||
| initialAcs: results, | ||
| lastUpdateOffset: offset, | ||
| updates: [] | ||
| }); | ||
| } | ||
| }; | ||
| }); | ||
| } | ||
| createInterfaceFilter(interfaceId) { | ||
| return { | ||
| cumulative: [ | ||
| { | ||
| identifierFilter: { | ||
| InterfaceFilter: { | ||
| value: { | ||
| interfaceId, | ||
| includeInterfaceView: true, | ||
| includeCreatedEventBlob: this.settings.includeCreatedEventBlob | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| createTemplateFilter(templateId) { | ||
| return { | ||
| cumulative: [ | ||
| { | ||
| identifierFilter: { | ||
| TemplateFilter: { | ||
| value: { | ||
| templateId, | ||
| includeCreatedEventBlob: this.settings.includeCreatedEventBlob | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
| createEventFormat(key) { | ||
| const cumulativeFilter = key.templateId ? this.createTemplateFilter(key.templateId) : this.createInterfaceFilter(key.interfaceId ?? ""); | ||
| if (key.party) { | ||
| if (!key.interfaceId && !key.templateId) { | ||
| return { | ||
| filtersByParty: { | ||
| [key.party]: {} | ||
| }, | ||
| verbose: false | ||
| }; | ||
| } | ||
| return { | ||
| filtersByParty: { | ||
| [key.party]: cumulativeFilter | ||
| }, | ||
| verbose: false | ||
| }; | ||
| } | ||
| return { | ||
| filtersForAnyParty: cumulativeFilter, | ||
| verbose: false | ||
| }; | ||
| } | ||
| }; | ||
| var DEFAULT_MAX_CACHE_SIZE = 100; | ||
| var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3; | ||
| var SharedACSCache = new LRUCache({ | ||
| maxSize: DEFAULT_MAX_CACHE_SIZE, | ||
| entryExpirationTimeInMS: DEFAULT_ENTRY_EXPIRATION_TIME, | ||
| onEntryEvicted: (entry) => { | ||
| console.debug(`${entry} has expired`); | ||
| SharedACSCacheStats.evictions++; | ||
| } | ||
| }); | ||
| var SharedACSCacheStats = { | ||
| hits: 0, | ||
| misses: 0, | ||
| evictions: 0, | ||
| totalLookupTime: 0, | ||
| totalCacheServeTime: 0 | ||
| }; | ||
| // src/acs/acs-helper.ts | ||
| var ACSHelper = class _ACSHelper { | ||
| constructor(apiInstance, _logger, options, sharedCache) { | ||
| __publicField(this, "contractsSet"); | ||
| __publicField(this, "apiInstance"); | ||
| __publicField(this, "wsSupport"); | ||
| __publicField(this, "logger"); | ||
| __publicField(this, "includeCreatedEventBlob"); | ||
| __publicField(this, "totalCacheServeTime", 0); | ||
| this.contractsSet = sharedCache ?? new LRUCache({ | ||
| maxSize: options?.maxCacheSize ?? DEFAULT_MAX_CACHE_SIZE, | ||
| entryExpirationTimeInMS: options?.entryExpirationTime ?? DEFAULT_ENTRY_EXPIRATION_TIME, | ||
| // 10 minutes | ||
| onEntryEvicted: (entry) => { | ||
| this.logger.debug( | ||
| `entry ${entry.key} isExpired = ${entry.isExpired}. evicting entry.` | ||
| ); | ||
| SharedACSCacheStats.evictions++; | ||
| } | ||
| }); | ||
| this.apiInstance = apiInstance; | ||
| this.wsSupport = options?.wsSupport; | ||
| this.logger = _logger.child({ component: "ACSHelper" }); | ||
| this.includeCreatedEventBlob = options?.includeCreatedEventBlob ?? true; | ||
| } | ||
| getCacheStats() { | ||
| const totalCalls = SharedACSCacheStats.hits + SharedACSCacheStats.misses; | ||
| const hitRate = totalCalls ? SharedACSCacheStats.hits / totalCalls * 100 : 0; | ||
| const avgLookupTime = totalCalls > 0 ? SharedACSCacheStats.totalLookupTime / totalCalls : 0; | ||
| return { | ||
| totalCalls, | ||
| hits: SharedACSCacheStats.hits, | ||
| misses: SharedACSCacheStats.misses, | ||
| evictions: SharedACSCacheStats.evictions, | ||
| cacheSize: this.contractsSet.size, | ||
| hitRate: hitRate.toFixed(2) + "%", | ||
| averageLookupTime: avgLookupTime.toFixed(3) + " ms", | ||
| cacheServeTime: SharedACSCacheStats.totalCacheServeTime.toFixed(3) | ||
| }; | ||
| } | ||
| static createKey(party, templateId, interfaceId) { | ||
| return { party, templateId, interfaceId }; | ||
| } | ||
| static keyToString(key, ledgerBaseUrl) { | ||
| return `${ledgerBaseUrl}_${key.party ? key.party : "ANY"}_T:${key.templateId ?? "()"}_I:${key.interfaceId ?? "()"}`; | ||
| } | ||
| findACSContainer(key) { | ||
| const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href); | ||
| const start = performance.now(); | ||
| const existing = this.contractsSet.get(keyStr); | ||
| const end = performance.now(); | ||
| SharedACSCacheStats.totalLookupTime += end - start; | ||
| if (existing) { | ||
| SharedACSCacheStats.hits++; | ||
| this.logger.debug("cache hit"); | ||
| return existing; | ||
| } | ||
| this.logger.debug("cache miss"); | ||
| SharedACSCacheStats.misses++; | ||
| const newContainer = new ACSContainer(void 0, { | ||
| includeCreatedEventBlob: this.includeCreatedEventBlob | ||
| }); | ||
| this.contractsSet.set(keyStr, newContainer); | ||
| return newContainer; | ||
| } | ||
| async updateSingleKey(offset, key) { | ||
| const start = performance.now(); | ||
| const container = this.findACSContainer(key); | ||
| const result = await container.update( | ||
| offset, | ||
| key, | ||
| this.apiInstance, | ||
| this.wsSupport | ||
| ); | ||
| const end = performance.now(); | ||
| const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href); | ||
| if (this.contractsSet.has(keyStr)) { | ||
| SharedACSCacheStats.totalCacheServeTime += end - start; | ||
| } | ||
| return result; | ||
| } | ||
| async queryAcsByKeys(offset, keys) { | ||
| const result = []; | ||
| for (const key of keys) { | ||
| const contracts = await this.updateSingleKey(offset, key); | ||
| result.push(...contracts); | ||
| } | ||
| return result; | ||
| } | ||
| async activeContractsForTemplates(offset, parties, templateIds) { | ||
| const keys = parties.flatMap( | ||
| (party) => templateIds.map( | ||
| (templateId) => _ACSHelper.createKey(party, templateId, void 0) | ||
| ) | ||
| ); | ||
| return this.queryAcsByKeys(offset, keys); | ||
| } | ||
| async activeContractsForInterfaces(offset, parties, interfaceIds) { | ||
| const keys = parties.flatMap( | ||
| (party) => interfaceIds.map( | ||
| (interfaceId) => _ACSHelper.createKey(party, void 0, interfaceId) | ||
| ) | ||
| ); | ||
| return this.queryAcsByKeys(offset, keys); | ||
| } | ||
| async activeContractsForTemplate(offset, partyFilter, templateId) { | ||
| return this.updateSingleKey( | ||
| offset, | ||
| _ACSHelper.createKey(partyFilter, templateId, void 0) | ||
| ); | ||
| } | ||
| async activeContractsForInterface(offset, partyFilter, interfaceId) { | ||
| return this.updateSingleKey( | ||
| offset, | ||
| _ACSHelper.createKey(partyFilter, void 0, interfaceId) | ||
| ); | ||
| } | ||
| }; | ||
| // src/ledger-client.ts | ||
@@ -629,4 +152,3 @@ var supportedVersions = supportedLedgerApiVersions; | ||
| accessTokenProvider, | ||
| version, | ||
| acsHelperOptions | ||
| version | ||
| }) { | ||
@@ -638,3 +160,2 @@ // privately manage the active connected version and associated client codegen | ||
| __publicField(this, "accessTokenProvider"); | ||
| __publicField(this, "acsHelper"); | ||
| __publicField(this, "logger"); | ||
@@ -666,8 +187,2 @@ __publicField(this, "synchronizerId"); | ||
| this.baseUrl = baseUrl; | ||
| this.acsHelper = new ACSHelper( | ||
| this, | ||
| logger, | ||
| acsHelperOptions, | ||
| SharedACSCache | ||
| ); | ||
| } | ||
@@ -927,195 +442,2 @@ get currentClient() { | ||
| } | ||
| /* | ||
| if limit is provided, this function performs a one-time query. Automatically splits into multiple `/v2/updates` calls with `continueUntilCompletion` on. | ||
| if limit is omitted, results may be served from the ACS cache | ||
| current cache design doesn't support limiting queries because updates/deltas for the acs at offset x will be incorrect | ||
| TODO: expose query mode vs subscribe mode to call queryActiveContracts vs subscribeActiveContracts | ||
| */ | ||
| async activeContracts(options) { | ||
| const { | ||
| offset, | ||
| templateIds, | ||
| parties, | ||
| interfaceIds, | ||
| limit, | ||
| continueUntilCompletion | ||
| } = options; | ||
| if (continueUntilCompletion) { | ||
| const filter2 = this.buildActiveContractFilter(options); | ||
| return await this.fetchActiveContractsUntilComplete( | ||
| filter2, | ||
| limit ?? 200 | ||
| ); | ||
| } | ||
| const hasLimit = typeof limit === "number"; | ||
| if (hasLimit) { | ||
| const filter2 = this.buildActiveContractFilter(options); | ||
| return await this.postWithRetry( | ||
| "/v2/state/active-contracts", | ||
| filter2, | ||
| defaultRetryableOptions, | ||
| { query: { limit: limit.toString() } } | ||
| ); | ||
| } | ||
| this.logger.debug(options, "options for active contracts"); | ||
| const hasParties = Array.isArray(parties) && parties.length > 0; | ||
| if (templateIds?.length && hasParties) { | ||
| return this.acsHelper.activeContractsForTemplates( | ||
| offset, | ||
| parties, | ||
| templateIds | ||
| ); | ||
| } | ||
| if (interfaceIds?.length && hasParties) { | ||
| return this.acsHelper.activeContractsForInterfaces( | ||
| offset, | ||
| parties, | ||
| interfaceIds | ||
| ); | ||
| } | ||
| const filter = this.buildActiveContractFilter(options); | ||
| this.logger.debug("falling back to post request"); | ||
| return await this.postWithRetry( | ||
| "/v2/state/active-contracts", | ||
| filter, | ||
| defaultRetryableOptions | ||
| ); | ||
| } | ||
| /** | ||
| * Fetches active contracts by splitting requests into multiple `/v2/updates` calls. | ||
| * Should only be used when the number of contracts exceeds http-list-max-elements-limit (200 by default). | ||
| * For limits at or below http-list-max-elements-limit, use a single `/v2/state/active-contracts` call instead. | ||
| * @param activeContractsArgs The request parameters for active contracts query | ||
| * @returns A promise that resolves to an array of active contract responses | ||
| * @private | ||
| */ | ||
| async fetchActiveContractsUntilComplete(activeContractsArgs, limit) { | ||
| const ledgerEnd = await this.getWithRetry("/v2/state/ledger-end"); | ||
| const bodyRequest = { | ||
| beginExclusive: 0, | ||
| endInclusive: ledgerEnd.offset, | ||
| verbose: false, | ||
| updateFormat: {} | ||
| }; | ||
| if (!activeContractsArgs.filter) | ||
| bodyRequest.filter = activeContractsArgs.filter; | ||
| let currentOffset = 0; | ||
| const allContractsData = /* @__PURE__ */ new Map(); | ||
| const exercisedContracts = /* @__PURE__ */ new Set(); | ||
| while (currentOffset < ledgerEnd.offset) { | ||
| bodyRequest.beginExclusive = currentOffset; | ||
| const results = (await this.postWithRetry( | ||
| "/v2/updates", | ||
| bodyRequest, | ||
| defaultRetryableOptions, | ||
| { | ||
| query: { limit: limit.toString() } | ||
| } | ||
| )).filter(({ update }) => update && "Transaction" in update).map(({ update }) => { | ||
| if (update && "Transaction" in update) { | ||
| return update.Transaction.value; | ||
| } | ||
| throw new Error("Expected Transaction update"); | ||
| }).map((data) => { | ||
| const exercisedEvents = data.events?.filter( | ||
| (event) => !!event && "ExercisedEvent" in event | ||
| ).map( | ||
| (event) => event.ExercisedEvent | ||
| ).filter((event) => !!event).filter((event) => !!event.consuming); | ||
| const createdEvents = data.events?.filter((event) => !!event && "CreatedEvent" in event).map( | ||
| (event) => event.CreatedEvent | ||
| ).filter((event) => !!event).filter( | ||
| (event) => Object.keys( | ||
| activeContractsArgs.filter?.filtersByParty ?? {} | ||
| ).includes( | ||
| event.createArgument?.owner ?? "" | ||
| ) | ||
| ); | ||
| exercisedEvents?.forEach((event) => { | ||
| if (event.contractId) | ||
| exercisedContracts.add(event.contractId); | ||
| }); | ||
| createdEvents?.forEach((event) => { | ||
| if (!event.contractId) return; | ||
| allContractsData.set(event.contractId, { | ||
| workflowId: data.workflowId, | ||
| contractEntry: { | ||
| JsActiveContract: { | ||
| synchronizerId: data.synchronizerId, | ||
| createdEvent: event, | ||
| reassignmentCounter: data.offset | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| currentOffset = Math.max(currentOffset, data.offset); | ||
| return true; | ||
| }); | ||
| if (!results.length) currentOffset++; | ||
| } | ||
| exercisedContracts.forEach((cid) => { | ||
| allContractsData.delete(cid); | ||
| }); | ||
| return Array.from(allContractsData.values()); | ||
| } | ||
| buildActiveContractFilter(options) { | ||
| const filter = { | ||
| eventFormat: { | ||
| filtersByParty: {}, | ||
| verbose: false | ||
| }, | ||
| activeAtOffset: options?.offset | ||
| }; | ||
| const buildTemplateFilter = (templateIds) => { | ||
| if (!templateIds) return []; | ||
| return [ | ||
| { | ||
| identifierFilter: { | ||
| TemplateFilter: { | ||
| value: { | ||
| templateId: templateIds[0], | ||
| includeCreatedEventBlob: true | ||
| //TODO: figure out if this should be configurable | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ]; | ||
| }; | ||
| const buildInterfaceFilter = (interfaceIds) => { | ||
| if (!interfaceIds) return []; | ||
| return [ | ||
| { | ||
| identifierFilter: { | ||
| InterfaceFilter: { | ||
| value: { | ||
| interfaceId: interfaceIds[0], | ||
| includeCreatedEventBlob: true, | ||
| //TODO: figure out if this should be configurable | ||
| includeInterfaceView: true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ]; | ||
| }; | ||
| this.logger.info(options, "active contract query options"); | ||
| if (options?.filterByParty && options.parties && options.parties.length > 0) { | ||
| const cumulativeFilter = options?.templateIds && !options?.interfaceIds ? buildTemplateFilter(options.templateIds) : options?.interfaceIds && !options?.templateIds ? buildInterfaceFilter(options.interfaceIds) : []; | ||
| for (const party of options.parties) { | ||
| filter.filter.filtersByParty[party] = { | ||
| cumulative: cumulativeFilter | ||
| }; | ||
| } | ||
| } else if (options?.templateIds) { | ||
| filter.filter.filtersForAnyParty = { | ||
| cumulative: buildTemplateFilter(options.templateIds) | ||
| }; | ||
| } else if (options?.interfaceIds) { | ||
| filter.filter.filtersForAnyParty = { | ||
| cumulative: buildInterfaceFilter(options.templateIds) | ||
| }; | ||
| } | ||
| return filter; | ||
| } | ||
| // Retrieve an (arbitrary) synchronizer id from the validator. | ||
@@ -1177,5 +499,2 @@ // This synchronizer id is cached for the remainder of this object's life. | ||
| } | ||
| getCacheStats() { | ||
| return this.acsHelper.getCacheStats(); | ||
| } | ||
| async patch(path, body, params, additionalOptions) { | ||
@@ -1206,43 +525,4 @@ const options = { body, params, ...additionalOptions }; | ||
| // src/acs/ws-support.ts | ||
| var INITIAL_BACKOFF_MS = 1e3; | ||
| var MAX_BACKOFF_MS = 10 * 60 * 1e3; | ||
| var WSSupportWithBackOffSwitch = class { | ||
| constructor(extractProtocols, baseUrl) { | ||
| this.extractProtocols = extractProtocols; | ||
| this.baseUrl = baseUrl; | ||
| __publicField(this, "backOffUntil", null); | ||
| __publicField(this, "backOffDurationMs", INITIAL_BACKOFF_MS); | ||
| } | ||
| enabled() { | ||
| if (this.backOffUntil === null) { | ||
| return true; | ||
| } | ||
| const now = Date.now(); | ||
| if (now >= this.backOffUntil) { | ||
| this.backOffUntil = null; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| reportError(error) { | ||
| console.error("WebSocket error reported:", error); | ||
| const now = Date.now(); | ||
| if (this.backOffUntil !== null && now - this.backOffUntil < 500) { | ||
| return; | ||
| } | ||
| this.backOffUntil = Date.now() + this.backOffDurationMs; | ||
| this.backOffDurationMs = Math.min( | ||
| this.backOffDurationMs * 1.6, | ||
| MAX_BACKOFF_MS | ||
| ); | ||
| } | ||
| reportSuccess() { | ||
| this.backOffUntil = null; | ||
| this.backOffDurationMs = INITIAL_BACKOFF_MS; | ||
| } | ||
| }; | ||
| export { ACSContainer, ACS_UPDATE_CONFIG, LedgerClient, WSSupportWithBackOffSwitch, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions }; | ||
| export { LedgerClient, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions }; | ||
| //# sourceMappingURL=index.js.map | ||
| //# sourceMappingURL=index.js.map |
@@ -6,3 +6,2 @@ import { type LedgerApiVersion, type LedgerCommonPaths, type LedgerCommonSchemas } from '@canton-network/core-ledger-client-types'; | ||
| import { retryableOptions } from './ledger-api-utils.js'; | ||
| import { AcsHelperOptions } from './acs/acs-helper.js'; | ||
| import { AccessTokenProvider } from '@canton-network/core-wallet-auth'; | ||
@@ -92,7 +91,6 @@ export declare const supportedVersions: readonly ["3.4", "3.5"]; | ||
| private accessTokenProvider; | ||
| private acsHelper; | ||
| private readonly logger; | ||
| private synchronizerId; | ||
| baseUrl: URL; | ||
| constructor({ baseUrl, logger, accessTokenProvider, version, acsHelperOptions, }: { | ||
| constructor({ baseUrl, logger, accessTokenProvider, version, }: { | ||
| baseUrl: URL; | ||
@@ -102,3 +100,2 @@ logger: Logger; | ||
| version?: SupportedVersions; | ||
| acsHelperOptions?: AcsHelperOptions; | ||
| }); | ||
@@ -155,21 +152,2 @@ private get currentClient(); | ||
| generateTopology(synchronizerId: string, publicKey: string, partyHint: string, localParticipantObservationOnly?: boolean, confirmationThreshold?: number, otherConfirmingParticipantUids?: string[], observingParticipantUids?: string[]): Promise<GenerateTransactionResponse>; | ||
| activeContracts(options: { | ||
| offset: number; | ||
| templateIds?: string[]; | ||
| parties?: string[]; | ||
| filterByParty?: boolean; | ||
| interfaceIds?: string[]; | ||
| limit?: number; | ||
| continueUntilCompletion?: boolean; | ||
| }): Promise<Array<Types['JsGetActiveContractsResponse']>>; | ||
| /** | ||
| * Fetches active contracts by splitting requests into multiple `/v2/updates` calls. | ||
| * Should only be used when the number of contracts exceeds http-list-max-elements-limit (200 by default). | ||
| * For limits at or below http-list-max-elements-limit, use a single `/v2/state/active-contracts` call instead. | ||
| * @param activeContractsArgs The request parameters for active contracts query | ||
| * @returns A promise that resolves to an array of active contract responses | ||
| * @private | ||
| */ | ||
| private fetchActiveContractsUntilComplete; | ||
| private buildActiveContractFilter; | ||
| getSynchronizerId(): Promise<string>; | ||
@@ -188,12 +166,2 @@ postWithRetry<Path extends PostEndpoint>(path: Path, body: PostRequest<Path>, retryOptions?: retryableOptions, params?: { | ||
| }, additionalOptions?: ExtraPostOpts): Promise<PatchResponse<Path>>; | ||
| getCacheStats(): { | ||
| totalCalls: number; | ||
| hits: number; | ||
| misses: number; | ||
| evictions: number; | ||
| cacheSize: number; | ||
| hitRate: string; | ||
| averageLookupTime: string; | ||
| cacheServeTime: string; | ||
| }; | ||
| patch<Path extends PatchEndpoint>(path: Path, body: PatchRequest<Path>, params?: { | ||
@@ -200,0 +168,0 @@ path?: Record<string, string>; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ledger-client.d.ts","sourceRoot":"","sources":["../src/ledger-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAEH,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAC3B,MAAM,0CAA0C,CAAA;AACjD,OAAqB,EAAU,YAAY,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAIH,gBAAgB,EACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAa,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAEtE,eAAO,MAAM,iBAAiB,yBAA6B,CAAA;AAE3D,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAAA;AAEhD,KAAK,KAAK,GA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EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;KACpD,EAED,iBAAiB,CAAC,EAAE,aAAa,GAClC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAQjB,GAAG,CAAC,IAAI,SAAS,WAAW,EACrC,IAAI,EAAE,IAAI,EACV,MAAM,CAAC,EAAE;QACL,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACjC,GACF,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAQf,YAAY;CAU7B"} |
+7
-7
| { | ||
| "name": "@canton-network/core-ledger-client", | ||
| "version": "1.3.2", | ||
| "version": "1.4.0", | ||
| "type": "module", | ||
@@ -39,8 +39,8 @@ "description": "Provides a TypeScript Canton Network ledger client, generated by the OpenAPI spec", | ||
| "dependencies": { | ||
| "@canton-network/core-ledger-client-types": "^1.3.2", | ||
| "@canton-network/core-ledger-proto": "^1.3.2", | ||
| "@canton-network/core-splice-client": "^1.3.2", | ||
| "@canton-network/core-token-standard": "^1.3.2", | ||
| "@canton-network/core-types": "^1.3.2", | ||
| "@canton-network/core-wallet-auth": "^1.3.2", | ||
| "@canton-network/core-ledger-client-types": "^1.4.0", | ||
| "@canton-network/core-ledger-proto": "^1.4.0", | ||
| "@canton-network/core-splice-client": "^1.4.0", | ||
| "@canton-network/core-token-standard": "^1.4.0", | ||
| "@canton-network/core-types": "^1.4.0", | ||
| "@canton-network/core-wallet-auth": "^1.4.0", | ||
| "bignumber.js": "^10.0.2", | ||
@@ -47,0 +47,0 @@ "dayjs": "^1.11.19", |
| import { PartyId } from '@canton-network/core-types'; | ||
| import { LedgerClient } from '../ledger-client'; | ||
| import { WSSupport } from './ws-support.js'; | ||
| import { JsGetActiveContractsResponse } from './types.js'; | ||
| interface ACSUpdateConfig { | ||
| maxEventsBeforePrune: number; | ||
| safeOffsetDeltaForPrune: number; | ||
| maxUpdatesToFetch: number; | ||
| wsTimeoutBeforeFirstElement: number; | ||
| } | ||
| export declare const ACS_UPDATE_CONFIG: ACSUpdateConfig; | ||
| export interface ACSKey { | ||
| party?: PartyId | undefined; | ||
| templateId?: string | undefined; | ||
| interfaceId?: string | undefined; | ||
| } | ||
| export declare class ACSContainer { | ||
| private acsSet; | ||
| private settings; | ||
| constructor(orginalContainer?: ACSContainer | null, settings?: { | ||
| includeCreatedEventBlob: boolean; | ||
| }); | ||
| update(offset: number, key: ACSKey, api: LedgerClient, wsSupport?: WSSupport): Promise<JsGetActiveContractsResponse[]>; | ||
| private static calculateAt; | ||
| private static extractEvents; | ||
| private static updateContracts; | ||
| private static compact; | ||
| private readACS; | ||
| private readHttpACS; | ||
| private readACSUsingWs; | ||
| private createInterfaceFilter; | ||
| private createTemplateFilter; | ||
| private createEventFormat; | ||
| } | ||
| export {}; | ||
| //# sourceMappingURL=acs-container.d.ts.map |
| {"version":3,"file":"acs-container.d.ts","sourceRoot":"","sources":["../../src/acs/acs-container.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAEH,4BAA4B,EAO/B,MAAM,YAAY,CAAA;AAEnB,UAAU,eAAe;IACrB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,uBAAuB,EAAE,MAAM,CAAA;IAC/B,iBAAiB,EAAE,MAAM,CAAA;IACzB,2BAA2B,EAAE,MAAM,CAAA;CACtC;AAUD,eAAO,MAAM,iBAAiB,EAAE,eAU/B,CAAA;AAOD,MAAM,WAAW,MAAM;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC;AAcD,qBAAa,YAAY;IACrB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,QAAQ,CAAsC;gBAGlD,gBAAgB,GAAE,YAAY,GAAG,IAAW,EAC5C,QAAQ;;KAAoC;IAM1C,MAAM,CACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,YAAY,EACjB,SAAS,CAAC,EAAE,SAAS,GACtB,OAAO,CAAC,4BAA4B,EAAE,CAAC;IA+C1C,OAAO,CAAC,MAAM,CAAC,WAAW;IAsD1B,OAAO,CAAC,MAAM,CAAC,aAAa;mBAgEP,eAAe;mBAgCf,OAAO;YAmBd,OAAO;YAeP,WAAW;IAuBzB,OAAO,CAAC,cAAc;IA+DtB,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,iBAAiB;CA4B5B"} |
| import { LedgerClient } from '../ledger-client'; | ||
| import { LRUCache } from 'typescript-lru-cache'; | ||
| import { ACSContainer, ACSKey } from './acs-container.js'; | ||
| import { WSSupport } from './ws-support.js'; | ||
| import { PartyId } from '@canton-network/core-types'; | ||
| import { Logger } from 'pino'; | ||
| import { JsGetActiveContractsResponse } from './types.js'; | ||
| export type AcsHelperOptions = { | ||
| wsSupport?: WSSupport; | ||
| maxCacheSize?: number; | ||
| entryExpirationTime?: number; | ||
| includeCreatedEventBlob?: boolean; | ||
| }; | ||
| export declare class ACSHelper { | ||
| private contractsSet; | ||
| private readonly apiInstance; | ||
| private readonly wsSupport; | ||
| private readonly logger; | ||
| private includeCreatedEventBlob; | ||
| private totalCacheServeTime; | ||
| constructor(apiInstance: LedgerClient, _logger: Logger, options?: AcsHelperOptions, sharedCache?: LRUCache<string, ACSContainer>); | ||
| getCacheStats(): { | ||
| totalCalls: number; | ||
| hits: number; | ||
| misses: number; | ||
| evictions: number; | ||
| cacheSize: number; | ||
| hitRate: string; | ||
| averageLookupTime: string; | ||
| cacheServeTime: string; | ||
| }; | ||
| private static createKey; | ||
| private static keyToString; | ||
| private findACSContainer; | ||
| updateSingleKey(offset: number, key: ACSKey): Promise<({ | ||
| workflowId?: string; | ||
| contractEntry?: import("../../../ledger-client-types/dist/generated-clients/openapi-3.4.12").components["schemas"]["JsContractEntry"]; | ||
| } & { | ||
| workflowId?: string; | ||
| contractEntry?: import("../../../ledger-client-types/dist/generated-clients/openapi-3.5.1").components["schemas"]["JsContractEntry"]; | ||
| streamContinuationToken?: string; | ||
| })[]>; | ||
| queryAcsByKeys(offset: number, keys: ACSKey[]): Promise<({ | ||
| workflowId?: string; | ||
| contractEntry?: import("../../../ledger-client-types/dist/generated-clients/openapi-3.4.12").components["schemas"]["JsContractEntry"]; | ||
| } & { | ||
| workflowId?: string; | ||
| contractEntry?: import("../../../ledger-client-types/dist/generated-clients/openapi-3.5.1").components["schemas"]["JsContractEntry"]; | ||
| streamContinuationToken?: string; | ||
| })[]>; | ||
| activeContractsForTemplates(offset: number, parties: PartyId[], templateIds: string[]): Promise<JsGetActiveContractsResponse[]>; | ||
| activeContractsForInterfaces(offset: number, parties: PartyId[], interfaceIds: string[]): Promise<JsGetActiveContractsResponse[]>; | ||
| activeContractsForTemplate(offset: number, partyFilter: PartyId, templateId: string): Promise<JsGetActiveContractsResponse[]>; | ||
| activeContractsForInterface(offset: number, partyFilter: PartyId | undefined, interfaceId: string): Promise<Array<JsGetActiveContractsResponse>>; | ||
| } | ||
| //# sourceMappingURL=acs-helper.d.ts.map |
| {"version":3,"file":"acs-helper.d.ts","sourceRoot":"","sources":["../../src/acs/acs-helper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAMzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAA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CAAC;IASpC,4BAA4B,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAAE,EAClB,YAAY,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,4BAA4B,EAAE,CAAC;IAUpC,0BAA0B,CAC5B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,OAAO,EACpB,UAAU,EAAE,MAAM,GACnB,OAAO,CAAC,4BAA4B,EAAE,CAAC;IAOpC,2BAA2B,CAC7B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,OAAO,GAAG,SAAS,EAChC,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;CAMlD"} |
| import { LRUCache } from 'typescript-lru-cache'; | ||
| import { ACSContainer } from './acs-container.js'; | ||
| export declare const DEFAULT_MAX_CACHE_SIZE = 100; | ||
| export declare const DEFAULT_ENTRY_EXPIRATION_TIME: number; | ||
| export declare const SharedACSCache: LRUCache<string, ACSContainer>; | ||
| export declare const SharedACSCacheStats: { | ||
| hits: number; | ||
| misses: number; | ||
| evictions: number; | ||
| cacheSize: number; | ||
| totalLookupTime: number; | ||
| totalCacheServeTime: number; | ||
| }; | ||
| //# sourceMappingURL=acs-shared-cache.d.ts.map |
| {"version":3,"file":"acs-shared-cache.d.ts","sourceRoot":"","sources":["../../src/acs/acs-shared-cache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,eAAO,MAAM,sBAAsB,MAAM,CAAA;AACzC,eAAO,MAAM,6BAA6B,QAAiB,CAAA;AAE3D,eAAO,MAAM,cAAc,gCAOzB,CAAA;AAEF,eAAO,MAAM,mBAAmB;;;;;;;CAO/B,CAAA"} |
| import { Types } from '../ledger-client'; | ||
| export type CreatedEvent = Types['CreatedEvent']; | ||
| export type JsGetActiveContractsResponse = Types['JsGetActiveContractsResponse']; | ||
| export type EventFormat = Types['EventFormat']; | ||
| export type Filters = Types['Filters']; | ||
| export type GetActiveContractsRequest = Types['GetActiveContractsRequest']; | ||
| export type JsGetUpdatesResponse = Types['JsGetUpdatesResponse']; | ||
| export type GetUpdatesRequest = Types['GetUpdatesRequest']; | ||
| export type Event = Types['Event']; | ||
| //# sourceMappingURL=types.d.ts.map |
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/acs/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAExC,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,cAAc,CAAC,CAAA;AAChD,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAAC,8BAA8B,CAAC,CAAA;AAChF,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAC,CAAA;AAC9C,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,CAAA;AACtC,MAAM,MAAM,yBAAyB,GAAG,KAAK,CAAC,2BAA2B,CAAC,CAAA;AAC1E,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,sBAAsB,CAAC,CAAA;AAChE,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,mBAAmB,CAAC,CAAA;AAC1D,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA"} |
| export interface WSSupport { | ||
| extractProtocols: () => string[]; | ||
| baseUrl: string; | ||
| enabled: () => boolean; | ||
| reportError: (error: Error) => void; | ||
| reportSuccess: () => void; | ||
| } | ||
| export declare class WSSupportWithBackOffSwitch implements WSSupport { | ||
| extractProtocols: () => string[]; | ||
| baseUrl: string; | ||
| private backOffUntil; | ||
| private backOffDurationMs; | ||
| constructor(extractProtocols: () => string[], baseUrl: string); | ||
| enabled(): boolean; | ||
| reportError(error: Error): void; | ||
| reportSuccess(): void; | ||
| } | ||
| //# sourceMappingURL=ws-support.d.ts.map |
| {"version":3,"file":"ws-support.d.ts","sourceRoot":"","sources":["../../src/acs/ws-support.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACtB,gBAAgB,EAAE,MAAM,MAAM,EAAE,CAAA;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,OAAO,CAAA;IACtB,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IACnC,aAAa,EAAE,MAAM,IAAI,CAAA;CAC5B;AAcD,qBAAa,0BAA2B,YAAW,SAAS;IAM7C,gBAAgB,EAAE,MAAM,MAAM,EAAE;IAChC,OAAO,EAAE,MAAM;IAN1B,OAAO,CAAC,YAAY,CAAsB;IAE1C,OAAO,CAAC,iBAAiB,CAA6B;gBAG3C,gBAAgB,EAAE,MAAM,MAAM,EAAE,EAChC,OAAO,EAAE,MAAM;IAG1B,OAAO,IAAI,OAAO;IAYlB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAc/B,aAAa,IAAI,IAAI;CAIxB"} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
139538
-56.24%12
-45.45%1253
-56.08%