@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
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 +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- 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 +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- 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 +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
|
@@ -4,42 +4,43 @@ exports.BlockfrostBackend = void 0;
|
|
|
4
4
|
const blockfrost_js_1 = require("@blockfrost/blockfrost-js");
|
|
5
5
|
const backend_request_handler_1 = require("../../utils/backend-request-handler");
|
|
6
6
|
const errors_1 = require("../../utils/errors");
|
|
7
|
+
const collections_1 = require("../../utils/collections");
|
|
8
|
+
const call_signal_1 = require("./call-signal");
|
|
7
9
|
const mappers_1 = require("../../utils/mappers");
|
|
10
|
+
const pool_metadata_1 = require("../pool-metadata");
|
|
8
11
|
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
// The client fails over to the next backend itself, so the SDK does not retry. A retry would run
|
|
13
|
+
// past the client's timeout and repeat a request the client has given up.
|
|
14
|
+
const NO_RETRY = {
|
|
15
|
+
limit: 0,
|
|
16
|
+
methods: [],
|
|
17
|
+
statusCodes: [],
|
|
18
|
+
errorCodes: [],
|
|
19
|
+
calculateDelay: () => 0,
|
|
20
|
+
};
|
|
21
|
+
/** CardanoBackend + PaginatingBackend implementation on the Blockfrost API SDK. */
|
|
13
22
|
class BlockfrostBackend {
|
|
14
23
|
name = 'blockfrost';
|
|
15
24
|
api;
|
|
16
25
|
network;
|
|
17
|
-
timeoutMs;
|
|
18
|
-
/**
|
|
19
|
-
* Constructor
|
|
20
|
-
*/
|
|
21
26
|
constructor(network, timeoutMs, projectId, customBackend) {
|
|
22
27
|
if (!projectId && !customBackend) {
|
|
23
28
|
throw new errors_1.BackendInitError('blockfrost', new Error('Either projectId (BLOCKFROST_API_KEY) or customBackend (BLOCKFROST_CUSTOM_BACKEND) is required'));
|
|
24
29
|
}
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// SDK validator accepts customBackend OR projectId — this substitution is purely
|
|
28
|
-
// for the runtime HTTP header.
|
|
30
|
+
// Self-hosted Blockfrost-compatible servers reject an empty project_id header,
|
|
31
|
+
// even without authentication, so a placeholder is sent.
|
|
29
32
|
const effectiveProjectId = projectId || 'self-hosted';
|
|
33
|
+
// the SDK builds its HTTP client in the constructor, so timeout and retries are set here
|
|
30
34
|
this.api = new blockfrost_js_1.BlockFrostAPI({
|
|
31
35
|
projectId: effectiveProjectId,
|
|
32
36
|
network,
|
|
37
|
+
requestTimeout: timeoutMs,
|
|
38
|
+
retrySettings: NO_RETRY,
|
|
33
39
|
...(customBackend ? { customBackend } : {}),
|
|
34
40
|
});
|
|
35
41
|
this.network = network;
|
|
36
|
-
this.timeoutMs = timeoutMs;
|
|
37
42
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Initialize the backend
|
|
40
|
-
*/
|
|
41
43
|
async init() {
|
|
42
|
-
this.api.options.requestTimeout = this.timeoutMs;
|
|
43
44
|
// Test connection by fetching latest block
|
|
44
45
|
try {
|
|
45
46
|
await this.api.blocksLatest();
|
|
@@ -49,10 +50,7 @@ class BlockfrostBackend {
|
|
|
49
50
|
}
|
|
50
51
|
return true;
|
|
51
52
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Get Network Information
|
|
54
|
-
* @returns {Promise<NetworkInformation>} network information
|
|
55
|
-
*/
|
|
53
|
+
/** Network information (supply, stake). */
|
|
56
54
|
async getNetworkInformation() {
|
|
57
55
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
58
56
|
const networkInfo = await this.api.network();
|
|
@@ -62,19 +60,11 @@ class BlockfrostBackend {
|
|
|
62
60
|
};
|
|
63
61
|
}, this.name);
|
|
64
62
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Get Block Data
|
|
67
|
-
* @param blockHash block hash (hex)
|
|
68
|
-
* @returns {Promise<BlockData>} block data
|
|
69
|
-
*/
|
|
63
|
+
/** Block by hash (hex). */
|
|
70
64
|
async getBlock(blockHash) {
|
|
71
65
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => this.toBlockData(await this.api.blocks(blockHash)), this.name);
|
|
72
66
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Get Epoch Data
|
|
75
|
-
* @param epochNumber epoch number
|
|
76
|
-
* @returns {Promise<EpochData>} epoch data
|
|
77
|
-
*/
|
|
67
|
+
/** Epoch by number. */
|
|
78
68
|
async getEpoch(epochNumber) {
|
|
79
69
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
80
70
|
const epochData = await this.api.epochs(epochNumber);
|
|
@@ -92,14 +82,10 @@ class BlockfrostBackend {
|
|
|
92
82
|
};
|
|
93
83
|
}, this.name);
|
|
94
84
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Get Transaction Data
|
|
97
|
-
* @param hash transaction hash (hex)
|
|
98
|
-
* @returns {Promise<Transaction>} transaction data
|
|
99
|
-
*/
|
|
85
|
+
/** Transaction by hash (hex), with UTxOs and metadata. */
|
|
100
86
|
async getTransaction(hash) {
|
|
101
87
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
102
|
-
// independent endpoints
|
|
88
|
+
// independent endpoints, fetched in parallel
|
|
103
89
|
const [tx, txUtxos, txMetadata] = await Promise.all([
|
|
104
90
|
this.api.txs(hash),
|
|
105
91
|
this.api.txsUtxos(hash),
|
|
@@ -110,7 +96,8 @@ class BlockfrostBackend {
|
|
|
110
96
|
label: md.label,
|
|
111
97
|
json: md.json_metadata,
|
|
112
98
|
})) : undefined;
|
|
113
|
-
|
|
99
|
+
// ledger view: inputs in ledger order, only what the ledger applied (see ledgerView)
|
|
100
|
+
return (0, mappers_1.ledgerView)({
|
|
114
101
|
hash: tx.hash,
|
|
115
102
|
blockHash: tx.block,
|
|
116
103
|
blockHeight: tx.block_height,
|
|
@@ -120,6 +107,10 @@ class BlockfrostBackend {
|
|
|
120
107
|
fee: tx.fees,
|
|
121
108
|
deposit: tx.deposit,
|
|
122
109
|
size: tx.size,
|
|
110
|
+
// `spends === 'collaterals'` in Ogmios terms: the script phase failed, so the
|
|
111
|
+
// ledger applied neither the declared inputs/outputs nor the declared mint.
|
|
112
|
+
spendsCollaterals: tx.valid_contract === false,
|
|
113
|
+
// one mixed list in Blockfrost's order; ledgerView groups and sorts it
|
|
123
114
|
inputs: txUtxos.inputs.map(input => ({
|
|
124
115
|
address: input.address,
|
|
125
116
|
txHash: input.tx_hash,
|
|
@@ -128,8 +119,8 @@ class BlockfrostBackend {
|
|
|
128
119
|
dataHash: input.data_hash,
|
|
129
120
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(input.inline_datum),
|
|
130
121
|
referenceScriptHash: input.reference_script_hash,
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
isCollateral: input.collateral === true,
|
|
123
|
+
isReference: input.reference === true,
|
|
133
124
|
})),
|
|
134
125
|
outputs: txUtxos.outputs.map(output => ({
|
|
135
126
|
address: output.address,
|
|
@@ -142,14 +133,10 @@ class BlockfrostBackend {
|
|
|
142
133
|
referenceScriptHash: output.reference_script_hash,
|
|
143
134
|
})),
|
|
144
135
|
metadata: metadata,
|
|
145
|
-
};
|
|
136
|
+
});
|
|
146
137
|
}, this.name);
|
|
147
138
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Get Transaction Metadata
|
|
150
|
-
* @param tx_hash transaction hash (hex)
|
|
151
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata list
|
|
152
|
-
*/
|
|
139
|
+
/** Metadata labels of a transaction (hash hex); NotFoundError when it has none. */
|
|
153
140
|
async getTransactionMetadata(tx_hash) {
|
|
154
141
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
155
142
|
const txMetadata = await this.api.txsMetadata(tx_hash);
|
|
@@ -163,21 +150,17 @@ class BlockfrostBackend {
|
|
|
163
150
|
}));
|
|
164
151
|
}, this.name);
|
|
165
152
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Get Address Data (without transactions - use getAddressTransactions() separately)
|
|
168
|
-
* @param address bech32 address string
|
|
169
|
-
* @returns {Promise<Address>} address data
|
|
170
|
-
*/
|
|
153
|
+
/** Address data with UTxOs. Transactions come from getAddressTransactions(). */
|
|
171
154
|
async getAddress(address) {
|
|
172
155
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
173
156
|
const address_data = await this.api.addresses(address);
|
|
174
|
-
// *All variant
|
|
175
|
-
// silently truncating larger wallets (wrong balances / spurious InsufficientFunds)
|
|
157
|
+
// plain addressesUtxos silently stops at 100 entries; the *All variant pages through all of them
|
|
176
158
|
const address_utxos = await this.api.addressesUtxosAll(address);
|
|
177
159
|
return {
|
|
178
160
|
address: address_data.address,
|
|
179
161
|
stakeAddress: address_data.stake_address,
|
|
180
|
-
|
|
162
|
+
// Blockfrost says shelley | byron; the other sources and the model use the CIP-19 kind
|
|
163
|
+
type: (0, mappers_1.decodeShelleyAddress)(address_data.address).type,
|
|
181
164
|
isScript: address_data.script,
|
|
182
165
|
amount: address_data.amount,
|
|
183
166
|
utxos: address_utxos.map(utxo => ({
|
|
@@ -193,14 +176,10 @@ class BlockfrostBackend {
|
|
|
193
176
|
};
|
|
194
177
|
}, this.name);
|
|
195
178
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Get Address Transactions
|
|
198
|
-
* @param address bech32 address string
|
|
199
|
-
* @returns {Promise<Transaction[]>} list of transactions for this address
|
|
200
|
-
*/
|
|
179
|
+
/** Transactions of an address, most recent first, with full details (batched). */
|
|
201
180
|
async getAddressTransactions(address, limit) {
|
|
202
181
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
203
|
-
// Blockfrost rejects count > 100 with a 400
|
|
182
|
+
// Blockfrost rejects count > 100 with a 400
|
|
204
183
|
const count = limit === undefined ? undefined : Math.min(Math.max(limit, 1), 100);
|
|
205
184
|
const address_txs = await this.api.addressesTransactions(address, { order: 'desc', count });
|
|
206
185
|
const txHashes = address_txs.map(tx => tx.tx_hash);
|
|
@@ -216,11 +195,7 @@ class BlockfrostBackend {
|
|
|
216
195
|
return transactions;
|
|
217
196
|
}, this.name);
|
|
218
197
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Get Address UTxOs
|
|
221
|
-
* @param address bech32 address string
|
|
222
|
-
* @returns {Promise<UTxO[]>} list of UTxOs
|
|
223
|
-
*/
|
|
198
|
+
/** UTxOs of an address. */
|
|
224
199
|
async getAddressUtxos(address) {
|
|
225
200
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
226
201
|
// *All variant paginates internally (plain addressesUtxos caps at 100 entries)
|
|
@@ -237,14 +212,11 @@ class BlockfrostBackend {
|
|
|
237
212
|
}));
|
|
238
213
|
}, this.name);
|
|
239
214
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Get Pool Data
|
|
242
|
-
* @param poolId stake pool id (hex)
|
|
243
|
-
* @return {Promise<PoolData>} pool data
|
|
244
|
-
*/
|
|
215
|
+
/** Stake pool by id. */
|
|
245
216
|
async getPool(poolId) {
|
|
246
217
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
247
|
-
const poolData = await this.api.poolsById(poolId);
|
|
218
|
+
const [poolData, registered] = await Promise.all([this.api.poolsById(poolId), this.api.poolMetadata(poolId)]);
|
|
219
|
+
const metadata = (0, pool_metadata_1.validPoolMetadata)(registered);
|
|
248
220
|
return {
|
|
249
221
|
poolId: poolData.pool_id,
|
|
250
222
|
vrfKeyHash: poolData.vrf_key,
|
|
@@ -253,37 +225,30 @@ class BlockfrostBackend {
|
|
|
253
225
|
liveStake: poolData.live_stake || '0',
|
|
254
226
|
liveSize: poolData.live_size,
|
|
255
227
|
liveDelegators: poolData.live_delegators,
|
|
228
|
+
// Blockfrost reports saturation as a fraction (0.7542 = 75.42 %), the canonical unit
|
|
256
229
|
liveSaturation: poolData.live_saturation,
|
|
257
230
|
activeStake: poolData.active_stake || '0',
|
|
258
231
|
activeSize: poolData.active_size,
|
|
259
|
-
pledge
|
|
232
|
+
// the pledge of the certificate, as Koios and Ogmios report it; live_pledge is the owners' stake
|
|
233
|
+
pledge: poolData.declared_pledge || '0',
|
|
260
234
|
margin: poolData.margin_cost,
|
|
261
235
|
fixedCost: poolData.fixed_cost || '0',
|
|
262
236
|
rewardAccount: poolData.reward_account,
|
|
237
|
+
metadataUrl: registered.url ?? null,
|
|
238
|
+
metadataHash: registered.hash ?? null,
|
|
239
|
+
name: metadata?.name ?? null,
|
|
240
|
+
ticker: metadata?.ticker ?? null,
|
|
241
|
+
homepage: metadata?.homepage ?? null,
|
|
242
|
+
description: metadata?.description ?? null,
|
|
263
243
|
};
|
|
264
244
|
}, this.name);
|
|
265
245
|
}
|
|
266
|
-
/**
|
|
267
|
-
* Get Asset Info (supply, mint history, CIP-25 + CIP-26 metadata).
|
|
268
|
-
* Blockfrost does NOT expose initial-mint timestamp in this endpoint —
|
|
269
|
-
* `initialMintTime` is left null. Filling it would cost an extra tx fetch.
|
|
270
|
-
* @param unit policyId + assetNameHex (concatenated hex)
|
|
271
|
-
* @return {Promise<AssetInfo>} canonical asset info
|
|
272
|
-
*/
|
|
246
|
+
/** Asset info. Blockfrost has no initial-mint timestamp here, so `initialMintTime` stays null. */
|
|
273
247
|
async getAssetInfo(unit) {
|
|
274
248
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
275
249
|
const a = await this.api.assetsById(unit);
|
|
276
250
|
const reg = a.metadata ?? null;
|
|
277
|
-
const decodeUtf8 = (hex) =>
|
|
278
|
-
if (!hex)
|
|
279
|
-
return null;
|
|
280
|
-
try {
|
|
281
|
-
return Buffer.from(hex, 'hex').toString('utf8');
|
|
282
|
-
}
|
|
283
|
-
catch {
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
};
|
|
251
|
+
const decodeUtf8 = (hex) => (hex ? (0, mappers_1.decodeAssetName)(hex) : null);
|
|
287
252
|
return {
|
|
288
253
|
unit: a.asset,
|
|
289
254
|
policyId: a.policy_id,
|
|
@@ -304,39 +269,23 @@ class BlockfrostBackend {
|
|
|
304
269
|
};
|
|
305
270
|
}, this.name);
|
|
306
271
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
* Blockfrost's `assetsHistory` returns tx_hash + action + amount only; we
|
|
310
|
-
* backfill `blockTime` and `blockHeight` via concurrent `api.txs(...)` calls.
|
|
311
|
-
* Cost: 1 extra API call per history entry. Failed tx fetches leave the
|
|
312
|
-
* timestamp fields null instead of failing the whole call (best-effort).
|
|
313
|
-
* @param unit policyId + assetNameHex (concatenated hex)
|
|
314
|
-
* @param limit max number of events (default 100, max 100 per Blockfrost page)
|
|
315
|
-
* @return {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
|
|
316
|
-
*/
|
|
272
|
+
// Mint and burn events, newest first, at most 100 per page. `assetsHistory` has no block data,
|
|
273
|
+
// so one `txs()` call per entry fills blockTime and blockHeight. A failed call leaves them null.
|
|
317
274
|
async getAssetHistory(unit, limit = 100) {
|
|
318
275
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
319
276
|
const count = Math.min(Math.max(1, limit), 100);
|
|
320
277
|
const data = await this.api.assetsHistory(unit, { order: 'desc', count });
|
|
321
|
-
// Backfill block metadata via concurrent tx fetches
|
|
322
|
-
const concurrent = BlockfrostBackend.MAX_CONCURRENT;
|
|
323
278
|
const blockMetaByTx = new Map();
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
blockTime: typeof r.value.block_time === 'number' ? r.value.block_time : null,
|
|
332
|
-
blockHeight: typeof r.value.block_height === 'number' ? r.value.block_height : null,
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
blockMetaByTx.set(entry.tx_hash, { blockTime: null, blockHeight: null });
|
|
279
|
+
const results = await (0, collections_1.settleInBatches)(data, BlockfrostBackend.MAX_CONCURRENT, entry => this.api.txs(entry.tx_hash), (0, call_signal_1.callSignal)());
|
|
280
|
+
data.forEach((entry, idx) => {
|
|
281
|
+
const r = results[idx];
|
|
282
|
+
blockMetaByTx.set(entry.tx_hash, r.status === 'fulfilled'
|
|
283
|
+
? {
|
|
284
|
+
blockTime: typeof r.value.block_time === 'number' ? r.value.block_time : null,
|
|
285
|
+
blockHeight: typeof r.value.block_height === 'number' ? r.value.block_height : null,
|
|
337
286
|
}
|
|
338
|
-
|
|
339
|
-
}
|
|
287
|
+
: { blockTime: null, blockHeight: null });
|
|
288
|
+
});
|
|
340
289
|
return data.map(entry => {
|
|
341
290
|
const meta = blockMetaByTx.get(entry.tx_hash) ?? { blockTime: null, blockHeight: null };
|
|
342
291
|
return {
|
|
@@ -350,11 +299,7 @@ class BlockfrostBackend {
|
|
|
350
299
|
});
|
|
351
300
|
}, this.name);
|
|
352
301
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Get Drep Data
|
|
355
|
-
* @param drepId drep id (bech32)
|
|
356
|
-
* @return {Promise<DrepData>} drep data
|
|
357
|
-
*/
|
|
302
|
+
/** DRep by id (bech32). */
|
|
358
303
|
async getDrep(drepId) {
|
|
359
304
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
360
305
|
const drepData = await this.api.governance.drepsById(drepId);
|
|
@@ -369,26 +314,16 @@ class BlockfrostBackend {
|
|
|
369
314
|
};
|
|
370
315
|
}, this.name);
|
|
371
316
|
}
|
|
372
|
-
/**
|
|
373
|
-
* Get Account Data
|
|
374
|
-
* @param stakeAddress bech32 stake address
|
|
375
|
-
* @return {Promise<AccountData>} account data
|
|
376
|
-
*/
|
|
317
|
+
/** Account by stake address (bech32) with the addresses under it, not their UTxOs. */
|
|
377
318
|
async getAccount(stakeAddress) {
|
|
378
319
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
379
320
|
const accountData = await this.api.accounts(stakeAddress);
|
|
380
321
|
// *All variant paginates internally (plain accountsAddresses caps at 100 entries)
|
|
381
|
-
const
|
|
382
|
-
const addresses = [];
|
|
383
|
-
const concurrent = BlockfrostBackend.MAX_CONCURRENT;
|
|
384
|
-
for (let i = 0; i < addressData.length; i += concurrent) {
|
|
385
|
-
const chunk = addressData.slice(i, i + concurrent);
|
|
386
|
-
const chunkResults = await Promise.all(chunk.map(a => this.getAddress(a.address)));
|
|
387
|
-
addresses.push(...chunkResults);
|
|
388
|
-
}
|
|
322
|
+
const addresses = (await this.api.accountsAddressesAll(stakeAddress)).map(a => a.address);
|
|
389
323
|
return {
|
|
390
324
|
stakeaddress: accountData.stake_address,
|
|
391
|
-
active
|
|
325
|
+
// `active` is the delegation state; registration lives in `registered`
|
|
326
|
+
active: accountData.registered,
|
|
392
327
|
activeEpoch: accountData.active_epoch ?? 0,
|
|
393
328
|
controlledAmount: accountData.controlled_amount,
|
|
394
329
|
rewardsSum: accountData.rewards_sum,
|
|
@@ -402,22 +337,24 @@ class BlockfrostBackend {
|
|
|
402
337
|
};
|
|
403
338
|
}, this.name);
|
|
404
339
|
}
|
|
405
|
-
/**
|
|
406
|
-
* Submit Transaction
|
|
407
|
-
* @param signedTxCbor hex-encoded signed transaction CBOR
|
|
408
|
-
* @returns {Promise<string>} transaction hash
|
|
409
|
-
*/
|
|
340
|
+
/** Submit a signed transaction (CBOR hex); returns the tx hash. */
|
|
410
341
|
async submitTransaction(signedTxCbor) {
|
|
411
342
|
const txBytes = Buffer.from(signedTxCbor, "hex");
|
|
412
343
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
413
|
-
|
|
414
|
-
|
|
344
|
+
try {
|
|
345
|
+
return await this.api.txSubmit(txBytes);
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
// a 400 carries the node's rejection; the submit API forwards it in the body
|
|
349
|
+
if ((0, errors_1.getErrorStatus)(err) === 400) {
|
|
350
|
+
const e = err;
|
|
351
|
+
throw (0, errors_1.submitRejection)((0, errors_1.nodeRejectionReason)(e.body ?? e.message ?? ''), this.name, err);
|
|
352
|
+
}
|
|
353
|
+
throw err;
|
|
354
|
+
}
|
|
415
355
|
}, this.name);
|
|
416
356
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Get Protocol Parameters
|
|
419
|
-
* @returns {Promise<LedgerProtocolParameters>} protocol parameters
|
|
420
|
-
*/
|
|
357
|
+
/** Protocol parameters of the latest epoch. */
|
|
421
358
|
async getProtocolParameters() {
|
|
422
359
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
423
360
|
const protocolParams = await this.api.epochsLatestParameters();
|
|
@@ -440,6 +377,7 @@ class BlockfrostBackend {
|
|
|
440
377
|
collateralPercent: protocolParams.collateral_percent,
|
|
441
378
|
maxCollateralInputs: protocolParams.max_collateral_inputs,
|
|
442
379
|
coinsPerUtxoSize: protocolParams.coins_per_utxo_size,
|
|
380
|
+
minFeeRefScriptCostPerByte: protocolParams.min_fee_ref_script_cost_per_byte ?? null,
|
|
443
381
|
maxBlockHeaderSize: protocolParams.max_block_header_size,
|
|
444
382
|
maxTxSize: protocolParams.max_tx_size,
|
|
445
383
|
keyDeposit: protocolParams.key_deposit,
|
|
@@ -459,10 +397,7 @@ class BlockfrostBackend {
|
|
|
459
397
|
};
|
|
460
398
|
}, this.name);
|
|
461
399
|
}
|
|
462
|
-
/**
|
|
463
|
-
* Get Latest Epoch Data
|
|
464
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
465
|
-
*/
|
|
400
|
+
/** Latest epoch. */
|
|
466
401
|
async getLatestEpoch() {
|
|
467
402
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
468
403
|
const epochData = await this.api.epochsLatest();
|
|
@@ -480,10 +415,7 @@ class BlockfrostBackend {
|
|
|
480
415
|
};
|
|
481
416
|
}, this.name);
|
|
482
417
|
}
|
|
483
|
-
/**
|
|
484
|
-
* Get Latest Block Data
|
|
485
|
-
* @returns {Promise<BlockData>} latest block data
|
|
486
|
-
*/
|
|
418
|
+
/** Latest block. */
|
|
487
419
|
async getLatestBlock() {
|
|
488
420
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
489
421
|
const blockdata = await this.api.blocksLatest();
|
|
@@ -501,10 +433,7 @@ class BlockfrostBackend {
|
|
|
501
433
|
};
|
|
502
434
|
}, this.name);
|
|
503
435
|
}
|
|
504
|
-
/**
|
|
505
|
-
* Get the latest chain tip slot.
|
|
506
|
-
* @returns {Promise<number>} current chain slot
|
|
507
|
-
*/
|
|
436
|
+
/** Latest chain tip slot; ProviderUnavailableError when the latest block has no slot. */
|
|
508
437
|
async getCurrentSlot() {
|
|
509
438
|
const block = await this.getLatestBlock();
|
|
510
439
|
if (block.slot == null) {
|
|
@@ -512,12 +441,7 @@ class BlockfrostBackend {
|
|
|
512
441
|
}
|
|
513
442
|
return block.slot;
|
|
514
443
|
}
|
|
515
|
-
/**
|
|
516
|
-
* Check whether a UTxO is still unspent via Blockfrost's `consumed_by_tx` field.
|
|
517
|
-
* @param txHash 64-char lowercase hex
|
|
518
|
-
* @param outputIndex non-negative integer
|
|
519
|
-
* @returns {Promise<boolean>} true iff the UTxO exists and is unspent
|
|
520
|
-
*/
|
|
444
|
+
/** Whether a UTxO is unspent, via Blockfrost's `consumed_by_tx`; false for unknown tx or out-of-range index. */
|
|
521
445
|
async isUtxoUnspent(txHash, outputIndex) {
|
|
522
446
|
if (!Number.isInteger(outputIndex) || outputIndex < 0)
|
|
523
447
|
return false;
|
|
@@ -525,14 +449,14 @@ class BlockfrostBackend {
|
|
|
525
449
|
return await (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
526
450
|
const utxos = await this.api.txsUtxos(txHash);
|
|
527
451
|
const out = utxos?.outputs?.find(o => o.output_index === outputIndex);
|
|
528
|
-
|
|
452
|
+
// consumed_by_tx is always null on a collateral output, so its state is unknown here
|
|
453
|
+
if (!out || out.collateral === true)
|
|
529
454
|
return false;
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
// router falls through to another backend rather than silently lying.
|
|
455
|
+
// Blockfrost servers before 0.1.59 omit consumed_by_tx. Without it unspent cannot be
|
|
456
|
+
// proven, so the router must fall through to another backend.
|
|
533
457
|
const consumed = out.consumed_by_tx;
|
|
534
458
|
if (consumed === undefined) {
|
|
535
|
-
throw new errors_1.ProviderUnavailableError(`${this.name}: server does not expose consumed_by_tx
|
|
459
|
+
throw new errors_1.ProviderUnavailableError(`${this.name}: server does not expose consumed_by_tx, cannot determine UTxO status`, this.name);
|
|
536
460
|
}
|
|
537
461
|
return consumed === null;
|
|
538
462
|
}, this.name);
|
|
@@ -548,47 +472,34 @@ class BlockfrostBackend {
|
|
|
548
472
|
//-----------------------------------------------------------------------------
|
|
549
473
|
/** Max concurrent Blockfrost API calls (free tier: ~10 req/s) */
|
|
550
474
|
static MAX_CONCURRENT = 10;
|
|
551
|
-
/**
|
|
552
|
-
* Get transaction hashes for an address (lightweight — no full tx details).
|
|
553
|
-
* @param address bech32 address
|
|
554
|
-
* @param limit maximum number of hashes
|
|
555
|
-
* @returns {Promise<string[]>} most recent tx hashes
|
|
556
|
-
*/
|
|
475
|
+
/** Most recent tx hashes of an address (no details). */
|
|
557
476
|
async getAddressTransactionHashes(address, limit) {
|
|
558
477
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
559
|
-
// Blockfrost rejects count > 100 with a 400
|
|
478
|
+
// Blockfrost rejects count > 100 with a 400
|
|
560
479
|
const count = Math.min(Math.max(limit, 1), 100);
|
|
561
480
|
const txs = await this.api.addressesTransactions(address, { order: 'desc', count });
|
|
562
481
|
return txs.map(tx => tx.tx_hash);
|
|
563
482
|
}, this.name);
|
|
564
483
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
* Blockfrost has no batch endpoint — uses concurrency-limited parallel calls.
|
|
568
|
-
* @param txHashes array of transaction hashes
|
|
569
|
-
* @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
|
|
570
|
-
*/
|
|
484
|
+
// Transactions by hash, at most MAX_CONCURRENT calls at once. A hash Blockfrost does not know is
|
|
485
|
+
// left out, as Koios does; any other failure fails the batch.
|
|
571
486
|
async getTransactionsBatch(txHashes) {
|
|
572
487
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
573
488
|
const result = new Map();
|
|
574
|
-
const
|
|
575
|
-
for (
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}
|
|
489
|
+
const settled = await (0, collections_1.settleInBatches)(txHashes, BlockfrostBackend.MAX_CONCURRENT, h => this.getTransaction(h), (0, call_signal_1.callSignal)());
|
|
490
|
+
for (const r of settled) {
|
|
491
|
+
if (r.status === 'fulfilled')
|
|
492
|
+
result.set(r.value.hash, r.value);
|
|
493
|
+
else if (!(r.reason instanceof errors_1.NotFoundError))
|
|
494
|
+
throw r.reason;
|
|
581
495
|
}
|
|
582
496
|
return result;
|
|
583
497
|
}, this.name);
|
|
584
498
|
}
|
|
585
499
|
// ---------------------------------------------------------------------------
|
|
586
|
-
// PaginatingBackend
|
|
500
|
+
// PaginatingBackend: forward iteration for the chain crawler
|
|
587
501
|
// ---------------------------------------------------------------------------
|
|
588
|
-
/**
|
|
589
|
-
* Map a Blockfrost block summary (from blocks()/blocksNext()) to our BlockData.
|
|
590
|
-
* Same shape getBlock() maps inline — kept private to avoid touching getBlock().
|
|
591
|
-
*/
|
|
502
|
+
/** Map a Blockfrost block summary (blocks()/blocksNext()) to BlockData. */
|
|
592
503
|
toBlockData(b) {
|
|
593
504
|
return {
|
|
594
505
|
time: b.time,
|
|
@@ -601,18 +512,14 @@ class BlockfrostBackend {
|
|
|
601
512
|
size: b.size,
|
|
602
513
|
txCount: b.tx_count,
|
|
603
514
|
fees: b.fees,
|
|
515
|
+
previousHash: b.previous_block,
|
|
604
516
|
};
|
|
605
517
|
}
|
|
606
|
-
/**
|
|
607
|
-
* Get a block by its height. Blockfrost's `blocks` endpoint accepts a height as
|
|
608
|
-
* well as a hash.
|
|
609
|
-
*/
|
|
518
|
+
/** Block by height; Blockfrost's `blocks` endpoint accepts a height as well as a hash. */
|
|
610
519
|
async getBlockByHeight(height) {
|
|
611
520
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => this.toBlockData(await this.api.blocks(height)), this.name);
|
|
612
521
|
}
|
|
613
|
-
/**
|
|
614
|
-
* Get up to `count` blocks immediately following `afterHash`, in ascending chain order.
|
|
615
|
-
*/
|
|
522
|
+
/** Up to `count` blocks immediately following `afterHash`, in ascending chain order. */
|
|
616
523
|
async getNextBlocks(afterHash, count) {
|
|
617
524
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
618
525
|
let blocks;
|
|
@@ -620,33 +527,36 @@ class BlockfrostBackend {
|
|
|
620
527
|
blocks = await this.api.blocksNext(afterHash, { count });
|
|
621
528
|
}
|
|
622
529
|
catch (err) {
|
|
623
|
-
// Blockfrost only knows canonical blocks
|
|
624
|
-
//
|
|
625
|
-
//
|
|
626
|
-
// NotFoundError would be treated as transient and the crawler would halt
|
|
627
|
-
// with an error streak instead of entering reorg recovery.
|
|
530
|
+
// Blockfrost only knows canonical blocks: a 404 on the anchor means the cursor block was
|
|
531
|
+
// orphaned by a reorg. Signal CHAIN_POINT_MISMATCH so the crawler enters reorg recovery;
|
|
532
|
+
// a plain NotFoundError would count as transient and halt it with an error streak.
|
|
628
533
|
const normalized = (0, errors_1.normalizeBackendError)(err, this.name);
|
|
629
534
|
if (normalized.statusCode === 404) {
|
|
630
|
-
throw new errors_1.ProviderUnavailableError(`CHAIN_POINT_MISMATCH: cursor block ${afterHash} is unknown to ${this.name}
|
|
535
|
+
throw new errors_1.ProviderUnavailableError(`CHAIN_POINT_MISMATCH: cursor block ${afterHash} is unknown to ${this.name}, likely orphaned by a reorg`, this.name);
|
|
631
536
|
}
|
|
632
537
|
throw err;
|
|
633
538
|
}
|
|
634
539
|
return blocks.map(b => this.toBlockData(b));
|
|
635
540
|
}, this.name);
|
|
636
541
|
}
|
|
637
|
-
/**
|
|
638
|
-
|
|
639
|
-
* hashes; details are batched via getTransactionsBatch. Order is preserved.
|
|
640
|
-
*/
|
|
641
|
-
async getBlockTransactions(blockHash) {
|
|
542
|
+
/** Full transaction list of a block in block order (hashes from blocksTxsAll, details batched). */
|
|
543
|
+
async getBlockTransactions(blockHash, txCount) {
|
|
642
544
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
545
|
+
if (txCount === 0)
|
|
546
|
+
return [];
|
|
643
547
|
const hashes = await this.api.blocksTxsAll(blockHash);
|
|
548
|
+
// A short list, or a transaction the batch did not find, would store the block incomplete.
|
|
549
|
+
if (txCount !== undefined && hashes.length !== txCount) {
|
|
550
|
+
throw new errors_1.ProviderUnavailableError(`Incomplete transaction list for block ${blockHash}: ${hashes.length}/${txCount} transaction(s)`, this.name);
|
|
551
|
+
}
|
|
644
552
|
if (!hashes.length)
|
|
645
553
|
return [];
|
|
646
554
|
const byHash = await this.getTransactionsBatch(hashes);
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
.
|
|
555
|
+
const missing = hashes.filter(h => !byHash.has(h));
|
|
556
|
+
if (missing.length > 0) {
|
|
557
|
+
throw new errors_1.ProviderUnavailableError(`Incomplete transaction data for block ${blockHash}: ${missing.length}/${hashes.length} transaction(s) missing`, this.name);
|
|
558
|
+
}
|
|
559
|
+
return hashes.map(h => byHash.get(h));
|
|
650
560
|
}, this.name);
|
|
651
561
|
}
|
|
652
562
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Runs `fn` with `signal` as the signal of the backend call. */
|
|
2
|
+
export declare function withCallSignal<T>(signal: AbortSignal, fn: () => Promise<T>): Promise<T>;
|
|
3
|
+
/** Signal of the backend call in progress, if any. */
|
|
4
|
+
export declare function callSignal(): AbortSignal | undefined;
|
|
5
|
+
/** Throws the abort reason once the backend call in progress was given up. */
|
|
6
|
+
export declare function throwIfCallAborted(): void;
|
|
7
|
+
//# sourceMappingURL=call-signal.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withCallSignal = withCallSignal;
|
|
4
|
+
exports.callSignal = callSignal;
|
|
5
|
+
exports.throwIfCallAborted = throwIfCallAborted;
|
|
6
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
7
|
+
// The abort signal of the backend call in progress. CardanoClient aborts it when the call times
|
|
8
|
+
// out, so the HTTP requests and batch loops the call started stop as well.
|
|
9
|
+
const storage = new node_async_hooks_1.AsyncLocalStorage();
|
|
10
|
+
/** Runs `fn` with `signal` as the signal of the backend call. */
|
|
11
|
+
function withCallSignal(signal, fn) {
|
|
12
|
+
return storage.run(signal, fn);
|
|
13
|
+
}
|
|
14
|
+
/** Signal of the backend call in progress, if any. */
|
|
15
|
+
function callSignal() {
|
|
16
|
+
return storage.getStore();
|
|
17
|
+
}
|
|
18
|
+
/** Throws the abort reason once the backend call in progress was given up. */
|
|
19
|
+
function throwIfCallAborted() {
|
|
20
|
+
callSignal()?.throwIfAborted();
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=call-signal.js.map
|