@odatano/core 2.0.0-rc.3 → 2.0.0-rc.30
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 +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoBackendService/index.d.ts +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
- package/@cds-models/CardanoIndexerService/index.js +25 -0
- package/@cds-models/CardanoODataService/index.d.ts +294 -7
- package/@cds-models/CardanoODataService/index.js +33 -0
- package/@cds-models/CardanoSignService/index.d.ts +28 -3
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +52 -19
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +18 -0
- package/@cds-models/index.js +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +408 -7
- package/@cds-models/odatano/cardano/index.js +42 -0
- package/README.md +64 -5
- package/db/schema.cds +677 -13
- package/db/types.cds +27 -0
- package/package.json +182 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +11 -10
- package/src/index.js +28 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +49 -160
- package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
- package/srv/blockchain/backends/cardano-backend.js +19 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +356 -217
- package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
- package/srv/blockchain/backends/odatano-backend.js +170 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
- package/srv/blockchain/backends/ogmios-backend.js +548 -197
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +78 -205
- package/srv/blockchain/cardano-client.js +186 -242
- package/srv/blockchain/cardano-indexer.d.ts +302 -242
- package/srv/blockchain/cardano-indexer.js +1191 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +43 -81
- package/srv/blockchain/cardano-tx-builder.js +177 -132
- package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
- package/srv/blockchain/crawler/certificate-backfill.js +169 -0
- package/srv/blockchain/crawler/crawler.d.ts +139 -54
- package/srv/blockchain/crawler/crawler.js +478 -96
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +46 -28
- package/srv/blockchain/crawler/sync-state.js +128 -43
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
- package/srv/blockchain/crawler/utxo-set-import.js +363 -0
- package/srv/blockchain/ledger-state.d.ts +101 -0
- package/srv/blockchain/ledger-state.js +432 -0
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -49
- package/srv/blockchain/stored-chain.d.ts +33 -0
- package/srv/blockchain/stored-chain.js +234 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +108 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +620 -285
- package/srv/blockchain/transaction-building/caller-datums.d.ts +17 -0
- package/srv/blockchain/transaction-building/caller-datums.js +50 -0
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +43 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +48 -24
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +244 -0
- package/srv/cardano-indexer-service.cds +201 -73
- package/srv/cardano-indexer-service.js +280 -11
- package/srv/cardano-service.cds +56 -1
- package/srv/cardano-service.js +52 -113
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +439 -364
- package/srv/cardano-tx-service.js +305 -209
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/parse.js +13 -1
- package/srv/server.d.ts +28 -86
- package/srv/server.js +127 -135
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +922 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +30 -67
- package/srv/utils/const.js +32 -72
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +94 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/error-codes.d.ts +20 -73
- package/srv/utils/error-codes.js +19 -70
- package/srv/utils/errors.d.ts +50 -177
- package/srv/utils/errors.js +94 -218
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +40 -0
- package/srv/utils/mappers.d.ts +128 -214
- package/srv/utils/mappers.js +354 -299
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +62 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +56 -0
- package/srv/utils/plutus-placeholders.d.ts +23 -16
- package/srv/utils/plutus-placeholders.js +63 -27
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +26 -92
- package/srv/utils/tx-build-helper.js +68 -123
- package/srv/utils/tx-request-parsers.d.ts +107 -21
- package/srv/utils/tx-request-parsers.js +433 -34
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +238 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
package/srv/cardano-service.js
CHANGED
|
@@ -9,30 +9,27 @@ const validators_1 = require("./utils/validators");
|
|
|
9
9
|
const errors_1 = require("./utils/errors");
|
|
10
10
|
const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
11
11
|
const cbor_1 = require("./cbor");
|
|
12
|
+
/** Newest temporal slice per key; child tables keep one row per validFrom. */
|
|
13
|
+
function latestSlices(rows, keyOf) {
|
|
14
|
+
const seen = new Map();
|
|
15
|
+
for (const row of rows) {
|
|
16
|
+
const key = keyOf(row);
|
|
17
|
+
const prev = seen.get(key);
|
|
18
|
+
if (!prev || (row.validFrom ?? '') > (prev.validFrom ?? ''))
|
|
19
|
+
seen.set(key, row);
|
|
20
|
+
}
|
|
21
|
+
return Array.from(seen.values());
|
|
22
|
+
}
|
|
12
23
|
const { SELECT } = cds_1.default.ql;
|
|
13
24
|
const logger = cds_1.default.log(`CardanoService`);
|
|
14
|
-
/**
|
|
15
|
-
* Upper bound of the temporal window opened by {@link widenTemporalWindow}.
|
|
16
|
-
* Generous on purpose: it only has to outlast the slowest index-on-miss (chained
|
|
17
|
-
* backend timeouts of several calls) within ONE request.
|
|
18
|
-
*/
|
|
25
|
+
/** Upper bound of the temporal window; must outlast the slowest index-on-miss of one request. */
|
|
19
26
|
const TEMPORAL_WINDOW_SLACK_MS = 60 * 60 * 1000;
|
|
20
27
|
/**
|
|
21
|
-
* Let this request see temporal slices
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* transaction begins (HANA) or on first use (sqlite) and otherwise defaults to
|
|
27
|
-
* `now` / `now + 1ms` — a window that is closed long before the backend fetch
|
|
28
|
-
* returns, so a slice stamped after the fetch would be invisible to the
|
|
29
|
-
* `req.query` re-read that honours `$expand` / `$select` (KNOWN_ISSUES #13).
|
|
30
|
-
*
|
|
31
|
-
* Only the UPPER bound is moved. No slice is ever future-dated (every mapper
|
|
32
|
-
* stamps `validFrom = now`), so the only additional rows this admits are the
|
|
33
|
-
* ones this very request writes; expired rows stay hidden (`validTo >
|
|
34
|
-
* $valid.from` is untouched). Explicit `sap-valid-*` query options are left
|
|
35
|
-
* alone. Must run before the handler's first DB statement.
|
|
28
|
+
* Let this request see the temporal slices it writes during index-on-miss: CAP's temporal
|
|
29
|
+
* filter (`validFrom < $valid.to`) defaults to a `now`..`now+1ms` window fixed at transaction
|
|
30
|
+
* start, so a slice stamped after the backend fetch would be invisible to the handler's
|
|
31
|
+
* re-read. Only the upper bound moves; explicit `sap-valid-*` options are left alone.
|
|
32
|
+
* Must run before the handler's first DB statement.
|
|
36
33
|
*/
|
|
37
34
|
function widenTemporalWindow(req) {
|
|
38
35
|
const q = req.http?.req?.query;
|
|
@@ -41,9 +38,7 @@ function widenTemporalWindow(req) {
|
|
|
41
38
|
const now = Date.now();
|
|
42
39
|
const from = new Date(now).toISOString();
|
|
43
40
|
const to = new Date(now + TEMPORAL_WINDOW_SLACK_MS).toISOString();
|
|
44
|
-
// The DB session
|
|
45
|
-
// with — `req` for our `cds.tx(req)`, the root context if a generic handler got
|
|
46
|
-
// there first — so stamp both bags.
|
|
41
|
+
// The DB session reads the bag of whichever context opened the transaction; stamp both.
|
|
47
42
|
const r = req;
|
|
48
43
|
for (const bag of new Set([r._, r.context?._])) {
|
|
49
44
|
if (!bag)
|
|
@@ -53,47 +48,32 @@ function widenTemporalWindow(req) {
|
|
|
53
48
|
}
|
|
54
49
|
}
|
|
55
50
|
/**
|
|
56
|
-
* Factory: READ handler with index-on-miss
|
|
57
|
-
*
|
|
58
|
-
* client's own query so `$expand` / `$select` are honoured on the keyed branch
|
|
59
|
-
* too (KNOWN_ISSUES #13: returning the bare row silently dropped them).
|
|
60
|
-
* If no key, passes through to generic req.query.
|
|
51
|
+
* Factory: READ handler with index-on-miss. With a key, indexes on a cache miss and then
|
|
52
|
+
* runs the client's own query so `$expand` / `$select` apply; without a key, passes through.
|
|
61
53
|
*/
|
|
62
54
|
function indexOnMissRead(entity, reqKeyField, validate, indexFn, options) {
|
|
63
55
|
const dbKey = options?.entityKeyField || reqKeyField;
|
|
64
56
|
const errMsg = options?.errorMessage || `Invalid ${reqKeyField} format`;
|
|
65
57
|
return async (req) => {
|
|
66
58
|
const key = req.data?.[reqKeyField];
|
|
67
|
-
//
|
|
68
|
-
// like epoch=0 or an empty string (the latter then hit the backend unvalidated)
|
|
59
|
+
// Explicit null check: falsy keys such as epoch=0 or '' must still be validated.
|
|
69
60
|
if (key !== undefined && key !== null && validate && !validate(key))
|
|
70
61
|
(0, errors_1.rejectInvalid)(req, dbKey, errMsg, reqKeyField);
|
|
71
62
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
72
63
|
if (key !== undefined && key !== null) {
|
|
73
|
-
widenTemporalWindow(req); // before the first DB statement
|
|
74
|
-
//
|
|
64
|
+
widenTemporalWindow(req); // before the first DB statement
|
|
65
|
+
// The temporal aspect hides expired rows, so a miss here triggers a re-index.
|
|
75
66
|
const existing = await db.run(SELECT.one.from(entity).where({ [dbKey]: key }));
|
|
76
|
-
// Populate the row (+ compositions) on a miss, then let CAP run the client's
|
|
77
|
-
// query — one extra SELECT per keyed read, but $expand/$select (and the
|
|
78
|
-
// temporal filter of the projection) apply exactly as on the un-keyed path.
|
|
79
67
|
if (!existing)
|
|
80
68
|
await indexFn(db, key);
|
|
81
|
-
// The client's query is the
|
|
82
|
-
//
|
|
83
|
-
// answers a request the client never made — a second key that does not
|
|
84
|
-
// match, or an excluding $filter, would get a sibling row with a 200
|
|
85
|
-
// instead of a 404 (KNOWN_ISSUES #15). Non-temporal entities always see
|
|
86
|
-
// their fresh rows here; temporal ones rely on widenTemporalWindow above,
|
|
87
|
-
// and if that ever stops working the failure is a loud 404 covered by
|
|
88
|
-
// test/integration/keyed-read-expand.test.ts, not silently wrong data.
|
|
69
|
+
// The client's query is the only authority on the result: never fall back to
|
|
70
|
+
// `existing`, or an excluding $filter / second key would yield a sibling row instead of 404.
|
|
89
71
|
}
|
|
90
72
|
return db.run(req.query);
|
|
91
73
|
});
|
|
92
74
|
};
|
|
93
75
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Factory: Action handler with required key validation and index-on-miss.
|
|
96
|
-
*/
|
|
76
|
+
/** Factory: action handler with required-key validation and index-on-miss. */
|
|
97
77
|
function indexOnMissAction(actionName, entity, reqKeyField, validate, indexFn, options) {
|
|
98
78
|
const dbKey = options?.entityKeyField || reqKeyField;
|
|
99
79
|
const errMsg = options?.errorMessage || `Invalid ${reqKeyField} format`;
|
|
@@ -104,7 +84,7 @@ function indexOnMissAction(actionName, entity, reqKeyField, validate, indexFn, o
|
|
|
104
84
|
if (!validate(key))
|
|
105
85
|
(0, errors_1.rejectInvalid)(req, actionName, errMsg, reqKeyField);
|
|
106
86
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
107
|
-
//
|
|
87
|
+
// The temporal aspect hides expired rows, so a miss here triggers a re-index.
|
|
108
88
|
const existing = await db.run(SELECT.one.from(entity).where({ [dbKey]: key }));
|
|
109
89
|
if (!existing)
|
|
110
90
|
return await indexFn(db, key);
|
|
@@ -115,23 +95,14 @@ function indexOnMissAction(actionName, entity, reqKeyField, validate, indexFn, o
|
|
|
115
95
|
// ---------------------------------------------------------------------------
|
|
116
96
|
// Service Registration
|
|
117
97
|
// ---------------------------------------------------------------------------
|
|
118
|
-
/**
|
|
119
|
-
* Cardano Service Implementation
|
|
120
|
-
* Handles various Cardano blockchain data queries with index-on-miss behavior.
|
|
121
|
-
*/
|
|
98
|
+
/** CardanoODataService handlers: blockchain read queries with index-on-miss. */
|
|
122
99
|
module.exports = (srv) => {
|
|
123
100
|
logger.debug('Module loaded - registering handlers');
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
// registration must use the plural class — under cds 10 registering `srv.on('READ',
|
|
128
|
-
// <singular proxy>)` no longer matches incoming OData READs, so the generic CRUD
|
|
129
|
-
// handler silently served those entities (empty results / 404 instead of
|
|
130
|
-
// index-on-miss). All other names below already resolve to plural classes.
|
|
101
|
+
// For plural-shaped names (NetworkInformation, TransactionMetadata, AssetHistory) cds-typer
|
|
102
|
+
// exports the singular class under the plain name and the entity-set class with a trailing
|
|
103
|
+
// underscore. Handlers must register the entity-set class; a singular one never matches under cds 10.
|
|
131
104
|
const { NetworkInformation_: NetworkInformation, Blocks, Epochs, Addresses, AddressAssets, AddressUTxOs, Transactions, TransactionMetadata_: TransactionMetadata, Pools, Accounts, Dreps, Assets, AssetHistory_: AssetHistory, LedgerProtocolParameters, AddressTransactions } = require('#cds-models/CardanoODataService');
|
|
132
|
-
// Fail fast
|
|
133
|
-
// above): a singular registration silently degrades to the generic CRUD handler.
|
|
134
|
-
// Every cds-typer proxy carries an explicit is_singular marker we can assert on.
|
|
105
|
+
// Fail fast on a singular class: it would silently degrade to the generic CRUD handler.
|
|
135
106
|
for (const [name, entity] of Object.entries({
|
|
136
107
|
NetworkInformation, Blocks, Epochs, Addresses, AddressAssets, AddressUTxOs,
|
|
137
108
|
Transactions, TransactionMetadata, Pools, Accounts, Dreps, Assets, AssetHistory,
|
|
@@ -143,7 +114,6 @@ module.exports = (srv) => {
|
|
|
143
114
|
`plural entity-set class instead (e.g. '${name}_ as ${name}').`);
|
|
144
115
|
}
|
|
145
116
|
}
|
|
146
|
-
// Helper: shorthand for indexer access
|
|
147
117
|
const indexer = () => (0, server_1.getCardanoIndexer)();
|
|
148
118
|
// ---------------------------------------------------------------------------
|
|
149
119
|
// Network Information (singleton - no key field)
|
|
@@ -197,18 +167,13 @@ module.exports = (srv) => {
|
|
|
197
167
|
srv.on('READ', Assets, indexOnMissRead(Assets, 'unit', validators_1.isAssetUnit, (db, u) => indexer().indexAsset(db, u), { errorMessage: 'Invalid asset unit format' }));
|
|
198
168
|
srv.on('GetAssetInfo', indexOnMissAction('GetAssetInfo', Assets, 'unit', validators_1.isAssetUnit, (db, u) => indexer().indexAsset(db, u), { errorMessage: 'Invalid asset unit format' }));
|
|
199
169
|
// ---------------------------------------------------------------------------
|
|
200
|
-
// Asset History
|
|
170
|
+
// Asset History
|
|
201
171
|
// ---------------------------------------------------------------------------
|
|
202
|
-
// Generic READ
|
|
203
|
-
// must call GetAssetHistory(unit) first to seed entries for a given asset,
|
|
204
|
-
// then page via $top/$skip on the AssetHistory entity.
|
|
172
|
+
// Generic READ is served from the DB only; GetAssetHistory(unit) seeds the rows.
|
|
205
173
|
srv.on('READ', AssetHistory, async (req) => {
|
|
206
174
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => db.run(req.query));
|
|
207
175
|
});
|
|
208
|
-
|
|
209
|
-
* Action: GetAssetHistory - Always-fresh fetch of recent mint/burn events.
|
|
210
|
-
* Multi-backend: Koios preferred (block timestamps), Blockfrost fallback.
|
|
211
|
-
*/
|
|
176
|
+
// GetAssetHistory — always-fresh fetch of recent mint/burn events.
|
|
212
177
|
srv.on('GetAssetHistory', async (req) => {
|
|
213
178
|
const { unit, limit } = req.data;
|
|
214
179
|
if (!unit)
|
|
@@ -216,7 +181,7 @@ module.exports = (srv) => {
|
|
|
216
181
|
if (!(0, validators_1.isAssetUnit)(unit)) {
|
|
217
182
|
return (0, errors_1.rejectInvalid)(req, 'GetAssetHistory', 'Invalid asset unit format', 'unit');
|
|
218
183
|
}
|
|
219
|
-
//
|
|
184
|
+
// Clamp: an unbounded limit would page the upstream backend indefinitely.
|
|
220
185
|
const effectiveLimit = Math.min(Math.max(typeof limit === 'number' ? limit : 100, 1), 100);
|
|
221
186
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
222
187
|
return await indexer().indexAssetHistory(db, unit, effectiveLimit);
|
|
@@ -227,9 +192,7 @@ module.exports = (srv) => {
|
|
|
227
192
|
// ---------------------------------------------------------------------------
|
|
228
193
|
srv.on('READ', Addresses, indexOnMissRead(Addresses, 'address', validators_1.isValidBech32Address, (db, a) => indexer().indexAddress(db, a), { errorMessage: 'Invalid bech32 address format' }));
|
|
229
194
|
srv.on('GetAddressByBech32', indexOnMissAction('GetAddressByBech32', Addresses, 'address', validators_1.isValidBech32Address, (db, a) => indexer().indexAddress(db, a), { errorMessage: 'Invalid bech32 address format' }));
|
|
230
|
-
|
|
231
|
-
* Action: GetAssetsByAddress - indexes parent address if needed, then queries child assets.
|
|
232
|
-
*/
|
|
195
|
+
// GetAssetsByAddress — indexes the parent address if needed, then queries child assets.
|
|
233
196
|
srv.on('GetAssetsByAddress', async (req) => {
|
|
234
197
|
const { address } = req.data;
|
|
235
198
|
if (!address)
|
|
@@ -237,23 +200,15 @@ module.exports = (srv) => {
|
|
|
237
200
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
238
201
|
(0, errors_1.rejectInvalid)(req, 'GetAssetsByAddress', 'Invalid bech32 address format', 'address');
|
|
239
202
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
203
|
+
widenTemporalWindow(req); // before the first DB statement
|
|
240
204
|
const existing = await db.run(SELECT.one.from(Addresses).where({ address }));
|
|
241
205
|
if (!existing)
|
|
242
206
|
await indexer().indexAddress(db, address);
|
|
243
207
|
const assets = await db.run(SELECT.from(AddressAssets).where({ address_address: address }));
|
|
244
|
-
|
|
245
|
-
const seen = new Map();
|
|
246
|
-
for (const asset of assets) {
|
|
247
|
-
if (!seen.has(asset.unit) || asset.validFrom > seen.get(asset.unit).validFrom) {
|
|
248
|
-
seen.set(asset.unit, asset);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return Array.from(seen.values());
|
|
208
|
+
return latestSlices(assets, (asset) => asset.unit ?? '');
|
|
252
209
|
});
|
|
253
210
|
});
|
|
254
|
-
|
|
255
|
-
* Action: GetUTxOsByAddress - indexes parent address if needed, then queries child UTxOs.
|
|
256
|
-
*/
|
|
211
|
+
// GetUTxOsByAddress — indexes the parent address if needed, then queries child UTxOs.
|
|
257
212
|
srv.on('GetUTxOsByAddress', async (req) => {
|
|
258
213
|
const { address } = req.data;
|
|
259
214
|
if (!address)
|
|
@@ -261,16 +216,12 @@ module.exports = (srv) => {
|
|
|
261
216
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
262
217
|
(0, errors_1.rejectInvalid)(req, 'GetUTxOsByAddress', 'Invalid bech32 address format', 'address');
|
|
263
218
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
219
|
+
widenTemporalWindow(req); // before the first DB statement
|
|
264
220
|
const existing = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
|
|
265
221
|
if (!existing || existing.length === 0) {
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
// only needs the UTxO set, which Ogmios serves via getAddressUtxos even though it
|
|
270
|
-
// doesn't support getAddress — so when NO configured backend can serve getAddress
|
|
271
|
-
// (AllBackendsFailedError with zero collected errors == every backend skipped it),
|
|
272
|
-
// fall back to a UTxO-only index instead of failing. getAddress is indexAddress's
|
|
273
|
-
// first call, so nothing is persisted before this throws — the fallback is clean.
|
|
222
|
+
// Prefer the full address index; when no configured backend supports getAddress
|
|
223
|
+
// (AllBackendsFailedError with zero collected errors, e.g. Ogmios only), fall back to a
|
|
224
|
+
// UTxO-only index. getAddress is indexAddress's first call, so nothing is persisted before.
|
|
274
225
|
try {
|
|
275
226
|
await indexer().indexAddress(db, address);
|
|
276
227
|
}
|
|
@@ -285,23 +236,11 @@ module.exports = (srv) => {
|
|
|
285
236
|
const fresh = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
|
|
286
237
|
return fresh;
|
|
287
238
|
}
|
|
288
|
-
|
|
289
|
-
const seen = new Map();
|
|
290
|
-
for (const utxo of existing) {
|
|
291
|
-
const key = `${utxo.hash}#${utxo.index}`;
|
|
292
|
-
if (!seen.has(key) || utxo.validFrom > seen.get(key).validFrom) {
|
|
293
|
-
seen.set(key, utxo);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return Array.from(seen.values());
|
|
239
|
+
return latestSlices(existing, (utxo) => `${utxo.hash}#${utxo.index}`);
|
|
297
240
|
});
|
|
298
241
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
* Always-fresh (no cache check) — credential queries serve dApp state-read use
|
|
302
|
-
* cases (Indigo CDPs, Liqwid positions) that need current blockchain state.
|
|
303
|
-
* Throws ProviderUnavailableError if Koios backend is not configured.
|
|
304
|
-
*/
|
|
242
|
+
// GetUTxOsByCredential — always-fresh credential-keyed UTxO query (dApp state reads need current
|
|
243
|
+
// data). Crawled UTxO set + node first, else Koios; ProviderUnavailableError without either.
|
|
305
244
|
srv.on('GetUTxOsByCredential', async (req) => {
|
|
306
245
|
const { credential } = req.data;
|
|
307
246
|
if (!credential)
|
|
@@ -322,10 +261,7 @@ module.exports = (srv) => {
|
|
|
322
261
|
// Transaction Metadata
|
|
323
262
|
// ---------------------------------------------------------------------------
|
|
324
263
|
srv.on('READ', TransactionMetadata, indexOnMissRead(TransactionMetadata, 'tx_hash', validators_1.isTxHash, (db, h) => indexer().indexTransactionMetadata(db, h), { errorMessage: 'Invalid transaction hash format' }));
|
|
325
|
-
|
|
326
|
-
* Action: GetMetadataByTxHash - returns multiple metadata rows (uses SELECT.from, not SELECT.one).
|
|
327
|
-
* Takes camelCase `txHash` like every other action (renamed from `tx_hash` in 1.9.4).
|
|
328
|
-
*/
|
|
264
|
+
// GetMetadataByTxHash — returns all metadata rows of a transaction.
|
|
329
265
|
srv.on('GetMetadataByTxHash', async (req) => {
|
|
330
266
|
const { txHash } = req.data;
|
|
331
267
|
if (!txHash)
|
|
@@ -355,7 +291,7 @@ module.exports = (srv) => {
|
|
|
355
291
|
return (0, backend_request_handler_1.handleRequest)(req, (db) => indexer().indexProtocolParameters(db));
|
|
356
292
|
});
|
|
357
293
|
// ---------------------------------------------------------------------------
|
|
358
|
-
// Transaction CBOR parsing (pure
|
|
294
|
+
// Transaction CBOR parsing (pure; no backend or DB access)
|
|
359
295
|
// ---------------------------------------------------------------------------
|
|
360
296
|
srv.on('ParseTransactionCbor', async (req) => {
|
|
361
297
|
const { cbor } = req.data;
|
|
@@ -377,6 +313,9 @@ module.exports = (srv) => {
|
|
|
377
313
|
(0, errors_1.rejectInvalid)(req, 'GetLatestTransactionsByAddress', 'Invalid bech32 address format', 'address');
|
|
378
314
|
const txLimit = Math.min(Math.max(limit || 10, 1), 100);
|
|
379
315
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
316
|
+
// The crawled UTxO set is current; the cached rows may miss the newest transactions.
|
|
317
|
+
if (await indexer().ledgerCoverageActive(db))
|
|
318
|
+
return indexer().indexAddressTransactions(db, address, txLimit);
|
|
380
319
|
const existing = await db.run(SELECT.from(AddressTransactions)
|
|
381
320
|
.where({ address_address: address })
|
|
382
321
|
.orderBy('blockTime desc')
|