@odatano/core 2.0.0-rc.20 → 2.0.0-rc.21
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/CardanoODataService/index.d.ts +7 -6
- package/@cds-models/odatano/cardano/index.d.ts +7 -6
- package/db/schema.cds +19 -7
- package/package.json +4 -2
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +7 -2
- package/srv/blockchain/backends/koios-backend.js +1 -1
- package/srv/blockchain/backends/ogmios-backend.d.ts +15 -3
- package/srv/blockchain/backends/ogmios-backend.js +102 -56
- package/srv/blockchain/cardano-client.d.ts +8 -0
- package/srv/blockchain/cardano-client.js +14 -2
- package/srv/blockchain/cardano-indexer.d.ts +35 -1
- package/srv/blockchain/cardano-indexer.js +177 -57
- package/srv/blockchain/cardano-tx-builder.d.ts +15 -3
- package/srv/blockchain/cardano-tx-builder.js +70 -24
- package/srv/blockchain/crawler/crawler.js +3 -9
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +42 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +6 -1
- package/srv/cardano-tx-service.js +3 -1
- package/srv/utils/db-indexes.js +4 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/errors.d.ts +2 -1
- package/srv/utils/errors.js +7 -3
- package/srv/utils/mappers.d.ts +7 -4
- package/srv/utils/mappers.js +18 -9
- package/srv/utils/types.d.ts +2 -0
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OgmiosBackend = void 0;
|
|
7
|
+
exports.ogmiosScriptHash = ogmiosScriptHash;
|
|
8
|
+
exports.issuerKeyToPoolId = issuerKeyToPoolId;
|
|
7
9
|
exports.decodeDrepId = decodeDrepId;
|
|
8
10
|
exports.resolveOgmiosTip = resolveOgmiosTip;
|
|
9
11
|
exports.resolveOgmiosHeight = resolveOgmiosHeight;
|
|
@@ -11,28 +13,14 @@ const cds_1 = __importDefault(require("@sap/cds"));
|
|
|
11
13
|
const node_http_1 = __importDefault(require("node:http"));
|
|
12
14
|
const client_1 = require("@cardano-ogmios/client");
|
|
13
15
|
const bech32_1 = require("bech32");
|
|
16
|
+
const crypto_1 = require("@harmoniclabs/crypto");
|
|
14
17
|
const backend_request_handler_1 = require("../../utils/backend-request-handler");
|
|
15
18
|
const errors_1 = require("../../utils/errors");
|
|
16
19
|
const ogmios_frame_guard_1 = require("./ogmios-frame-guard");
|
|
20
|
+
const epoch_slots_1 = require("../../utils/epoch-slots");
|
|
17
21
|
const mappers_1 = require("../../utils/mappers");
|
|
18
22
|
const const_1 = require("../../utils/const");
|
|
19
23
|
const logger = cds_1.default.log('OgmiosBackend');
|
|
20
|
-
/**
|
|
21
|
-
* First absolute slot of an epoch, from the network's Shelley anchor
|
|
22
|
-
* (86 400 slots per epoch on preview; Byron offset on mainnet/preprod).
|
|
23
|
-
*/
|
|
24
|
-
function epochStartSlot(network, epoch) {
|
|
25
|
-
const cfg = const_1.EPOCH_CONFIG_BY_NETWORK[network];
|
|
26
|
-
return cfg.shelleyStartSlot + (epoch - cfg.shelleyStartEpoch) * cfg.slotsPerEpoch;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Absolute POSIX seconds for a slot via the Shelley-anchored genesis infos. Ogmios'
|
|
30
|
-
* `eraStart.time` is RelativeTime since system start, not a Unix timestamp.
|
|
31
|
-
*/
|
|
32
|
-
function slotToPosixSeconds(network, slot) {
|
|
33
|
-
const genesis = const_1.GENESIS_INFOS_BY_NETWORK[network];
|
|
34
|
-
return Math.floor((genesis.systemStartPosixMs + (slot - genesis.startSlotNo) * genesis.slotLengthMs) / 1000);
|
|
35
|
-
}
|
|
36
24
|
/** Parse an Ogmios `Ratio` ("num/den", e.g. "3/1000") into a number; `Number("3/1000")` is NaN. */
|
|
37
25
|
function parseOgmiosRatio(ratio) {
|
|
38
26
|
if (ratio === null || ratio === undefined)
|
|
@@ -47,6 +35,31 @@ function parseOgmiosRatio(ratio) {
|
|
|
47
35
|
const n = Number(ratio);
|
|
48
36
|
return Number.isFinite(n) ? n : 0;
|
|
49
37
|
}
|
|
38
|
+
const SCRIPT_LANGUAGE_TAG = { native: 0, 'plutus:v1': 1, 'plutus:v2': 2, 'plutus:v3': 3 };
|
|
39
|
+
/** Hash of an Ogmios `Script`: blake2b-224 over the language tag byte followed by the script CBOR. */
|
|
40
|
+
function ogmiosScriptHash(script) {
|
|
41
|
+
const s = script;
|
|
42
|
+
const tag = s?.language === undefined ? undefined : SCRIPT_LANGUAGE_TAG[s.language];
|
|
43
|
+
if (tag === undefined || typeof s?.cbor !== 'string' || s.cbor.length === 0)
|
|
44
|
+
return null;
|
|
45
|
+
const bytes = Uint8Array.from(Buffer.concat([Buffer.from([tag]), Buffer.from(s.cbor, 'hex')]));
|
|
46
|
+
return Buffer.from((0, crypto_1.blake2b_224)(bytes)).toString('hex');
|
|
47
|
+
}
|
|
48
|
+
/** Bech32 pool id of a block issuer: blake2b-224 of its cold verification key. */
|
|
49
|
+
function issuerKeyToPoolId(verificationKeyHex) {
|
|
50
|
+
const keyHash = (0, crypto_1.blake2b_224)(Uint8Array.from(Buffer.from(verificationKeyHex, 'hex')));
|
|
51
|
+
return bech32_1.bech32.encode('pool', bech32_1.bech32.toWords(keyHash));
|
|
52
|
+
}
|
|
53
|
+
/** CIP-129 DRep id for a registered DRep, the predefined id for abstain / no confidence. */
|
|
54
|
+
function ogmiosDrepToId(d) {
|
|
55
|
+
if (!d)
|
|
56
|
+
return null;
|
|
57
|
+
if (d.type === 'abstain')
|
|
58
|
+
return 'drep_always_abstain';
|
|
59
|
+
if (d.type === 'noConfidence')
|
|
60
|
+
return 'drep_always_no_confidence';
|
|
61
|
+
return d.id ? (0, mappers_1.credentialToDrepId)(d.id, d.from === 'script') : null;
|
|
62
|
+
}
|
|
50
63
|
/** Lovelace amount from Ogmios' value shapes; v6 returns `{ ada: { lovelace } }` objects. */
|
|
51
64
|
function ogmiosValueToLovelaceString(value) {
|
|
52
65
|
if (value === null || value === undefined)
|
|
@@ -84,8 +97,8 @@ class OgmiosBackend {
|
|
|
84
97
|
name = 'ogmios';
|
|
85
98
|
/**
|
|
86
99
|
* Capability declaration — the orchestrator skips Ogmios for these without counting
|
|
87
|
-
* circuit failures. Historic queries are out of protocol scope, and address
|
|
88
|
-
*
|
|
100
|
+
* circuit failures. Historic queries are out of protocol scope, and address aggregates
|
|
101
|
+
* cannot be derived from state queries.
|
|
89
102
|
*/
|
|
90
103
|
unsupportedMethods = new Set([
|
|
91
104
|
// getEpoch is NOT listed: Ogmios can serve the CURRENT epoch and only
|
|
@@ -98,7 +111,6 @@ class OgmiosBackend {
|
|
|
98
111
|
// queryLedgerState/delegateRepresentatives (Ogmios ≥ 6.4).
|
|
99
112
|
'getAssetInfo',
|
|
100
113
|
'getAddress',
|
|
101
|
-
'getNetworkInformation',
|
|
102
114
|
]);
|
|
103
115
|
stateQueryClient = null;
|
|
104
116
|
txSubmissionClient = null;
|
|
@@ -338,10 +350,39 @@ class OgmiosBackend {
|
|
|
338
350
|
throw new errors_1.ProviderUnavailableError('Asset info queries not supported by Ogmios backend', this.name);
|
|
339
351
|
}, this.name);
|
|
340
352
|
}
|
|
341
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* Supply figures from `queryLedgerState/treasuryAndReserves`: total = max − reserves.
|
|
355
|
+
* Circulating, locked and stake totals are not in the ledger state and stay '0'.
|
|
356
|
+
*/
|
|
342
357
|
async getNetworkInformation() {
|
|
343
358
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
344
|
-
|
|
359
|
+
await this.ensureConnected();
|
|
360
|
+
if (!this.context) {
|
|
361
|
+
throw new errors_1.ProviderUnavailableError('Ogmios interaction context not available', this.name);
|
|
362
|
+
}
|
|
363
|
+
const pots = await (0, client_1.Method)({ method: 'queryLedgerState/treasuryAndReserves' }, {
|
|
364
|
+
handler: (response, resolve, reject) => {
|
|
365
|
+
if (response.error) {
|
|
366
|
+
reject(new Error(response.error.message ?? `Ogmios error ${response.error.code ?? ''}`.trim()));
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
resolve(response.result ?? {});
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
}, this.context);
|
|
373
|
+
const max = const_1.CARDANO_DEFAULTS.MAX_LOVELACE_SUPPLY;
|
|
374
|
+
const reserves = ogmiosValueToLovelaceString(pots.reserves);
|
|
375
|
+
return {
|
|
376
|
+
supply: {
|
|
377
|
+
max,
|
|
378
|
+
total: (BigInt(max) - BigInt(reserves)).toString(),
|
|
379
|
+
circulating: '0',
|
|
380
|
+
locked: '0',
|
|
381
|
+
treasury: ogmiosValueToLovelaceString(pots.treasury),
|
|
382
|
+
reserves,
|
|
383
|
+
},
|
|
384
|
+
stake: { live: '0', active: '0' },
|
|
385
|
+
};
|
|
345
386
|
}, this.name);
|
|
346
387
|
}
|
|
347
388
|
/**
|
|
@@ -375,7 +416,7 @@ class OgmiosBackend {
|
|
|
375
416
|
datumHash: u.datumHash,
|
|
376
417
|
// Ogmios delivers the inline datum as CBOR hex in `datum`
|
|
377
418
|
inlineDatum: typeof u.datum === 'string' ? u.datum : null,
|
|
378
|
-
scriptRef: u.script
|
|
419
|
+
scriptRef: ogmiosScriptHash(u.script) ?? undefined,
|
|
379
420
|
};
|
|
380
421
|
}
|
|
381
422
|
/**
|
|
@@ -427,9 +468,10 @@ class OgmiosBackend {
|
|
|
427
468
|
throw new errors_1.NotFoundError('Pool', this.name);
|
|
428
469
|
return {
|
|
429
470
|
poolId,
|
|
430
|
-
vrfKeyHash: pool.
|
|
471
|
+
vrfKeyHash: pool.vrfVerificationKeyHash || '',
|
|
431
472
|
blocksMinted: 0,
|
|
432
|
-
|
|
473
|
+
// not in the ledger state; null = unavailable, as on Koios
|
|
474
|
+
blocksEpoch: null,
|
|
433
475
|
liveStake: pool.stake?.ada?.lovelace ? String(pool.stake.ada.lovelace) : '0',
|
|
434
476
|
liveSize: 0,
|
|
435
477
|
liveDelegators: 0,
|
|
@@ -469,14 +511,15 @@ class OgmiosBackend {
|
|
|
469
511
|
// reaching this point (summary found) therefore implies the account is active.
|
|
470
512
|
active: true,
|
|
471
513
|
activeEpoch: 0,
|
|
472
|
-
|
|
514
|
+
// reward-account summaries carry no controlled amount and no withdrawal totals
|
|
515
|
+
controlledAmount: '0',
|
|
473
516
|
rewardsSum: ogmiosValueToLovelaceString(account.rewards),
|
|
474
|
-
withdrawalsSum:
|
|
517
|
+
withdrawalsSum: '0',
|
|
475
518
|
reservesSum: '0',
|
|
476
519
|
treasurySum: '0',
|
|
477
520
|
withdrawableAmount: ogmiosValueToLovelaceString(account.rewards),
|
|
478
|
-
poolId: account.
|
|
479
|
-
drepId: account.
|
|
521
|
+
poolId: account.stakePool?.id || null,
|
|
522
|
+
drepId: ogmiosDrepToId(account.delegateRepresentative),
|
|
480
523
|
addresses: []
|
|
481
524
|
};
|
|
482
525
|
}, this.name);
|
|
@@ -569,14 +612,14 @@ class OgmiosBackend {
|
|
|
569
612
|
]);
|
|
570
613
|
const { slot } = resolveOgmiosTip(tip);
|
|
571
614
|
// Network-aware epoch geometry + Shelley-anchored slot→time conversion
|
|
572
|
-
const startSlot = epochStartSlot(this.network, currentEpoch);
|
|
615
|
+
const startSlot = (0, epoch_slots_1.epochStartSlot)(this.network, currentEpoch);
|
|
573
616
|
const endSlot = startSlot + const_1.EPOCH_CONFIG_BY_NETWORK[this.network].slotsPerEpoch;
|
|
574
617
|
return {
|
|
575
618
|
epoch: currentEpoch,
|
|
576
|
-
start_time: slotToPosixSeconds(this.network, startSlot),
|
|
577
|
-
end_time: slotToPosixSeconds(this.network, endSlot),
|
|
578
|
-
first_block_time: slotToPosixSeconds(this.network, startSlot),
|
|
579
|
-
last_block_time: slotToPosixSeconds(this.network, slot),
|
|
619
|
+
start_time: (0, epoch_slots_1.slotToPosixSeconds)(this.network, startSlot),
|
|
620
|
+
end_time: (0, epoch_slots_1.slotToPosixSeconds)(this.network, endSlot),
|
|
621
|
+
first_block_time: (0, epoch_slots_1.slotToPosixSeconds)(this.network, startSlot),
|
|
622
|
+
last_block_time: (0, epoch_slots_1.slotToPosixSeconds)(this.network, slot),
|
|
580
623
|
block_count: 0, // Not available from Ogmios state queries
|
|
581
624
|
tx_count: 0, // Not available from Ogmios state queries
|
|
582
625
|
output: '0',
|
|
@@ -601,9 +644,9 @@ class OgmiosBackend {
|
|
|
601
644
|
const { slot, hash } = resolveOgmiosTip(tip);
|
|
602
645
|
const height = resolveOgmiosHeight(blockHeight);
|
|
603
646
|
// network-aware slot-in-epoch
|
|
604
|
-
const epochSlot = Math.max(0, slot - epochStartSlot(this.network, epoch));
|
|
647
|
+
const epochSlot = Math.max(0, slot - (0, epoch_slots_1.epochStartSlot)(this.network, epoch));
|
|
605
648
|
return {
|
|
606
|
-
time: slotToPosixSeconds(this.network, slot), // seconds (mapBlock expects seconds)
|
|
649
|
+
time: (0, epoch_slots_1.slotToPosixSeconds)(this.network, slot), // seconds (mapBlock expects seconds)
|
|
607
650
|
height,
|
|
608
651
|
hash,
|
|
609
652
|
slot,
|
|
@@ -613,6 +656,7 @@ class OgmiosBackend {
|
|
|
613
656
|
size: 0, // Not available via ledgerTip - would need full block data
|
|
614
657
|
txCount: 0, // Not available via ledgerTip - would need full block data
|
|
615
658
|
fees: '0', // Not available via ledgerTip - would need full block data
|
|
659
|
+
headerOnly: true,
|
|
616
660
|
};
|
|
617
661
|
}, this.name);
|
|
618
662
|
}
|
|
@@ -643,6 +687,18 @@ class OgmiosBackend {
|
|
|
643
687
|
return Array.isArray(result) && result.length > 0;
|
|
644
688
|
}, this.name);
|
|
645
689
|
}
|
|
690
|
+
/** Outputs among `refs` that are unspent in the live ledger; spent or unknown references are absent. */
|
|
691
|
+
async getUnspentOutputs(refs) {
|
|
692
|
+
if (refs.length === 0)
|
|
693
|
+
return [];
|
|
694
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
695
|
+
await this.ensureConnected();
|
|
696
|
+
const result = await this.stateQueryClient.utxo({
|
|
697
|
+
outputReferences: refs.map(r => ({ transaction: { id: r.txHash }, index: r.outputIndex })),
|
|
698
|
+
});
|
|
699
|
+
return result.map((u) => this.mapOgmiosUtxo(u));
|
|
700
|
+
}, this.name);
|
|
701
|
+
}
|
|
646
702
|
/** Close the WebSocket and mark the backend as shut down. */
|
|
647
703
|
async shutdown() {
|
|
648
704
|
if (this.isShutdown)
|
|
@@ -854,16 +910,15 @@ class OgmiosBackend {
|
|
|
854
910
|
mapOgmiosBlock(block) {
|
|
855
911
|
const txs = (block.transactions ?? []).map((t, i) => this.mapOgmiosTx(t, block, i));
|
|
856
912
|
const totalFees = txs.reduce((sum, t) => sum + BigInt(t.fee || 0), 0n);
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
const epochSlot = block.slot - epochStartSlot(this.network, epoch);
|
|
913
|
+
const epoch = (0, epoch_slots_1.epochOfSlot)(this.network, block.slot);
|
|
914
|
+
// Shelley-anchored helpers (handle preview/preprod geometry and the Byron offset)
|
|
915
|
+
const epochSlot = block.slot - (0, epoch_slots_1.epochStartSlot)(this.network, epoch);
|
|
861
916
|
const blockData = {
|
|
862
|
-
time: slotToPosixSeconds(this.network, block.slot),
|
|
917
|
+
time: (0, epoch_slots_1.slotToPosixSeconds)(this.network, block.slot),
|
|
863
918
|
height: block.height,
|
|
864
919
|
hash: block.id,
|
|
865
920
|
slot: block.slot,
|
|
866
|
-
slotLeader: block.issuer?.verificationKey
|
|
921
|
+
slotLeader: block.issuer?.verificationKey ? issuerKeyToPoolId(block.issuer.verificationKey) : '',
|
|
867
922
|
epoch,
|
|
868
923
|
epochSlot,
|
|
869
924
|
size: block.size?.bytes ?? 0,
|
|
@@ -899,7 +954,7 @@ class OgmiosBackend {
|
|
|
899
954
|
dataHash: output.datumHash ?? null,
|
|
900
955
|
inlineDatum: output.datum ?? null,
|
|
901
956
|
isCollateral,
|
|
902
|
-
referenceScriptHash:
|
|
957
|
+
referenceScriptHash: ogmiosScriptHash(output.script),
|
|
903
958
|
});
|
|
904
959
|
const outputs = spendsCollaterals
|
|
905
960
|
? (tx.collateralReturn
|
|
@@ -935,7 +990,7 @@ class OgmiosBackend {
|
|
|
935
990
|
// null = unknown (chain-sync doesn't surface the serialized size) — matches the
|
|
936
991
|
// lazy path's `size ?? null` convention; 0 would masquerade as a real size
|
|
937
992
|
size: null,
|
|
938
|
-
blockTime: slotToPosixSeconds(this.network, block.slot),
|
|
993
|
+
blockTime: (0, epoch_slots_1.slotToPosixSeconds)(this.network, block.slot),
|
|
939
994
|
inputs,
|
|
940
995
|
outputs,
|
|
941
996
|
// undefined (not []) when absent — matches the Blockfrost path so
|
|
@@ -957,15 +1012,6 @@ class OgmiosBackend {
|
|
|
957
1012
|
const out = [];
|
|
958
1013
|
const lovelace = (v) => v?.ada?.lovelace != null ? v.ada.lovelace.toString() : null;
|
|
959
1014
|
const stakeAddr = (c) => c.credential ? (0, mappers_1.credentialToStakeAddress)(c.credential, c.from === 'script', this.network) : null;
|
|
960
|
-
const drepId = (d) => {
|
|
961
|
-
if (!d)
|
|
962
|
-
return null;
|
|
963
|
-
if (d.type === 'abstain')
|
|
964
|
-
return 'drep_always_abstain';
|
|
965
|
-
if (d.type === 'noConfidence')
|
|
966
|
-
return 'drep_always_no_confidence';
|
|
967
|
-
return d.id ? (0, mappers_1.credentialToDrepId)(d.id, d.from === 'script') : null;
|
|
968
|
-
};
|
|
969
1015
|
certs.forEach((c, certIndex) => {
|
|
970
1016
|
switch (c.type) {
|
|
971
1017
|
case 'stakeCredentialRegistration':
|
|
@@ -979,7 +1025,7 @@ class OgmiosBackend {
|
|
|
979
1025
|
if (c.stakePool?.id)
|
|
980
1026
|
out.push({ certIndex, kind: 'pool_delegation', stakeAddress, poolId: c.stakePool.id });
|
|
981
1027
|
if (c.delegateRepresentative)
|
|
982
|
-
out.push({ certIndex, kind: 'vote_delegation', stakeAddress, drepId:
|
|
1028
|
+
out.push({ certIndex, kind: 'vote_delegation', stakeAddress, drepId: ogmiosDrepToId(c.delegateRepresentative) });
|
|
983
1029
|
break;
|
|
984
1030
|
}
|
|
985
1031
|
case 'stakePoolRegistration':
|
|
@@ -989,13 +1035,13 @@ class OgmiosBackend {
|
|
|
989
1035
|
out.push({ certIndex, kind: 'pool_retirement', poolId: c.stakePool?.id ?? null, epoch: c.stakePool?.retirementEpoch ?? null });
|
|
990
1036
|
break;
|
|
991
1037
|
case 'delegateRepresentativeRegistration':
|
|
992
|
-
out.push({ certIndex, kind: 'drep_registration', drepId:
|
|
1038
|
+
out.push({ certIndex, kind: 'drep_registration', drepId: ogmiosDrepToId(c.delegateRepresentative), deposit: lovelace(c.deposit) });
|
|
993
1039
|
break;
|
|
994
1040
|
case 'delegateRepresentativeUpdate':
|
|
995
|
-
out.push({ certIndex, kind: 'drep_update', drepId:
|
|
1041
|
+
out.push({ certIndex, kind: 'drep_update', drepId: ogmiosDrepToId(c.delegateRepresentative) });
|
|
996
1042
|
break;
|
|
997
1043
|
case 'delegateRepresentativeRetirement':
|
|
998
|
-
out.push({ certIndex, kind: 'drep_retirement', drepId:
|
|
1044
|
+
out.push({ certIndex, kind: 'drep_retirement', drepId: ogmiosDrepToId(c.delegateRepresentative), deposit: lovelace(c.deposit) });
|
|
999
1045
|
break;
|
|
1000
1046
|
case 'constitutionalCommitteeDelegation':
|
|
1001
1047
|
out.push({ certIndex, kind: 'committee_hot_auth' });
|
|
@@ -127,6 +127,14 @@ export declare class CardanoClient {
|
|
|
127
127
|
recoverChainSyncBackend(): Promise<ChainSyncBackend | null>;
|
|
128
128
|
/** The first usable backend that can dump the UTxO set at a point (Ogmios) — crawler.utxoSet import. */
|
|
129
129
|
getLedgerStateBackend(): LedgerStateBackend | null;
|
|
130
|
+
/**
|
|
131
|
+
* Outputs among `refs` that are unspent at the tip, read from the node's ledger; null when no
|
|
132
|
+
* ledger-state backend is usable (the caller then resolves via the producing transaction).
|
|
133
|
+
*/
|
|
134
|
+
getUnspentOutputs(refs: Array<{
|
|
135
|
+
txHash: string;
|
|
136
|
+
outputIndex: number;
|
|
137
|
+
}>): Promise<UTxO[] | null>;
|
|
130
138
|
/**
|
|
131
139
|
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
132
140
|
* snapshots stay off instead of degrading into thousands of single requests.
|
|
@@ -19,7 +19,8 @@ const METHOD_ROUTING = {
|
|
|
19
19
|
getAddress: { preferLive: true },
|
|
20
20
|
getAddressUtxos: { preferLive: false },
|
|
21
21
|
getAddressTransactions: { preferLive: false },
|
|
22
|
-
|
|
22
|
+
// providers first: they report circulation; Ogmios only has treasury and reserves
|
|
23
|
+
getNetworkInformation: { preferLive: false },
|
|
23
24
|
getTransactionMetadata: { preferLive: false },
|
|
24
25
|
getBlock: { preferLive: false },
|
|
25
26
|
getEpoch: { preferLive: false },
|
|
@@ -241,6 +242,7 @@ class CardanoClient {
|
|
|
241
242
|
async executeWithPriority(fn, preferLive, methodName) {
|
|
242
243
|
await this.ensureInitialized();
|
|
243
244
|
const errors = [];
|
|
245
|
+
const skipped = [];
|
|
244
246
|
// Determine backend order based on preference
|
|
245
247
|
const primaryBackends = preferLive
|
|
246
248
|
? (this.liveBackend ? [this.liveBackend] : [])
|
|
@@ -254,10 +256,12 @@ class CardanoClient {
|
|
|
254
256
|
// capability routing: declared non-support is a skip, not a failure
|
|
255
257
|
if (methodName && backend.unsupportedMethods?.has(methodName)) {
|
|
256
258
|
logger.debug(`${backend.name} does not support ${methodName}, skipping`);
|
|
259
|
+
skipped.push(`${backend.name}: does not support ${methodName}`);
|
|
257
260
|
continue;
|
|
258
261
|
}
|
|
259
262
|
if (!this.circuitBreaker.shouldAttempt(backend.name)) {
|
|
260
263
|
logger.debug(`Circuit open for ${backend.name}, skipping`);
|
|
264
|
+
skipped.push(`${backend.name}: circuit open`);
|
|
261
265
|
continue;
|
|
262
266
|
}
|
|
263
267
|
// fast-path sync check — only await the init retry in the rare failure case
|
|
@@ -284,7 +288,7 @@ class CardanoClient {
|
|
|
284
288
|
logger[logLevel](`Backend failed${backendError.statusCode === 404 ? ': resource not found' : ''}: ${backend.name} - ${backendError.message}`);
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
|
-
throw new errors_1.AllBackendsFailedError(errors);
|
|
291
|
+
throw new errors_1.AllBackendsFailedError(errors, undefined, skipped);
|
|
288
292
|
}
|
|
289
293
|
/** Route a call by METHOD_ROUTING (default: historical first). */
|
|
290
294
|
route(methodName, fn) {
|
|
@@ -439,6 +443,14 @@ class CardanoClient {
|
|
|
439
443
|
}
|
|
440
444
|
return null;
|
|
441
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Outputs among `refs` that are unspent at the tip, read from the node's ledger; null when no
|
|
448
|
+
* ledger-state backend is usable (the caller then resolves via the producing transaction).
|
|
449
|
+
*/
|
|
450
|
+
async getUnspentOutputs(refs) {
|
|
451
|
+
const backend = this.getLedgerStateBackend();
|
|
452
|
+
return backend ? backend.getUnspentOutputs(refs) : null;
|
|
453
|
+
}
|
|
442
454
|
/**
|
|
443
455
|
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
444
456
|
* snapshots stay off instead of degrading into thousands of single requests.
|
|
@@ -63,6 +63,16 @@ export declare class CardanoIndexer {
|
|
|
63
63
|
certificates?: boolean;
|
|
64
64
|
utxoSet?: boolean;
|
|
65
65
|
}): void;
|
|
66
|
+
/**
|
|
67
|
+
* What the crawled data answers authoritatively: only while a live crawler is at the tip.
|
|
68
|
+
* Every block after `fromSlot` is held; `ledger` = the crawled UTxO set is active.
|
|
69
|
+
*/
|
|
70
|
+
private localCoverage;
|
|
71
|
+
/**
|
|
72
|
+
* Block counts of a pool from crawled blocks (`slotLeader` = pool id): the current epoch when the
|
|
73
|
+
* crawl covers it from its first slot, the lifetime total when it covers the chain since Shelley.
|
|
74
|
+
*/
|
|
75
|
+
private localPoolBlocks;
|
|
66
76
|
/** The anchor the imported UTxO set describes (null = ledger mode inactive). */
|
|
67
77
|
setUtxoAnchor(anchor: LedgerAnchor | null): void;
|
|
68
78
|
/**
|
|
@@ -88,12 +98,21 @@ export declare class CardanoIndexer {
|
|
|
88
98
|
*/
|
|
89
99
|
prefetchCrawlEpoch(epochNumber: number): Promise<void>;
|
|
90
100
|
private refreshCrawlEpoch;
|
|
101
|
+
/**
|
|
102
|
+
* Block, transaction and fee totals of an epoch summed over the crawled blocks, when the crawl
|
|
103
|
+
* covers the epoch from its first slot; null otherwise. Output and active stake stay with the backend.
|
|
104
|
+
*/
|
|
105
|
+
private crawledEpochTotals;
|
|
106
|
+
/** Epoch row with only the slot-derived bounds, for an epoch the backend cannot describe. */
|
|
107
|
+
private bareEpochRow;
|
|
91
108
|
constructor(client: CardanoClient, txBuilder: CardanoTransactionBuilder);
|
|
92
109
|
/**
|
|
93
110
|
* Index a transaction with inputs/outputs/assets/metadata; all UPSERTs run in the caller's
|
|
94
111
|
* transaction, so either everything persists or nothing does.
|
|
95
112
|
*/
|
|
96
113
|
indexTransaction(tx: CapTransaction, txHash: string): Promise<CardanoTransaction>;
|
|
114
|
+
/** Lazy path: inputs, outputs, their assets and metadata of one transaction. */
|
|
115
|
+
private writeTransactionChildren;
|
|
97
116
|
/**
|
|
98
117
|
* Index address data with assets and UTxOs; transactions are loaded separately via
|
|
99
118
|
* indexAddressTransactions().
|
|
@@ -123,7 +142,7 @@ export declare class CardanoIndexer {
|
|
|
123
142
|
indexAddressTransactionBuilds(tx: CapTransaction, addr: string, buildId: string): Promise<void>;
|
|
124
143
|
/** Index the metadata rows of a transaction. */
|
|
125
144
|
indexTransactionMetadata(tx: CapTransaction, tx_hash: string): Promise<TransactionMetadata[]>;
|
|
126
|
-
/** Index the network information. */
|
|
145
|
+
/** Index the network information; circulating supply comes from the crawled UTxO set when it is current. */
|
|
127
146
|
indexNetworkInformation(tx: CapTransaction): Promise<NetworkInformation>;
|
|
128
147
|
/** Index a block by hash, with best-effort epoch enrichment. */
|
|
129
148
|
indexBlock(tx: CapTransaction, blockHash: string): Promise<Block>;
|
|
@@ -133,6 +152,16 @@ export declare class CardanoIndexer {
|
|
|
133
152
|
* atomically. Bare chain-sync inputs are backfilled by resolveInputs() first.
|
|
134
153
|
*/
|
|
135
154
|
indexBlockFull(tx: CapTransaction, blockData: BlockData, txs: ProviderTransaction[]): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Drop other Block rows at the crawled block's height that no transaction references: lazily
|
|
157
|
+
* indexed tips that were rolled back, which no crawler reorg covers.
|
|
158
|
+
*/
|
|
159
|
+
private removeSupersededBlocks;
|
|
160
|
+
/**
|
|
161
|
+
* Drop transactions of another fork that hold one of this block's txSeq keys (a lazily indexed
|
|
162
|
+
* tx from a rolled-back block at the same slot); their input/output rows would mix with ours.
|
|
163
|
+
*/
|
|
164
|
+
private removeStaleTxSeqs;
|
|
136
165
|
/**
|
|
137
166
|
* Warn once when `crawler.certificates` is on but the source reports none (`certificates`
|
|
138
167
|
* undefined, as with Blockfrost). `[]` means "none" and is not a warning.
|
|
@@ -289,6 +318,11 @@ export declare class CardanoIndexer {
|
|
|
289
318
|
indexLatestBlock(tx: CapTransaction): Promise<Block>;
|
|
290
319
|
/** Max addresses to index concurrently (avoid overloading backends) */
|
|
291
320
|
private static readonly ADDR_CONCURRENCY;
|
|
321
|
+
/** Block position of a transaction already in the local index (crawled or cached), or null. */
|
|
322
|
+
findIndexedTransaction(tx: CapTransaction, txHash: string): Promise<{
|
|
323
|
+
slot: number | null;
|
|
324
|
+
blockHeight: number | null;
|
|
325
|
+
} | null>;
|
|
292
326
|
/**
|
|
293
327
|
* Ensure a set of transactions is indexed: DB check, batch fetch of the missing ones, UPSERT.
|
|
294
328
|
* @returns provider transactions for the hashes that had to be fetched
|