@odatano/core 2.0.0-rc.21 → 2.0.0-rc.24
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/CardanoBackendService/index.d.ts +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +18 -0
- package/@cds-models/CardanoIndexerService/index.js +3 -0
- package/@cds-models/CardanoODataService/index.d.ts +37 -0
- package/@cds-models/CardanoODataService/index.js +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +37 -0
- package/@cds-models/odatano/cardano/index.js +3 -0
- package/db/schema.cds +2226 -2133
- package/package.json +182 -181
- package/srv/blockchain/backends/cardano-backend.d.ts +23 -0
- package/srv/blockchain/backends/cardano-backend.js +5 -0
- package/srv/blockchain/backends/odatano-backend.d.ts +59 -0
- package/srv/blockchain/backends/odatano-backend.js +154 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +92 -9
- package/srv/blockchain/backends/ogmios-backend.js +164 -32
- package/srv/blockchain/cardano-client.d.ts +19 -5
- package/srv/blockchain/cardano-client.js +53 -12
- package/srv/blockchain/cardano-indexer.d.ts +100 -4
- package/srv/blockchain/cardano-indexer.js +466 -23
- package/srv/blockchain/cardano-tx-builder.js +2 -2
- package/srv/blockchain/crawler/crawler.d.ts +20 -5
- package/srv/blockchain/crawler/crawler.js +78 -15
- package/srv/blockchain/crawler/utxo-set-import.js +3 -0
- package/srv/blockchain/ledger-state.d.ts +6 -0
- package/srv/blockchain/ledger-state.js +29 -0
- package/srv/blockchain/stored-chain.d.ts +30 -0
- package/srv/blockchain/stored-chain.js +208 -0
- package/srv/cardano-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +217 -0
- package/srv/cardano-indexer-service.cds +176 -164
- package/srv/cardano-indexer-service.js +30 -0
- package/srv/cardano-service.cds +6 -1
- package/srv/cardano-service.js +5 -2
- package/srv/server.js +19 -2
- package/srv/utils/agent-grants.js +7 -0
- package/srv/utils/const.d.ts +4 -0
- package/srv/utils/const.js +4 -3
- package/srv/utils/db-indexes.js +1 -0
- package/srv/utils/errors.d.ts +8 -0
- package/srv/utils/errors.js +14 -1
- package/srv/utils/mappers.d.ts +19 -2
- package/srv/utils/mappers.js +25 -7
- package/srv/utils/types.d.ts +8 -1
|
@@ -1,10 +1,84 @@
|
|
|
1
1
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, AccountData, DrepData, AssetInfo, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
|
|
2
|
-
import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint, LedgerStateBackend } from './cardano-backend';
|
|
2
|
+
import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint, LedgerStateBackend, EpochStateBackend, EpochLedgerState } from './cardano-backend';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
|
+
/** Ogmios response shapes not fully typed in @cardano-ogmios/client. */
|
|
5
|
+
interface OgmiosStakePool {
|
|
6
|
+
vrfVerificationKeyHash?: string;
|
|
7
|
+
stake?: {
|
|
8
|
+
ada?: {
|
|
9
|
+
lovelace?: number | bigint;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
pledge?: {
|
|
13
|
+
ada?: {
|
|
14
|
+
lovelace?: number | bigint;
|
|
15
|
+
};
|
|
16
|
+
} | number | bigint;
|
|
17
|
+
margin?: number | string;
|
|
18
|
+
cost?: {
|
|
19
|
+
ada?: {
|
|
20
|
+
lovelace?: number | bigint;
|
|
21
|
+
};
|
|
22
|
+
} | number | bigint;
|
|
23
|
+
rewardAccount?: string;
|
|
24
|
+
}
|
|
4
25
|
/** Hash of an Ogmios `Script`: blake2b-224 over the language tag byte followed by the script CBOR. */
|
|
5
26
|
export declare function ogmiosScriptHash(script: unknown): string | null;
|
|
6
27
|
/** Bech32 pool id of a block issuer: blake2b-224 of its cold verification key. */
|
|
7
28
|
export declare function issuerKeyToPoolId(verificationKeyHex: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Ogmios v6 `queryLedgerState/delegateRepresentatives` summary (local wire type; the schema
|
|
31
|
+
* package is only a transitive dependency). Only the `registered` variant carries an id.
|
|
32
|
+
*/
|
|
33
|
+
interface OgmiosDrepSummary {
|
|
34
|
+
type: 'registered' | 'noConfidence' | 'abstain';
|
|
35
|
+
id?: string;
|
|
36
|
+
from?: 'verificationKey' | 'script';
|
|
37
|
+
mandate?: {
|
|
38
|
+
epoch?: number;
|
|
39
|
+
};
|
|
40
|
+
stake?: {
|
|
41
|
+
ada?: {
|
|
42
|
+
lovelace?: number | bigint;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
deposit?: {
|
|
46
|
+
ada?: {
|
|
47
|
+
lovelace?: number | bigint;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
delegators?: unknown[];
|
|
51
|
+
}
|
|
52
|
+
/** Ogmios `stakePoolsPerformances`: only nOpt is used — its stake figures are live, not active. */
|
|
53
|
+
interface OgmiosStakePoolsPerformances {
|
|
54
|
+
desiredNumberOfStakePools?: number;
|
|
55
|
+
}
|
|
56
|
+
/** Raw Ogmios answers for one epoch snapshot, all read at the same acquired block. */
|
|
57
|
+
export interface OgmiosEpochStateRaw {
|
|
58
|
+
epoch: number;
|
|
59
|
+
stakePools: Record<string, OgmiosStakePool>;
|
|
60
|
+
performances: OgmiosStakePoolsPerformances | null;
|
|
61
|
+
dreps: OgmiosDrepSummary[];
|
|
62
|
+
pots: {
|
|
63
|
+
treasury?: {
|
|
64
|
+
ada?: {
|
|
65
|
+
lovelace?: number | bigint;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
reserves?: {
|
|
69
|
+
ada?: {
|
|
70
|
+
lovelace?: number | bigint;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
} | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Ogmios ledger answers -> EpochLedgerState. Saturation follows the ledger: live stake over
|
|
77
|
+
* (max supply - reserves) / nOpt. Figures the ledger view does not carry stay 0 / null: active
|
|
78
|
+
* stake (the indexer derives it from the previous snapshot), block counts, delegator counts,
|
|
79
|
+
* DRep last activity.
|
|
80
|
+
*/
|
|
81
|
+
export declare function mapOgmiosEpochState(raw: OgmiosEpochStateRaw): EpochLedgerState;
|
|
8
82
|
/**
|
|
9
83
|
* Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into credential hash and type. Header byte:
|
|
10
84
|
* high nibble 0x2 = DRep, low nibble 0x2 = key hash / 0x3 = script hash.
|
|
@@ -24,12 +98,11 @@ export declare function resolveOgmiosTip(tip: 'origin' | {
|
|
|
24
98
|
/** Resolve Ogmios block height which may be 'origin' (genesis block) or a number */
|
|
25
99
|
export declare function resolveOgmiosHeight(height: 'origin' | number): number;
|
|
26
100
|
/** CardanoBackend implementation over an Ogmios WebSocket (local node). */
|
|
27
|
-
export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBackend, LedgerStateBackend {
|
|
101
|
+
export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBackend, LedgerStateBackend, EpochStateBackend {
|
|
28
102
|
readonly name = "ogmios";
|
|
29
103
|
/**
|
|
30
104
|
* Capability declaration — the orchestrator skips Ogmios for these without counting
|
|
31
|
-
* circuit failures. Historic queries are out of protocol scope
|
|
32
|
-
* cannot be derived from state queries.
|
|
105
|
+
* circuit failures. Historic queries are out of protocol scope.
|
|
33
106
|
*/
|
|
34
107
|
readonly unsupportedMethods: ReadonlySet<string>;
|
|
35
108
|
private stateQueryClient;
|
|
@@ -111,10 +184,10 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
|
|
|
111
184
|
*/
|
|
112
185
|
getNetworkInformation(): Promise<NetworkInformation>;
|
|
113
186
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
187
|
+
* Address at the tip: type, script flag and stake address decoded from the address itself,
|
|
188
|
+
* UTxOs from the ledger, balance summed over them. No transaction history (getAddressTransactions).
|
|
116
189
|
*/
|
|
117
|
-
getAddress(
|
|
190
|
+
getAddress(address: string): Promise<Address>;
|
|
118
191
|
/** get current specific Address UTxOs
|
|
119
192
|
* @param address bech32 address
|
|
120
193
|
* @returns {Promise<UTxO[]>} address UTxOs
|
|
@@ -123,11 +196,18 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
|
|
|
123
196
|
/** Ogmios `Utxo` entry → normalized UTxO line (shared by the address query and the set import). */
|
|
124
197
|
private mapOgmiosUtxo;
|
|
125
198
|
/**
|
|
126
|
-
*
|
|
199
|
+
* Run `fn` against the ledger state acquired at `point` on a SEPARATE WebSocket: local-state-query
|
|
127
200
|
* holds one acquired point per connection, so the shared socket would pin live queries to the past.
|
|
128
|
-
* The point must be inside the node's volatile window (
|
|
201
|
+
* The point must be inside the node's volatile window (k blocks) or acquisition is refused.
|
|
129
202
|
*/
|
|
203
|
+
private withLedgerStateAt;
|
|
204
|
+
/** Whole UTxO set as of `point` (crawler snapshot import). */
|
|
130
205
|
queryUtxoSetAt(point: ChainPoint): Promise<UTxO[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Pools, DReps and pots as of `point` (crawler epoch snapshot), all read from one acquired
|
|
208
|
+
* ledger state. Performances are optional: without them (no nOpt) saturation stays 0.
|
|
209
|
+
*/
|
|
210
|
+
epochStateAt(point: ChainPoint): Promise<EpochLedgerState>;
|
|
131
211
|
/** Not supported — Ogmios is a live state-query backend; use Blockfrost/Koios. */
|
|
132
212
|
getAddressTransactions(_address: string): Promise<Transaction[]>;
|
|
133
213
|
/**
|
|
@@ -180,6 +260,8 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
|
|
|
180
260
|
* @param outputIndex non-negative integer
|
|
181
261
|
*/
|
|
182
262
|
isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
|
|
263
|
+
/** Unspent outputs of several addresses in the live ledger (one query per 100 addresses). */
|
|
264
|
+
getUtxosByAddresses(addresses: string[]): Promise<UTxO[]>;
|
|
183
265
|
/** Outputs among `refs` that are unspent in the live ledger; spent or unknown references are absent. */
|
|
184
266
|
getUnspentOutputs(refs: Array<{
|
|
185
267
|
txHash: string;
|
|
@@ -219,4 +301,5 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
|
|
|
219
301
|
*/
|
|
220
302
|
private mapOgmiosCertificates;
|
|
221
303
|
}
|
|
304
|
+
export {};
|
|
222
305
|
//# sourceMappingURL=ogmios-backend.d.ts.map
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.OgmiosBackend = void 0;
|
|
7
7
|
exports.ogmiosScriptHash = ogmiosScriptHash;
|
|
8
8
|
exports.issuerKeyToPoolId = issuerKeyToPoolId;
|
|
9
|
+
exports.mapOgmiosEpochState = mapOgmiosEpochState;
|
|
9
10
|
exports.decodeDrepId = decodeDrepId;
|
|
10
11
|
exports.resolveOgmiosTip = resolveOgmiosTip;
|
|
11
12
|
exports.resolveOgmiosHeight = resolveOgmiosHeight;
|
|
@@ -69,6 +70,82 @@ function ogmiosValueToLovelaceString(value) {
|
|
|
69
70
|
const lovelace = value.ada?.lovelace;
|
|
70
71
|
return lovelace === undefined ? '0' : String(lovelace);
|
|
71
72
|
}
|
|
73
|
+
/** Fraction a/b of two lovelace amounts; 0 when b is 0. */
|
|
74
|
+
function ratio(a, b) {
|
|
75
|
+
return b === 0n ? 0 : Number((a * 1000000n) / b) / 1_000_000;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Ogmios ledger answers -> EpochLedgerState. Saturation follows the ledger: live stake over
|
|
79
|
+
* (max supply - reserves) / nOpt. Figures the ledger view does not carry stay 0 / null: active
|
|
80
|
+
* stake (the indexer derives it from the previous snapshot), block counts, delegator counts,
|
|
81
|
+
* DRep last activity.
|
|
82
|
+
*/
|
|
83
|
+
function mapOgmiosEpochState(raw) {
|
|
84
|
+
const lovelace = (v) => BigInt(ogmiosValueToLovelaceString(v));
|
|
85
|
+
const reserves = raw.pots?.reserves ? lovelace(raw.pots.reserves) : null;
|
|
86
|
+
const nOpt = raw.performances?.desiredNumberOfStakePools ?? 0;
|
|
87
|
+
const saturationPoint = reserves != null && nOpt > 0
|
|
88
|
+
? (BigInt(const_1.CARDANO_DEFAULTS.MAX_LOVELACE_SUPPLY) - reserves) / BigInt(nOpt)
|
|
89
|
+
: 0n;
|
|
90
|
+
const entries = Object.entries(raw.stakePools);
|
|
91
|
+
const liveTotal = entries.reduce((sum, [, p]) => sum + lovelace(p.stake), 0n);
|
|
92
|
+
const pools = entries.map(([poolId, p]) => {
|
|
93
|
+
const live = lovelace(p.stake);
|
|
94
|
+
return {
|
|
95
|
+
poolId,
|
|
96
|
+
vrfKeyHash: p.vrfVerificationKeyHash || '',
|
|
97
|
+
blocksMinted: 0,
|
|
98
|
+
blocksEpoch: null,
|
|
99
|
+
liveStake: live.toString(),
|
|
100
|
+
liveSize: ratio(live, liveTotal),
|
|
101
|
+
liveSaturation: ratio(live, saturationPoint),
|
|
102
|
+
liveDelegators: null,
|
|
103
|
+
activeStake: '0',
|
|
104
|
+
activeSize: 0,
|
|
105
|
+
pledge: ogmiosValueToLovelaceString(p.pledge),
|
|
106
|
+
margin: parseOgmiosRatio(p.margin),
|
|
107
|
+
fixedCost: ogmiosValueToLovelaceString(p.cost),
|
|
108
|
+
rewardAccount: p.rewardAccount || '',
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
let abstain = null;
|
|
112
|
+
let noConfidence = null;
|
|
113
|
+
const dreps = [];
|
|
114
|
+
for (const d of raw.dreps) {
|
|
115
|
+
if (d.type === 'abstain') {
|
|
116
|
+
abstain = (abstain ?? 0n) + lovelace(d.stake);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (d.type === 'noConfidence') {
|
|
120
|
+
noConfidence = (noConfidence ?? 0n) + lovelace(d.stake);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (d.type !== 'registered' || !d.id)
|
|
124
|
+
continue;
|
|
125
|
+
const mandate = d.mandate?.epoch;
|
|
126
|
+
dreps.push({
|
|
127
|
+
drepId: (0, mappers_1.credentialToDrepId)(d.id, d.from === 'script'),
|
|
128
|
+
hex: d.id,
|
|
129
|
+
amount: ogmiosValueToLovelaceString(d.stake),
|
|
130
|
+
hasScript: d.from === 'script',
|
|
131
|
+
lastActiveEpoch: 0,
|
|
132
|
+
expired: typeof mandate === 'number' && mandate < raw.epoch,
|
|
133
|
+
retired: false,
|
|
134
|
+
deposit: d.deposit ? ogmiosValueToLovelaceString(d.deposit) : null,
|
|
135
|
+
expiresEpoch: typeof mandate === 'number' ? mandate : null,
|
|
136
|
+
delegatorCount: Array.isArray(d.delegators) ? d.delegators.length : null,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
epoch: raw.epoch,
|
|
141
|
+
pools,
|
|
142
|
+
dreps,
|
|
143
|
+
treasury: raw.pots?.treasury ? ogmiosValueToLovelaceString(raw.pots.treasury) : null,
|
|
144
|
+
reserves: reserves == null ? null : reserves.toString(),
|
|
145
|
+
drepAbstainStake: abstain == null ? null : abstain.toString(),
|
|
146
|
+
drepNoConfidenceStake: noConfidence == null ? null : noConfidence.toString(),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
72
149
|
/**
|
|
73
150
|
* Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into credential hash and type. Header byte:
|
|
74
151
|
* high nibble 0x2 = DRep, low nibble 0x2 = key hash / 0x3 = script hash.
|
|
@@ -97,8 +174,7 @@ class OgmiosBackend {
|
|
|
97
174
|
name = 'ogmios';
|
|
98
175
|
/**
|
|
99
176
|
* Capability declaration — the orchestrator skips Ogmios for these without counting
|
|
100
|
-
* circuit failures. Historic queries are out of protocol scope
|
|
101
|
-
* cannot be derived from state queries.
|
|
177
|
+
* circuit failures. Historic queries are out of protocol scope.
|
|
102
178
|
*/
|
|
103
179
|
unsupportedMethods = new Set([
|
|
104
180
|
// getEpoch is NOT listed: Ogmios can serve the CURRENT epoch and only
|
|
@@ -110,7 +186,6 @@ class OgmiosBackend {
|
|
|
110
186
|
// getDrep is NOT listed: served from the live ledger state via
|
|
111
187
|
// queryLedgerState/delegateRepresentatives (Ogmios ≥ 6.4).
|
|
112
188
|
'getAssetInfo',
|
|
113
|
-
'getAddress',
|
|
114
189
|
]);
|
|
115
190
|
stateQueryClient = null;
|
|
116
191
|
txSubmissionClient = null;
|
|
@@ -386,12 +461,23 @@ class OgmiosBackend {
|
|
|
386
461
|
}, this.name);
|
|
387
462
|
}
|
|
388
463
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
464
|
+
* Address at the tip: type, script flag and stake address decoded from the address itself,
|
|
465
|
+
* UTxOs from the ledger, balance summed over them. No transaction history (getAddressTransactions).
|
|
391
466
|
*/
|
|
392
|
-
async getAddress(
|
|
467
|
+
async getAddress(address) {
|
|
393
468
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
394
|
-
|
|
469
|
+
await this.ensureConnected();
|
|
470
|
+
const decoded = (0, mappers_1.decodeShelleyAddress)(address);
|
|
471
|
+
const raw = await this.stateQueryClient.utxo({ addresses: [address] });
|
|
472
|
+
const utxos = raw.map((u) => this.mapOgmiosUtxo(u, address));
|
|
473
|
+
return {
|
|
474
|
+
address,
|
|
475
|
+
stakeAddress: decoded.stakeAddress,
|
|
476
|
+
type: decoded.type,
|
|
477
|
+
isScript: decoded.isScript,
|
|
478
|
+
amount: (0, mappers_1.sumUtxoAmounts)(utxos),
|
|
479
|
+
utxos,
|
|
480
|
+
};
|
|
395
481
|
}, this.name);
|
|
396
482
|
}
|
|
397
483
|
/** get current specific Address UTxOs
|
|
@@ -420,33 +506,63 @@ class OgmiosBackend {
|
|
|
420
506
|
};
|
|
421
507
|
}
|
|
422
508
|
/**
|
|
423
|
-
*
|
|
509
|
+
* Run `fn` against the ledger state acquired at `point` on a SEPARATE WebSocket: local-state-query
|
|
424
510
|
* holds one acquired point per connection, so the shared socket would pin live queries to the past.
|
|
425
|
-
* The point must be inside the node's volatile window (
|
|
511
|
+
* The point must be inside the node's volatile window (k blocks) or acquisition is refused.
|
|
426
512
|
*/
|
|
427
|
-
async
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
try {
|
|
442
|
-
await client.shutdown();
|
|
443
|
-
}
|
|
444
|
-
catch { /* best effort */ }
|
|
513
|
+
async withLedgerStateAt(point, label, fn) {
|
|
514
|
+
const url = new URL(this.ogmiosUrl);
|
|
515
|
+
const connection = { host: url.hostname, port: Number(url.port) || (url.protocol === 'wss:' ? 443 : 80), tls: url.protocol === 'wss:' };
|
|
516
|
+
const context = await (0, client_1.createInteractionContext)((err) => logger.error(`[OgmiosBackend] ${label} context error: ${err.message}`), () => { }, { connection });
|
|
517
|
+
let client = null;
|
|
518
|
+
try {
|
|
519
|
+
client = await (0, client_1.createLedgerStateQueryClient)(context, { point: { slot: point.slot, id: point.hash } });
|
|
520
|
+
return await fn(client);
|
|
521
|
+
}
|
|
522
|
+
finally {
|
|
523
|
+
// shutdown() closes THIS connection only; the backend's own socket is untouched
|
|
524
|
+
if (client) {
|
|
525
|
+
try {
|
|
526
|
+
await client.shutdown();
|
|
445
527
|
}
|
|
446
|
-
|
|
447
|
-
this.forceCloseContext(context);
|
|
528
|
+
catch { /* best effort */ }
|
|
448
529
|
}
|
|
449
|
-
|
|
530
|
+
else
|
|
531
|
+
this.forceCloseContext(context);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/** Whole UTxO set as of `point` (crawler snapshot import). */
|
|
535
|
+
async queryUtxoSetAt(point) {
|
|
536
|
+
return (0, backend_request_handler_1.handleBackendRequest)(() => this.withLedgerStateAt(point, 'snapshot', async (client) => {
|
|
537
|
+
const utxos = await client.utxo();
|
|
538
|
+
return utxos.map((u) => this.mapOgmiosUtxo(u));
|
|
539
|
+
}), this.name);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Pools, DReps and pots as of `point` (crawler epoch snapshot), all read from one acquired
|
|
543
|
+
* ledger state. Performances are optional: without them (no nOpt) saturation stays 0.
|
|
544
|
+
*/
|
|
545
|
+
async epochStateAt(point) {
|
|
546
|
+
return (0, backend_request_handler_1.handleBackendRequest)(() => this.withLedgerStateAt(point, 'epoch snapshot', async (client) => {
|
|
547
|
+
const ctx = client.context;
|
|
548
|
+
const [epoch, stakePools, performances, dreps, pots] = await Promise.all([
|
|
549
|
+
client.epoch(),
|
|
550
|
+
client.stakePools(undefined, true),
|
|
551
|
+
client.stakePoolsPerformances().catch((err) => {
|
|
552
|
+
logger.warn(`stakePoolsPerformances unavailable, saturation stays 0: ${err?.message ?? err}`);
|
|
553
|
+
return null;
|
|
554
|
+
}),
|
|
555
|
+
(0, client_1.Method)({ method: 'queryLedgerState/delegateRepresentatives' }, {}, ctx),
|
|
556
|
+
(0, client_1.Method)({ method: 'queryLedgerState/treasuryAndReserves' }, {}, ctx),
|
|
557
|
+
]);
|
|
558
|
+
return mapOgmiosEpochState({
|
|
559
|
+
epoch: Number(epoch),
|
|
560
|
+
stakePools: (stakePools ?? {}),
|
|
561
|
+
performances: performances,
|
|
562
|
+
dreps: Array.isArray(dreps) ? dreps : [],
|
|
563
|
+
pots: pots ?? null,
|
|
564
|
+
});
|
|
565
|
+
}), this.name);
|
|
450
566
|
}
|
|
451
567
|
/** Not supported — Ogmios is a live state-query backend; use Blockfrost/Koios. */
|
|
452
568
|
async getAddressTransactions(_address) {
|
|
@@ -474,7 +590,8 @@ class OgmiosBackend {
|
|
|
474
590
|
blocksEpoch: null,
|
|
475
591
|
liveStake: pool.stake?.ada?.lovelace ? String(pool.stake.ada.lovelace) : '0',
|
|
476
592
|
liveSize: 0,
|
|
477
|
-
|
|
593
|
+
// not in the ledger state; null = unavailable
|
|
594
|
+
liveDelegators: null,
|
|
478
595
|
liveSaturation: 0,
|
|
479
596
|
// activeStake is not available from Ogmios pool params — report 0 instead
|
|
480
597
|
// of fabricating it from the pledge
|
|
@@ -687,6 +804,21 @@ class OgmiosBackend {
|
|
|
687
804
|
return Array.isArray(result) && result.length > 0;
|
|
688
805
|
}, this.name);
|
|
689
806
|
}
|
|
807
|
+
/** Unspent outputs of several addresses in the live ledger (one query per 100 addresses). */
|
|
808
|
+
async getUtxosByAddresses(addresses) {
|
|
809
|
+
if (addresses.length === 0)
|
|
810
|
+
return [];
|
|
811
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
812
|
+
await this.ensureConnected();
|
|
813
|
+
const out = [];
|
|
814
|
+
for (let i = 0; i < addresses.length; i += 100) {
|
|
815
|
+
const utxos = await this.stateQueryClient.utxo({ addresses: addresses.slice(i, i + 100) });
|
|
816
|
+
for (const u of utxos)
|
|
817
|
+
out.push(this.mapOgmiosUtxo(u));
|
|
818
|
+
}
|
|
819
|
+
return out;
|
|
820
|
+
}, this.name);
|
|
821
|
+
}
|
|
690
822
|
/** Outputs among `refs` that are unspent in the live ledger; spent or unknown references are absent. */
|
|
691
823
|
async getUnspentOutputs(refs) {
|
|
692
824
|
if (refs.length === 0)
|
|
@@ -806,7 +938,7 @@ class OgmiosBackend {
|
|
|
806
938
|
if (intentionalClose || this.isShutdown)
|
|
807
939
|
return;
|
|
808
940
|
const detail = reason?.toString() || 'no reason supplied';
|
|
809
|
-
const err = new errors_1.
|
|
941
|
+
const err = new errors_1.ChainSyncClosedError(`Ogmios chain-sync socket closed unexpectedly (code ${code}: ${detail})`, this.name);
|
|
810
942
|
logger.warn(`[OgmiosBackend] ${err.message}`);
|
|
811
943
|
void reportStreamError(err);
|
|
812
944
|
}, { connection });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend, LedgerStateBackend } from './backends/cardano-backend';
|
|
1
|
+
import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend, LedgerStateBackend, EpochStateBackend } from './backends/cardano-backend';
|
|
2
2
|
import { type CircuitBreakerConfig } from './circuit-breaker';
|
|
3
3
|
import { Transaction, Address, UTxO, NetworkInformation, BlockData, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../utils/types';
|
|
4
4
|
export type Network = 'mainnet' | 'preview' | 'preprod';
|
|
5
|
-
export type BackendName = 'blockfrost' | 'koios' | 'ogmios';
|
|
5
|
+
export type BackendName = 'blockfrost' | 'koios' | 'ogmios' | 'odatano';
|
|
6
6
|
export type TransactionBuilderName = 'buildooor';
|
|
7
7
|
export type CardanoClientConfig = {
|
|
8
8
|
network: Network;
|
|
@@ -11,6 +11,10 @@ export type CardanoClientConfig = {
|
|
|
11
11
|
blockfrostCustomBackend?: string;
|
|
12
12
|
koiosApiKey: string;
|
|
13
13
|
ogmiosUrl: string;
|
|
14
|
+
/** Remote ODATANO for the `odatano` backend; defaults to the public API of the network. */
|
|
15
|
+
odatanoUrl?: string;
|
|
16
|
+
/** Key for the remote ODATANO (a gateway `oda_…` key or an agent grant token). */
|
|
17
|
+
odatanoApiKey?: string;
|
|
14
18
|
transactionBuilders: TransactionBuilderName[];
|
|
15
19
|
primaryTimeoutMs: number;
|
|
16
20
|
fallbackTimeoutMs: number;
|
|
@@ -88,7 +92,7 @@ export declare class CardanoClient {
|
|
|
88
92
|
getAddressUtxos(address: string): Promise<UTxO[]>;
|
|
89
93
|
/**
|
|
90
94
|
* UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
|
|
91
|
-
*
|
|
95
|
+
* Needs a credential-keyed backend (Koios, or another ODATANO); Blockfrost has none.
|
|
92
96
|
*/
|
|
93
97
|
getCredentialUtxos(credHash: string): Promise<UTxO[]>;
|
|
94
98
|
getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
|
|
@@ -135,6 +139,12 @@ export declare class CardanoClient {
|
|
|
135
139
|
txHash: string;
|
|
136
140
|
outputIndex: number;
|
|
137
141
|
}>): Promise<UTxO[] | null>;
|
|
142
|
+
/** Unspent outputs of several addresses from the node's ledger; null when no ledger-state backend can do it. */
|
|
143
|
+
getUtxosByAddresses(addresses: string[]): Promise<UTxO[] | null>;
|
|
144
|
+
/** True when an initialized backend implements `method` and does not declare it unsupported. */
|
|
145
|
+
hasBackendFor(method: string): boolean;
|
|
146
|
+
/** A backend that reads pool/DRep/pot state at a block (Ogmios) — preferred source of epoch snapshots. */
|
|
147
|
+
getEpochStateBackend(): EpochStateBackend | null;
|
|
138
148
|
/**
|
|
139
149
|
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
140
150
|
* snapshots stay off instead of degrading into thousands of single requests.
|
|
@@ -159,9 +169,13 @@ export declare class CardanoClient {
|
|
|
159
169
|
* the next backend may answer 409 "already submitted" — callers treat that as success.
|
|
160
170
|
*/
|
|
161
171
|
submitTransaction(signedTxCbor: string): Promise<string>;
|
|
162
|
-
/** True when Ogmios is the live backend
|
|
172
|
+
/** True when Ogmios is the live backend. */
|
|
163
173
|
hasOgmiosBackend(): boolean;
|
|
164
|
-
/**
|
|
174
|
+
/** The backend that evaluates scripts: the live one (Ogmios), else an evaluating historical one (odatano). */
|
|
175
|
+
private evaluatingBackend;
|
|
176
|
+
/** True when some backend can evaluate script execution units. */
|
|
177
|
+
hasEvaluatingBackend(): boolean;
|
|
178
|
+
/** Evaluate script execution units of an unsigned transaction. */
|
|
165
179
|
evaluateTransaction(unsignedTxCbor: string): Promise<ScriptEvaluationResult[]>;
|
|
166
180
|
}
|
|
167
181
|
//# sourceMappingURL=cardano-client.d.ts.map
|
|
@@ -12,12 +12,14 @@ const request_coalescer_1 = require("./request-coalescer");
|
|
|
12
12
|
const ogmios_backend_1 = require("./backends/ogmios-backend");
|
|
13
13
|
const blockfrost_backend_1 = require("./backends/blockfrost-backend");
|
|
14
14
|
const koios_backend_1 = require("./backends/koios-backend");
|
|
15
|
+
const odatano_backend_1 = require("./backends/odatano-backend");
|
|
15
16
|
const logger = cds_1.default.log('CardanoClient');
|
|
16
17
|
/** Which backend type to prefer per method. */
|
|
17
18
|
const METHOD_ROUTING = {
|
|
18
19
|
getTransaction: { preferLive: false },
|
|
20
|
+
// node first: UTxOs at the tip; Ogmios decodes the type itself (base/enterprise/…, not shelley/byron)
|
|
19
21
|
getAddress: { preferLive: true },
|
|
20
|
-
getAddressUtxos: { preferLive:
|
|
22
|
+
getAddressUtxos: { preferLive: true },
|
|
21
23
|
getAddressTransactions: { preferLive: false },
|
|
22
24
|
// providers first: they report circulation; Ogmios only has treasury and reserves
|
|
23
25
|
getNetworkInformation: { preferLive: false },
|
|
@@ -29,7 +31,8 @@ const METHOD_ROUTING = {
|
|
|
29
31
|
getCurrentSlot: { preferLive: true },
|
|
30
32
|
isUtxoUnspent: { preferLive: true },
|
|
31
33
|
getPool: { preferLive: true },
|
|
32
|
-
|
|
34
|
+
// node first; a DRep the ledger no longer lists (retired) falls through to the providers
|
|
35
|
+
getDrep: { preferLive: true },
|
|
33
36
|
getAccount: { preferLive: true },
|
|
34
37
|
getAssetInfo: { preferLive: false },
|
|
35
38
|
getProtocolParameters: { preferLive: true },
|
|
@@ -70,6 +73,9 @@ class CardanoClient {
|
|
|
70
73
|
if (backends.includes('koios')) {
|
|
71
74
|
this.historicalBackends.push(new koios_backend_1.KoiosBackend(clientConfig.network, clientConfig.primaryTimeoutMs, clientConfig.koiosApiKey));
|
|
72
75
|
}
|
|
76
|
+
if (backends.includes('odatano')) {
|
|
77
|
+
this.historicalBackends.push(new odatano_backend_1.OdatanoBackend(clientConfig.network, clientConfig.primaryTimeoutMs, clientConfig.odatanoUrl, clientConfig.odatanoApiKey));
|
|
78
|
+
}
|
|
73
79
|
if (!this.liveBackend && this.historicalBackends.length === 0) {
|
|
74
80
|
throw new errors_1.ConfigError('No valid backends configured for CardanoClient');
|
|
75
81
|
}
|
|
@@ -308,15 +314,16 @@ class CardanoClient {
|
|
|
308
314
|
}
|
|
309
315
|
/**
|
|
310
316
|
* UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
|
|
311
|
-
*
|
|
317
|
+
* Needs a credential-keyed backend (Koios, or another ODATANO); Blockfrost has none.
|
|
312
318
|
*/
|
|
313
319
|
getCredentialUtxos(credHash) {
|
|
314
320
|
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
321
|
+
const capable = candidates.filter((b) => typeof b?.getCredentialUtxos === 'function');
|
|
322
|
+
const backend = capable.find(b => b.name === 'koios') ?? capable[0];
|
|
323
|
+
if (!backend) {
|
|
324
|
+
throw new errors_1.ProviderUnavailableError("getCredentialUtxos requires a Koios or odatano backend. Configure one in cds.requires.odatano-core.backends.", 'koios');
|
|
318
325
|
}
|
|
319
|
-
return this.credCoalescer.get(credHash, () => this.callWithResilience(
|
|
326
|
+
return this.credCoalescer.get(credHash, () => this.callWithResilience(backend, () => backend.getCredentialUtxos(credHash)));
|
|
320
327
|
}
|
|
321
328
|
getAddressTransactions(address, limit) {
|
|
322
329
|
return this.route('getAddressTransactions', b => b.getAddressTransactions(address, limit));
|
|
@@ -451,6 +458,28 @@ class CardanoClient {
|
|
|
451
458
|
const backend = this.getLedgerStateBackend();
|
|
452
459
|
return backend ? backend.getUnspentOutputs(refs) : null;
|
|
453
460
|
}
|
|
461
|
+
/** Unspent outputs of several addresses from the node's ledger; null when no ledger-state backend can do it. */
|
|
462
|
+
async getUtxosByAddresses(addresses) {
|
|
463
|
+
const backend = this.getLedgerStateBackend();
|
|
464
|
+
return backend?.getUtxosByAddresses ? backend.getUtxosByAddresses(addresses) : null;
|
|
465
|
+
}
|
|
466
|
+
/** True when an initialized backend implements `method` and does not declare it unsupported. */
|
|
467
|
+
hasBackendFor(method) {
|
|
468
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
469
|
+
return candidates.some((b) => !!b
|
|
470
|
+
&& !this.uninitializedBackends.has(b)
|
|
471
|
+
&& typeof b[method] === 'function'
|
|
472
|
+
&& !b.unsupportedMethods?.has(method));
|
|
473
|
+
}
|
|
474
|
+
/** A backend that reads pool/DRep/pot state at a block (Ogmios) — preferred source of epoch snapshots. */
|
|
475
|
+
getEpochStateBackend() {
|
|
476
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
477
|
+
for (const b of candidates) {
|
|
478
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isEpochStateBackend)(b))
|
|
479
|
+
return b;
|
|
480
|
+
}
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
454
483
|
/**
|
|
455
484
|
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
456
485
|
* snapshots stay off instead of degrading into thousands of single requests.
|
|
@@ -548,18 +577,30 @@ class CardanoClient {
|
|
|
548
577
|
submitTransaction(signedTxCbor) {
|
|
549
578
|
return this.route('submitTransaction', b => b.submitTransaction(signedTxCbor));
|
|
550
579
|
}
|
|
551
|
-
/** True when Ogmios is the live backend
|
|
580
|
+
/** True when Ogmios is the live backend. */
|
|
552
581
|
hasOgmiosBackend() {
|
|
553
582
|
return this.liveBackend?.name === 'ogmios';
|
|
554
583
|
}
|
|
555
|
-
/**
|
|
584
|
+
/** The backend that evaluates scripts: the live one (Ogmios), else an evaluating historical one (odatano). */
|
|
585
|
+
evaluatingBackend() {
|
|
586
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
587
|
+
for (const b of candidates)
|
|
588
|
+
if (b && (0, cardano_backend_1.isEvaluatingBackend)(b))
|
|
589
|
+
return b;
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
/** True when some backend can evaluate script execution units. */
|
|
593
|
+
hasEvaluatingBackend() {
|
|
594
|
+
return this.evaluatingBackend() != null;
|
|
595
|
+
}
|
|
596
|
+
/** Evaluate script execution units of an unsigned transaction. */
|
|
556
597
|
async evaluateTransaction(unsignedTxCbor) {
|
|
557
598
|
await this.ensureInitialized();
|
|
558
|
-
|
|
559
|
-
|
|
599
|
+
const backend = this.evaluatingBackend();
|
|
600
|
+
if (!backend) {
|
|
601
|
+
throw new errors_1.ProviderUnavailableError('Transaction evaluation requires an evaluating backend (Ogmios or odatano)');
|
|
560
602
|
}
|
|
561
603
|
// timeout + breaker, so a hanging socket cannot block Plutus builds
|
|
562
|
-
const backend = this.liveBackend;
|
|
563
604
|
return this.callWithResilience(backend, () => backend.evaluateTransaction(unsignedTxCbor));
|
|
564
605
|
}
|
|
565
606
|
}
|