@canton-network/core-ledger-client 0.20.3 → 0.21.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 +97 -79
- 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 +97 -79
- 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
|
|
@@ -1209,7 +1207,7 @@ var CoreService = class _CoreService {
|
|
|
1209
1207
|
limit: limit ?? 100
|
|
1210
1208
|
};
|
|
1211
1209
|
const acsResponses = await this.ledgerClient.activeContracts(options);
|
|
1212
|
-
const isActiveContractEntry = (acsResponse) => !!acsResponse.contractEntry.JsActiveContract?.createdEvent;
|
|
1210
|
+
const isActiveContractEntry = (acsResponse) => "JsActiveContract" in acsResponse.contractEntry && !!acsResponse.contractEntry.JsActiveContract?.createdEvent;
|
|
1213
1211
|
const activeContractEntries = acsResponses.filter(
|
|
1214
1212
|
isActiveContractEntry
|
|
1215
1213
|
);
|
|
@@ -1225,8 +1223,8 @@ var CoreService = class _CoreService {
|
|
|
1225
1223
|
}
|
|
1226
1224
|
}
|
|
1227
1225
|
async toPrettyTransactions(updates, partyId, ledgerClient) {
|
|
1228
|
-
const isOffsetCheckpointUpdate = (updateResponse) =>
|
|
1229
|
-
const isTransactionUpdate = (updateResponse) => !!updateResponse.update
|
|
1226
|
+
const isOffsetCheckpointUpdate = (updateResponse) => "OffsetCheckpoint" in updateResponse.update;
|
|
1227
|
+
const isTransactionUpdate = (updateResponse) => "Transaction" in updateResponse.update && !!updateResponse.update.Transaction?.value;
|
|
1230
1228
|
const offsetCheckpoints = updates.filter(isOffsetCheckpointUpdate).map((update) => update.update.OffsetCheckpoint.value.offset);
|
|
1231
1229
|
const latestCheckpointOffset = Math.max(...offsetCheckpoints);
|
|
1232
1230
|
const transactions = await Promise.all(
|
|
@@ -1330,9 +1328,10 @@ var AllocationService = class {
|
|
|
1330
1328
|
}
|
|
1331
1329
|
};
|
|
1332
1330
|
}
|
|
1333
|
-
async fetchAllocationFactoryChoiceContext(registryUrl, choiceArgs) {
|
|
1331
|
+
async fetchAllocationFactoryChoiceContext(registryUrl, choiceArgs, excludeDebugFields = true) {
|
|
1334
1332
|
return this.core.getTokenStandardClient(registryUrl).post("/registry/allocation-instruction/v1/allocation-factory", {
|
|
1335
|
-
choiceArguments: choiceArgs
|
|
1333
|
+
choiceArguments: choiceArgs,
|
|
1334
|
+
excludeDebugFields
|
|
1336
1335
|
});
|
|
1337
1336
|
}
|
|
1338
1337
|
async createAllocationInstructionFromContext(factoryId, choiceArgs, choiceContext) {
|
|
@@ -1578,9 +1577,10 @@ var TransferService = class {
|
|
|
1578
1577
|
}
|
|
1579
1578
|
};
|
|
1580
1579
|
}
|
|
1581
|
-
async fetchTransferFactoryChoiceContext(registryUrl, choiceArgs) {
|
|
1580
|
+
async fetchTransferFactoryChoiceContext(registryUrl, choiceArgs, excludeDebugFields = true) {
|
|
1582
1581
|
return await this.core.getTokenStandardClient(registryUrl).post("/registry/transfer-instruction/v1/transfer-factory", {
|
|
1583
|
-
choiceArguments: choiceArgs
|
|
1582
|
+
choiceArguments: choiceArgs,
|
|
1583
|
+
excludeDebugFields
|
|
1584
1584
|
});
|
|
1585
1585
|
}
|
|
1586
1586
|
async createTransferFromContext(factoryId, choiceArgs, choiceContext) {
|
|
@@ -1878,6 +1878,28 @@ var TransferService = class {
|
|
|
1878
1878
|
choiceContext
|
|
1879
1879
|
);
|
|
1880
1880
|
}
|
|
1881
|
+
async createTransferInstruction(transferInstructionCid, registryUrl, instructionChoice, prefetchedRegistryChoiceContext) {
|
|
1882
|
+
switch (instructionChoice) {
|
|
1883
|
+
case "Accept":
|
|
1884
|
+
return this.createAcceptTransferInstruction(
|
|
1885
|
+
transferInstructionCid,
|
|
1886
|
+
registryUrl,
|
|
1887
|
+
prefetchedRegistryChoiceContext
|
|
1888
|
+
);
|
|
1889
|
+
case "Reject":
|
|
1890
|
+
return this.createRejectTransferInstruction(
|
|
1891
|
+
transferInstructionCid,
|
|
1892
|
+
registryUrl,
|
|
1893
|
+
prefetchedRegistryChoiceContext
|
|
1894
|
+
);
|
|
1895
|
+
case "Withdraw":
|
|
1896
|
+
return this.createWithdrawTransferInstruction(
|
|
1897
|
+
transferInstructionCid,
|
|
1898
|
+
registryUrl,
|
|
1899
|
+
prefetchedRegistryChoiceContext
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1881
1903
|
};
|
|
1882
1904
|
var TokenStandardService = class {
|
|
1883
1905
|
constructor(ledgerClient, logger, accessTokenProvider, isMasterUser) {
|
|
@@ -2405,11 +2427,10 @@ var ACSContainer = class _ACSContainer {
|
|
|
2405
2427
|
}
|
|
2406
2428
|
});
|
|
2407
2429
|
const createdContracts = acs.initialAcs.concat(addedContracts);
|
|
2408
|
-
const result = createdContracts.filter(
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
);
|
|
2430
|
+
const result = createdContracts.filter(({ contractEntry }) => {
|
|
2431
|
+
const id = "JsActiveContract" in contractEntry ? contractEntry.JsActiveContract.createdEvent.contractId : "";
|
|
2432
|
+
return !removedContractIds.has(id);
|
|
2433
|
+
});
|
|
2413
2434
|
return Promise.resolve(result);
|
|
2414
2435
|
}
|
|
2415
2436
|
static extractEvents(fromOffset, updates) {
|
|
@@ -2686,7 +2707,7 @@ var ACSHelper = class _ACSHelper {
|
|
|
2686
2707
|
cacheSize: this.contractsSet.size,
|
|
2687
2708
|
hitRate: hitRate.toFixed(2) + "%",
|
|
2688
2709
|
averageLookupTime: avgLookupTime.toFixed(3) + " ms",
|
|
2689
|
-
cacheServeTime:
|
|
2710
|
+
cacheServeTime: SharedACSCacheStats.totalCacheServeTime.toFixed(3)
|
|
2690
2711
|
};
|
|
2691
2712
|
}
|
|
2692
2713
|
static createKey(party, templateId, interfaceId) {
|
|
@@ -2714,41 +2735,57 @@ var ACSHelper = class _ACSHelper {
|
|
|
2714
2735
|
this.contractsSet.set(keyStr, newContainer);
|
|
2715
2736
|
return newContainer;
|
|
2716
2737
|
}
|
|
2717
|
-
async
|
|
2718
|
-
const key = _ACSHelper.createKey(partyFilter, templateId, void 0);
|
|
2738
|
+
async updateSingleKey(offset, key) {
|
|
2719
2739
|
const start = performance.now();
|
|
2720
2740
|
const container = this.findACSContainer(key);
|
|
2721
|
-
const result = container.update(
|
|
2741
|
+
const result = await container.update(
|
|
2722
2742
|
offset,
|
|
2723
2743
|
key,
|
|
2724
2744
|
this.apiInstance,
|
|
2725
2745
|
this.wsSupport
|
|
2726
2746
|
);
|
|
2727
2747
|
const end = performance.now();
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
)) {
|
|
2748
|
+
const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href);
|
|
2749
|
+
if (this.contractsSet.has(keyStr)) {
|
|
2731
2750
|
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2732
2751
|
}
|
|
2733
2752
|
return result;
|
|
2734
2753
|
}
|
|
2754
|
+
async queryAcsByKeys(offset, keys) {
|
|
2755
|
+
const result = [];
|
|
2756
|
+
for (const key of keys) {
|
|
2757
|
+
const contracts = await this.updateSingleKey(offset, key);
|
|
2758
|
+
result.push(...contracts);
|
|
2759
|
+
}
|
|
2760
|
+
return result;
|
|
2761
|
+
}
|
|
2762
|
+
async activeContractsForTemplates(offset, parties, templateIds) {
|
|
2763
|
+
const keys = parties.flatMap(
|
|
2764
|
+
(party) => templateIds.map(
|
|
2765
|
+
(templateId) => _ACSHelper.createKey(party, templateId, void 0)
|
|
2766
|
+
)
|
|
2767
|
+
);
|
|
2768
|
+
return this.queryAcsByKeys(offset, keys);
|
|
2769
|
+
}
|
|
2770
|
+
async activeContractsForInterfaces(offset, parties, interfaceIds) {
|
|
2771
|
+
const keys = parties.flatMap(
|
|
2772
|
+
(party) => interfaceIds.map(
|
|
2773
|
+
(interfaceId) => _ACSHelper.createKey(party, void 0, interfaceId)
|
|
2774
|
+
)
|
|
2775
|
+
);
|
|
2776
|
+
return this.queryAcsByKeys(offset, keys);
|
|
2777
|
+
}
|
|
2778
|
+
async activeContractsForTemplate(offset, partyFilter, templateId) {
|
|
2779
|
+
return this.updateSingleKey(
|
|
2780
|
+
offset,
|
|
2781
|
+
_ACSHelper.createKey(partyFilter, templateId, void 0)
|
|
2782
|
+
);
|
|
2783
|
+
}
|
|
2735
2784
|
async activeContractsForInterface(offset, partyFilter, interfaceId) {
|
|
2736
|
-
|
|
2737
|
-
const start = performance.now();
|
|
2738
|
-
const container = this.findACSContainer(key);
|
|
2739
|
-
const result = container.update(
|
|
2785
|
+
return this.updateSingleKey(
|
|
2740
2786
|
offset,
|
|
2741
|
-
|
|
2742
|
-
this.apiInstance,
|
|
2743
|
-
this.wsSupport
|
|
2787
|
+
_ACSHelper.createKey(partyFilter, void 0, interfaceId)
|
|
2744
2788
|
);
|
|
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
2789
|
}
|
|
2753
2790
|
};
|
|
2754
2791
|
|
|
@@ -3094,41 +3131,22 @@ var LedgerClient = class {
|
|
|
3094
3131
|
}
|
|
3095
3132
|
}
|
|
3096
3133
|
async activeContracts(options) {
|
|
3097
|
-
const {
|
|
3098
|
-
offset,
|
|
3099
|
-
templateIds,
|
|
3100
|
-
parties,
|
|
3101
|
-
filterByParty,
|
|
3102
|
-
interfaceIds,
|
|
3103
|
-
limit
|
|
3104
|
-
} = options;
|
|
3134
|
+
const { offset, templateIds, parties, interfaceIds, limit } = options;
|
|
3105
3135
|
this.logger.debug(options, "options for active contracts");
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
return this.acsHelper.activeContractsForTemplate(
|
|
3136
|
+
const hasParties = Array.isArray(parties) && parties.length > 0;
|
|
3137
|
+
if (templateIds?.length && hasParties) {
|
|
3138
|
+
return this.acsHelper.activeContractsForTemplates(
|
|
3110
3139
|
offset,
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
);
|
|
3114
|
-
}
|
|
3115
|
-
if (interfaceIds?.length === 1 && parties?.length === 1) {
|
|
3116
|
-
const party = parties[0];
|
|
3117
|
-
const interfaceId = interfaceIds[0];
|
|
3118
|
-
return this.acsHelper.activeContractsForInterface(
|
|
3119
|
-
offset,
|
|
3120
|
-
party,
|
|
3121
|
-
interfaceId
|
|
3140
|
+
parties,
|
|
3141
|
+
templateIds
|
|
3122
3142
|
);
|
|
3123
3143
|
}
|
|
3124
|
-
if (
|
|
3125
|
-
|
|
3126
|
-
const r = this.acsHelper.activeContractsForInterface(
|
|
3144
|
+
if (interfaceIds?.length && hasParties) {
|
|
3145
|
+
return this.acsHelper.activeContractsForInterfaces(
|
|
3127
3146
|
offset,
|
|
3128
|
-
|
|
3129
|
-
|
|
3147
|
+
parties,
|
|
3148
|
+
interfaceIds
|
|
3130
3149
|
);
|
|
3131
|
-
return r;
|
|
3132
3150
|
}
|
|
3133
3151
|
const filter = this.buildActiveContractFilter(options);
|
|
3134
3152
|
this.logger.debug("falling back to post request");
|