@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45
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 +0 -46
- package/@cds-models/CardanoBackendService/index.d.ts +0 -10
- package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +19 -47
- package/@cds-models/CardanoSignService/index.d.ts +3 -18
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
- package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
- package/@cds-models/index.d.ts +17 -0
- package/@cds-models/index.js +2 -0
- package/@cds-models/odatano/cardano/index.d.ts +1 -34
- package/README.md +6 -6
- package/db/schema.cds +29 -44
- package/db/types.cds +22 -5
- package/package.json +3 -1
- package/scripts/migrate-slot-leader.mjs +3 -11
- package/scripts/migrate-txseq.mjs +3 -12
- package/src/index.d.ts +0 -4
- package/src/index.js +3 -5
- package/src/plugin.js +4 -8
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -10
- package/srv/blockchain/backends/blockfrost-backend.js +15 -21
- package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
- package/srv/blockchain/backends/koios-backend.d.ts +14 -147
- package/srv/blockchain/backends/koios-backend.js +40 -164
- package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
- package/srv/blockchain/backends/odatano-backend.js +11 -12
- package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
- package/srv/blockchain/backends/ogmios-backend.js +48 -175
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
- package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
- package/srv/blockchain/cardano-client.d.ts +12 -80
- package/srv/blockchain/cardano-client.js +36 -88
- package/srv/blockchain/cardano-indexer.d.ts +12 -192
- package/srv/blockchain/cardano-indexer.js +132 -222
- package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
- package/srv/blockchain/cardano-tx-builder.js +17 -34
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
- package/srv/blockchain/crawler/certificate-backfill.js +8 -22
- package/srv/blockchain/crawler/crawler.d.ts +16 -93
- package/srv/blockchain/crawler/crawler.js +85 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
- package/srv/blockchain/crawler/credential-backfill.js +6 -6
- package/srv/blockchain/crawler/hooks.d.ts +1 -5
- package/srv/blockchain/crawler/index.d.ts +0 -12
- package/srv/blockchain/crawler/index.js +6 -20
- package/srv/blockchain/crawler/sync-state.d.ts +6 -44
- package/srv/blockchain/crawler/sync-state.js +18 -53
- package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
- package/srv/blockchain/crawler/transaction-backfill.js +11 -30
- package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
- package/srv/blockchain/crawler/utxo-set-import.js +27 -53
- package/srv/blockchain/ledger-state.d.ts +10 -54
- package/srv/blockchain/ledger-state.js +11 -27
- package/srv/blockchain/pending-spends.d.ts +0 -12
- package/srv/blockchain/pending-spends.js +4 -12
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +0 -9
- package/srv/blockchain/signing/cose-verifier.js +4 -10
- package/srv/blockchain/signing/external-signer.d.ts +1 -4
- package/srv/blockchain/signing/external-signer.js +2 -8
- package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
- package/srv/blockchain/signing/hsm-signer.js +16 -28
- package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
- package/srv/blockchain/signing/signature-verifier.js +9 -19
- package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
- package/srv/blockchain/signing/submission-finalizer.js +48 -19
- package/srv/blockchain/stored-chain.d.ts +1 -14
- package/srv/blockchain/stored-chain.js +3 -8
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
- package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
- package/srv/blockchain/transaction-building/caller-datums.js +3 -9
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
- package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
- package/srv/blockchain/wallet-worker/build-request.js +6 -9
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -5
- package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
- package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
- package/srv/blockchain/wallet-worker/signers.js +3 -6
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
- package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
- package/srv/cardano-agent-service.cds +123 -146
- package/srv/cardano-agent-service.js +2 -5
- package/srv/cardano-backend-service.cds +10 -17
- package/srv/cardano-backend-service.js +7 -12
- package/srv/cardano-indexer-service.cds +35 -37
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +64 -33
- package/srv/cardano-service.cds +56 -40
- package/srv/cardano-service.js +42 -69
- package/srv/cardano-sign-service.cds +14 -23
- package/srv/cardano-sign-service.js +18 -24
- package/srv/cardano-tx-service.cds +27 -29
- package/srv/cardano-tx-service.js +60 -122
- package/srv/cardano-worker-service.cds +109 -125
- package/srv/cardano-worker-service.js +21 -31
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +6 -1
- package/srv/cbor/parse.d.ts +3 -18
- package/srv/cbor/parse.js +2 -7
- package/srv/cbor/plutus-data-json.d.ts +0 -4
- package/srv/server.d.ts +5 -36
- package/srv/server.js +30 -51
- package/srv/utils/agent-grants-config.d.ts +0 -18
- package/srv/utils/agent-grants-config.js +6 -13
- package/srv/utils/agent-grants.d.ts +14 -68
- package/srv/utils/agent-grants.js +42 -60
- package/srv/utils/agent-token-auth.d.ts +0 -5
- package/srv/utils/agent-token-auth.js +2 -5
- package/srv/utils/backend-request-handler.d.ts +1 -1
- package/srv/utils/collections.d.ts +1 -4
- package/srv/utils/collections.js +1 -4
- package/srv/utils/const.d.ts +0 -18
- package/srv/utils/const.js +7 -18
- package/srv/utils/crypto.js +3 -5
- package/srv/utils/db-indexes.d.ts +2 -0
- package/srv/utils/db-indexes.js +22 -9
- package/srv/utils/db-sanitize.d.ts +1 -8
- package/srv/utils/db-sanitize.js +3 -8
- package/srv/utils/epoch-slots.d.ts +1 -8
- package/srv/utils/epoch-slots.js +3 -8
- package/srv/utils/error-codes.d.ts +0 -4
- package/srv/utils/error-codes.js +2 -4
- package/srv/utils/errors.d.ts +2 -22
- package/srv/utils/errors.js +13 -27
- package/srv/utils/liveness.d.ts +0 -4
- package/srv/utils/liveness.js +2 -4
- package/srv/utils/mappers.d.ts +0 -37
- package/srv/utils/mappers.js +22 -39
- package/srv/utils/network-context.js +2 -4
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.js +3 -7
- package/srv/utils/pg-order-nulls.js +2 -5
- package/srv/utils/plutus-placeholders.d.ts +0 -13
- package/srv/utils/plutus-placeholders.js +6 -13
- package/srv/utils/rate-limiter.d.ts +0 -8
- package/srv/utils/rate-limiter.js +2 -4
- package/srv/utils/reference-script.d.ts +0 -18
- package/srv/utils/reference-script.js +8 -19
- package/srv/utils/service-events.d.ts +0 -4
- package/srv/utils/service-events.js +2 -4
- package/srv/utils/signing-helper.d.ts +1 -8
- package/srv/utils/signing-helper.js +3 -8
- package/srv/utils/tx-build-helper.d.ts +2 -32
- package/srv/utils/tx-build-helper.js +26 -40
- package/srv/utils/tx-request-parsers.d.ts +1 -25
- package/srv/utils/tx-request-parsers.js +10 -25
- package/srv/utils/tx-utils.d.ts +0 -8
- package/srv/utils/tx-utils.js +10 -13
- package/srv/utils/types.d.ts +2 -37
- package/srv/utils/validators.d.ts +0 -4
- package/srv/utils/validators.js +2 -4
package/srv/utils/db-indexes.js
CHANGED
|
@@ -3,14 +3,12 @@ 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.DB_INDEXES = void 0;
|
|
6
|
+
exports.DROPPED_DB_INDEXES = exports.DB_INDEXES = void 0;
|
|
7
7
|
exports.indexStatement = indexStatement;
|
|
8
8
|
exports.ensureDbIndexes = ensureDbIndexes;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* folds them like @cap-js does; failures are logged, never fatal. HANA is skipped (column store, no IF NOT EXISTS).
|
|
13
|
-
*/
|
|
9
|
+
// Secondary indexes the CDS model cannot declare, created at start. Temporal keys start with validFrom,
|
|
10
|
+
// so lookups by business key would scan without them. Failures are logged, never fatal.
|
|
11
|
+
// HANA is skipped because it has no CREATE INDEX IF NOT EXISTS.
|
|
14
12
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
15
13
|
const logger = cds_1.default.log('DbIndexes');
|
|
16
14
|
/** Every entry answers a query the service or the crawler actually runs. */
|
|
@@ -24,15 +22,16 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
24
22
|
{ name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
|
|
25
23
|
// block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
|
|
26
24
|
{ name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
|
|
27
|
-
// Transactions of a block (rollback `blockHash in`,
|
|
28
|
-
{ name: '
|
|
25
|
+
// Transactions of a block in block order (rollback `blockHash in`, GetBlockTransactions)
|
|
26
|
+
{ name: 'odatano_cardano_transactions_block_idx', table: 'odatano_cardano_Transactions', columns: 'blockHash, txIndex' },
|
|
29
27
|
{ name: 'odatano_cardano_transactions_height', table: 'odatano_cardano_Transactions', columns: 'blockHeight' },
|
|
30
28
|
// Input/output rows back to their transaction (`tx` association, stale-seq check of the crawler)
|
|
31
29
|
{ name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
|
|
32
30
|
// GetMetadataByTxHash, rollback
|
|
33
31
|
{ name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
|
|
34
|
-
// rollback `txHash in` (key is unit, txHash)
|
|
32
|
+
// rollback `txHash in` (key is unit, txHash); newest events of a unit
|
|
35
33
|
{ name: 'odatano_cardano_assethistory_tx', table: 'odatano_cardano_AssetHistory', columns: 'txHash' },
|
|
34
|
+
{ name: 'odatano_cardano_assethistory_unit_height', table: 'odatano_cardano_AssetHistory', columns: 'unit, blockHeight DESC', postgres: 'unit, blockHeight DESC NULLS LAST' },
|
|
36
35
|
// temporal entities: the business key behind validFrom
|
|
37
36
|
{ name: 'odatano_cardano_assets_unit', table: 'odatano_cardano_Assets', columns: 'unit' },
|
|
38
37
|
{ name: 'odatano_cardano_addresses_address', table: 'odatano_cardano_Addresses', columns: 'address' },
|
|
@@ -57,12 +56,22 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
57
56
|
{ name: 'odatano_cardano_transactionwithdrawals_stake', table: 'odatano_cardano_TransactionWithdrawals', columns: 'stakeAddress' },
|
|
58
57
|
// crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
|
|
59
58
|
{ name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
|
|
59
|
+
// newest created and spent rows of an address (latest transactions from the UTxO set)
|
|
60
|
+
{ name: 'odatano_cardano_ledgerutxos_address_created', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, createdSlot' },
|
|
61
|
+
{ name: 'odatano_cardano_ledgerutxos_address_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentSlot' },
|
|
60
62
|
{ name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
|
|
61
63
|
{ name: 'odatano_cardano_ledgerutxos_paycred', table: 'odatano_cardano_LedgerUTxOs', columns: 'utxo_paymentCredential, spentTxHash' },
|
|
62
64
|
{ name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
|
|
63
65
|
{ name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
|
|
64
66
|
{ name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
|
|
65
67
|
{ name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
|
|
68
|
+
// wallet worker: due jobs in dispatch order, active jobs of one wallet
|
|
69
|
+
{ name: 'odatano_cardano_cardanowalletjobs_due', table: 'odatano_cardano_CardanoWalletJobs', columns: 'status, priority, createdAt' },
|
|
70
|
+
{ name: 'odatano_cardano_cardanowalletjobs_wallet', table: 'odatano_cardano_CardanoWalletJobs', columns: 'walletId, status, createdAt' },
|
|
71
|
+
]);
|
|
72
|
+
/** Indexes a composite entry above replaces; dropped at start. */
|
|
73
|
+
exports.DROPPED_DB_INDEXES = Object.freeze([
|
|
74
|
+
'odatano_cardano_transactions_block',
|
|
66
75
|
]);
|
|
67
76
|
/** The statement for one entry; exported so tests pin the shape. */
|
|
68
77
|
function indexStatement(spec, kind = 'sqlite') {
|
|
@@ -82,6 +91,10 @@ async function ensureDbIndexes(runner = cds_1.default.db) {
|
|
|
82
91
|
logger.info('HANA: secondary indexes not created (column store, no IF NOT EXISTS)');
|
|
83
92
|
return { ensured, failed };
|
|
84
93
|
}
|
|
94
|
+
for (const name of exports.DROPPED_DB_INDEXES) {
|
|
95
|
+
await runner.run(`DROP INDEX IF EXISTS ${name}`)
|
|
96
|
+
.catch((err) => logger.warn(`index ${name} not dropped: ${String(err?.message ?? err)}`));
|
|
97
|
+
}
|
|
85
98
|
for (const spec of exports.DB_INDEXES) {
|
|
86
99
|
try {
|
|
87
100
|
await runner.run(indexStatement(spec, kind));
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strips U+0000 from every row this plugin writes: PostgreSQL cannot store NUL in `text`, and
|
|
3
|
-
* @cap-js/postgres bulk rows go through a JSON parser that rejects the NUL escape, failing the whole write.
|
|
4
|
-
*/
|
|
5
1
|
/** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
|
|
6
2
|
export declare function stripNulStrings<T>(row: T): T;
|
|
7
3
|
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
@@ -18,10 +14,7 @@ export declare function sanitizeDbRequest(req: DbWriteRequest): void;
|
|
|
18
14
|
interface HookableService {
|
|
19
15
|
before(event: string | string[], handler: (req: DbWriteRequest) => void): unknown;
|
|
20
16
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Hook the sanitizer into the database service (idempotent per instance; no-op without a db).
|
|
23
|
-
* @returns true when the hook was installed by this call
|
|
24
|
-
*/
|
|
17
|
+
/** Hooks the sanitizer into the database service once. Returns true when this call installed it. */
|
|
25
18
|
export declare function installDbSanitizer(db?: HookableService | undefined): boolean;
|
|
26
19
|
export {};
|
|
27
20
|
//# sourceMappingURL=db-sanitize.d.ts.map
|
package/srv/utils/db-sanitize.js
CHANGED
|
@@ -8,10 +8,8 @@ exports.sanitizeRows = sanitizeRows;
|
|
|
8
8
|
exports.sanitizeDbRequest = sanitizeDbRequest;
|
|
9
9
|
exports.installDbSanitizer = installDbSanitizer;
|
|
10
10
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @cap-js/postgres bulk rows go through a JSON parser that rejects the NUL escape, failing the whole write.
|
|
14
|
-
*/
|
|
11
|
+
// Strips U+0000 from every row this plugin writes. PostgreSQL cannot store NUL in text,
|
|
12
|
+
// and one NUL fails a whole bulk write.
|
|
15
13
|
/** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
|
|
16
14
|
function stripNulStrings(row) {
|
|
17
15
|
if (typeof row === 'string')
|
|
@@ -71,10 +69,7 @@ function sanitizeDbRequest(req) {
|
|
|
71
69
|
upd.data = stripNulStrings(upd.data);
|
|
72
70
|
}
|
|
73
71
|
const installed = new WeakSet();
|
|
74
|
-
/**
|
|
75
|
-
* Hook the sanitizer into the database service (idempotent per instance; no-op without a db).
|
|
76
|
-
* @returns true when the hook was installed by this call
|
|
77
|
-
*/
|
|
72
|
+
/** Hooks the sanitizer into the database service once. Returns true when this call installed it. */
|
|
78
73
|
function installDbSanitizer(db = cds_1.default.db) {
|
|
79
74
|
if (!db || typeof db.before !== 'function' || installed.has(db))
|
|
80
75
|
return false;
|
|
@@ -4,17 +4,10 @@ type EpochNetwork = keyof typeof EPOCH_CONFIG_BY_NETWORK;
|
|
|
4
4
|
export declare function epochOfSlot(network: EpochNetwork, slot: number): number;
|
|
5
5
|
/** First absolute slot of an epoch, from the network's Shelley anchor. */
|
|
6
6
|
export declare function epochStartSlot(network: EpochNetwork, epoch: number): number;
|
|
7
|
-
/**
|
|
8
|
-
* Absolute POSIX milliseconds 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
7
|
export declare function slotToPosixMs(network: EpochNetwork, slot: number): number;
|
|
12
8
|
/** Absolute POSIX seconds for a slot, rounded down. */
|
|
13
9
|
export declare function slotToPosixSeconds(network: EpochNetwork, slot: number): number;
|
|
14
|
-
/**
|
|
15
|
-
* Slot that contains a POSIX time in milliseconds.
|
|
16
|
-
* @throws RangeError for a time before the Shelley start, where slots were 20 s long.
|
|
17
|
-
*/
|
|
10
|
+
/** Slot that contains a POSIX time. Throws RangeError before Shelley, where slots were 20 s long. */
|
|
18
11
|
export declare function posixToSlot(network: EpochNetwork, posixMs: number): number;
|
|
19
12
|
export {};
|
|
20
13
|
//# sourceMappingURL=epoch-slots.d.ts.map
|
package/srv/utils/epoch-slots.js
CHANGED
|
@@ -16,10 +16,8 @@ function epochStartSlot(network, epoch) {
|
|
|
16
16
|
const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
|
|
17
17
|
return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
|
|
22
|
-
*/
|
|
19
|
+
// POSIX milliseconds for a slot, exact for Shelley-era slots.
|
|
20
|
+
// Ogmios eraStart.time is relative to system start, not a Unix timestamp.
|
|
23
21
|
function slotToPosixMs(network, slot) {
|
|
24
22
|
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
25
23
|
return genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs;
|
|
@@ -28,10 +26,7 @@ function slotToPosixMs(network, slot) {
|
|
|
28
26
|
function slotToPosixSeconds(network, slot) {
|
|
29
27
|
return Math.floor(slotToPosixMs(network, slot) / 1000);
|
|
30
28
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Slot that contains a POSIX time in milliseconds.
|
|
33
|
-
* @throws RangeError for a time before the Shelley start, where slots were 20 s long.
|
|
34
|
-
*/
|
|
29
|
+
/** Slot that contains a POSIX time. Throws RangeError before Shelley, where slots were 20 s long. */
|
|
35
30
|
function posixToSlot(network, posixMs) {
|
|
36
31
|
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
37
32
|
const shelleyStartMs = slotToPosixMs(network, const_1.EPOCH_CONFIG_BY_NETWORK[network].shelleyStartSlot);
|
|
@@ -30,10 +30,6 @@ export declare const ERROR_CODES: {
|
|
|
30
30
|
readonly HSM_SIGNING_FAILED: "ODATANO_HSM_SIGNING_FAILED";
|
|
31
31
|
/** 400: HSM signing requested but HSM not configured. */
|
|
32
32
|
readonly HSM_NOT_CONFIGURED: "ODATANO_HSM_NOT_CONFIGURED";
|
|
33
|
-
/**
|
|
34
|
-
* 503: a detached bookkeeping transaction could not acquire a pooled DB connection in time,
|
|
35
|
-
* typically because an in-process caller awaits the action while its own request tx holds the single sqlite connection.
|
|
36
|
-
*/
|
|
37
33
|
readonly NESTED_TX_TIMEOUT: "ODATANO_NESTED_TX_TIMEOUT";
|
|
38
34
|
};
|
|
39
35
|
/** Union of all error code values. */
|
package/srv/utils/error-codes.js
CHANGED
|
@@ -33,10 +33,8 @@ exports.ERROR_CODES = {
|
|
|
33
33
|
HSM_SIGNING_FAILED: 'ODATANO_HSM_SIGNING_FAILED',
|
|
34
34
|
/** 400: HSM signing requested but HSM not configured. */
|
|
35
35
|
HSM_NOT_CONFIGURED: 'ODATANO_HSM_NOT_CONFIGURED',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* typically because an in-process caller awaits the action while its own request tx holds the single sqlite connection.
|
|
39
|
-
*/
|
|
36
|
+
// 503: a detached transaction got no DB connection in time. Typical cause is an in-process caller
|
|
37
|
+
// whose own request transaction holds the single SQLite connection.
|
|
40
38
|
NESTED_TX_TIMEOUT: 'ODATANO_NESTED_TX_TIMEOUT',
|
|
41
39
|
};
|
|
42
40
|
//# sourceMappingURL=error-codes.js.map
|
package/srv/utils/errors.d.ts
CHANGED
|
@@ -22,10 +22,6 @@ export declare class TransactionValidationError extends BackendError {
|
|
|
22
22
|
export declare class ScriptValidationError extends BackendError {
|
|
23
23
|
constructor(message: string, originalError?: unknown);
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* A crawler cursor block this instance does not follow (409). A 4xx keeps its message in production,
|
|
27
|
-
* so a remote crawler receives the `CHAIN_POINT_MISMATCH:` marker it recovers on.
|
|
28
|
-
*/
|
|
29
25
|
export declare class ChainPointMismatchError extends BackendError {
|
|
30
26
|
constructor(message: string, backendName?: string);
|
|
31
27
|
}
|
|
@@ -34,10 +30,6 @@ export declare class TransactionAlreadySubmittedError extends BackendError {
|
|
|
34
30
|
readonly txHash: string;
|
|
35
31
|
constructor(txHash: string, originalError?: unknown);
|
|
36
32
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Not enough of an asset for the transaction (400). `required`/`available` are 0n when unknown;
|
|
39
|
-
* `detail` then replaces the amounts in the message.
|
|
40
|
-
*/
|
|
41
33
|
export declare class InsufficientFundsError extends BackendError {
|
|
42
34
|
readonly assetUnit: string;
|
|
43
35
|
readonly required: bigint;
|
|
@@ -64,10 +56,6 @@ export declare class AllBackendsFailedError extends BackendError {
|
|
|
64
56
|
/** @param skipped why backends were not called at all, e.g. `koios: circuit open` */
|
|
65
57
|
constructor(errors: BackendError[], originalError?: unknown, skipped?: string[]);
|
|
66
58
|
}
|
|
67
|
-
/**
|
|
68
|
-
* True when the resource is absent on every consulted backend: a NotFoundError, or an
|
|
69
|
-
* AllBackendsFailedError whose per-backend errors are all 404. A mixed result is not proof of absence.
|
|
70
|
-
*/
|
|
71
59
|
export declare function isNotFoundOnAllBackends(err: unknown): boolean;
|
|
72
60
|
/** Simplified shape of HTTP errors from various client libraries. */
|
|
73
61
|
export interface HttpErrorLike {
|
|
@@ -91,11 +79,6 @@ export declare function isPostgrestServerErrorCode(code: unknown): boolean;
|
|
|
91
79
|
export declare function getErrorStatus(err: HttpErrorLike | unknown): number;
|
|
92
80
|
/** Message of an HttpErrorLike: `response.data.error` (Koios), else `message`. */
|
|
93
81
|
export declare function getErrorMessage(err: HttpErrorLike | unknown): string;
|
|
94
|
-
/**
|
|
95
|
-
* Normalizes any backend error into a typed BackendError. An Ogmios script failure is recognised
|
|
96
|
-
* by its JSON-RPC code. Message hints are then checked in priority
|
|
97
|
-
* order (already submitted, script failure, validation, not found, rate limit) before the HTTP status.
|
|
98
|
-
*/
|
|
99
82
|
export declare function normalizeBackendError(err: unknown, backendName?: string): BackendError;
|
|
100
83
|
/** HSM operation failed (session, key access, signing). */
|
|
101
84
|
export declare class HsmError extends BackendError {
|
|
@@ -105,11 +88,7 @@ export declare class HsmError extends BackendError {
|
|
|
105
88
|
export declare class ConfigError extends Error {
|
|
106
89
|
constructor(message: string);
|
|
107
90
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Ogmios chain-sync frame that could not be parsed. Names the block (when readable from the raw
|
|
110
|
-
* text) so the crawler can fetch that one block through the paginating backend instead.
|
|
111
|
-
*/
|
|
112
|
-
/** The Ogmios chain-sync socket closed without being asked to (server-side failure or restart). */
|
|
91
|
+
/** The Ogmios chain-sync socket closed without being asked to. */
|
|
113
92
|
export declare class ChainSyncClosedError extends ProviderUnavailableError {
|
|
114
93
|
}
|
|
115
94
|
/** Chain-sync closed before delivering block `height`; the crawler fetches it over pagination. */
|
|
@@ -117,6 +96,7 @@ export declare class ChainSyncStalledError extends BackendError {
|
|
|
117
96
|
readonly height: number;
|
|
118
97
|
constructor(height: number, reason: string);
|
|
119
98
|
}
|
|
99
|
+
/** Unparsable chain-sync frame. Names the block when readable, so the crawler can fetch it by pagination. */
|
|
120
100
|
export declare class ChainSyncFrameError extends BackendError {
|
|
121
101
|
readonly height: number | null;
|
|
122
102
|
readonly id: string | null;
|
package/srv/utils/errors.js
CHANGED
|
@@ -27,6 +27,9 @@ class BackendError extends Error {
|
|
|
27
27
|
this.target = target;
|
|
28
28
|
this.name = this.constructor.name;
|
|
29
29
|
Error.captureStackTrace(this, this.constructor);
|
|
30
|
+
// CAP copies enumerable fields into the response body; these stay server-side
|
|
31
|
+
for (const key of ['name', 'backendName', 'originalError'])
|
|
32
|
+
Object.defineProperty(this, key, { enumerable: false });
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
exports.BackendError = BackendError;
|
|
@@ -51,10 +54,8 @@ class ScriptValidationError extends BackendError {
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
exports.ScriptValidationError = ScriptValidationError;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* so a remote crawler receives the `CHAIN_POINT_MISMATCH:` marker it recovers on.
|
|
57
|
-
*/
|
|
57
|
+
// 409: the crawler cursor block is not on this instance's chain. A 4xx keeps its message in
|
|
58
|
+
// production, so a remote crawler receives the `CHAIN_POINT_MISMATCH:` marker it recovers on.
|
|
58
59
|
class ChainPointMismatchError extends BackendError {
|
|
59
60
|
constructor(message, backendName) {
|
|
60
61
|
super(message, 409, error_codes_1.ERROR_CODES.CHAIN_POINT_MISMATCH, backendName);
|
|
@@ -70,10 +71,7 @@ class TransactionAlreadySubmittedError extends BackendError {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
exports.TransactionAlreadySubmittedError = TransactionAlreadySubmittedError;
|
|
73
|
-
|
|
74
|
-
* Not enough of an asset for the transaction (400). `required`/`available` are 0n when unknown;
|
|
75
|
-
* `detail` then replaces the amounts in the message.
|
|
76
|
-
*/
|
|
74
|
+
// 400: not enough of an asset. The amounts are 0n when unknown, and then detail replaces them in the message.
|
|
77
75
|
class InsufficientFundsError extends BackendError {
|
|
78
76
|
assetUnit;
|
|
79
77
|
required;
|
|
@@ -133,10 +131,7 @@ class AllBackendsFailedError extends BackendError {
|
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
exports.AllBackendsFailedError = AllBackendsFailedError;
|
|
136
|
-
|
|
137
|
-
* True when the resource is absent on every consulted backend: a NotFoundError, or an
|
|
138
|
-
* AllBackendsFailedError whose per-backend errors are all 404. A mixed result is not proof of absence.
|
|
139
|
-
*/
|
|
134
|
+
// True when every consulted backend answered 404. A mixed result is not proof of absence.
|
|
140
135
|
function isNotFoundOnAllBackends(err) {
|
|
141
136
|
if (err instanceof NotFoundError)
|
|
142
137
|
return true;
|
|
@@ -144,11 +139,8 @@ function isNotFoundOnAllBackends(err) {
|
|
|
144
139
|
&& err.errors.length > 0
|
|
145
140
|
&& err.errors.every((e) => e instanceof NotFoundError || e.statusCode === 404);
|
|
146
141
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
* 08 connection, 42 undefined object, 53 resources, 57 operator intervention, 58 system, XX internal.
|
|
150
|
-
* Client-input classes (22 etc.) stay 4xx.
|
|
151
|
-
*/
|
|
142
|
+
// PostgreSQL error classes that mean a provider-side fault. Koios returns them as HTTP 400.
|
|
143
|
+
// Client-input classes such as 22 stay 4xx.
|
|
152
144
|
const PG_SERVER_ERROR_CODE_CLASSES = ['08', '42', '53', '57', '58', 'XX'];
|
|
153
145
|
/** True when a PostgREST error body's `code` denotes a provider-side SQL fault. */
|
|
154
146
|
function isPostgrestServerErrorCode(code) {
|
|
@@ -172,11 +164,8 @@ function getErrorMessage(err) {
|
|
|
172
164
|
const OGMIOS_SCRIPT_EXECUTION_FAILURE = 3010;
|
|
173
165
|
/** Characters of Ogmios error data kept in a message. */
|
|
174
166
|
const OGMIOS_DETAIL_MAX = 2000;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* by its JSON-RPC code. Message hints are then checked in priority
|
|
178
|
-
* order (already submitted, script failure, validation, not found, rate limit) before the HTTP status.
|
|
179
|
-
*/
|
|
167
|
+
// Turns any backend error into a typed BackendError. Ogmios script failures are matched by JSON-RPC code.
|
|
168
|
+
// Message hints are checked in a fixed priority order before the HTTP status.
|
|
180
169
|
function normalizeBackendError(err, backendName) {
|
|
181
170
|
if (err instanceof BackendError)
|
|
182
171
|
return err;
|
|
@@ -314,11 +303,7 @@ class ConfigError extends Error {
|
|
|
314
303
|
}
|
|
315
304
|
}
|
|
316
305
|
exports.ConfigError = ConfigError;
|
|
317
|
-
/**
|
|
318
|
-
* Ogmios chain-sync frame that could not be parsed. Names the block (when readable from the raw
|
|
319
|
-
* text) so the crawler can fetch that one block through the paginating backend instead.
|
|
320
|
-
*/
|
|
321
|
-
/** The Ogmios chain-sync socket closed without being asked to (server-side failure or restart). */
|
|
306
|
+
/** The Ogmios chain-sync socket closed without being asked to. */
|
|
322
307
|
class ChainSyncClosedError extends ProviderUnavailableError {
|
|
323
308
|
}
|
|
324
309
|
exports.ChainSyncClosedError = ChainSyncClosedError;
|
|
@@ -331,6 +316,7 @@ class ChainSyncStalledError extends BackendError {
|
|
|
331
316
|
}
|
|
332
317
|
}
|
|
333
318
|
exports.ChainSyncStalledError = ChainSyncStalledError;
|
|
319
|
+
/** Unparsable chain-sync frame. Names the block when readable, so the crawler can fetch it by pagination. */
|
|
334
320
|
class ChainSyncFrameError extends BackendError {
|
|
335
321
|
height;
|
|
336
322
|
id;
|
package/srv/utils/liveness.d.ts
CHANGED
package/srv/utils/liveness.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* never touches app context, backends or DB, so it answers while those initialize or fail.
|
|
5
|
-
*/
|
|
2
|
+
// Liveness body for getLiveness(). It reports process facts only and never touches
|
|
3
|
+
// backends or the DB, so it answers while those start or fail.
|
|
6
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
6
|
};
|
package/srv/utils/mappers.d.ts
CHANGED
|
@@ -24,17 +24,7 @@ export declare function compareOutRef(a: {
|
|
|
24
24
|
txHash: string;
|
|
25
25
|
outputIndex: number;
|
|
26
26
|
}): number;
|
|
27
|
-
/**
|
|
28
|
-
* Inputs of a transaction in the order chain-sync reports them: regular, collateral, reference,
|
|
29
|
-
* each sorted like the ledger's input sets. `inputIndex` and spend-redeemer indices rely on it.
|
|
30
|
-
*/
|
|
31
27
|
export declare function ledgerInputOrder(inputs: TxInputProviderData[]): TxInputProviderData[];
|
|
32
|
-
/**
|
|
33
|
-
* The transaction as the ledger applied it, the same for every source: inputs in ledger order;
|
|
34
|
-
* after a phase-2 failure only collateral and reference inputs, the collateral return as the only
|
|
35
|
-
* output and no mint; otherwise no collateral return (never produced). Unknown validity
|
|
36
|
-
* (`spendsCollaterals` undefined) keeps what the source reported.
|
|
37
|
-
*/
|
|
38
28
|
export declare function ledgerView<T extends TransactionProviderData>(tx: T): T;
|
|
39
29
|
/** Normalized redeemers to TransactionRedeemerRows, keyed (tx, purpose, index). */
|
|
40
30
|
export declare function mapTransactionRedeemers(txHash: string, redeemers: TxRedeemerProviderData[]): TransactionRedeemerRow[];
|
|
@@ -62,11 +52,6 @@ export declare function mapBlock(providerBlockData: BlockProviderData, epochData
|
|
|
62
52
|
export declare function mapEpoch(providerEpochData: EpochProviderData): EpochRow;
|
|
63
53
|
/** Provider metadata labels to TransactionMetadataRows; non-uint64 labels are skipped. */
|
|
64
54
|
export declare function mapTransactionMetadata(providerLabels: MetadataLabelTxProviderData[]): TransactionMetadataRow[];
|
|
65
|
-
/**
|
|
66
|
-
* uint64 metadata label to the int64 `TransactionMetadata.id` key: labels >= 2^63 wrap via two's complement,
|
|
67
|
-
* values beyond 2^53 are passed as a decimal string (CAP accepts strings for Integer64).
|
|
68
|
-
* @returns the key, or null when the label is not a non-negative integer
|
|
69
|
-
*/
|
|
70
55
|
export declare function metadataIdFor(label: string | number): number | string | null;
|
|
71
56
|
/** Where an epoch snapshot came from; `hash` is the block the ledger state was read at (Ogmios only). */
|
|
72
57
|
export interface SnapshotOrigin {
|
|
@@ -87,17 +72,7 @@ export declare function mapDrepSnapshot(providerDrepData: DrepProviderData, epoc
|
|
|
87
72
|
export declare function mapPool(providerPoolData: PoolProviderData, max_age: number): PoolRow;
|
|
88
73
|
/** Canonical asset info to a temporal AssetRow valid for `max_age` ms; on-chain metadata is JSON-stringified. */
|
|
89
74
|
export declare function mapAsset(providerAssetInfo: AssetInfoProviderData, max_age: number): AssetRow;
|
|
90
|
-
/**
|
|
91
|
-
* Fixed validity stamp for a crawler-written bare `Assets` row: epoch zero, so the row is born expired
|
|
92
|
-
* (hidden by CAP's temporal filter) and its `(validFrom, unit)` key never collides with a mapAsset() slice.
|
|
93
|
-
*/
|
|
94
75
|
export declare const BARE_ASSET_STAMP = "1970-01-01T00:00:00.000Z";
|
|
95
|
-
/**
|
|
96
|
-
* Bare AssetRow from the unit alone (policyId, assetNameHex, decoded name, CIP-14 fingerprint), no provider call.
|
|
97
|
-
* Stamped `validTo === validFrom` with the fixed sentinel: hidden from OData reads, so the first keyed read
|
|
98
|
-
* still misses and the lazy path enriches it; one idempotent row per unit inside the crawler's block tx.
|
|
99
|
-
* @returns the row, or null when the unit is not a native asset unit
|
|
100
|
-
*/
|
|
101
76
|
export declare function mapBareAsset(unit: string): AssetRow | null;
|
|
102
77
|
/** Asset history events to non-temporal AssetHistoryRows (immutable, keyed on unit + txHash). */
|
|
103
78
|
export declare function mapAssetHistory(entries: AssetHistoryEntryProviderData[]): AssetHistoryRow[];
|
|
@@ -129,15 +104,7 @@ export declare function mapTransactionSubmission(signedTxCbor: string, txHash: s
|
|
|
129
104
|
export declare function mapAddressSigningRequest(addr: string, signingRequestId: string): AddressSigningRequestRow;
|
|
130
105
|
/** Address to transaction-build association row. */
|
|
131
106
|
export declare function mapAddressTransactionBuild(addr: string, buildId: string): AddressTransactionBuildRow;
|
|
132
|
-
/**
|
|
133
|
-
* Cost models to number arrays in canonical Plutus parameter order. V3 goes through toCostModelArrV3
|
|
134
|
-
* (canonical keys, padded to 297); for V1/V2 alphabetical key order is the canonical order.
|
|
135
|
-
*/
|
|
136
107
|
export declare function normalizeCostModels(raw: Record<string, unknown>): Record<string, number[]>;
|
|
137
|
-
/**
|
|
138
|
-
* Asset name (hex bytes) to its display string; the hex is returned unchanged for invalid UTF-8 or
|
|
139
|
-
* names containing U+0000 (PostgreSQL rejects NUL in `text`). `assetNameHex` always keeps the exact bytes.
|
|
140
|
-
*/
|
|
141
108
|
export declare function decodeAssetName(hex: string): string;
|
|
142
109
|
/** CIP-14 fingerprint: bech32("asset", blake2b_160(policyId_bytes + assetName_bytes)). */
|
|
143
110
|
export declare function computeCip14Fingerprint(policyIdHex: string, assetNameHex: string): string;
|
|
@@ -156,10 +123,6 @@ export interface DecodedAddress {
|
|
|
156
123
|
/** Network nibble of the header (1 = mainnet, 0 = testnets); null when not a Shelley address. */
|
|
157
124
|
networkId: number | null;
|
|
158
125
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Decode the CIP-19 Shelley address header: type, script flag and, for base addresses, the embedded
|
|
161
|
-
* stake credential as a reward account. Byron (base58) and unparseable input yield `byron` / `unknown`.
|
|
162
|
-
*/
|
|
163
126
|
export declare function decodeShelleyAddress(address: string): DecodedAddress;
|
|
164
127
|
/** Payment credential (hex) of a bech32 address; null for Byron, reward and unresolved ('') addresses. */
|
|
165
128
|
export declare function paymentCredentialOf(address: string | null | undefined): string | null;
|
package/srv/utils/mappers.js
CHANGED
|
@@ -164,20 +164,15 @@ function compareOutRef(a, b) {
|
|
|
164
164
|
const ha = a.txHash.toLowerCase(), hb = b.txHash.toLowerCase();
|
|
165
165
|
return ha < hb ? -1 : ha > hb ? 1 : a.outputIndex - b.outputIndex;
|
|
166
166
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
* each sorted like the ledger's input sets. `inputIndex` and spend-redeemer indices rely on it.
|
|
170
|
-
*/
|
|
167
|
+
// Inputs in chain-sync order: regular, collateral, reference, each sorted like the ledger's sets.
|
|
168
|
+
// inputIndex and spend-redeemer indices rely on this order.
|
|
171
169
|
function ledgerInputOrder(inputs) {
|
|
172
170
|
const rank = (i) => (i.isReference ? 2 : i.isCollateral ? 1 : 0);
|
|
173
171
|
return [...inputs].sort((a, b) => rank(a) - rank(b) || compareOutRef(a, b));
|
|
174
172
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
* output and no mint; otherwise no collateral return (never produced). Unknown validity
|
|
179
|
-
* (`spendsCollaterals` undefined) keeps what the source reported.
|
|
180
|
-
*/
|
|
173
|
+
// The transaction as the ledger applied it, identical for every source. After a phase-2 failure only
|
|
174
|
+
// collateral and reference inputs remain and the collateral return is the only output.
|
|
175
|
+
// Unknown validity keeps what the source reported.
|
|
181
176
|
function ledgerView(tx) {
|
|
182
177
|
const inputs = ledgerInputOrder(tx.inputs ?? []);
|
|
183
178
|
if (tx.spendsCollaterals === undefined)
|
|
@@ -466,7 +461,7 @@ function mapTransactionMetadata(providerLabels) {
|
|
|
466
461
|
const id = metadataIdFor(lbl.label);
|
|
467
462
|
if (id === null) {
|
|
468
463
|
// a NaN key would fail the whole bulk write on PostgreSQL
|
|
469
|
-
logger.warn(`Metadata label ${JSON.stringify(lbl.label)} of tx ${lbl.txHash} is not a uint64
|
|
464
|
+
logger.warn(`Metadata label ${JSON.stringify(lbl.label)} of tx ${lbl.txHash} is not a uint64, row skipped`);
|
|
470
465
|
continue;
|
|
471
466
|
}
|
|
472
467
|
rows.push({
|
|
@@ -480,11 +475,8 @@ function mapTransactionMetadata(providerLabels) {
|
|
|
480
475
|
}
|
|
481
476
|
return rows;
|
|
482
477
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
* values beyond 2^53 are passed as a decimal string (CAP accepts strings for Integer64).
|
|
486
|
-
* @returns the key, or null when the label is not a non-negative integer
|
|
487
|
-
*/
|
|
478
|
+
// Maps a uint64 metadata label to the int64 id key. Labels >= 2^63 wrap by two's complement.
|
|
479
|
+
// Values beyond 2^53 are returned as a decimal string. Null when the label is no non-negative integer.
|
|
488
480
|
function metadataIdFor(label) {
|
|
489
481
|
let big;
|
|
490
482
|
if (typeof label === 'number') {
|
|
@@ -590,6 +582,8 @@ function mapAsset(providerAssetInfo, max_age) {
|
|
|
590
582
|
registryName: providerAssetInfo.registryName,
|
|
591
583
|
registryTicker: providerAssetInfo.registryTicker,
|
|
592
584
|
registryDecimals: providerAssetInfo.registryDecimals,
|
|
585
|
+
// the registry value until the caller resolves a CIP-68 reference datum
|
|
586
|
+
decimals: providerAssetInfo.registryDecimals,
|
|
593
587
|
registryDescription: providerAssetInfo.registryDescription,
|
|
594
588
|
registryUrl: providerAssetInfo.registryUrl,
|
|
595
589
|
registryLogo: providerAssetInfo.registryLogo,
|
|
@@ -597,17 +591,11 @@ function mapAsset(providerAssetInfo, max_age) {
|
|
|
597
591
|
validTo,
|
|
598
592
|
};
|
|
599
593
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
* (hidden by CAP's temporal filter) and its `(validFrom, unit)` key never collides with a mapAsset() slice.
|
|
603
|
-
*/
|
|
594
|
+
// Epoch-zero stamp for bare Assets rows. The row is born expired and hidden by the temporal filter,
|
|
595
|
+
// and its key never collides with an enriched row.
|
|
604
596
|
exports.BARE_ASSET_STAMP = '1970-01-01T00:00:00.000Z';
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
* Stamped `validTo === validFrom` with the fixed sentinel: hidden from OData reads, so the first keyed read
|
|
608
|
-
* still misses and the lazy path enriches it; one idempotent row per unit inside the crawler's block tx.
|
|
609
|
-
* @returns the row, or null when the unit is not a native asset unit
|
|
610
|
-
*/
|
|
597
|
+
// Asset row built from the unit alone, without a provider call. Its stamp hides it from reads, so the
|
|
598
|
+
// first keyed read still misses and the lazy path enriches it. Null for a non-asset unit.
|
|
611
599
|
function mapBareAsset(unit) {
|
|
612
600
|
// same unit definition isAssetUnit() enforces on the API
|
|
613
601
|
if (!const_1.ASSET_UNIT_REGEX.test(unit))
|
|
@@ -629,6 +617,7 @@ function mapBareAsset(unit) {
|
|
|
629
617
|
registryName: null,
|
|
630
618
|
registryTicker: null,
|
|
631
619
|
registryDecimals: null,
|
|
620
|
+
decimals: null,
|
|
632
621
|
registryDescription: null,
|
|
633
622
|
registryUrl: null,
|
|
634
623
|
registryLogo: null,
|
|
@@ -691,7 +680,7 @@ function mapAccount(providerAccountData, max_age) {
|
|
|
691
680
|
/** Rejects the OData request for a BackendError; unknown errors are logged and answered as a sanitized 500. */
|
|
692
681
|
function mapError(req, err, ctx) {
|
|
693
682
|
if (err instanceof errors_1.BackendError) {
|
|
694
|
-
return req.reject(err.statusCode, fmt(err.code, ctx, err.message), err.target);
|
|
683
|
+
return req.reject({ status: err.statusCode, code: err.code, message: fmt(err.code, ctx, err.message), target: err.target });
|
|
695
684
|
}
|
|
696
685
|
const internalMsg = err instanceof Error ? err.message : String(err);
|
|
697
686
|
logger.error({ error: internalMsg }, `Unexpected error in ${ctx}`);
|
|
@@ -819,10 +808,8 @@ function mapAddressTransactionBuild(addr, buildId) {
|
|
|
819
808
|
//-----------------------------------------------------------------------
|
|
820
809
|
// Helper Functions
|
|
821
810
|
//-----------------------------------------------------------------------
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
* (canonical keys, padded to 297); for V1/V2 alphabetical key order is the canonical order.
|
|
825
|
-
*/
|
|
811
|
+
// Cost models as number arrays in canonical Plutus parameter order.
|
|
812
|
+
// For V1 and V2 the alphabetical key order is the canonical order.
|
|
826
813
|
function normalizeCostModels(raw) {
|
|
827
814
|
const result = {};
|
|
828
815
|
for (const [key, value] of Object.entries(raw)) {
|
|
@@ -855,10 +842,8 @@ function hexToUtf8(hex) {
|
|
|
855
842
|
}
|
|
856
843
|
// ignoreBOM: a leading U+FEFF is part of the asset name's bytes and must survive the round trip
|
|
857
844
|
const strictUtf8 = new node_util_1.TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
* names containing U+0000 (PostgreSQL rejects NUL in `text`). `assetNameHex` always keeps the exact bytes.
|
|
861
|
-
*/
|
|
845
|
+
// Display string for a hex asset name. Invalid UTF-8 or names with U+0000 return the hex unchanged,
|
|
846
|
+
// because PostgreSQL rejects NUL in text.
|
|
862
847
|
function decodeAssetName(hex) {
|
|
863
848
|
if (!hex)
|
|
864
849
|
return hex;
|
|
@@ -911,10 +896,8 @@ function credentialToStakeAddress(credentialHex, isScript, network) {
|
|
|
911
896
|
const hrp = network === 'mainnet' ? 'stake' : 'stake_test';
|
|
912
897
|
return bech32_1.bech32.encode(hrp, bech32_1.bech32.toWords(payload), 120);
|
|
913
898
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
* stake credential as a reward account. Byron (base58) and unparseable input yield `byron` / `unknown`.
|
|
917
|
-
*/
|
|
899
|
+
// Decodes the CIP-19 address header. Base addresses also yield the stake credential as a reward account.
|
|
900
|
+
// Byron addresses yield type byron, unparsable input yields unknown.
|
|
918
901
|
function decodeShelleyAddress(address) {
|
|
919
902
|
const none = { type: 'unknown', isScript: false, stakeAddress: null, paymentCredential: null, networkId: null };
|
|
920
903
|
if (typeof address !== 'string' || !address.length)
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setActiveNetwork = setActiveNetwork;
|
|
4
4
|
exports.getActiveNetwork = getActiveNetwork;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* without importing `server.ts`. Set by `initializeAppContext`, `null` before bootstrap.
|
|
8
|
-
*/
|
|
5
|
+
// Holds the active network so validators can read it without importing server.ts.
|
|
6
|
+
// Null before bootstrap.
|
|
9
7
|
let active = null;
|
|
10
8
|
/** Record the active network. Pass `null` to clear (shutdown/reset). */
|
|
11
9
|
function setActiveNetwork(n) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Request } from '@sap/cds';
|
|
2
|
+
/** A page of a list operation. The CDS model range-checks `limit` and `skip` before the handler runs. */
|
|
3
|
+
export interface Page {
|
|
4
|
+
limit: number;
|
|
5
|
+
skip: number;
|
|
6
|
+
}
|
|
7
|
+
/** The page a request asks for, with the operation's default limit when none is given. */
|
|
8
|
+
export declare function pageOf(data: {
|
|
9
|
+
limit?: number | null;
|
|
10
|
+
skip?: number | null;
|
|
11
|
+
}, defaultLimit: number): Page;
|
|
12
|
+
/** The rows of one page out of a list that is already in its final order. */
|
|
13
|
+
export declare function pageRows<T>(rows: T[], page: Page): T[];
|
|
14
|
+
/** Rows sorted by a string key; a fixed order keeps pages stable across calls. */
|
|
15
|
+
export declare function byKey<T>(rows: T[], keyOf: (row: T) => string): T[];
|
|
16
|
+
/** UTxOs in output-reference order: tx hash, then output index. */
|
|
17
|
+
export declare function byOutRef<T extends {
|
|
18
|
+
hash?: string | null;
|
|
19
|
+
index?: number | null;
|
|
20
|
+
}>(rows: T[]): T[];
|
|
21
|
+
/** Newest first. Koios rows carry only a time, Blockfrost rows only a height; the tx hash breaks ties. */
|
|
22
|
+
export declare function sortAssetHistory<T extends {
|
|
23
|
+
blockHeight?: number | null;
|
|
24
|
+
blockTime?: number | null;
|
|
25
|
+
txHash?: string | null;
|
|
26
|
+
}>(rows: T[]): T[];
|
|
27
|
+
/** Operations over a provider's newest rows reach at most this far. */
|
|
28
|
+
export declare const LATEST_WINDOW = 100;
|
|
29
|
+
/** Page over the newest LATEST_WINDOW rows; a page reaching past them is a 400. */
|
|
30
|
+
export declare function latestWindowPage(req: Request, ctx: string, defaultLimit: number): Page;
|
|
31
|
+
//# sourceMappingURL=paging.d.ts.map
|