@canton-network/core-ledger-client 0.27.1 → 0.27.3
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-helper.d.ts +4 -4
- package/dist/acs/acs-helper.d.ts.map +1 -1
- package/dist/index.cjs +110 -256
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +103 -253
- package/dist/index.js.map +1 -1
- package/dist/ledger-api-utils.d.ts +0 -20
- package/dist/ledger-api-utils.d.ts.map +1 -1
- package/dist/ledger-client.d.ts +12 -2
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts +6 -6
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/txparse/parser.d.ts +2 -2
- package/dist/txparse/parser.d.ts.map +1 -1
- package/dist/txparse/types.d.ts +3 -3
- package/dist/txparse/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/generated-clients/asyncapi-3.4.7.d.ts +0 -994
- package/dist/generated-clients/asyncapi-3.4.7.d.ts.map +0 -1
- package/dist/generated-clients/openapi-3.3.0-SNAPSHOT.d.ts +0 -6114
- package/dist/generated-clients/openapi-3.3.0-SNAPSHOT.d.ts.map +0 -1
- package/dist/generated-clients/openapi-3.4.7.d.ts +0 -7143
- package/dist/generated-clients/openapi-3.4.7.d.ts.map +0 -1
- package/dist/web-socket-client.d.ts +0 -44
- package/dist/web-socket-client.d.ts.map +0 -1
package/dist/acs/acs-helper.d.ts
CHANGED
|
@@ -34,17 +34,17 @@ export declare class ACSHelper {
|
|
|
34
34
|
private findACSContainer;
|
|
35
35
|
updateSingleKey(offset: number, key: ACSKey): Promise<({
|
|
36
36
|
workflowId: string;
|
|
37
|
-
contractEntry: import("
|
|
37
|
+
contractEntry: import("../../../ledger-client-types/dist/generated-clients/openapi-3.3.0-SNAPSHOT").components["schemas"]["JsContractEntry"];
|
|
38
38
|
} | {
|
|
39
39
|
workflowId: string;
|
|
40
|
-
contractEntry: import("
|
|
40
|
+
contractEntry: import("../../../ledger-client-types/dist/generated-clients/openapi-3.4.11").components["schemas"]["JsContractEntry"];
|
|
41
41
|
})[]>;
|
|
42
42
|
queryAcsByKeys(offset: number, keys: ACSKey[]): Promise<({
|
|
43
43
|
workflowId: string;
|
|
44
|
-
contractEntry: import("
|
|
44
|
+
contractEntry: import("../../../ledger-client-types/dist/generated-clients/openapi-3.3.0-SNAPSHOT").components["schemas"]["JsContractEntry"];
|
|
45
45
|
} | {
|
|
46
46
|
workflowId: string;
|
|
47
|
-
contractEntry: import("
|
|
47
|
+
contractEntry: import("../../../ledger-client-types/dist/generated-clients/openapi-3.4.11").components["schemas"]["JsContractEntry"];
|
|
48
48
|
})[]>;
|
|
49
49
|
activeContractsForTemplates(offset: number, parties: PartyId[], templateIds: string[]): Promise<JsGetActiveContractsResponse[]>;
|
|
50
50
|
activeContractsForInterfaces(offset: number, parties: PartyId[], interfaceIds: string[]): Promise<JsGetActiveContractsResponse[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,MAAM,gBAAgB,GAAG;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB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AE,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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var coreTokenStandard = require('@canton-network/core-token-standard');
|
|
4
|
+
var coreLedgerClientTypes = require('@canton-network/core-ledger-client-types');
|
|
4
5
|
var coreLedgerProto = require('@canton-network/core-ledger-proto');
|
|
5
6
|
var BigNumber = require('bignumber.js');
|
|
6
7
|
var createClient = require('openapi-fetch');
|
|
@@ -50,131 +51,6 @@ var AllKnownMetaKeys = [
|
|
|
50
51
|
ReasonMetaKey,
|
|
51
52
|
BurnedMetaKey
|
|
52
53
|
];
|
|
53
|
-
function createIdentiferFilter(type, id) {
|
|
54
|
-
if (type === "Template") {
|
|
55
|
-
return {
|
|
56
|
-
identifierFilter: {
|
|
57
|
-
TemplateFilter: {
|
|
58
|
-
value: {
|
|
59
|
-
templateId: id,
|
|
60
|
-
includeCreatedEventBlob: true
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
} else {
|
|
66
|
-
return {
|
|
67
|
-
identifierFilter: {
|
|
68
|
-
InterfaceFilter: {
|
|
69
|
-
value: {
|
|
70
|
-
interfaceId: id,
|
|
71
|
-
includeInterfaceView: true,
|
|
72
|
-
includeCreatedEventBlob: true
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function createWildcardFilter() {
|
|
80
|
-
return {
|
|
81
|
-
identifierFilter: {
|
|
82
|
-
WildcardFilter: {
|
|
83
|
-
value: {
|
|
84
|
-
includeCreatedEventBlob: true
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function buildCumulativeFilters(templateIds, interfaceIds, includeWildcard) {
|
|
91
|
-
if (templateIds.length > 0) {
|
|
92
|
-
return [
|
|
93
|
-
...templateIds.map(
|
|
94
|
-
(templateId) => createIdentiferFilter("Template", templateId)
|
|
95
|
-
),
|
|
96
|
-
...includeWildcard ? [createWildcardFilter()] : []
|
|
97
|
-
];
|
|
98
|
-
} else {
|
|
99
|
-
return [
|
|
100
|
-
...interfaceIds.map(
|
|
101
|
-
(interfaceId) => createIdentiferFilter("Interface", interfaceId)
|
|
102
|
-
),
|
|
103
|
-
...includeWildcard ? [createWildcardFilter()] : []
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function buildFilter(templateIds, interfaceIds, options, additionalProps) {
|
|
108
|
-
const { isMasterUser = false, partyId, includeWildcard = false } = options;
|
|
109
|
-
if (isMasterUser) {
|
|
110
|
-
return {
|
|
111
|
-
filtersByParty: {},
|
|
112
|
-
filtersForAnyParty: filtersForAnyParty(
|
|
113
|
-
templateIds,
|
|
114
|
-
interfaceIds,
|
|
115
|
-
includeWildcard
|
|
116
|
-
),
|
|
117
|
-
...additionalProps
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
if (!partyId) {
|
|
121
|
-
throw new Error("Party must be provided for non-master users");
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
filtersByParty: filtersByParty(
|
|
125
|
-
partyId,
|
|
126
|
-
templateIds,
|
|
127
|
-
interfaceIds,
|
|
128
|
-
includeWildcard
|
|
129
|
-
),
|
|
130
|
-
...additionalProps
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function TransactionFilterBySetup(options) {
|
|
134
|
-
const { templateIds, interfaceIds, ...baseOptions } = options;
|
|
135
|
-
return buildFilter(
|
|
136
|
-
normalizeToArray(templateIds || []),
|
|
137
|
-
normalizeToArray(interfaceIds || []),
|
|
138
|
-
baseOptions
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
function EventFilterBySetup(options) {
|
|
142
|
-
const {
|
|
143
|
-
templateIds,
|
|
144
|
-
interfaceIds,
|
|
145
|
-
verbose = false,
|
|
146
|
-
...baseOptions
|
|
147
|
-
} = options;
|
|
148
|
-
return buildFilter(
|
|
149
|
-
normalizeToArray(templateIds || []),
|
|
150
|
-
normalizeToArray(interfaceIds || []),
|
|
151
|
-
baseOptions,
|
|
152
|
-
{ verbose }
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
function filtersByParty(party, templateIds, interfaceIds, includeWildcard) {
|
|
156
|
-
return {
|
|
157
|
-
[party]: {
|
|
158
|
-
cumulative: buildCumulativeFilters(
|
|
159
|
-
templateIds,
|
|
160
|
-
interfaceIds,
|
|
161
|
-
includeWildcard
|
|
162
|
-
)
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function filtersForAnyParty(interfaceNames, templateIds, includeWildcard) {
|
|
167
|
-
return {
|
|
168
|
-
cumulative: buildCumulativeFilters(
|
|
169
|
-
templateIds,
|
|
170
|
-
interfaceNames,
|
|
171
|
-
includeWildcard
|
|
172
|
-
)
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function normalizeToArray(value) {
|
|
176
|
-
return Array.isArray(value) ? value : [value];
|
|
177
|
-
}
|
|
178
54
|
function hasInterface(interfaceId, event) {
|
|
179
55
|
return (event.implementedInterfaces || []).some(
|
|
180
56
|
(id) => matchInterfaceIds(id, interfaceId)
|
|
@@ -1023,7 +899,7 @@ var TransactionParser = class {
|
|
|
1023
899
|
}
|
|
1024
900
|
const basePayload = {
|
|
1025
901
|
contractId: archivedEvent.contractId,
|
|
1026
|
-
eventFormat: EventFilterBySetup({
|
|
902
|
+
eventFormat: coreLedgerClientTypes.EventFilterBySetup({
|
|
1027
903
|
interfaceIds: [
|
|
1028
904
|
coreTokenStandard.HOLDING_INTERFACE_ID,
|
|
1029
905
|
coreTokenStandard.TRANSFER_INSTRUCTION_INTERFACE_ID
|
|
@@ -1259,14 +1135,17 @@ var CoreService = class _CoreService {
|
|
|
1259
1135
|
);
|
|
1260
1136
|
}
|
|
1261
1137
|
// TODO: probably needs a filter by instrument ID as well?
|
|
1262
|
-
async getInputHoldingsCids(sender, inputUtxos, amount) {
|
|
1138
|
+
async getInputHoldingsCids(sender, inputUtxos, amount, continueUntilCompletion) {
|
|
1263
1139
|
const now = /* @__PURE__ */ new Date();
|
|
1264
1140
|
if (inputUtxos && inputUtxos.length > 0) {
|
|
1265
1141
|
return inputUtxos;
|
|
1266
1142
|
}
|
|
1267
1143
|
const senderHoldings = await this.listContractsByInterface(
|
|
1268
1144
|
coreTokenStandard.HOLDING_INTERFACE_ID,
|
|
1269
|
-
sender
|
|
1145
|
+
sender,
|
|
1146
|
+
void 0,
|
|
1147
|
+
void 0,
|
|
1148
|
+
continueUntilCompletion
|
|
1270
1149
|
);
|
|
1271
1150
|
if (senderHoldings.length === 0) {
|
|
1272
1151
|
throw new Error(
|
|
@@ -1331,14 +1210,15 @@ var CoreService = class _CoreService {
|
|
|
1331
1210
|
}
|
|
1332
1211
|
return cIds;
|
|
1333
1212
|
}
|
|
1334
|
-
async listContractsByInterface(interfaceId, partyId, limit, offset) {
|
|
1213
|
+
async listContractsByInterface(interfaceId, partyId, limit, offset, continueUntilCompletion) {
|
|
1335
1214
|
try {
|
|
1336
1215
|
const ledgerEnd = offset ?? (await this.ledgerClient.getWithRetry("/v2/state/ledger-end")).offset;
|
|
1337
1216
|
const options = {
|
|
1338
1217
|
offset: ledgerEnd,
|
|
1339
1218
|
interfaceIds: [interfaceId],
|
|
1340
1219
|
parties: [partyId],
|
|
1341
|
-
filterByParty: true
|
|
1220
|
+
filterByParty: true,
|
|
1221
|
+
continueUntilCompletion: Boolean(continueUntilCompletion)
|
|
1342
1222
|
};
|
|
1343
1223
|
if (limit !== void 0) {
|
|
1344
1224
|
options.limit = limit;
|
|
@@ -1689,11 +1569,12 @@ var TransferService = class {
|
|
|
1689
1569
|
this.core = core;
|
|
1690
1570
|
this.logger = logger;
|
|
1691
1571
|
}
|
|
1692
|
-
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta) {
|
|
1572
|
+
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta, continueUntilCompletion) {
|
|
1693
1573
|
const inputHoldingCids = await this.core.getInputHoldingsCids(
|
|
1694
1574
|
sender,
|
|
1695
1575
|
inputUtxos,
|
|
1696
|
-
parseFloat(amount)
|
|
1576
|
+
parseFloat(amount),
|
|
1577
|
+
continueUntilCompletion
|
|
1697
1578
|
);
|
|
1698
1579
|
return {
|
|
1699
1580
|
expectedAdmin: instrumentAdmin,
|
|
@@ -1741,7 +1622,7 @@ var TransferService = class {
|
|
|
1741
1622
|
return [exercise, choiceContext.disclosedContracts];
|
|
1742
1623
|
}
|
|
1743
1624
|
// TODO: use named parameters
|
|
1744
|
-
async createTransfer(sender, receiver, amount, instrumentAdmin, instrumentId, registryUrl, inputUtxos, memo, expiryDate, meta, prefetchedRegistryChoiceContext) {
|
|
1625
|
+
async createTransfer(sender, receiver, amount, instrumentAdmin, instrumentId, registryUrl, inputUtxos, memo, expiryDate, meta, prefetchedRegistryChoiceContext, continueUntilCompletion) {
|
|
1745
1626
|
try {
|
|
1746
1627
|
const choiceArgs = await this.buildTransferChoiceArgs(
|
|
1747
1628
|
sender,
|
|
@@ -1752,7 +1633,8 @@ var TransferService = class {
|
|
|
1752
1633
|
inputUtxos,
|
|
1753
1634
|
memo,
|
|
1754
1635
|
expiryDate,
|
|
1755
|
-
meta
|
|
1636
|
+
meta,
|
|
1637
|
+
continueUntilCompletion
|
|
1756
1638
|
);
|
|
1757
1639
|
if (prefetchedRegistryChoiceContext) {
|
|
1758
1640
|
return this.createTransferFromContext(
|
|
@@ -2106,12 +1988,13 @@ var TokenStandardService = class {
|
|
|
2106
1988
|
}
|
|
2107
1989
|
// <T> is shape of viewValue related to queried interface.
|
|
2108
1990
|
// i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
|
|
2109
|
-
async listContractsByInterface(interfaceId, partyId, limit, offset) {
|
|
1991
|
+
async listContractsByInterface(interfaceId, partyId, limit, offset, continueUntilCompletion) {
|
|
2110
1992
|
return this.core.listContractsByInterface(
|
|
2111
1993
|
interfaceId,
|
|
2112
1994
|
partyId,
|
|
2113
1995
|
limit,
|
|
2114
|
-
offset
|
|
1996
|
+
offset,
|
|
1997
|
+
continueUntilCompletion
|
|
2115
1998
|
);
|
|
2116
1999
|
}
|
|
2117
2000
|
async listHoldingTransactions(partyId, afterOffset, beforeOffset) {
|
|
@@ -2125,7 +2008,7 @@ var TokenStandardService = class {
|
|
|
2125
2008
|
const updatesResponse = await this.ledgerClient.postWithRetry("/v2/updates/flats", {
|
|
2126
2009
|
updateFormat: {
|
|
2127
2010
|
includeTransactions: {
|
|
2128
|
-
eventFormat: EventFilterBySetup({
|
|
2011
|
+
eventFormat: coreLedgerClientTypes.EventFilterBySetup({
|
|
2129
2012
|
interfaceIds: TokenStandardTransactionInterfaces,
|
|
2130
2013
|
isMasterUser: this.isMasterUser,
|
|
2131
2014
|
partyId,
|
|
@@ -2150,7 +2033,7 @@ var TokenStandardService = class {
|
|
|
2150
2033
|
}
|
|
2151
2034
|
async getTransactionById(updateId, partyId) {
|
|
2152
2035
|
const transactionFormat = {
|
|
2153
|
-
eventFormat: EventFilterBySetup({
|
|
2036
|
+
eventFormat: coreLedgerClientTypes.EventFilterBySetup({
|
|
2154
2037
|
interfaceIds: TokenStandardTransactionInterfaces,
|
|
2155
2038
|
isMasterUser: this.isMasterUser,
|
|
2156
2039
|
partyId,
|
|
@@ -3291,13 +3174,27 @@ var LedgerClient = class {
|
|
|
3291
3174
|
}
|
|
3292
3175
|
}
|
|
3293
3176
|
/*
|
|
3294
|
-
if limit is provided, this function performs a one-time query
|
|
3177
|
+
if limit is provided, this function performs a one-time query. Automatically splits into multiple `/v2/updates` calls with `continueUntilCompletion` on.
|
|
3295
3178
|
if limit is omitted, results may be served from the ACS cache
|
|
3296
3179
|
current cache design doesn't support limiting queries because updates/deltas for the acs at offset x will be incorrect
|
|
3297
3180
|
TODO: expose query mode vs subscribe mode to call queryActiveContracts vs subscribeActiveContracts
|
|
3298
3181
|
*/
|
|
3299
3182
|
async activeContracts(options) {
|
|
3300
|
-
const {
|
|
3183
|
+
const {
|
|
3184
|
+
offset,
|
|
3185
|
+
templateIds,
|
|
3186
|
+
parties,
|
|
3187
|
+
interfaceIds,
|
|
3188
|
+
limit,
|
|
3189
|
+
continueUntilCompletion
|
|
3190
|
+
} = options;
|
|
3191
|
+
if (continueUntilCompletion) {
|
|
3192
|
+
const filter2 = this.buildActiveContractFilter(options);
|
|
3193
|
+
return await this.fetchActiveContractsUntilComplete(
|
|
3194
|
+
filter2,
|
|
3195
|
+
limit ?? 200
|
|
3196
|
+
);
|
|
3197
|
+
}
|
|
3301
3198
|
const hasLimit = typeof limit === "number";
|
|
3302
3199
|
if (hasLimit) {
|
|
3303
3200
|
const filter2 = this.buildActiveContractFilter(options);
|
|
@@ -3305,9 +3202,7 @@ var LedgerClient = class {
|
|
|
3305
3202
|
"/v2/state/active-contracts",
|
|
3306
3203
|
filter2,
|
|
3307
3204
|
defaultRetryableOptions,
|
|
3308
|
-
{
|
|
3309
|
-
query: limit ? { limit: limit.toString() } : {}
|
|
3310
|
-
}
|
|
3205
|
+
{ query: { limit: limit.toString() } }
|
|
3311
3206
|
);
|
|
3312
3207
|
}
|
|
3313
3208
|
this.logger.debug(options, "options for active contracts");
|
|
@@ -3334,6 +3229,72 @@ var LedgerClient = class {
|
|
|
3334
3229
|
defaultRetryableOptions
|
|
3335
3230
|
);
|
|
3336
3231
|
}
|
|
3232
|
+
/**
|
|
3233
|
+
* Fetches active contracts by splitting requests into multiple `/v2/updates` calls.
|
|
3234
|
+
* Should only be used when the number of contracts exceeds http-list-max-elements-limit (200 by default).
|
|
3235
|
+
* For limits at or below http-list-max-elements-limit, use a single `/v2/state/active-contracts` call instead.
|
|
3236
|
+
* @param activeContractsArgs The request parameters for active contracts query
|
|
3237
|
+
* @returns A promise that resolves to an array of active contract responses
|
|
3238
|
+
* @private
|
|
3239
|
+
*/
|
|
3240
|
+
async fetchActiveContractsUntilComplete(activeContractsArgs, limit) {
|
|
3241
|
+
const ledgerEnd = await this.getWithRetry("/v2/state/ledger-end");
|
|
3242
|
+
const bodyRequest = {
|
|
3243
|
+
beginExclusive: 0,
|
|
3244
|
+
endInclusive: ledgerEnd.offset,
|
|
3245
|
+
verbose: false
|
|
3246
|
+
};
|
|
3247
|
+
if (activeContractsArgs.filter)
|
|
3248
|
+
bodyRequest.filter = activeContractsArgs.filter;
|
|
3249
|
+
let currentOffset = 0;
|
|
3250
|
+
const allContractsData = /* @__PURE__ */ new Map();
|
|
3251
|
+
const exercisedContracts = /* @__PURE__ */ new Set();
|
|
3252
|
+
while (currentOffset < ledgerEnd.offset) {
|
|
3253
|
+
bodyRequest.beginExclusive = currentOffset;
|
|
3254
|
+
const results = (await this.postWithRetry(
|
|
3255
|
+
"/v2/updates",
|
|
3256
|
+
bodyRequest,
|
|
3257
|
+
defaultRetryableOptions,
|
|
3258
|
+
{
|
|
3259
|
+
query: { limit: limit.toString() }
|
|
3260
|
+
}
|
|
3261
|
+
)).filter(({ update }) => "Transaction" in update).map(({ update }) => {
|
|
3262
|
+
if ("Transaction" in update) {
|
|
3263
|
+
return update.Transaction.value;
|
|
3264
|
+
}
|
|
3265
|
+
throw new Error("Expected Transaction update");
|
|
3266
|
+
}).map((data) => {
|
|
3267
|
+
const exercisedEvents = data.events?.filter((event) => "ExercisedEvent" in event).map(
|
|
3268
|
+
(event) => event.ExercisedEvent
|
|
3269
|
+
).filter((event) => event.consuming);
|
|
3270
|
+
const createdEvents = data.events?.filter((event) => "CreatedEvent" in event).map(
|
|
3271
|
+
(event) => event.CreatedEvent
|
|
3272
|
+
);
|
|
3273
|
+
exercisedEvents?.forEach((event) => {
|
|
3274
|
+
exercisedContracts.add(event.contractId);
|
|
3275
|
+
});
|
|
3276
|
+
createdEvents?.forEach((event) => {
|
|
3277
|
+
allContractsData.set(event.contractId, {
|
|
3278
|
+
workflowId: data.workflowId,
|
|
3279
|
+
contractEntry: {
|
|
3280
|
+
JsActiveContract: {
|
|
3281
|
+
synchronizerId: data.synchronizerId,
|
|
3282
|
+
createdEvent: event,
|
|
3283
|
+
reassignmentCounter: data.offset
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
});
|
|
3287
|
+
});
|
|
3288
|
+
currentOffset = Math.max(currentOffset, data.offset);
|
|
3289
|
+
return true;
|
|
3290
|
+
});
|
|
3291
|
+
if (!results.length) currentOffset++;
|
|
3292
|
+
}
|
|
3293
|
+
exercisedContracts.forEach((cid) => {
|
|
3294
|
+
allContractsData.delete(cid);
|
|
3295
|
+
});
|
|
3296
|
+
return Array.from(allContractsData.values());
|
|
3297
|
+
}
|
|
3337
3298
|
buildActiveContractFilter(options) {
|
|
3338
3299
|
const filter = {
|
|
3339
3300
|
filter: {
|
|
@@ -3493,118 +3454,6 @@ var WSSupportWithBackOffSwitch = class {
|
|
|
3493
3454
|
}
|
|
3494
3455
|
};
|
|
3495
3456
|
|
|
3496
|
-
// src/generated-clients/asyncapi-3.4.7.ts
|
|
3497
|
-
var CHANNELS = {
|
|
3498
|
-
v2_commands_completions: "/v2/commands/completions",
|
|
3499
|
-
v2_updates: "/v2/updates"};
|
|
3500
|
-
|
|
3501
|
-
// src/web-socket-client.ts
|
|
3502
|
-
var WebSocketClient = class {
|
|
3503
|
-
constructor({
|
|
3504
|
-
baseUrl,
|
|
3505
|
-
isAdmin,
|
|
3506
|
-
accessTokenProvider,
|
|
3507
|
-
logger,
|
|
3508
|
-
wsSupportBackOff
|
|
3509
|
-
}) {
|
|
3510
|
-
__publicField(this, "ws", null);
|
|
3511
|
-
__publicField(this, "baseUrl");
|
|
3512
|
-
__publicField(this, "token", "");
|
|
3513
|
-
__publicField(this, "isAdmin");
|
|
3514
|
-
__publicField(this, "protocol", []);
|
|
3515
|
-
__publicField(this, "logger");
|
|
3516
|
-
__publicField(this, "wsSupportBackOff");
|
|
3517
|
-
__publicField(this, "accessTokenProvider");
|
|
3518
|
-
this.logger = logger.child({ component: "WebSocketClient" });
|
|
3519
|
-
this.baseUrl = baseUrl;
|
|
3520
|
-
this.wsSupportBackOff = wsSupportBackOff;
|
|
3521
|
-
this.accessTokenProvider = accessTokenProvider;
|
|
3522
|
-
this.isAdmin = isAdmin ?? false;
|
|
3523
|
-
}
|
|
3524
|
-
async init() {
|
|
3525
|
-
this.token = this.isAdmin ? await this.accessTokenProvider.getAdminAccessToken() : await this.accessTokenProvider.getUserAccessToken();
|
|
3526
|
-
this.protocol = [`jwt.token.${this.token}`, "daml.ws.auth"];
|
|
3527
|
-
this.logger.info(
|
|
3528
|
-
`initializing websocket client with ${this.protocol.length} protocols`
|
|
3529
|
-
);
|
|
3530
|
-
}
|
|
3531
|
-
generate(wsUrl, request) {
|
|
3532
|
-
const messageQueue = [];
|
|
3533
|
-
let resolveNext = null;
|
|
3534
|
-
let isClosed = false;
|
|
3535
|
-
let streamError = null;
|
|
3536
|
-
const generator = async function* () {
|
|
3537
|
-
await this.init();
|
|
3538
|
-
this.logger.debug(request);
|
|
3539
|
-
const ws = new WebSocket(wsUrl, this.protocol);
|
|
3540
|
-
ws.onopen = () => {
|
|
3541
|
-
ws.send(JSON.stringify(request));
|
|
3542
|
-
};
|
|
3543
|
-
ws.onmessage = (event) => {
|
|
3544
|
-
messageQueue.push(JSON.parse(event.data));
|
|
3545
|
-
this.logger.debug(event.data, `Received event`);
|
|
3546
|
-
resolveNext?.();
|
|
3547
|
-
};
|
|
3548
|
-
ws.onerror = () => {
|
|
3549
|
-
streamError = new Error("WebSocket Handshake/Connection failed");
|
|
3550
|
-
this.logger.error(`Encountered ws.onError`);
|
|
3551
|
-
isClosed = true;
|
|
3552
|
-
resolveNext?.();
|
|
3553
|
-
};
|
|
3554
|
-
ws.onclose = (event) => {
|
|
3555
|
-
this.logger.debug(
|
|
3556
|
-
`CLOSING WEBSOCKET CONNECTION code: ${event.code}, reason: ${event.reason}`
|
|
3557
|
-
);
|
|
3558
|
-
isClosed = true;
|
|
3559
|
-
resolveNext?.();
|
|
3560
|
-
};
|
|
3561
|
-
try {
|
|
3562
|
-
while (true) {
|
|
3563
|
-
if (messageQueue.length === 0) {
|
|
3564
|
-
if (isClosed) break;
|
|
3565
|
-
await new Promise((r) => resolveNext = r);
|
|
3566
|
-
}
|
|
3567
|
-
if (streamError) throw streamError;
|
|
3568
|
-
while (messageQueue.length > 0) {
|
|
3569
|
-
yield messageQueue.shift();
|
|
3570
|
-
}
|
|
3571
|
-
if (isClosed && messageQueue.length === 0) break;
|
|
3572
|
-
}
|
|
3573
|
-
} finally {
|
|
3574
|
-
if (ws.readyState === WebSocket.OPEN) ws.close();
|
|
3575
|
-
this.logger.info("Generator cleanup: WebSocket closed.");
|
|
3576
|
-
}
|
|
3577
|
-
};
|
|
3578
|
-
return generator.call(this);
|
|
3579
|
-
}
|
|
3580
|
-
streamUpdates(options) {
|
|
3581
|
-
const wsUpdatesUrl = `${this.baseUrl}${CHANNELS.v2_updates}`;
|
|
3582
|
-
const filter = options.templateIds ? TransactionFilterBySetup({
|
|
3583
|
-
templateIds: options.templateIds,
|
|
3584
|
-
partyId: options.partyId
|
|
3585
|
-
}) : TransactionFilterBySetup({
|
|
3586
|
-
interfaceIds: options.interfaceIds,
|
|
3587
|
-
partyId: options.partyId
|
|
3588
|
-
});
|
|
3589
|
-
const request = {
|
|
3590
|
-
beginExclusive: options.beginExclusive,
|
|
3591
|
-
endInclusive: options.endInclusive,
|
|
3592
|
-
verbose: options.verbose ?? true,
|
|
3593
|
-
filter
|
|
3594
|
-
};
|
|
3595
|
-
return this.generate(wsUpdatesUrl, request);
|
|
3596
|
-
}
|
|
3597
|
-
streamCompletions(options) {
|
|
3598
|
-
const wsCompletionsUrl = `${this.baseUrl}${CHANNELS.v2_commands_completions}`;
|
|
3599
|
-
const request = {
|
|
3600
|
-
beginExclusive: options.beginExclusive,
|
|
3601
|
-
userId: options.userId,
|
|
3602
|
-
parties: options.parties
|
|
3603
|
-
};
|
|
3604
|
-
return this.generate(wsCompletionsUrl, request);
|
|
3605
|
-
}
|
|
3606
|
-
};
|
|
3607
|
-
|
|
3608
3457
|
exports.ACSContainer = ACSContainer;
|
|
3609
3458
|
exports.ACS_UPDATE_CONFIG = ACS_UPDATE_CONFIG;
|
|
3610
3459
|
exports.AmuletService = AmuletService;
|
|
@@ -3614,12 +3463,17 @@ exports.TokenStandardService = TokenStandardService;
|
|
|
3614
3463
|
exports.TokenStandardTransactionInterfaces = TokenStandardTransactionInterfaces;
|
|
3615
3464
|
exports.TransactionParser = TransactionParser;
|
|
3616
3465
|
exports.WSSupportWithBackOffSwitch = WSSupportWithBackOffSwitch;
|
|
3617
|
-
exports.WebSocketClient = WebSocketClient;
|
|
3618
3466
|
exports.asJsCantonError = asJsCantonError;
|
|
3619
3467
|
exports.awaitCompletion = awaitCompletion;
|
|
3620
3468
|
exports.defaultRetryableOptions = defaultRetryableOptions;
|
|
3621
3469
|
exports.isJsCantonError = isJsCantonError;
|
|
3622
3470
|
exports.promiseWithTimeout = promiseWithTimeout;
|
|
3623
3471
|
exports.supportedVersions = supportedVersions;
|
|
3472
|
+
Object.keys(coreLedgerClientTypes).forEach(function (k) {
|
|
3473
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
3474
|
+
enumerable: true,
|
|
3475
|
+
get: function () { return coreLedgerClientTypes[k]; }
|
|
3476
|
+
});
|
|
3477
|
+
});
|
|
3624
3478
|
//# sourceMappingURL=index.cjs.map
|
|
3625
3479
|
//# sourceMappingURL=index.cjs.map
|