@canton-network/core-ledger-client 0.20.3 → 0.22.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.
- package/dist/acs/acs-container.d.ts +1 -1
- package/dist/acs/acs-container.d.ts.map +1 -1
- package/dist/acs/acs-helper.d.ts +20 -3
- package/dist/acs/acs-helper.d.ts.map +1 -1
- package/dist/amulet-service.d.ts.map +1 -1
- package/dist/generated-clients/openapi-3.3.0-SNAPSHOT.d.ts +2219 -1170
- package/dist/generated-clients/openapi-3.3.0-SNAPSHOT.d.ts.map +1 -1
- package/dist/generated-clients/openapi-3.4.7.d.ts +2584 -1398
- package/dist/generated-clients/openapi-3.4.7.d.ts.map +1 -1
- package/dist/index.cjs +120 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -84
- package/dist/index.js.map +1 -1
- package/dist/ledger-api-utils.d.ts +1 -0
- package/dist/ledger-api-utils.d.ts.map +1 -1
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts +3 -2
- package/dist/token-standard-service.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -236,27 +236,25 @@ async function awaitCompletion(ledgerClient, ledgerEnd, partyId, userId, command
|
|
|
236
236
|
}
|
|
237
237
|
);
|
|
238
238
|
const completions = responses.filter(
|
|
239
|
-
(
|
|
239
|
+
(r) => "Completion" in r.completionResponse
|
|
240
240
|
);
|
|
241
|
-
const wantedCompletion =
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (completion.value.submissionId === commandIdOrSubmissionId)
|
|
247
|
-
return true;
|
|
241
|
+
const wantedCompletion = responses.find((r) => {
|
|
242
|
+
if ("Completion" in r.completionResponse) {
|
|
243
|
+
const completion = r.completionResponse.Completion.value;
|
|
244
|
+
return completion.userId === userId && (completion.commandId === commandIdOrSubmissionId || completion.submissionId === commandIdOrSubmissionId);
|
|
245
|
+
}
|
|
248
246
|
return false;
|
|
249
247
|
});
|
|
250
|
-
if (wantedCompletion) {
|
|
251
|
-
const completion = wantedCompletion.completionResponse.Completion;
|
|
252
|
-
const status = completion.
|
|
248
|
+
if (wantedCompletion && "Completion" in wantedCompletion.completionResponse) {
|
|
249
|
+
const completion = wantedCompletion.completionResponse.Completion.value;
|
|
250
|
+
const status = completion.status;
|
|
253
251
|
if (status && status.code !== 0) {
|
|
254
252
|
throw asGrpcError(status);
|
|
255
253
|
}
|
|
256
|
-
return completion
|
|
254
|
+
return completion;
|
|
257
255
|
} else {
|
|
258
256
|
const lastCompletion = completions[completions.length - 1];
|
|
259
|
-
const newLedgerEnd = lastCompletion
|
|
257
|
+
const newLedgerEnd = lastCompletion && "Completion" in lastCompletion.completionResponse ? lastCompletion.completionResponse.Completion.value.offset : void 0;
|
|
260
258
|
return awaitCompletion(
|
|
261
259
|
ledgerClient,
|
|
262
260
|
newLedgerEnd || ledgerEnd,
|
|
@@ -316,7 +314,7 @@ async function retryable(fn, retryableOptions2, logger) {
|
|
|
316
314
|
}
|
|
317
315
|
throw new Error("retryable: Exceeded maximum retries without throwing.");
|
|
318
316
|
}
|
|
319
|
-
var isJsCantonError = (e) => typeof e === "object" && e !== null && "
|
|
317
|
+
var isJsCantonError = (e) => typeof e === "object" && e !== null && "code" in e && "cause" in e && "errorCategory" in e;
|
|
320
318
|
var asJsCantonError = (e) => {
|
|
321
319
|
if (isJsCantonError(e)) {
|
|
322
320
|
return e;
|
|
@@ -1026,7 +1024,7 @@ function isLeafEventNode(result) {
|
|
|
1026
1024
|
return !!result.event;
|
|
1027
1025
|
}
|
|
1028
1026
|
function getNodeIdAndEvent(event) {
|
|
1029
|
-
if (event
|
|
1027
|
+
if ("ExercisedEvent" in event) {
|
|
1030
1028
|
if (event.ExercisedEvent.choice === "Archive") {
|
|
1031
1029
|
return {
|
|
1032
1030
|
nodeId: event.ExercisedEvent.nodeId,
|
|
@@ -1038,12 +1036,12 @@ function getNodeIdAndEvent(event) {
|
|
|
1038
1036
|
exercisedEvent: event.ExercisedEvent
|
|
1039
1037
|
};
|
|
1040
1038
|
}
|
|
1041
|
-
} else if (event
|
|
1039
|
+
} else if ("CreatedEvent" in event) {
|
|
1042
1040
|
return {
|
|
1043
1041
|
nodeId: event.CreatedEvent.nodeId,
|
|
1044
1042
|
createdEvent: event.CreatedEvent
|
|
1045
1043
|
};
|
|
1046
|
-
} else if (event
|
|
1044
|
+
} else if ("ArchivedEvent" in event) {
|
|
1047
1045
|
return {
|
|
1048
1046
|
nodeId: event.ArchivedEvent.nodeId,
|
|
1049
1047
|
archivedEvent: event.ArchivedEvent
|
|
@@ -1205,11 +1203,13 @@ var CoreService = class _CoreService {
|
|
|
1205
1203
|
offset: ledgerEnd,
|
|
1206
1204
|
interfaceIds: [interfaceId],
|
|
1207
1205
|
parties: [partyId],
|
|
1208
|
-
filterByParty: true
|
|
1209
|
-
limit: limit ?? 100
|
|
1206
|
+
filterByParty: true
|
|
1210
1207
|
};
|
|
1208
|
+
if (limit !== void 0) {
|
|
1209
|
+
options.limit = limit;
|
|
1210
|
+
}
|
|
1211
1211
|
const acsResponses = await this.ledgerClient.activeContracts(options);
|
|
1212
|
-
const isActiveContractEntry = (acsResponse) => !!acsResponse.contractEntry.JsActiveContract?.createdEvent;
|
|
1212
|
+
const isActiveContractEntry = (acsResponse) => "JsActiveContract" in acsResponse.contractEntry && !!acsResponse.contractEntry.JsActiveContract?.createdEvent;
|
|
1213
1213
|
const activeContractEntries = acsResponses.filter(
|
|
1214
1214
|
isActiveContractEntry
|
|
1215
1215
|
);
|
|
@@ -1225,8 +1225,8 @@ var CoreService = class _CoreService {
|
|
|
1225
1225
|
}
|
|
1226
1226
|
}
|
|
1227
1227
|
async toPrettyTransactions(updates, partyId, ledgerClient) {
|
|
1228
|
-
const isOffsetCheckpointUpdate = (updateResponse) =>
|
|
1229
|
-
const isTransactionUpdate = (updateResponse) => !!updateResponse.update
|
|
1228
|
+
const isOffsetCheckpointUpdate = (updateResponse) => "OffsetCheckpoint" in updateResponse.update;
|
|
1229
|
+
const isTransactionUpdate = (updateResponse) => "Transaction" in updateResponse.update && !!updateResponse.update.Transaction?.value;
|
|
1230
1230
|
const offsetCheckpoints = updates.filter(isOffsetCheckpointUpdate).map((update) => update.update.OffsetCheckpoint.value.offset);
|
|
1231
1231
|
const latestCheckpointOffset = Math.max(...offsetCheckpoints);
|
|
1232
1232
|
const transactions = await Promise.all(
|
|
@@ -1330,9 +1330,10 @@ var AllocationService = class {
|
|
|
1330
1330
|
}
|
|
1331
1331
|
};
|
|
1332
1332
|
}
|
|
1333
|
-
async fetchAllocationFactoryChoiceContext(registryUrl, choiceArgs) {
|
|
1333
|
+
async fetchAllocationFactoryChoiceContext(registryUrl, choiceArgs, excludeDebugFields = true) {
|
|
1334
1334
|
return this.core.getTokenStandardClient(registryUrl).post("/registry/allocation-instruction/v1/allocation-factory", {
|
|
1335
|
-
choiceArguments: choiceArgs
|
|
1335
|
+
choiceArguments: choiceArgs,
|
|
1336
|
+
excludeDebugFields
|
|
1336
1337
|
});
|
|
1337
1338
|
}
|
|
1338
1339
|
async createAllocationInstructionFromContext(factoryId, choiceArgs, choiceContext) {
|
|
@@ -1578,9 +1579,10 @@ var TransferService = class {
|
|
|
1578
1579
|
}
|
|
1579
1580
|
};
|
|
1580
1581
|
}
|
|
1581
|
-
async fetchTransferFactoryChoiceContext(registryUrl, choiceArgs) {
|
|
1582
|
+
async fetchTransferFactoryChoiceContext(registryUrl, choiceArgs, excludeDebugFields = true) {
|
|
1582
1583
|
return await this.core.getTokenStandardClient(registryUrl).post("/registry/transfer-instruction/v1/transfer-factory", {
|
|
1583
|
-
choiceArguments: choiceArgs
|
|
1584
|
+
choiceArguments: choiceArgs,
|
|
1585
|
+
excludeDebugFields
|
|
1584
1586
|
});
|
|
1585
1587
|
}
|
|
1586
1588
|
async createTransferFromContext(factoryId, choiceArgs, choiceContext) {
|
|
@@ -1597,6 +1599,7 @@ var TransferService = class {
|
|
|
1597
1599
|
};
|
|
1598
1600
|
return [exercise, choiceContext.disclosedContracts];
|
|
1599
1601
|
}
|
|
1602
|
+
// TODO: use named parameters
|
|
1600
1603
|
async createTransfer(sender, receiver, amount, instrumentAdmin, instrumentId, registryUrl, inputUtxos, memo, expiryDate, meta, prefetchedRegistryChoiceContext) {
|
|
1601
1604
|
try {
|
|
1602
1605
|
const choiceArgs = await this.buildTransferChoiceArgs(
|
|
@@ -1878,6 +1881,28 @@ var TransferService = class {
|
|
|
1878
1881
|
choiceContext
|
|
1879
1882
|
);
|
|
1880
1883
|
}
|
|
1884
|
+
async createTransferInstruction(transferInstructionCid, registryUrl, instructionChoice, prefetchedRegistryChoiceContext) {
|
|
1885
|
+
switch (instructionChoice) {
|
|
1886
|
+
case "Accept":
|
|
1887
|
+
return this.createAcceptTransferInstruction(
|
|
1888
|
+
transferInstructionCid,
|
|
1889
|
+
registryUrl,
|
|
1890
|
+
prefetchedRegistryChoiceContext
|
|
1891
|
+
);
|
|
1892
|
+
case "Reject":
|
|
1893
|
+
return this.createRejectTransferInstruction(
|
|
1894
|
+
transferInstructionCid,
|
|
1895
|
+
registryUrl,
|
|
1896
|
+
prefetchedRegistryChoiceContext
|
|
1897
|
+
);
|
|
1898
|
+
case "Withdraw":
|
|
1899
|
+
return this.createWithdrawTransferInstruction(
|
|
1900
|
+
transferInstructionCid,
|
|
1901
|
+
registryUrl,
|
|
1902
|
+
prefetchedRegistryChoiceContext
|
|
1903
|
+
);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1881
1906
|
};
|
|
1882
1907
|
var TokenStandardService = class {
|
|
1883
1908
|
constructor(ledgerClient, logger, accessTokenProvider, isMasterUser) {
|
|
@@ -2405,11 +2430,10 @@ var ACSContainer = class _ACSContainer {
|
|
|
2405
2430
|
}
|
|
2406
2431
|
});
|
|
2407
2432
|
const createdContracts = acs.initialAcs.concat(addedContracts);
|
|
2408
|
-
const result = createdContracts.filter(
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
);
|
|
2433
|
+
const result = createdContracts.filter(({ contractEntry }) => {
|
|
2434
|
+
const id = "JsActiveContract" in contractEntry ? contractEntry.JsActiveContract.createdEvent.contractId : "";
|
|
2435
|
+
return !removedContractIds.has(id);
|
|
2436
|
+
});
|
|
2413
2437
|
return Promise.resolve(result);
|
|
2414
2438
|
}
|
|
2415
2439
|
static extractEvents(fromOffset, updates) {
|
|
@@ -2686,7 +2710,7 @@ var ACSHelper = class _ACSHelper {
|
|
|
2686
2710
|
cacheSize: this.contractsSet.size,
|
|
2687
2711
|
hitRate: hitRate.toFixed(2) + "%",
|
|
2688
2712
|
averageLookupTime: avgLookupTime.toFixed(3) + " ms",
|
|
2689
|
-
cacheServeTime:
|
|
2713
|
+
cacheServeTime: SharedACSCacheStats.totalCacheServeTime.toFixed(3)
|
|
2690
2714
|
};
|
|
2691
2715
|
}
|
|
2692
2716
|
static createKey(party, templateId, interfaceId) {
|
|
@@ -2714,41 +2738,57 @@ var ACSHelper = class _ACSHelper {
|
|
|
2714
2738
|
this.contractsSet.set(keyStr, newContainer);
|
|
2715
2739
|
return newContainer;
|
|
2716
2740
|
}
|
|
2717
|
-
async
|
|
2718
|
-
const key = _ACSHelper.createKey(partyFilter, templateId, void 0);
|
|
2741
|
+
async updateSingleKey(offset, key) {
|
|
2719
2742
|
const start = performance.now();
|
|
2720
2743
|
const container = this.findACSContainer(key);
|
|
2721
|
-
const result = container.update(
|
|
2744
|
+
const result = await container.update(
|
|
2722
2745
|
offset,
|
|
2723
2746
|
key,
|
|
2724
2747
|
this.apiInstance,
|
|
2725
2748
|
this.wsSupport
|
|
2726
2749
|
);
|
|
2727
2750
|
const end = performance.now();
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
)) {
|
|
2751
|
+
const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href);
|
|
2752
|
+
if (this.contractsSet.has(keyStr)) {
|
|
2731
2753
|
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2732
2754
|
}
|
|
2733
2755
|
return result;
|
|
2734
2756
|
}
|
|
2757
|
+
async queryAcsByKeys(offset, keys) {
|
|
2758
|
+
const result = [];
|
|
2759
|
+
for (const key of keys) {
|
|
2760
|
+
const contracts = await this.updateSingleKey(offset, key);
|
|
2761
|
+
result.push(...contracts);
|
|
2762
|
+
}
|
|
2763
|
+
return result;
|
|
2764
|
+
}
|
|
2765
|
+
async activeContractsForTemplates(offset, parties, templateIds) {
|
|
2766
|
+
const keys = parties.flatMap(
|
|
2767
|
+
(party) => templateIds.map(
|
|
2768
|
+
(templateId) => _ACSHelper.createKey(party, templateId, void 0)
|
|
2769
|
+
)
|
|
2770
|
+
);
|
|
2771
|
+
return this.queryAcsByKeys(offset, keys);
|
|
2772
|
+
}
|
|
2773
|
+
async activeContractsForInterfaces(offset, parties, interfaceIds) {
|
|
2774
|
+
const keys = parties.flatMap(
|
|
2775
|
+
(party) => interfaceIds.map(
|
|
2776
|
+
(interfaceId) => _ACSHelper.createKey(party, void 0, interfaceId)
|
|
2777
|
+
)
|
|
2778
|
+
);
|
|
2779
|
+
return this.queryAcsByKeys(offset, keys);
|
|
2780
|
+
}
|
|
2781
|
+
async activeContractsForTemplate(offset, partyFilter, templateId) {
|
|
2782
|
+
return this.updateSingleKey(
|
|
2783
|
+
offset,
|
|
2784
|
+
_ACSHelper.createKey(partyFilter, templateId, void 0)
|
|
2785
|
+
);
|
|
2786
|
+
}
|
|
2735
2787
|
async activeContractsForInterface(offset, partyFilter, interfaceId) {
|
|
2736
|
-
|
|
2737
|
-
const start = performance.now();
|
|
2738
|
-
const container = this.findACSContainer(key);
|
|
2739
|
-
const result = container.update(
|
|
2788
|
+
return this.updateSingleKey(
|
|
2740
2789
|
offset,
|
|
2741
|
-
|
|
2742
|
-
this.apiInstance,
|
|
2743
|
-
this.wsSupport
|
|
2790
|
+
_ACSHelper.createKey(partyFilter, void 0, interfaceId)
|
|
2744
2791
|
);
|
|
2745
|
-
const end = performance.now();
|
|
2746
|
-
if (this.contractsSet.has(
|
|
2747
|
-
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
2748
|
-
)) {
|
|
2749
|
-
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2750
|
-
}
|
|
2751
|
-
return result;
|
|
2752
2792
|
}
|
|
2753
2793
|
};
|
|
2754
2794
|
|
|
@@ -3093,52 +3133,48 @@ var LedgerClient = class {
|
|
|
3093
3133
|
return this.valueOrError(resp);
|
|
3094
3134
|
}
|
|
3095
3135
|
}
|
|
3136
|
+
/*
|
|
3137
|
+
if limit is provided, this function performs a one-time query
|
|
3138
|
+
if limit is omitted, results may be served from the ACS cache
|
|
3139
|
+
current cache design doesn't support limiting queries because updates/deltas for the acs at offset x will be incorrect
|
|
3140
|
+
TODO: expose query mode vs subscribe mode to call queryActiveContracts vs subscribeActiveContracts
|
|
3141
|
+
*/
|
|
3096
3142
|
async activeContracts(options) {
|
|
3097
|
-
const {
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
const templateId = templateIds[0];
|
|
3109
|
-
return this.acsHelper.activeContractsForTemplate(
|
|
3110
|
-
offset,
|
|
3111
|
-
party,
|
|
3112
|
-
templateId
|
|
3143
|
+
const { offset, templateIds, parties, interfaceIds, limit } = options;
|
|
3144
|
+
const hasLimit = typeof limit === "number";
|
|
3145
|
+
if (hasLimit) {
|
|
3146
|
+
const filter2 = this.buildActiveContractFilter(options);
|
|
3147
|
+
return await this.postWithRetry(
|
|
3148
|
+
"/v2/state/active-contracts",
|
|
3149
|
+
filter2,
|
|
3150
|
+
defaultRetryableOptions,
|
|
3151
|
+
{
|
|
3152
|
+
query: limit ? { limit: limit.toString() } : {}
|
|
3153
|
+
}
|
|
3113
3154
|
);
|
|
3114
3155
|
}
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
return this.acsHelper.
|
|
3156
|
+
this.logger.debug(options, "options for active contracts");
|
|
3157
|
+
const hasParties = Array.isArray(parties) && parties.length > 0;
|
|
3158
|
+
if (templateIds?.length && hasParties) {
|
|
3159
|
+
return this.acsHelper.activeContractsForTemplates(
|
|
3119
3160
|
offset,
|
|
3120
|
-
|
|
3121
|
-
|
|
3161
|
+
parties,
|
|
3162
|
+
templateIds
|
|
3122
3163
|
);
|
|
3123
3164
|
}
|
|
3124
|
-
if (
|
|
3125
|
-
|
|
3126
|
-
const r = this.acsHelper.activeContractsForInterface(
|
|
3165
|
+
if (interfaceIds?.length && hasParties) {
|
|
3166
|
+
return this.acsHelper.activeContractsForInterfaces(
|
|
3127
3167
|
offset,
|
|
3128
|
-
|
|
3129
|
-
|
|
3168
|
+
parties,
|
|
3169
|
+
interfaceIds
|
|
3130
3170
|
);
|
|
3131
|
-
return r;
|
|
3132
3171
|
}
|
|
3133
3172
|
const filter = this.buildActiveContractFilter(options);
|
|
3134
3173
|
this.logger.debug("falling back to post request");
|
|
3135
3174
|
return await this.postWithRetry(
|
|
3136
3175
|
"/v2/state/active-contracts",
|
|
3137
3176
|
filter,
|
|
3138
|
-
defaultRetryableOptions
|
|
3139
|
-
{
|
|
3140
|
-
query: limit ? { limit: limit.toString() } : {}
|
|
3141
|
-
}
|
|
3177
|
+
defaultRetryableOptions
|
|
3142
3178
|
);
|
|
3143
3179
|
}
|
|
3144
3180
|
buildActiveContractFilter(options) {
|