@odatano/core 2.0.0-rc.31 → 2.0.0-rc.33

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.
Files changed (36) hide show
  1. package/@cds-models/CardanoODataService/index.d.ts +11 -0
  2. package/@cds-models/CardanoODataService/index.js +1 -0
  3. package/@cds-models/index.d.ts +53 -0
  4. package/@cds-models/index.js +9 -0
  5. package/db/schema.cds +1 -1
  6. package/db/types.cds +83 -0
  7. package/package.json +1 -1
  8. package/src/index.d.ts +7 -1
  9. package/src/index.js +17 -1
  10. package/srv/blockchain/backends/blockfrost-backend.js +2 -1
  11. package/srv/blockchain/backends/koios-backend.js +22 -20
  12. package/srv/blockchain/backends/ogmios-backend.js +2 -1
  13. package/srv/blockchain/cardano-indexer.d.ts +10 -1
  14. package/srv/blockchain/cardano-indexer.js +47 -2
  15. package/srv/blockchain/signing/signature-verifier.d.ts +6 -1
  16. package/srv/blockchain/signing/signature-verifier.js +62 -24
  17. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +2 -0
  18. package/srv/blockchain/transaction-building/buildooor-tx.js +57 -23
  19. package/srv/cardano-service.cds +8 -1
  20. package/srv/cardano-service.js +8 -0
  21. package/srv/cardano-sign-service.js +2 -11
  22. package/srv/cardano-tx-service.cds +3 -3
  23. package/srv/cardano-tx-service.js +5 -2
  24. package/srv/cbor/index.d.ts +1 -1
  25. package/srv/cbor/parse.d.ts +25 -0
  26. package/srv/cbor/parse.js +49 -1
  27. package/srv/utils/epoch-slots.d.ts +8 -1
  28. package/srv/utils/epoch-slots.js +20 -2
  29. package/srv/utils/mappers.js +1 -1
  30. package/srv/utils/signing-helper.d.ts +6 -1
  31. package/srv/utils/signing-helper.js +33 -35
  32. package/srv/utils/tx-build-helper.d.ts +2 -1
  33. package/srv/utils/tx-build-helper.js +7 -1
  34. package/srv/utils/tx-request-parsers.d.ts +1 -1
  35. package/srv/utils/tx-request-parsers.js +4 -4
  36. package/srv/utils/types.d.ts +20 -1
