@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/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
export * from './token-standard-service.js';
|
|
2
2
|
export { AmuletService } from './amulet-service.js';
|
|
3
3
|
export * from './ledger-client.js';
|
|
4
|
-
export * from './generated-clients/openapi-3.3.0-SNAPSHOT.js';
|
|
5
4
|
export * from './acs/acs-container.js';
|
|
6
5
|
export * from './acs/ws-support.js';
|
|
7
6
|
export type { Transaction, TokenStandardEvent, Holding, HoldingLock, HoldingsChange, HoldingsChangeSummary, TransferInstructionView, TokenStandardChoice, PrettyTransactions, PrettyContract, ViewValue, Label, TransferIn, TransferOut, MergeSplit, Burn, Mint, Unlock, ExpireDust, RawArchive, RawCreate, } from './txparse/types.js';
|
|
8
7
|
export { TransactionParser } from './txparse/parser.js';
|
|
9
8
|
export { TokenStandardTransactionInterfaces } from './constants.js';
|
|
10
9
|
export { awaitCompletion, promiseWithTimeout, isJsCantonError, asJsCantonError, JsCantonError, JSContractEntry, defaultRetryableOptions, } from './ledger-api-utils.js';
|
|
11
|
-
export * from '
|
|
12
|
-
export { GetUpdatesRequest, JsGetUpdatesResponse, CompletionResponse, } from './generated-clients/asyncapi-3.4.7.js';
|
|
10
|
+
export * from '@canton-network/core-ledger-client-types';
|
|
13
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,cAAc,oBAAoB,CAAA;AAClC,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,YAAY,EACR,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,KAAK,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,UAAU,EACV,SAAS,GACZ,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,kCAAkC,EAAE,MAAM,gBAAgB,CAAA;AAEnE,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,uBAAuB,GAC1B,MAAM,uBAAuB,CAAA;AAE9B,cAAc,0CAA0C,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { HOLDING_INTERFACE_ID, TRANSFER_FACTORY_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID, ALLOCATION_FACTORY_INTERFACE_ID, ALLOCATION_INSTRUCTION_INTERFACE_ID, ALLOCATION_INTERFACE_ID, ALLOCATION_REQUEST_INTERFACE_ID, TokenStandardClient, FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID } from '@canton-network/core-token-standard';
|
|
2
|
+
import { EventFilterBySetup } from '@canton-network/core-ledger-client-types';
|
|
3
|
+
export * from '@canton-network/core-ledger-client-types';
|
|
2
4
|
import { ErrorInfo, RetryInfo } from '@canton-network/core-ledger-proto';
|
|
3
5
|
import BigNumber from 'bignumber.js';
|
|
4
6
|
import createClient from 'openapi-fetch';
|
|
@@ -43,131 +45,6 @@ var AllKnownMetaKeys = [
|
|
|
43
45
|
ReasonMetaKey,
|
|
44
46
|
BurnedMetaKey
|
|
45
47
|
];
|
|
46
|
-
function createIdentiferFilter(type, id) {
|
|
47
|
-
if (type === "Template") {
|
|
48
|
-
return {
|
|
49
|
-
identifierFilter: {
|
|
50
|
-
TemplateFilter: {
|
|
51
|
-
value: {
|
|
52
|
-
templateId: id,
|
|
53
|
-
includeCreatedEventBlob: true
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
} else {
|
|
59
|
-
return {
|
|
60
|
-
identifierFilter: {
|
|
61
|
-
InterfaceFilter: {
|
|
62
|
-
value: {
|
|
63
|
-
interfaceId: id,
|
|
64
|
-
includeInterfaceView: true,
|
|
65
|
-
includeCreatedEventBlob: true
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function createWildcardFilter() {
|
|
73
|
-
return {
|
|
74
|
-
identifierFilter: {
|
|
75
|
-
WildcardFilter: {
|
|
76
|
-
value: {
|
|
77
|
-
includeCreatedEventBlob: true
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function buildCumulativeFilters(templateIds, interfaceIds, includeWildcard) {
|
|
84
|
-
if (templateIds.length > 0) {
|
|
85
|
-
return [
|
|
86
|
-
...templateIds.map(
|
|
87
|
-
(templateId) => createIdentiferFilter("Template", templateId)
|
|
88
|
-
),
|
|
89
|
-
...includeWildcard ? [createWildcardFilter()] : []
|
|
90
|
-
];
|
|
91
|
-
} else {
|
|
92
|
-
return [
|
|
93
|
-
...interfaceIds.map(
|
|
94
|
-
(interfaceId) => createIdentiferFilter("Interface", interfaceId)
|
|
95
|
-
),
|
|
96
|
-
...includeWildcard ? [createWildcardFilter()] : []
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function buildFilter(templateIds, interfaceIds, options, additionalProps) {
|
|
101
|
-
const { isMasterUser = false, partyId, includeWildcard = false } = options;
|
|
102
|
-
if (isMasterUser) {
|
|
103
|
-
return {
|
|
104
|
-
filtersByParty: {},
|
|
105
|
-
filtersForAnyParty: filtersForAnyParty(
|
|
106
|
-
templateIds,
|
|
107
|
-
interfaceIds,
|
|
108
|
-
includeWildcard
|
|
109
|
-
),
|
|
110
|
-
...additionalProps
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
if (!partyId) {
|
|
114
|
-
throw new Error("Party must be provided for non-master users");
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
filtersByParty: filtersByParty(
|
|
118
|
-
partyId,
|
|
119
|
-
templateIds,
|
|
120
|
-
interfaceIds,
|
|
121
|
-
includeWildcard
|
|
122
|
-
),
|
|
123
|
-
...additionalProps
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function TransactionFilterBySetup(options) {
|
|
127
|
-
const { templateIds, interfaceIds, ...baseOptions } = options;
|
|
128
|
-
return buildFilter(
|
|
129
|
-
normalizeToArray(templateIds || []),
|
|
130
|
-
normalizeToArray(interfaceIds || []),
|
|
131
|
-
baseOptions
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
function EventFilterBySetup(options) {
|
|
135
|
-
const {
|
|
136
|
-
templateIds,
|
|
137
|
-
interfaceIds,
|
|
138
|
-
verbose = false,
|
|
139
|
-
...baseOptions
|
|
140
|
-
} = options;
|
|
141
|
-
return buildFilter(
|
|
142
|
-
normalizeToArray(templateIds || []),
|
|
143
|
-
normalizeToArray(interfaceIds || []),
|
|
144
|
-
baseOptions,
|
|
145
|
-
{ verbose }
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
function filtersByParty(party, templateIds, interfaceIds, includeWildcard) {
|
|
149
|
-
return {
|
|
150
|
-
[party]: {
|
|
151
|
-
cumulative: buildCumulativeFilters(
|
|
152
|
-
templateIds,
|
|
153
|
-
interfaceIds,
|
|
154
|
-
includeWildcard
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function filtersForAnyParty(interfaceNames, templateIds, includeWildcard) {
|
|
160
|
-
return {
|
|
161
|
-
cumulative: buildCumulativeFilters(
|
|
162
|
-
templateIds,
|
|
163
|
-
interfaceNames,
|
|
164
|
-
includeWildcard
|
|
165
|
-
)
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function normalizeToArray(value) {
|
|
169
|
-
return Array.isArray(value) ? value : [value];
|
|
170
|
-
}
|
|
171
48
|
function hasInterface(interfaceId, event) {
|
|
172
49
|
return (event.implementedInterfaces || []).some(
|
|
173
50
|
(id) => matchInterfaceIds(id, interfaceId)
|
|
@@ -1252,14 +1129,17 @@ var CoreService = class _CoreService {
|
|
|
1252
1129
|
);
|
|
1253
1130
|
}
|
|
1254
1131
|
// TODO: probably needs a filter by instrument ID as well?
|
|
1255
|
-
async getInputHoldingsCids(sender, inputUtxos, amount) {
|
|
1132
|
+
async getInputHoldingsCids(sender, inputUtxos, amount, continueUntilCompletion) {
|
|
1256
1133
|
const now = /* @__PURE__ */ new Date();
|
|
1257
1134
|
if (inputUtxos && inputUtxos.length > 0) {
|
|
1258
1135
|
return inputUtxos;
|
|
1259
1136
|
}
|
|
1260
1137
|
const senderHoldings = await this.listContractsByInterface(
|
|
1261
1138
|
HOLDING_INTERFACE_ID,
|
|
1262
|
-
sender
|
|
1139
|
+
sender,
|
|
1140
|
+
void 0,
|
|
1141
|
+
void 0,
|
|
1142
|
+
continueUntilCompletion
|
|
1263
1143
|
);
|
|
1264
1144
|
if (senderHoldings.length === 0) {
|
|
1265
1145
|
throw new Error(
|
|
@@ -1324,14 +1204,15 @@ var CoreService = class _CoreService {
|
|
|
1324
1204
|
}
|
|
1325
1205
|
return cIds;
|
|
1326
1206
|
}
|
|
1327
|
-
async listContractsByInterface(interfaceId, partyId, limit, offset) {
|
|
1207
|
+
async listContractsByInterface(interfaceId, partyId, limit, offset, continueUntilCompletion) {
|
|
1328
1208
|
try {
|
|
1329
1209
|
const ledgerEnd = offset ?? (await this.ledgerClient.getWithRetry("/v2/state/ledger-end")).offset;
|
|
1330
1210
|
const options = {
|
|
1331
1211
|
offset: ledgerEnd,
|
|
1332
1212
|
interfaceIds: [interfaceId],
|
|
1333
1213
|
parties: [partyId],
|
|
1334
|
-
filterByParty: true
|
|
1214
|
+
filterByParty: true,
|
|
1215
|
+
continueUntilCompletion: Boolean(continueUntilCompletion)
|
|
1335
1216
|
};
|
|
1336
1217
|
if (limit !== void 0) {
|
|
1337
1218
|
options.limit = limit;
|
|
@@ -1682,11 +1563,12 @@ var TransferService = class {
|
|
|
1682
1563
|
this.core = core;
|
|
1683
1564
|
this.logger = logger;
|
|
1684
1565
|
}
|
|
1685
|
-
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta) {
|
|
1566
|
+
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta, continueUntilCompletion) {
|
|
1686
1567
|
const inputHoldingCids = await this.core.getInputHoldingsCids(
|
|
1687
1568
|
sender,
|
|
1688
1569
|
inputUtxos,
|
|
1689
|
-
parseFloat(amount)
|
|
1570
|
+
parseFloat(amount),
|
|
1571
|
+
continueUntilCompletion
|
|
1690
1572
|
);
|
|
1691
1573
|
return {
|
|
1692
1574
|
expectedAdmin: instrumentAdmin,
|
|
@@ -1734,7 +1616,7 @@ var TransferService = class {
|
|
|
1734
1616
|
return [exercise, choiceContext.disclosedContracts];
|
|
1735
1617
|
}
|
|
1736
1618
|
// TODO: use named parameters
|
|
1737
|
-
async createTransfer(sender, receiver, amount, instrumentAdmin, instrumentId, registryUrl, inputUtxos, memo, expiryDate, meta, prefetchedRegistryChoiceContext) {
|
|
1619
|
+
async createTransfer(sender, receiver, amount, instrumentAdmin, instrumentId, registryUrl, inputUtxos, memo, expiryDate, meta, prefetchedRegistryChoiceContext, continueUntilCompletion) {
|
|
1738
1620
|
try {
|
|
1739
1621
|
const choiceArgs = await this.buildTransferChoiceArgs(
|
|
1740
1622
|
sender,
|
|
@@ -1745,7 +1627,8 @@ var TransferService = class {
|
|
|
1745
1627
|
inputUtxos,
|
|
1746
1628
|
memo,
|
|
1747
1629
|
expiryDate,
|
|
1748
|
-
meta
|
|
1630
|
+
meta,
|
|
1631
|
+
continueUntilCompletion
|
|
1749
1632
|
);
|
|
1750
1633
|
if (prefetchedRegistryChoiceContext) {
|
|
1751
1634
|
return this.createTransferFromContext(
|
|
@@ -2099,12 +1982,13 @@ var TokenStandardService = class {
|
|
|
2099
1982
|
}
|
|
2100
1983
|
// <T> is shape of viewValue related to queried interface.
|
|
2101
1984
|
// i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
|
|
2102
|
-
async listContractsByInterface(interfaceId, partyId, limit, offset) {
|
|
1985
|
+
async listContractsByInterface(interfaceId, partyId, limit, offset, continueUntilCompletion) {
|
|
2103
1986
|
return this.core.listContractsByInterface(
|
|
2104
1987
|
interfaceId,
|
|
2105
1988
|
partyId,
|
|
2106
1989
|
limit,
|
|
2107
|
-
offset
|
|
1990
|
+
offset,
|
|
1991
|
+
continueUntilCompletion
|
|
2108
1992
|
);
|
|
2109
1993
|
}
|
|
2110
1994
|
async listHoldingTransactions(partyId, afterOffset, beforeOffset) {
|
|
@@ -3284,13 +3168,27 @@ var LedgerClient = class {
|
|
|
3284
3168
|
}
|
|
3285
3169
|
}
|
|
3286
3170
|
/*
|
|
3287
|
-
if limit is provided, this function performs a one-time query
|
|
3171
|
+
if limit is provided, this function performs a one-time query. Automatically splits into multiple `/v2/updates` calls with `continueUntilCompletion` on.
|
|
3288
3172
|
if limit is omitted, results may be served from the ACS cache
|
|
3289
3173
|
current cache design doesn't support limiting queries because updates/deltas for the acs at offset x will be incorrect
|
|
3290
3174
|
TODO: expose query mode vs subscribe mode to call queryActiveContracts vs subscribeActiveContracts
|
|
3291
3175
|
*/
|
|
3292
3176
|
async activeContracts(options) {
|
|
3293
|
-
const {
|
|
3177
|
+
const {
|
|
3178
|
+
offset,
|
|
3179
|
+
templateIds,
|
|
3180
|
+
parties,
|
|
3181
|
+
interfaceIds,
|
|
3182
|
+
limit,
|
|
3183
|
+
continueUntilCompletion
|
|
3184
|
+
} = options;
|
|
3185
|
+
if (continueUntilCompletion) {
|
|
3186
|
+
const filter2 = this.buildActiveContractFilter(options);
|
|
3187
|
+
return await this.fetchActiveContractsUntilComplete(
|
|
3188
|
+
filter2,
|
|
3189
|
+
limit ?? 200
|
|
3190
|
+
);
|
|
3191
|
+
}
|
|
3294
3192
|
const hasLimit = typeof limit === "number";
|
|
3295
3193
|
if (hasLimit) {
|
|
3296
3194
|
const filter2 = this.buildActiveContractFilter(options);
|
|
@@ -3298,9 +3196,7 @@ var LedgerClient = class {
|
|
|
3298
3196
|
"/v2/state/active-contracts",
|
|
3299
3197
|
filter2,
|
|
3300
3198
|
defaultRetryableOptions,
|
|
3301
|
-
{
|
|
3302
|
-
query: limit ? { limit: limit.toString() } : {}
|
|
3303
|
-
}
|
|
3199
|
+
{ query: { limit: limit.toString() } }
|
|
3304
3200
|
);
|
|
3305
3201
|
}
|
|
3306
3202
|
this.logger.debug(options, "options for active contracts");
|
|
@@ -3327,6 +3223,72 @@ var LedgerClient = class {
|
|
|
3327
3223
|
defaultRetryableOptions
|
|
3328
3224
|
);
|
|
3329
3225
|
}
|
|
3226
|
+
/**
|
|
3227
|
+
* Fetches active contracts by splitting requests into multiple `/v2/updates` calls.
|
|
3228
|
+
* Should only be used when the number of contracts exceeds http-list-max-elements-limit (200 by default).
|
|
3229
|
+
* For limits at or below http-list-max-elements-limit, use a single `/v2/state/active-contracts` call instead.
|
|
3230
|
+
* @param activeContractsArgs The request parameters for active contracts query
|
|
3231
|
+
* @returns A promise that resolves to an array of active contract responses
|
|
3232
|
+
* @private
|
|
3233
|
+
*/
|
|
3234
|
+
async fetchActiveContractsUntilComplete(activeContractsArgs, limit) {
|
|
3235
|
+
const ledgerEnd = await this.getWithRetry("/v2/state/ledger-end");
|
|
3236
|
+
const bodyRequest = {
|
|
3237
|
+
beginExclusive: 0,
|
|
3238
|
+
endInclusive: ledgerEnd.offset,
|
|
3239
|
+
verbose: false
|
|
3240
|
+
};
|
|
3241
|
+
if (activeContractsArgs.filter)
|
|
3242
|
+
bodyRequest.filter = activeContractsArgs.filter;
|
|
3243
|
+
let currentOffset = 0;
|
|
3244
|
+
const allContractsData = /* @__PURE__ */ new Map();
|
|
3245
|
+
const exercisedContracts = /* @__PURE__ */ new Set();
|
|
3246
|
+
while (currentOffset < ledgerEnd.offset) {
|
|
3247
|
+
bodyRequest.beginExclusive = currentOffset;
|
|
3248
|
+
const results = (await this.postWithRetry(
|
|
3249
|
+
"/v2/updates",
|
|
3250
|
+
bodyRequest,
|
|
3251
|
+
defaultRetryableOptions,
|
|
3252
|
+
{
|
|
3253
|
+
query: { limit: limit.toString() }
|
|
3254
|
+
}
|
|
3255
|
+
)).filter(({ update }) => "Transaction" in update).map(({ update }) => {
|
|
3256
|
+
if ("Transaction" in update) {
|
|
3257
|
+
return update.Transaction.value;
|
|
3258
|
+
}
|
|
3259
|
+
throw new Error("Expected Transaction update");
|
|
3260
|
+
}).map((data) => {
|
|
3261
|
+
const exercisedEvents = data.events?.filter((event) => "ExercisedEvent" in event).map(
|
|
3262
|
+
(event) => event.ExercisedEvent
|
|
3263
|
+
).filter((event) => event.consuming);
|
|
3264
|
+
const createdEvents = data.events?.filter((event) => "CreatedEvent" in event).map(
|
|
3265
|
+
(event) => event.CreatedEvent
|
|
3266
|
+
);
|
|
3267
|
+
exercisedEvents?.forEach((event) => {
|
|
3268
|
+
exercisedContracts.add(event.contractId);
|
|
3269
|
+
});
|
|
3270
|
+
createdEvents?.forEach((event) => {
|
|
3271
|
+
allContractsData.set(event.contractId, {
|
|
3272
|
+
workflowId: data.workflowId,
|
|
3273
|
+
contractEntry: {
|
|
3274
|
+
JsActiveContract: {
|
|
3275
|
+
synchronizerId: data.synchronizerId,
|
|
3276
|
+
createdEvent: event,
|
|
3277
|
+
reassignmentCounter: data.offset
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
});
|
|
3282
|
+
currentOffset = Math.max(currentOffset, data.offset);
|
|
3283
|
+
return true;
|
|
3284
|
+
});
|
|
3285
|
+
if (!results.length) currentOffset++;
|
|
3286
|
+
}
|
|
3287
|
+
exercisedContracts.forEach((cid) => {
|
|
3288
|
+
allContractsData.delete(cid);
|
|
3289
|
+
});
|
|
3290
|
+
return Array.from(allContractsData.values());
|
|
3291
|
+
}
|
|
3330
3292
|
buildActiveContractFilter(options) {
|
|
3331
3293
|
const filter = {
|
|
3332
3294
|
filter: {
|
|
@@ -3486,118 +3448,6 @@ var WSSupportWithBackOffSwitch = class {
|
|
|
3486
3448
|
}
|
|
3487
3449
|
};
|
|
3488
3450
|
|
|
3489
|
-
|
|
3490
|
-
var CHANNELS = {
|
|
3491
|
-
v2_commands_completions: "/v2/commands/completions",
|
|
3492
|
-
v2_updates: "/v2/updates"};
|
|
3493
|
-
|
|
3494
|
-
// src/web-socket-client.ts
|
|
3495
|
-
var WebSocketClient = class {
|
|
3496
|
-
constructor({
|
|
3497
|
-
baseUrl,
|
|
3498
|
-
isAdmin,
|
|
3499
|
-
accessTokenProvider,
|
|
3500
|
-
logger,
|
|
3501
|
-
wsSupportBackOff
|
|
3502
|
-
}) {
|
|
3503
|
-
__publicField(this, "ws", null);
|
|
3504
|
-
__publicField(this, "baseUrl");
|
|
3505
|
-
__publicField(this, "token", "");
|
|
3506
|
-
__publicField(this, "isAdmin");
|
|
3507
|
-
__publicField(this, "protocol", []);
|
|
3508
|
-
__publicField(this, "logger");
|
|
3509
|
-
__publicField(this, "wsSupportBackOff");
|
|
3510
|
-
__publicField(this, "accessTokenProvider");
|
|
3511
|
-
this.logger = logger.child({ component: "WebSocketClient" });
|
|
3512
|
-
this.baseUrl = baseUrl;
|
|
3513
|
-
this.wsSupportBackOff = wsSupportBackOff;
|
|
3514
|
-
this.accessTokenProvider = accessTokenProvider;
|
|
3515
|
-
this.isAdmin = isAdmin ?? false;
|
|
3516
|
-
}
|
|
3517
|
-
async init() {
|
|
3518
|
-
this.token = this.isAdmin ? await this.accessTokenProvider.getAdminAccessToken() : await this.accessTokenProvider.getUserAccessToken();
|
|
3519
|
-
this.protocol = [`jwt.token.${this.token}`, "daml.ws.auth"];
|
|
3520
|
-
this.logger.info(
|
|
3521
|
-
`initializing websocket client with ${this.protocol.length} protocols`
|
|
3522
|
-
);
|
|
3523
|
-
}
|
|
3524
|
-
generate(wsUrl, request) {
|
|
3525
|
-
const messageQueue = [];
|
|
3526
|
-
let resolveNext = null;
|
|
3527
|
-
let isClosed = false;
|
|
3528
|
-
let streamError = null;
|
|
3529
|
-
const generator = async function* () {
|
|
3530
|
-
await this.init();
|
|
3531
|
-
this.logger.debug(request);
|
|
3532
|
-
const ws = new WebSocket(wsUrl, this.protocol);
|
|
3533
|
-
ws.onopen = () => {
|
|
3534
|
-
ws.send(JSON.stringify(request));
|
|
3535
|
-
};
|
|
3536
|
-
ws.onmessage = (event) => {
|
|
3537
|
-
messageQueue.push(JSON.parse(event.data));
|
|
3538
|
-
this.logger.debug(event.data, `Received event`);
|
|
3539
|
-
resolveNext?.();
|
|
3540
|
-
};
|
|
3541
|
-
ws.onerror = () => {
|
|
3542
|
-
streamError = new Error("WebSocket Handshake/Connection failed");
|
|
3543
|
-
this.logger.error(`Encountered ws.onError`);
|
|
3544
|
-
isClosed = true;
|
|
3545
|
-
resolveNext?.();
|
|
3546
|
-
};
|
|
3547
|
-
ws.onclose = (event) => {
|
|
3548
|
-
this.logger.debug(
|
|
3549
|
-
`CLOSING WEBSOCKET CONNECTION code: ${event.code}, reason: ${event.reason}`
|
|
3550
|
-
);
|
|
3551
|
-
isClosed = true;
|
|
3552
|
-
resolveNext?.();
|
|
3553
|
-
};
|
|
3554
|
-
try {
|
|
3555
|
-
while (true) {
|
|
3556
|
-
if (messageQueue.length === 0) {
|
|
3557
|
-
if (isClosed) break;
|
|
3558
|
-
await new Promise((r) => resolveNext = r);
|
|
3559
|
-
}
|
|
3560
|
-
if (streamError) throw streamError;
|
|
3561
|
-
while (messageQueue.length > 0) {
|
|
3562
|
-
yield messageQueue.shift();
|
|
3563
|
-
}
|
|
3564
|
-
if (isClosed && messageQueue.length === 0) break;
|
|
3565
|
-
}
|
|
3566
|
-
} finally {
|
|
3567
|
-
if (ws.readyState === WebSocket.OPEN) ws.close();
|
|
3568
|
-
this.logger.info("Generator cleanup: WebSocket closed.");
|
|
3569
|
-
}
|
|
3570
|
-
};
|
|
3571
|
-
return generator.call(this);
|
|
3572
|
-
}
|
|
3573
|
-
streamUpdates(options) {
|
|
3574
|
-
const wsUpdatesUrl = `${this.baseUrl}${CHANNELS.v2_updates}`;
|
|
3575
|
-
const filter = options.templateIds ? TransactionFilterBySetup({
|
|
3576
|
-
templateIds: options.templateIds,
|
|
3577
|
-
partyId: options.partyId
|
|
3578
|
-
}) : TransactionFilterBySetup({
|
|
3579
|
-
interfaceIds: options.interfaceIds,
|
|
3580
|
-
partyId: options.partyId
|
|
3581
|
-
});
|
|
3582
|
-
const request = {
|
|
3583
|
-
beginExclusive: options.beginExclusive,
|
|
3584
|
-
endInclusive: options.endInclusive,
|
|
3585
|
-
verbose: options.verbose ?? true,
|
|
3586
|
-
filter
|
|
3587
|
-
};
|
|
3588
|
-
return this.generate(wsUpdatesUrl, request);
|
|
3589
|
-
}
|
|
3590
|
-
streamCompletions(options) {
|
|
3591
|
-
const wsCompletionsUrl = `${this.baseUrl}${CHANNELS.v2_commands_completions}`;
|
|
3592
|
-
const request = {
|
|
3593
|
-
beginExclusive: options.beginExclusive,
|
|
3594
|
-
userId: options.userId,
|
|
3595
|
-
parties: options.parties
|
|
3596
|
-
};
|
|
3597
|
-
return this.generate(wsCompletionsUrl, request);
|
|
3598
|
-
}
|
|
3599
|
-
};
|
|
3600
|
-
|
|
3601
|
-
export { ACSContainer, ACS_UPDATE_CONFIG, AmuletService, CoreService, LedgerClient, TokenStandardService, TokenStandardTransactionInterfaces, TransactionParser, WSSupportWithBackOffSwitch, WebSocketClient, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions };
|
|
3451
|
+
export { ACSContainer, ACS_UPDATE_CONFIG, AmuletService, CoreService, LedgerClient, TokenStandardService, TokenStandardTransactionInterfaces, TransactionParser, WSSupportWithBackOffSwitch, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions };
|
|
3602
3452
|
//# sourceMappingURL=index.js.map
|
|
3603
3453
|
//# sourceMappingURL=index.js.map
|