@odatano/core 2.0.0-rc.20 → 2.0.0-rc.21

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.
@@ -763,7 +763,9 @@ module.exports = (srv) => {
763
763
  if (!submission)
764
764
  throw new errors_1.NotFoundError(`Submission '${submissionId}'`);
765
765
  try {
766
- const txDetails = await (0, server_1.getCardanoClient)().getTransaction(submission.txHash);
766
+ // the local index first (filled by the crawler), then the backends
767
+ const txDetails = await (0, server_1.getCardanoIndexer)().findIndexedTransaction(db, submission.txHash)
768
+ ?? await (0, server_1.getCardanoClient)().getTransaction(submission.txHash);
767
769
  if (txDetails) {
768
770
  await db.run(UPDATE.entity(TransactionSubmissions)
769
771
  .set({ status: 'confirmed' })
@@ -22,9 +22,13 @@ exports.DB_INDEXES = Object.freeze([
22
22
  { name: 'odatano_cardano_blocks_height_desc', table: 'odatano_cardano_Blocks', columns: 'height DESC', postgres: 'height DESC NULLS LAST' },
23
23
  { name: 'odatano_cardano_blocks_slot', table: 'odatano_cardano_Blocks', columns: 'slot' },
24
24
  { name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
25
+ // block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
26
+ { name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
25
27
  // Transactions of a block (rollback `blockHash in`, OData filters by block / height)
26
28
  { name: 'odatano_cardano_transactions_block', table: 'odatano_cardano_Transactions', columns: 'blockHash' },
27
29
  { name: 'odatano_cardano_transactions_height', table: 'odatano_cardano_Transactions', columns: 'blockHeight' },
30
+ // Input/output rows back to their transaction (`tx` association, stale-seq check of the crawler)
31
+ { name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
28
32
  // GetMetadataByTxHash, rollback
29
33
  { name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
30
34
  // rollback `txHash in` (key is unit, txHash)
@@ -0,0 +1,13 @@
1
+ import { EPOCH_CONFIG_BY_NETWORK } from './const';
2
+ type EpochNetwork = keyof typeof EPOCH_CONFIG_BY_NETWORK;
3
+ /** Epoch a slot belongs to, from the network's Shelley anchor. */
4
+ export declare function epochOfSlot(network: EpochNetwork, slot: number): number;
5
+ /** First absolute slot of an epoch, from the network's Shelley anchor. */
6
+ export declare function epochStartSlot(network: EpochNetwork, epoch: number): number;
7
+ /**
8
+ * Absolute POSIX seconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
9
+ * slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
10
+ */
11
+ export declare function slotToPosixSeconds(network: EpochNetwork, slot: number): number;
12
+ export {};
13
+ //# sourceMappingURL=epoch-slots.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.epochOfSlot = epochOfSlot;
4
+ exports.epochStartSlot = epochStartSlot;
5
+ exports.slotToPosixSeconds = slotToPosixSeconds;
6
+ const const_1 = require("./const");
7
+ /** Epoch a slot belongs to, from the network's Shelley anchor. */
8
+ function epochOfSlot(network, slot) {
9
+ const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
10
+ return cfg.shelleyStartEpoch + Math.floor((slot - cfg.shelleyStartSlot) / cfg.slotsPerEpoch);
11
+ }
12
+ /** First absolute slot of an epoch, from the network's Shelley anchor. */
13
+ function epochStartSlot(network, epoch) {
14
+ const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
15
+ return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
16
+ }
17
+ /**
18
+ * Absolute POSIX seconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
19
+ * slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
20
+ */
21
+ function slotToPosixSeconds(network, slot) {
22
+ const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
23
+ return Math.floor((genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs) / 1000);
24
+ }
25
+ //# sourceMappingURL=epoch-slots.js.map
@@ -54,7 +54,8 @@ export declare class RateLimitError extends BackendError {
54
54
  /** Every backend failed; carries the last error's status, or 503 when all were skipped. */
55
55
  export declare class AllBackendsFailedError extends BackendError {
56
56
  readonly errors: BackendError[];
57
- constructor(errors: BackendError[], originalError?: unknown);
57
+ /** @param skipped why backends were not called at all, e.g. `koios: circuit open` */
58
+ constructor(errors: BackendError[], originalError?: unknown, skipped?: string[]);
58
59
  }
59
60
  /**
60
61
  * True when the resource is absent on every consulted backend: a NotFoundError, or an
@@ -112,11 +112,13 @@ exports.RateLimitError = RateLimitError;
112
112
  /** Every backend failed; carries the last error's status, or 503 when all were skipped. */
113
113
  class AllBackendsFailedError extends BackendError {
114
114
  errors;
115
- constructor(errors, originalError) {
115
+ /** @param skipped why backends were not called at all, e.g. `koios: circuit open` */
116
+ constructor(errors, originalError, skipped = []) {
116
117
  const lastError = errors[errors.length - 1];
118
+ const noneCalled = skipped.length ? `no backend available (${skipped.join('; ')})` : 'unknown error';
117
119
  super(
118
120
  // Empty errors: every backend was skipped (method unsupported), nothing failed upstream, so 503
119
- `All backends failed: ${lastError?.message ?? 'unknown error'}`, lastError?.statusCode ?? 503, lastError?.code ?? error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, undefined, originalError);
121
+ `All backends failed: ${lastError?.message ?? noneCalled}`, lastError?.statusCode ?? 503, lastError?.code ?? error_codes_1.ERROR_CODES.PROVIDER_UNAVAILABLE, undefined, originalError);
120
122
  this.errors = errors;
121
123
  }
122
124
  }
@@ -308,7 +310,9 @@ exports.ChainSyncFrameError = ChainSyncFrameError;
308
310
  /** A backend failed to initialize. */
309
311
  class BackendInitError extends BackendError {
310
312
  constructor(backendName, originalError) {
311
- super(`Failed to initialize backend: ${backendName}`, 500, error_codes_1.ERROR_CODES.INTERNAL_ERROR, backendName, originalError);
313
+ super(originalError != null
314
+ ? `Failed to initialize backend: ${backendName} (${getErrorMessage(originalError)})`
315
+ : `Failed to initialize backend: ${backendName}`, 500, error_codes_1.ERROR_CODES.INTERNAL_ERROR, backendName, originalError);
312
316
  this.name = 'BackendInitError';
313
317
  }
314
318
  }
@@ -3,20 +3,23 @@ import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as
3
3
  import type { TransactionBuild as TransactionBuildRow, TransactionBuildInput as TransactionBuildInputRow, TransactionBuildOutput as TransactionBuildOutputRow, TransactionSubmission as TransactionSubmissionRow, AddressTransactionBuild as AddressTransactionBuildRow } from '#cds-models/CardanoTransactionService';
4
4
  import type { AddressSigningRequest as AddressSigningRequestRow } from '#cds-models/CardanoSignService';
5
5
  import type { Request } from '@sap/cds';
6
+ /** Key of a transaction's input/output rows: chain position, ascending, below 2^53 for any real slot. */
7
+ export declare const TX_SEQ_SLOT_FACTOR = 65536;
8
+ export declare function txSeqOf(slot: number, txIndex: number): number;
6
9
  /** Provider transaction to TransactionRow. */
7
10
  export declare function mapTransaction(providerTx: TransactionProviderData): TransactionRow;
8
11
  /** Provider transaction inputs to TransactionInputRows, keyed by position in the tx. */
9
- export declare function mapTransactionInputs(txHash: string, txInputs: TxInputProviderData[]): TransactionInputRow[];
12
+ export declare function mapTransactionInputs(txSeq: number, txInputs: TxInputProviderData[]): TransactionInputRow[];
10
13
  /** Provider transaction input assets to TransactionInputAssetRows. */
11
- export declare function mapTransactionInputAssets(txHash: string, inputs: TxInputProviderData[]): TransactionInputAssetRow[];
14
+ export declare function mapTransactionInputAssets(txSeq: number, inputs: TxInputProviderData[]): TransactionInputAssetRow[];
12
15
  /** Normalized certificates to TransactionCertificateRows, one per (certIndex, kind). */
13
16
  export declare function mapTransactionCertificates(txHash: string, certificates: TxCertificateProviderData[]): TransactionCertificateRow[];
14
17
  /** Normalized withdrawals to TransactionWithdrawalRows, one per reward account. */
15
18
  export declare function mapTransactionWithdrawals(txHash: string, withdrawals: TxWithdrawalProviderData[]): TransactionWithdrawalRow[];
16
19
  /** Provider transaction outputs to TransactionOutputRows. */
17
- export declare function mapTransactionOutputs(txHash: string, txOutputs: TxOutputProviderData[]): TransactionOutputRow[];
20
+ export declare function mapTransactionOutputs(txSeq: number, txOutputs: TxOutputProviderData[]): TransactionOutputRow[];
18
21
  /** Provider transaction output assets to TransactionOutputAssetRows. */
19
- export declare function mapTransactionOutputAssets(txHash: string, outputs: TxOutputProviderData[]): TransactionOutputAssetRow[];
22
+ export declare function mapTransactionOutputAssets(txSeq: number, outputs: TxOutputProviderData[]): TransactionOutputAssetRow[];
20
23
  /** Provider address to a temporal AddressRow valid for `maxAge` ms. */
21
24
  export declare function mapAddress(address: string, addressData: AddressProviderData, maxAge: number): AddressRow;
22
25
  /** Provider transactions to AddressTransactionRows with the address's net amounts; non-temporal. */
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BARE_ASSET_STAMP = void 0;
6
+ exports.BARE_ASSET_STAMP = exports.TX_SEQ_SLOT_FACTOR = void 0;
7
+ exports.txSeqOf = txSeqOf;
7
8
  exports.mapTransaction = mapTransaction;
8
9
  exports.mapTransactionInputs = mapTransactionInputs;
9
10
  exports.mapTransactionInputAssets = mapTransactionInputAssets;
@@ -53,6 +54,11 @@ const cardano_costmodels_ts_1 = require("@harmoniclabs/cardano-costmodels-ts");
53
54
  const logger = cds_1.default.log('mappers');
54
55
  const errors_1 = require("./errors");
55
56
  const const_1 = require("./const");
57
+ /** Key of a transaction's input/output rows: chain position, ascending, below 2^53 for any real slot. */
58
+ exports.TX_SEQ_SLOT_FACTOR = 65536;
59
+ function txSeqOf(slot, txIndex) {
60
+ return slot * exports.TX_SEQ_SLOT_FACTOR + txIndex;
61
+ }
56
62
  /** Provider transaction to TransactionRow. */
57
63
  function mapTransaction(providerTx) {
58
64
  // length check: chain-sync delivers `[]` for metadata-less txs
@@ -61,6 +67,7 @@ function mapTransaction(providerTx) {
61
67
  const hasOutputs = Array.isArray(providerTx.outputs) && providerTx.outputs.length > 0;
62
68
  return {
63
69
  hash: providerTx.hash,
70
+ txSeq: txSeqOf(providerTx.slot, providerTx.index),
64
71
  blockHash: providerTx.blockHash,
65
72
  blockHeight: providerTx.blockHeight ?? null,
66
73
  blockTime: providerTx.blockTime ?? null,
@@ -75,14 +82,14 @@ function mapTransaction(providerTx) {
75
82
  };
76
83
  }
77
84
  /** Provider transaction inputs to TransactionInputRows, keyed by position in the tx. */
78
- function mapTransactionInputs(txHash, txInputs) {
85
+ function mapTransactionInputs(txSeq, txInputs) {
79
86
  return txInputs.map((input, idx) => {
80
87
  // Position in this tx's inputs; input.outputIndex is the spent UTxO's index, not a key here
81
88
  const inputIndex = idx;
82
89
  const hasAddress = !!input.address?.length;
83
90
  const hasAssets = Array.isArray(input.amount) && input.amount.length > 0;
84
91
  return {
85
- tx_hash: txHash,
92
+ txSeq,
86
93
  inputIndex: inputIndex,
87
94
  // unresolved chain-sync inputs carry '': persist a null FK, not an empty-string association
88
95
  address_address: input.address || null,
@@ -100,7 +107,7 @@ function mapTransactionInputs(txHash, txInputs) {
100
107
  });
101
108
  }
102
109
  /** Provider transaction input assets to TransactionInputAssetRows. */
103
- function mapTransactionInputAssets(txHash, inputs) {
110
+ function mapTransactionInputAssets(txSeq, inputs) {
104
111
  return inputs.flatMap((input, idx) => {
105
112
  // must match mapTransactionInputs
106
113
  const inputIndex = idx;
@@ -109,7 +116,7 @@ function mapTransactionInputAssets(txHash, inputs) {
109
116
  return input.amount.map(a => {
110
117
  const { policyId, assetName } = parseAssetUnit(a.unit);
111
118
  return {
112
- input_tx_hash: txHash,
119
+ input_txSeq: txSeq,
113
120
  input_inputIndex: inputIndex,
114
121
  unit: a.unit,
115
122
  asset_quantity: a.quantity,
@@ -143,13 +150,13 @@ function mapTransactionWithdrawals(txHash, withdrawals) {
143
150
  }));
144
151
  }
145
152
  /** Provider transaction outputs to TransactionOutputRows. */
146
- function mapTransactionOutputs(txHash, txOutputs) {
153
+ function mapTransactionOutputs(txSeq, txOutputs) {
147
154
  return txOutputs.map((output) => {
148
155
  const outputIndex = output.outputIndex;
149
156
  const hasAddresses = !!output.address?.length;
150
157
  const hasAssets = Array.isArray(output.amount) && output.amount.length > 0;
151
158
  return {
152
- tx_hash: txHash,
159
+ txSeq,
153
160
  outputIndex: outputIndex,
154
161
  address_address: output.address,
155
162
  utxo_dataHash: output.dataHash || null,
@@ -161,7 +168,7 @@ function mapTransactionOutputs(txHash, txOutputs) {
161
168
  });
162
169
  }
163
170
  /** Provider transaction output assets to TransactionOutputAssetRows. */
164
- function mapTransactionOutputAssets(txHash, outputs) {
171
+ function mapTransactionOutputAssets(txSeq, outputs) {
165
172
  return outputs.flatMap((output) => {
166
173
  const outputIndex = output.outputIndex;
167
174
  if (!Array.isArray(output.amount))
@@ -169,7 +176,7 @@ function mapTransactionOutputAssets(txHash, outputs) {
169
176
  return output.amount.map(a => {
170
177
  const { policyId, assetName } = parseAssetUnit(a.unit);
171
178
  return {
172
- output_tx_hash: txHash,
179
+ output_txSeq: txSeq,
173
180
  output_outputIndex: outputIndex,
174
181
  unit: a.unit,
175
182
  asset_quantity: a.quantity,
@@ -604,6 +611,8 @@ function mapAccount(providerAccountData, max_age) {
604
611
  reservesSum: providerAccountData.reservesSum,
605
612
  treasurySum: providerAccountData.treasurySum,
606
613
  withdrawableAmount: providerAccountData.withdrawableAmount,
614
+ poolId_poolId: providerAccountData.poolId ?? null,
615
+ drepId_drepId: providerAccountData.drepId ?? null,
607
616
  hasAddresses: providerAccountData.addresses.length > 0,
608
617
  };
609
618
  }
@@ -132,6 +132,8 @@ export interface BlockData {
132
132
  size: number;
133
133
  txCount: number;
134
134
  fees?: string | null;
135
+ /** Header fields only (ledger tip): size, txCount, fees and slotLeader are placeholders, not block data. */
136
+ headerOnly?: boolean;
135
137
  }
136
138
  /** Network supply */
137
139
  export interface Supply {