@odatano/core 2.0.0-rc.36 → 2.0.0-rc.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "2.0.0-rc.36",
3
+ "version": "2.0.0-rc.39",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -26,7 +26,7 @@
26
26
  "@sap/cds": ">=10"
27
27
  },
28
28
  "dependencies": {
29
- "@blockfrost/blockfrost-js": "~6.0.0",
29
+ "@blockfrost/blockfrost-js": "~6.2.0",
30
30
  "@cap-js/hana": "^3",
31
31
  "@cardano-ogmios/client": "^7.0.0",
32
32
  "@harmoniclabs/buildooor": "0.2.9",
@@ -77,6 +77,18 @@
77
77
  "vitest": "^4.1.10"
78
78
  },
79
79
  "cds": {
80
+ "log": {
81
+ "mask_headers": [
82
+ "/authorization/i",
83
+ "/cookie/i",
84
+ "/cert/i",
85
+ "/ssl/i",
86
+ "/token/i",
87
+ "/key/i",
88
+ "/secret/i",
89
+ "/project_id/i"
90
+ ]
91
+ },
80
92
  "typer": {
81
93
  "ieee754compatible": true
82
94
  },
@@ -323,7 +323,8 @@ class BlockfrostBackend {
323
323
  }
324
324
  return {
325
325
  stakeaddress: accountData.stake_address,
326
- active: accountData.active,
326
+ // `active` is the delegation state; registration lives in `registered`
327
+ active: accountData.registered,
327
328
  activeEpoch: accountData.active_epoch ?? 0,
328
329
  controlledAmount: accountData.controlled_amount,
329
330
  rewardsSum: accountData.rewards_sum,
@@ -679,19 +679,22 @@ class OgmiosBackend {
679
679
  async getAccount(stakeAddress) {
680
680
  return (0, backend_request_handler_1.handleBackendRequest)(async () => {
681
681
  await this.ensureConnected();
682
- const rawResult = await this.stateQueryClient.rewardAccountSummaries({ keys: [stakeAddress] });
682
+ // Ogmios keeps key-hash and script-hash credentials in separate lists. A script stake address
683
+ // asked under `keys` is never found.
684
+ const rawResult = await this.stateQueryClient.rewardAccountSummaries((0, mappers_1.decodeShelleyAddress)(stakeAddress).isScript ? { scripts: [stakeAddress] } : { keys: [stakeAddress] });
683
685
  // Ogmios returns a record keyed by stake address; normalize to array
684
686
  const summaries = Array.isArray(rawResult)
685
687
  ? rawResult
686
688
  : Object.values(rawResult);
687
689
  const account = summaries && summaries.length > 0 ? summaries[0] : null;
690
+ // The summary lists only credentials delegated to a pool or a DRep. A registered credential without
691
+ // delegation is absent here, so "not found" does not mean "not registered".
688
692
  if (!account) {
689
693
  throw new errors_1.NotFoundError('Account', this.name);
690
694
  }
691
695
  return {
692
696
  stakeaddress: stakeAddress,
693
- // Ogmios only returns reward-account summaries for REGISTERED stake keys —
694
- // reaching this point (summary found) therefore implies the account is active.
697
+ // a summary exists only for a registered credential
695
698
  active: true,
696
699
  activeEpoch: 0,
697
700
  // reward-account summaries carry no controlled amount and no withdrawal totals
@@ -108,6 +108,18 @@ export declare class CardanoClient {
108
108
  getPool(poolId: string): Promise<PoolData>;
109
109
  getDrep(drepId: string): Promise<DrepData>;
110
110
  getAccount(stakeAddress: string): Promise<AccountData>;
111
+ /**
112
+ * Whether the reward account is registered in the ledger. Node first; the first backend that
113
+ * answers decides, its "not found" means not registered. Only a backend failure falls through.
114
+ */
115
+ /**
116
+ * Whether the stake credential is registered. The node's reward-account summary proves it, but
117
+ * the summary lists only credentials delegated to a pool or a DRep, so its absence proves nothing and the
118
+ * providers answer from the certificate history; one that knows the account decides, one that
119
+ * knows no such account means not registered. `null`: nobody could tell (no summary on the
120
+ * node, no provider configured or reachable).
121
+ */
122
+ isRewardAccountRegistered(stakeAddress: string): Promise<boolean | null>;
111
123
  /** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
112
124
  getAssetInfo(unit: string): Promise<AssetInfo>;
113
125
  /**
@@ -358,6 +358,32 @@ class CardanoClient {
358
358
  getAccount(stakeAddress) {
359
359
  return this.route('getAccount', b => b.getAccount(stakeAddress));
360
360
  }
361
+ /**
362
+ * Whether the reward account is registered in the ledger. Node first; the first backend that
363
+ * answers decides, its "not found" means not registered. Only a backend failure falls through.
364
+ */
365
+ /**
366
+ * Whether the stake credential is registered. The node's reward-account summary proves it, but
367
+ * the summary lists only credentials delegated to a pool or a DRep, so its absence proves nothing and the
368
+ * providers answer from the certificate history; one that knows the account decides, one that
369
+ * knows no such account means not registered. `null`: nobody could tell (no summary on the
370
+ * node, no provider configured or reachable).
371
+ */
372
+ async isRewardAccountRegistered(stakeAddress) {
373
+ try {
374
+ return await this.executeWithPriority(async (b) => (await b.getAccount(stakeAddress)).active, true, 'getAccount');
375
+ }
376
+ catch (err) {
377
+ if (err instanceof errors_1.AllBackendsFailedError) {
378
+ const providers = err.errors.filter(e => e.backendName !== this.liveBackend?.name);
379
+ if (providers.some(e => e.statusCode === 404))
380
+ return false;
381
+ if (err.errors.length > 0 && err.errors.every(e => e.statusCode === 404))
382
+ return null;
383
+ }
384
+ throw err;
385
+ }
386
+ }
361
387
  /** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
362
388
  getAssetInfo(unit) {
363
389
  return this.route('getAssetInfo', b => b.getAssetInfo(unit));
@@ -39,7 +39,8 @@ export declare class CardanoTransactionBuilder {
39
39
  buildPlutusTransaction(req: TxBuildPlutusRequest, protocolParameters: LedgerProtocolParameter): Promise<TxBuildResult>;
40
40
  /**
41
41
  * The ledger rejects a withdrawal from an unregistered reward account (also a zero one), so the
42
- * build fails here with the account named. A provider failure is passed on as it is.
42
+ * build fails here with the account named. A provider failure is passed on as it is. When no
43
+ * backend can tell, the build goes on and the node decides at submit.
43
44
  */
44
45
  private _assertRewardAccountsRegistered;
45
46
  /**
@@ -210,24 +210,20 @@ class CardanoTransactionBuilder {
210
210
  }
211
211
  /**
212
212
  * The ledger rejects a withdrawal from an unregistered reward account (also a zero one), so the
213
- * build fails here with the account named. A provider failure is passed on as it is.
213
+ * build fails here with the account named. A provider failure is passed on as it is. When no
214
+ * backend can tell, the build goes on and the node decides at submit.
214
215
  */
215
216
  async _assertRewardAccountsRegistered(withdrawals, registeredHere = new Set()) {
216
217
  for (const [i, w] of withdrawals.entries()) {
217
218
  if (registeredHere.has(w.rewardAddress.toLowerCase()))
218
219
  continue;
219
- let active;
220
- try {
221
- active = (await this.client.getAccount(w.rewardAddress)).active;
222
- }
223
- catch (err) {
224
- if (!(err instanceof errors_1.NotFoundError))
225
- throw err;
226
- active = false;
227
- }
228
- if (!active) {
220
+ const registered = await this.client.isRewardAccountRegistered(w.rewardAddress);
221
+ if (registered === false) {
229
222
  throw new errors_1.TransactionValidationError(`withdrawals[${i}] reward account ${w.rewardAddress} is not registered on chain; register the stake credential first`);
230
223
  }
224
+ if (registered === null) {
225
+ logger.warn(`withdrawals[${i}] reward account ${w.rewardAddress}: registration not verifiable (the node lists delegated accounts only, no provider answered); the node checks it at submit`);
226
+ }
231
227
  }
232
228
  }
233
229
  /**