@canton-network/core-ledger-client 0.18.1 → 0.20.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/index.js CHANGED
@@ -1481,13 +1481,11 @@ var CoreService = class _CoreService {
1481
1481
  }
1482
1482
  return cIds;
1483
1483
  }
1484
- async listContractsByInterface(interfaceId, partyId, limit) {
1484
+ async listContractsByInterface(interfaceId, partyId, limit, offset) {
1485
1485
  try {
1486
- const ledgerEnd = await this.ledgerClient.getWithRetry(
1487
- "/v2/state/ledger-end"
1488
- );
1486
+ const ledgerEnd = offset ?? (await this.ledgerClient.getWithRetry("/v2/state/ledger-end")).offset;
1489
1487
  const options = {
1490
- offset: ledgerEnd.offset,
1488
+ offset: ledgerEnd,
1491
1489
  interfaceIds: [interfaceId],
1492
1490
  parties: [partyId],
1493
1491
  filterByParty: true,
@@ -1499,7 +1497,7 @@ var CoreService = class _CoreService {
1499
1497
  isActiveContractEntry
1500
1498
  );
1501
1499
  return activeContractEntries.map(
1502
- (response) => this.toPrettyContract(interfaceId, response)
1500
+ (response) => this.toPrettyContract(interfaceId, response, ledgerEnd)
1503
1501
  );
1504
1502
  } catch (err) {
1505
1503
  this.logger.error(
@@ -1563,7 +1561,7 @@ var CoreService = class _CoreService {
1563
1561
  }
1564
1562
  // returns object with JsActiveContract content
1565
1563
  // and contractId and interface view value extracted from it as separate fields for convenience
1566
- toPrettyContract(interfaceId, response) {
1564
+ toPrettyContract(interfaceId, response, offset) {
1567
1565
  const activeContract = response.contractEntry.JsActiveContract;
1568
1566
  const { createdEvent } = activeContract;
1569
1567
  return {
@@ -1572,9 +1570,14 @@ var CoreService = class _CoreService {
1572
1570
  interfaceViewValue: ensureInterfaceViewIsPresent(
1573
1571
  createdEvent,
1574
1572
  interfaceId
1575
- ).viewValue
1573
+ ).viewValue,
1574
+ fetchedAtOffset: offset
1576
1575
  };
1577
1576
  }
1577
+ toQualifiedMemberId(memberId) {
1578
+ if (!memberId) throw new Error("memberId is required");
1579
+ return /^(PAR|MED)::/.test(memberId) ? memberId : `PAR::${memberId}`;
1580
+ }
1578
1581
  };
1579
1582
  var AllocationService = class {
1580
1583
  constructor(core, logger) {
@@ -2155,12 +2158,13 @@ var TransferService = class {
2155
2158
  }
2156
2159
  };
2157
2160
  var TokenStandardService = class {
2158
- constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser) {
2161
+ constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, scanClient) {
2159
2162
  this.ledgerClient = ledgerClient;
2160
2163
  this.scanProxyClient = scanProxyClient;
2161
2164
  this.logger = logger;
2162
2165
  this.accessTokenProvider = accessTokenProvider;
2163
2166
  this.isMasterUser = isMasterUser;
2167
+ this.scanClient = scanClient;
2164
2168
  __publicField(this, "core");
2165
2169
  __publicField(this, "allocation");
2166
2170
  __publicField(this, "transfer");
@@ -2169,7 +2173,9 @@ var TokenStandardService = class {
2169
2173
  scanProxyClient,
2170
2174
  logger,
2171
2175
  accessTokenProvider,
2172
- isMasterUser
2176
+ isMasterUser,
2177
+ void 0,
2178
+ void 0
2173
2179
  );
2174
2180
  this.allocation = new AllocationService(this.core, this.logger);
2175
2181
  this.transfer = new TransferService(this.core, this.logger);
@@ -2258,7 +2264,7 @@ var TokenStandardService = class {
2258
2264
  value: cid
2259
2265
  })),
2260
2266
  provider,
2261
- memberId,
2267
+ memberId: this.core.toQualifiedMemberId(memberId),
2262
2268
  synchronizerId,
2263
2269
  migrationId,
2264
2270
  trafficAmount,
@@ -2272,6 +2278,20 @@ var TokenStandardService = class {
2272
2278
  };
2273
2279
  return [exercise, disclosed];
2274
2280
  }
2281
+ async getMemberTrafficStatus(domainId, memberId) {
2282
+ if (!this.scanClient) {
2283
+ throw new Error("Scan API URL was not provided");
2284
+ }
2285
+ return this.scanClient.get(
2286
+ "/v0/domains/{domain_id}/members/{member_id}/traffic-status",
2287
+ {
2288
+ path: {
2289
+ domain_id: domainId,
2290
+ member_id: this.core.toQualifiedMemberId(memberId)
2291
+ }
2292
+ }
2293
+ );
2294
+ }
2275
2295
  async getInstrumentAdmin(registryUrl) {
2276
2296
  const client = this.core.getTokenStandardClient(registryUrl);
2277
2297
  const info = await client.get("/registry/metadata/v1/info");
@@ -2288,11 +2308,12 @@ var TokenStandardService = class {
2288
2308
  }
2289
2309
  // <T> is shape of viewValue related to queried interface.
2290
2310
  // i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
2291
- async listContractsByInterface(interfaceId, partyId, limit) {
2311
+ async listContractsByInterface(interfaceId, partyId, limit, offset) {
2292
2312
  return this.core.listContractsByInterface(
2293
2313
  interfaceId,
2294
2314
  partyId,
2295
- limit
2315
+ limit,
2316
+ offset
2296
2317
  );
2297
2318
  }
2298
2319
  async listHoldingTransactions(partyId, afterOffset, beforeOffset) {
@@ -3015,6 +3036,7 @@ var LedgerClient = class {
3015
3036
  __publicField(this, "accessTokenProvider");
3016
3037
  __publicField(this, "acsHelper");
3017
3038
  __publicField(this, "logger");
3039
+ __publicField(this, "synchronizerId");
3018
3040
  __publicField(this, "baseUrl");
3019
3041
  this.logger = _logger.child({ component: "LedgerClient" });
3020
3042
  this.accessTokenProvider = accessTokenProvider;
@@ -3453,6 +3475,25 @@ var LedgerClient = class {
3453
3475
  }
3454
3476
  return filter;
3455
3477
  }
3478
+ // Retrieve an (arbitrary) synchronizer id from the validator.
3479
+ // This synchronizer id is cached for the remainder of this object's life.
3480
+ async getSynchronizerId() {
3481
+ if (this.synchronizerId) return this.synchronizerId;
3482
+ const response = await this.getWithRetry(
3483
+ "/v2/state/connected-synchronizers"
3484
+ );
3485
+ if (!response.connectedSynchronizers?.[0]) {
3486
+ throw new Error("No connected synchronizers found");
3487
+ }
3488
+ const synchronizerId = response.connectedSynchronizers[0].synchronizerId;
3489
+ if (response.connectedSynchronizers.length > 1) {
3490
+ this.logger.warn(
3491
+ `Found ${response.connectedSynchronizers.length} synchronizers, defaulting to ${synchronizerId}`
3492
+ );
3493
+ }
3494
+ this.synchronizerId = synchronizerId;
3495
+ return synchronizerId;
3496
+ }
3456
3497
  async postWithRetry(path, body, retryOptions = defaultRetryableOptions, params, additionalOptions) {
3457
3498
  return await retryable(
3458
3499
  () => this.post(path, body, params, additionalOptions),