@@ -41,6 +41,7 @@ export default class {
41
41
  static readonly GetAssetHistory: typeof GetAssetHistory;
42
42
  static readonly GetAccountByStakeAddress: typeof GetAccountByStakeAddress;
43
43
  static readonly GetTransactionByHash: typeof GetTransactionByHash;
44
+ static readonly GetTransactionConfirmations: typeof GetTransactionConfirmations;
44
45
  static readonly GetMetadataByTxHash: typeof GetMetadataByTxHash;
45
46
  static readonly GetAddressByBech32: typeof GetAddressByBech32;
46
47
  static readonly GetUTxOsByAddress: typeof GetUTxOsByAddress;
@@ -983,6 +984,16 @@ export declare const GetTransactionByHash: {
983
984
  kind: 'action'
984
985
  }
985
986
 
987
+ export declare const GetTransactionConfirmations: {
988
+ // positional
989
+ (txHash: _.Blake2b256 | null): globalThis.Promise<_.TransactionConfirmations | null> | _.TransactionConfirmations | null
990
+ // named
991
+ ({txHash}: {txHash?: _.Blake2b256 | null}): globalThis.Promise<_.TransactionConfirmations | null> | _.TransactionConfirmations | null
992
+ // metadata (do not use)
993
+ __parameters: {txHash?: _.Blake2b256 | null}, __returns: globalThis.Promise<_.TransactionConfirmations | null> | _.TransactionConfirmations | null, __self: never
994
+ kind: 'action'
995
+ }
996
+
986
997
  export declare const GetMetadataByTxHash: {
987
998
  // positional
988
999
  (txHash: _.Blake2b256 | null): globalThis.Promise<Array<TransactionMetadata>> | Array<TransactionMetadata>
@@ -108,6 +108,7 @@ module.exports.GetAssetInfo = 'GetAssetInfo'
108
108
  module.exports.GetAssetHistory = 'GetAssetHistory'
109
109
  module.exports.GetAccountByStakeAddress = 'GetAccountByStakeAddress'
110
110
  module.exports.GetTransactionByHash = 'GetTransactionByHash'
111
+ module.exports.GetTransactionConfirmations = 'GetTransactionConfirmations'
111
112
  module.exports.GetMetadataByTxHash = 'GetMetadataByTxHash'
112
113
  module.exports.GetAddressByBech32 = 'GetAddressByBech32'
113
114
  module.exports.GetUTxOsByAddress = 'GetUTxOsByAddress'
@@ -228,6 +228,22 @@ export declare function _UTxODataSliceAspect<TBase extends new (...args: any[])
228
228
  export class UTxODataSlice extends _UTxODataSliceAspect(__.Entity) {
229
229
  }
230
230
 
231
+ // entity 'TransactionConfirmations'
232
+ export declare function _TransactionConfirmationsAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
233
+ new (...args: any[]): {
234
+ txHash?: Blake2b256 | null
235
+ blockHeight?: number | null
236
+ tipHeight?: number | null
237
+ confirmations?: number | null
238
+ } & InstanceType<TBase>
239
+ readonly kind: 'type';
240
+ readonly keys: __.KeysOf<TransactionConfirmations>;
241
+ readonly elements: __.ElementsOf<TransactionConfirmations>;
242
+ readonly actions: globalThis.Record<never, never>;
243
+ };
244
+ export class TransactionConfirmations extends _TransactionConfirmationsAspect(__.Entity) {
245
+ }
246
+
231
247
  // entity 'ParsedInput'
232
248
  export declare function _ParsedInputAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
233
249
  new (...args: any[]): {
@@ -265,6 +281,7 @@ export declare function _ParsedOutputAspect<TBase extends new (...args: any[]) =
265
281
  datumHash?: Blake2b256 | null
266
282
  inlineDatumHex?: string | null
267
283
  referenceScriptHex?: string | null
284
+ cborSize?: number | null
268
285
  } & InstanceType<TBase>
269
286
  readonly kind: 'type';
270
287
  readonly keys: __.KeysOf<ParsedOutput>;
@@ -274,6 +291,34 @@ export declare function _ParsedOutputAspect<TBase extends new (...args: any[]) =
274
291
  export class ParsedOutput extends _ParsedOutputAspect(__.Entity) {
275
292
  }
276
293
 
294
+ // entity 'ParsedWithdrawal'
295
+ export declare function _ParsedWithdrawalAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
296
+ new (...args: any[]): {
297
+ rewardAddress?: Bech32 | null
298
+ lovelace?: Lovelace | null
299
+ } & InstanceType<TBase>
300
+ readonly kind: 'type';
301
+ readonly keys: __.KeysOf<ParsedWithdrawal>;
302
+ readonly elements: __.ElementsOf<ParsedWithdrawal>;
303
+ readonly actions: globalThis.Record<never, never>;
304
+ };
305
+ export class ParsedWithdrawal extends _ParsedWithdrawalAspect(__.Entity) {
306
+ }
307
+
308
+ // entity 'ParsedCertificate'
309
+ export declare function _ParsedCertificateAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
310
+ new (...args: any[]): {
311
+ index?: number | null
312
+ type?: string | null
313
+ } & InstanceType<TBase>
314
+ readonly kind: 'type';
315
+ readonly keys: __.KeysOf<ParsedCertificate>;
316
+ readonly elements: __.ElementsOf<ParsedCertificate>;
317
+ readonly actions: globalThis.Record<never, never>;
318
+ };
319
+ export class ParsedCertificate extends _ParsedCertificateAspect(__.Entity) {
320
+ }
321
+
277
322
  // entity 'ParsedWitnesses'
278
323
  export declare function _ParsedWitnessesAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
