@canton-network/core-ledger-client 0.19.0 → 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
@@ -1574,6 +1574,10 @@ var CoreService = class _CoreService {
1574
1574
  fetchedAtOffset: offset
1575
1575
  };
1576
1576
  }
1577
+ toQualifiedMemberId(memberId) {
1578
+ if (!memberId) throw new Error("memberId is required");
1579
+ return /^(PAR|MED)::/.test(memberId) ? memberId : `PAR::${memberId}`;
1580
+ }
1577
1581
  };
1578
1582
  var AllocationService = class {
1579
1583
  constructor(core, logger) {
@@ -2154,12 +2158,13 @@ var TransferService = class {
2154
2158
  }
2155
2159
  };
2156
2160
  var TokenStandardService = class {
2157
- constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser) {
2161
+ constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, scanClient) {
2158
2162
  this.ledgerClient = ledgerClient;
2159
2163
  this.scanProxyClient = scanProxyClient;
2160
2164
  this.logger = logger;
2161
2165
  this.accessTokenProvider = accessTokenProvider;
2162
2166
  this.isMasterUser = isMasterUser;
2167
+ this.scanClient = scanClient;
2163
2168
  __publicField(this, "core");
2164
2169
  __publicField(this, "allocation");
2165
2170
  __publicField(this, "transfer");
@@ -2168,7 +2173,9 @@ var TokenStandardService = class {
2168
2173
  scanProxyClient,
2169
2174
  logger,
2170
2175
  accessTokenProvider,
2171
- isMasterUser
2176
+ isMasterUser,
2177
+ void 0,
2178
+ void 0
2172
2179
  );
2173
2180
  this.allocation = new AllocationService(this.core, this.logger);
2174
2181
  this.transfer = new TransferService(this.core, this.logger);
@@ -2257,7 +2264,7 @@ var TokenStandardService = class {
2257
2264
  value: cid
2258
2265
  })),
2259
2266
  provider,
2260
- memberId,
2267
+ memberId: this.core.toQualifiedMemberId(memberId),
2261
2268
  synchronizerId,
2262
2269
  migrationId,
2263
2270
  trafficAmount,
@@ -2271,6 +2278,20 @@ var TokenStandardService = class {
2271
2278
  };
2272
2279
  return [exercise, disclosed];
2273
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
+ }
2274
2295
  async getInstrumentAdmin(registryUrl) {
2275
2296
  const client = this.core.getTokenStandardClient(registryUrl);
2276
2297
  const info = await client.get("/registry/metadata/v1/info");
@@ -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),