@canton-network/core-ledger-client 0.17.0 → 0.18.1
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 +3 -5
- package/dist/acs/acs-helper.d.ts.map +1 -1
- package/dist/acs/acs-shared-cache.d.ts +14 -0
- package/dist/acs/acs-shared-cache.d.ts.map +1 -0
- package/dist/generated-clients/{openapi-3.4.0-SNAPSHOT.d.ts → openapi-3.4.7.d.ts} +458 -64
- package/dist/generated-clients/openapi-3.4.7.d.ts.map +1 -0
- package/dist/index.cjs +386 -134
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +386 -134
- package/dist/index.js.map +1 -1
- package/dist/ledger-client.d.ts +17 -14
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts +10 -4
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/txparse/parser.d.ts.map +1 -1
- package/dist/txparse/types.d.ts +9 -2
- package/dist/txparse/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/generated-clients/openapi-3.4.0-SNAPSHOT.d.ts.map +0 -1
- package/dist/txparse/test-data/expected/txs.d.ts +0 -1143
- package/dist/txparse/test-data/expected/txs.d.ts.map +0 -1
- package/dist/txparse/test-data/mock/txs.d.ts +0 -3304
- package/dist/txparse/test-data/mock/txs.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -340,27 +340,6 @@ var AllKnownMetaKeys = [
|
|
|
340
340
|
ReasonMetaKey,
|
|
341
341
|
BurnedMetaKey
|
|
342
342
|
];
|
|
343
|
-
function TransactionFilterBySetup(interfaceNames, options = { includeWildcard: false, isMasterUser: false }) {
|
|
344
|
-
const interfaceArrayed = Array.isArray(interfaceNames) ? interfaceNames : [interfaceNames];
|
|
345
|
-
if (options.isMasterUser)
|
|
346
|
-
return {
|
|
347
|
-
filtersByParty: {},
|
|
348
|
-
filtersForAnyParty: filtersForAnyParty(
|
|
349
|
-
interfaceArrayed,
|
|
350
|
-
options.includeWildcard ?? false
|
|
351
|
-
) ?? {}
|
|
352
|
-
};
|
|
353
|
-
else if (!options.partyId || options.partyId === void 0)
|
|
354
|
-
throw new Error("Party must be provided for non-master users");
|
|
355
|
-
else
|
|
356
|
-
return {
|
|
357
|
-
filtersByParty: filtersByParty(
|
|
358
|
-
options.partyId,
|
|
359
|
-
interfaceArrayed,
|
|
360
|
-
options.includeWildcard ?? false
|
|
361
|
-
) ?? {}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
343
|
function EventFilterBySetup(interfaceNames, options = { includeWildcard: false, isMasterUser: false }) {
|
|
365
344
|
const interfaceArrayed = Array.isArray(interfaceNames) ? interfaceNames : [interfaceNames];
|
|
366
345
|
if (options.isMasterUser)
|
|
@@ -695,15 +674,15 @@ var renderTransactionEvent = (e) => {
|
|
|
695
674
|
);
|
|
696
675
|
return {
|
|
697
676
|
...e,
|
|
698
|
-
lockedHoldingsChange
|
|
699
|
-
unlockedHoldingsChange
|
|
700
|
-
lockedHoldingsChangeSummary
|
|
701
|
-
unlockedHoldingsChangeSummary
|
|
677
|
+
lockedHoldingsChange,
|
|
678
|
+
unlockedHoldingsChange,
|
|
679
|
+
lockedHoldingsChangeSummary,
|
|
680
|
+
unlockedHoldingsChangeSummary
|
|
702
681
|
};
|
|
703
682
|
};
|
|
704
683
|
var renderHoldingsChangeSummary = (s) => {
|
|
705
684
|
if (s.numInputs === 0 && s.numOutputs === 0 && s.inputAmount === "0" && s.outputAmount === "0" && s.amountChange === "0") {
|
|
706
|
-
return
|
|
685
|
+
return null;
|
|
707
686
|
}
|
|
708
687
|
return {
|
|
709
688
|
...s.numInputs !== 0 && { numInputs: s.numInputs },
|
|
@@ -715,13 +694,37 @@ var renderHoldingsChangeSummary = (s) => {
|
|
|
715
694
|
};
|
|
716
695
|
var renderHoldingsChange = (c) => {
|
|
717
696
|
if (c.creates.length === 0 && c.archives.length === 0) {
|
|
718
|
-
return
|
|
697
|
+
return null;
|
|
719
698
|
}
|
|
720
699
|
return {
|
|
721
700
|
...c.creates.length !== 0 && { creates: c.creates },
|
|
722
701
|
...c.archives.length !== 0 && { archives: c.archives }
|
|
723
702
|
};
|
|
724
703
|
};
|
|
704
|
+
function currentStatusFromChoiceOrResult(choice, resultTag) {
|
|
705
|
+
if (resultTag === "TransferInstructionResult_Failed") return "Failed";
|
|
706
|
+
if (resultTag === "TransferInstructionResult_Completed") return "Completed";
|
|
707
|
+
switch (choice) {
|
|
708
|
+
case "TransferInstruction_Reject":
|
|
709
|
+
return "Rejected";
|
|
710
|
+
case "TransferInstruction_Withdraw":
|
|
711
|
+
return "Withdrawn";
|
|
712
|
+
case "TransferInstruction_Accept":
|
|
713
|
+
case "TransferInstruction_Update":
|
|
714
|
+
return "Pending";
|
|
715
|
+
default:
|
|
716
|
+
return "Pending";
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function getCorrelationIdFromTransferInstruction(currentInstructionCid, originalInstructionCid) {
|
|
720
|
+
return originalInstructionCid ?? currentInstructionCid;
|
|
721
|
+
}
|
|
722
|
+
function getPendingTransferInstructionCid(exercisedEvent) {
|
|
723
|
+
const output = exercisedEvent.exerciseResult?.output;
|
|
724
|
+
if (output?.tag !== "TransferInstructionResult_Pending") return void 0;
|
|
725
|
+
const cid = output.value?.transferInstructionCid;
|
|
726
|
+
return cid ?? void 0;
|
|
727
|
+
}
|
|
725
728
|
var TransactionParser = class {
|
|
726
729
|
constructor(transaction, ledgerClient, partyId, isMasterUser) {
|
|
727
730
|
__publicField(this, "ledgerClient");
|
|
@@ -866,9 +869,24 @@ var TransactionParser = class {
|
|
|
866
869
|
].some((stakeholder) => stakeholder === this.partyId)) {
|
|
867
870
|
result = null;
|
|
868
871
|
} else {
|
|
872
|
+
const multiStepCorrelationId = getCorrelationIdFromTransferInstruction(
|
|
873
|
+
originalCreate.contractId,
|
|
874
|
+
transferInstructionView.originalInstructionCid ?? null
|
|
875
|
+
);
|
|
869
876
|
result = {
|
|
870
877
|
payload: transferInstructionView,
|
|
871
|
-
transferInstruction:
|
|
878
|
+
transferInstruction: {
|
|
879
|
+
originalInstructionCid: transferInstructionView.originalInstructionCid,
|
|
880
|
+
transfer: transferInstructionView.transfer,
|
|
881
|
+
meta: transferInstructionView.meta,
|
|
882
|
+
status: {
|
|
883
|
+
before: transferInstructionView.status,
|
|
884
|
+
// raw DAML pending sub-state
|
|
885
|
+
current: { tag: "Pending", value: {} }
|
|
886
|
+
// normalized
|
|
887
|
+
},
|
|
888
|
+
multiStepCorrelationId
|
|
889
|
+
},
|
|
872
890
|
unlockedHoldingsChange: { creates: [], archives: [] },
|
|
873
891
|
lockedHoldingsChange: { creates: [], archives: [] },
|
|
874
892
|
unlockedHoldingsChangeSummary: EmptyHoldingsChangeSummary,
|
|
@@ -1002,6 +1020,12 @@ var TransactionParser = class {
|
|
|
1002
1020
|
);
|
|
1003
1021
|
return null;
|
|
1004
1022
|
}
|
|
1023
|
+
const resultTag = exercisedEvent.exerciseResult?.output?.tag || void 0;
|
|
1024
|
+
const pendingCid = getPendingTransferInstructionCid(exercisedEvent);
|
|
1025
|
+
const currentTag = currentStatusFromChoiceOrResult(
|
|
1026
|
+
exercisedEvent.choice,
|
|
1027
|
+
resultTag
|
|
1028
|
+
);
|
|
1005
1029
|
const children = await this.getChildren(exercisedEvent);
|
|
1006
1030
|
const receiverAmounts = /* @__PURE__ */ new Map();
|
|
1007
1031
|
children.creates.filter((h) => h.owner !== sender).forEach(
|
|
@@ -1045,13 +1069,25 @@ var TransactionParser = class {
|
|
|
1045
1069
|
meta
|
|
1046
1070
|
};
|
|
1047
1071
|
}
|
|
1072
|
+
if (transferInstructions) {
|
|
1073
|
+
transferInstructions.status.current = transferInstructions.status.current || { tag: currentTag, value: {} };
|
|
1074
|
+
return {
|
|
1075
|
+
label,
|
|
1076
|
+
children,
|
|
1077
|
+
transferInstruction: transferInstructions
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1048
1080
|
const transferInstruction = {
|
|
1049
1081
|
originalInstructionCid: null,
|
|
1050
|
-
|
|
1082
|
+
...choiceArgumentTransfer !== void 0 && {
|
|
1083
|
+
transfer: choiceArgumentTransfer
|
|
1084
|
+
},
|
|
1051
1085
|
status: {
|
|
1052
|
-
before: null
|
|
1086
|
+
before: null,
|
|
1087
|
+
current: { tag: currentTag, value: {} }
|
|
1053
1088
|
},
|
|
1054
|
-
meta: null
|
|
1089
|
+
meta: null,
|
|
1090
|
+
...pendingCid ? { multiStepCorrelationId: pendingCid } : {}
|
|
1055
1091
|
};
|
|
1056
1092
|
return {
|
|
1057
1093
|
label,
|
|
@@ -1089,6 +1125,7 @@ var TransactionParser = class {
|
|
|
1089
1125
|
};
|
|
1090
1126
|
}
|
|
1091
1127
|
async buildFromTransferInstructionExercise(exercisedEvent, tokenStandardChoice) {
|
|
1128
|
+
const instructionCid = exercisedEvent.contractId;
|
|
1092
1129
|
const transferInstructionEvents = await this.getEventsForArchive(exercisedEvent);
|
|
1093
1130
|
if (!transferInstructionEvents) {
|
|
1094
1131
|
return null;
|
|
@@ -1097,15 +1134,26 @@ var TransactionParser = class {
|
|
|
1097
1134
|
transferInstructionEvents.created.createdEvent,
|
|
1098
1135
|
coreTokenStandard.TRANSFER_INSTRUCTION_INTERFACE_ID
|
|
1099
1136
|
).viewValue;
|
|
1137
|
+
const multiStepCorrelationId = getCorrelationIdFromTransferInstruction(
|
|
1138
|
+
instructionCid,
|
|
1139
|
+
transferInstructionView.originalInstructionCid ?? null
|
|
1140
|
+
);
|
|
1141
|
+
const resultTag = exercisedEvent.exerciseResult?.output?.tag || void 0;
|
|
1142
|
+
const currentTag = currentStatusFromChoiceOrResult(
|
|
1143
|
+
exercisedEvent.choice,
|
|
1144
|
+
resultTag
|
|
1145
|
+
);
|
|
1100
1146
|
const transferInstruction = {
|
|
1101
1147
|
originalInstructionCid: transferInstructionView.originalInstructionCid,
|
|
1148
|
+
multiStepCorrelationId,
|
|
1102
1149
|
transfer: transferInstructionView.transfer,
|
|
1103
1150
|
meta: transferInstructionView.meta,
|
|
1104
1151
|
status: {
|
|
1105
|
-
before: transferInstructionView.status
|
|
1152
|
+
before: transferInstructionView.status,
|
|
1153
|
+
current: { tag: currentTag, value: {} }
|
|
1106
1154
|
}
|
|
1107
1155
|
};
|
|
1108
|
-
const exerciseResultOutputTag =
|
|
1156
|
+
const exerciseResultOutputTag = resultTag;
|
|
1109
1157
|
let result = null;
|
|
1110
1158
|
switch (exerciseResultOutputTag) {
|
|
1111
1159
|
case "TransferInstructionResult_Failed":
|
|
@@ -1350,7 +1398,7 @@ function holdingChangesNonEmpty(event) {
|
|
|
1350
1398
|
var MEMO_KEY = "splice.lfdecentralizedtrust.org/reason";
|
|
1351
1399
|
var REQUESTED_AT_SKEW_MS = 6e4;
|
|
1352
1400
|
var EMPTY_META = { values: {} };
|
|
1353
|
-
var CoreService = class {
|
|
1401
|
+
var CoreService = class _CoreService {
|
|
1354
1402
|
constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, isAdmin = false, accessToken = "") {
|
|
1355
1403
|
this.ledgerClient = ledgerClient;
|
|
1356
1404
|
this.scanProxyClient = scanProxyClient;
|
|
@@ -1369,7 +1417,7 @@ var CoreService = class {
|
|
|
1369
1417
|
this.accessTokenProvider
|
|
1370
1418
|
);
|
|
1371
1419
|
}
|
|
1372
|
-
async getInputHoldingsCids(sender, inputUtxos) {
|
|
1420
|
+
async getInputHoldingsCids(sender, inputUtxos, amount) {
|
|
1373
1421
|
const now = /* @__PURE__ */ new Date();
|
|
1374
1422
|
if (inputUtxos && inputUtxos.length > 0) {
|
|
1375
1423
|
return inputUtxos;
|
|
@@ -1383,35 +1431,77 @@ var CoreService = class {
|
|
|
1383
1431
|
"Sender has no holdings, so transfer can't be executed."
|
|
1384
1432
|
);
|
|
1385
1433
|
}
|
|
1386
|
-
|
|
1434
|
+
const unlockedSenderHoldings = senderHoldings.filter((utxo) => {
|
|
1387
1435
|
const lock = utxo.interfaceViewValue.lock;
|
|
1388
1436
|
if (!lock) return true;
|
|
1389
1437
|
const expiresAt = lock.expiresAt;
|
|
1390
1438
|
if (!expiresAt) return false;
|
|
1391
1439
|
const expiresAtDate = new Date(expiresAt);
|
|
1392
1440
|
return expiresAtDate <= now;
|
|
1393
|
-
})
|
|
1441
|
+
});
|
|
1442
|
+
if (unlockedSenderHoldings.length > 100) {
|
|
1443
|
+
this.logger.warn(`Sender has more than 100 unlocked utxos.`);
|
|
1444
|
+
}
|
|
1445
|
+
if (amount) {
|
|
1446
|
+
return _CoreService.getInputHoldingsCidsForAmount(
|
|
1447
|
+
amount,
|
|
1448
|
+
unlockedSenderHoldings
|
|
1449
|
+
);
|
|
1450
|
+
} else {
|
|
1451
|
+
return unlockedSenderHoldings.map((h) => h.contractId);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
static async getInputHoldingsCidsForAmount(amount, unlockedSenderHoldings) {
|
|
1455
|
+
const exactAmount = unlockedSenderHoldings.find(
|
|
1456
|
+
(holding) => parseFloat(holding.interfaceViewValue.amount) === amount
|
|
1457
|
+
);
|
|
1458
|
+
if (exactAmount) {
|
|
1459
|
+
return [exactAmount.contractId];
|
|
1460
|
+
}
|
|
1461
|
+
const sortedUnlockedSenderHoldings = unlockedSenderHoldings.toSorted(
|
|
1462
|
+
(a, b) => parseFloat(a.interfaceViewValue.amount) - parseFloat(b.interfaceViewValue.amount)
|
|
1463
|
+
);
|
|
1464
|
+
const largestHoldingAmount = sortedUnlockedSenderHoldings.pop();
|
|
1465
|
+
if (!largestHoldingAmount) {
|
|
1466
|
+
throw new Error(`Sender doesn't have any unlocked holdings`);
|
|
1467
|
+
}
|
|
1468
|
+
let currentSum = parseFloat(
|
|
1469
|
+
largestHoldingAmount.interfaceViewValue.amount
|
|
1470
|
+
);
|
|
1471
|
+
const cIds = [largestHoldingAmount.contractId];
|
|
1472
|
+
for (const h of sortedUnlockedSenderHoldings) {
|
|
1473
|
+
if (currentSum >= amount) {
|
|
1474
|
+
break;
|
|
1475
|
+
}
|
|
1476
|
+
const currentHoldingAmount = parseFloat(h.interfaceViewValue.amount);
|
|
1477
|
+
currentSum += currentHoldingAmount;
|
|
1478
|
+
cIds.push(h.contractId);
|
|
1479
|
+
}
|
|
1480
|
+
if (currentSum < amount) {
|
|
1481
|
+
throw new Error(
|
|
1482
|
+
`Sender doesn't have sufficient funds for this transfer. Missing amount: ${amount - currentSum}`
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
if (cIds.length > 100) {
|
|
1486
|
+
throw new Error(
|
|
1487
|
+
`Exceeded the maximum of 100 utxos in 1 transaction`
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
return cIds;
|
|
1394
1491
|
}
|
|
1395
1492
|
async listContractsByInterface(interfaceId, partyId, limit) {
|
|
1396
1493
|
try {
|
|
1397
1494
|
const ledgerEnd = await this.ledgerClient.getWithRetry(
|
|
1398
1495
|
"/v2/state/ledger-end"
|
|
1399
1496
|
);
|
|
1400
|
-
const
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
activeAtOffset: ledgerEnd.offset
|
|
1409
|
-
},
|
|
1410
|
-
defaultRetryableOptions,
|
|
1411
|
-
{
|
|
1412
|
-
query: limit ? { limit: limit.toString() } : {}
|
|
1413
|
-
}
|
|
1414
|
-
);
|
|
1497
|
+
const options = {
|
|
1498
|
+
offset: ledgerEnd.offset,
|
|
1499
|
+
interfaceIds: [interfaceId],
|
|
1500
|
+
parties: [partyId],
|
|
1501
|
+
filterByParty: true,
|
|
1502
|
+
limit: limit ?? 100
|
|
1503
|
+
};
|
|
1504
|
+
const acsResponses = await this.ledgerClient.activeContracts(options);
|
|
1415
1505
|
const isActiveContractEntry = (acsResponse) => !!acsResponse.contractEntry.JsActiveContract?.createdEvent;
|
|
1416
1506
|
const activeContractEntries = acsResponses.filter(
|
|
1417
1507
|
isActiveContractEntry
|
|
@@ -1748,7 +1838,8 @@ var TransferService = class {
|
|
|
1748
1838
|
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta) {
|
|
1749
1839
|
const inputHoldingCids = await this.core.getInputHoldingsCids(
|
|
1750
1840
|
sender,
|
|
1751
|
-
inputUtxos
|
|
1841
|
+
inputUtxos,
|
|
1842
|
+
parseFloat(amount)
|
|
1752
1843
|
);
|
|
1753
1844
|
return {
|
|
1754
1845
|
expectedAdmin: instrumentAdmin,
|
|
@@ -2132,11 +2223,77 @@ var TokenStandardService = class {
|
|
|
2132
2223
|
);
|
|
2133
2224
|
}
|
|
2134
2225
|
}
|
|
2226
|
+
async buyMemberTraffic(dso, provider, trafficAmount, synchronizerId, memberId, migrationId, inputUtxos) {
|
|
2227
|
+
const amuletRules = await this.scanProxyClient.getAmuletRules();
|
|
2228
|
+
const activeRound = await this.scanProxyClient.getActiveOpenMiningRound();
|
|
2229
|
+
const inputHoldings = await this.core.getInputHoldingsCids(
|
|
2230
|
+
provider,
|
|
2231
|
+
inputUtxos,
|
|
2232
|
+
trafficAmount
|
|
2233
|
+
);
|
|
2234
|
+
if (!amuletRules) {
|
|
2235
|
+
throw new Error("AmuletRules contract not found");
|
|
2236
|
+
}
|
|
2237
|
+
if (!activeRound) {
|
|
2238
|
+
throw new Error(
|
|
2239
|
+
"OpenMiningRound active at current moment not found"
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
const disclosed = [
|
|
2243
|
+
{
|
|
2244
|
+
templateId: amuletRules.template_id,
|
|
2245
|
+
contractId: amuletRules.contract_id,
|
|
2246
|
+
createdEventBlob: amuletRules.created_event_blob,
|
|
2247
|
+
synchronizerId
|
|
2248
|
+
},
|
|
2249
|
+
{
|
|
2250
|
+
templateId: activeRound.template_id,
|
|
2251
|
+
contractId: activeRound.contract_id,
|
|
2252
|
+
createdEventBlob: activeRound.created_event_blob,
|
|
2253
|
+
synchronizerId
|
|
2254
|
+
}
|
|
2255
|
+
];
|
|
2256
|
+
const context = {
|
|
2257
|
+
openMiningRound: activeRound.contract_id,
|
|
2258
|
+
issuingMiningRounds: [],
|
|
2259
|
+
validatorRights: [],
|
|
2260
|
+
featuredAppRight: null
|
|
2261
|
+
};
|
|
2262
|
+
const choiceArgs = {
|
|
2263
|
+
context,
|
|
2264
|
+
inputs: inputHoldings.map((cid) => ({
|
|
2265
|
+
tag: "InputAmulet",
|
|
2266
|
+
value: cid
|
|
2267
|
+
})),
|
|
2268
|
+
provider,
|
|
2269
|
+
memberId,
|
|
2270
|
+
synchronizerId,
|
|
2271
|
+
migrationId,
|
|
2272
|
+
trafficAmount,
|
|
2273
|
+
expectedDso: dso
|
|
2274
|
+
};
|
|
2275
|
+
const exercise = {
|
|
2276
|
+
templateId: "#splice-amulet:Splice.AmuletRules:AmuletRules",
|
|
2277
|
+
contractId: amuletRules.contract_id,
|
|
2278
|
+
choice: "AmuletRules_BuyMemberTraffic",
|
|
2279
|
+
choiceArgument: choiceArgs
|
|
2280
|
+
};
|
|
2281
|
+
return [exercise, disclosed];
|
|
2282
|
+
}
|
|
2135
2283
|
async getInstrumentAdmin(registryUrl) {
|
|
2136
2284
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
2137
2285
|
const info = await client.get("/registry/metadata/v1/info");
|
|
2138
2286
|
return info.adminId;
|
|
2139
2287
|
}
|
|
2288
|
+
async listInstruments(registryUrl, pageSize, pageToken) {
|
|
2289
|
+
const client = this.core.getTokenStandardClient(registryUrl);
|
|
2290
|
+
return client.get("/registry/metadata/v1/instruments", {
|
|
2291
|
+
query: {
|
|
2292
|
+
...pageSize && { pageSize },
|
|
2293
|
+
...pageToken && { pageToken }
|
|
2294
|
+
}
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2140
2297
|
// <T> is shape of viewValue related to queried interface.
|
|
2141
2298
|
// i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
|
|
2142
2299
|
async listContractsByInterface(interfaceId, partyId, limit) {
|
|
@@ -2732,23 +2889,34 @@ var ACSContainer = class _ACSContainer {
|
|
|
2732
2889
|
};
|
|
2733
2890
|
}
|
|
2734
2891
|
};
|
|
2892
|
+
var DEFAULT_MAX_CACHE_SIZE = 100;
|
|
2893
|
+
var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3;
|
|
2894
|
+
var SharedACSCache = new typescriptLruCache.LRUCache({
|
|
2895
|
+
maxSize: DEFAULT_MAX_CACHE_SIZE,
|
|
2896
|
+
entryExpirationTimeInMS: DEFAULT_ENTRY_EXPIRATION_TIME,
|
|
2897
|
+
onEntryEvicted: (entry) => {
|
|
2898
|
+
console.debug(`${entry} has expired`);
|
|
2899
|
+
SharedACSCacheStats.evictions++;
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
var SharedACSCacheStats = {
|
|
2903
|
+
hits: 0,
|
|
2904
|
+
misses: 0,
|
|
2905
|
+
evictions: 0,
|
|
2906
|
+
totalLookupTime: 0,
|
|
2907
|
+
totalCacheServeTime: 0
|
|
2908
|
+
};
|
|
2735
2909
|
|
|
2736
2910
|
// src/acs/acs-helper.ts
|
|
2737
|
-
var DEFAULT_MAX_CACHE_SIZE = 50;
|
|
2738
|
-
var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3;
|
|
2739
2911
|
var ACSHelper = class _ACSHelper {
|
|
2740
|
-
constructor(apiInstance, _logger, options) {
|
|
2912
|
+
constructor(apiInstance, _logger, options, sharedCache) {
|
|
2741
2913
|
__publicField(this, "contractsSet");
|
|
2742
2914
|
__publicField(this, "apiInstance");
|
|
2743
2915
|
__publicField(this, "wsSupport");
|
|
2744
2916
|
__publicField(this, "logger");
|
|
2745
2917
|
__publicField(this, "includeCreatedEventBlob");
|
|
2746
|
-
__publicField(this, "hits", 0);
|
|
2747
|
-
__publicField(this, "misses", 0);
|
|
2748
|
-
__publicField(this, "evictions", 0);
|
|
2749
|
-
__publicField(this, "totalLookuptime", 0);
|
|
2750
2918
|
__publicField(this, "totalCacheServeTime", 0);
|
|
2751
|
-
this.contractsSet = new typescriptLruCache.LRUCache({
|
|
2919
|
+
this.contractsSet = sharedCache ?? new typescriptLruCache.LRUCache({
|
|
2752
2920
|
maxSize: options?.maxCacheSize ?? DEFAULT_MAX_CACHE_SIZE,
|
|
2753
2921
|
entryExpirationTimeInMS: options?.entryExpirationTime ?? DEFAULT_ENTRY_EXPIRATION_TIME,
|
|
2754
2922
|
// 10 minutes
|
|
@@ -2756,7 +2924,7 @@ var ACSHelper = class _ACSHelper {
|
|
|
2756
2924
|
this.logger.debug(
|
|
2757
2925
|
`entry ${entry.key} isExpired = ${entry.isExpired}. evicting entry.`
|
|
2758
2926
|
);
|
|
2759
|
-
|
|
2927
|
+
SharedACSCacheStats.evictions++;
|
|
2760
2928
|
}
|
|
2761
2929
|
});
|
|
2762
2930
|
this.apiInstance = apiInstance;
|
|
@@ -2765,14 +2933,14 @@ var ACSHelper = class _ACSHelper {
|
|
|
2765
2933
|
this.includeCreatedEventBlob = options?.includeCreatedEventBlob ?? true;
|
|
2766
2934
|
}
|
|
2767
2935
|
getCacheStats() {
|
|
2768
|
-
const totalCalls =
|
|
2769
|
-
const hitRate = totalCalls ?
|
|
2770
|
-
const avgLookupTime = totalCalls > 0 ?
|
|
2936
|
+
const totalCalls = SharedACSCacheStats.hits + SharedACSCacheStats.misses;
|
|
2937
|
+
const hitRate = totalCalls ? SharedACSCacheStats.hits / totalCalls * 100 : 0;
|
|
2938
|
+
const avgLookupTime = totalCalls > 0 ? SharedACSCacheStats.totalLookupTime / totalCalls : 0;
|
|
2771
2939
|
return {
|
|
2772
2940
|
totalCalls,
|
|
2773
|
-
hits:
|
|
2774
|
-
misses:
|
|
2775
|
-
evictions:
|
|
2941
|
+
hits: SharedACSCacheStats.hits,
|
|
2942
|
+
misses: SharedACSCacheStats.misses,
|
|
2943
|
+
evictions: SharedACSCacheStats.evictions,
|
|
2776
2944
|
cacheSize: this.contractsSet.size,
|
|
2777
2945
|
hitRate: hitRate.toFixed(2) + "%",
|
|
2778
2946
|
averageLookupTime: avgLookupTime.toFixed(3) + " ms",
|
|
@@ -2782,22 +2950,22 @@ var ACSHelper = class _ACSHelper {
|
|
|
2782
2950
|
static createKey(party, templateId, interfaceId) {
|
|
2783
2951
|
return { party, templateId, interfaceId };
|
|
2784
2952
|
}
|
|
2785
|
-
static keyToString(key) {
|
|
2786
|
-
return `${key.party ? key.party : "ANY"}_T:${key.templateId ?? "()"}_I:${key.interfaceId ?? "()"}`;
|
|
2953
|
+
static keyToString(key, ledgerBaseUrl) {
|
|
2954
|
+
return `${ledgerBaseUrl}_${key.party ? key.party : "ANY"}_T:${key.templateId ?? "()"}_I:${key.interfaceId ?? "()"}`;
|
|
2787
2955
|
}
|
|
2788
2956
|
findACSContainer(key) {
|
|
2789
|
-
const keyStr = _ACSHelper.keyToString(key);
|
|
2957
|
+
const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href);
|
|
2790
2958
|
const start = performance.now();
|
|
2791
2959
|
const existing = this.contractsSet.get(keyStr);
|
|
2792
2960
|
const end = performance.now();
|
|
2793
|
-
|
|
2961
|
+
SharedACSCacheStats.totalLookupTime += end - start;
|
|
2794
2962
|
if (existing) {
|
|
2795
|
-
|
|
2963
|
+
SharedACSCacheStats.hits++;
|
|
2796
2964
|
this.logger.debug("cache hit");
|
|
2797
2965
|
return existing;
|
|
2798
2966
|
}
|
|
2799
2967
|
this.logger.debug("cache miss");
|
|
2800
|
-
|
|
2968
|
+
SharedACSCacheStats.misses++;
|
|
2801
2969
|
const newContainer = new ACSContainer(void 0, {
|
|
2802
2970
|
includeCreatedEventBlob: this.includeCreatedEventBlob
|
|
2803
2971
|
});
|
|
@@ -2815,8 +2983,10 @@ var ACSHelper = class _ACSHelper {
|
|
|
2815
2983
|
this.wsSupport
|
|
2816
2984
|
);
|
|
2817
2985
|
const end = performance.now();
|
|
2818
|
-
if (this.contractsSet.has(
|
|
2819
|
-
this.
|
|
2986
|
+
if (this.contractsSet.has(
|
|
2987
|
+
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
2988
|
+
)) {
|
|
2989
|
+
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2820
2990
|
}
|
|
2821
2991
|
return result;
|
|
2822
2992
|
}
|
|
@@ -2831,8 +3001,10 @@ var ACSHelper = class _ACSHelper {
|
|
|
2831
3001
|
this.wsSupport
|
|
2832
3002
|
);
|
|
2833
3003
|
const end = performance.now();
|
|
2834
|
-
if (this.contractsSet.has(
|
|
2835
|
-
this.
|
|
3004
|
+
if (this.contractsSet.has(
|
|
3005
|
+
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
3006
|
+
)) {
|
|
3007
|
+
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2836
3008
|
}
|
|
2837
3009
|
return result;
|
|
2838
3010
|
}
|
|
@@ -2844,13 +3016,14 @@ var LedgerClient = class {
|
|
|
2844
3016
|
constructor(baseUrl, _logger, isAdmin = false, accessToken, accessTokenProvider, version, acsHelperOptions) {
|
|
2845
3017
|
// privately manage the active connected version and associated client codegen
|
|
2846
3018
|
__publicField(this, "clients");
|
|
2847
|
-
__publicField(this, "clientVersion", "3.
|
|
2848
|
-
// default to 3.
|
|
3019
|
+
__publicField(this, "clientVersion", "3.4");
|
|
3020
|
+
// default to 3.4 if not provided
|
|
2849
3021
|
__publicField(this, "currentClient");
|
|
2850
3022
|
__publicField(this, "initialized", false);
|
|
2851
3023
|
__publicField(this, "accessTokenProvider");
|
|
2852
3024
|
__publicField(this, "acsHelper");
|
|
2853
3025
|
__publicField(this, "logger");
|
|
3026
|
+
__publicField(this, "baseUrl");
|
|
2854
3027
|
this.logger = _logger.child({ component: "LedgerClient" });
|
|
2855
3028
|
this.accessTokenProvider = accessTokenProvider;
|
|
2856
3029
|
this.clients = {
|
|
@@ -2887,7 +3060,13 @@ var LedgerClient = class {
|
|
|
2887
3060
|
};
|
|
2888
3061
|
this.clientVersion = version ?? this.clientVersion;
|
|
2889
3062
|
this.currentClient = this.clients[this.clientVersion];
|
|
2890
|
-
this.
|
|
3063
|
+
this.baseUrl = baseUrl;
|
|
3064
|
+
this.acsHelper = new ACSHelper(
|
|
3065
|
+
this,
|
|
3066
|
+
_logger,
|
|
3067
|
+
acsHelperOptions,
|
|
3068
|
+
SharedACSCache
|
|
3069
|
+
);
|
|
2891
3070
|
}
|
|
2892
3071
|
async init() {
|
|
2893
3072
|
if (!this.initialized) {
|
|
@@ -2895,6 +3074,7 @@ var LedgerClient = class {
|
|
|
2895
3074
|
this.clientVersion = this.parseSupportedVersions(
|
|
2896
3075
|
versionFromClient.data?.version
|
|
2897
3076
|
);
|
|
3077
|
+
this.currentClient = this.clients[this.clientVersion];
|
|
2898
3078
|
this.initialized = true;
|
|
2899
3079
|
}
|
|
2900
3080
|
}
|
|
@@ -3095,53 +3275,86 @@ var LedgerClient = class {
|
|
|
3095
3275
|
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
3096
3276
|
async allocateExternalParty(synchronizerId, onboardingTransactions, multiHashSignatures) {
|
|
3097
3277
|
await this.init();
|
|
3098
|
-
if (this.clientVersion
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3278
|
+
if (this.clientVersion == "3.3") {
|
|
3279
|
+
const client = this.clients["3.3"];
|
|
3280
|
+
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3281
|
+
body: {
|
|
3282
|
+
synchronizer: synchronizerId,
|
|
3283
|
+
identityProviderId: "",
|
|
3284
|
+
onboardingTransactions,
|
|
3285
|
+
multiHashSignatures
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
3288
|
+
return this.valueOrError(resp);
|
|
3289
|
+
} else {
|
|
3290
|
+
const client = this.clients["3.4"];
|
|
3291
|
+
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3292
|
+
body: {
|
|
3293
|
+
synchronizer: synchronizerId,
|
|
3294
|
+
identityProviderId: "",
|
|
3295
|
+
onboardingTransactions,
|
|
3296
|
+
multiHashSignatures
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
return this.valueOrError(resp);
|
|
3102
3300
|
}
|
|
3103
|
-
const client = this.clients["3.3"];
|
|
3104
|
-
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3105
|
-
body: {
|
|
3106
|
-
synchronizer: synchronizerId,
|
|
3107
|
-
identityProviderId: "",
|
|
3108
|
-
onboardingTransactions,
|
|
3109
|
-
multiHashSignatures
|
|
3110
|
-
}
|
|
3111
|
-
});
|
|
3112
|
-
return this.valueOrError(resp);
|
|
3113
3301
|
}
|
|
3114
3302
|
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
3115
3303
|
async generateTopology(synchronizerId, publicKey, partyHint, localParticipantObservationOnly = false, confirmationThreshold = 1, otherConfirmingParticipantUids = [], observingParticipantUids = []) {
|
|
3116
3304
|
await this.init();
|
|
3117
|
-
if (this.clientVersion
|
|
3118
|
-
|
|
3119
|
-
|
|
3305
|
+
if (this.clientVersion == "3.3") {
|
|
3306
|
+
const client = this.clients["3.3"];
|
|
3307
|
+
const body = {
|
|
3308
|
+
synchronizer: synchronizerId,
|
|
3309
|
+
partyHint,
|
|
3310
|
+
publicKey: {
|
|
3311
|
+
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3312
|
+
keyData: publicKey,
|
|
3313
|
+
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3314
|
+
},
|
|
3315
|
+
localParticipantObservationOnly,
|
|
3316
|
+
confirmationThreshold,
|
|
3317
|
+
otherConfirmingParticipantUids,
|
|
3318
|
+
observingParticipantUids
|
|
3319
|
+
};
|
|
3320
|
+
this.logger.debug(body, "generateTopology request body");
|
|
3321
|
+
const resp = await client.POST(
|
|
3322
|
+
"/v2/parties/external/generate-topology",
|
|
3323
|
+
{ body }
|
|
3120
3324
|
);
|
|
3325
|
+
return this.valueOrError(resp);
|
|
3326
|
+
} else {
|
|
3327
|
+
const client = this.clients["3.4"];
|
|
3328
|
+
const body = {
|
|
3329
|
+
synchronizer: synchronizerId,
|
|
3330
|
+
partyHint,
|
|
3331
|
+
publicKey: {
|
|
3332
|
+
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3333
|
+
keyData: publicKey,
|
|
3334
|
+
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3335
|
+
},
|
|
3336
|
+
localParticipantObservationOnly,
|
|
3337
|
+
confirmationThreshold,
|
|
3338
|
+
otherConfirmingParticipantUids,
|
|
3339
|
+
observingParticipantUids
|
|
3340
|
+
};
|
|
3341
|
+
this.logger.debug(body, "generateTopology request body");
|
|
3342
|
+
const resp = await client.POST(
|
|
3343
|
+
"/v2/parties/external/generate-topology",
|
|
3344
|
+
{ body }
|
|
3345
|
+
);
|
|
3346
|
+
return this.valueOrError(resp);
|
|
3121
3347
|
}
|
|
3122
|
-
const client = this.clients["3.3"];
|
|
3123
|
-
const body = {
|
|
3124
|
-
synchronizer: synchronizerId,
|
|
3125
|
-
partyHint,
|
|
3126
|
-
publicKey: {
|
|
3127
|
-
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3128
|
-
keyData: publicKey,
|
|
3129
|
-
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3130
|
-
},
|
|
3131
|
-
localParticipantObservationOnly,
|
|
3132
|
-
confirmationThreshold,
|
|
3133
|
-
otherConfirmingParticipantUids,
|
|
3134
|
-
observingParticipantUids
|
|
3135
|
-
};
|
|
3136
|
-
this.logger.debug(body, "generateTopology request body");
|
|
3137
|
-
const resp = await client.POST(
|
|
3138
|
-
"/v2/parties/external/generate-topology",
|
|
3139
|
-
{ body }
|
|
3140
|
-
);
|
|
3141
|
-
return this.valueOrError(resp);
|
|
3142
3348
|
}
|
|
3143
3349
|
async activeContracts(options) {
|
|
3144
|
-
const {
|
|
3350
|
+
const {
|
|
3351
|
+
offset,
|
|
3352
|
+
templateIds,
|
|
3353
|
+
parties,
|
|
3354
|
+
filterByParty,
|
|
3355
|
+
interfaceIds,
|
|
3356
|
+
limit
|
|
3357
|
+
} = options;
|
|
3145
3358
|
this.logger.debug(options, "options for active contracts");
|
|
3146
3359
|
if (templateIds?.length === 1 && parties?.length === 1) {
|
|
3147
3360
|
const party = parties[0];
|
|
@@ -3152,21 +3365,36 @@ var LedgerClient = class {
|
|
|
3152
3365
|
templateId
|
|
3153
3366
|
);
|
|
3154
3367
|
}
|
|
3155
|
-
if (
|
|
3368
|
+
if (interfaceIds?.length === 1 && parties?.length === 1) {
|
|
3369
|
+
const party = parties[0];
|
|
3370
|
+
const interfaceId = interfaceIds[0];
|
|
3371
|
+
return this.acsHelper.activeContractsForInterface(
|
|
3372
|
+
offset,
|
|
3373
|
+
party,
|
|
3374
|
+
interfaceId
|
|
3375
|
+
);
|
|
3376
|
+
}
|
|
3377
|
+
if (filterByParty && !templateIds?.length && !interfaceIds?.length && parties?.length === 1) {
|
|
3156
3378
|
const party = parties[0];
|
|
3157
3379
|
const r = this.acsHelper.activeContractsForInterface(
|
|
3158
3380
|
offset,
|
|
3159
3381
|
party,
|
|
3160
3382
|
""
|
|
3161
3383
|
);
|
|
3162
|
-
this.logger.info(r);
|
|
3163
3384
|
return r;
|
|
3164
3385
|
}
|
|
3165
|
-
const filter = this.
|
|
3386
|
+
const filter = this.buildActiveContractFilter(options);
|
|
3166
3387
|
this.logger.debug("falling back to post request");
|
|
3167
|
-
return await this.postWithRetry(
|
|
3388
|
+
return await this.postWithRetry(
|
|
3389
|
+
"/v2/state/active-contracts",
|
|
3390
|
+
filter,
|
|
3391
|
+
defaultRetryableOptions,
|
|
3392
|
+
{
|
|
3393
|
+
query: limit ? { limit: limit.toString() } : {}
|
|
3394
|
+
}
|
|
3395
|
+
);
|
|
3168
3396
|
}
|
|
3169
|
-
|
|
3397
|
+
buildActiveContractFilter(options) {
|
|
3170
3398
|
const filter = {
|
|
3171
3399
|
filter: {
|
|
3172
3400
|
filtersByParty: {}
|
|
@@ -3190,16 +3418,46 @@ var LedgerClient = class {
|
|
|
3190
3418
|
}
|
|
3191
3419
|
];
|
|
3192
3420
|
};
|
|
3421
|
+
const buildInterfaceFilter = (interfaceIds) => {
|
|
3422
|
+
if (!interfaceIds) return [];
|
|
3423
|
+
return [
|
|
3424
|
+
{
|
|
3425
|
+
identifierFilter: {
|
|
3426
|
+
InterfaceFilter: {
|
|
3427
|
+
value: {
|
|
3428
|
+
interfaceId: interfaceIds[0],
|
|
3429
|
+
includeCreatedEventBlob: true,
|
|
3430
|
+
//TODO: figure out if this should be configurable
|
|
3431
|
+
includeInterfaceView: true
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
];
|
|
3437
|
+
};
|
|
3438
|
+
this.logger.info(options, "active contract query options");
|
|
3193
3439
|
if (options?.filterByParty && options.parties && options.parties.length > 0) {
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3440
|
+
if (options?.templateIds && !options?.interfaceIds) {
|
|
3441
|
+
for (const party of options.parties) {
|
|
3442
|
+
filter.filter.filtersByParty[party] = {
|
|
3443
|
+
cumulative: options.templateIds ? buildTemplateFilter(options.templateIds) : []
|
|
3444
|
+
};
|
|
3445
|
+
}
|
|
3446
|
+
} else if (options?.interfaceIds && !options?.templateIds) {
|
|
3447
|
+
for (const party of options.parties) {
|
|
3448
|
+
filter.filter.filtersByParty[party] = {
|
|
3449
|
+
cumulative: options.interfaceIds ? buildInterfaceFilter(options.interfaceIds) : []
|
|
3450
|
+
};
|
|
3451
|
+
}
|
|
3198
3452
|
}
|
|
3199
3453
|
} else if (options?.templateIds) {
|
|
3200
3454
|
filter.filter.filtersForAnyParty = {
|
|
3201
3455
|
cumulative: buildTemplateFilter(options.templateIds)
|
|
3202
3456
|
};
|
|
3457
|
+
} else if (options?.interfaceIds) {
|
|
3458
|
+
filter.filter.filtersForAnyParty = {
|
|
3459
|
+
cumulative: buildInterfaceFilter(options.templateIds)
|
|
3460
|
+
};
|
|
3203
3461
|
}
|
|
3204
3462
|
return filter;
|
|
3205
3463
|
}
|
|
@@ -3224,17 +3482,11 @@ var LedgerClient = class {
|
|
|
3224
3482
|
getCacheStats() {
|
|
3225
3483
|
return this.acsHelper.getCacheStats();
|
|
3226
3484
|
}
|
|
3227
|
-
/**
|
|
3228
|
-
* @deprecated use postWithRetry instead, should be made private
|
|
3229
|
-
*/
|
|
3230
3485
|
async post(path, body, params, additionalOptions) {
|
|
3231
3486
|
const options = { body, params, ...additionalOptions };
|
|
3232
3487
|
const resp = await this.currentClient.POST(path, options);
|
|
3233
3488
|
return this.valueOrError(resp);
|
|
3234
3489
|
}
|
|
3235
|
-
/**
|
|
3236
|
-
* @deprecated use getWithRetry instead, should be made private
|
|
3237
|
-
*/
|
|
3238
3490
|
async get(path, params) {
|
|
3239
3491
|
await this.init();
|
|
3240
3492
|
const options = { params };
|