279
324
  new (...args: any[]): {
@@ -296,6 +341,7 @@ export declare function _ParsedTransactionAspect<TBase extends new (...args: any
296
341
  new (...args: any[]): {
297
342
  txHash?: Blake2b256 | null
298
343
  network?: string | null
344
+ networkId?: number | null
299
345
  inputs?: Array<ParsedInput>
300
346
  outputs?: Array<ParsedOutput>
301
347
  validityStart?: string | null
@@ -304,6 +350,13 @@ export declare function _ParsedTransactionAspect<TBase extends new (...args: any
304
350
  mint?: Array<ParsedAsset>
305
351
  metadataLabels?: Array<string>
306
352
  collateral?: Array<ParsedInput>
353
+ referenceInputs?: Array<ParsedInput>
354
+ withdrawals?: Array<ParsedWithdrawal>
355
+ certificates?: Array<ParsedCertificate>
356
+ votingProcedures?: number | null
357
+ proposalProcedures?: number | null
358
+ treasuryDonation?: Lovelace | null
359
+ currentTreasuryValue?: Lovelace | null
307
360
  requiredSigners?: Array<Blake2b224>
308
361
  scriptDataHash?: Blake2b256 | null
309
362
  witnesses?: ParsedWitnesses | null
@@ -12,6 +12,9 @@ module.exports.__Array_MetadataSlice_ = createEntityProxy(['', 'MetadataSlice'],
12
12
  // UTxODataSlice
13
13
  module.exports.UTxODataSlice = createEntityProxy(['', 'UTxODataSlice'], { target: { is_singular: true } })
14
14
  module.exports.__Array_UTxODataSlice_ = createEntityProxy(['', 'UTxODataSlice'], { target: { is_singular: false }})
15
+ // TransactionConfirmations
16
+ module.exports.TransactionConfirmations = createEntityProxy(['', 'TransactionConfirmations'], { target: { is_singular: true } })
17
+ module.exports.__Array_TransactionConfirmations_ = createEntityProxy(['', 'TransactionConfirmations'], { target: { is_singular: false }})
15
18
  // ParsedInput
16
19
  module.exports.ParsedInput = createEntityProxy(['', 'ParsedInput'], { target: { is_singular: true } })
17
20
  module.exports.__Array_ParsedInput_ = createEntityProxy(['', 'ParsedInput'], { target: { is_singular: false }})
@@ -21,6 +24,12 @@ module.exports.__Array_ParsedAsset_ = createEntityProxy(['', 'ParsedAsset'], { t
21
24
  // ParsedOutput
22
25
  module.exports.ParsedOutput = createEntityProxy(['', 'ParsedOutput'], { target: { is_singular: true } })
23
26
  module.exports.__Array_ParsedOutput_ = createEntityProxy(['', 'ParsedOutput'], { target: { is_singular: false }})
27
+ // ParsedWithdrawal
28
+ module.exports.ParsedWithdrawal = createEntityProxy(['', 'ParsedWithdrawal'], { target: { is_singular: true } })
29
+ module.exports.__Array_ParsedWithdrawal_ = createEntityProxy(['', 'ParsedWithdrawal'], { target: { is_singular: false }})
30
+ // ParsedCertificate
31
+ module.exports.ParsedCertificate = createEntityProxy(['', 'ParsedCertificate'], { target: { is_singular: true } })
32
+ module.exports.__Array_ParsedCertificate_ = createEntityProxy(['', 'ParsedCertificate'], { target: { is_singular: false }})
24
33
  // ParsedWitnesses
25
34
  module.exports.ParsedWitnesses = createEntityProxy(['', 'ParsedWitnesses'], { target: { is_singular: true } })
26
35
  module.exports.__Array_ParsedWitnesses_ = createEntityProxy(['', 'ParsedWitnesses'], { target: { is_singular: false }})
package/db/schema.cds CHANGED
@@ -542,7 +542,7 @@ entity Addresses : temporal {
542
542
  stakeAddress : Bech32;
543
543
 
544
544
  @title : 'Address Type'
545
- @description: 'The type of address (base | enterprise | pointer | reward | script | unknown)'
545
+ @description: 'The CIP-19 kind of address (base | pointer | enterprise | reward | byron | unknown); a script payment credential shows in isScript'
546
546
  type : String(20);
547
547
 
548
548
  @title : 'Is Script Address'
package/db/types.cds CHANGED
@@ -186,6 +186,29 @@ type WorkerSignerType : String(10) enum {
186
186
  software = 'software'; // operator-configured Ed25519 key (dev/test)
187
187
  }
188
188
 
189
+ // -----------------------------------------------------
190
+ // Transaction confirmations (GetTransactionConfirmations action result)
191
+ // -----------------------------------------------------
192
+ @title : 'Transaction Confirmations'
193
+ @description: 'Depth of a transaction in the chain. Depth 1 means it sits in the tip block.'
194
+ type TransactionConfirmations {
195
+ @title : 'Transaction Hash'
196
+ @description: 'The transaction asked for'
197
+ txHash : Blake2b256;
198
+
199
+ @title : 'Block Height'
200
+ @description: 'Height of the block holding the transaction; null while it is not on chain'
201
+ blockHeight : Integer64;
202
+
203
+ @title : 'Tip Height'
204
+ @description: 'Height of the chain tip used for the count; null while the transaction is not on chain'
205
+ tipHeight : Integer64;
206
+
207
+ @title : 'Confirmations'
208
+ @description: 'Tip height minus block height plus one; 0 while the transaction is not on chain'
209
+ confirmations : Integer;
210
+ }
211
+
189
212
  // -----------------------------------------------------
190
213
  // Parsed Transaction (ParseTransactionCbor action result)
191
214
  // -----------------------------------------------------
@@ -239,6 +262,34 @@ type ParsedOutput {
239
262
  @title : 'Reference Script CBOR'
240
263
  @description: 'Hex-encoded CIP-33 reference script CBOR when present; null otherwise'
241
264
  referenceScriptHex : LargeString;
265
+
266
+ @title : 'Output CBOR Size'
267
+ @description: 'Byte length of the output as it stands in the transaction (input for the min-UTxO check)'
268
+ cborSize : Integer;
269
+ }
270
+
271
+ @title : 'Parsed Withdrawal'
272
+ @description: 'A reward withdrawal of a parsed transaction'
273
+ type ParsedWithdrawal {
274
+ @title : 'Reward Address'
275
+ @description: 'Bech32 reward address the lovelace is withdrawn from'
276
+ rewardAddress : Bech32;
277
+
278
+ @title : 'Withdrawn Lovelace'
279
+ @description: 'Withdrawn amount in lovelace (decimal string)'
280
+ lovelace : Lovelace;
281
+ }
282
+
283
+ @title : 'Parsed Certificate'
284
+ @description: 'A certificate of a parsed transaction'
285
+ type ParsedCertificate {
286
+ @title : 'Certificate Index'
287
+ @description: 'Position in the body certificate list'
288
+ index : Integer;
289
+
290
+ @title : 'Certificate Type'
291
+ @description: 'Ledger certificate name, e.g. StakeDelegation or RegistrationDrep'
292
+ type : String(40);
242
293
  }
243
294
 
244
295
  @title : 'Parsed Witness Counts'
@@ -276,6 +327,10 @@ type ParsedTransaction {
276
327
  @description: '"mainnet" or "testnet" from the tx body network ID byte; null if absent. preview vs preprod cannot be distinguished from CBOR alone.'
277
328
  network : String(10);
278
329
 
330
+ @title : 'Network ID'
331
+ @description: 'Body field 15: 1 = mainnet, 0 = testnet; null if absent'
332
+ networkId : Integer;
333
+
279
334
  @title : 'Inputs'
280
335
  @description: 'UTxOs consumed by the transaction'
281
336
  inputs : many ParsedInput;
@@ -308,6 +363,34 @@ type ParsedTransaction {
308
363
  @description: 'Collateral UTxOs for phase-2 validation (empty when no Plutus scripts run)'
309
364
  collateral : many ParsedInput;
310
365
 
366
+ @title : 'Reference Inputs'
367
+ @description: 'UTxOs the transaction reads without spending them'
368
+ referenceInputs : many ParsedInput;
369
+
370
+ @title : 'Withdrawals'
371
+ @description: 'Reward withdrawals; empty array if none'
372
+ withdrawals : many ParsedWithdrawal;
373
+
374
+ @title : 'Certificates'
375
+ @description: 'Certificates in body order; empty array if none'
376
+ certificates : many ParsedCertificate;
377
+
378
+ @title : 'Vote Count'
379
+ @description: 'Number of votes over all voters; 0 if the body has no voting procedures'
380
+ votingProcedures : Integer;
381
+
382
+ @title : 'Proposal Count'
383
+ @description: 'Number of governance proposals'
384
+ proposalProcedures : Integer;
385
+
386
+ @title : 'Treasury Donation'
387
+ @description: 'Lovelace donated to the treasury; null if absent'
388
+ treasuryDonation : Lovelace;
389
+
390
+ @title : 'Current Treasury Value'
391
+ @description: 'Treasury value the transaction asserts; null if absent'
392
+ currentTreasuryValue : Lovelace;
393
+
311
394
  @title : 'Required Signers'
312
395
  @description: '28-byte Ed25519 key hashes listed in the tx body required_signers field'
313
396
  requiredSigners : many Blake2b224;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "2.0.0-rc.31",
3
+ "version": "2.0.0-rc.33",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { TransactionConfirmations } from '../srv/utils/types';
1
2
  export { CardanoClient } from '../srv/blockchain/cardano-client';
2
3
  export type { CardanoClientConfig, Network, BackendName, TransactionBuilderName } from '../srv/blockchain/cardano-client';
3
4
  export { CardanoIndexer } from '../srv/blockchain/cardano-indexer';
@@ -12,7 +13,10 @@ export { loadAgentGrantsConfig } from '../srv/utils/agent-grants-config';
12
13
  export type { AgentGrantsConfig } from '../srv/utils/agent-grants-config';
13
14
  export type { HsmConfig, HsmSignResult } from '../srv/utils/types';
14
15
  export { parseTransaction } from '../srv/cbor';
15
- export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, } from '../srv/cbor';
16
+ export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, ParsedWithdrawal, ParsedCertificate, } from '../srv/cbor';
17
+ export { verifyTxWitnesses } from '../srv/blockchain/signing/signature-verifier';
18
+ export { posixToSlot, slotToPosixMs } from '../srv/utils/epoch-slots';
19
+ export type { TxWitnessVerification, TransactionConfirmations } from '../srv/utils/types';
16
20
  export { applyScriptParameters, plutusScriptHash } from '../srv/utils/tx-build-helper';
17
21
  /**
18
22
  * Initialize the plugin: config from cds.env.requires["odatano-core"] or env vars,
@@ -21,6 +25,8 @@ export { applyScriptParameters, plutusScriptHash } from '../srv/utils/tx-build-h
21
25
  export declare function initialize(): Promise<void>;
22
26
  /** Shut down the plugin and close all backend connections. */
23
27
  export declare function shutdown(): Promise<void>;
28
+ /** Confirmations of a transaction; needs initialize(). See CardanoIndexer.resolveTransactionConfirmations. */
29
+ export declare function getTransactionConfirmations(txHash: string): Promise<TransactionConfirmations>;
24
30
  /** Current plugin status. */
25
31
  export declare function getStatus(): {
26
32
  initialized: boolean;
package/src/index.js CHANGED
@@ -36,11 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.plutusScriptHash = exports.applyScriptParameters = exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
39
+ exports.plutusScriptHash = exports.applyScriptParameters = exports.slotToPosixMs = exports.posixToSlot = exports.verifyTxWitnesses = exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
40
40
  exports.initialize = initialize;
41
41
  exports.shutdown = shutdown;
42
+ exports.getTransactionConfirmations = getTransactionConfirmations;
42
43
  exports.getStatus = getStatus;
43
44
  const cds_1 = __importDefault(require("@sap/cds"));
45
+ const validators_1 = require("../srv/utils/validators");
46
+ const errors_1 = require("../srv/utils/errors");
47
+ const error_codes_1 = require("../srv/utils/error-codes");
44
48
  const logger = cds_1.default.log('ODATANO');
45
49
  // Re-export key types and classes for programmatic consumers
46
50
  var cardano_client_1 = require("../srv/blockchain/cardano-client");
@@ -86,6 +90,11 @@ Object.defineProperty(exports, "loadAgentGrantsConfig", { enumerable: true, get:
86
90
  // Re-export pure CBOR utilities (no CAP round-trip needed)
87
91
  var cbor_1 = require("../srv/cbor");
88
92
  Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return cbor_1.parseTransaction; } });
93
+ var signature_verifier_1 = require("../srv/blockchain/signing/signature-verifier");
94
+ Object.defineProperty(exports, "verifyTxWitnesses", { enumerable: true, get: function () { return signature_verifier_1.verifyTxWitnesses; } });
95
+ var epoch_slots_1 = require("../srv/utils/epoch-slots");
96
+ Object.defineProperty(exports, "posixToSlot", { enumerable: true, get: function () { return epoch_slots_1.posixToSlot; } });
97
+ Object.defineProperty(exports, "slotToPosixMs", { enumerable: true, get: function () { return epoch_slots_1.slotToPosixMs; } });
89
98
  // Pure script helpers (no initialize() needed)
90
99
  var tx_build_helper_1 = require("../srv/utils/tx-build-helper");
91
100
  Object.defineProperty(exports, "applyScriptParameters", { enumerable: true, get: function () { return tx_build_helper_1.applyScriptParameters; } });
@@ -122,6 +131,13 @@ async function shutdown() {
122
131
  await shutdownAppContext();
123
132
  logger.info('ODATANO core shutdown');
124
133
  }
134
+ /** Confirmations of a transaction; needs initialize(). See CardanoIndexer.resolveTransactionConfirmations. */
135
+ async function getTransactionConfirmations(txHash) {
136
+ if (!(0, validators_1.isTxHash)(txHash))
137
+ throw new errors_1.TransactionValidationError(`Invalid transaction hash: ${txHash}`, undefined, error_codes_1.ERROR_CODES.INVALID_INPUT);
138
+ const { getCardanoIndexer } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
139
+ return cds_1.default.tx((tx) => getCardanoIndexer().resolveTransactionConfirmations(tx, txHash));
140
+ }
125
141
  /** Current plugin status. */
126
142
  function getStatus() {
127
143
  try {
@@ -147,7 +147,8 @@ class BlockfrostBackend {
147
147
  return {
148
148
  address: address_data.address,
149
149
  stakeAddress: address_data.stake_address,
150
- type: address_data.type,
150
+ // Blockfrost says shelley | byron; the other sources and the model use the CIP-19 kind
151
+ type: (0, mappers_1.decodeShelleyAddress)(address_data.address).type,
151
152
  isScript: address_data.script,
152
153
  amount: address_data.amount,
153
154
  utxos: address_utxos.map(utxo => ({
@@ -216,10 +216,10 @@ class KoiosBackend {
216
216
  end_time: data.end_time,
217
217
  first_block_time: data.first_block_time,
218
218
  last_block_time: data.last_block_time,
219
- block_count: data.block_count,
219
+ block_count: data.blk_count,
220
220
  tx_count: data.tx_count,
221
- output: data.total_output,
222
- fees: data.total_fees,
221
+ output: data.out_sum,
222
+ fees: data.fees,
223
223
  active_stake: data.active_stake,
224
224
  };
225
225
  }, this.name);
@@ -251,8 +251,9 @@ class KoiosBackend {
251
251
  return {
252
252
  address: address,
253
253
  stakeAddress: addressData.stake_address || null,
254
- type: addressData.address_type,
255
- isScript: addressData.is_script,
254
+ // /address_info has no address type; it follows from the address itself
255
+ type: (0, mappers_1.decodeShelleyAddress)(address).type,
256
+ isScript: addressData.script_address,
256
257
  amount: amount,
257
258
  utxos: addressUtxos,
258
259
  };
@@ -304,7 +305,6 @@ class KoiosBackend {
304
305
  outputIndex: utxo.tx_index,
305
306
  address: address,
306
307
  amount: amount,
307
- blockHash: utxo.block_hash,
308
308
  datumHash: utxo.datum_hash || null,
309
309
  scriptRef: koiosRefScriptBytes(utxo.reference_script),
310
310
  inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(utxo.inline_datum),
@@ -339,7 +339,6 @@ class KoiosBackend {
339
339
  outputIndex: utxo.tx_index,
340
340
  address: utxo.address ?? '',
341
341
  amount: amount,
342
- blockHash: utxo.block_hash,
343
342
  datumHash: utxo.datum_hash || null,
344
343
  scriptRef: koiosRefScriptBytes(utxo.reference_script),
345
344
  inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(utxo.inline_datum),
@@ -450,13 +449,14 @@ class KoiosBackend {
450
449
  // a 0 would be indistinguishable from a real zero downstream.
451
450
  blocksEpoch: null,
452
451
  liveStake: poolData.live_stake || '0',
453
- liveSize: poolData.live_size || 0,
452
+ // /pool_info has no live share
453
+ liveSize: null,
454
454
  liveDelegators: poolData.live_delegators || 0,
455
455
  // Koios reports saturation in PERCENT (75.42); PoolData holds a fraction (0.7542)
456
456
  // stored in Decimal(9, 4) — the percent value would overflow the column.
457
457
  liveSaturation: (Number(poolData.live_saturation) || 0) / 100,
458
458
  activeStake: poolData.active_stake || '0',
459
- activeSize: poolData.active_size || 0,
459
+ activeSize: Number(poolData.sigma) || 0,
460
460
  pledge: poolData.pledge || '0',
461
461
  margin: poolData.margin || 0,
462
462
  fixedCost: poolData.fixed_cost || '0',
@@ -558,7 +558,8 @@ class KoiosBackend {
558
558
  action: isNegative ? 'burn' : 'mint',
559
559
  quantity: isNegative ? rawQty.slice(1) : rawQty,
560
560
  blockTime: typeof entry.block_time === 'number' ? entry.block_time : null,
561
- blockHeight: typeof entry.block_height === 'number' ? entry.block_height : null,
561
+ // minting_txs carry no block height
562
+ blockHeight: null,
562
563
  };
563
564
  });
564
565
  // Sort newest-first and cap at limit (defensive — Koios may return ascending)
@@ -627,16 +628,17 @@ class KoiosBackend {
627
628
  const accountData = data[0];
628
629
  return {
629
630
  stakeaddress: accountData.stake_address,
630
- active: accountData.active ?? false,
631
- activeEpoch: accountData.active_epoch ?? 0,
632
- controlledAmount: accountData.controlled_amount,
633
- rewardsSum: accountData.rewards_sum,
634
- withdrawalsSum: accountData.withdrawals_sum,
635
- reservesSum: accountData.reserves_sum,
636
- treasurySum: accountData.treasury_sum,
637
- withdrawableAmount: accountData.withdrawable_amount,
638
- poolId: accountData.pool_id || null,
639
- drepId: accountData.drep_id || null,
631
+ active: accountData.status === 'registered',
632
+ // /account_info has no registration epoch
633
+ activeEpoch: 0,
634
+ controlledAmount: accountData.total_balance,
635
+ rewardsSum: accountData.rewards,
636
+ withdrawalsSum: accountData.withdrawals,
637
+ reservesSum: accountData.reserves,
638
+ treasurySum: accountData.treasury,
639
+ withdrawableAmount: accountData.rewards_available,
640
+ poolId: accountData.delegated_pool || null,
641
+ drepId: accountData.delegated_drep || null,
640
642
  addresses: addresses,
641
643
  };
642
644
  }, this.name);
@@ -654,7 +654,8 @@ class OgmiosBackend {
654
654
  // not in the ledger state; null = unavailable, as on Koios
655
655
  blocksEpoch: null,
656
656
  liveStake: pool.stake?.ada?.lovelace ? String(pool.stake.ada.lovelace) : '0',
657
- liveSize: 0,
657
+ // no total live stake to divide by; null = unavailable
658
+ liveSize: null,
658
659
  // not in the ledger state; null = unavailable
659
660
  liveDelegators: null,
660
661
  liveSaturation: 0,
@@ -3,7 +3,7 @@ import type { CardanoClient } from './cardano-client';
3
3
  import type { CardanoTransactionBuilder } from './cardano-tx-builder';
4
4
  import { Transaction as CardanoTransaction, AddressUTxOs, TransactionMetadata, NetworkInformation, Block, Epoch, AssetHistory, Account, Drep, Pool, Asset, Address, LedgerProtocolParameter, AddressTransactions } from '#cds-models/CardanoODataService';
5
5
  import { TransactionBuild, TransactionSubmission } from '#cds-models/CardanoTransactionService';
6
- import { TxBuildRequest, TxBuildPlutusRequest, AssetInfo, AccountData, PoolData, NetworkInformation as ProviderNetworkInformation, Address as ProviderAddress, Transaction as ProviderTransaction, UTxO as OdatanoUtxo, BlockData, AssetHistoryEntry as AssetHistoryEntryProviderData } from '../utils/types';
6
+ import { TxBuildRequest, TxBuildPlutusRequest, AssetInfo, AccountData, PoolData, NetworkInformation as ProviderNetworkInformation, Address as ProviderAddress, Transaction as ProviderTransaction, UTxO as OdatanoUtxo, BlockData, AssetHistoryEntry as AssetHistoryEntryProviderData, TransactionConfirmations } from '../utils/types';
7
7
  import { type LedgerAnchor, type LedgerLookup } from './ledger-state';
8
8
  import type { TxCacheTargets } from '../utils/tx-build-helper';
9
9
  /**
@@ -442,7 +442,16 @@ export declare class CardanoIndexer {
442
442
  findIndexedTransaction(tx: CapTransaction, txHash: string): Promise<{
443
443
  slot: number | null;
444
444
  blockHeight: number | null;
445
+ blockHash: string | null;
445
446
  } | null>;
447
+ /**
448
+ * Blocks on top of a transaction, its own block included; 0 while it is not on chain.
449
+ * A stored row counts only when its block lies in the crawled chain, because the crawler
450
+ * removes those rows on a rollback. Otherwise height and tip come from the backends.
451
+ */
452
+ resolveTransactionConfirmations(tx: CapTransaction, txHash: string): Promise<TransactionConfirmations>;
453
+ /** Height of a transaction in a crawled block and the crawler's tip; null when the crawl does not hold it. */
454
+ private crawledTransactionDepth;
446
455
  /**
447
456
  * Ensure a set of transactions is indexed: DB check, batch fetch of the missing ones, UPSERT.
448
457
  * @returns provider transactions for the hashes that had to be fetched
@@ -117,7 +117,7 @@ class CardanoIndexer {
117
117
  const cursor = await (0, sync_state_1.readCursor)(tx);
118
118
  if (!cursor || cursor.syncStatus !== 'synced' || cursor.startSlot == null || !(0, sync_state_1.isCrawlerLeaseActive)(cursor))
119
119
  return null;
120
- return { fromSlot: cursor.startSlot, lastSlot: cursor.lastSlot, ledger: cursor.utxoSet.status === 'active' };
120
+ return { fromSlot: cursor.startSlot, lastSlot: cursor.lastSlot, tipHeight: cursor.tipHeight, ledger: cursor.utxoSet.status === 'active' };
121
121
  }
122
122
  /**
123
123
  * Block counts of a pool from crawled blocks (`slotLeader` = pool id): the current epoch when the
@@ -1791,9 +1791,54 @@ class CardanoIndexer {
1791
1791
  static ADDR_CONCURRENCY = 5;
1792
1792
  /** Block position of a transaction already in the local index (crawled or cached), or null. */
1793
1793
  async findIndexedTransaction(tx, txHash) {
1794
- const row = await tx.run(SELECT.one.from(CardanoODataService_1.Transactions).columns('slot', 'blockHeight').where({ hash: txHash }));
1794
+ const row = await tx.run(SELECT.one.from(CardanoODataService_1.Transactions).columns('slot', 'blockHeight', 'blockHash').where({ hash: txHash }));
1795
1795
  return row ?? null;
1796
1796
  }
1797
+ /**
1798
+ * Blocks on top of a transaction, its own block included; 0 while it is not on chain.
1799
+ * A stored row counts only when its block lies in the crawled chain, because the crawler
1800
+ * removes those rows on a rollback. Otherwise height and tip come from the backends.
1801
+ */
1802
+ async resolveTransactionConfirmations(tx, txHash) {
1803
+ const crawled = await this.crawledTransactionDepth(tx, txHash);
1804
+ if (crawled)
1805
+ return { txHash, ...crawled, confirmations: crawled.tipHeight - crawled.blockHeight + 1 };
1806
+ let blockHeight;
1807
+ try {
1808
+ const indexed = await this.indexTransaction(tx, txHash);
1809
+ blockHeight = indexed.blockHeight == null ? null : Number(indexed.blockHeight);
1810
+ }
1811
+ catch (err) {
1812
+ if (!(0, errors_1.isNotFoundOnAllBackends)(err))
1813
+ throw err;
1814
+ blockHeight = null;
1815
+ }
1816
+ if (blockHeight == null)
1817
+ return { txHash, blockHeight: null, tipHeight: null, confirmations: 0 };
1818
+ const tip = await this.client.getLatestBlock();
1819
+ if (tip.height == null)
1820
+ throw new errors_1.ProviderUnavailableError('Chain tip height unknown');
1821
+ // a tip from a backend that lags the one that found the tx counts the tx block only
1822
+ const tipHeight = Math.max(tip.height, blockHeight);
1823
+ return { txHash, blockHeight, tipHeight, confirmations: tipHeight - blockHeight + 1 };
1824
+ }
1825
+ /** Height of a transaction in a crawled block and the crawler's tip; null when the crawl does not hold it. */
1826
+ async crawledTransactionDepth(tx, txHash) {
1827
+ const coverage = await this.localCoverage(tx);
1828
+ if (coverage?.tipHeight == null)
1829
+ return null;
1830
+ const stored = await this.findIndexedTransaction(tx, txHash);
1831
+ if (stored?.blockHeight == null || stored.slot == null || !stored.blockHash)
1832
+ return null;
1833
+ const slot = Number(stored.slot);
1834
+ if (slot < coverage.fromSlot || slot > coverage.lastSlot)
1835
+ return null;
1836
+ const block = await tx.run(SELECT.one.from(CardanoODataService_1.Blocks).columns('hash').where({ hash: stored.blockHash }));
1837
+ if (!block)
1838
+ return null;
1839
+ const blockHeight = Number(stored.blockHeight);
1840
+ return { blockHeight, tipHeight: Math.max(coverage.tipHeight, blockHeight) };
1841
+ }
1797
1842
  /**
1798
1843
  * Ensure a set of transactions is indexed: DB check, batch fetch of the missing ones, UPSERT.
1799
1844
  * @returns provider transactions for the hashes that had to be fetched
@@ -1,4 +1,9 @@
1
- import { SignatureVerificationResult, VerificationOptions } from '../../utils/types';
1
+ import { SignatureVerificationResult, TxWitnessVerification, VerificationOptions } from '../../utils/types';
2
+ /**
3
+ * Check every vkey witness of a signed tx against its body hash. Pure, needs no initialize().
4
+ * A tx without vkey witnesses is valid here; which keys had to sign is the caller's check.
5
+ */
6
+ export declare function verifyTxWitnesses(signedTxCbor: string): TxWitnessVerification;
2
7
  /**
3
8
  * Verifies externally signed transactions without private keys: CBOR parse, body-hash
4
9
  * integrity against the build, required signers present, Ed25519 check per witness.