@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,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard for Ogmios chain-sync frames the client's `safeJSON.parse` cannot handle: it recurses per
|
|
3
|
+
* nesting level, so a deeply nested native script overflows the stack inside an un-awaited socket
|
|
4
|
+
* handler and ends the process. On RangeError fall back to iterative `JSON.parse` (big ints as strings).
|
|
5
|
+
*/
|
|
6
|
+
import { safeJSON } from '@cardano-ogmios/client';
|
|
7
|
+
/** A frame the guard could not turn into an object at all. */
|
|
8
|
+
export interface UnparseableFrame {
|
|
9
|
+
/** Block height, when it could be read off the raw text; null when even that failed. */
|
|
10
|
+
height: number | null;
|
|
11
|
+
/** Block id (hash), when readable. */
|
|
12
|
+
id: string | null;
|
|
13
|
+
reason: string;
|
|
14
|
+
bytes: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Wrap integers outside the safe double range in JSON strings so plain `JSON.parse` cannot
|
|
18
|
+
* round them. One linear pass, no recursion; digits inside strings, floats and exponents
|
|
19
|
+
* are left alone.
|
|
20
|
+
*/
|
|
21
|
+
export declare function widenBigIntegers(text: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Wrap `safeJSON.parse` once per process and register a report callback; returns its
|
|
24
|
+
* unregister function. The parser is shared by every open chain-sync socket and cannot tell
|
|
25
|
+
* which one a frame came from, so an unusable frame goes to every registered callback.
|
|
26
|
+
* After a reported frame the stream stalls (the client drops non-nextBlock responses),
|
|
27
|
+
* so the caller decides what happens next.
|
|
28
|
+
*/
|
|
29
|
+
export declare function installOgmiosFrameGuard(onUnparseableFrame: (frame: UnparseableFrame) => void): () => void;
|
|
30
|
+
/** Tests only — drop the wrapper so each case starts from the untouched client. */
|
|
31
|
+
export declare function resetOgmiosFrameGuardForTests(originalParse?: typeof safeJSON.parse): void;
|
|
32
|
+
//# sourceMappingURL=ogmios-frame-guard.d.ts.map
|
|
@@ -0,0 +1,142 @@
|
|
|
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.widenBigIntegers = widenBigIntegers;
|
|
7
|
+
exports.installOgmiosFrameGuard = installOgmiosFrameGuard;
|
|
8
|
+
exports.resetOgmiosFrameGuardForTests = resetOgmiosFrameGuardForTests;
|
|
9
|
+
/**
|
|
10
|
+
* Guard for Ogmios chain-sync frames the client's `safeJSON.parse` cannot handle: it recurses per
|
|
11
|
+
* nesting level, so a deeply nested native script overflows the stack inside an un-awaited socket
|
|
12
|
+
* handler and ends the process. On RangeError fall back to iterative `JSON.parse` (big ints as strings).
|
|
13
|
+
*/
|
|
14
|
+
const client_1 = require("@cardano-ogmios/client");
|
|
15
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
16
|
+
const logger = cds_1.default.log('OgmiosFrameGuard');
|
|
17
|
+
/**
|
|
18
|
+
* Wrap integers outside the safe double range in JSON strings so plain `JSON.parse` cannot
|
|
19
|
+
* round them. One linear pass, no recursion; digits inside strings, floats and exponents
|
|
20
|
+
* are left alone.
|
|
21
|
+
*/
|
|
22
|
+
function widenBigIntegers(text) {
|
|
23
|
+
const SAFE_DIGITS = String(Number.MAX_SAFE_INTEGER).length; // 16
|
|
24
|
+
let out = '';
|
|
25
|
+
let last = 0;
|
|
26
|
+
let inString = false;
|
|
27
|
+
let escaped = false;
|
|
28
|
+
for (let i = 0; i < text.length; i++) {
|
|
29
|
+
const c = text[i];
|
|
30
|
+
if (inString) {
|
|
31
|
+
if (escaped)
|
|
32
|
+
escaped = false;
|
|
33
|
+
else if (c === '\\')
|
|
34
|
+
escaped = true;
|
|
35
|
+
else if (c === '"')
|
|
36
|
+
inString = false;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (c === '"') {
|
|
40
|
+
inString = true;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
// a number literal starts here only after a structural character
|
|
44
|
+
if (c !== '-' && (c < '0' || c > '9'))
|
|
45
|
+
continue;
|
|
46
|
+
const prev = text[i - 1];
|
|
47
|
+
if (prev !== ':' && prev !== ',' && prev !== '[' && prev !== ' ' && prev !== '\n' && prev !== '\t' && prev !== '\r')
|
|
48
|
+
continue;
|
|
49
|
+
let j = i;
|
|
50
|
+
if (text[j] === '-')
|
|
51
|
+
j++;
|
|
52
|
+
const digitsFrom = j;
|
|
53
|
+
while (j < text.length && text[j] >= '0' && text[j] <= '9')
|
|
54
|
+
j++;
|
|
55
|
+
const digits = j - digitsFrom;
|
|
56
|
+
if (digits === 0)
|
|
57
|
+
continue;
|
|
58
|
+
// a fraction or exponent means it was never an exact integer — leave it alone
|
|
59
|
+
const after = text[j];
|
|
60
|
+
if (after === '.' || after === 'e' || after === 'E') {
|
|
61
|
+
i = j;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (digits >= SAFE_DIGITS) {
|
|
65
|
+
const literal = text.slice(i, j);
|
|
66
|
+
if (!Number.isSafeInteger(Number(literal))) {
|
|
67
|
+
out += text.slice(last, i) + '"' + literal + '"';
|
|
68
|
+
last = j;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
i = j - 1;
|
|
72
|
+
}
|
|
73
|
+
return last === 0 ? text : out + text.slice(last);
|
|
74
|
+
}
|
|
75
|
+
/** Block height/id from the front of an unparseable frame, to name the block in logs and `lastError`. */
|
|
76
|
+
function readBlockHeader(text) {
|
|
77
|
+
const head = text.slice(0, 4096);
|
|
78
|
+
const id = /"id"\s*:\s*"([0-9a-fA-F]{64})"/.exec(head);
|
|
79
|
+
const height = /"height"\s*:\s*(\d{1,15})/.exec(head);
|
|
80
|
+
return { height: height ? Number(height[1]) : null, id: id ? id[1] : null };
|
|
81
|
+
}
|
|
82
|
+
let installed = false;
|
|
83
|
+
const reporters = new Set();
|
|
84
|
+
/**
|
|
85
|
+
* Wrap `safeJSON.parse` once per process and register a report callback; returns its
|
|
86
|
+
* unregister function. The parser is shared by every open chain-sync socket and cannot tell
|
|
87
|
+
* which one a frame came from, so an unusable frame goes to every registered callback.
|
|
88
|
+
* After a reported frame the stream stalls (the client drops non-nextBlock responses),
|
|
89
|
+
* so the caller decides what happens next.
|
|
90
|
+
*/
|
|
91
|
+
function installOgmiosFrameGuard(onUnparseableFrame) {
|
|
92
|
+
reporters.add(onUnparseableFrame);
|
|
93
|
+
const unregister = () => { reporters.delete(onUnparseableFrame); };
|
|
94
|
+
if (installed)
|
|
95
|
+
return unregister;
|
|
96
|
+
const original = client_1.safeJSON.parse.bind(client_1.safeJSON);
|
|
97
|
+
installed = true; // only once the original is safely in hand
|
|
98
|
+
client_1.safeJSON.parse = (raw) => {
|
|
99
|
+
try {
|
|
100
|
+
return original(raw);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (!(err instanceof RangeError))
|
|
104
|
+
throw err; // a genuine syntax error stays a syntax error
|
|
105
|
+
const text = String(raw);
|
|
106
|
+
const where = readBlockHeader(text);
|
|
107
|
+
try {
|
|
108
|
+
const parsed = JSON.parse(widenBigIntegers(text));
|
|
109
|
+
logger.warn(`chain-sync frame too deeply nested for the client's parser (block ${where.height ?? '?'} ` +
|
|
110
|
+
`${where.id ?? ''}, ${text.length} bytes) — parsed without it. Integers beyond 2^53 are ` +
|
|
111
|
+
`strings on this path; the chain-sync mapper stringifies them anyway.`);
|
|
112
|
+
return parsed;
|
|
113
|
+
}
|
|
114
|
+
catch (fallbackErr) {
|
|
115
|
+
const reason = fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
|
|
116
|
+
logger.error(`chain-sync frame unparseable (block ${where.height ?? '?'} ${where.id ?? ''}, ` +
|
|
117
|
+
`${text.length} bytes): ${reason}`);
|
|
118
|
+
const frame = { ...where, reason, bytes: text.length };
|
|
119
|
+
for (const r of [...reporters]) {
|
|
120
|
+
try {
|
|
121
|
+
r(frame);
|
|
122
|
+
}
|
|
123
|
+
catch (cbErr) {
|
|
124
|
+
logger.error('frame guard report callback failed:', cbErr);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Never throw: this runs in an async socket handler nobody awaits, so a throw
|
|
128
|
+
// becomes an unhandled rejection and ends the process.
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return unregister;
|
|
134
|
+
}
|
|
135
|
+
/** Tests only — drop the wrapper so each case starts from the untouched client. */
|
|
136
|
+
function resetOgmiosFrameGuardForTests(originalParse) {
|
|
137
|
+
if (originalParse)
|
|
138
|
+
client_1.safeJSON.parse = originalParse;
|
|
139
|
+
installed = false;
|
|
140
|
+
reporters.clear();
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=ogmios-frame-guard.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ChainSyncBackend, PaginatingBackend } from './backends/cardano-backend';
|
|
1
|
+
import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend, LedgerStateBackend, EpochStateBackend } from './backends/cardano-backend';
|
|
2
|
+
import { PendingSpends } from './pending-spends';
|
|
2
3
|
import { type CircuitBreakerConfig } from './circuit-breaker';
|
|
3
4
|
import { Transaction, Address, UTxO, NetworkInformation, BlockData, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../utils/types';
|
|
4
5
|
export type Network = 'mainnet' | 'preview' | 'preprod';
|
|
5
|
-
export type BackendName = 'blockfrost' | 'koios' | 'ogmios';
|
|
6
|
+
export type BackendName = 'blockfrost' | 'koios' | 'ogmios' | 'odatano';
|
|
6
7
|
export type TransactionBuilderName = 'buildooor';
|
|
7
8
|
export type CardanoClientConfig = {
|
|
8
9
|
network: Network;
|
|
@@ -11,6 +12,10 @@ export type CardanoClientConfig = {
|
|
|
11
12
|
blockfrostCustomBackend?: string;
|
|
12
13
|
koiosApiKey: string;
|
|
13
14
|
ogmiosUrl: string;
|
|
15
|
+
/** Remote ODATANO for the `odatano` backend; defaults to the public API of the network. */
|
|
16
|
+
odatanoUrl?: string;
|
|
17
|
+
/** Key for the remote ODATANO (a gateway `oda_…` key or an agent grant token). */
|
|
18
|
+
odatanoApiKey?: string;
|
|
14
19
|
transactionBuilders: TransactionBuilderName[];
|
|
15
20
|
primaryTimeoutMs: number;
|
|
16
21
|
fallbackTimeoutMs: number;
|
|
@@ -18,12 +23,8 @@ export type CardanoClientConfig = {
|
|
|
18
23
|
circuitBreaker?: Partial<CircuitBreakerConfig>;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* Routes requests to appropriate backends:
|
|
24
|
-
* - Live/State queries → Ogmios (if available)
|
|
25
|
-
* - Historical queries → Blockfrost/Koios (if available)
|
|
26
|
-
* - Automatic fallback between backends
|
|
26
|
+
* Multi-backend Cardano client: live/state queries prefer Ogmios, historical queries prefer
|
|
27
|
+
* Blockfrost/Koios, with automatic fallback between them.
|
|
27
28
|
*/
|
|
28
29
|
export declare class CardanoClient {
|
|
29
30
|
private config;
|
|
@@ -36,51 +37,38 @@ export declare class CardanoClient {
|
|
|
36
37
|
private uninitializedBackends;
|
|
37
38
|
network: Network;
|
|
38
39
|
max_age_ms: number;
|
|
40
|
+
/** Transactions submitted through this client that the ledger view does not show yet. */
|
|
41
|
+
readonly pendingSpends: PendingSpends;
|
|
39
42
|
private protocolParamsCache?;
|
|
40
43
|
private protocolParamsFetchPromise;
|
|
44
|
+
/** Last protocol parameters the live backend (node) answered. */
|
|
45
|
+
private lastLiveProtocolParams?;
|
|
41
46
|
private static readonly PROTOCOL_PARAMS_TTL_MS;
|
|
42
47
|
private txCoalescer;
|
|
43
48
|
private addrCoalescer;
|
|
44
49
|
private credCoalescer;
|
|
45
|
-
/**
|
|
46
|
-
* Constructor for CardanoClient
|
|
47
|
-
* @param liveBackend - Optional backend for live/state queries (typically Ogmios)
|
|
48
|
-
* @param historicalBackends - Optional backends for historical queries (typically Blockfrost/Koios)
|
|
49
|
-
*/
|
|
50
|
+
/** Builds the configured backends; throws ConfigError when none is configured. */
|
|
50
51
|
constructor(clientConfig: CardanoClientConfig);
|
|
51
52
|
/** Names of the configured backends (live + historical), for status reporting. */
|
|
52
53
|
listBackends(): string[];
|
|
53
54
|
/**
|
|
54
|
-
* Ensure backends are initialized.
|
|
55
|
-
*
|
|
56
|
-
* a transient startup failure (e.g. Ogmios briefly down) left the client
|
|
57
|
-
* permanently broken until process restart.
|
|
58
|
-
* @returns {Promise<void>}
|
|
55
|
+
* Ensure backends are initialized. A rejected init promise is cleared so the next request
|
|
56
|
+
* retries instead of leaving the client permanently broken.
|
|
59
57
|
*/
|
|
60
58
|
private ensureInitialized;
|
|
61
59
|
/**
|
|
62
|
-
* Transient (retryable) init failures: a backend momentarily unreachable at
|
|
63
|
-
*
|
|
64
|
-
* a freshly-arrived block ("Premature close"), or the socket still coming up
|
|
65
|
-
* (ECONNREFUSED). Config/validation errors are NOT transient.
|
|
60
|
+
* Transient (retryable) init failures: a backend momentarily unreachable at startup
|
|
61
|
+
* (connection refused/reset, a cut-short health response). Config/validation errors are not.
|
|
66
62
|
*/
|
|
67
63
|
private static isTransientInitError;
|
|
68
64
|
/**
|
|
69
|
-
* Init a backend, retrying brief transient failures.
|
|
70
|
-
*
|
|
71
|
-
* time must stay well under it (≤3 attempts × 4s init-timeout + 1s backoff
|
|
72
|
-
* ≈ 14s worst case; in practice "Premature close" returns sub-second). With
|
|
73
|
-
* the node at tip these failures are momentary block-processing blips, so a
|
|
74
|
-
* couple of quick retries ride over them; a sustained outage still fails fast.
|
|
65
|
+
* Init a backend, retrying brief transient failures. Kept small (3 attempts, 1 s backoff) so
|
|
66
|
+
* a sustained outage still fails fast and the total stays under the test bootstrap hook.
|
|
75
67
|
*/
|
|
76
68
|
private initBackendWithRetry;
|
|
77
69
|
/**
|
|
78
|
-
* Initialize all backends
|
|
79
|
-
*
|
|
80
|
-
* and tracked in `uninitializedBackends` — the request loops retry their
|
|
81
|
-
* init lazily, so a backend that comes back online recovers without a
|
|
82
|
-
* process restart. The circuit breaker bounds the retry cost.
|
|
83
|
-
* @returns {Promise<void>}
|
|
70
|
+
* Initialize all backends. Backends whose init fails stay in rotation, tracked in
|
|
71
|
+
* `uninitializedBackends`, and are retried lazily per request (bounded by the circuit breaker).
|
|
84
72
|
*/
|
|
85
73
|
private initBackends;
|
|
86
74
|
/**
|
|
@@ -89,226 +77,123 @@ export declare class CardanoClient {
|
|
|
89
77
|
* retry failed.
|
|
90
78
|
*/
|
|
91
79
|
private ensureBackendInitialized;
|
|
92
|
-
/**
|
|
93
|
-
* Wrap a promise with a timeout
|
|
94
|
-
* @param promise - the promise to wrap
|
|
95
|
-
* @param ms - timeout in milliseconds
|
|
96
|
-
* @param backendName - name of the backend (for error context)
|
|
97
|
-
* @returns {Promise<T>} the result of the promise or a timeout error
|
|
98
|
-
*/
|
|
80
|
+
/** Wrap a promise with a timeout that rejects with ProviderUnavailableError. */
|
|
99
81
|
private withTimeout;
|
|
100
|
-
/**
|
|
101
|
-
* Get timeout for specific backend
|
|
102
|
-
* @param backend CardanoBackend instance
|
|
103
|
-
* @returns {number} timeout in milliseconds
|
|
104
|
-
*/
|
|
82
|
+
/** Per-backend timeout: Koios and a remote ODATANO get the fallback timeout, everything else the primary one. */
|
|
105
83
|
private getTimeoutForBackend;
|
|
106
84
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* recording (4xx exempt). For the paths that cannot fail over (Koios-only,
|
|
110
|
-
* Ogmios-only, batch-capable loops) — these previously bypassed timeout AND
|
|
111
|
-
* breaker entirely, so a hanging socket blocked the caller indefinitely.
|
|
85
|
+
* Single-backend call with the executeWithPriority resilience contract (breaker gate, timeout,
|
|
86
|
+
* success/failure recording, 4xx exempt) for paths that cannot fail over.
|
|
112
87
|
*/
|
|
113
88
|
private callWithResilience;
|
|
114
|
-
/**
|
|
115
|
-
* Execute with priority-based backend selection and automatic fallback
|
|
116
|
-
* @param fn function to execute on backend
|
|
117
|
-
* @param preferLive whether to prefer live backend over historical
|
|
118
|
-
* @returns {Promise<T>} result from backend
|
|
119
|
-
*/
|
|
89
|
+
/** Execute on backends in preference order (live vs historical) with automatic fallback. */
|
|
120
90
|
private executeWithPriority;
|
|
121
|
-
/**
|
|
122
|
-
* Route method call to appropriate backend based on method routing configuration
|
|
123
|
-
* @param methodName name of the method being called
|
|
124
|
-
* @param fn function to execute on backend
|
|
125
|
-
* @returns {Promise<T>} result from backend
|
|
126
|
-
*/
|
|
91
|
+
/** Route a call by METHOD_ROUTING (default: historical first). */
|
|
127
92
|
private route;
|
|
128
|
-
/**
|
|
129
|
-
* Get transaction by hash with fallback between backends
|
|
130
|
-
* @param txHash transaction hash (hex)
|
|
131
|
-
* @returns {Promise<Transaction>} transaction data
|
|
132
|
-
*/
|
|
93
|
+
/** Transaction by hash (coalesced across concurrent callers). */
|
|
133
94
|
getTransaction(txHash: string): Promise<Transaction>;
|
|
134
|
-
/**
|
|
135
|
-
* Get address by bech32 address with fallback between backends
|
|
136
|
-
* @param address bech32 address
|
|
137
|
-
* @returns {Promise<Address>} address data
|
|
138
|
-
*/
|
|
95
|
+
/** Address data (coalesced across concurrent callers). */
|
|
139
96
|
getAddress(address: string): Promise<Address>;
|
|
140
|
-
/**
|
|
141
|
-
* Get address UTxOs with fallback between backends
|
|
142
|
-
* @param address bech32 address
|
|
143
|
-
* @returns {Promise<UTxO[]>} list of UTxOs
|
|
144
|
-
*/
|
|
145
97
|
getAddressUtxos(address: string): Promise<UTxO[]>;
|
|
146
98
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* Throws ProviderUnavailableError if Koios is not configured.
|
|
150
|
-
* @param credHash 28-byte payment credential as 56-char lowercase hex
|
|
151
|
-
* @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms sharing the credential
|
|
99
|
+
* UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
|
|
100
|
+
* Needs a credential-keyed backend (Koios, or another ODATANO); Blockfrost has none.
|
|
152
101
|
*/
|
|
153
102
|
getCredentialUtxos(credHash: string): Promise<UTxO[]>;
|
|
154
|
-
/**
|
|
155
|
-
* Get address transactions with fallback between backends
|
|
156
|
-
* @param address bech32 address
|
|
157
|
-
* @returns {Promise<Transaction[]>} list of transactions for this address
|
|
158
|
-
*/
|
|
159
103
|
getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
|
|
160
|
-
/**
|
|
161
|
-
* Get network information with fallback between backends
|
|
162
|
-
* @returns {Promise<Network>} network information
|
|
163
|
-
*/
|
|
164
104
|
getNetworkInformation(): Promise<NetworkInformation>;
|
|
165
|
-
/**
|
|
166
|
-
* Get transaction metadata with fallback between backends
|
|
167
|
-
* @param tx_hash transaction hash (hex)
|
|
168
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata
|
|
169
|
-
*/
|
|
170
105
|
getTransactionMetadata(tx_hash: string): Promise<MetadataLabelTx[]>;
|
|
171
|
-
/**
|
|
172
|
-
* Get block data with fallback between backends
|
|
173
|
-
* @param block_hash block hash (hex)
|
|
174
|
-
* @returns {Promise<BlockData>} block data
|
|
175
|
-
*/
|
|
176
106
|
getBlock(block_hash: string): Promise<BlockData>;
|
|
177
|
-
/**
|
|
178
|
-
* Get epoch data with fallback between backends
|
|
179
|
-
* @param epochNumber epoch number
|
|
180
|
-
* @returns {Promise<EpochData>} epoch data
|
|
181
|
-
*/
|
|
182
107
|
getEpoch(epochNumber: number): Promise<EpochData>;
|
|
183
|
-
/**
|
|
184
|
-
* Get Pool data with fallback between backends
|
|
185
|
-
* @param poolId pool id
|
|
186
|
-
* @returns {Promise<PoolData>} pool data
|
|
187
|
-
*/
|
|
188
108
|
getPool(poolId: string): Promise<PoolData>;
|
|
189
|
-
/**
|
|
190
|
-
* Get drep data with fallback between backends
|
|
191
|
-
* @param drepId drep id
|
|
192
|
-
* @returns {Promise<DrepData>} drep data
|
|
193
|
-
*/
|
|
194
109
|
getDrep(drepId: string): Promise<DrepData>;
|
|
110
|
+
getAccount(stakeAddress: string): Promise<AccountData>;
|
|
195
111
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* @returns {Promise<AccountData>} account data
|
|
112
|
+
* Whether the reward account is registered in the ledger. Node first; the first backend that
|
|
113
|
+
* answers decides, its "not found" means not registered. Only a backend failure falls through.
|
|
199
114
|
*/
|
|
200
|
-
getAccount(stakeAddress: string): Promise<AccountData>;
|
|
201
115
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
116
|
+
* Whether the stake credential is registered. The node's reward-account summary proves it, but
|
|
117
|
+
* the summary lists only credentials delegated to a pool or a DRep, so its absence proves nothing and the
|
|
118
|
+
* providers answer from the certificate history; one that knows the account decides, one that
|
|
119
|
+
* knows no such account means not registered. `null`: nobody could tell (no summary on the
|
|
120
|
+
* node, no provider configured or reachable).
|
|
206
121
|
*/
|
|
122
|
+
isRewardAccountRegistered(stakeAddress: string): Promise<boolean | null>;
|
|
123
|
+
/** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
|
|
207
124
|
getAssetInfo(unit: string): Promise<AssetInfo>;
|
|
208
125
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* Ogmios doesn't implement — fallback skips it via the optional method check.
|
|
212
|
-
* @param unit policyId + assetNameHex (concatenated hex)
|
|
213
|
-
* @param limit max number of events (default 100)
|
|
214
|
-
* @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
|
|
126
|
+
* Latest mint/burn events for an asset, most recent first. Prefers Koios (block timestamps);
|
|
127
|
+
* Blockfrost is the fallback with timestamps left null.
|
|
215
128
|
*/
|
|
216
129
|
getAssetHistory(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
|
|
217
130
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* falls back to getAddressTransactions() and extracts hashes.
|
|
221
|
-
* @param address bech32 address
|
|
222
|
-
* @param limit maximum number of hashes
|
|
223
|
-
* @returns {Promise<string[]>} list of transaction hashes
|
|
131
|
+
* Transaction hashes for an address; falls back to a full getAddressTransactions when no
|
|
132
|
+
* backend supports the lightweight listing.
|
|
224
133
|
*/
|
|
225
134
|
getAddressTransactionHashes(address: string, limit: number): Promise<string[]>;
|
|
226
|
-
/**
|
|
227
|
-
* Batch fetch multiple transactions by hash.
|
|
228
|
-
* Uses getTransactionsBatch() if backend supports it, otherwise
|
|
229
|
-
* falls back to individual getTransaction() calls (still coalesced).
|
|
230
|
-
* @param txHashes array of transaction hashes
|
|
231
|
-
* @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
|
|
232
|
-
*/
|
|
135
|
+
/** Batch fetch transactions by hash; falls back to individual coalesced getTransaction calls. */
|
|
233
136
|
getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
|
|
234
|
-
/**
|
|
235
|
-
* Backends in historical-first order. Used by the batch methods — both
|
|
236
|
-
* always prefer historical data, so the former preferLive parameter was a
|
|
237
|
-
* dead branch.
|
|
238
|
-
*/
|
|
137
|
+
/** Backends in historical-first order, for the batch methods. */
|
|
239
138
|
private getOrderedBackends;
|
|
240
139
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* Backends whose init() failed are skipped — the crawler uses these instances
|
|
244
|
-
* DIRECTLY (outside executeWithPriority's lazy-retry/breaker), so handing out an
|
|
245
|
-
* uninitialized backend would wedge it.
|
|
140
|
+
* A backend that supports streamed chain-sync (Ogmios), or null. Backends whose init failed
|
|
141
|
+
* are skipped: the crawler uses these instances directly, outside the lazy-retry/breaker path.
|
|
246
142
|
*/
|
|
247
143
|
getChainSyncBackend(): ChainSyncBackend | null;
|
|
248
144
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* Skips backends whose init() failed (see getChainSyncBackend).
|
|
252
|
-
*
|
|
253
|
-
* Koios is preferred over Blockfrost for bulk block-crawling: Koios batches 100 txs
|
|
254
|
-
* per POST /tx_info, while Blockfrost has no batch endpoint (~3 HTTP calls per tx) —
|
|
255
|
-
* roughly a 40x difference in request volume per crawled block.
|
|
145
|
+
* getChainSyncBackend(), retrying a failed startup init. Polled by the crawler while it runs
|
|
146
|
+
* on pagination because no chain-sync source was usable when it started.
|
|
256
147
|
*/
|
|
257
|
-
|
|
148
|
+
recoverChainSyncBackend(): Promise<ChainSyncBackend | null>;
|
|
149
|
+
/** The first usable backend that can dump the UTxO set at a point (Ogmios) — crawler.utxoSet import. */
|
|
150
|
+
getLedgerStateBackend(): LedgerStateBackend | null;
|
|
258
151
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
152
|
+
* Outputs among `refs` that are unspent at the tip, read from the node's ledger (Ogmios, or a remote
|
|
153
|
+
* ODATANO that asks its node); null when no backend can (the caller then resolves via the producing
|
|
154
|
+
* transaction, which carries no reference-script bytes).
|
|
262
155
|
*/
|
|
263
|
-
|
|
156
|
+
getUnspentOutputs(refs: Array<{
|
|
157
|
+
txHash: string;
|
|
158
|
+
outputIndex: number;
|
|
159
|
+
}>): Promise<UTxO[] | null>;
|
|
160
|
+
/** A usable backend answering output-reference lookups without a whole-ledger dump (the odatano backend). */
|
|
161
|
+
private outputLookupBackend;
|
|
162
|
+
/** True when an initialized backend implements `method` and does not declare it unsupported. */
|
|
163
|
+
hasBackendFor(method: string): boolean;
|
|
164
|
+
/** A backend that reads pool/DRep/pot state at a block (Ogmios) — preferred source of epoch snapshots. */
|
|
165
|
+
getEpochStateBackend(): EpochStateBackend | null;
|
|
264
166
|
/**
|
|
265
|
-
*
|
|
167
|
+
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
168
|
+
* snapshots stay off instead of degrading into thousands of single requests.
|
|
266
169
|
*/
|
|
267
|
-
|
|
170
|
+
getEnumeratingBackend(): EnumeratingBackend | null;
|
|
268
171
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
172
|
+
* A backend that can be walked forward by pagination (Blockfrost/Koios), or null. Koios is
|
|
173
|
+
* preferred: it batches 100 txs per call, Blockfrost needs ~3 calls per tx.
|
|
271
174
|
*/
|
|
175
|
+
getPaginatingBackend(): PaginatingBackend | null;
|
|
176
|
+
/** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
|
|
177
|
+
getProtocolParameters(): Promise<LedgerProtocolParameters>;
|
|
178
|
+
/** Shut down all backends. */
|
|
179
|
+
shutdown(): Promise<void>;
|
|
272
180
|
getLatestBlock(): Promise<BlockData>;
|
|
273
|
-
/**
|
|
274
|
-
* Get latest epoch data with fallback between backends
|
|
275
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
276
|
-
*/
|
|
277
181
|
getLatestEpoch(): Promise<EpochData>;
|
|
278
|
-
/**
|
|
279
|
-
* Get the current chain slot with fallback between backends.
|
|
280
|
-
* @returns {Promise<number>} current chain slot
|
|
281
|
-
*/
|
|
282
182
|
getCurrentSlot(): Promise<number>;
|
|
283
|
-
/**
|
|
284
|
-
* Check whether a UTxO is still unspent with fallback between backends.
|
|
285
|
-
* @param txHash 64-char lowercase hex transaction hash
|
|
286
|
-
* @param outputIndex non-negative integer output index
|
|
287
|
-
* @returns {Promise<boolean>} true iff the UTxO exists and is unspent
|
|
288
|
-
*/
|
|
183
|
+
/** True iff the UTxO exists and is unspent. */
|
|
289
184
|
isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
|
|
290
185
|
/**
|
|
291
|
-
* Submit transaction
|
|
292
|
-
*
|
|
293
|
-
* @returns {Promise<string>} transaction hash
|
|
294
|
-
*
|
|
295
|
-
* NOTE on failover semantics: when the preferred backend ACCEPTS the tx but
|
|
296
|
-
* its response is lost (timeout), the failover resubmits on the next backend,
|
|
297
|
-
* which may answer 409 "already submitted". Callers should treat a
|
|
298
|
-
* TransactionAlreadySubmittedError after a submit attempt as success — the
|
|
299
|
-
* transaction IS in the mempool.
|
|
186
|
+
* Submit a signed transaction (CBOR hex); returns its hash. On failover after a lost response
|
|
187
|
+
* the next backend may answer 409 "already submitted" — callers treat that as success.
|
|
300
188
|
*/
|
|
301
189
|
submitTransaction(signedTxCbor: string): Promise<string>;
|
|
302
|
-
/**
|
|
303
|
-
* Check if Ogmios backend is available for transaction evaluation
|
|
304
|
-
* @returns {boolean} true if Ogmios is the live backend
|
|
305
|
-
*/
|
|
190
|
+
/** True when Ogmios is the live backend. */
|
|
306
191
|
hasOgmiosBackend(): boolean;
|
|
307
|
-
/**
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
192
|
+
/** The backend that evaluates scripts: the live one (Ogmios), else an evaluating historical one (odatano). */
|
|
193
|
+
private evaluatingBackend;
|
|
194
|
+
/** True when some backend can evaluate script execution units. */
|
|
195
|
+
hasEvaluatingBackend(): boolean;
|
|
196
|
+
/** Evaluate script execution units of an unsigned transaction. */
|
|
312
197
|
evaluateTransaction(unsignedTxCbor: string): Promise<ScriptEvaluationResult[]>;
|
|
313
198
|
}
|
|
314
199
|
//# sourceMappingURL=cardano-client.d.ts.map
|