@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.js
CHANGED
|
@@ -332,27 +332,6 @@ var AllKnownMetaKeys = [
|
|
|
332
332
|
ReasonMetaKey,
|
|
333
333
|
BurnedMetaKey
|
|
334
334
|
];
|
|
335
|
-
function TransactionFilterBySetup(interfaceNames, options = { includeWildcard: false, isMasterUser: false }) {
|
|
336
|
-
const interfaceArrayed = Array.isArray(interfaceNames) ? interfaceNames : [interfaceNames];
|
|
337
|
-
if (options.isMasterUser)
|
|
338
|
-
return {
|
|
339
|
-
filtersByParty: {},
|
|
340
|
-
filtersForAnyParty: filtersForAnyParty(
|
|
341
|
-
interfaceArrayed,
|
|
342
|
-
options.includeWildcard ?? false
|
|
343
|
-
) ?? {}
|
|
344
|
-
};
|
|
345
|
-
else if (!options.partyId || options.partyId === void 0)
|
|
346
|
-
throw new Error("Party must be provided for non-master users");
|
|
347
|
-
else
|
|
348
|
-
return {
|
|
349
|
-
filtersByParty: filtersByParty(
|
|
350
|
-
options.partyId,
|
|
351
|
-
interfaceArrayed,
|
|
352
|
-
options.includeWildcard ?? false
|
|
353
|
-
) ?? {}
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
335
|
function EventFilterBySetup(interfaceNames, options = { includeWildcard: false, isMasterUser: false }) {
|
|
357
336
|
const interfaceArrayed = Array.isArray(interfaceNames) ? interfaceNames : [interfaceNames];
|
|
358
337
|
if (options.isMasterUser)
|
|
@@ -687,15 +666,15 @@ var renderTransactionEvent = (e) => {
|
|
|
687
666
|
);
|
|
688
667
|
return {
|
|
689
668
|
...e,
|
|
690
|
-
lockedHoldingsChange
|
|
691
|
-
unlockedHoldingsChange
|
|
692
|
-
lockedHoldingsChangeSummary
|
|
693
|
-
unlockedHoldingsChangeSummary
|
|
669
|
+
lockedHoldingsChange,
|
|
670
|
+
unlockedHoldingsChange,
|
|
671
|
+
lockedHoldingsChangeSummary,
|
|
672
|
+
unlockedHoldingsChangeSummary
|
|
694
673
|
};
|
|
695
674
|
};
|
|
696
675
|
var renderHoldingsChangeSummary = (s) => {
|
|
697
676
|
if (s.numInputs === 0 && s.numOutputs === 0 && s.inputAmount === "0" && s.outputAmount === "0" && s.amountChange === "0") {
|
|
698
|
-
return
|
|
677
|
+
return null;
|
|
699
678
|
}
|
|
700
679
|
return {
|
|
701
680
|
...s.numInputs !== 0 && { numInputs: s.numInputs },
|
|
@@ -707,13 +686,37 @@ var renderHoldingsChangeSummary = (s) => {
|
|
|
707
686
|
};
|
|
708
687
|
var renderHoldingsChange = (c) => {
|
|
709
688
|
if (c.creates.length === 0 && c.archives.length === 0) {
|
|
710
|
-
return
|
|
689
|
+
return null;
|
|
711
690
|
}
|
|
712
691
|
return {
|
|
713
692
|
...c.creates.length !== 0 && { creates: c.creates },
|
|
714
693
|
...c.archives.length !== 0 && { archives: c.archives }
|
|
715
694
|
};
|
|
716
695
|
};
|
|
696
|
+
function currentStatusFromChoiceOrResult(choice, resultTag) {
|
|
697
|
+
if (resultTag === "TransferInstructionResult_Failed") return "Failed";
|
|
698
|
+
if (resultTag === "TransferInstructionResult_Completed") return "Completed";
|
|
699
|
+
switch (choice) {
|
|
700
|
+
case "TransferInstruction_Reject":
|
|
701
|
+
return "Rejected";
|
|
702
|
+
case "TransferInstruction_Withdraw":
|
|
703
|
+
return "Withdrawn";
|
|
704
|
+
case "TransferInstruction_Accept":
|
|
705
|
+
case "TransferInstruction_Update":
|
|
706
|
+
return "Pending";
|
|
707
|
+
default:
|
|
708
|
+
return "Pending";
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function getCorrelationIdFromTransferInstruction(currentInstructionCid, originalInstructionCid) {
|
|
712
|
+
return originalInstructionCid ?? currentInstructionCid;
|
|
713
|
+
}
|
|
714
|
+
function getPendingTransferInstructionCid(exercisedEvent) {
|
|
715
|
+
const output = exercisedEvent.exerciseResult?.output;
|
|
716
|
+
if (output?.tag !== "TransferInstructionResult_Pending") return void 0;
|
|
717
|
+
const cid = output.value?.transferInstructionCid;
|
|
718
|
+
return cid ?? void 0;
|
|
719
|
+
}
|
|
717
720
|
var TransactionParser = class {
|
|
718
721
|
constructor(transaction, ledgerClient, partyId, isMasterUser) {
|
|
719
722
|
__publicField(this, "ledgerClient");
|
|
@@ -858,9 +861,24 @@ var TransactionParser = class {
|
|
|
858
861
|
].some((stakeholder) => stakeholder === this.partyId)) {
|
|
859
862
|
result = null;
|
|
860
863
|
} else {
|
|
864
|
+
const multiStepCorrelationId = getCorrelationIdFromTransferInstruction(
|
|
865
|
+
originalCreate.contractId,
|
|
866
|
+
transferInstructionView.originalInstructionCid ?? null
|
|
867
|
+
);
|
|
861
868
|
result = {
|
|
862
869
|
payload: transferInstructionView,
|
|
863
|
-
transferInstruction:
|
|
870
|
+
transferInstruction: {
|
|
871
|
+
originalInstructionCid: transferInstructionView.originalInstructionCid,
|
|
872
|
+
transfer: transferInstructionView.transfer,
|
|
873
|
+
meta: transferInstructionView.meta,
|
|
874
|
+
status: {
|
|
875
|
+
before: transferInstructionView.status,
|
|
876
|
+
// raw DAML pending sub-state
|
|
877
|
+
current: { tag: "Pending", value: {} }
|
|
878
|
+
// normalized
|
|
879
|
+
},
|
|
880
|
+
multiStepCorrelationId
|
|
881
|
+
},
|
|
864
882
|
unlockedHoldingsChange: { creates: [], archives: [] },
|
|
865
883
|
lockedHoldingsChange: { creates: [], archives: [] },
|
|
866
884
|
unlockedHoldingsChangeSummary: EmptyHoldingsChangeSummary,
|
|
@@ -994,6 +1012,12 @@ var TransactionParser = class {
|
|
|
994
1012
|
);
|
|
995
1013
|
return null;
|
|
996
1014
|
}
|
|
1015
|
+
const resultTag = exercisedEvent.exerciseResult?.output?.tag || void 0;
|
|
1016
|
+
const pendingCid = getPendingTransferInstructionCid(exercisedEvent);
|
|
1017
|
+
const currentTag = currentStatusFromChoiceOrResult(
|
|
1018
|
+
exercisedEvent.choice,
|
|
1019
|
+
resultTag
|
|
1020
|
+
);
|
|
997
1021
|
const children = await this.getChildren(exercisedEvent);
|
|
998
1022
|
const receiverAmounts = /* @__PURE__ */ new Map();
|
|
999
1023
|
children.creates.filter((h) => h.owner !== sender).forEach(
|
|
@@ -1037,13 +1061,25 @@ var TransactionParser = class {
|
|
|
1037
1061
|
meta
|
|
1038
1062
|
};
|
|
1039
1063
|
}
|
|
1064
|
+
if (transferInstructions) {
|
|
1065
|
+
transferInstructions.status.current = transferInstructions.status.current || { tag: currentTag, value: {} };
|
|
1066
|
+
return {
|
|
1067
|
+
label,
|
|
1068
|
+
children,
|
|
1069
|
+
transferInstruction: transferInstructions
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1040
1072
|
const transferInstruction = {
|
|
1041
1073
|
originalInstructionCid: null,
|
|
1042
|
-
|
|
1074
|
+
...choiceArgumentTransfer !== void 0 && {
|
|
1075
|
+
transfer: choiceArgumentTransfer
|
|
1076
|
+
},
|
|
1043
1077
|
status: {
|
|
1044
|
-
before: null
|
|
1078
|
+
before: null,
|
|
1079
|
+
current: { tag: currentTag, value: {} }
|
|
1045
1080
|
},
|
|
1046
|
-
meta: null
|
|
1081
|
+
meta: null,
|
|
1082
|
+
...pendingCid ? { multiStepCorrelationId: pendingCid } : {}
|
|
1047
1083
|
};
|
|
1048
1084
|
return {
|
|
1049
1085
|
label,
|
|
@@ -1081,6 +1117,7 @@ var TransactionParser = class {
|
|
|
1081
1117
|
};
|
|
1082
1118
|
}
|
|
1083
1119
|
async buildFromTransferInstructionExercise(exercisedEvent, tokenStandardChoice) {
|
|
1120
|
+
const instructionCid = exercisedEvent.contractId;
|
|
1084
1121
|
const transferInstructionEvents = await this.getEventsForArchive(exercisedEvent);
|
|
1085
1122
|
if (!transferInstructionEvents) {
|
|
1086
1123
|
return null;
|
|
@@ -1089,15 +1126,26 @@ var TransactionParser = class {
|
|
|
1089
1126
|
transferInstructionEvents.created.createdEvent,
|
|
1090
1127
|
TRANSFER_INSTRUCTION_INTERFACE_ID
|
|
1091
1128
|
).viewValue;
|
|
1129
|
+
const multiStepCorrelationId = getCorrelationIdFromTransferInstruction(
|
|
1130
|
+
instructionCid,
|
|
1131
|
+
transferInstructionView.originalInstructionCid ?? null
|
|
1132
|
+
);
|
|
1133
|
+
const resultTag = exercisedEvent.exerciseResult?.output?.tag || void 0;
|
|
1134
|
+
const currentTag = currentStatusFromChoiceOrResult(
|
|
1135
|
+
exercisedEvent.choice,
|
|
1136
|
+
resultTag
|
|
1137
|
+
);
|
|
1092
1138
|
const transferInstruction = {
|
|
1093
1139
|
originalInstructionCid: transferInstructionView.originalInstructionCid,
|
|
1140
|
+
multiStepCorrelationId,
|
|
1094
1141
|
transfer: transferInstructionView.transfer,
|
|
1095
1142
|
meta: transferInstructionView.meta,
|
|
1096
1143
|
status: {
|
|
1097
|
-
before: transferInstructionView.status
|
|
1144
|
+
before: transferInstructionView.status,
|
|
1145
|
+
current: { tag: currentTag, value: {} }
|
|
1098
1146
|
}
|
|
1099
1147
|
};
|
|
1100
|
-
const exerciseResultOutputTag =
|
|
1148
|
+
const exerciseResultOutputTag = resultTag;
|
|
1101
1149
|
let result = null;
|
|
1102
1150
|
switch (exerciseResultOutputTag) {
|
|
1103
1151
|
case "TransferInstructionResult_Failed":
|
|
@@ -1342,7 +1390,7 @@ function holdingChangesNonEmpty(event) {
|
|
|
1342
1390
|
var MEMO_KEY = "splice.lfdecentralizedtrust.org/reason";
|
|
1343
1391
|
var REQUESTED_AT_SKEW_MS = 6e4;
|
|
1344
1392
|
var EMPTY_META = { values: {} };
|
|
1345
|
-
var CoreService = class {
|
|
1393
|
+
var CoreService = class _CoreService {
|
|
1346
1394
|
constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, isAdmin = false, accessToken = "") {
|
|
1347
1395
|
this.ledgerClient = ledgerClient;
|
|
1348
1396
|
this.scanProxyClient = scanProxyClient;
|
|
@@ -1361,7 +1409,7 @@ var CoreService = class {
|
|
|
1361
1409
|
this.accessTokenProvider
|
|
1362
1410
|
);
|
|
1363
1411
|
}
|
|
1364
|
-
async getInputHoldingsCids(sender, inputUtxos) {
|
|
1412
|
+
async getInputHoldingsCids(sender, inputUtxos, amount) {
|
|
1365
1413
|
const now = /* @__PURE__ */ new Date();
|
|
1366
1414
|
if (inputUtxos && inputUtxos.length > 0) {
|
|
1367
1415
|
return inputUtxos;
|
|
@@ -1375,35 +1423,77 @@ var CoreService = class {
|
|
|
1375
1423
|
"Sender has no holdings, so transfer can't be executed."
|
|
1376
1424
|
);
|
|
1377
1425
|
}
|
|
1378
|
-
|
|
1426
|
+
const unlockedSenderHoldings = senderHoldings.filter((utxo) => {
|
|
1379
1427
|
const lock = utxo.interfaceViewValue.lock;
|
|
1380
1428
|
if (!lock) return true;
|
|
1381
1429
|
const expiresAt = lock.expiresAt;
|
|
1382
1430
|
if (!expiresAt) return false;
|
|
1383
1431
|
const expiresAtDate = new Date(expiresAt);
|
|
1384
1432
|
return expiresAtDate <= now;
|
|
1385
|
-
})
|
|
1433
|
+
});
|
|
1434
|
+
if (unlockedSenderHoldings.length > 100) {
|
|
1435
|
+
this.logger.warn(`Sender has more than 100 unlocked utxos.`);
|
|
1436
|
+
}
|
|
1437
|
+
if (amount) {
|
|
1438
|
+
return _CoreService.getInputHoldingsCidsForAmount(
|
|
1439
|
+
amount,
|
|
1440
|
+
unlockedSenderHoldings
|
|
1441
|
+
);
|
|
1442
|
+
} else {
|
|
1443
|
+
return unlockedSenderHoldings.map((h) => h.contractId);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
static async getInputHoldingsCidsForAmount(amount, unlockedSenderHoldings) {
|
|
1447
|
+
const exactAmount = unlockedSenderHoldings.find(
|
|
1448
|
+
(holding) => parseFloat(holding.interfaceViewValue.amount) === amount
|
|
1449
|
+
);
|
|
1450
|
+
if (exactAmount) {
|
|
1451
|
+
return [exactAmount.contractId];
|
|
1452
|
+
}
|
|
1453
|
+
const sortedUnlockedSenderHoldings = unlockedSenderHoldings.toSorted(
|
|
1454
|
+
(a, b) => parseFloat(a.interfaceViewValue.amount) - parseFloat(b.interfaceViewValue.amount)
|
|
1455
|
+
);
|
|
1456
|
+
const largestHoldingAmount = sortedUnlockedSenderHoldings.pop();
|
|
1457
|
+
if (!largestHoldingAmount) {
|
|
1458
|
+
throw new Error(`Sender doesn't have any unlocked holdings`);
|
|
1459
|
+
}
|
|
1460
|
+
let currentSum = parseFloat(
|
|
1461
|
+
largestHoldingAmount.interfaceViewValue.amount
|
|
1462
|
+
);
|
|
1463
|
+
const cIds = [largestHoldingAmount.contractId];
|
|
1464
|
+
for (const h of sortedUnlockedSenderHoldings) {
|
|
1465
|
+
if (currentSum >= amount) {
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
const currentHoldingAmount = parseFloat(h.interfaceViewValue.amount);
|
|
1469
|
+
currentSum += currentHoldingAmount;
|
|
1470
|
+
cIds.push(h.contractId);
|
|
1471
|
+
}
|
|
1472
|
+
if (currentSum < amount) {
|
|
1473
|
+
throw new Error(
|
|
1474
|
+
`Sender doesn't have sufficient funds for this transfer. Missing amount: ${amount - currentSum}`
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
if (cIds.length > 100) {
|
|
1478
|
+
throw new Error(
|
|
1479
|
+
`Exceeded the maximum of 100 utxos in 1 transaction`
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
return cIds;
|
|
1386
1483
|
}
|
|
1387
1484
|
async listContractsByInterface(interfaceId, partyId, limit) {
|
|
1388
1485
|
try {
|
|
1389
1486
|
const ledgerEnd = await this.ledgerClient.getWithRetry(
|
|
1390
1487
|
"/v2/state/ledger-end"
|
|
1391
1488
|
);
|
|
1392
|
-
const
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
activeAtOffset: ledgerEnd.offset
|
|
1401
|
-
},
|
|
1402
|
-
defaultRetryableOptions,
|
|
1403
|
-
{
|
|
1404
|
-
query: limit ? { limit: limit.toString() } : {}
|
|
1405
|
-
}
|
|
1406
|
-
);
|
|
1489
|
+
const options = {
|
|
1490
|
+
offset: ledgerEnd.offset,
|
|
1491
|
+
interfaceIds: [interfaceId],
|
|
1492
|
+
parties: [partyId],
|
|
1493
|
+
filterByParty: true,
|
|
1494
|
+
limit: limit ?? 100
|
|
1495
|
+
};
|
|
1496
|
+
const acsResponses = await this.ledgerClient.activeContracts(options);
|
|
1407
1497
|
const isActiveContractEntry = (acsResponse) => !!acsResponse.contractEntry.JsActiveContract?.createdEvent;
|
|
1408
1498
|
const activeContractEntries = acsResponses.filter(
|
|
1409
1499
|
isActiveContractEntry
|
|
@@ -1740,7 +1830,8 @@ var TransferService = class {
|
|
|
1740
1830
|
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta) {
|
|
1741
1831
|
const inputHoldingCids = await this.core.getInputHoldingsCids(
|
|
1742
1832
|
sender,
|
|
1743
|
-
inputUtxos
|
|
1833
|
+
inputUtxos,
|
|
1834
|
+
parseFloat(amount)
|
|
1744
1835
|
);
|
|
1745
1836
|
return {
|
|
1746
1837
|
expectedAdmin: instrumentAdmin,
|
|
@@ -2124,11 +2215,77 @@ var TokenStandardService = class {
|
|
|
2124
2215
|
);
|
|
2125
2216
|
}
|
|
2126
2217
|
}
|
|
2218
|
+
async buyMemberTraffic(dso, provider, trafficAmount, synchronizerId, memberId, migrationId, inputUtxos) {
|
|
2219
|
+
const amuletRules = await this.scanProxyClient.getAmuletRules();
|
|
2220
|
+
const activeRound = await this.scanProxyClient.getActiveOpenMiningRound();
|
|
2221
|
+
const inputHoldings = await this.core.getInputHoldingsCids(
|
|
2222
|
+
provider,
|
|
2223
|
+
inputUtxos,
|
|
2224
|
+
trafficAmount
|
|
2225
|
+
);
|
|
2226
|
+
if (!amuletRules) {
|
|
2227
|
+
throw new Error("AmuletRules contract not found");
|
|
2228
|
+
}
|
|
2229
|
+
if (!activeRound) {
|
|
2230
|
+
throw new Error(
|
|
2231
|
+
"OpenMiningRound active at current moment not found"
|
|
2232
|
+
);
|
|
2233
|
+
}
|
|
2234
|
+
const disclosed = [
|
|
2235
|
+
{
|
|
2236
|
+
templateId: amuletRules.template_id,
|
|
2237
|
+
contractId: amuletRules.contract_id,
|
|
2238
|
+
createdEventBlob: amuletRules.created_event_blob,
|
|
2239
|
+
synchronizerId
|
|
2240
|
+
},
|
|
2241
|
+
{
|
|
2242
|
+
templateId: activeRound.template_id,
|
|
2243
|
+
contractId: activeRound.contract_id,
|
|
2244
|
+
createdEventBlob: activeRound.created_event_blob,
|
|
2245
|
+
synchronizerId
|
|
2246
|
+
}
|
|
2247
|
+
];
|
|
2248
|
+
const context = {
|
|
2249
|
+
openMiningRound: activeRound.contract_id,
|
|
2250
|
+
issuingMiningRounds: [],
|
|
2251
|
+
validatorRights: [],
|
|
2252
|
+
featuredAppRight: null
|
|
2253
|
+
};
|
|
2254
|
+
const choiceArgs = {
|
|
2255
|
+
context,
|
|
2256
|
+
inputs: inputHoldings.map((cid) => ({
|
|
2257
|
+
tag: "InputAmulet",
|
|
2258
|
+
value: cid
|
|
2259
|
+
})),
|
|
2260
|
+
provider,
|
|
2261
|
+
memberId,
|
|
2262
|
+
synchronizerId,
|
|
2263
|
+
migrationId,
|
|
2264
|
+
trafficAmount,
|
|
2265
|
+
expectedDso: dso
|
|
2266
|
+
};
|
|
2267
|
+
const exercise = {
|
|
2268
|
+
templateId: "#splice-amulet:Splice.AmuletRules:AmuletRules",
|
|
2269
|
+
contractId: amuletRules.contract_id,
|
|
2270
|
+
choice: "AmuletRules_BuyMemberTraffic",
|
|
2271
|
+
choiceArgument: choiceArgs
|
|
2272
|
+
};
|
|
2273
|
+
return [exercise, disclosed];
|
|
2274
|
+
}
|
|
2127
2275
|
async getInstrumentAdmin(registryUrl) {
|
|
2128
2276
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
2129
2277
|
const info = await client.get("/registry/metadata/v1/info");
|
|
2130
2278
|
return info.adminId;
|
|
2131
2279
|
}
|
|
2280
|
+
async listInstruments(registryUrl, pageSize, pageToken) {
|
|
2281
|
+
const client = this.core.getTokenStandardClient(registryUrl);
|
|
2282
|
+
return client.get("/registry/metadata/v1/instruments", {
|
|
2283
|
+
query: {
|
|
2284
|
+
...pageSize && { pageSize },
|
|
2285
|
+
...pageToken && { pageToken }
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2132
2289
|
// <T> is shape of viewValue related to queried interface.
|
|
2133
2290
|
// i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
|
|
2134
2291
|
async listContractsByInterface(interfaceId, partyId, limit) {
|
|
@@ -2724,23 +2881,34 @@ var ACSContainer = class _ACSContainer {
|
|
|
2724
2881
|
};
|
|
2725
2882
|
}
|
|
2726
2883
|
};
|
|
2884
|
+
var DEFAULT_MAX_CACHE_SIZE = 100;
|
|
2885
|
+
var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3;
|
|
2886
|
+
var SharedACSCache = new LRUCache({
|
|
2887
|
+
maxSize: DEFAULT_MAX_CACHE_SIZE,
|
|
2888
|
+
entryExpirationTimeInMS: DEFAULT_ENTRY_EXPIRATION_TIME,
|
|
2889
|
+
onEntryEvicted: (entry) => {
|
|
2890
|
+
console.debug(`${entry} has expired`);
|
|
2891
|
+
SharedACSCacheStats.evictions++;
|
|
2892
|
+
}
|
|
2893
|
+
});
|
|
2894
|
+
var SharedACSCacheStats = {
|
|
2895
|
+
hits: 0,
|
|
2896
|
+
misses: 0,
|
|
2897
|
+
evictions: 0,
|
|
2898
|
+
totalLookupTime: 0,
|
|
2899
|
+
totalCacheServeTime: 0
|
|
2900
|
+
};
|
|
2727
2901
|
|
|
2728
2902
|
// src/acs/acs-helper.ts
|
|
2729
|
-
var DEFAULT_MAX_CACHE_SIZE = 50;
|
|
2730
|
-
var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3;
|
|
2731
2903
|
var ACSHelper = class _ACSHelper {
|
|
2732
|
-
constructor(apiInstance, _logger, options) {
|
|
2904
|
+
constructor(apiInstance, _logger, options, sharedCache) {
|
|
2733
2905
|
__publicField(this, "contractsSet");
|
|
2734
2906
|
__publicField(this, "apiInstance");
|
|
2735
2907
|
__publicField(this, "wsSupport");
|
|
2736
2908
|
__publicField(this, "logger");
|
|
2737
2909
|
__publicField(this, "includeCreatedEventBlob");
|
|
2738
|
-
__publicField(this, "hits", 0);
|
|
2739
|
-
__publicField(this, "misses", 0);
|
|
2740
|
-
__publicField(this, "evictions", 0);
|
|
2741
|
-
__publicField(this, "totalLookuptime", 0);
|
|
2742
2910
|
__publicField(this, "totalCacheServeTime", 0);
|
|
2743
|
-
this.contractsSet = new LRUCache({
|
|
2911
|
+
this.contractsSet = sharedCache ?? new LRUCache({
|
|
2744
2912
|
maxSize: options?.maxCacheSize ?? DEFAULT_MAX_CACHE_SIZE,
|
|
2745
2913
|
entryExpirationTimeInMS: options?.entryExpirationTime ?? DEFAULT_ENTRY_EXPIRATION_TIME,
|
|
2746
2914
|
// 10 minutes
|
|
@@ -2748,7 +2916,7 @@ var ACSHelper = class _ACSHelper {
|
|
|
2748
2916
|
this.logger.debug(
|
|
2749
2917
|
`entry ${entry.key} isExpired = ${entry.isExpired}. evicting entry.`
|
|
2750
2918
|
);
|
|
2751
|
-
|
|
2919
|
+
SharedACSCacheStats.evictions++;
|
|
2752
2920
|
}
|
|
2753
2921
|
});
|
|
2754
2922
|
this.apiInstance = apiInstance;
|
|
@@ -2757,14 +2925,14 @@ var ACSHelper = class _ACSHelper {
|
|
|
2757
2925
|
this.includeCreatedEventBlob = options?.includeCreatedEventBlob ?? true;
|
|
2758
2926
|
}
|
|
2759
2927
|
getCacheStats() {
|
|
2760
|
-
const totalCalls =
|
|
2761
|
-
const hitRate = totalCalls ?
|
|
2762
|
-
const avgLookupTime = totalCalls > 0 ?
|
|
2928
|
+
const totalCalls = SharedACSCacheStats.hits + SharedACSCacheStats.misses;
|
|
2929
|
+
const hitRate = totalCalls ? SharedACSCacheStats.hits / totalCalls * 100 : 0;
|
|
2930
|
+
const avgLookupTime = totalCalls > 0 ? SharedACSCacheStats.totalLookupTime / totalCalls : 0;
|
|
2763
2931
|
return {
|
|
2764
2932
|
totalCalls,
|
|
2765
|
-
hits:
|
|
2766
|
-
misses:
|
|
2767
|
-
evictions:
|
|
2933
|
+
hits: SharedACSCacheStats.hits,
|
|
2934
|
+
misses: SharedACSCacheStats.misses,
|
|
2935
|
+
evictions: SharedACSCacheStats.evictions,
|
|
2768
2936
|
cacheSize: this.contractsSet.size,
|
|
2769
2937
|
hitRate: hitRate.toFixed(2) + "%",
|
|
2770
2938
|
averageLookupTime: avgLookupTime.toFixed(3) + " ms",
|
|
@@ -2774,22 +2942,22 @@ var ACSHelper = class _ACSHelper {
|
|
|
2774
2942
|
static createKey(party, templateId, interfaceId) {
|
|
2775
2943
|
return { party, templateId, interfaceId };
|
|
2776
2944
|
}
|
|
2777
|
-
static keyToString(key) {
|
|
2778
|
-
return `${key.party ? key.party : "ANY"}_T:${key.templateId ?? "()"}_I:${key.interfaceId ?? "()"}`;
|
|
2945
|
+
static keyToString(key, ledgerBaseUrl) {
|
|
2946
|
+
return `${ledgerBaseUrl}_${key.party ? key.party : "ANY"}_T:${key.templateId ?? "()"}_I:${key.interfaceId ?? "()"}`;
|
|
2779
2947
|
}
|
|
2780
2948
|
findACSContainer(key) {
|
|
2781
|
-
const keyStr = _ACSHelper.keyToString(key);
|
|
2949
|
+
const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href);
|
|
2782
2950
|
const start = performance.now();
|
|
2783
2951
|
const existing = this.contractsSet.get(keyStr);
|
|
2784
2952
|
const end = performance.now();
|
|
2785
|
-
|
|
2953
|
+
SharedACSCacheStats.totalLookupTime += end - start;
|
|
2786
2954
|
if (existing) {
|
|
2787
|
-
|
|
2955
|
+
SharedACSCacheStats.hits++;
|
|
2788
2956
|
this.logger.debug("cache hit");
|
|
2789
2957
|
return existing;
|
|
2790
2958
|
}
|
|
2791
2959
|
this.logger.debug("cache miss");
|
|
2792
|
-
|
|
2960
|
+
SharedACSCacheStats.misses++;
|
|
2793
2961
|
const newContainer = new ACSContainer(void 0, {
|
|
2794
2962
|
includeCreatedEventBlob: this.includeCreatedEventBlob
|
|
2795
2963
|
});
|
|
@@ -2807,8 +2975,10 @@ var ACSHelper = class _ACSHelper {
|
|
|
2807
2975
|
this.wsSupport
|
|
2808
2976
|
);
|
|
2809
2977
|
const end = performance.now();
|
|
2810
|
-
if (this.contractsSet.has(
|
|
2811
|
-
this.
|
|
2978
|
+
if (this.contractsSet.has(
|
|
2979
|
+
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
2980
|
+
)) {
|
|
2981
|
+
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2812
2982
|
}
|
|
2813
2983
|
return result;
|
|
2814
2984
|
}
|
|
@@ -2823,8 +2993,10 @@ var ACSHelper = class _ACSHelper {
|
|
|
2823
2993
|
this.wsSupport
|
|
2824
2994
|
);
|
|
2825
2995
|
const end = performance.now();
|
|
2826
|
-
if (this.contractsSet.has(
|
|
2827
|
-
this.
|
|
2996
|
+
if (this.contractsSet.has(
|
|
2997
|
+
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
2998
|
+
)) {
|
|
2999
|
+
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2828
3000
|
}
|
|
2829
3001
|
return result;
|
|
2830
3002
|
}
|
|
@@ -2836,13 +3008,14 @@ var LedgerClient = class {
|
|
|
2836
3008
|
constructor(baseUrl, _logger, isAdmin = false, accessToken, accessTokenProvider, version, acsHelperOptions) {
|
|
2837
3009
|
// privately manage the active connected version and associated client codegen
|
|
2838
3010
|
__publicField(this, "clients");
|
|
2839
|
-
__publicField(this, "clientVersion", "3.
|
|
2840
|
-
// default to 3.
|
|
3011
|
+
__publicField(this, "clientVersion", "3.4");
|
|
3012
|
+
// default to 3.4 if not provided
|
|
2841
3013
|
__publicField(this, "currentClient");
|
|
2842
3014
|
__publicField(this, "initialized", false);
|
|
2843
3015
|
__publicField(this, "accessTokenProvider");
|
|
2844
3016
|
__publicField(this, "acsHelper");
|
|
2845
3017
|
__publicField(this, "logger");
|
|
3018
|
+
__publicField(this, "baseUrl");
|
|
2846
3019
|
this.logger = _logger.child({ component: "LedgerClient" });
|
|
2847
3020
|
this.accessTokenProvider = accessTokenProvider;
|
|
2848
3021
|
this.clients = {
|
|
@@ -2879,7 +3052,13 @@ var LedgerClient = class {
|
|
|
2879
3052
|
};
|
|
2880
3053
|
this.clientVersion = version ?? this.clientVersion;
|
|
2881
3054
|
this.currentClient = this.clients[this.clientVersion];
|
|
2882
|
-
this.
|
|
3055
|
+
this.baseUrl = baseUrl;
|
|
3056
|
+
this.acsHelper = new ACSHelper(
|
|
3057
|
+
this,
|
|
3058
|
+
_logger,
|
|
3059
|
+
acsHelperOptions,
|
|
3060
|
+
SharedACSCache
|
|
3061
|
+
);
|
|
2883
3062
|
}
|
|
2884
3063
|
async init() {
|
|
2885
3064
|
if (!this.initialized) {
|
|
@@ -2887,6 +3066,7 @@ var LedgerClient = class {
|
|
|
2887
3066
|
this.clientVersion = this.parseSupportedVersions(
|
|
2888
3067
|
versionFromClient.data?.version
|
|
2889
3068
|
);
|
|
3069
|
+
this.currentClient = this.clients[this.clientVersion];
|
|
2890
3070
|
this.initialized = true;
|
|
2891
3071
|
}
|
|
2892
3072
|
}
|
|
@@ -3087,53 +3267,86 @@ var LedgerClient = class {
|
|
|
3087
3267
|
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
3088
3268
|
async allocateExternalParty(synchronizerId, onboardingTransactions, multiHashSignatures) {
|
|
3089
3269
|
await this.init();
|
|
3090
|
-
if (this.clientVersion
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3270
|
+
if (this.clientVersion == "3.3") {
|
|
3271
|
+
const client = this.clients["3.3"];
|
|
3272
|
+
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3273
|
+
body: {
|
|
3274
|
+
synchronizer: synchronizerId,
|
|
3275
|
+
identityProviderId: "",
|
|
3276
|
+
onboardingTransactions,
|
|
3277
|
+
multiHashSignatures
|
|
3278
|
+
}
|
|
3279
|
+
});
|
|
3280
|
+
return this.valueOrError(resp);
|
|
3281
|
+
} else {
|
|
3282
|
+
const client = this.clients["3.4"];
|
|
3283
|
+
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3284
|
+
body: {
|
|
3285
|
+
synchronizer: synchronizerId,
|
|
3286
|
+
identityProviderId: "",
|
|
3287
|
+
onboardingTransactions,
|
|
3288
|
+
multiHashSignatures
|
|
3289
|
+
}
|
|
3290
|
+
});
|
|
3291
|
+
return this.valueOrError(resp);
|
|
3094
3292
|
}
|
|
3095
|
-
const client = this.clients["3.3"];
|
|
3096
|
-
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3097
|
-
body: {
|
|
3098
|
-
synchronizer: synchronizerId,
|
|
3099
|
-
identityProviderId: "",
|
|
3100
|
-
onboardingTransactions,
|
|
3101
|
-
multiHashSignatures
|
|
3102
|
-
}
|
|
3103
|
-
});
|
|
3104
|
-
return this.valueOrError(resp);
|
|
3105
3293
|
}
|
|
3106
3294
|
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
3107
3295
|
async generateTopology(synchronizerId, publicKey, partyHint, localParticipantObservationOnly = false, confirmationThreshold = 1, otherConfirmingParticipantUids = [], observingParticipantUids = []) {
|
|
3108
3296
|
await this.init();
|
|
3109
|
-
if (this.clientVersion
|
|
3110
|
-
|
|
3111
|
-
|
|
3297
|
+
if (this.clientVersion == "3.3") {
|
|
3298
|
+
const client = this.clients["3.3"];
|
|
3299
|
+
const body = {
|
|
3300
|
+
synchronizer: synchronizerId,
|
|
3301
|
+
partyHint,
|
|
3302
|
+
publicKey: {
|
|
3303
|
+
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3304
|
+
keyData: publicKey,
|
|
3305
|
+
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3306
|
+
},
|
|
3307
|
+
localParticipantObservationOnly,
|
|
3308
|
+
confirmationThreshold,
|
|
3309
|
+
otherConfirmingParticipantUids,
|
|
3310
|
+
observingParticipantUids
|
|
3311
|
+
};
|
|
3312
|
+
this.logger.debug(body, "generateTopology request body");
|
|
3313
|
+
const resp = await client.POST(
|
|
3314
|
+
"/v2/parties/external/generate-topology",
|
|
3315
|
+
{ body }
|
|
3112
3316
|
);
|
|
3317
|
+
return this.valueOrError(resp);
|
|
3318
|
+
} else {
|
|
3319
|
+
const client = this.clients["3.4"];
|
|
3320
|
+
const body = {
|
|
3321
|
+
synchronizer: synchronizerId,
|
|
3322
|
+
partyHint,
|
|
3323
|
+
publicKey: {
|
|
3324
|
+
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3325
|
+
keyData: publicKey,
|
|
3326
|
+
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3327
|
+
},
|
|
3328
|
+
localParticipantObservationOnly,
|
|
3329
|
+
confirmationThreshold,
|
|
3330
|
+
otherConfirmingParticipantUids,
|
|
3331
|
+
observingParticipantUids
|
|
3332
|
+
};
|
|
3333
|
+
this.logger.debug(body, "generateTopology request body");
|
|
3334
|
+
const resp = await client.POST(
|
|
3335
|
+
"/v2/parties/external/generate-topology",
|
|
3336
|
+
{ body }
|
|
3337
|
+
);
|
|
3338
|
+
return this.valueOrError(resp);
|
|
3113
3339
|
}
|
|
3114
|
-
const client = this.clients["3.3"];
|
|
3115
|
-
const body = {
|
|
3116
|
-
synchronizer: synchronizerId,
|
|
3117
|
-
partyHint,
|
|
3118
|
-
publicKey: {
|
|
3119
|
-
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3120
|
-
keyData: publicKey,
|
|
3121
|
-
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3122
|
-
},
|
|
3123
|
-
localParticipantObservationOnly,
|
|
3124
|
-
confirmationThreshold,
|
|
3125
|
-
otherConfirmingParticipantUids,
|
|
3126
|
-
observingParticipantUids
|
|
3127
|
-
};
|
|
3128
|
-
this.logger.debug(body, "generateTopology request body");
|
|
3129
|
-
const resp = await client.POST(
|
|
3130
|
-
"/v2/parties/external/generate-topology",
|
|
3131
|
-
{ body }
|
|
3132
|
-
);
|
|
3133
|
-
return this.valueOrError(resp);
|
|
3134
3340
|
}
|
|
3135
3341
|
async activeContracts(options) {
|
|
3136
|
-
const {
|
|
3342
|
+
const {
|
|
3343
|
+
offset,
|
|
3344
|
+
templateIds,
|
|
3345
|
+
parties,
|
|
3346
|
+
filterByParty,
|
|
3347
|
+
interfaceIds,
|
|
3348
|
+
limit
|
|
3349
|
+
} = options;
|
|
3137
3350
|
this.logger.debug(options, "options for active contracts");
|
|
3138
3351
|
if (templateIds?.length === 1 && parties?.length === 1) {
|
|
3139
3352
|
const party = parties[0];
|
|
@@ -3144,21 +3357,36 @@ var LedgerClient = class {
|
|
|
3144
3357
|
templateId
|
|
3145
3358
|
);
|
|
3146
3359
|
}
|
|
3147
|
-
if (
|
|
3360
|
+
if (interfaceIds?.length === 1 && parties?.length === 1) {
|
|
3361
|
+
const party = parties[0];
|
|
3362
|
+
const interfaceId = interfaceIds[0];
|
|
3363
|
+
return this.acsHelper.activeContractsForInterface(
|
|
3364
|
+
offset,
|
|
3365
|
+
party,
|
|
3366
|
+
interfaceId
|
|
3367
|
+
);
|
|
3368
|
+
}
|
|
3369
|
+
if (filterByParty && !templateIds?.length && !interfaceIds?.length && parties?.length === 1) {
|
|
3148
3370
|
const party = parties[0];
|
|
3149
3371
|
const r = this.acsHelper.activeContractsForInterface(
|
|
3150
3372
|
offset,
|
|
3151
3373
|
party,
|
|
3152
3374
|
""
|
|
3153
3375
|
);
|
|
3154
|
-
this.logger.info(r);
|
|
3155
3376
|
return r;
|
|
3156
3377
|
}
|
|
3157
|
-
const filter = this.
|
|
3378
|
+
const filter = this.buildActiveContractFilter(options);
|
|
3158
3379
|
this.logger.debug("falling back to post request");
|
|
3159
|
-
return await this.postWithRetry(
|
|
3380
|
+
return await this.postWithRetry(
|
|
3381
|
+
"/v2/state/active-contracts",
|
|
3382
|
+
filter,
|
|
3383
|
+
defaultRetryableOptions,
|
|
3384
|
+
{
|
|
3385
|
+
query: limit ? { limit: limit.toString() } : {}
|
|
3386
|
+
}
|
|
3387
|
+
);
|
|
3160
3388
|
}
|
|
3161
|
-
|
|
3389
|
+
buildActiveContractFilter(options) {
|
|
3162
3390
|
const filter = {
|
|
3163
3391
|
filter: {
|
|
3164
3392
|
filtersByParty: {}
|
|
@@ -3182,16 +3410,46 @@ var LedgerClient = class {
|
|
|
3182
3410
|
}
|
|
3183
3411
|
];
|
|
3184
3412
|
};
|
|
3413
|
+
const buildInterfaceFilter = (interfaceIds) => {
|
|
3414
|
+
if (!interfaceIds) return [];
|
|
3415
|
+
return [
|
|
3416
|
+
{
|
|
3417
|
+
identifierFilter: {
|
|
3418
|
+
InterfaceFilter: {
|
|
3419
|
+
value: {
|
|
3420
|
+
interfaceId: interfaceIds[0],
|
|
3421
|
+
includeCreatedEventBlob: true,
|
|
3422
|
+
//TODO: figure out if this should be configurable
|
|
3423
|
+
includeInterfaceView: true
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
];
|
|
3429
|
+
};
|
|
3430
|
+
this.logger.info(options, "active contract query options");
|
|
3185
3431
|
if (options?.filterByParty && options.parties && options.parties.length > 0) {
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3432
|
+
if (options?.templateIds && !options?.interfaceIds) {
|
|
3433
|
+
for (const party of options.parties) {
|
|
3434
|
+
filter.filter.filtersByParty[party] = {
|
|
3435
|
+
cumulative: options.templateIds ? buildTemplateFilter(options.templateIds) : []
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
} else if (options?.interfaceIds && !options?.templateIds) {
|
|
3439
|
+
for (const party of options.parties) {
|
|
3440
|
+
filter.filter.filtersByParty[party] = {
|
|
3441
|
+
cumulative: options.interfaceIds ? buildInterfaceFilter(options.interfaceIds) : []
|
|
3442
|
+
};
|
|
3443
|
+
}
|
|
3190
3444
|
}
|
|
3191
3445
|
} else if (options?.templateIds) {
|
|
3192
3446
|
filter.filter.filtersForAnyParty = {
|
|
3193
3447
|
cumulative: buildTemplateFilter(options.templateIds)
|
|
3194
3448
|
};
|
|
3449
|
+
} else if (options?.interfaceIds) {
|
|
3450
|
+
filter.filter.filtersForAnyParty = {
|
|
3451
|
+
cumulative: buildInterfaceFilter(options.templateIds)
|
|
3452
|
+
};
|
|
3195
3453
|
}
|
|
3196
3454
|
return filter;
|
|
3197
3455
|
}
|
|
@@ -3216,17 +3474,11 @@ var LedgerClient = class {
|
|
|
3216
3474
|
getCacheStats() {
|
|
3217
3475
|
return this.acsHelper.getCacheStats();
|
|
3218
3476
|
}
|
|
3219
|
-
/**
|
|
3220
|
-
* @deprecated use postWithRetry instead, should be made private
|
|
3221
|
-
*/
|
|
3222
3477
|
async post(path, body, params, additionalOptions) {
|
|
3223
3478
|
const options = { body, params, ...additionalOptions };
|
|
3224
3479
|
const resp = await this.currentClient.POST(path, options);
|
|
3225
3480
|
return this.valueOrError(resp);
|
|
3226
3481
|
}
|
|
3227
|
-
/**
|
|
3228
|
-
* @deprecated use getWithRetry instead, should be made private
|
|
3229
|
-
*/
|
|
3230
3482
|
async get(path, params) {
|
|
3231
3483
|
await this.init();
|
|
3232
3484
|
const options = { params };
|