@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45
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 +0 -46
- package/@cds-models/CardanoBackendService/index.d.ts +0 -10
- package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +19 -47
- package/@cds-models/CardanoSignService/index.d.ts +3 -18
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
- package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
- package/@cds-models/index.d.ts +17 -0
- package/@cds-models/index.js +2 -0
- package/@cds-models/odatano/cardano/index.d.ts +1 -34
- package/README.md +6 -6
- package/db/schema.cds +29 -44
- package/db/types.cds +22 -5
- package/package.json +3 -1
- package/scripts/migrate-slot-leader.mjs +3 -11
- package/scripts/migrate-txseq.mjs +3 -12
- package/src/index.d.ts +0 -4
- package/src/index.js +3 -5
- package/src/plugin.js +4 -8
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -10
- package/srv/blockchain/backends/blockfrost-backend.js +15 -21
- package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
- package/srv/blockchain/backends/koios-backend.d.ts +14 -147
- package/srv/blockchain/backends/koios-backend.js +40 -164
- package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
- package/srv/blockchain/backends/odatano-backend.js +11 -12
- package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
- package/srv/blockchain/backends/ogmios-backend.js +48 -175
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
- package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
- package/srv/blockchain/cardano-client.d.ts +12 -80
- package/srv/blockchain/cardano-client.js +36 -88
- package/srv/blockchain/cardano-indexer.d.ts +12 -192
- package/srv/blockchain/cardano-indexer.js +132 -222
- package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
- package/srv/blockchain/cardano-tx-builder.js +17 -34
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
- package/srv/blockchain/crawler/certificate-backfill.js +8 -22
- package/srv/blockchain/crawler/crawler.d.ts +16 -93
- package/srv/blockchain/crawler/crawler.js +85 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
- package/srv/blockchain/crawler/credential-backfill.js +6 -6
- package/srv/blockchain/crawler/hooks.d.ts +1 -5
- package/srv/blockchain/crawler/index.d.ts +0 -12
- package/srv/blockchain/crawler/index.js +6 -20
- package/srv/blockchain/crawler/sync-state.d.ts +6 -44
- package/srv/blockchain/crawler/sync-state.js +18 -53
- package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
- package/srv/blockchain/crawler/transaction-backfill.js +11 -30
- package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
- package/srv/blockchain/crawler/utxo-set-import.js +27 -53
- package/srv/blockchain/ledger-state.d.ts +10 -54
- package/srv/blockchain/ledger-state.js +11 -27
- package/srv/blockchain/pending-spends.d.ts +0 -12
- package/srv/blockchain/pending-spends.js +4 -12
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +0 -9
- package/srv/blockchain/signing/cose-verifier.js +4 -10
- package/srv/blockchain/signing/external-signer.d.ts +1 -4
- package/srv/blockchain/signing/external-signer.js +2 -8
- package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
- package/srv/blockchain/signing/hsm-signer.js +16 -28
- package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
- package/srv/blockchain/signing/signature-verifier.js +9 -19
- package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
- package/srv/blockchain/signing/submission-finalizer.js +48 -19
- package/srv/blockchain/stored-chain.d.ts +1 -14
- package/srv/blockchain/stored-chain.js +3 -8
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
- package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
- package/srv/blockchain/transaction-building/caller-datums.js +3 -9
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
- package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
- package/srv/blockchain/wallet-worker/build-request.js +6 -9
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -5
- package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
- package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
- package/srv/blockchain/wallet-worker/signers.js +3 -6
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
- package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
- package/srv/cardano-agent-service.cds +123 -146
- package/srv/cardano-agent-service.js +2 -5
- package/srv/cardano-backend-service.cds +10 -17
- package/srv/cardano-backend-service.js +7 -12
- package/srv/cardano-indexer-service.cds +35 -37
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +64 -33
- package/srv/cardano-service.cds +56 -40
- package/srv/cardano-service.js +42 -69
- package/srv/cardano-sign-service.cds +14 -23
- package/srv/cardano-sign-service.js +18 -24
- package/srv/cardano-tx-service.cds +27 -29
- package/srv/cardano-tx-service.js +60 -122
- package/srv/cardano-worker-service.cds +109 -125
- package/srv/cardano-worker-service.js +21 -31
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +6 -1
- package/srv/cbor/parse.d.ts +3 -18
- package/srv/cbor/parse.js +2 -7
- package/srv/cbor/plutus-data-json.d.ts +0 -4
- package/srv/server.d.ts +5 -36
- package/srv/server.js +30 -51
- package/srv/utils/agent-grants-config.d.ts +0 -18
- package/srv/utils/agent-grants-config.js +6 -13
- package/srv/utils/agent-grants.d.ts +14 -68
- package/srv/utils/agent-grants.js +42 -60
- package/srv/utils/agent-token-auth.d.ts +0 -5
- package/srv/utils/agent-token-auth.js +2 -5
- package/srv/utils/backend-request-handler.d.ts +1 -1
- package/srv/utils/collections.d.ts +1 -4
- package/srv/utils/collections.js +1 -4
- package/srv/utils/const.d.ts +0 -18
- package/srv/utils/const.js +7 -18
- package/srv/utils/crypto.js +3 -5
- package/srv/utils/db-indexes.d.ts +2 -0
- package/srv/utils/db-indexes.js +22 -9
- package/srv/utils/db-sanitize.d.ts +1 -8
- package/srv/utils/db-sanitize.js +3 -8
- package/srv/utils/epoch-slots.d.ts +1 -8
- package/srv/utils/epoch-slots.js +3 -8
- package/srv/utils/error-codes.d.ts +0 -4
- package/srv/utils/error-codes.js +2 -4
- package/srv/utils/errors.d.ts +2 -22
- package/srv/utils/errors.js +13 -27
- package/srv/utils/liveness.d.ts +0 -4
- package/srv/utils/liveness.js +2 -4
- package/srv/utils/mappers.d.ts +0 -37
- package/srv/utils/mappers.js +22 -39
- package/srv/utils/network-context.js +2 -4
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.js +3 -7
- package/srv/utils/pg-order-nulls.js +2 -5
- package/srv/utils/plutus-placeholders.d.ts +0 -13
- package/srv/utils/plutus-placeholders.js +6 -13
- package/srv/utils/rate-limiter.d.ts +0 -8
- package/srv/utils/rate-limiter.js +2 -4
- package/srv/utils/reference-script.d.ts +0 -18
- package/srv/utils/reference-script.js +8 -19
- package/srv/utils/service-events.d.ts +0 -4
- package/srv/utils/service-events.js +2 -4
- package/srv/utils/signing-helper.d.ts +1 -8
- package/srv/utils/signing-helper.js +3 -8
- package/srv/utils/tx-build-helper.d.ts +2 -32
- package/srv/utils/tx-build-helper.js +26 -40
- package/srv/utils/tx-request-parsers.d.ts +1 -25
- package/srv/utils/tx-request-parsers.js +10 -25
- package/srv/utils/tx-utils.d.ts +0 -8
- package/srv/utils/tx-utils.js +10 -13
- package/srv/utils/types.d.ts +2 -37
- package/srv/utils/validators.d.ts +0 -4
- package/srv/utils/validators.js +2 -4
|
@@ -22,10 +22,7 @@ const KOIOS_URLS = {
|
|
|
22
22
|
preview: 'https://preview.koios.rest/api/v1',
|
|
23
23
|
preprod: 'https://preprod.koios.rest/api/v1',
|
|
24
24
|
};
|
|
25
|
-
/**
|
|
26
|
-
* Koios `reference_script` (`_extended: true`) is an object `{ hash, size, type, bytes, value }`.
|
|
27
|
-
* Returns the full script CBOR when present (needed for local Plutus eval), else the hash.
|
|
28
|
-
*/
|
|
25
|
+
/** Script CBOR from a Koios `reference_script` object, else its hash. Local Plutus eval needs the CBOR. */
|
|
29
26
|
function koiosRefScriptBytes(ref) {
|
|
30
27
|
if (!ref)
|
|
31
28
|
return null;
|
|
@@ -51,7 +48,7 @@ function koiosRefScriptMeta(ref) {
|
|
|
51
48
|
const size = Number(obj.size);
|
|
52
49
|
return { size: Number.isInteger(size) && size > 0 ? size : null, type: (0, reference_script_1.normalizeScriptType)(obj.type) };
|
|
53
50
|
}
|
|
54
|
-
/** Sort Koios /address_txs rows newest
|
|
51
|
+
/** Sort Koios /address_txs rows newest first. Koios gives no ordering guarantee. */
|
|
55
52
|
function sortAddressTxsDesc(rows) {
|
|
56
53
|
return [...rows].sort((a, b) => Number(b.block_height ?? b.block_time ?? 0) - Number(a.block_height ?? a.block_time ?? 0));
|
|
57
54
|
}
|
|
@@ -106,7 +103,7 @@ class KoiosBackend {
|
|
|
106
103
|
if (attempt > PG_SERVER_ERROR_MAX_RETRIES)
|
|
107
104
|
throw error;
|
|
108
105
|
config.pgRetryCount = attempt;
|
|
109
|
-
logger.warn(`Koios instance returned server-side SQL error ${pgCode} for ${config.url}
|
|
106
|
+
logger.warn(`Koios instance returned server-side SQL error ${pgCode} for ${config.url}, retry ${attempt}/${PG_SERVER_ERROR_MAX_RETRIES}`);
|
|
110
107
|
await new Promise(resolve => setTimeout(resolve, PG_SERVER_ERROR_RETRY_DELAY_MS * attempt));
|
|
111
108
|
return this.api.request(config);
|
|
112
109
|
});
|
|
@@ -121,10 +118,7 @@ class KoiosBackend {
|
|
|
121
118
|
}
|
|
122
119
|
return true;
|
|
123
120
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Retry (500 → 1000 → 2000 ms) when Koios transiently returns [] for a valid query.
|
|
126
|
-
* Only non-emptiness is checked here; rows keep the caller's element type.
|
|
127
|
-
*/
|
|
121
|
+
/** Retry with backoff when Koios briefly returns [] for a valid query. */
|
|
128
122
|
async fetchWithRetryOnEmpty(fn, label) {
|
|
129
123
|
const maxRetries = 3;
|
|
130
124
|
const baseDelayMs = 500;
|
|
@@ -143,11 +137,8 @@ class KoiosBackend {
|
|
|
143
137
|
}
|
|
144
138
|
return [];
|
|
145
139
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* version-skewed Koios instances behind the load balancer return it for a request that
|
|
149
|
-
* healthy instances serve fine. Other 400s still fail fast.
|
|
150
|
-
*/
|
|
140
|
+
// Retry on Postgres error 42804. Outdated Koios instances behind the load balancer return it
|
|
141
|
+
// for requests that healthy instances serve. Other 400s still fail fast.
|
|
151
142
|
async getWithRetryOn42804(url, config, label) {
|
|
152
143
|
const maxRetries = 8;
|
|
153
144
|
const baseDelayMs = 300;
|
|
@@ -168,11 +159,6 @@ class KoiosBackend {
|
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
161
|
}
|
|
171
|
-
/**
|
|
172
|
-
* Get Transaction Data for specified transaction hash
|
|
173
|
-
* @param hash transaction hash (hex)
|
|
174
|
-
* @returns {Promise<Transaction>} transaction data
|
|
175
|
-
*/
|
|
176
162
|
async getTransaction(hash) {
|
|
177
163
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
178
164
|
const body = {
|
|
@@ -193,11 +179,6 @@ class KoiosBackend {
|
|
|
193
179
|
return this._mapKoiosTx(tx);
|
|
194
180
|
}, this.name);
|
|
195
181
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Get Block Data for specified block hash
|
|
198
|
-
* @param blockHash block hash (hex)
|
|
199
|
-
* @returns {Promise<BlockData>} block data
|
|
200
|
-
*/
|
|
201
182
|
async getBlock(blockHash) {
|
|
202
183
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
203
184
|
const results = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_info', { _block_hashes: [blockHash] }), `getBlock(${blockHash})`);
|
|
@@ -207,11 +188,6 @@ class KoiosBackend {
|
|
|
207
188
|
return this.mapKoiosBlockInfo(results[0]);
|
|
208
189
|
}, this.name);
|
|
209
190
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Get Epoch Data for specified epoch number
|
|
212
|
-
* @param epochNumber epoch number
|
|
213
|
-
* @returns {Promise<EpochData>} epoch data
|
|
214
|
-
*/
|
|
215
191
|
async getEpoch(epochNumber) {
|
|
216
192
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
217
193
|
const results = await this.fetchWithRetryOnEmpty(() => this.getWithRetryOn42804('/epoch_info', { params: { _epoch_no: epochNumber } }, `getEpoch(${epochNumber})`), `getEpoch(${epochNumber})`);
|
|
@@ -233,11 +209,7 @@ class KoiosBackend {
|
|
|
233
209
|
};
|
|
234
210
|
}, this.name);
|
|
235
211
|
}
|
|
236
|
-
/**
|
|
237
|
-
* Get Address Data (without transactions - use getAddressTransactions() separately)
|
|
238
|
-
* @param address bech32 address
|
|
239
|
-
* @returns {Promise<Address>} address data
|
|
240
|
-
*/
|
|
212
|
+
/** Address data. Transactions come from getAddressTransactions(). */
|
|
241
213
|
async getAddress(address) {
|
|
242
214
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
243
215
|
const { data } = await this.api.post('/address_info', { _addresses: [address] });
|
|
@@ -268,11 +240,6 @@ class KoiosBackend {
|
|
|
268
240
|
};
|
|
269
241
|
}, this.name);
|
|
270
242
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Get Address Transactions
|
|
273
|
-
* @param address bech32 address
|
|
274
|
-
* @returns {Promise<Transaction[]>} list of transactions for this address
|
|
275
|
-
*/
|
|
276
243
|
async getAddressTransactions(address, limit) {
|
|
277
244
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
278
245
|
const { data: addressTxs } = await this.api.post('/address_txs', { _addresses: [address] });
|
|
@@ -288,11 +255,6 @@ class KoiosBackend {
|
|
|
288
255
|
return transactions;
|
|
289
256
|
}, this.name);
|
|
290
257
|
}
|
|
291
|
-
/**
|
|
292
|
-
* Get Address UTxOs for specified address
|
|
293
|
-
* @param address bech32 address
|
|
294
|
-
* @returns {Promise<UTxO[]>} list of UTxOs
|
|
295
|
-
*/
|
|
296
258
|
async getAddressUtxos(address) {
|
|
297
259
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
298
260
|
const { data } = await this.api.post('/address_utxos', { _addresses: [address], _extended: true });
|
|
@@ -323,10 +285,7 @@ class KoiosBackend {
|
|
|
323
285
|
});
|
|
324
286
|
}, this.name);
|
|
325
287
|
}
|
|
326
|
-
/**
|
|
327
|
-
* UTxOs across all bech32 addresses sharing a payment credential (native Koios endpoint).
|
|
328
|
-
* @param credHash 28-byte payment credential as 56-char lowercase hex
|
|
329
|
-
*/
|
|
288
|
+
/** UTxOs of every address with this payment credential (56 hex chars). */
|
|
330
289
|
async getCredentialUtxos(credHash) {
|
|
331
290
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
332
291
|
const { data } = await this.api.post('/credential_utxos', {
|
|
@@ -359,10 +318,6 @@ class KoiosBackend {
|
|
|
359
318
|
});
|
|
360
319
|
}, this.name);
|
|
361
320
|
}
|
|
362
|
-
/**
|
|
363
|
-
* Get Network Information
|
|
364
|
-
* @returns {Promise<Network>} network information
|
|
365
|
-
*/
|
|
366
321
|
async getNetworkInformation() {
|
|
367
322
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
368
323
|
// /totals works on mainnet but returns [] on preview/preprod
|
|
@@ -409,11 +364,6 @@ class KoiosBackend {
|
|
|
409
364
|
};
|
|
410
365
|
}, this.name);
|
|
411
366
|
}
|
|
412
|
-
/**
|
|
413
|
-
* Get Transaction Metadata for specified transaction hash
|
|
414
|
-
* @param tx_hash transaction hash (hex)
|
|
415
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata list
|
|
416
|
-
*/
|
|
417
367
|
async getTransactionMetadata(tx_hash) {
|
|
418
368
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
419
369
|
const body = {
|
|
@@ -438,11 +388,6 @@ class KoiosBackend {
|
|
|
438
388
|
return labels;
|
|
439
389
|
}, this.name);
|
|
440
390
|
}
|
|
441
|
-
/**
|
|
442
|
-
* Get Pool Data for specified pool id
|
|
443
|
-
* @param poolId pool id
|
|
444
|
-
* @returns {Promise<PoolData>} pool data
|
|
445
|
-
*/
|
|
446
391
|
async getPool(poolId) {
|
|
447
392
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
448
393
|
const { data } = await this.api.post('/pool_info', { _pool_bech32_ids: [poolId] });
|
|
@@ -465,8 +410,8 @@ class KoiosBackend {
|
|
|
465
410
|
// /pool_info has no live share
|
|
466
411
|
liveSize: null,
|
|
467
412
|
liveDelegators: poolData.live_delegators || 0,
|
|
468
|
-
// Koios reports saturation in
|
|
469
|
-
//
|
|
413
|
+
// Koios reports saturation in percent (75.42). PoolData holds a fraction (0.7542),
|
|
414
|
+
// because the percent value would overflow the Decimal(9, 4) column.
|
|
470
415
|
liveSaturation: (Number(poolData.live_saturation) || 0) / 100,
|
|
471
416
|
activeStake: poolData.active_stake || '0',
|
|
472
417
|
activeSize: Number(poolData.sigma) || 0,
|
|
@@ -476,10 +421,7 @@ class KoiosBackend {
|
|
|
476
421
|
rewardAccount: poolData.reward_addr || '',
|
|
477
422
|
};
|
|
478
423
|
}
|
|
479
|
-
/**
|
|
480
|
-
* Asset info from Koios `asset_info`: supply, mint/burn counts, minting tx, CIP-25 + CIP-26 metadata.
|
|
481
|
-
* @param unit policyId + assetNameHex (concatenated hex)
|
|
482
|
-
*/
|
|
424
|
+
/** Asset info from Koios `asset_info`. */
|
|
483
425
|
async getAssetInfo(unit) {
|
|
484
426
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
485
427
|
if (unit.length < 56 || !/^[a-f0-9]+$/i.test(unit)) {
|
|
@@ -495,7 +437,7 @@ class KoiosBackend {
|
|
|
495
437
|
}
|
|
496
438
|
const a = data[0];
|
|
497
439
|
// Koios token_registry_metadata fields are typically strings, but the
|
|
498
|
-
// CIP-26 registry
|
|
440
|
+
// CIP-26 registry entries may be wrapped in {value, signatures}. Accept either form.
|
|
499
441
|
const regRaw = (a.token_registry_metadata ?? null);
|
|
500
442
|
const regStr = (key) => {
|
|
501
443
|
const v = regRaw?.[key];
|
|
@@ -543,11 +485,8 @@ class KoiosBackend {
|
|
|
543
485
|
};
|
|
544
486
|
}, this.name);
|
|
545
487
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
* (negative = burn): action derives from the sign, `quantity` stores the absolute value,
|
|
549
|
-
* `limit` is applied client-side after sorting by block_time desc.
|
|
550
|
-
*/
|
|
488
|
+
// Koios `asset_history` returns all events with a signed quantity. A negative one is a burn.
|
|
489
|
+
// `limit` is applied here after sorting newest first.
|
|
551
490
|
async getAssetHistory(unit, limit = 100) {
|
|
552
491
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
553
492
|
if (unit.length < 56 || !/^[a-f0-9]+$/i.test(unit)) {
|
|
@@ -575,16 +514,11 @@ class KoiosBackend {
|
|
|
575
514
|
blockHeight: null,
|
|
576
515
|
};
|
|
577
516
|
});
|
|
578
|
-
//
|
|
517
|
+
// Koios may return ascending order
|
|
579
518
|
events.sort((a, b) => (b.blockTime ?? 0) - (a.blockTime ?? 0));
|
|
580
519
|
return events.slice(0, Math.max(1, limit));
|
|
581
520
|
}, this.name);
|
|
582
521
|
}
|
|
583
|
-
/**
|
|
584
|
-
* Get Drep Data for specified drep id
|
|
585
|
-
* @param drepId drep id
|
|
586
|
-
* @returns {Promise<DrepData>} drep data
|
|
587
|
-
*/
|
|
588
522
|
async getDrep(drepId) {
|
|
589
523
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
590
524
|
const body = {
|
|
@@ -608,17 +542,12 @@ class KoiosBackend {
|
|
|
608
542
|
hex: drepData.hex,
|
|
609
543
|
amount: drepData.amount,
|
|
610
544
|
hasScript: drepData.has_script,
|
|
611
|
-
// The newer schema has no last-activity epoch
|
|
545
|
+
// The newer schema has no last-activity epoch, and `expires_epoch_no` means something else.
|
|
612
546
|
lastActiveEpoch: drepData.last_active_epoch ?? 0,
|
|
613
547
|
expired,
|
|
614
548
|
retired,
|
|
615
549
|
};
|
|
616
550
|
}
|
|
617
|
-
/**
|
|
618
|
-
* Get Account Data for specified stake address
|
|
619
|
-
* @param accountId account id
|
|
620
|
-
* @returns {Promise<AccountData>} account data
|
|
621
|
-
*/
|
|
622
551
|
async getAccount(accountId) {
|
|
623
552
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
624
553
|
const body = {
|
|
@@ -656,11 +585,6 @@ class KoiosBackend {
|
|
|
656
585
|
};
|
|
657
586
|
}, this.name);
|
|
658
587
|
}
|
|
659
|
-
/**
|
|
660
|
-
* Submit Transaction
|
|
661
|
-
* @param signedTxCbor signed transaction in CBOR hex format
|
|
662
|
-
* @returns {Promise<string>} transaction hash
|
|
663
|
-
*/
|
|
664
588
|
async submitTransaction(signedTxCbor) {
|
|
665
589
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
666
590
|
// Koios /submittx expects raw CBOR bytes with Content-Type: application/cbor
|
|
@@ -688,10 +612,6 @@ class KoiosBackend {
|
|
|
688
612
|
}
|
|
689
613
|
}, this.name);
|
|
690
614
|
}
|
|
691
|
-
/**
|
|
692
|
-
* Get Protocol Parameters
|
|
693
|
-
* @returns {Promise<any>} protocol parameters
|
|
694
|
-
*/
|
|
695
615
|
async getProtocolParameters() {
|
|
696
616
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
697
617
|
// /cli_protocol_params carries no epoch; the tip does. Without it the epoch stays 0.
|
|
@@ -748,10 +668,6 @@ class KoiosBackend {
|
|
|
748
668
|
};
|
|
749
669
|
}, this.name);
|
|
750
670
|
}
|
|
751
|
-
/**
|
|
752
|
-
* Get Latest Block Data
|
|
753
|
-
* @returns {Promise<BlockData>} latest block data
|
|
754
|
-
*/
|
|
755
671
|
async getLatestBlock() {
|
|
756
672
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
757
673
|
const tipData = await this.fetchWithRetryOnEmpty(() => this.api.get('/tip'), 'getLatestBlock');
|
|
@@ -761,10 +677,6 @@ class KoiosBackend {
|
|
|
761
677
|
return await this.getBlock(tipData[0].hash);
|
|
762
678
|
}, this.name);
|
|
763
679
|
}
|
|
764
|
-
/**
|
|
765
|
-
* Get Latest Epoch Data
|
|
766
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
767
|
-
*/
|
|
768
680
|
async getLatestEpoch() {
|
|
769
681
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
770
682
|
const tipData = await this.fetchWithRetryOnEmpty(() => this.api.get('/tip'), 'getLatestEpoch');
|
|
@@ -776,15 +688,11 @@ class KoiosBackend {
|
|
|
776
688
|
return await this.getEpoch(epochNo);
|
|
777
689
|
}
|
|
778
690
|
catch {
|
|
779
|
-
//
|
|
691
|
+
// Koios may not have the current epoch yet, so use the previous one
|
|
780
692
|
return await this.getEpoch(epochNo - 1);
|
|
781
693
|
}
|
|
782
694
|
}, this.name);
|
|
783
695
|
}
|
|
784
|
-
/**
|
|
785
|
-
* Get the latest chain tip slot.
|
|
786
|
-
* @returns {Promise<number>} current chain slot
|
|
787
|
-
*/
|
|
788
696
|
async getCurrentSlot() {
|
|
789
697
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
790
698
|
const tipData = await this.fetchWithRetryOnEmpty(() => this.api.get('/tip'), 'getCurrentSlot');
|
|
@@ -798,12 +706,7 @@ class KoiosBackend {
|
|
|
798
706
|
return slot;
|
|
799
707
|
}, this.name);
|
|
800
708
|
}
|
|
801
|
-
/**
|
|
802
|
-
* Check whether a UTxO is still unspent via Koios `POST /utxo_info`.
|
|
803
|
-
* @param txHash 64-char lowercase hex
|
|
804
|
-
* @param outputIndex non-negative integer
|
|
805
|
-
* @returns {Promise<boolean>} true iff the UTxO exists and is unspent
|
|
806
|
-
*/
|
|
709
|
+
/** Whether a UTxO exists and is unspent, via Koios `POST /utxo_info`. */
|
|
807
710
|
async isUtxoUnspent(txHash, outputIndex) {
|
|
808
711
|
if (!Number.isInteger(outputIndex) || outputIndex < 0)
|
|
809
712
|
return false;
|
|
@@ -821,12 +724,7 @@ class KoiosBackend {
|
|
|
821
724
|
//-----------------------------------------------------------------------------
|
|
822
725
|
// Batch Methods (N+1 Optimization)
|
|
823
726
|
//-----------------------------------------------------------------------------
|
|
824
|
-
/**
|
|
825
|
-
* Get transaction hashes for an address (lightweight — no full tx details).
|
|
826
|
-
* @param address bech32 address
|
|
827
|
-
* @param limit maximum number of hashes
|
|
828
|
-
* @returns {Promise<string[]>} most recent tx hashes
|
|
829
|
-
*/
|
|
727
|
+
/** Most recent tx hashes of an address, without tx details. */
|
|
830
728
|
async getAddressTransactionHashes(address, limit) {
|
|
831
729
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
832
730
|
const { data } = await this.api.post('/address_txs', { _addresses: [address] });
|
|
@@ -873,7 +771,7 @@ class KoiosBackend {
|
|
|
873
771
|
}, this.name);
|
|
874
772
|
}
|
|
875
773
|
// ---------------------------------------------------------------------------
|
|
876
|
-
// PaginatingBackend
|
|
774
|
+
// PaginatingBackend: forward iteration for the chain crawler
|
|
877
775
|
// ---------------------------------------------------------------------------
|
|
878
776
|
/** Map a Koios /block_info row to BlockData. */
|
|
879
777
|
mapKoiosBlockInfo(data) {
|
|
@@ -890,10 +788,7 @@ class KoiosBackend {
|
|
|
890
788
|
fees: data.total_fees,
|
|
891
789
|
};
|
|
892
790
|
}
|
|
893
|
-
/**
|
|
894
|
-
* Get a block by its height via the PostgREST-filtered /blocks list, then resolve
|
|
895
|
-
* full data through /block_info.
|
|
896
|
-
*/
|
|
791
|
+
/** Finds the block in the filtered /blocks list, then reads it from /block_info. */
|
|
897
792
|
async getBlockByHeight(height) {
|
|
898
793
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
899
794
|
const rows = await this.fetchWithRetryOnEmpty(() => this.api.get(`/blocks?block_height=eq.${height}&limit=1`), `getBlockByHeight(${height})`);
|
|
@@ -902,11 +797,8 @@ class KoiosBackend {
|
|
|
902
797
|
return await this.getBlock(rows[0].hash);
|
|
903
798
|
}, this.name);
|
|
904
799
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
* list blocks above the anchor height (PostgREST gt + order + limit), then batch /block_info.
|
|
908
|
-
* A known `afterHeight` skips the hash→height round-trip.
|
|
909
|
-
*/
|
|
800
|
+
// Koios has no "blocks after hash" endpoint. This lists blocks above the start height
|
|
801
|
+
// and reads them in one /block_info batch. A known `afterHeight` saves the height lookup.
|
|
910
802
|
async getNextBlocks(afterHash, count, afterHeight) {
|
|
911
803
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
912
804
|
let anchorHeight = afterHeight;
|
|
@@ -951,18 +843,15 @@ class KoiosBackend {
|
|
|
951
843
|
}, this.name);
|
|
952
844
|
}
|
|
953
845
|
// ---------------------------------------------------------------------------
|
|
954
|
-
// EnumeratingBackend
|
|
846
|
+
// EnumeratingBackend: all pools and DReps for the crawler's epoch snapshots
|
|
955
847
|
// ---------------------------------------------------------------------------
|
|
956
848
|
/** Rows per page when listing ids (PostgREST caps a response at 1000 rows). */
|
|
957
849
|
static LIST_PAGE_SIZE = 1000;
|
|
958
850
|
/** Ids resolved per /pool_info / /drep_info request. */
|
|
959
851
|
static INFO_BATCH_SIZE = 50;
|
|
960
|
-
/** Page cap
|
|
852
|
+
/** Page cap. 500 pages hold 500 000 ids, far beyond any real pool or DRep set. */
|
|
961
853
|
static LIST_MAX_PAGES = 500;
|
|
962
|
-
/**
|
|
963
|
-
* Page through a PostgREST list endpoint and collect one id column. Stops on the first
|
|
964
|
-
* short page, so a complete set costs exactly ceil(n / 1000) + 1 requests.
|
|
965
|
-
*/
|
|
854
|
+
/** Pages through a PostgREST list endpoint for one id column. Stops on the first short page. */
|
|
966
855
|
async listAllIds(path, column, label) {
|
|
967
856
|
const ids = [];
|
|
968
857
|
for (let page = 0; page < KoiosBackend.LIST_MAX_PAGES; page++) {
|
|
@@ -978,20 +867,14 @@ class KoiosBackend {
|
|
|
978
867
|
if (data.length < KoiosBackend.LIST_PAGE_SIZE)
|
|
979
868
|
return ids;
|
|
980
869
|
}
|
|
981
|
-
logger.warn(`${label}: stopped after ${KoiosBackend.LIST_MAX_PAGES} pages
|
|
870
|
+
logger.warn(`${label}: stopped after ${KoiosBackend.LIST_MAX_PAGES} pages, the list may be truncated`);
|
|
982
871
|
return ids;
|
|
983
872
|
}
|
|
984
|
-
/**
|
|
985
|
-
* All stake-pool ids known to Koios (bech32), including retired ones — a snapshot that
|
|
986
|
-
* silently dropped retiring pools would misreport the epoch's pool set.
|
|
987
|
-
*/
|
|
873
|
+
/** All pool ids, including retired ones, so a snapshot does not drop retiring pools. */
|
|
988
874
|
async getPoolIds() {
|
|
989
875
|
return (0, backend_request_handler_1.handleBackendRequest)(() => this.listAllIds('/pool_list', 'pool_id_bech32', 'getPoolIds'), this.name);
|
|
990
876
|
}
|
|
991
|
-
/**
|
|
992
|
-
* Resolve pool ids in batches. Ids Koios does not return are omitted rather than
|
|
993
|
-
* substituted with empty rows — a missing pool is better than an invented one.
|
|
994
|
-
*/
|
|
877
|
+
/** Resolve pool ids in batches. Ids Koios does not return are omitted, never filled with empty rows. */
|
|
995
878
|
async getPools(poolIds) {
|
|
996
879
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
997
880
|
const out = [];
|
|
@@ -1025,10 +908,7 @@ class KoiosBackend {
|
|
|
1025
908
|
return out;
|
|
1026
909
|
}, this.name);
|
|
1027
910
|
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Full transaction list of a block in block order via /block_txs → /tx_info batch.
|
|
1030
|
-
* Accepts both the flattened ({tx_hash} per row) and the {tx_hashes:[...]} shape.
|
|
1031
|
-
*/
|
|
911
|
+
/** All transactions of a block in order. /block_txs may answer flat rows or one `tx_hashes` array. */
|
|
1032
912
|
async getBlockTransactions(blockHash) {
|
|
1033
913
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
1034
914
|
const rows = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_txs', { _block_hashes: [blockHash] }), `getBlockTransactions(${blockHash})`);
|
|
@@ -1044,8 +924,8 @@ class KoiosBackend {
|
|
|
1044
924
|
const byHash = await this.getTransactionsBatch(hashes);
|
|
1045
925
|
const missing = hashes.filter(h => !byHash.has(h));
|
|
1046
926
|
if (missing.length > 0) {
|
|
1047
|
-
// A partial /tx_info would
|
|
1048
|
-
// crawler
|
|
927
|
+
// A partial /tx_info would lose the missing transactions for good.
|
|
928
|
+
// A 503 makes the crawler retry the whole block without storing it.
|
|
1049
929
|
throw new errors_1.ProviderUnavailableError(`Incomplete transaction data for block ${blockHash}: ${missing.length}/${hashes.length} transaction(s) missing`, this.name);
|
|
1050
930
|
}
|
|
1051
931
|
return hashes.map(h => byHash.get(h));
|
|
@@ -1074,8 +954,8 @@ class KoiosBackend {
|
|
|
1074
954
|
index: tx.tx_block_index ?? 0,
|
|
1075
955
|
fee: tx.fee || '0',
|
|
1076
956
|
deposit: tx.deposit || '0',
|
|
1077
|
-
// undefined
|
|
1078
|
-
//
|
|
957
|
+
// undefined when Koios omits the field, so the indexer uses the input and output delta.
|
|
958
|
+
// [] would wrongly mean "no mint".
|
|
1079
959
|
mint: Array.isArray(tx.assets_minted)
|
|
1080
960
|
? tx.assets_minted
|
|
1081
961
|
.filter((a) => a?.policy_id && a.quantity != null)
|
|
@@ -1100,8 +980,8 @@ class KoiosBackend {
|
|
|
1100
980
|
...asKoiosList(tx.collateral_output).map((output) => mapKoiosOutput(tx.tx_hash, output, true)),
|
|
1101
981
|
],
|
|
1102
982
|
metadata: labels,
|
|
1103
|
-
// undefined
|
|
1104
|
-
//
|
|
983
|
+
// undefined when the call did not ask for them. The indexer tells "none" from
|
|
984
|
+
// "not reported" by this.
|
|
1105
985
|
certificates: Array.isArray(tx.certificates) ? mapKoiosCertificates(tx.certificates) : undefined,
|
|
1106
986
|
withdrawals: Array.isArray(tx.withdrawals)
|
|
1107
987
|
? tx.withdrawals
|
|
@@ -1112,10 +992,8 @@ class KoiosBackend {
|
|
|
1112
992
|
}
|
|
1113
993
|
}
|
|
1114
994
|
exports.KoiosBackend = KoiosBackend;
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
* array) and `asset_list` on it as the JSON STRING "[]". Normalize both before mapping.
|
|
1118
|
-
*/
|
|
995
|
+
// Koios sends `collateral_output` as one object although the spec says array.
|
|
996
|
+
// Its `asset_list` may be the JSON string "[]". This turns both into arrays.
|
|
1119
997
|
function asKoiosList(v) {
|
|
1120
998
|
if (Array.isArray(v))
|
|
1121
999
|
return v;
|
|
@@ -1186,10 +1064,8 @@ const KOIOS_CERT_KINDS = {
|
|
|
1186
1064
|
pot_transfer: 'pot_transfer',
|
|
1187
1065
|
param_proposal: 'param_proposal',
|
|
1188
1066
|
};
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
* per type (`retiring_epoch` is spelled `retiring epoch` in current Koios), so every alias is read.
|
|
1192
|
-
*/
|
|
1067
|
+
// Normalize Koios `/tx_info` certificates. Field names inside `info` vary by type and
|
|
1068
|
+
// version, for example `retiring epoch` with a space, so every alias is read.
|
|
1193
1069
|
function mapKoiosCertificates(certs) {
|
|
1194
1070
|
const str = (v) => (typeof v === 'string' && v.length ? v : null);
|
|
1195
1071
|
const num = (v) => {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { CardanoBackend, EvaluatingBackend, PaginatingBackend, EnumeratingBackend } from './cardano-backend';
|
|
2
2
|
import type { Transaction, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, BlockData, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
|
-
/** Public ODATANO API per network
|
|
4
|
+
/** Public ODATANO API per network; mainnet has no default and needs `odatanoUrl`. */
|
|
5
5
|
export declare const ODATANO_API_URLS: Partial<Record<Network, string>>;
|
|
6
|
-
/**
|
|
7
|
-
* Backend over another ODATANO instance (typically the hosted API behind the ACCESS gateway),
|
|
8
|
-
* speaking its `CardanoBackendService`. Answers arrive in the provider shape, so everything above
|
|
9
|
-
* this class treats it like Koios. The key goes as `Authorization: Bearer`.
|
|
10
|
-
*/
|
|
11
6
|
export declare class OdatanoBackend implements CardanoBackend, EvaluatingBackend, PaginatingBackend, EnumeratingBackend {
|
|
12
7
|
readonly name = "odatano";
|
|
13
8
|
private readonly api;
|
|
@@ -53,11 +48,6 @@ export declare class OdatanoBackend implements CardanoBackend, EvaluatingBackend
|
|
|
53
48
|
getDreps(drepIds: string[]): Promise<DrepData[]>;
|
|
54
49
|
shutdown(): Promise<void>;
|
|
55
50
|
private batched;
|
|
56
|
-
/**
|
|
57
|
-
* POST one operation, parse the JSON string it answers (safeJSON keeps big integers) and map
|
|
58
|
-
* HTTP failures to the backend error classes. The remote message is kept verbatim, so markers
|
|
59
|
-
* such as `CHAIN_POINT_MISMATCH:` reach the crawler unchanged.
|
|
60
|
-
*/
|
|
61
51
|
private call;
|
|
62
52
|
private mapError;
|
|
63
53
|
}
|
|
@@ -10,7 +10,7 @@ const client_1 = require("@cardano-ogmios/client");
|
|
|
10
10
|
const errors_1 = require("../../utils/errors");
|
|
11
11
|
const error_codes_1 = require("../../utils/error-codes");
|
|
12
12
|
const logger = cds_1.default.log('OdatanoBackend');
|
|
13
|
-
/** Public ODATANO API per network
|
|
13
|
+
/** Public ODATANO API per network; mainnet has no default and needs `odatanoUrl`. */
|
|
14
14
|
exports.ODATANO_API_URLS = {
|
|
15
15
|
preview: 'https://api.preview.odatano.dev',
|
|
16
16
|
preprod: 'https://api.preprod.odatano.dev',
|
|
@@ -18,11 +18,8 @@ exports.ODATANO_API_URLS = {
|
|
|
18
18
|
const SERVICE_PATH = '/odata/v4/cardano-backend';
|
|
19
19
|
/** Ids per GetPools / GetDreps call, below the service's list cap. */
|
|
20
20
|
const ENUMERATION_BATCH = 200;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* speaking its `CardanoBackendService`. Answers arrive in the provider shape, so everything above
|
|
24
|
-
* this class treats it like Koios. The key goes as `Authorization: Bearer`.
|
|
25
|
-
*/
|
|
21
|
+
// Backend over another ODATANO instance via its `CardanoBackendService`.
|
|
22
|
+
// Answers arrive in the provider shape, so callers treat it like Koios.
|
|
26
23
|
class OdatanoBackend {
|
|
27
24
|
name = 'odatano';
|
|
28
25
|
api;
|
|
@@ -120,11 +117,8 @@ class OdatanoBackend {
|
|
|
120
117
|
}
|
|
121
118
|
return out;
|
|
122
119
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
* HTTP failures to the backend error classes. The remote message is kept verbatim, so markers
|
|
126
|
-
* such as `CHAIN_POINT_MISMATCH:` reach the crawler unchanged.
|
|
127
|
-
*/
|
|
120
|
+
// POSTs one operation and parses the JSON answer with safeJSON to keep big integers.
|
|
121
|
+
// The remote error message stays verbatim, so `CHAIN_POINT_MISMATCH:` reaches the crawler.
|
|
128
122
|
async call(operation, body = {}) {
|
|
129
123
|
try {
|
|
130
124
|
const res = await this.api.post(`/${operation}`, body);
|
|
@@ -144,6 +138,8 @@ class OdatanoBackend {
|
|
|
144
138
|
return err instanceof Error ? err : new Error(String(err));
|
|
145
139
|
const status = ax.response?.status;
|
|
146
140
|
const message = ax.response?.data?.error?.message ?? ax.message;
|
|
141
|
+
// older instances carry the code only as a `[CODE]` prefix of the message
|
|
142
|
+
const code = ax.response?.data?.error?.code ?? message;
|
|
147
143
|
// the remote prefixes `[CODE] Operation: `; the crawler recognises the reorg marker at the start
|
|
148
144
|
const marker = message.indexOf('CHAIN_POINT_MISMATCH:');
|
|
149
145
|
if (marker >= 0)
|
|
@@ -155,8 +151,11 @@ class OdatanoBackend {
|
|
|
155
151
|
const retryAfter = Number(ax.response?.headers?.['retry-after']);
|
|
156
152
|
return new errors_1.RateLimitError(message, this.name, Number.isFinite(retryAfter) ? retryAfter : undefined);
|
|
157
153
|
}
|
|
154
|
+
if (status === 409 && code.includes(error_codes_1.ERROR_CODES.TX_ALREADY_SUBMITTED)) {
|
|
155
|
+
return new errors_1.TransactionAlreadySubmittedError(/[0-9a-f]{64}/.exec(message)?.[0] ?? '', message);
|
|
156
|
+
}
|
|
158
157
|
if (status === 400) {
|
|
159
|
-
return
|
|
158
|
+
return code.includes(error_codes_1.ERROR_CODES.SCRIPT_VALIDATION_FAILURE)
|
|
160
159
|
? new errors_1.ScriptValidationError(message)
|
|
161
160
|
: new errors_1.TransactionValidationError(message);
|
|
162
161
|
}
|