@odatano/core 2.0.0-rc.3 → 2.0.0-rc.30
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 +294 -7
- package/@cds-models/CardanoODataService/index.js +33 -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 +52 -19
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +18 -0
- package/@cds-models/index.js +3 -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 +677 -13
- package/db/types.cds +27 -0
- package/package.json +182 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +11 -10
- package/src/index.js +28 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +49 -160
- 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 +356 -217
- 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 +548 -197
- 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 +78 -205
- package/srv/blockchain/cardano-client.js +186 -242
- package/srv/blockchain/cardano-indexer.d.ts +302 -242
- package/srv/blockchain/cardano-indexer.js +1191 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +43 -81
- package/srv/blockchain/cardano-tx-builder.js +177 -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 +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- 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 +108 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +620 -285
- package/srv/blockchain/transaction-building/caller-datums.d.ts +17 -0
- package/srv/blockchain/transaction-building/caller-datums.js +50 -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 +48 -24
- 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 +56 -1
- package/srv/cardano-service.js +52 -113
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +439 -364
- package/srv/cardano-tx-service.js +305 -209
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/parse.js +13 -1
- package/srv/server.d.ts +28 -86
- package/srv/server.js +127 -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 +13 -0
- package/srv/utils/epoch-slots.js +25 -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/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 +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +26 -92
- package/srv/utils/tx-build-helper.js +68 -123
- package/srv/utils/tx-request-parsers.d.ts +107 -21
- package/srv/utils/tx-request-parsers.js +433 -34
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +238 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
package/srv/utils/tx-utils.js
CHANGED
|
@@ -10,29 +10,20 @@ const cds_1 = __importDefault(require("@sap/cds"));
|
|
|
10
10
|
const errors_1 = require("./errors");
|
|
11
11
|
const error_codes_1 = require("./error-codes");
|
|
12
12
|
/**
|
|
13
|
-
* Transaction
|
|
14
|
-
*
|
|
15
|
-
* Context: @cap-js/sqlite runs on a SINGLE pooled connection. A request
|
|
16
|
-
* transaction begins lazily on its first CQL statement and holds that
|
|
17
|
-
* connection until the request commits. Any code that then needs a NEW ROOT
|
|
18
|
-
* transaction (detached committed bookkeeping) waits on the pool — forever,
|
|
19
|
-
* if the waiter is awaited by the very request holding the connection
|
|
20
|
-
* (docs/KNOWN_ISSUES.md issue 11).
|
|
13
|
+
* Transaction helpers for the sign-service and background workers. @cap-js/sqlite has a single pooled
|
|
14
|
+
* connection held by the request tx, so a new root tx awaited by that request would wait forever.
|
|
21
15
|
*/
|
|
22
16
|
const logger = cds_1.default.log('tx-utils');
|
|
23
17
|
/** Default acquire budget for detached bookkeeping transactions. */
|
|
24
18
|
exports.DETACHED_TX_TIMEOUT_MS = 10_000;
|
|
25
|
-
/**
|
|
19
|
+
/** ODATANO_DETACHED_TX_TIMEOUT_MS override, else the default; read per call. */
|
|
26
20
|
function effectiveTimeoutMs() {
|
|
27
21
|
const fromEnv = Number(process.env.ODATANO_DETACHED_TX_TIMEOUT_MS);
|
|
28
22
|
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : exports.DETACHED_TX_TIMEOUT_MS;
|
|
29
23
|
}
|
|
30
24
|
/**
|
|
31
|
-
* Run `fn` with `cds.context` cleared
|
|
32
|
-
*
|
|
33
|
-
* Under @cap-js/sqlite (pool.max=1) this is what keeps the single pooled
|
|
34
|
-
* connection free during long awaits (NIGHTGATE lesson 2; used by the
|
|
35
|
-
* wallet-worker job loops).
|
|
25
|
+
* Run `fn` with `cds.context` cleared so inner `db.run` calls get short-lived transactions instead of
|
|
26
|
+
* joining a long-lived ambient one; keeps the single sqlite connection free during long awaits.
|
|
36
27
|
*/
|
|
37
28
|
function runWithoutAmbientTx(fn) {
|
|
38
29
|
return cds_1.default._with(undefined, fn);
|
|
@@ -45,34 +36,16 @@ class DetachedTxAbortedError extends Error {
|
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
38
|
/**
|
|
48
|
-
* `cds.tx(fn)` with a deadlock guard:
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* Why: the sign-service must commit its submit bookkeeping (claim, finalize,
|
|
52
|
-
* failure marker) independently of the caller's request transaction. When an
|
|
53
|
-
* in-process consumer awaits the action while its own request transaction
|
|
54
|
-
* holds the single pooled sqlite connection, the acquire can never succeed —
|
|
55
|
-
* without this guard that is a silent, zero-CPU, infinite hang.
|
|
56
|
-
*
|
|
57
|
-
* Guarantees:
|
|
58
|
-
* - On timeout, throws `BackendError` 503 `ODATANO_NESTED_TX_TIMEOUT` with a
|
|
59
|
-
* diagnosis pointing at KNOWN_ISSUES #11.
|
|
60
|
-
* - A late connection grant (after the timeout already fired) performs NO
|
|
61
|
-
* work: the callback forces the acquire via an explicit `begin()` and
|
|
62
|
-
* checks the abort flag right after it, so it rolls back immediately and
|
|
63
|
-
* the caller never observes an error for work that then silently happened
|
|
64
|
-
* anyway. (A flag check at callback ENTRY would run long before the lazy
|
|
65
|
-
* acquire and miss the timeout.)
|
|
39
|
+
* `cds.tx(fn)` as a new root transaction with a deadlock guard: throws BackendError 503
|
|
40
|
+
* `ODATANO_NESTED_TX_TIMEOUT` when no pooled connection arrives in time, and a late grant does no work.
|
|
66
41
|
*/
|
|
67
42
|
async function detachedTx(label, fn, timeoutMs) {
|
|
68
43
|
const effectiveTimeout = timeoutMs ?? effectiveTimeoutMs();
|
|
69
44
|
let timedOut = false;
|
|
70
45
|
let timer;
|
|
71
46
|
const work = cds_1.default.tx(async (db) => {
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// the abort flag — a late grant (after the caller already received the
|
|
75
|
-
// timeout error) must roll back before doing any work.
|
|
47
|
+
// The connection is acquired lazily by the first statement: force it now, then check the abort
|
|
48
|
+
// flag so a grant after the timeout rolls back before doing any work.
|
|
76
49
|
await db.begin();
|
|
77
50
|
if (timedOut)
|
|
78
51
|
throw new DetachedTxAbortedError(label);
|
|
@@ -84,8 +57,8 @@ async function detachedTx(label, fn, timeoutMs) {
|
|
|
84
57
|
reject(new errors_1.BackendError(`${label}: could not begin a detached DB transaction within ${effectiveTimeout}ms. ` +
|
|
85
58
|
`Most likely the calling request still holds the pooled DB connection open ` +
|
|
86
59
|
`(in-process nested call — do not await this action while your request ` +
|
|
87
|
-
`transaction is open; detach your reads into a committed cds.tx first
|
|
88
|
-
`
|
|
60
|
+
`transaction is open; detach your reads into a committed cds.tx first). ` +
|
|
61
|
+
`Alternatively the connection pool is exhausted.`, 503, error_codes_1.ERROR_CODES.NESTED_TX_TIMEOUT));
|
|
89
62
|
}, effectiveTimeout);
|
|
90
63
|
});
|
|
91
64
|
try {
|
|
@@ -95,9 +68,7 @@ async function detachedTx(label, fn, timeoutMs) {
|
|
|
95
68
|
if (timer)
|
|
96
69
|
clearTimeout(timer);
|
|
97
70
|
if (timedOut) {
|
|
98
|
-
// The orphaned acquire may still be granted
|
|
99
|
-
// itself via the flag. Observe the rejection so it never surfaces as an
|
|
100
|
-
// unhandled promise rejection.
|
|
71
|
+
// The orphaned acquire may still be granted; observe its rejection so it is never unhandled.
|
|
101
72
|
work.catch((e) => {
|
|
102
73
|
if (!(e instanceof DetachedTxAbortedError)) {
|
|
103
74
|
logger.warn(`Orphaned detached tx '${label}' failed after timeout: ${e instanceof Error ? e.message : String(e)}`);
|