@odatano/core 2.0.0-rc.4 → 2.0.0-rc.41
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 +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoBackendService/index.d.ts +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
- package/@cds-models/CardanoIndexerService/index.js +25 -0
- package/@cds-models/CardanoODataService/index.d.ts +305 -7
- package/@cds-models/CardanoODataService/index.js +34 -0
- package/@cds-models/CardanoSignService/index.d.ts +28 -3
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +46 -13
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +72 -0
- package/@cds-models/index.js +12 -0
- package/@cds-models/odatano/cardano/index.d.ts +408 -7
- package/@cds-models/odatano/cardano/index.js +42 -0
- package/README.md +64 -5
- package/db/schema.cds +2297 -1633
- package/db/types.cds +114 -0
- package/package.json +27 -6
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +18 -11
- package/src/index.js +44 -14
- package/src/plugin.js +42 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +53 -162
- package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
- package/srv/blockchain/backends/cardano-backend.js +19 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +376 -235
- package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
- package/srv/blockchain/backends/odatano-backend.js +170 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
- package/srv/blockchain/backends/ogmios-backend.js +556 -201
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +87 -202
- package/srv/blockchain/cardano-client.js +210 -240
- package/srv/blockchain/cardano-indexer.d.ts +311 -242
- package/srv/blockchain/cardano-indexer.js +1238 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
- package/srv/blockchain/cardano-tx-builder.js +173 -132
- package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
- package/srv/blockchain/crawler/certificate-backfill.js +169 -0
- package/srv/blockchain/crawler/crawler.d.ts +139 -54
- package/srv/blockchain/crawler/crawler.js +478 -96
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +46 -28
- package/srv/blockchain/crawler/sync-state.js +128 -43
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
- package/srv/blockchain/crawler/utxo-set-import.js +363 -0
- package/srv/blockchain/ledger-state.d.ts +101 -0
- package/srv/blockchain/ledger-state.js +432 -0
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +14 -45
- package/srv/blockchain/signing/signature-verifier.js +73 -76
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -49
- package/srv/blockchain/stored-chain.d.ts +33 -0
- package/srv/blockchain/stored-chain.js +234 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +111 -173
- package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
- package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
- package/srv/blockchain/transaction-building/caller-datums.js +139 -0
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +43 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +18 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +244 -0
- package/srv/cardano-indexer-service.cds +201 -73
- package/srv/cardano-indexer-service.js +280 -11
- package/srv/cardano-service.cds +65 -2
- package/srv/cardano-service.js +170 -129
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +57 -184
- package/srv/cardano-tx-service.cds +439 -370
- package/srv/cardano-tx-service.js +231 -190
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/index.d.ts +1 -1
- package/srv/cbor/parse.d.ts +27 -0
- package/srv/cbor/parse.js +63 -2
- package/srv/server.d.ts +28 -86
- package/srv/server.js +132 -135
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +922 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +30 -67
- package/srv/utils/const.js +32 -72
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +94 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +20 -0
- package/srv/utils/epoch-slots.js +43 -0
- package/srv/utils/error-codes.d.ts +20 -73
- package/srv/utils/error-codes.js +19 -70
- package/srv/utils/errors.d.ts +50 -177
- package/srv/utils/errors.js +94 -218
- package/srv/utils/legacy-service-paths.d.ts +11 -0
- package/srv/utils/legacy-service-paths.js +58 -0
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +40 -0
- package/srv/utils/mappers.d.ts +128 -214
- package/srv/utils/mappers.js +354 -299
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +62 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +56 -0
- package/srv/utils/plutus-placeholders.d.ts +23 -16
- package/srv/utils/plutus-placeholders.js +63 -27
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +6 -16
- package/srv/utils/signing-helper.js +36 -60
- package/srv/utils/tx-build-helper.d.ts +28 -93
- package/srv/utils/tx-build-helper.js +75 -124
- package/srv/utils/tx-request-parsers.d.ts +101 -28
- package/srv/utils/tx-request-parsers.js +410 -43
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +252 -179
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
|
@@ -0,0 +1,94 @@
|
|
|
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.DB_INDEXES = void 0;
|
|
7
|
+
exports.indexStatement = indexStatement;
|
|
8
|
+
exports.ensureDbIndexes = ensureDbIndexes;
|
|
9
|
+
/**
|
|
10
|
+
* Secondary indexes the CDS model cannot declare (temporal keys start with `validFrom`, so business-key
|
|
11
|
+
* lookups would scan). Created at start with CREATE INDEX IF NOT EXISTS, unquoted identifiers so Postgres
|
|
12
|
+
* folds them like @cap-js does; failures are logged, never fatal. HANA is skipped (column store, no IF NOT EXISTS).
|
|
13
|
+
*/
|
|
14
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
15
|
+
const logger = cds_1.default.log('DbIndexes');
|
|
16
|
+
/** Every entry answers a query the service or the crawler actually runs. */
|
|
17
|
+
exports.DB_INDEXES = Object.freeze([
|
|
18
|
+
// Blocks: latest (ORDER BY height DESC), byHeight, crawler `height in`, rollback `slot >`, epoch filters
|
|
19
|
+
{ name: 'odatano_cardano_blocks_height', table: 'odatano_cardano_Blocks', columns: 'height' },
|
|
20
|
+
// CAP renders `$orderby=height desc` as DESC NULLS LAST, which the plain ASC NULLS LAST
|
|
21
|
+
// index cannot serve backwards; the plain one stays for ASC and equality.
|
|
22
|
+
{ name: 'odatano_cardano_blocks_height_desc', table: 'odatano_cardano_Blocks', columns: 'height DESC', postgres: 'height DESC NULLS LAST' },
|
|
23
|
+
{ name: 'odatano_cardano_blocks_slot', table: 'odatano_cardano_Blocks', columns: 'slot' },
|
|
24
|
+
{ name: 'odatano_cardano_blocks_epoch', table: 'odatano_cardano_Blocks', columns: 'epochNumber' },
|
|
25
|
+
// block counts per pool (Pools.blocksEpoch / blocksMinted from crawled blocks)
|
|
26
|
+
{ name: 'odatano_cardano_blocks_slotleader', table: 'odatano_cardano_Blocks', columns: 'slotLeader, slot' },
|
|
27
|
+
// Transactions of a block (rollback `blockHash in`, OData filters by block / height)
|
|
28
|
+
{ name: 'odatano_cardano_transactions_block', table: 'odatano_cardano_Transactions', columns: 'blockHash' },
|
|
29
|
+
{ name: 'odatano_cardano_transactions_height', table: 'odatano_cardano_Transactions', columns: 'blockHeight' },
|
|
30
|
+
// Input/output rows back to their transaction (`tx` association, stale-seq check of the crawler)
|
|
31
|
+
{ name: 'odatano_cardano_transactions_txseq', table: 'odatano_cardano_Transactions', columns: 'txSeq' },
|
|
32
|
+
// GetMetadataByTxHash, rollback
|
|
33
|
+
{ name: 'odatano_cardano_transactionmetadata_tx', table: 'odatano_cardano_TransactionMetadata', columns: 'tx_hash' },
|
|
34
|
+
// rollback `txHash in` (key is unit, txHash)
|
|
35
|
+
{ name: 'odatano_cardano_assethistory_tx', table: 'odatano_cardano_AssetHistory', columns: 'txHash' },
|
|
36
|
+
// temporal entities: the business key behind validFrom
|
|
37
|
+
{ name: 'odatano_cardano_assets_unit', table: 'odatano_cardano_Assets', columns: 'unit' },
|
|
38
|
+
{ name: 'odatano_cardano_addresses_address', table: 'odatano_cardano_Addresses', columns: 'address' },
|
|
39
|
+
{ name: 'odatano_cardano_addressutxos_address', table: 'odatano_cardano_AddressUTxOs', columns: 'address_address' },
|
|
40
|
+
{ name: 'odatano_cardano_addressassets_address', table: 'odatano_cardano_AddressAssets', columns: 'address_address' },
|
|
41
|
+
{ name: 'odatano_cardano_utxoassets_address', table: 'odatano_cardano_UTxOAssets', columns: 'utxo_address_address' },
|
|
42
|
+
{ name: 'odatano_cardano_addresstransactions_tx', table: 'odatano_cardano_AddressTransactions', columns: 'tx_hash' },
|
|
43
|
+
{ name: 'odatano_cardano_accounts_stake', table: 'odatano_cardano_Accounts', columns: 'stakeAddress' },
|
|
44
|
+
{ name: 'odatano_cardano_pools_poolid', table: 'odatano_cardano_Pools', columns: 'poolId' },
|
|
45
|
+
{ name: 'odatano_cardano_dreps_drepid', table: 'odatano_cardano_Dreps', columns: 'drepId' },
|
|
46
|
+
// agent token lane: one lookup by token hash per request
|
|
47
|
+
{ name: 'odatano_cardano_cardanoagentgrants_token', table: 'odatano_cardano_CardanoAgentGrants', columns: 'tokenHash' },
|
|
48
|
+
// crawler-fed ledger state: "who spent this output" and delegation per stake key / pool / DRep
|
|
49
|
+
{ name: 'odatano_cardano_transactioninputs_spent', table: 'odatano_cardano_TransactionInputs', columns: 'spentTxHash, spentOutputIndex' },
|
|
50
|
+
{ name: 'odatano_cardano_transactioncertificates_stake', table: 'odatano_cardano_TransactionCertificates', columns: 'stakeAddress' },
|
|
51
|
+
{ name: 'odatano_cardano_transactioncertificates_pool', table: 'odatano_cardano_TransactionCertificates', columns: 'poolId' },
|
|
52
|
+
{ name: 'odatano_cardano_transactioncertificates_drep', table: 'odatano_cardano_TransactionCertificates', columns: 'drepId' },
|
|
53
|
+
{ name: 'odatano_cardano_transactionwithdrawals_stake', table: 'odatano_cardano_TransactionWithdrawals', columns: 'stakeAddress' },
|
|
54
|
+
// crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
|
|
55
|
+
{ name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
|
|
56
|
+
{ name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
|
|
57
|
+
{ name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
|
|
58
|
+
{ name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
|
|
59
|
+
{ name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
|
|
60
|
+
{ name: 'odatano_cardano_ledgeraddressassets_unit', table: 'odatano_cardano_LedgerAddressAssets', columns: 'unit' },
|
|
61
|
+
]);
|
|
62
|
+
/** The statement for one entry; exported so tests pin the shape. */
|
|
63
|
+
function indexStatement(spec, kind = 'sqlite') {
|
|
64
|
+
const columns = kind === 'postgres' && spec.postgres ? spec.postgres : spec.columns;
|
|
65
|
+
return `CREATE INDEX IF NOT EXISTS ${spec.name} ON ${spec.table} (${columns})`;
|
|
66
|
+
}
|
|
67
|
+
/** Creates every missing index; a failing statement is logged and skipped, the others still run. */
|
|
68
|
+
async function ensureDbIndexes(runner = cds_1.default.db) {
|
|
69
|
+
const ensured = [];
|
|
70
|
+
const failed = [];
|
|
71
|
+
if (!runner) {
|
|
72
|
+
logger.debug('no database service connected, indexes skipped');
|
|
73
|
+
return { ensured, failed };
|
|
74
|
+
}
|
|
75
|
+
const kind = String(runner.kind ?? 'sqlite');
|
|
76
|
+
if (kind === 'hana') {
|
|
77
|
+
logger.info('HANA: secondary indexes not created (column store, no IF NOT EXISTS)');
|
|
78
|
+
return { ensured, failed };
|
|
79
|
+
}
|
|
80
|
+
for (const spec of exports.DB_INDEXES) {
|
|
81
|
+
try {
|
|
82
|
+
await runner.run(indexStatement(spec, kind));
|
|
83
|
+
ensured.push(spec.name);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
failed.push(spec.name);
|
|
87
|
+
logger.warn(`index ${spec.name} on ${spec.table} not ensured: ${String(err?.message ?? err)}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (failed.length === 0)
|
|
91
|
+
logger.info(`${ensured.length} indexes ensured`);
|
|
92
|
+
return { ensured, failed };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=db-indexes.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
/** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
|
|
6
|
+
export declare function stripNulStrings<T>(row: T): T;
|
|
7
|
+
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
8
|
+
export declare function sanitizeRows<T>(rows: T[]): T[];
|
|
9
|
+
/** The slice of a db-service request the sanitizer looks at (structural, so tests can fake it). */
|
|
10
|
+
export interface DbWriteRequest {
|
|
11
|
+
query?: unknown;
|
|
12
|
+
target?: {
|
|
13
|
+
name?: string;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
/** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
|
|
17
|
+
export declare function sanitizeDbRequest(req: DbWriteRequest): void;
|
|
18
|
+
interface HookableService {
|
|
19
|
+
before(event: string | string[], handler: (req: DbWriteRequest) => void): unknown;
|
|
20
|
+
}
|
|
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
|
+
*/
|
|
25
|
+
export declare function installDbSanitizer(db?: HookableService | undefined): boolean;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=db-sanitize.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
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.stripNulStrings = stripNulStrings;
|
|
7
|
+
exports.sanitizeRows = sanitizeRows;
|
|
8
|
+
exports.sanitizeDbRequest = sanitizeDbRequest;
|
|
9
|
+
exports.installDbSanitizer = installDbSanitizer;
|
|
10
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
11
|
+
/**
|
|
12
|
+
* Strips U+0000 from every row this plugin writes: PostgreSQL cannot store NUL in `text`, and
|
|
13
|
+
* @cap-js/postgres bulk rows go through a JSON parser that rejects the NUL escape, failing the whole write.
|
|
14
|
+
*/
|
|
15
|
+
/** Remove U+0000 from every string value of the row (nested objects included); same row when unchanged. */
|
|
16
|
+
function stripNulStrings(row) {
|
|
17
|
+
if (typeof row === 'string')
|
|
18
|
+
return (row.includes('\u0000') ? row.replaceAll('\u0000', '') : row);
|
|
19
|
+
if (row === null || typeof row !== 'object' || Buffer.isBuffer(row))
|
|
20
|
+
return row;
|
|
21
|
+
if (Array.isArray(row)) {
|
|
22
|
+
let out = null;
|
|
23
|
+
for (let i = 0; i < row.length; i++) {
|
|
24
|
+
const v = stripNulStrings(row[i]);
|
|
25
|
+
if (v !== row[i]) {
|
|
26
|
+
out ??= [...row];
|
|
27
|
+
out[i] = v;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return (out ?? row);
|
|
31
|
+
}
|
|
32
|
+
let out = null;
|
|
33
|
+
for (const [k, v] of Object.entries(row)) {
|
|
34
|
+
const nv = stripNulStrings(v);
|
|
35
|
+
if (nv !== v) {
|
|
36
|
+
out ??= { ...row };
|
|
37
|
+
out[k] = nv;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return (out ?? row);
|
|
41
|
+
}
|
|
42
|
+
/** Sanitise a row array for the database; cheap when nothing needs changing. */
|
|
43
|
+
function sanitizeRows(rows) {
|
|
44
|
+
let out = null;
|
|
45
|
+
for (let i = 0; i < rows.length; i++) {
|
|
46
|
+
const r = stripNulStrings(rows[i]);
|
|
47
|
+
if (r !== rows[i]) {
|
|
48
|
+
out ??= [...rows];
|
|
49
|
+
out[i] = r;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out ?? rows;
|
|
53
|
+
}
|
|
54
|
+
/** Only this plugin's entities are rewritten; a consumer's own data is never touched. */
|
|
55
|
+
const OWN_NAMESPACE = 'odatano.cardano.';
|
|
56
|
+
/** `before` handler for the db service: strips U+0000 from INSERT / UPSERT / UPDATE rows in place. */
|
|
57
|
+
function sanitizeDbRequest(req) {
|
|
58
|
+
if (!req.target?.name?.startsWith(OWN_NAMESPACE))
|
|
59
|
+
return;
|
|
60
|
+
const q = req.query;
|
|
61
|
+
if (!q || typeof q !== 'object')
|
|
62
|
+
return;
|
|
63
|
+
const ins = q.INSERT;
|
|
64
|
+
if (ins && Array.isArray(ins.entries))
|
|
65
|
+
ins.entries = sanitizeRows(ins.entries);
|
|
66
|
+
const ups = q.UPSERT;
|
|
67
|
+
if (ups && Array.isArray(ups.entries))
|
|
68
|
+
ups.entries = sanitizeRows(ups.entries);
|
|
69
|
+
const upd = q.UPDATE;
|
|
70
|
+
if (upd?.data && typeof upd.data === 'object')
|
|
71
|
+
upd.data = stripNulStrings(upd.data);
|
|
72
|
+
}
|
|
73
|
+
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
|
+
*/
|
|
78
|
+
function installDbSanitizer(db = cds_1.default.db) {
|
|
79
|
+
if (!db || typeof db.before !== 'function' || installed.has(db))
|
|
80
|
+
return false;
|
|
81
|
+
db.before(['CREATE', 'UPSERT', 'UPDATE'], sanitizeDbRequest);
|
|
82
|
+
installed.add(db);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=db-sanitize.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EPOCH_CONFIG_BY_NETWORK } from './const';
|
|
2
|
+
type EpochNetwork = keyof typeof EPOCH_CONFIG_BY_NETWORK;
|
|
3
|
+
/** Epoch a slot belongs to, from the network's Shelley anchor. */
|
|
4
|
+
export declare function epochOfSlot(network: EpochNetwork, slot: number): number;
|
|
5
|
+
/** First absolute slot of an epoch, from the network's Shelley anchor. */
|
|
6
|
+
export declare function epochStartSlot(network: EpochNetwork, epoch: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Absolute POSIX 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
|
+
export declare function slotToPosixMs(network: EpochNetwork, slot: number): number;
|
|
12
|
+
/** Absolute POSIX seconds for a slot, rounded down. */
|
|
13
|
+
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
|
+
*/
|
|
18
|
+
export declare function posixToSlot(network: EpochNetwork, posixMs: number): number;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=epoch-slots.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.epochOfSlot = epochOfSlot;
|
|
4
|
+
exports.epochStartSlot = epochStartSlot;
|
|
5
|
+
exports.slotToPosixMs = slotToPosixMs;
|
|
6
|
+
exports.slotToPosixSeconds = slotToPosixSeconds;
|
|
7
|
+
exports.posixToSlot = posixToSlot;
|
|
8
|
+
const const_1 = require("./const");
|
|
9
|
+
/** Epoch a slot belongs to, from the network's Shelley anchor. */
|
|
10
|
+
function epochOfSlot(network, slot) {
|
|
11
|
+
const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
|
|
12
|
+
return cfg.shelleyStartEpoch + Math.floor((slot - cfg.shelleyStartSlot) / cfg.slotsPerEpoch);
|
|
13
|
+
}
|
|
14
|
+
/** First absolute slot of an epoch, from the network's Shelley anchor. */
|
|
15
|
+
function epochStartSlot(network, epoch) {
|
|
16
|
+
const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
|
|
17
|
+
return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Absolute POSIX milliseconds for a slot via the Shelley-anchored genesis infos (exact for Shelley-era
|
|
21
|
+
* slots). Ogmios' `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
|
|
22
|
+
*/
|
|
23
|
+
function slotToPosixMs(network, slot) {
|
|
24
|
+
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
25
|
+
return genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs;
|
|
26
|
+
}
|
|
27
|
+
/** Absolute POSIX seconds for a slot, rounded down. */
|
|
28
|
+
function slotToPosixSeconds(network, slot) {
|
|
29
|
+
return Math.floor(slotToPosixMs(network, slot) / 1000);
|
|
30
|
+
}
|
|
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
|
+
*/
|
|
35
|
+
function posixToSlot(network, posixMs) {
|
|
36
|
+
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
37
|
+
const shelleyStartMs = slotToPosixMs(network, const_1.EPOCH_CONFIG_BY_NETWORK[network].shelleyStartSlot);
|
|
38
|
+
if (!Number.isFinite(posixMs) || posixMs < shelleyStartMs) {
|
|
39
|
+
throw new RangeError(`posixToSlot: ${posixMs} is not a time from the ${network} Shelley start on`);
|
|
40
|
+
}
|
|
41
|
+
return genesis.startSlotNo + Math.floor((posixMs - genesis.systemStartPosixMs) / genesis.slotLengthMs);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=epoch-slots.js.map
|
|
@@ -1,94 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error codes used throughout the ODATANO backend
|
|
3
|
-
*/
|
|
1
|
+
/** Error codes used throughout the backend. */
|
|
4
2
|
export declare const ERROR_CODES: {
|
|
5
|
-
/**
|
|
6
|
-
* 400 – Invalid input
|
|
7
|
-
* Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
|
|
8
|
-
*/
|
|
3
|
+
/** 400: malformed client input (address, tx hash, ...). */
|
|
9
4
|
readonly INVALID_INPUT: "ODATANO_INVALID_INPUT";
|
|
10
|
-
/**
|
|
11
|
-
* 403 – Caller lacks the required role
|
|
12
|
-
* Indicates the caller is authenticated but not authorized for the operation
|
|
13
|
-
* (e.g. HSM-backed signing without the configured hsm.requiresRole)
|
|
14
|
-
*/
|
|
5
|
+
/** 403: authenticated but lacking the required role (e.g. hsm.requiresRole). */
|
|
15
6
|
readonly FORBIDDEN: "ODATANO_FORBIDDEN";
|
|
16
|
-
/**
|
|
17
|
-
* 404 – Data not found
|
|
18
|
-
* Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
|
|
19
|
-
*/
|
|
7
|
+
/** 404: requested resource not found (unknown tx hash, address without UTxOs, ...). */
|
|
20
8
|
readonly NOT_FOUND: "ODATANO_NOT_FOUND";
|
|
21
|
-
/**
|
|
22
|
-
* 400 – Insufficient funds/assets
|
|
23
|
-
* Indicates that the address does not have enough funds or assets to complete the transaction
|
|
24
|
-
*/
|
|
9
|
+
/** 400: address lacks the funds or assets for the transaction. */
|
|
25
10
|
readonly INSUFFICIENT_FUNDS: "ODATANO_INSUFFICIENT_FUNDS";
|
|
26
|
-
/**
|
|
27
|
-
* 400 – Transaction validation failed
|
|
28
|
-
* Indicates that the transaction failed validation (wrong signature, tampered CBOR, etc.)
|
|
29
|
-
*/
|
|
11
|
+
/** 400: decoded transaction failed validation (wrong signature, tampered CBOR, ...). */
|
|
30
12
|
readonly TX_VALIDATION_FAILED: "ODATANO_TX_VALIDATION_FAILED";
|
|
31
|
-
/**
|
|
32
|
-
* 400 – Transaction CBOR parse failed
|
|
33
|
-
* Indicates that the provided transaction CBOR could not be decoded
|
|
34
|
-
* (malformed bytes, truncated, not a Cardano Conway tx). Distinct from
|
|
35
|
-
* TX_VALIDATION_FAILED which applies to decoded-but-invalid transactions.
|
|
36
|
-
*/
|
|
13
|
+
/** 400: transaction CBOR could not be decoded (malformed, truncated, not a Conway tx). */
|
|
37
14
|
readonly TX_PARSE_FAILED: "ODATANO_TX_PARSE_FAILED";
|
|
38
|
-
/**
|
|
39
|
-
* 400 – Plutus script validation failed
|
|
40
|
-
* Indicates that the ledger cleanly rejected the transaction due to script
|
|
41
|
-
* evaluation — e.g. PlutusFailure, CekError, overspent budget, script hash
|
|
42
|
-
* mismatch. Distinct from provider outages (503) and generic tx validation.
|
|
43
|
-
*/
|
|
15
|
+
/** 400: ledger rejected the tx on script evaluation (PlutusFailure, CekError, budget, hash mismatch). */
|
|
44
16
|
readonly SCRIPT_VALIDATION_FAILURE: "ODATANO_SCRIPT_VALIDATION_FAILURE";
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
17
|
+
/** 409: a crawler cursor block is not on this instance's chain (orphaned by a reorg). */
|
|
18
|
+
readonly CHAIN_POINT_MISMATCH: "ODATANO_CHAIN_POINT_MISMATCH";
|
|
19
|
+
/** 409: transaction already submitted (duplicate / replay). */
|
|
49
20
|
readonly TX_ALREADY_SUBMITTED: "ODATANO_TX_ALREADY_SUBMITTED";
|
|
50
|
-
/**
|
|
51
|
-
* 429 – Rate limiting
|
|
52
|
-
* indicates temporary unavailability
|
|
53
|
-
*/
|
|
21
|
+
/** 429: provider rate limit hit. */
|
|
54
22
|
readonly PROVIDER_RATE_LIMITED: "ODATANO_PROVIDER_RATE_LIMITED";
|
|
55
|
-
/**
|
|
56
|
-
* 503 – Upstream / connectivity
|
|
57
|
-
* Indicates that the Cardano data provider is currently unavailable
|
|
58
|
-
*/
|
|
23
|
+
/** 503: Cardano data provider unavailable. */
|
|
59
24
|
readonly PROVIDER_UNAVAILABLE: "ODATANO_PROVIDER_UNAVAILABLE";
|
|
60
|
-
/**
|
|
61
|
-
* 500 – Internal fallback
|
|
62
|
-
* Indicates an unexpected internal error
|
|
63
|
-
*/
|
|
25
|
+
/** 500: unexpected internal error. */
|
|
64
26
|
readonly INTERNAL_ERROR: "ODATANO_INTERNAL_ERROR";
|
|
65
|
-
/**
|
|
66
|
-
* 503 – HSM unavailable
|
|
67
|
-
* Indicates the HSM device or session is not available
|
|
68
|
-
*/
|
|
27
|
+
/** 503: HSM device or session not available. */
|
|
69
28
|
readonly HSM_UNAVAILABLE: "ODATANO_HSM_UNAVAILABLE";
|
|
70
|
-
/**
|
|
71
|
-
* 500 – HSM signing failed
|
|
72
|
-
* Indicates the HSM signing operation failed
|
|
73
|
-
*/
|
|
29
|
+
/** 500: HSM signing operation failed. */
|
|
74
30
|
readonly HSM_SIGNING_FAILED: "ODATANO_HSM_SIGNING_FAILED";
|
|
75
|
-
/**
|
|
76
|
-
* 400 – HSM not configured
|
|
77
|
-
* Indicates HSM signing was requested but HSM is not configured
|
|
78
|
-
*/
|
|
31
|
+
/** 400: HSM signing requested but HSM not configured. */
|
|
79
32
|
readonly HSM_NOT_CONFIGURED: "ODATANO_HSM_NOT_CONFIGURED";
|
|
80
33
|
/**
|
|
81
|
-
* 503
|
|
82
|
-
*
|
|
83
|
-
* detached bookkeeping transactions. Most common cause: an in-process
|
|
84
|
-
* consumer awaits SubmitVerifiedTransaction/SignAndSubmitWithHsm while its
|
|
85
|
-
* own request transaction holds the (single) pooled sqlite connection —
|
|
86
|
-
* see docs/KNOWN_ISSUES.md issue 11.
|
|
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.
|
|
87
36
|
*/
|
|
88
37
|
readonly NESTED_TX_TIMEOUT: "ODATANO_NESTED_TX_TIMEOUT";
|
|
89
38
|
};
|
|
90
|
-
/**
|
|
91
|
-
* EnumType representing all possible error codes
|
|
92
|
-
*/
|
|
39
|
+
/** Union of all error code values. */
|
|
93
40
|
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
94
41
|
//# sourceMappingURL=error-codes.d.ts.map
|
package/srv/utils/error-codes.js
CHANGED
|
@@ -1,92 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ERROR_CODES = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Error codes used throughout the ODATANO backend
|
|
6
|
-
*/
|
|
4
|
+
/** Error codes used throughout the backend. */
|
|
7
5
|
exports.ERROR_CODES = {
|
|
8
|
-
/**
|
|
9
|
-
* 400 – Invalid input
|
|
10
|
-
* Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
|
|
11
|
-
*/
|
|
6
|
+
/** 400: malformed client input (address, tx hash, ...). */
|
|
12
7
|
INVALID_INPUT: 'ODATANO_INVALID_INPUT',
|
|
13
|
-
/**
|
|
14
|
-
* 403 – Caller lacks the required role
|
|
15
|
-
* Indicates the caller is authenticated but not authorized for the operation
|
|
16
|
-
* (e.g. HSM-backed signing without the configured hsm.requiresRole)
|
|
17
|
-
*/
|
|
8
|
+
/** 403: authenticated but lacking the required role (e.g. hsm.requiresRole). */
|
|
18
9
|
FORBIDDEN: 'ODATANO_FORBIDDEN',
|
|
19
|
-
/**
|
|
20
|
-
* 404 – Data not found
|
|
21
|
-
* Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
|
|
22
|
-
*/
|
|
10
|
+
/** 404: requested resource not found (unknown tx hash, address without UTxOs, ...). */
|
|
23
11
|
NOT_FOUND: 'ODATANO_NOT_FOUND',
|
|
24
|
-
/**
|
|
25
|
-
* 400 – Insufficient funds/assets
|
|
26
|
-
* Indicates that the address does not have enough funds or assets to complete the transaction
|
|
27
|
-
*/
|
|
12
|
+
/** 400: address lacks the funds or assets for the transaction. */
|
|
28
13
|
INSUFFICIENT_FUNDS: 'ODATANO_INSUFFICIENT_FUNDS',
|
|
29
|
-
/**
|
|
30
|
-
* 400 – Transaction validation failed
|
|
31
|
-
* Indicates that the transaction failed validation (wrong signature, tampered CBOR, etc.)
|
|
32
|
-
*/
|
|
14
|
+
/** 400: decoded transaction failed validation (wrong signature, tampered CBOR, ...). */
|
|
33
15
|
TX_VALIDATION_FAILED: 'ODATANO_TX_VALIDATION_FAILED',
|
|
34
|
-
/**
|
|
35
|
-
* 400 – Transaction CBOR parse failed
|
|
36
|
-
* Indicates that the provided transaction CBOR could not be decoded
|
|
37
|
-
* (malformed bytes, truncated, not a Cardano Conway tx). Distinct from
|
|
38
|
-
* TX_VALIDATION_FAILED which applies to decoded-but-invalid transactions.
|
|
39
|
-
*/
|
|
16
|
+
/** 400: transaction CBOR could not be decoded (malformed, truncated, not a Conway tx). */
|
|
40
17
|
TX_PARSE_FAILED: 'ODATANO_TX_PARSE_FAILED',
|
|
41
|
-
/**
|
|
42
|
-
* 400 – Plutus script validation failed
|
|
43
|
-
* Indicates that the ledger cleanly rejected the transaction due to script
|
|
44
|
-
* evaluation — e.g. PlutusFailure, CekError, overspent budget, script hash
|
|
45
|
-
* mismatch. Distinct from provider outages (503) and generic tx validation.
|
|
46
|
-
*/
|
|
18
|
+
/** 400: ledger rejected the tx on script evaluation (PlutusFailure, CekError, budget, hash mismatch). */
|
|
47
19
|
SCRIPT_VALIDATION_FAILURE: 'ODATANO_SCRIPT_VALIDATION_FAILURE',
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
20
|
+
/** 409: a crawler cursor block is not on this instance's chain (orphaned by a reorg). */
|
|
21
|
+
CHAIN_POINT_MISMATCH: 'ODATANO_CHAIN_POINT_MISMATCH',
|
|
22
|
+
/** 409: transaction already submitted (duplicate / replay). */
|
|
52
23
|
TX_ALREADY_SUBMITTED: 'ODATANO_TX_ALREADY_SUBMITTED',
|
|
53
|
-
/**
|
|
54
|
-
* 429 – Rate limiting
|
|
55
|
-
* indicates temporary unavailability
|
|
56
|
-
*/
|
|
24
|
+
/** 429: provider rate limit hit. */
|
|
57
25
|
PROVIDER_RATE_LIMITED: 'ODATANO_PROVIDER_RATE_LIMITED',
|
|
58
|
-
/**
|
|
59
|
-
* 503 – Upstream / connectivity
|
|
60
|
-
* Indicates that the Cardano data provider is currently unavailable
|
|
61
|
-
*/
|
|
26
|
+
/** 503: Cardano data provider unavailable. */
|
|
62
27
|
PROVIDER_UNAVAILABLE: 'ODATANO_PROVIDER_UNAVAILABLE',
|
|
63
|
-
/**
|
|
64
|
-
* 500 – Internal fallback
|
|
65
|
-
* Indicates an unexpected internal error
|
|
66
|
-
*/
|
|
28
|
+
/** 500: unexpected internal error. */
|
|
67
29
|
INTERNAL_ERROR: 'ODATANO_INTERNAL_ERROR',
|
|
68
|
-
/**
|
|
69
|
-
* 503 – HSM unavailable
|
|
70
|
-
* Indicates the HSM device or session is not available
|
|
71
|
-
*/
|
|
30
|
+
/** 503: HSM device or session not available. */
|
|
72
31
|
HSM_UNAVAILABLE: 'ODATANO_HSM_UNAVAILABLE',
|
|
73
|
-
/**
|
|
74
|
-
* 500 – HSM signing failed
|
|
75
|
-
* Indicates the HSM signing operation failed
|
|
76
|
-
*/
|
|
32
|
+
/** 500: HSM signing operation failed. */
|
|
77
33
|
HSM_SIGNING_FAILED: 'ODATANO_HSM_SIGNING_FAILED',
|
|
78
|
-
/**
|
|
79
|
-
* 400 – HSM not configured
|
|
80
|
-
* Indicates HSM signing was requested but HSM is not configured
|
|
81
|
-
*/
|
|
34
|
+
/** 400: HSM signing requested but HSM not configured. */
|
|
82
35
|
HSM_NOT_CONFIGURED: 'ODATANO_HSM_NOT_CONFIGURED',
|
|
83
36
|
/**
|
|
84
|
-
* 503
|
|
85
|
-
*
|
|
86
|
-
* detached bookkeeping transactions. Most common cause: an in-process
|
|
87
|
-
* consumer awaits SubmitVerifiedTransaction/SignAndSubmitWithHsm while its
|
|
88
|
-
* own request transaction holds the (single) pooled sqlite connection —
|
|
89
|
-
* see docs/KNOWN_ISSUES.md issue 11.
|
|
37
|
+
* 503: a detached bookkeeping transaction could not acquire a pooled DB connection in time,
|
|
38
|
+
* typically because an in-process caller awaits the action while its own request tx holds the single sqlite connection.
|
|
90
39
|
*/
|
|
91
40
|
NESTED_TX_TIMEOUT: 'ODATANO_NESTED_TX_TIMEOUT',
|
|
92
41
|
};
|