@odatano/core 2.0.0-rc.49 → 2.0.0-rc.50
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/@cds-models/CardanoAgentService/index.d.ts +6 -12
- package/@cds-models/CardanoIndexerService/index.d.ts +200 -2
- package/@cds-models/CardanoIndexerService/index.js +24 -0
- package/@cds-models/CardanoODataService/index.d.ts +49 -6
- package/@cds-models/CardanoODataService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +3 -3
- package/@cds-models/CardanoWorkerService/index.d.ts +4 -3
- package/@cds-models/index.d.ts +9 -1
- package/@cds-models/index.js +2 -1
- package/@cds-models/odatano/cardano/index.d.ts +59 -5
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/README.md +29 -17
- package/db/schema.cds +117 -24
- package/db/types.cds +8 -0
- package/package.json +17 -15
- package/scripts/migrate-schema.mjs +334 -0
- package/src/index.d.ts +7 -5
- package/src/index.js +12 -10
- package/src/plugin.js +6 -7
- package/srv/blockchain/backends/blockfrost-backend.js +9 -1
- package/srv/blockchain/backends/cardano-backend.d.ts +15 -0
- package/srv/blockchain/backends/cardano-backend.js +5 -0
- package/srv/blockchain/backends/koios-backend.js +16 -10
- package/srv/blockchain/backends/ogmios-backend.d.ts +9 -3
- package/srv/blockchain/backends/ogmios-backend.js +60 -18
- package/srv/blockchain/cardano-client.d.ts +5 -4
- package/srv/blockchain/cardano-client.js +46 -13
- package/srv/blockchain/cardano-indexer.d.ts +116 -9
- package/srv/blockchain/cardano-indexer.js +436 -189
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +23 -1
- package/srv/blockchain/crawler/asset-registry-backfill.js +91 -1
- package/srv/blockchain/crawler/certificate-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/certificate-backfill.js +10 -3
- package/srv/blockchain/crawler/crawler.d.ts +15 -0
- package/srv/blockchain/crawler/crawler.js +68 -3
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +171 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
- package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/transaction-backfill.js +12 -8
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -1
- package/srv/blockchain/signing/cose-verifier.js +144 -56
- package/srv/blockchain/signing/hsm-signer.js +2 -1
- package/srv/blockchain/signing/submission-finalizer.d.ts +15 -4
- package/srv/blockchain/signing/submission-finalizer.js +201 -69
- package/srv/blockchain/stored-chain.js +1 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +1 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +34 -54
- package/srv/blockchain/transaction-presence.d.ts +5 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.js +1 -1
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -1
- package/srv/blockchain/wallet-worker/build-request.js +25 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +1 -1
- package/srv/blockchain/wallet-worker/job-store.d.ts +17 -7
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +2 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +2 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +42 -32
- package/srv/cardano-agent-service.cds +11 -12
- package/srv/cardano-agent-service.js +2 -0
- package/srv/cardano-backend-service.cds +34 -1
- package/srv/cardano-backend-service.js +20 -17
- package/srv/cardano-indexer-service.cds +153 -12
- package/srv/cardano-indexer-service.js +175 -29
- package/srv/cardano-service.cds +67 -3
- package/srv/cardano-service.js +132 -67
- package/srv/cardano-sign-service.cds +30 -20
- package/srv/cardano-sign-service.js +13 -10
- package/srv/cardano-tx-service.cds +15 -1
- package/srv/cardano-tx-service.js +4 -1
- package/srv/cardano-worker-service.cds +16 -7
- package/srv/cardano-worker-service.js +31 -22
- package/srv/cbor/parse.js +11 -34
- package/srv/config.d.ts +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +9 -14
- package/srv/server.js +32 -316
- package/srv/utils/agent-access.d.ts +9 -0
- package/srv/utils/agent-access.js +67 -0
- package/srv/utils/agent-grants-config.d.ts +0 -17
- package/srv/utils/agent-grants-config.js +6 -81
- package/srv/utils/agent-grants.d.ts +6 -19
- package/srv/utils/agent-grants.js +69 -130
- package/srv/utils/const.d.ts +4 -0
- package/srv/utils/const.js +5 -1
- package/srv/utils/db-indexes.js +11 -3
- package/srv/utils/error-codes.d.ts +4 -0
- package/srv/utils/error-codes.js +4 -0
- package/srv/utils/errors.d.ts +6 -0
- package/srv/utils/errors.js +23 -1
- package/srv/utils/liveness.js +2 -5
- package/srv/utils/mappers.d.ts +5 -7
- package/srv/utils/mappers.js +22 -9
- package/srv/utils/pg-order-nulls.js +4 -3
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/tx-request-parsers.d.ts +1 -1
- package/srv/utils/tx-request-parsers.js +3 -3
- package/srv/utils/tx-utils.d.ts +3 -0
- package/srv/utils/tx-utils.js +17 -3
- package/srv/utils/types.d.ts +16 -3
- package/scripts/migrate-txseq.mjs +0 -138
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -13
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +0 -71
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -15
- package/srv/blockchain/transaction-building/caller-datums.js +0 -133
- package/srv/cbor/redeemer-tag-patch.d.ts +0 -3
- package/srv/cbor/redeemer-tag-patch.js +0 -61
- package/srv/utils/legacy-service-paths.d.ts +0 -11
- package/srv/utils/legacy-service-paths.js +0 -58
package/srv/utils/db-indexes.js
CHANGED
|
@@ -20,6 +20,9 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
20
20
|
{ name: 'odatano_cardano_blocks_height_desc', table: 'odatano_cardano_Blocks', columns: 'height DESC', postgres: 'height DESC NULLS LAST' },
|
|
21
21
|
{ name: 'odatano_cardano_blocks_slot', table: 'odatano_cardano_Blocks', columns: 'slot' },
|
|
22
22
|
{ name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
|
|
23
|
+
// the first block at or after a point in time (`$filter=time ge …&$orderby=time`)
|
|
24
|
+
// CAP sorts a nullable column as ASC NULLS FIRST or DESC NULLS LAST on PostgreSQL; this serves both
|
|
25
|
+
{ name: 'odatano_cardano_blocks_time', table: 'odatano_cardano_Blocks', columns: 'time', postgres: 'time NULLS FIRST' },
|
|
23
26
|
// block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
|
|
24
27
|
{ name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
|
|
25
28
|
// Transactions of a block in block order (rollback `blockHash in`, GetBlockTransactions)
|
|
@@ -29,6 +32,7 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
29
32
|
{ name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
|
|
30
33
|
// GetMetadataByTxHash, rollback
|
|
31
34
|
{ name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
|
|
35
|
+
{ name: 'odatano_cardano_transactionmetadata_label_seq', table: 'odatano_cardano_TransactionMetadata', columns: 'id, txSeq' },
|
|
32
36
|
// rollback `txHash in` (key is unit, txHash); newest events of a unit
|
|
33
37
|
{ name: 'odatano_cardano_assethistory_tx', table: 'odatano_cardano_AssetHistory', columns: 'txHash' },
|
|
34
38
|
{ name: 'odatano_cardano_assethistory_unit_height', table: 'odatano_cardano_AssetHistory', columns: 'unit, blockHeight DESC', postgres: 'unit, blockHeight DESC NULLS LAST' },
|
|
@@ -54,6 +58,8 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
54
58
|
{ name: 'odatano_cardano_transactioncertificates_pool', table: 'odatano_cardano_TransactionCertificates', columns: 'poolId' },
|
|
55
59
|
{ name: 'odatano_cardano_transactioncertificates_drep', table: 'odatano_cardano_TransactionCertificates', columns: 'drepId' },
|
|
56
60
|
{ name: 'odatano_cardano_transactionwithdrawals_stake', table: 'odatano_cardano_TransactionWithdrawals', columns: 'stakeAddress' },
|
|
61
|
+
// all accounts of one epoch; the key starts with the stake address
|
|
62
|
+
{ name: 'odatano_cardano_accountepochsnapshots_epoch', table: 'odatano_cardano_AccountEpochSnapshots', columns: 'epoch' },
|
|
57
63
|
// crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
|
|
58
64
|
{ name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
|
|
59
65
|
// newest created and spent rows of an address (latest transactions from the UTxO set)
|
|
@@ -65,13 +71,15 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
65
71
|
{ name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
|
|
66
72
|
{ name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
|
|
67
73
|
{ name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
|
|
68
|
-
// wallet worker:
|
|
69
|
-
{ name: '
|
|
70
|
-
{ name: '
|
|
74
|
+
// wallet worker: jobs by status, and the jobs of one wallet with its next due job in dispatch order
|
|
75
|
+
{ name: 'odatano_cardano_cardanowalletjobs_status', table: 'odatano_cardano_CardanoWalletJobs', columns: 'status' },
|
|
76
|
+
{ name: 'odatano_cardano_cardanowalletjobs_next', table: 'odatano_cardano_CardanoWalletJobs', columns: 'walletId, status, priority, createdAt' },
|
|
71
77
|
]);
|
|
72
78
|
/** Indexes a composite entry above replaces; dropped at start. */
|
|
73
79
|
exports.DROPPED_DB_INDEXES = Object.freeze([
|
|
74
80
|
'odatano_cardano_transactions_block',
|
|
81
|
+
'odatano_cardano_cardanowalletjobs_due',
|
|
82
|
+
'odatano_cardano_cardanowalletjobs_wallet',
|
|
75
83
|
]);
|
|
76
84
|
/** The statement for one entry; exported so tests pin the shape. */
|
|
77
85
|
function indexStatement(spec, kind = 'sqlite') {
|
|
@@ -18,10 +18,14 @@ export declare const ERROR_CODES: {
|
|
|
18
18
|
readonly CHAIN_POINT_MISMATCH: "ODATANO_CHAIN_POINT_MISMATCH";
|
|
19
19
|
/** 409: transaction already submitted (duplicate / replay). */
|
|
20
20
|
readonly TX_ALREADY_SUBMITTED: "ODATANO_TX_ALREADY_SUBMITTED";
|
|
21
|
+
/** 409: the idempotency key belongs to a job with another request. */
|
|
22
|
+
readonly IDEMPOTENCY_KEY_CONFLICT: "ODATANO_IDEMPOTENCY_KEY_CONFLICT";
|
|
21
23
|
/** 429: provider rate limit hit. */
|
|
22
24
|
readonly PROVIDER_RATE_LIMITED: "ODATANO_PROVIDER_RATE_LIMITED";
|
|
23
25
|
/** 503: Cardano data provider unavailable. */
|
|
24
26
|
readonly PROVIDER_UNAVAILABLE: "ODATANO_PROVIDER_UNAVAILABLE";
|
|
27
|
+
/** 503: a submit failed without a verdict; the transaction may still reach the chain. */
|
|
28
|
+
readonly SUBMIT_OUTCOME_UNKNOWN: "ODATANO_SUBMIT_OUTCOME_UNKNOWN";
|
|
25
29
|
/** 500: unexpected internal error. */
|
|
26
30
|
readonly INTERNAL_ERROR: "ODATANO_INTERNAL_ERROR";
|
|
27
31
|
/** 503: HSM device or session not available. */
|
package/srv/utils/error-codes.js
CHANGED
|
@@ -21,10 +21,14 @@ exports.ERROR_CODES = {
|
|
|
21
21
|
CHAIN_POINT_MISMATCH: 'ODATANO_CHAIN_POINT_MISMATCH',
|
|
22
22
|
/** 409: transaction already submitted (duplicate / replay). */
|
|
23
23
|
TX_ALREADY_SUBMITTED: 'ODATANO_TX_ALREADY_SUBMITTED',
|
|
24
|
+
/** 409: the idempotency key belongs to a job with another request. */
|
|
25
|
+
IDEMPOTENCY_KEY_CONFLICT: 'ODATANO_IDEMPOTENCY_KEY_CONFLICT',
|
|
24
26
|
/** 429: provider rate limit hit. */
|
|
25
27
|
PROVIDER_RATE_LIMITED: 'ODATANO_PROVIDER_RATE_LIMITED',
|
|
26
28
|
/** 503: Cardano data provider unavailable. */
|
|
27
29
|
PROVIDER_UNAVAILABLE: 'ODATANO_PROVIDER_UNAVAILABLE',
|
|
30
|
+
/** 503: a submit failed without a verdict; the transaction may still reach the chain. */
|
|
31
|
+
SUBMIT_OUTCOME_UNKNOWN: 'ODATANO_SUBMIT_OUTCOME_UNKNOWN',
|
|
28
32
|
/** 500: unexpected internal error. */
|
|
29
33
|
INTERNAL_ERROR: 'ODATANO_INTERNAL_ERROR',
|
|
30
34
|
/** 503: HSM device or session not available. */
|
package/srv/utils/errors.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export declare class AllBackendsFailedError extends BackendError {
|
|
|
57
57
|
constructor(errors: BackendError[], originalError?: unknown, skipped?: string[]);
|
|
58
58
|
}
|
|
59
59
|
export declare function isNotFoundOnAllBackends(err: unknown): boolean;
|
|
60
|
+
export declare function isSubmitRejection(err: unknown): boolean;
|
|
61
|
+
/** A submit failed without a verdict (503). The record stays open and the server keeps resolving it. */
|
|
62
|
+
export declare class SubmitOutcomeUnknownError extends BackendError {
|
|
63
|
+
readonly txHash: string;
|
|
64
|
+
constructor(txHash: string, originalError?: unknown);
|
|
65
|
+
}
|
|
60
66
|
/** Simplified shape of HTTP errors from various client libraries. */
|
|
61
67
|
export interface HttpErrorLike {
|
|
62
68
|
message?: string;
|
package/srv/utils/errors.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ChainSyncStalledError = exports.ChainSyncClosedError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ChainPointMismatchError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
|
|
3
|
+
exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ChainSyncStalledError = exports.ChainSyncClosedError = exports.ConfigError = exports.HsmError = exports.SubmitOutcomeUnknownError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ChainPointMismatchError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
|
|
4
4
|
exports.isNotFoundOnAllBackends = isNotFoundOnAllBackends;
|
|
5
|
+
exports.isSubmitRejection = isSubmitRejection;
|
|
5
6
|
exports.isPostgrestServerErrorCode = isPostgrestServerErrorCode;
|
|
6
7
|
exports.getErrorStatus = getErrorStatus;
|
|
7
8
|
exports.getErrorMessage = getErrorMessage;
|
|
@@ -139,6 +140,27 @@ function isNotFoundOnAllBackends(err) {
|
|
|
139
140
|
&& err.errors.length > 0
|
|
140
141
|
&& err.errors.every((e) => e instanceof NotFoundError || e.statusCode === 404);
|
|
141
142
|
}
|
|
143
|
+
function isBackendVerdict(err) {
|
|
144
|
+
return err instanceof BackendError && !(err instanceof AllBackendsFailedError)
|
|
145
|
+
&& err.statusCode >= 400 && err.statusCode < 500 && err.statusCode !== 429;
|
|
146
|
+
}
|
|
147
|
+
// True when every backend that was asked refused the transaction itself. A timeout, a 5xx or a
|
|
148
|
+
// rate limit is no verdict: the transaction may have been accepted before the answer was lost.
|
|
149
|
+
function isSubmitRejection(err) {
|
|
150
|
+
if (err instanceof AllBackendsFailedError)
|
|
151
|
+
return err.errors.length > 0 && err.errors.every(isBackendVerdict);
|
|
152
|
+
return isBackendVerdict(err);
|
|
153
|
+
}
|
|
154
|
+
/** A submit failed without a verdict (503). The record stays open and the server keeps resolving it. */
|
|
155
|
+
class SubmitOutcomeUnknownError extends BackendError {
|
|
156
|
+
txHash;
|
|
157
|
+
constructor(txHash, originalError) {
|
|
158
|
+
const cause = originalError instanceof Error ? ` (${originalError.message})` : '';
|
|
159
|
+
super(`Submit of transaction ${txHash} got no verdict${cause}. It may still reach the chain: read its status before sending a replacement.`, 503, error_codes_1.ERROR_CODES.SUBMIT_OUTCOME_UNKNOWN, undefined, originalError);
|
|
160
|
+
this.txHash = txHash;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.SubmitOutcomeUnknownError = SubmitOutcomeUnknownError;
|
|
142
164
|
// PostgreSQL error classes that mean a provider-side fault. Koios returns them as HTTP 400.
|
|
143
165
|
// Client-input classes such as 22 stay 4xx.
|
|
144
166
|
const PG_SERVER_ERROR_CODE_CLASSES = ['08', '42', '53', '57', '58', 'XX'];
|
package/srv/utils/liveness.js
CHANGED
|
@@ -6,8 +6,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
};
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.buildLiveness = buildLiveness;
|
|
9
|
-
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const config_1 = require("../config");
|
|
11
11
|
const processStartedAt = Date.now();
|
|
12
12
|
let cachedVersion = null;
|
|
13
13
|
function packageVersion() {
|
|
@@ -24,15 +24,12 @@ function packageVersion() {
|
|
|
24
24
|
return cachedVersion;
|
|
25
25
|
}
|
|
26
26
|
function buildLiveness(now = new Date()) {
|
|
27
|
-
const requires = (cds_1.default.env?.requires ?? {});
|
|
28
|
-
const core = (requires['odatano-core'] ?? {});
|
|
29
|
-
const network = String(core.network || process.env.NETWORK || 'preview');
|
|
30
27
|
return {
|
|
31
28
|
status: 'alive',
|
|
32
29
|
timestamp: now.toISOString(),
|
|
33
30
|
uptime: Math.max(0, Math.floor((now.getTime() - processStartedAt) / 1000)),
|
|
34
31
|
version: packageVersion(),
|
|
35
|
-
network,
|
|
32
|
+
network: (0, config_1.configuredNetworkName)(),
|
|
36
33
|
};
|
|
37
34
|
}
|
|
38
35
|
//# sourceMappingURL=liveness.js.map
|
package/srv/utils/mappers.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Transaction as TransactionProviderData, Address as AddressProviderData, UTxO as UtxosProviderData, TxInputLine as TxInputProviderData, TxOutputLine as TxOutputProviderData, TxCertificate as TxCertificateProviderData, TxWithdrawal as TxWithdrawalProviderData, TxRedeemer as TxRedeemerProviderData, TxDatum as TxDatumProviderData, Amount as AmountProviderData, NetworkInformation as NetworkInfoProviderData, BlockData as BlockProviderData, EpochData as EpochProviderData, MetadataLabelTx as MetadataLabelTxProviderData, PoolData as PoolProviderData, DrepData as DrepProviderData, AccountData as AccountProviderData, AssetInfo as AssetInfoProviderData, AssetHistoryEntry as AssetHistoryEntryProviderData, TxBuildResult as TransactionBuildResult, LedgerProtocolParameters as ProtocolParameters } from './types';
|
|
2
|
-
import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as AddressUTxORow, UTxOAsset as UTxOAssetRow, Transaction as TransactionRow, TransactionInput as TransactionInputRow,
|
|
2
|
+
import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as AddressUTxORow, UTxOAsset as UTxOAssetRow, Transaction as TransactionRow, TransactionInput as TransactionInputRow, TransactionOutput as TransactionOutputRow, TransactionOutputAsset as TransactionOutputAssetRow, TransactionCertificate as TransactionCertificateRow, TransactionWithdrawal as TransactionWithdrawalRow, TransactionRedeemer as TransactionRedeemerRow, TransactionDatum as TransactionDatumRow, NetworkInformation as NetworkInfoRow, TransactionMetadata as TransactionMetadataRow, Block as BlockRow, Epoch as EpochRow, Pool as PoolRow, Drep as DrepRow, PoolEpochSnapshot as PoolEpochSnapshotRow, DrepEpochSnapshot as DrepEpochSnapshotRow, Asset as AssetRow, AssetHistory as AssetHistoryRow, Account as AccountRow, LedgerProtocolParameter as ProtocolParameterRow, AddressTransaction as AddressTransactionRow } from '#cds-models/CardanoODataService';
|
|
3
|
+
import type { TransactionInputAssetCopy as TransactionInputAssetRow } from '#cds-models/odatano/cardano';
|
|
3
4
|
import type { TransactionBuild as TransactionBuildRow, TransactionBuildInput as TransactionBuildInputRow, TransactionBuildOutput as TransactionBuildOutputRow, TransactionSubmission as TransactionSubmissionRow, AddressTransactionBuild as AddressTransactionBuildRow } from '#cds-models/CardanoTransactionService';
|
|
4
5
|
import type { AddressSigningRequest as AddressSigningRequestRow } from '#cds-models/CardanoSignService';
|
|
5
6
|
import type { Request } from '@sap/cds';
|
|
@@ -8,10 +9,8 @@ export declare const TX_SEQ_SLOT_FACTOR = 65536;
|
|
|
8
9
|
export declare function txSeqOf(slot: number, txIndex: number): number;
|
|
9
10
|
/** Provider transaction to TransactionRow. */
|
|
10
11
|
export declare function mapTransaction(providerTx: TransactionProviderData): TransactionRow;
|
|
11
|
-
|
|
12
|
-
export declare function
|
|
13
|
-
/** Provider transaction input assets to TransactionInputAssetRows. */
|
|
14
|
-
export declare function mapTransactionInputAssets(txSeq: number, inputs: TxInputProviderData[]): TransactionInputAssetRow[];
|
|
12
|
+
export declare function mapTransactionInputs(txSeq: number, txInputs: TxInputProviderData[], byReference?: boolean): TransactionInputRow[];
|
|
13
|
+
export declare function mapTransactionInputAssets(txSeq: number, inputs: TxInputProviderData[], byReference?: boolean): TransactionInputAssetRow[];
|
|
15
14
|
/** Normalized certificates to TransactionCertificateRows, one per (certIndex, kind). */
|
|
16
15
|
export declare function mapTransactionCertificates(txHash: string, certificates: TxCertificateProviderData[]): TransactionCertificateRow[];
|
|
17
16
|
/** Normalized withdrawals to TransactionWithdrawalRows, one per reward account. */
|
|
@@ -50,8 +49,7 @@ export declare function mapNetworkInfo(providerNetworkData: NetworkInfoProviderD
|
|
|
50
49
|
export declare function mapBlock(providerBlockData: BlockProviderData, epochData?: EpochRow): BlockRow;
|
|
51
50
|
/** Provider epoch to EpochRow. */
|
|
52
51
|
export declare function mapEpoch(providerEpochData: EpochProviderData): EpochRow;
|
|
53
|
-
|
|
54
|
-
export declare function mapTransactionMetadata(providerLabels: MetadataLabelTxProviderData[]): TransactionMetadataRow[];
|
|
52
|
+
export declare function mapTransactionMetadata(providerLabels: MetadataLabelTxProviderData[], txSeq?: number | null): TransactionMetadataRow[];
|
|
55
53
|
export declare function metadataIdFor(label: string | number): number | string | null;
|
|
56
54
|
/** Where an epoch snapshot came from; `hash` is the block the ledger state was read at (Ogmios only). */
|
|
57
55
|
export interface SnapshotOrigin {
|
package/srv/utils/mappers.js
CHANGED
|
@@ -81,15 +81,16 @@ function mapTransaction(providerTx) {
|
|
|
81
81
|
slot: providerTx.slot ?? null,
|
|
82
82
|
txIndex: providerTx.index ?? null,
|
|
83
83
|
fee: providerTx.fee != null ? providerTx.fee : '0',
|
|
84
|
-
deposit: providerTx.deposit
|
|
84
|
+
deposit: providerTx.deposit ?? null,
|
|
85
85
|
size: providerTx.size ?? null,
|
|
86
86
|
hasInputs: hasInputs,
|
|
87
87
|
hasOutputs: hasOutputs,
|
|
88
88
|
hasMetadata: hasMetadata,
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// Provider transaction inputs to TransactionInputRows, keyed by position in the tx.
|
|
92
|
+
// byReference: an input whose spent output is stored points at it and keeps no copy of its assets.
|
|
93
|
+
function mapTransactionInputs(txSeq, txInputs, byReference = false) {
|
|
93
94
|
return txInputs.map((input, idx) => {
|
|
94
95
|
// Position in this tx's inputs; input.outputIndex is the spent UTxO's index, not a key here
|
|
95
96
|
const inputIndex = idx;
|
|
@@ -109,6 +110,7 @@ function mapTransactionInputs(txSeq, txInputs) {
|
|
|
109
110
|
// outpoint of the consumed UTxO
|
|
110
111
|
spentTxHash: input.txHash || null,
|
|
111
112
|
spentOutputIndex: Number.isInteger(input.outputIndex) ? input.outputIndex : null,
|
|
113
|
+
spentTxSeq: byReference ? input.spentTxSeq ?? null : null,
|
|
112
114
|
isCollateral: Boolean(input.isCollateral),
|
|
113
115
|
isReference: Boolean(input.isReference),
|
|
114
116
|
hasAddresses: hasAddress,
|
|
@@ -116,12 +118,13 @@ function mapTransactionInputs(txSeq, txInputs) {
|
|
|
116
118
|
};
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
// Provider transaction input assets to the rows kept as a copy. Must be called with the same
|
|
122
|
+
// byReference as mapTransactionInputs: an input that points at its output gets no copy.
|
|
123
|
+
function mapTransactionInputAssets(txSeq, inputs, byReference = false) {
|
|
121
124
|
return inputs.flatMap((input, idx) => {
|
|
122
125
|
// must match mapTransactionInputs
|
|
123
126
|
const inputIndex = idx;
|
|
124
|
-
if (!Array.isArray(input.amount))
|
|
127
|
+
if (!Array.isArray(input.amount) || (byReference && input.spentTxSeq != null))
|
|
125
128
|
return [];
|
|
126
129
|
return input.amount.map(a => {
|
|
127
130
|
const { policyId, assetName } = parseAssetUnit(a.unit);
|
|
@@ -171,7 +174,7 @@ function ledgerInputOrder(inputs) {
|
|
|
171
174
|
return [...inputs].sort((a, b) => rank(a) - rank(b) || compareOutRef(a, b));
|
|
172
175
|
}
|
|
173
176
|
// The transaction as the ledger applied it, identical for every source. After a phase-2 failure only
|
|
174
|
-
// collateral and reference inputs
|
|
177
|
+
// collateral and reference inputs and the collateral return remain: no mint, certificate or withdrawal.
|
|
175
178
|
// Unknown validity keeps what the source reported.
|
|
176
179
|
function ledgerView(tx) {
|
|
177
180
|
const inputs = ledgerInputOrder(tx.inputs ?? []);
|
|
@@ -183,6 +186,8 @@ function ledgerView(tx) {
|
|
|
183
186
|
inputs: failed ? inputs.filter(i => i.isCollateral || i.isReference) : inputs,
|
|
184
187
|
outputs: (tx.outputs ?? []).filter(o => (failed ? o.isCollateral : !o.isCollateral)),
|
|
185
188
|
mint: failed ? undefined : tx.mint,
|
|
189
|
+
certificates: failed && tx.certificates ? [] : tx.certificates,
|
|
190
|
+
withdrawals: failed && tx.withdrawals ? [] : tx.withdrawals,
|
|
186
191
|
};
|
|
187
192
|
}
|
|
188
193
|
/** Normalized redeemers to TransactionRedeemerRows, keyed (tx, purpose, index). */
|
|
@@ -454,8 +459,9 @@ function mapEpoch(providerEpochData) {
|
|
|
454
459
|
activeStake: providerEpochData.active_stake,
|
|
455
460
|
};
|
|
456
461
|
}
|
|
457
|
-
|
|
458
|
-
|
|
462
|
+
// Provider metadata labels to TransactionMetadataRows; non-uint64 labels are skipped.
|
|
463
|
+
// Without txSeq the column is left out, so an UPSERT keeps a stored position.
|
|
464
|
+
function mapTransactionMetadata(providerLabels, txSeq) {
|
|
459
465
|
const rows = [];
|
|
460
466
|
for (const lbl of providerLabels) {
|
|
461
467
|
const id = metadataIdFor(lbl.label);
|
|
@@ -471,6 +477,7 @@ function mapTransactionMetadata(providerLabels) {
|
|
|
471
477
|
label: lbl.label.toString(),
|
|
472
478
|
// Ogmios exposes numeric metadata as bigint; written as exact number tokens
|
|
473
479
|
payload: lbl.json !== undefined ? (0, deep_json_1.stringifyJson)(lbl.json) : null,
|
|
480
|
+
...(txSeq == null ? {} : { txSeq }),
|
|
474
481
|
});
|
|
475
482
|
}
|
|
476
483
|
return rows;
|
|
@@ -556,6 +563,12 @@ function mapPool(providerPoolData, max_age) {
|
|
|
556
563
|
margin: Number(providerPoolData.margin),
|
|
557
564
|
fixedCost: providerPoolData.fixedCost,
|
|
558
565
|
rewardAccount: providerPoolData.rewardAccount,
|
|
566
|
+
metadataUrl: providerPoolData.metadataUrl ?? null,
|
|
567
|
+
metadataHash: providerPoolData.metadataHash ?? null,
|
|
568
|
+
name: providerPoolData.name ?? null,
|
|
569
|
+
ticker: providerPoolData.ticker ?? null,
|
|
570
|
+
homepage: providerPoolData.homepage ?? null,
|
|
571
|
+
description: providerPoolData.description ?? null,
|
|
559
572
|
validFrom,
|
|
560
573
|
validTo,
|
|
561
574
|
};
|
|
@@ -10,6 +10,7 @@ exports.installPostgresOrderNulls = installPostgresOrderNulls;
|
|
|
10
10
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
11
11
|
const logger = cds_1.default.log('PgOrderNulls');
|
|
12
12
|
const INSTALLED = Symbol.for('odatano.pgOrderNulls');
|
|
13
|
+
const dbKind = () => String((cds_1.default.env?.requires?.db)?.kind ?? '');
|
|
13
14
|
/** Strips the null placement from the rendered terms whose column cannot be NULL. */
|
|
14
15
|
function stripNullsForNotNull(orderBy, rendered) {
|
|
15
16
|
return rendered.map((sql, i) => {
|
|
@@ -30,8 +31,7 @@ function installPostgresOrderNulls() {
|
|
|
30
31
|
}
|
|
31
32
|
catch (err) {
|
|
32
33
|
// No loadable Postgres driver: silent unless the database is Postgres.
|
|
33
|
-
|
|
34
|
-
if (dbKind === 'postgres')
|
|
34
|
+
if (dbKind() === 'postgres')
|
|
35
35
|
logger.warn(`@cap-js/postgres/lib/PostgresService not loadable, ORDER BY keeps the NULLS clause: ${String(err?.message ?? err)}`);
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
@@ -47,7 +47,8 @@ function installPostgresOrderNulls() {
|
|
|
47
47
|
return stripNullsForNotNull(orderBy, orig.call(this, orderBy, ...rest));
|
|
48
48
|
};
|
|
49
49
|
proto[INSTALLED] = true;
|
|
50
|
-
|
|
50
|
+
if (dbKind() === 'postgres')
|
|
51
|
+
logger.info('ORDER BY on Postgres: NULLS clause dropped for key and NOT NULL columns');
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
53
54
|
//# sourceMappingURL=pg-order-nulls.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Readiness {
|
|
2
|
+
status: 'ready' | 'not_ready';
|
|
3
|
+
timestamp: string;
|
|
4
|
+
/** The client, the indexer and the transaction builder exist. */
|
|
5
|
+
context: boolean;
|
|
6
|
+
/** The database answers and holds the schema. */
|
|
7
|
+
database: boolean;
|
|
8
|
+
/** The HSM session is connected; null when no HSM is configured. */
|
|
9
|
+
hsm: boolean | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildReadiness(parts: Pick<Readiness, 'context' | 'hsm'>, now?: Date): Promise<Readiness>;
|
|
12
|
+
//# sourceMappingURL=readiness.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Readiness body for getReadiness(): whether this instance can serve requests. It names the
|
|
3
|
+
// missing part and nothing else, so an anonymous probe learns no configuration detail.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.buildReadiness = buildReadiness;
|
|
9
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
|
+
const tx_utils_1 = require("./tx-utils");
|
|
11
|
+
const { SELECT } = cds_1.default.ql;
|
|
12
|
+
const PROBE_TIMEOUT_MS = 3000;
|
|
13
|
+
async function databaseAnswers() {
|
|
14
|
+
if (!cds_1.default.db)
|
|
15
|
+
return false;
|
|
16
|
+
try {
|
|
17
|
+
await (0, tx_utils_1.detachedTx)('readiness probe', (db) => db.run(SELECT.one.from('odatano.cardano.CardanoSyncState').columns('ID')), PROBE_TIMEOUT_MS);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function buildReadiness(parts, now = new Date()) {
|
|
25
|
+
const database = await databaseAnswers();
|
|
26
|
+
const ready = parts.context && database && parts.hsm !== false;
|
|
27
|
+
return { status: ready ? 'ready' : 'not_ready', timestamp: now.toISOString(), context: parts.context, database, hsm: parts.hsm };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=readiness.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import cds from '@sap/cds';
|
|
2
|
+
/** The parts of a linked model definition this module reads. */
|
|
3
|
+
interface Typed {
|
|
4
|
+
items?: Typed;
|
|
5
|
+
elements?: Record<string, Typed | undefined>;
|
|
6
|
+
_target?: Typed;
|
|
7
|
+
scale?: number;
|
|
8
|
+
returns?: Typed;
|
|
9
|
+
actions?: Record<string, Typed | undefined>;
|
|
10
|
+
}
|
|
11
|
+
/** `value` with every Int64 and Decimal number as text; `value` itself when it holds none. */
|
|
12
|
+
export declare function numbersAsText(def: Typed | undefined, value: unknown): unknown;
|
|
13
|
+
export declare function answerNumbersAsText(srv: cds.Service): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=result-numbers.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.numbersAsText = numbersAsText;
|
|
7
|
+
exports.answerNumbersAsText = answerNumbersAsText;
|
|
8
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
9
|
+
/** Text of an Int64 or Decimal value, in the form the database returns it. */
|
|
10
|
+
function numberText(def, value) {
|
|
11
|
+
const scale = def instanceof cds_1.default.builtin.classes.Decimal ? def.scale : undefined;
|
|
12
|
+
if (scale === undefined)
|
|
13
|
+
return String(value);
|
|
14
|
+
return typeof value === 'bigint' ? (scale ? `${value}.${'0'.repeat(scale)}` : String(value)) : value.toFixed(scale);
|
|
15
|
+
}
|
|
16
|
+
/** `value` with every Int64 and Decimal number as text; `value` itself when it holds none. */
|
|
17
|
+
function numbersAsText(def, value) {
|
|
18
|
+
if (!def || value === null || value === undefined)
|
|
19
|
+
return value;
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
// a to-many association has no `items`: its rows are rows of the target
|
|
22
|
+
const of = def.items ?? def;
|
|
23
|
+
let copy;
|
|
24
|
+
value.forEach((item, i) => {
|
|
25
|
+
const text = numbersAsText(of, item);
|
|
26
|
+
// Object.assign keeps what CAP adds to a result array, such as $count
|
|
27
|
+
if (text !== item)
|
|
28
|
+
(copy ??= Object.assign([], value))[i] = text;
|
|
29
|
+
});
|
|
30
|
+
return copy ?? value;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
33
|
+
const { Int64, Decimal } = cds_1.default.builtin.classes;
|
|
34
|
+
return def instanceof Int64 || def instanceof Decimal ? numberText(def, value) : value;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value !== 'object')
|
|
37
|
+
return value;
|
|
38
|
+
const elements = (def._target ?? def).elements;
|
|
39
|
+
if (!elements)
|
|
40
|
+
return value;
|
|
41
|
+
let copy;
|
|
42
|
+
for (const [name, item] of Object.entries(value)) {
|
|
43
|
+
const text = numbersAsText(elements[name], item);
|
|
44
|
+
if (text !== item)
|
|
45
|
+
(copy ??= { ...value })[name] = text;
|
|
46
|
+
}
|
|
47
|
+
return copy ?? value;
|
|
48
|
+
}
|
|
49
|
+
// Answers reads and operations of `srv` with Int64 and Decimal as text. The result is replaced,
|
|
50
|
+
// never changed in place: a handler may answer with an object that other code keeps counting in.
|
|
51
|
+
function answerNumbersAsText(srv) {
|
|
52
|
+
srv.after('*', (_results, req) => {
|
|
53
|
+
const target = req.target;
|
|
54
|
+
const operations = (target?.actions ?? srv.actions);
|
|
55
|
+
const def = req.event === 'READ' ? target : operations?.[req.event]?.returns;
|
|
56
|
+
const text = numbersAsText(def, req.results);
|
|
57
|
+
if (text !== req.results)
|
|
58
|
+
req.reply(text);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=result-numbers.js.map
|
|
@@ -46,7 +46,7 @@ export declare function parseExtraOutputs(extraOutputsJson: string | undefined):
|
|
|
46
46
|
error?: string;
|
|
47
47
|
};
|
|
48
48
|
/** Entries keep their order. `outputsJson` also accepts `datumHash`. */
|
|
49
|
-
export declare function parseOutputList(json: string | undefined, fieldName: 'extraOutputsJson' | 'outputsJson'): {
|
|
49
|
+
export declare function parseOutputList(json: string | undefined, fieldName: 'extraOutputsJson' | 'outputsJson', maxEntries?: number): {
|
|
50
50
|
parsed?: ParsedExtraOutput[];
|
|
51
51
|
error?: string;
|
|
52
52
|
};
|
|
@@ -104,7 +104,7 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
104
104
|
return parseOutputList(extraOutputsJson, 'extraOutputsJson');
|
|
105
105
|
}
|
|
106
106
|
/** Entries keep their order. `outputsJson` also accepts `datumHash`. */
|
|
107
|
-
function parseOutputList(json, fieldName) {
|
|
107
|
+
function parseOutputList(json, fieldName, maxEntries = exports.MAX_EXTRA_OUTPUTS) {
|
|
108
108
|
if (!json)
|
|
109
109
|
return { parsed: undefined };
|
|
110
110
|
const name = fieldName.replace(/Json$/, '');
|
|
@@ -115,8 +115,8 @@ function parseOutputList(json, fieldName) {
|
|
|
115
115
|
return { error: `${fieldName} must be a JSON array` };
|
|
116
116
|
if (jsonResult.parsed.length === 0)
|
|
117
117
|
return { parsed: undefined };
|
|
118
|
-
if (jsonResult.parsed.length >
|
|
119
|
-
return { error: `${fieldName} exceeds maximum of ${
|
|
118
|
+
if (jsonResult.parsed.length > maxEntries) {
|
|
119
|
+
return { error: `${fieldName} exceeds maximum of ${maxEntries} entries` };
|
|
120
120
|
}
|
|
121
121
|
const out = [];
|
|
122
122
|
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
package/srv/utils/tx-utils.d.ts
CHANGED
|
@@ -2,5 +2,8 @@ import cds from '@sap/cds';
|
|
|
2
2
|
/** Default acquire budget for detached bookkeeping transactions. */
|
|
3
3
|
export declare const DETACHED_TX_TIMEOUT_MS = 10000;
|
|
4
4
|
export declare function runWithoutAmbientTx<T>(fn: () => Promise<T>): Promise<T>;
|
|
5
|
+
/** True once the transaction has taken its database connection. */
|
|
6
|
+
export declare function holdsConnection(tx: unknown): boolean;
|
|
7
|
+
export declare function readOutside<T>(tx: cds.Transaction, read: (db: cds.Transaction) => Promise<T>): Promise<T>;
|
|
5
8
|
export declare function detachedTx<T>(label: string, fn: (db: cds.Transaction) => Promise<T>, timeoutMs?: number): Promise<T>;
|
|
6
9
|
//# sourceMappingURL=tx-utils.d.ts.map
|
package/srv/utils/tx-utils.js
CHANGED
|
@@ -5,25 +5,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DETACHED_TX_TIMEOUT_MS = void 0;
|
|
7
7
|
exports.runWithoutAmbientTx = runWithoutAmbientTx;
|
|
8
|
+
exports.holdsConnection = holdsConnection;
|
|
9
|
+
exports.readOutside = readOutside;
|
|
8
10
|
exports.detachedTx = detachedTx;
|
|
9
11
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
12
|
const errors_1 = require("./errors");
|
|
13
|
+
const config_1 = require("../config");
|
|
11
14
|
const error_codes_1 = require("./error-codes");
|
|
12
15
|
// @cap-js/sqlite has a single pooled connection held by the request transaction.
|
|
13
16
|
// A new root transaction awaited by that request would wait forever.
|
|
14
17
|
const logger = cds_1.default.log('tx-utils');
|
|
15
18
|
/** Default acquire budget for detached bookkeeping transactions. */
|
|
16
19
|
exports.DETACHED_TX_TIMEOUT_MS = 10_000;
|
|
17
|
-
/** ODATANO_DETACHED_TX_TIMEOUT_MS override, else the default; read per call. */
|
|
18
20
|
function effectiveTimeoutMs() {
|
|
19
|
-
|
|
20
|
-
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : exports.DETACHED_TX_TIMEOUT_MS;
|
|
21
|
+
return (0, config_1.detachedTxTimeoutMs)() ?? exports.DETACHED_TX_TIMEOUT_MS;
|
|
21
22
|
}
|
|
22
23
|
// Clears cds.context so inner db.run calls use short transactions instead of joining an ambient one.
|
|
23
24
|
// This keeps the single SQLite connection free during long awaits.
|
|
24
25
|
function runWithoutAmbientTx(fn) {
|
|
25
26
|
return cds_1.default._with(undefined, fn);
|
|
26
27
|
}
|
|
28
|
+
/** True once the transaction has taken its database connection. */
|
|
29
|
+
function holdsConnection(tx) {
|
|
30
|
+
const state = tx;
|
|
31
|
+
return Boolean(state && (state.dbc || state.ready));
|
|
32
|
+
}
|
|
33
|
+
// Database reads that come before a provider call. An idle transaction stays idle: the read runs in
|
|
34
|
+
// a short transaction of its own, so no connection is held while the provider answers.
|
|
35
|
+
// A transaction that already holds its connection does the read itself.
|
|
36
|
+
function readOutside(tx, read) {
|
|
37
|
+
const idle = typeof tx.begin === 'function' && !holdsConnection(tx);
|
|
38
|
+
// cds.tx resolves to what the callback resolves to; its typing wraps that in a second promise
|
|
39
|
+
return idle ? runWithoutAmbientTx(async () => await cds_1.default.tx(read)) : read(tx);
|
|
40
|
+
}
|
|
27
41
|
/** Thrown inside an orphaned `cds.tx` callback after its caller already timed out. */
|
|
28
42
|
class DetachedTxAbortedError extends Error {
|
|
29
43
|
constructor(label) {
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface TxInputLine {
|
|
|
20
20
|
amount: Amount[];
|
|
21
21
|
txHash: Hex;
|
|
22
22
|
outputIndex: number;
|
|
23
|
+
spentTxSeq?: number | null;
|
|
23
24
|
dataHash?: Hex | null;
|
|
24
25
|
inlineDatum?: string | null;
|
|
25
26
|
referenceScriptHash?: Hex | null;
|
|
@@ -96,7 +97,10 @@ export interface Transaction {
|
|
|
96
97
|
index: number;
|
|
97
98
|
/** What the ledger charged: the declared fee, or on a phase-2 failure the collateral consumed. */
|
|
98
99
|
fee: Lovelace | string;
|
|
99
|
-
|
|
100
|
+
/** Deposits locked minus deposits refunded; null while the source could not tell. */
|
|
101
|
+
deposit: Lovelace | string | null;
|
|
102
|
+
/** Lovelace donated to the treasury; only set by sources that report it. */
|
|
103
|
+
treasuryDonation?: string | null;
|
|
100
104
|
/** True when phase 2 failed and only collateral was consumed. Undefined when the source does not report it. */
|
|
101
105
|
spendsCollaterals?: boolean;
|
|
102
106
|
totalCollateral?: Lovelace | string | null;
|
|
@@ -202,11 +206,11 @@ export interface AccountData {
|
|
|
202
206
|
active: boolean;
|
|
203
207
|
activeEpoch: number;
|
|
204
208
|
controlledAmount: string;
|
|
205
|
-
rewardsSum: string;
|
|
209
|
+
rewardsSum: string | null;
|
|
206
210
|
withdrawalsSum: string;
|
|
207
211
|
reservesSum: string;
|
|
208
212
|
treasurySum: string;
|
|
209
|
-
withdrawableAmount: string;
|
|
213
|
+
withdrawableAmount: string | null;
|
|
210
214
|
poolId: string | null;
|
|
211
215
|
drepId: string | null;
|
|
212
216
|
addresses: Address[];
|
|
@@ -231,6 +235,15 @@ export interface PoolData {
|
|
|
231
235
|
margin: number;
|
|
232
236
|
fixedCost: string;
|
|
233
237
|
rewardAccount: string;
|
|
238
|
+
/** URL of the metadata file as registered; null without one. */
|
|
239
|
+
metadataUrl?: string | null;
|
|
240
|
+
/** hex; blake2b-256 the registration names for that file */
|
|
241
|
+
metadataHash?: string | null;
|
|
242
|
+
/** From the metadata file; null while it is unknown or failed its checks. */
|
|
243
|
+
name?: string | null;
|
|
244
|
+
ticker?: string | null;
|
|
245
|
+
homepage?: string | null;
|
|
246
|
+
description?: string | null;
|
|
234
247
|
}
|
|
235
248
|
/** DRep information */
|
|
236
249
|
export interface DrepData {
|