@canton-network/core-ledger-client 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acs/acs-container.d.ts +10 -7
- package/dist/acs/acs-container.d.ts.map +1 -1
- package/dist/acs/acs-helper.d.ts +5 -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 +415 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +415 -168
- package/dist/index.js.map +1 -1
- package/dist/ledger-client.d.ts +10 -7
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts +11 -6
- 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
|
|
@@ -1485,22 +1575,6 @@ var CoreService = class {
|
|
|
1485
1575
|
).viewValue
|
|
1486
1576
|
};
|
|
1487
1577
|
}
|
|
1488
|
-
async getActiveOpenMiningRound() {
|
|
1489
|
-
const openMiningRounds = await this.scanProxyClient.getOpenMiningRounds();
|
|
1490
|
-
if (!(Array.isArray(openMiningRounds) && openMiningRounds.length)) {
|
|
1491
|
-
throw new Error("OpenMiningRound contract not found");
|
|
1492
|
-
}
|
|
1493
|
-
const nowForOpenMiningRounds = Date.now();
|
|
1494
|
-
const latestOpenMiningRound = openMiningRounds.findLast(
|
|
1495
|
-
(openMiningRound) => {
|
|
1496
|
-
const { opensAt, targetClosesAt } = openMiningRound.payload;
|
|
1497
|
-
const opensAtMs = Number(new Date(opensAt));
|
|
1498
|
-
const targetClosesAtMs = Number(new Date(targetClosesAt));
|
|
1499
|
-
return opensAtMs <= nowForOpenMiningRounds && targetClosesAtMs > nowForOpenMiningRounds;
|
|
1500
|
-
}
|
|
1501
|
-
);
|
|
1502
|
-
return latestOpenMiningRound ?? null;
|
|
1503
|
-
}
|
|
1504
1578
|
};
|
|
1505
1579
|
var AllocationService = class {
|
|
1506
1580
|
constructor(core, logger) {
|
|
@@ -1756,7 +1830,8 @@ var TransferService = class {
|
|
|
1756
1830
|
async buildTransferChoiceArgs(sender, receiver, amount, instrumentAdmin, instrumentId, inputUtxos, memo, expiryDate, meta) {
|
|
1757
1831
|
const inputHoldingCids = await this.core.getInputHoldingsCids(
|
|
1758
1832
|
sender,
|
|
1759
|
-
inputUtxos
|
|
1833
|
+
inputUtxos,
|
|
1834
|
+
parseFloat(amount)
|
|
1760
1835
|
);
|
|
1761
1836
|
return {
|
|
1762
1837
|
expectedAdmin: instrumentAdmin,
|
|
@@ -2140,11 +2215,77 @@ var TokenStandardService = class {
|
|
|
2140
2215
|
);
|
|
2141
2216
|
}
|
|
2142
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
|
+
}
|
|
2143
2275
|
async getInstrumentAdmin(registryUrl) {
|
|
2144
2276
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
2145
2277
|
const info = await client.get("/registry/metadata/v1/info");
|
|
2146
2278
|
return info.adminId;
|
|
2147
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
|
+
}
|
|
2148
2289
|
// <T> is shape of viewValue related to queried interface.
|
|
2149
2290
|
// i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
|
|
2150
2291
|
async listContractsByInterface(interfaceId, partyId, limit) {
|
|
@@ -2287,7 +2428,7 @@ var TokenStandardService = class {
|
|
|
2287
2428
|
if (!amuletRules) {
|
|
2288
2429
|
throw new Error("AmuletRules contract not found");
|
|
2289
2430
|
}
|
|
2290
|
-
const latestOpenMiningRound = await this.
|
|
2431
|
+
const latestOpenMiningRound = await this.scanProxyClient.getActiveOpenMiningRound();
|
|
2291
2432
|
if (!latestOpenMiningRound) {
|
|
2292
2433
|
throw new Error(
|
|
2293
2434
|
"OpenMiningRound active at current moment not found"
|
|
@@ -2338,7 +2479,7 @@ var TokenStandardService = class {
|
|
|
2338
2479
|
}
|
|
2339
2480
|
async renewTransferPreapproval(contractId, templateId, provider, synchronizerId, newExpiresAt, inputUtxos) {
|
|
2340
2481
|
const amuletRules = await this.scanProxyClient.getAmuletRules();
|
|
2341
|
-
const activeRound = await this.
|
|
2482
|
+
const activeRound = await this.scanProxyClient.getActiveOpenMiningRound();
|
|
2342
2483
|
if (!amuletRules) {
|
|
2343
2484
|
throw new Error("AmuletRules contract not found");
|
|
2344
2485
|
}
|
|
@@ -2436,13 +2577,15 @@ if (typeof window !== "undefined") {
|
|
|
2436
2577
|
window["ACS_UPDATE_CONFIG"] = ACS_UPDATE_CONFIG;
|
|
2437
2578
|
}
|
|
2438
2579
|
var ACSContainer = class _ACSContainer {
|
|
2439
|
-
constructor(orginalContainer = null) {
|
|
2580
|
+
constructor(orginalContainer = null, settings = { includeCreatedEventBlob: true }) {
|
|
2440
2581
|
__publicField(this, "acsSet", null);
|
|
2582
|
+
__publicField(this, "settings");
|
|
2441
2583
|
this.acsSet = orginalContainer ? orginalContainer.acsSet : null;
|
|
2584
|
+
this.settings = settings;
|
|
2442
2585
|
}
|
|
2443
2586
|
async update(offset, key, api, wsSupport) {
|
|
2444
2587
|
if (this.acsSet === null) {
|
|
2445
|
-
const acs = await
|
|
2588
|
+
const acs = await this.readACS(offset, key, api, wsSupport);
|
|
2446
2589
|
this.acsSet = acs;
|
|
2447
2590
|
return _ACSContainer.calculateAt(acs, offset);
|
|
2448
2591
|
}
|
|
@@ -2456,7 +2599,7 @@ var ACSContainer = class _ACSContainer {
|
|
|
2456
2599
|
const updates = await _ACSContainer.updateContracts(
|
|
2457
2600
|
this.acsSet.lastUpdateOffset,
|
|
2458
2601
|
offset,
|
|
2459
|
-
|
|
2602
|
+
this.createEventFormat(key),
|
|
2460
2603
|
api
|
|
2461
2604
|
);
|
|
2462
2605
|
const [newEvents, newOffset] = _ACSContainer.extractEvents(
|
|
@@ -2607,19 +2750,17 @@ var ACSContainer = class _ACSContainer {
|
|
|
2607
2750
|
}
|
|
2608
2751
|
return acs;
|
|
2609
2752
|
}
|
|
2610
|
-
|
|
2753
|
+
async readACS(offset, key, api, wsSupport) {
|
|
2611
2754
|
if (wsSupport && wsSupport.enabled()) {
|
|
2612
|
-
return
|
|
2613
|
-
(
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
}
|
|
2617
|
-
);
|
|
2755
|
+
return this.readACSUsingWs(offset, key, wsSupport).catch(() => {
|
|
2756
|
+
console.log("Falling back to HTTP for ACS read");
|
|
2757
|
+
return this.readHttpACS(offset, key, api);
|
|
2758
|
+
});
|
|
2618
2759
|
}
|
|
2619
|
-
return
|
|
2760
|
+
return this.readHttpACS(offset, key, api);
|
|
2620
2761
|
}
|
|
2621
|
-
|
|
2622
|
-
const format =
|
|
2762
|
+
async readHttpACS(offset, key, api) {
|
|
2763
|
+
const format = this.createEventFormat(key);
|
|
2623
2764
|
const acs = await api.postWithRetry("/v2/state/active-contracts", {
|
|
2624
2765
|
activeAtOffset: offset,
|
|
2625
2766
|
verbose: false,
|
|
@@ -2632,9 +2773,9 @@ var ACSContainer = class _ACSContainer {
|
|
|
2632
2773
|
updates: []
|
|
2633
2774
|
};
|
|
2634
2775
|
}
|
|
2635
|
-
|
|
2776
|
+
readACSUsingWs(offset, key, wsSupport) {
|
|
2636
2777
|
const wsACSURL = `${wsSupport.baseUrl}/v2/state/active-contracts`;
|
|
2637
|
-
const format =
|
|
2778
|
+
const format = this.createEventFormat(key);
|
|
2638
2779
|
const request = {
|
|
2639
2780
|
activeAtOffset: offset,
|
|
2640
2781
|
verbose: false,
|
|
@@ -2687,7 +2828,7 @@ var ACSContainer = class _ACSContainer {
|
|
|
2687
2828
|
};
|
|
2688
2829
|
});
|
|
2689
2830
|
}
|
|
2690
|
-
|
|
2831
|
+
createInterfaceFilter(interfaceId) {
|
|
2691
2832
|
return {
|
|
2692
2833
|
cumulative: [
|
|
2693
2834
|
{
|
|
@@ -2696,7 +2837,7 @@ var ACSContainer = class _ACSContainer {
|
|
|
2696
2837
|
value: {
|
|
2697
2838
|
interfaceId,
|
|
2698
2839
|
includeInterfaceView: true,
|
|
2699
|
-
includeCreatedEventBlob:
|
|
2840
|
+
includeCreatedEventBlob: this.settings.includeCreatedEventBlob
|
|
2700
2841
|
}
|
|
2701
2842
|
}
|
|
2702
2843
|
}
|
|
@@ -2704,7 +2845,7 @@ var ACSContainer = class _ACSContainer {
|
|
|
2704
2845
|
]
|
|
2705
2846
|
};
|
|
2706
2847
|
}
|
|
2707
|
-
|
|
2848
|
+
createTemplateFilter(templateId) {
|
|
2708
2849
|
return {
|
|
2709
2850
|
cumulative: [
|
|
2710
2851
|
{
|
|
@@ -2712,7 +2853,7 @@ var ACSContainer = class _ACSContainer {
|
|
|
2712
2853
|
TemplateFilter: {
|
|
2713
2854
|
value: {
|
|
2714
2855
|
templateId,
|
|
2715
|
-
includeCreatedEventBlob:
|
|
2856
|
+
includeCreatedEventBlob: this.settings.includeCreatedEventBlob
|
|
2716
2857
|
}
|
|
2717
2858
|
}
|
|
2718
2859
|
}
|
|
@@ -2720,8 +2861,8 @@ var ACSContainer = class _ACSContainer {
|
|
|
2720
2861
|
]
|
|
2721
2862
|
};
|
|
2722
2863
|
}
|
|
2723
|
-
|
|
2724
|
-
const cumulativeFilter = key.templateId ?
|
|
2864
|
+
createEventFormat(key) {
|
|
2865
|
+
const cumulativeFilter = key.templateId ? this.createTemplateFilter(key.templateId) : this.createInterfaceFilter(key.interfaceId ?? "");
|
|
2725
2866
|
const baseFormat = {
|
|
2726
2867
|
filtersByParty: {},
|
|
2727
2868
|
verbose: false
|
|
@@ -2740,22 +2881,34 @@ var ACSContainer = class _ACSContainer {
|
|
|
2740
2881
|
};
|
|
2741
2882
|
}
|
|
2742
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
|
+
};
|
|
2743
2901
|
|
|
2744
2902
|
// src/acs/acs-helper.ts
|
|
2745
|
-
var DEFAULT_MAX_CACHE_SIZE = 50;
|
|
2746
|
-
var DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1e3;
|
|
2747
2903
|
var ACSHelper = class _ACSHelper {
|
|
2748
|
-
constructor(apiInstance, _logger, options) {
|
|
2904
|
+
constructor(apiInstance, _logger, options, sharedCache) {
|
|
2749
2905
|
__publicField(this, "contractsSet");
|
|
2750
2906
|
__publicField(this, "apiInstance");
|
|
2751
2907
|
__publicField(this, "wsSupport");
|
|
2752
2908
|
__publicField(this, "logger");
|
|
2753
|
-
__publicField(this, "
|
|
2754
|
-
__publicField(this, "misses", 0);
|
|
2755
|
-
__publicField(this, "evictions", 0);
|
|
2756
|
-
__publicField(this, "totalLookuptime", 0);
|
|
2909
|
+
__publicField(this, "includeCreatedEventBlob");
|
|
2757
2910
|
__publicField(this, "totalCacheServeTime", 0);
|
|
2758
|
-
this.contractsSet = new LRUCache({
|
|
2911
|
+
this.contractsSet = sharedCache ?? new LRUCache({
|
|
2759
2912
|
maxSize: options?.maxCacheSize ?? DEFAULT_MAX_CACHE_SIZE,
|
|
2760
2913
|
entryExpirationTimeInMS: options?.entryExpirationTime ?? DEFAULT_ENTRY_EXPIRATION_TIME,
|
|
2761
2914
|
// 10 minutes
|
|
@@ -2763,22 +2916,23 @@ var ACSHelper = class _ACSHelper {
|
|
|
2763
2916
|
this.logger.debug(
|
|
2764
2917
|
`entry ${entry.key} isExpired = ${entry.isExpired}. evicting entry.`
|
|
2765
2918
|
);
|
|
2766
|
-
|
|
2919
|
+
SharedACSCacheStats.evictions++;
|
|
2767
2920
|
}
|
|
2768
2921
|
});
|
|
2769
2922
|
this.apiInstance = apiInstance;
|
|
2770
2923
|
this.wsSupport = options?.wsSupport;
|
|
2771
2924
|
this.logger = _logger.child({ component: "ACSHelper" });
|
|
2925
|
+
this.includeCreatedEventBlob = options?.includeCreatedEventBlob ?? true;
|
|
2772
2926
|
}
|
|
2773
2927
|
getCacheStats() {
|
|
2774
|
-
const totalCalls =
|
|
2775
|
-
const hitRate = totalCalls ?
|
|
2776
|
-
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;
|
|
2777
2931
|
return {
|
|
2778
2932
|
totalCalls,
|
|
2779
|
-
hits:
|
|
2780
|
-
misses:
|
|
2781
|
-
evictions:
|
|
2933
|
+
hits: SharedACSCacheStats.hits,
|
|
2934
|
+
misses: SharedACSCacheStats.misses,
|
|
2935
|
+
evictions: SharedACSCacheStats.evictions,
|
|
2782
2936
|
cacheSize: this.contractsSet.size,
|
|
2783
2937
|
hitRate: hitRate.toFixed(2) + "%",
|
|
2784
2938
|
averageLookupTime: avgLookupTime.toFixed(3) + " ms",
|
|
@@ -2788,23 +2942,25 @@ var ACSHelper = class _ACSHelper {
|
|
|
2788
2942
|
static createKey(party, templateId, interfaceId) {
|
|
2789
2943
|
return { party, templateId, interfaceId };
|
|
2790
2944
|
}
|
|
2791
|
-
static keyToString(key) {
|
|
2792
|
-
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 ?? "()"}`;
|
|
2793
2947
|
}
|
|
2794
2948
|
findACSContainer(key) {
|
|
2795
|
-
const keyStr = _ACSHelper.keyToString(key);
|
|
2949
|
+
const keyStr = _ACSHelper.keyToString(key, this.apiInstance.baseUrl.href);
|
|
2796
2950
|
const start = performance.now();
|
|
2797
2951
|
const existing = this.contractsSet.get(keyStr);
|
|
2798
2952
|
const end = performance.now();
|
|
2799
|
-
|
|
2953
|
+
SharedACSCacheStats.totalLookupTime += end - start;
|
|
2800
2954
|
if (existing) {
|
|
2801
|
-
|
|
2955
|
+
SharedACSCacheStats.hits++;
|
|
2802
2956
|
this.logger.debug("cache hit");
|
|
2803
2957
|
return existing;
|
|
2804
2958
|
}
|
|
2805
2959
|
this.logger.debug("cache miss");
|
|
2806
|
-
|
|
2807
|
-
const newContainer = new ACSContainer(
|
|
2960
|
+
SharedACSCacheStats.misses++;
|
|
2961
|
+
const newContainer = new ACSContainer(void 0, {
|
|
2962
|
+
includeCreatedEventBlob: this.includeCreatedEventBlob
|
|
2963
|
+
});
|
|
2808
2964
|
this.contractsSet.set(keyStr, newContainer);
|
|
2809
2965
|
return newContainer;
|
|
2810
2966
|
}
|
|
@@ -2819,8 +2975,10 @@ var ACSHelper = class _ACSHelper {
|
|
|
2819
2975
|
this.wsSupport
|
|
2820
2976
|
);
|
|
2821
2977
|
const end = performance.now();
|
|
2822
|
-
if (this.contractsSet.has(
|
|
2823
|
-
this.
|
|
2978
|
+
if (this.contractsSet.has(
|
|
2979
|
+
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
2980
|
+
)) {
|
|
2981
|
+
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2824
2982
|
}
|
|
2825
2983
|
return result;
|
|
2826
2984
|
}
|
|
@@ -2835,8 +2993,10 @@ var ACSHelper = class _ACSHelper {
|
|
|
2835
2993
|
this.wsSupport
|
|
2836
2994
|
);
|
|
2837
2995
|
const end = performance.now();
|
|
2838
|
-
if (this.contractsSet.has(
|
|
2839
|
-
this.
|
|
2996
|
+
if (this.contractsSet.has(
|
|
2997
|
+
_ACSHelper.keyToString(key, this.apiInstance.baseUrl.href)
|
|
2998
|
+
)) {
|
|
2999
|
+
SharedACSCacheStats.totalCacheServeTime += end - start;
|
|
2840
3000
|
}
|
|
2841
3001
|
return result;
|
|
2842
3002
|
}
|
|
@@ -2848,13 +3008,14 @@ var LedgerClient = class {
|
|
|
2848
3008
|
constructor(baseUrl, _logger, isAdmin = false, accessToken, accessTokenProvider, version, acsHelperOptions) {
|
|
2849
3009
|
// privately manage the active connected version and associated client codegen
|
|
2850
3010
|
__publicField(this, "clients");
|
|
2851
|
-
__publicField(this, "clientVersion", "3.
|
|
2852
|
-
// default to 3.
|
|
3011
|
+
__publicField(this, "clientVersion", "3.4");
|
|
3012
|
+
// default to 3.4 if not provided
|
|
2853
3013
|
__publicField(this, "currentClient");
|
|
2854
3014
|
__publicField(this, "initialized", false);
|
|
2855
3015
|
__publicField(this, "accessTokenProvider");
|
|
2856
3016
|
__publicField(this, "acsHelper");
|
|
2857
3017
|
__publicField(this, "logger");
|
|
3018
|
+
__publicField(this, "baseUrl");
|
|
2858
3019
|
this.logger = _logger.child({ component: "LedgerClient" });
|
|
2859
3020
|
this.accessTokenProvider = accessTokenProvider;
|
|
2860
3021
|
this.clients = {
|
|
@@ -2891,7 +3052,13 @@ var LedgerClient = class {
|
|
|
2891
3052
|
};
|
|
2892
3053
|
this.clientVersion = version ?? this.clientVersion;
|
|
2893
3054
|
this.currentClient = this.clients[this.clientVersion];
|
|
2894
|
-
this.
|
|
3055
|
+
this.baseUrl = baseUrl;
|
|
3056
|
+
this.acsHelper = new ACSHelper(
|
|
3057
|
+
this,
|
|
3058
|
+
_logger,
|
|
3059
|
+
acsHelperOptions,
|
|
3060
|
+
SharedACSCache
|
|
3061
|
+
);
|
|
2895
3062
|
}
|
|
2896
3063
|
async init() {
|
|
2897
3064
|
if (!this.initialized) {
|
|
@@ -2899,6 +3066,7 @@ var LedgerClient = class {
|
|
|
2899
3066
|
this.clientVersion = this.parseSupportedVersions(
|
|
2900
3067
|
versionFromClient.data?.version
|
|
2901
3068
|
);
|
|
3069
|
+
this.currentClient = this.clients[this.clientVersion];
|
|
2902
3070
|
this.initialized = true;
|
|
2903
3071
|
}
|
|
2904
3072
|
}
|
|
@@ -3099,52 +3267,86 @@ var LedgerClient = class {
|
|
|
3099
3267
|
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
3100
3268
|
async allocateExternalParty(synchronizerId, onboardingTransactions, multiHashSignatures) {
|
|
3101
3269
|
await this.init();
|
|
3102
|
-
if (this.clientVersion
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
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);
|
|
3106
3292
|
}
|
|
3107
|
-
const client = this.clients["3.3"];
|
|
3108
|
-
const resp = await client.POST("/v2/parties/external/allocate", {
|
|
3109
|
-
body: {
|
|
3110
|
-
synchronizer: synchronizerId,
|
|
3111
|
-
identityProviderId: "",
|
|
3112
|
-
onboardingTransactions,
|
|
3113
|
-
multiHashSignatures
|
|
3114
|
-
}
|
|
3115
|
-
});
|
|
3116
|
-
return this.valueOrError(resp);
|
|
3117
3293
|
}
|
|
3118
3294
|
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
3119
|
-
async generateTopology(synchronizerId, publicKey, partyHint, localParticipantObservationOnly = false, confirmationThreshold = 1, otherConfirmingParticipantUids = []) {
|
|
3295
|
+
async generateTopology(synchronizerId, publicKey, partyHint, localParticipantObservationOnly = false, confirmationThreshold = 1, otherConfirmingParticipantUids = [], observingParticipantUids = []) {
|
|
3120
3296
|
await this.init();
|
|
3121
|
-
if (this.clientVersion
|
|
3122
|
-
|
|
3123
|
-
|
|
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 }
|
|
3124
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);
|
|
3125
3339
|
}
|
|
3126
|
-
const client = this.clients["3.3"];
|
|
3127
|
-
const body = {
|
|
3128
|
-
synchronizer: synchronizerId,
|
|
3129
|
-
partyHint,
|
|
3130
|
-
publicKey: {
|
|
3131
|
-
format: "CRYPTO_KEY_FORMAT_RAW",
|
|
3132
|
-
keyData: publicKey,
|
|
3133
|
-
keySpec: "SIGNING_KEY_SPEC_EC_CURVE25519"
|
|
3134
|
-
},
|
|
3135
|
-
localParticipantObservationOnly,
|
|
3136
|
-
confirmationThreshold,
|
|
3137
|
-
otherConfirmingParticipantUids
|
|
3138
|
-
};
|
|
3139
|
-
this.logger.debug(body, "generateTopology request body");
|
|
3140
|
-
const resp = await client.POST(
|
|
3141
|
-
"/v2/parties/external/generate-topology",
|
|
3142
|
-
{ body }
|
|
3143
|
-
);
|
|
3144
|
-
return this.valueOrError(resp);
|
|
3145
3340
|
}
|
|
3146
3341
|
async activeContracts(options) {
|
|
3147
|
-
const {
|
|
3342
|
+
const {
|
|
3343
|
+
offset,
|
|
3344
|
+
templateIds,
|
|
3345
|
+
parties,
|
|
3346
|
+
filterByParty,
|
|
3347
|
+
interfaceIds,
|
|
3348
|
+
limit
|
|
3349
|
+
} = options;
|
|
3148
3350
|
this.logger.debug(options, "options for active contracts");
|
|
3149
3351
|
if (templateIds?.length === 1 && parties?.length === 1) {
|
|
3150
3352
|
const party = parties[0];
|
|
@@ -3155,21 +3357,36 @@ var LedgerClient = class {
|
|
|
3155
3357
|
templateId
|
|
3156
3358
|
);
|
|
3157
3359
|
}
|
|
3158
|
-
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) {
|
|
3159
3370
|
const party = parties[0];
|
|
3160
3371
|
const r = this.acsHelper.activeContractsForInterface(
|
|
3161
3372
|
offset,
|
|
3162
3373
|
party,
|
|
3163
3374
|
""
|
|
3164
3375
|
);
|
|
3165
|
-
this.logger.info(r);
|
|
3166
3376
|
return r;
|
|
3167
3377
|
}
|
|
3168
|
-
const filter = this.
|
|
3378
|
+
const filter = this.buildActiveContractFilter(options);
|
|
3169
3379
|
this.logger.debug("falling back to post request");
|
|
3170
|
-
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
|
+
);
|
|
3171
3388
|
}
|
|
3172
|
-
|
|
3389
|
+
buildActiveContractFilter(options) {
|
|
3173
3390
|
const filter = {
|
|
3174
3391
|
filter: {
|
|
3175
3392
|
filtersByParty: {}
|
|
@@ -3193,16 +3410,46 @@ var LedgerClient = class {
|
|
|
3193
3410
|
}
|
|
3194
3411
|
];
|
|
3195
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");
|
|
3196
3431
|
if (options?.filterByParty && options.parties && options.parties.length > 0) {
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
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
|
+
}
|
|
3201
3444
|
}
|
|
3202
3445
|
} else if (options?.templateIds) {
|
|
3203
3446
|
filter.filter.filtersForAnyParty = {
|
|
3204
3447
|
cumulative: buildTemplateFilter(options.templateIds)
|
|
3205
3448
|
};
|
|
3449
|
+
} else if (options?.interfaceIds) {
|
|
3450
|
+
filter.filter.filtersForAnyParty = {
|
|
3451
|
+
cumulative: buildInterfaceFilter(options.templateIds)
|
|
3452
|
+
};
|
|
3206
3453
|
}
|
|
3207
3454
|
return filter;
|
|
3208
3455
|
}
|