@odatano/core 1.11.0 → 2.0.0-rc.2
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/CardanoIndexerService/index.d.ts +142 -0
- package/@cds-models/CardanoIndexerService/index.js +23 -0
- package/@cds-models/CardanoODataService/index.d.ts +693 -2172
- package/@cds-models/CardanoODataService/index.js +88 -390
- package/@cds-models/CardanoSignService/index.d.ts +443 -1574
- package/@cds-models/CardanoSignService/index.js +62 -293
- package/@cds-models/CardanoTransactionService/index.d.ts +431 -1488
- package/@cds-models/CardanoTransactionService/index.js +60 -271
- package/@cds-models/CardanoWorkerService/index.d.ts +224 -0
- package/@cds-models/CardanoWorkerService/index.js +32 -0
- package/@cds-models/_/index.d.ts +70 -40
- package/@cds-models/_/index.js +17 -32
- package/@cds-models/cds/outbox/index.d.ts +28 -0
- package/@cds-models/index.d.ts +225 -522
- package/@cds-models/index.js +35 -218
- package/@cds-models/odatano/cardano/index.d.ts +896 -2947
- package/@cds-models/odatano/cardano/index.js +109 -536
- package/@cds-models/sap/common/index.d.ts +196 -600
- package/@cds-models/sap/common/index.js +28 -269
- package/README.md +36 -2
- package/db/schema.cds +283 -1
- package/db/types.cds +48 -0
- package/package.json +173 -164
- package/src/index.d.ts +1 -1
- package/src/index.js +10 -2
- package/src/plugin.js +12 -2
- package/srv/blockchain/backends/blockfrost-backend.d.ts +21 -2
- package/srv/blockchain/backends/blockfrost-backend.js +68 -15
- package/srv/blockchain/backends/cardano-backend.d.ts +69 -0
- package/srv/blockchain/backends/cardano-backend.js +13 -0
- package/srv/blockchain/backends/koios-backend.d.ts +26 -2
- package/srv/blockchain/backends/koios-backend.js +147 -15
- package/srv/blockchain/backends/ogmios-backend.d.ts +37 -6
- package/srv/blockchain/backends/ogmios-backend.js +254 -5
- package/srv/blockchain/cardano-client.d.ts +19 -0
- package/srv/blockchain/cardano-client.js +36 -0
- package/srv/blockchain/cardano-indexer.d.ts +50 -1
- package/srv/blockchain/cardano-indexer.js +191 -0
- package/srv/blockchain/crawler/crawler.d.ts +151 -0
- package/srv/blockchain/crawler/crawler.js +677 -0
- package/srv/blockchain/crawler/hooks.d.ts +43 -0
- package/srv/blockchain/crawler/hooks.js +62 -0
- package/srv/blockchain/crawler/index.d.ts +26 -0
- package/srv/blockchain/crawler/index.js +135 -0
- package/srv/blockchain/crawler/sync-state.d.ts +94 -0
- package/srv/blockchain/crawler/sync-state.js +265 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +45 -0
- package/srv/blockchain/signing/hsm-signer.js +8 -1
- package/srv/blockchain/wallet-worker/build-request.d.ts +26 -0
- package/srv/blockchain/wallet-worker/build-request.js +341 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +86 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +228 -0
- package/srv/blockchain/wallet-worker/index.d.ts +14 -0
- package/srv/blockchain/wallet-worker/index.js +80 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +261 -0
- package/srv/blockchain/wallet-worker/job-store.js +564 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +43 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +99 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +57 -0
- package/srv/blockchain/wallet-worker/signers.js +131 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +145 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +542 -0
- package/srv/cardano-indexer-service.cds +73 -0
- package/srv/cardano-indexer-service.d.ts +2 -0
- package/srv/cardano-indexer-service.js +76 -0
- package/srv/cardano-service.js +76 -5
- package/srv/cardano-tx-service.d.ts +1 -11
- package/srv/cardano-tx-service.js +11 -162
- package/srv/cardano-worker-service.cds +125 -0
- package/srv/cardano-worker-service.d.ts +2 -0
- package/srv/cardano-worker-service.js +199 -0
- package/srv/server.d.ts +32 -1
- package/srv/server.js +229 -36
- package/srv/utils/collections.d.ts +13 -0
- package/srv/utils/collections.js +24 -0
- package/srv/utils/crypto.d.ts +16 -0
- package/srv/utils/crypto.js +75 -0
- package/srv/utils/error-codes.d.ts +6 -0
- package/srv/utils/error-codes.js +6 -0
- package/srv/utils/errors.d.ts +12 -0
- package/srv/utils/errors.js +45 -0
- package/srv/utils/mappers.js +13 -3
- package/srv/utils/service-events.d.ts +26 -0
- package/srv/utils/service-events.js +46 -0
- package/srv/utils/tx-request-parsers.d.ts +58 -0
- package/srv/utils/tx-request-parsers.js +170 -0
- package/srv/utils/tx-utils.d.ts +2 -1
- package/srv/utils/tx-utils.js +3 -2
- package/srv/utils/types.d.ts +2 -1
- package/@cds-models/CardanoODataService/index.d.ts.map +0 -1
- package/@cds-models/CardanoODataService/index.js.map +0 -1
- package/@cds-models/CardanoODataService/index.ts +0 -776
- package/@cds-models/CardanoSignService/index.d.ts.map +0 -1
- package/@cds-models/CardanoSignService/index.js.map +0 -1
- package/@cds-models/CardanoSignService/index.ts +0 -569
- package/@cds-models/CardanoTransactionService/index.d.ts.map +0 -1
- package/@cds-models/CardanoTransactionService/index.js.map +0 -1
- package/@cds-models/CardanoTransactionService/index.ts +0 -526
- package/@cds-models/_/index.d.ts.map +0 -1
- package/@cds-models/_/index.js.map +0 -1
- package/@cds-models/_/index.ts +0 -96
- package/@cds-models/cds/outbox/index.ts +0 -27
- package/@cds-models/index.d.ts.map +0 -1
- package/@cds-models/index.js.map +0 -1
- package/@cds-models/index.ts +0 -245
- package/@cds-models/odatano/cardano/index.d.ts.map +0 -1
- package/@cds-models/odatano/cardano/index.js.map +0 -1
- package/@cds-models/odatano/cardano/index.ts +0 -789
- package/@cds-models/sap/common/index.d.ts.map +0 -1
- package/@cds-models/sap/common/index.js.map +0 -1
- package/@cds-models/sap/common/index.ts +0 -249
|
@@ -179,4 +179,73 @@ export interface EvaluatingBackend extends CardanoBackend {
|
|
|
179
179
|
* @returns true if the backend supports evaluateTransaction
|
|
180
180
|
*/
|
|
181
181
|
export declare function isEvaluatingBackend(backend: CardanoBackend): backend is EvaluatingBackend;
|
|
182
|
+
/** A chain position the crawler can start from, stream to, or roll back to. */
|
|
183
|
+
export interface ChainPoint {
|
|
184
|
+
slot: number;
|
|
185
|
+
hash: string;
|
|
186
|
+
height?: number;
|
|
187
|
+
}
|
|
188
|
+
/** Callbacks driven by a streamed chain-sync (Ogmios). */
|
|
189
|
+
export interface ChainSyncCallbacks {
|
|
190
|
+
/**
|
|
191
|
+
* A new block (with its full transaction list) extends the chain.
|
|
192
|
+
* @param tip the node's current chain tip, when the protocol supplies it — lets the
|
|
193
|
+
* consumer track sync progress / detect being caught up
|
|
194
|
+
*/
|
|
195
|
+
rollForward(block: BlockData, txs: Transaction[], tip?: ChainPoint): Promise<void>;
|
|
196
|
+
/** The chain rolled back to `point` (or to genesis). All blocks after it are abandoned. */
|
|
197
|
+
rollBackward(point: ChainPoint | 'origin'): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* A message-handler error stalled the stream (mapping failure, callback throw). The
|
|
200
|
+
* stream stops requesting further blocks; the consumer should record the error and
|
|
201
|
+
* close/restart. Optional — without it such errors are only logged.
|
|
202
|
+
*/
|
|
203
|
+
onError?(err: unknown): Promise<void>;
|
|
204
|
+
}
|
|
205
|
+
/** Handle to an open chain-sync stream. */
|
|
206
|
+
export interface ChainSyncHandle {
|
|
207
|
+
/** Stop streaming and release the underlying connection. */
|
|
208
|
+
close(): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Backend that can stream the chain forward from a point, emitting ordered
|
|
212
|
+
* rollForward + native rollBackward (reorg) events. Implemented by Ogmios via the
|
|
213
|
+
* chain-synchronization protocol — the crawler's primary, reorg-aware source.
|
|
214
|
+
*/
|
|
215
|
+
export interface ChainSyncBackend extends CardanoBackend {
|
|
216
|
+
/**
|
|
217
|
+
* Open a chain-sync stream starting just after the first of `from` that is still
|
|
218
|
+
* on the node's chain (or from genesis).
|
|
219
|
+
* @param from candidate intersection points, NEWEST FIRST, or 'origin' for a
|
|
220
|
+
* fresh sync. Passing ancestors as well as the last-indexed point is what makes
|
|
221
|
+
* a reorg that happened while we were disconnected resolvable: the node
|
|
222
|
+
* intersects at the last common block and reports it via rollBackward, instead
|
|
223
|
+
* of failing the whole stream with "No intersection found".
|
|
224
|
+
* @param callbacks rollForward / rollBackward handlers
|
|
225
|
+
* @returns a handle to close the stream
|
|
226
|
+
*/
|
|
227
|
+
openChainSync(from: ChainPoint[] | 'origin', callbacks: ChainSyncCallbacks): Promise<ChainSyncHandle>;
|
|
228
|
+
}
|
|
229
|
+
/** Type guard: does this backend support streamed chain-sync? */
|
|
230
|
+
export declare function isChainSyncBackend(backend: CardanoBackend): backend is ChainSyncBackend;
|
|
231
|
+
/**
|
|
232
|
+
* Backend that can walk the chain forward by pagination (no live node). The
|
|
233
|
+
* crawler's fallback source when no Ogmios chain-sync is available. Reorgs are
|
|
234
|
+
* detected by the crawler via parent-hash mismatch (not delivered natively).
|
|
235
|
+
*/
|
|
236
|
+
export interface PaginatingBackend extends CardanoBackend {
|
|
237
|
+
/** Fetch a block by its height. */
|
|
238
|
+
getBlockByHeight(height: number): Promise<BlockData>;
|
|
239
|
+
/**
|
|
240
|
+
* Fetch up to `count` blocks immediately following `afterHash`, in chain order.
|
|
241
|
+
* @param afterHeight optional height of `afterHash` when the caller already knows it
|
|
242
|
+
* (the crawler's cursor does) — lets height-listing backends
|
|
243
|
+
* (Koios) skip a hash→height resolution round-trip
|
|
244
|
+
*/
|
|
245
|
+
getNextBlocks(afterHash: string, count: number, afterHeight?: number): Promise<BlockData[]>;
|
|
246
|
+
/** Fetch the full transaction list of a block, in block order. */
|
|
247
|
+
getBlockTransactions(blockHash: string): Promise<Transaction[]>;
|
|
248
|
+
}
|
|
249
|
+
/** Type guard: can this backend be walked forward by pagination? */
|
|
250
|
+
export declare function isPaginatingBackend(backend: CardanoBackend): backend is PaginatingBackend;
|
|
182
251
|
//# sourceMappingURL=cardano-backend.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isEvaluatingBackend = isEvaluatingBackend;
|
|
4
|
+
exports.isChainSyncBackend = isChainSyncBackend;
|
|
5
|
+
exports.isPaginatingBackend = isPaginatingBackend;
|
|
4
6
|
/**
|
|
5
7
|
* Type guard to check if a backend supports transaction evaluation
|
|
6
8
|
* @param backend - The backend to check
|
|
@@ -9,4 +11,15 @@ exports.isEvaluatingBackend = isEvaluatingBackend;
|
|
|
9
11
|
function isEvaluatingBackend(backend) {
|
|
10
12
|
return typeof backend.evaluateTransaction === 'function';
|
|
11
13
|
}
|
|
14
|
+
/** Type guard: does this backend support streamed chain-sync? */
|
|
15
|
+
function isChainSyncBackend(backend) {
|
|
16
|
+
return typeof backend.openChainSync === 'function';
|
|
17
|
+
}
|
|
18
|
+
/** Type guard: can this backend be walked forward by pagination? */
|
|
19
|
+
function isPaginatingBackend(backend) {
|
|
20
|
+
const b = backend;
|
|
21
|
+
return typeof b.getBlockByHeight === 'function'
|
|
22
|
+
&& typeof b.getNextBlocks === 'function'
|
|
23
|
+
&& typeof b.getBlockTransactions === 'function';
|
|
24
|
+
}
|
|
12
25
|
//# sourceMappingURL=cardano-backend.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CardanoBackend } from './cardano-backend';
|
|
1
|
+
import { CardanoBackend, PaginatingBackend } from './cardano-backend';
|
|
2
2
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters } from '../../utils/types';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
4
|
/**
|
|
5
5
|
* KoiosBackend Implementation for CardanoBackend Interface
|
|
6
6
|
* Implements the CardanoBackend interface using Koios API with Axios
|
|
7
7
|
*/
|
|
8
|
-
export declare class KoiosBackend implements CardanoBackend {
|
|
8
|
+
export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
|
|
9
9
|
readonly name = "koios";
|
|
10
10
|
private api;
|
|
11
11
|
private network;
|
|
@@ -173,6 +173,30 @@ export declare class KoiosBackend implements CardanoBackend {
|
|
|
173
173
|
* @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
|
|
174
174
|
*/
|
|
175
175
|
getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
|
|
176
|
+
/**
|
|
177
|
+
* Map a Koios /block_info response object to our BlockData (same shape getBlock
|
|
178
|
+
* maps inline; kept private to avoid touching getBlock).
|
|
179
|
+
*/
|
|
180
|
+
private mapKoiosBlockInfo;
|
|
181
|
+
/**
|
|
182
|
+
* Get a block by its height via the PostgREST-filtered /blocks list, then resolve
|
|
183
|
+
* full data through /block_info.
|
|
184
|
+
*/
|
|
185
|
+
getBlockByHeight(height: number): Promise<BlockData>;
|
|
186
|
+
/**
|
|
187
|
+
* Get up to `count` blocks following `afterHash`, in ascending chain order.
|
|
188
|
+
* Koios has no "next after hash" endpoint, so we list blocks above the anchor height
|
|
189
|
+
* (PostgREST gt + order + limit), then batch /block_info. When the caller already
|
|
190
|
+
* knows the anchor height (the crawler's cursor), the hash→height resolution
|
|
191
|
+
* round-trip is skipped entirely.
|
|
192
|
+
*/
|
|
193
|
+
getNextBlocks(afterHash: string, count: number, afterHeight?: number): Promise<BlockData[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Get the full transaction list of a block in block order via /block_txs → /tx_info
|
|
196
|
+
* batch. Handles both the current flattened shape ({tx_hash} per row) and the older
|
|
197
|
+
* {tx_hashes:[...]} shape defensively.
|
|
198
|
+
*/
|
|
199
|
+
getBlockTransactions(blockHash: string): Promise<Transaction[]>;
|
|
176
200
|
/**
|
|
177
201
|
* Map a Koios /tx_info response object to the normalized Transaction type.
|
|
178
202
|
*/
|
|
@@ -12,6 +12,9 @@ const mappers_1 = require("../../utils/mappers");
|
|
|
12
12
|
const const_1 = require("../../utils/const");
|
|
13
13
|
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
14
14
|
const logger = cds_1.default.log('KoiosBackend');
|
|
15
|
+
/** Bounded retries for instance-specific PostgREST server errors (42703, 57014, …). */
|
|
16
|
+
const PG_SERVER_ERROR_MAX_RETRIES = 2;
|
|
17
|
+
const PG_SERVER_ERROR_RETRY_DELAY_MS = 300;
|
|
15
18
|
const KOIOS_URLS = {
|
|
16
19
|
mainnet: 'https://api.koios.rest/api/v1',
|
|
17
20
|
preview: 'https://preview.koios.rest/api/v1',
|
|
@@ -72,6 +75,25 @@ class KoiosBackend {
|
|
|
72
75
|
headers,
|
|
73
76
|
});
|
|
74
77
|
this.network = network;
|
|
78
|
+
// Koios runs multiple instances behind a load balancer; during their schema
|
|
79
|
+
// migrations single instances serve broken SQL functions (PostgREST 400,
|
|
80
|
+
// e.g. code 42703 "column … does not exist") or hit statement timeouts
|
|
81
|
+
// (57014) while the rest are healthy. Such failures are instance-specific,
|
|
82
|
+
// so a short bounded retry usually lands on a healthy instance. Genuine
|
|
83
|
+
// client-input errors (PG class 22 etc.) are not retried.
|
|
84
|
+
this.api.interceptors.response.use(undefined, async (error) => {
|
|
85
|
+
const config = error.config;
|
|
86
|
+
const pgCode = error.response?.data?.code;
|
|
87
|
+
if (!config || !(0, errors_1.isPostgrestServerErrorCode)(pgCode))
|
|
88
|
+
throw error;
|
|
89
|
+
const attempt = (config.pgRetryCount ?? 0) + 1;
|
|
90
|
+
if (attempt > PG_SERVER_ERROR_MAX_RETRIES)
|
|
91
|
+
throw error;
|
|
92
|
+
config.pgRetryCount = attempt;
|
|
93
|
+
logger.warn(`Koios instance returned server-side SQL error ${pgCode} for ${config.url} — retry ${attempt}/${PG_SERVER_ERROR_MAX_RETRIES}`);
|
|
94
|
+
await new Promise(resolve => setTimeout(resolve, PG_SERVER_ERROR_RETRY_DELAY_MS * attempt));
|
|
95
|
+
return this.api.request(config);
|
|
96
|
+
});
|
|
75
97
|
}
|
|
76
98
|
/**
|
|
77
99
|
* Initialize the backend
|
|
@@ -181,19 +203,7 @@ class KoiosBackend {
|
|
|
181
203
|
if (!results || results.length === 0) {
|
|
182
204
|
throw new errors_1.NotFoundError('Block', this.name);
|
|
183
205
|
}
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
time: data.block_time,
|
|
187
|
-
height: data.block_height,
|
|
188
|
-
hash: data.hash,
|
|
189
|
-
slot: data.abs_slot,
|
|
190
|
-
epoch: data.epoch_no,
|
|
191
|
-
epochSlot: data.epoch_slot,
|
|
192
|
-
slotLeader: data.vrf_key,
|
|
193
|
-
size: data.block_size,
|
|
194
|
-
txCount: data.tx_count,
|
|
195
|
-
fees: data.total_fees,
|
|
196
|
-
};
|
|
206
|
+
return this.mapKoiosBlockInfo(results[0]);
|
|
197
207
|
}, this.name);
|
|
198
208
|
}
|
|
199
209
|
/**
|
|
@@ -596,14 +606,23 @@ class KoiosBackend {
|
|
|
596
606
|
throw new errors_1.NotFoundError('Drep', this.name);
|
|
597
607
|
}
|
|
598
608
|
const drepData = data[0];
|
|
609
|
+
// Koios changed the /drep_info schema (observed 2026-07): the old
|
|
610
|
+
// `expired`/`retired`/`last_active_epoch` fields were replaced by
|
|
611
|
+
// `drep_status` ('registered' | 'retired'), `active` (boolean) and
|
|
612
|
+
// `expires_epoch_no`. Read the old fields first (mainnet/preprod may
|
|
613
|
+
// lag the migration), then derive from the new ones.
|
|
614
|
+
const retired = drepData.retired ?? drepData.drep_status === 'retired';
|
|
615
|
+
const expired = drepData.expired ?? (drepData.active === false && !retired);
|
|
599
616
|
return {
|
|
600
617
|
drepId: drepData.drep_id,
|
|
601
618
|
hex: drepData.hex,
|
|
602
619
|
amount: drepData.amount,
|
|
603
620
|
hasScript: drepData.has_script,
|
|
621
|
+
// The new schema no longer reports the last-activity epoch (only
|
|
622
|
+
// `expires_epoch_no`, which has different semantics) — keep 0 there.
|
|
604
623
|
lastActiveEpoch: drepData.last_active_epoch ?? 0,
|
|
605
|
-
expired
|
|
606
|
-
retired
|
|
624
|
+
expired,
|
|
625
|
+
retired,
|
|
607
626
|
};
|
|
608
627
|
}, this.name);
|
|
609
628
|
}
|
|
@@ -840,6 +859,119 @@ class KoiosBackend {
|
|
|
840
859
|
return result;
|
|
841
860
|
}, this.name);
|
|
842
861
|
}
|
|
862
|
+
// ---------------------------------------------------------------------------
|
|
863
|
+
// PaginatingBackend — forward iteration for the chain crawler (v2.0)
|
|
864
|
+
// ---------------------------------------------------------------------------
|
|
865
|
+
/**
|
|
866
|
+
* Map a Koios /block_info response object to our BlockData (same shape getBlock
|
|
867
|
+
* maps inline; kept private to avoid touching getBlock).
|
|
868
|
+
*/
|
|
869
|
+
mapKoiosBlockInfo(data) {
|
|
870
|
+
return {
|
|
871
|
+
time: data.block_time,
|
|
872
|
+
height: data.block_height,
|
|
873
|
+
hash: data.hash,
|
|
874
|
+
slot: data.abs_slot,
|
|
875
|
+
epoch: data.epoch_no,
|
|
876
|
+
epochSlot: data.epoch_slot,
|
|
877
|
+
slotLeader: data.vrf_key,
|
|
878
|
+
size: data.block_size,
|
|
879
|
+
txCount: data.tx_count,
|
|
880
|
+
fees: data.total_fees,
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Get a block by its height via the PostgREST-filtered /blocks list, then resolve
|
|
885
|
+
* full data through /block_info.
|
|
886
|
+
*/
|
|
887
|
+
async getBlockByHeight(height) {
|
|
888
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
889
|
+
const rows = await this.fetchWithRetryOnEmpty(() => this.api.get(`/blocks?block_height=eq.${height}&limit=1`), `getBlockByHeight(${height})`);
|
|
890
|
+
if (!rows.length)
|
|
891
|
+
throw new errors_1.NotFoundError('Block', this.name);
|
|
892
|
+
return await this.getBlock(rows[0].hash);
|
|
893
|
+
}, this.name);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Get up to `count` blocks following `afterHash`, in ascending chain order.
|
|
897
|
+
* Koios has no "next after hash" endpoint, so we list blocks above the anchor height
|
|
898
|
+
* (PostgREST gt + order + limit), then batch /block_info. When the caller already
|
|
899
|
+
* knows the anchor height (the crawler's cursor), the hash→height resolution
|
|
900
|
+
* round-trip is skipped entirely.
|
|
901
|
+
*/
|
|
902
|
+
async getNextBlocks(afterHash, count, afterHeight) {
|
|
903
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
904
|
+
let anchorHeight = afterHeight;
|
|
905
|
+
if (anchorHeight != null && anchorHeight > 0) {
|
|
906
|
+
// A height hint saves the hash -> height lookup, but it must never be
|
|
907
|
+
// trusted as proof that the cursor is still on the canonical chain.
|
|
908
|
+
// After a rollback Koios can continue listing canonical blocks above H
|
|
909
|
+
// even though `afterHash` is the now-orphaned block at H. Validate the
|
|
910
|
+
// canonical hash first so the crawler enters its reorg-recovery path.
|
|
911
|
+
const canonical = await this.fetchWithRetryOnEmpty(() => this.api.get(`/blocks?block_height=eq.${anchorHeight}&limit=1`), `getNextBlocks/anchor(${anchorHeight})`);
|
|
912
|
+
const canonicalHash = canonical[0]?.hash;
|
|
913
|
+
if (!canonicalHash) {
|
|
914
|
+
throw new errors_1.ProviderUnavailableError(`Unable to validate canonical block at height ${anchorHeight}`, this.name);
|
|
915
|
+
}
|
|
916
|
+
if (canonicalHash !== afterHash) {
|
|
917
|
+
throw new errors_1.ProviderUnavailableError(`CHAIN_POINT_MISMATCH: cursor block ${afterHash} at height ${anchorHeight} is no longer canonical (canonical block: ${canonicalHash})`, this.name);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
const info = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_info', { _block_hashes: [afterHash] }), `getNextBlocks/height(${afterHash})`);
|
|
922
|
+
if (!info.length)
|
|
923
|
+
throw new errors_1.NotFoundError('Block', this.name);
|
|
924
|
+
anchorHeight = info[0].block_height;
|
|
925
|
+
}
|
|
926
|
+
const rows = await this.fetchWithRetryOnEmpty(() => this.api.get(`/blocks?block_height=gt.${anchorHeight}&order=block_height.asc&limit=${count}`), `getNextBlocks(${afterHash})`);
|
|
927
|
+
if (!rows.length)
|
|
928
|
+
return [];
|
|
929
|
+
const requestedHashes = rows.map((r) => r.hash);
|
|
930
|
+
const infos = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_info', { _block_hashes: requestedHashes }), `getNextBlocks/info(${afterHash})`);
|
|
931
|
+
// Completeness guard: Koios' load-balanced instances can return a PARTIAL
|
|
932
|
+
// /block_info batch (fetchWithRetryOnEmpty only retries fully empty
|
|
933
|
+
// responses). Returning the subset would let the crawler advance its cursor
|
|
934
|
+
// past the missing block, leaving a permanent hole in the pre-synced range
|
|
935
|
+
// (crawled entities are non-temporal — nothing re-fetches them). Fail the
|
|
936
|
+
// round as transient instead; the next round retries the same anchor.
|
|
937
|
+
if (infos.length < requestedHashes.length) {
|
|
938
|
+
const returned = new Set(infos.map((d) => d.hash));
|
|
939
|
+
const missing = requestedHashes.filter((h) => !returned.has(h));
|
|
940
|
+
throw new errors_1.ProviderUnavailableError(`Incomplete /block_info batch: ${infos.length}/${requestedHashes.length} blocks returned (missing: ${missing.slice(0, 3).join(', ')}${missing.length > 3 ? ', …' : ''})`, this.name);
|
|
941
|
+
}
|
|
942
|
+
return infos
|
|
943
|
+
.map((d) => this.mapKoiosBlockInfo(d))
|
|
944
|
+
.sort((a, b) => (a.height ?? 0) - (b.height ?? 0));
|
|
945
|
+
}, this.name);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Get the full transaction list of a block in block order via /block_txs → /tx_info
|
|
949
|
+
* batch. Handles both the current flattened shape ({tx_hash} per row) and the older
|
|
950
|
+
* {tx_hashes:[...]} shape defensively.
|
|
951
|
+
*/
|
|
952
|
+
async getBlockTransactions(blockHash) {
|
|
953
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
954
|
+
const rows = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_txs', { _block_hashes: [blockHash] }), `getBlockTransactions(${blockHash})`);
|
|
955
|
+
const hashes = [];
|
|
956
|
+
for (const row of rows) {
|
|
957
|
+
if (Array.isArray(row.tx_hashes))
|
|
958
|
+
hashes.push(...row.tx_hashes);
|
|
959
|
+
else if (row.tx_hash)
|
|
960
|
+
hashes.push(row.tx_hash);
|
|
961
|
+
}
|
|
962
|
+
if (!hashes.length)
|
|
963
|
+
return [];
|
|
964
|
+
const byHash = await this.getTransactionsBatch(hashes);
|
|
965
|
+
const missing = hashes.filter(h => !byHash.has(h));
|
|
966
|
+
if (missing.length > 0) {
|
|
967
|
+
// Advancing the block cursor with only a subset of /tx_info would make
|
|
968
|
+
// the omitted transactions permanent. Surface a 503 so the crawler
|
|
969
|
+
// retries the whole block without persisting it.
|
|
970
|
+
throw new errors_1.ProviderUnavailableError(`Incomplete transaction data for block ${blockHash}: ${missing.length}/${hashes.length} transaction(s) missing`, this.name);
|
|
971
|
+
}
|
|
972
|
+
return hashes.map(h => byHash.get(h));
|
|
973
|
+
}, this.name);
|
|
974
|
+
}
|
|
843
975
|
//-----------------------------------------------------------------------------
|
|
844
976
|
// Private Helpers
|
|
845
977
|
//-----------------------------------------------------------------------------
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, AccountData, DrepData, AssetInfo, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
|
|
2
|
-
import { EvaluatingBackend } from './cardano-backend';
|
|
2
|
+
import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint } from './cardano-backend';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
4
|
/** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
|
|
5
5
|
export declare function resolveOgmiosTip(tip: 'origin' | {
|
|
@@ -11,11 +11,7 @@ export declare function resolveOgmiosTip(tip: 'origin' | {
|
|
|
11
11
|
};
|
|
12
12
|
/** Resolve Ogmios block height which may be 'origin' (genesis block) or a number */
|
|
13
13
|
export declare function resolveOgmiosHeight(height: 'origin' | number): number;
|
|
14
|
-
|
|
15
|
-
* Ogmios Backend Implementation for Cardano Backend Interface
|
|
16
|
-
* Implements the CardanoBackend interface using Ogmios WebSocket client for local node interaction
|
|
17
|
-
*/
|
|
18
|
-
export declare class OgmiosBackend implements EvaluatingBackend {
|
|
14
|
+
export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBackend {
|
|
19
15
|
readonly name = "ogmios";
|
|
20
16
|
/**
|
|
21
17
|
* Capability declaration — the orchestrator skips Ogmios for these without
|
|
@@ -68,6 +64,13 @@ export declare class OgmiosBackend implements EvaluatingBackend {
|
|
|
68
64
|
* retry picks it up instead of dying.
|
|
69
65
|
*/
|
|
70
66
|
private withInitTimeout;
|
|
67
|
+
/**
|
|
68
|
+
* Force-release an Ogmios interaction socket after a failed/expired open or
|
|
69
|
+
* close step. The runtime uses `ws` (and therefore supports `terminate`), but
|
|
70
|
+
* the close fallback keeps the helper compatible with the public structural
|
|
71
|
+
* InteractionContext type and lightweight test doubles.
|
|
72
|
+
*/
|
|
73
|
+
private forceCloseContext;
|
|
71
74
|
/**
|
|
72
75
|
* Initialize the Ogmios backend connection
|
|
73
76
|
*/
|
|
@@ -212,5 +215,33 @@ export declare class OgmiosBackend implements EvaluatingBackend {
|
|
|
212
215
|
* Standard: [{ unit: 'lovelace', quantity: '1000000' }, { unit: 'policyId.assetName', quantity: 'N' }]
|
|
213
216
|
*/
|
|
214
217
|
private convertOgmiosValue;
|
|
218
|
+
/**
|
|
219
|
+
* Open a dedicated chain-synchronization stream. Uses its own InteractionContext
|
|
220
|
+
* (a separate WebSocket) from the query/submission clients, because it is a
|
|
221
|
+
* long-lived stream. `sequential: true` + `inFlight: 1` deliver blocks one at a
|
|
222
|
+
* time in order, which the crawler needs for reorg detection and serial persist.
|
|
223
|
+
*
|
|
224
|
+
* KNOWN LIMITATIONS (documented, to harden against a live node — see CRAWLER_DESIGN.md):
|
|
225
|
+
* - Input address/amount are left empty: Ogmios chain-sync inputs are bare
|
|
226
|
+
* references ({txId,index}); the indexer resolves them from already-indexed
|
|
227
|
+
* outputs (indexBlockFull, C3).
|
|
228
|
+
* - Per-tx `size` and `deposit` are not surfaced by chain-sync (set 0).
|
|
229
|
+
* - Output `referenceScriptHash` is not derived from the inline script yet.
|
|
230
|
+
*/
|
|
231
|
+
openChainSync(from: ChainPoint[] | 'origin', callbacks: ChainSyncCallbacks): Promise<ChainSyncHandle>;
|
|
232
|
+
/**
|
|
233
|
+
* Map an Ogmios Praos block into our BlockData + its transactions. Block-level
|
|
234
|
+
* fees are the sum of per-tx fees; epoch/epochSlot are derived from the slot via
|
|
235
|
+
* the network's Shelley anchor (same config the tx-builder uses).
|
|
236
|
+
*/
|
|
237
|
+
private mapOgmiosBlock;
|
|
238
|
+
/**
|
|
239
|
+
* Map a single Ogmios chain-sync transaction into our Transaction. Outputs, fee
|
|
240
|
+
* and metadata are mapped fully; inputs are kept as bare references (address/amount
|
|
241
|
+
* resolved downstream by the indexer). `spends` selects the ledger-applied
|
|
242
|
+
* partition: a phase-2-invalid transaction consumes collaterals and creates only
|
|
243
|
+
* its collateral-return output, never its declared regular inputs/outputs.
|
|
244
|
+
*/
|
|
245
|
+
private mapOgmiosTx;
|
|
215
246
|
}
|
|
216
247
|
//# sourceMappingURL=ogmios-backend.d.ts.map
|