@odatano/core 2.0.0-rc.35 → 2.0.0-rc.37
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odatano/core",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.37",
|
|
4
4
|
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#cds-models/*": "./@cds-models/*/index.js"
|
|
@@ -77,6 +77,18 @@
|
|
|
77
77
|
"vitest": "^4.1.10"
|
|
78
78
|
},
|
|
79
79
|
"cds": {
|
|
80
|
+
"log": {
|
|
81
|
+
"mask_headers": [
|
|
82
|
+
"/authorization/i",
|
|
83
|
+
"/cookie/i",
|
|
84
|
+
"/cert/i",
|
|
85
|
+
"/ssl/i",
|
|
86
|
+
"/token/i",
|
|
87
|
+
"/key/i",
|
|
88
|
+
"/secret/i",
|
|
89
|
+
"/project_id/i"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
80
92
|
"typer": {
|
|
81
93
|
"ieee754compatible": true
|
|
82
94
|
},
|
|
@@ -108,6 +108,11 @@ export declare class CardanoClient {
|
|
|
108
108
|
getPool(poolId: string): Promise<PoolData>;
|
|
109
109
|
getDrep(drepId: string): Promise<DrepData>;
|
|
110
110
|
getAccount(stakeAddress: string): Promise<AccountData>;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the reward account is registered in the ledger. Node first; the first backend that
|
|
113
|
+
* answers decides, its "not found" means not registered. Only a backend failure falls through.
|
|
114
|
+
*/
|
|
115
|
+
isRewardAccountRegistered(stakeAddress: string): Promise<boolean>;
|
|
111
116
|
/** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
|
|
112
117
|
getAssetInfo(unit: string): Promise<AssetInfo>;
|
|
113
118
|
/**
|
|
@@ -358,6 +358,22 @@ class CardanoClient {
|
|
|
358
358
|
getAccount(stakeAddress) {
|
|
359
359
|
return this.route('getAccount', b => b.getAccount(stakeAddress));
|
|
360
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Whether the reward account is registered in the ledger. Node first; the first backend that
|
|
363
|
+
* answers decides, its "not found" means not registered. Only a backend failure falls through.
|
|
364
|
+
*/
|
|
365
|
+
isRewardAccountRegistered(stakeAddress) {
|
|
366
|
+
return this.executeWithPriority(async (b) => {
|
|
367
|
+
try {
|
|
368
|
+
return (await b.getAccount(stakeAddress)).active;
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
if (err instanceof errors_1.NotFoundError)
|
|
372
|
+
return false;
|
|
373
|
+
throw err;
|
|
374
|
+
}
|
|
375
|
+
}, true, 'getAccount');
|
|
376
|
+
}
|
|
361
377
|
/** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
|
|
362
378
|
getAssetInfo(unit) {
|
|
363
379
|
return this.route('getAssetInfo', b => b.getAssetInfo(unit));
|
|
@@ -216,16 +216,7 @@ class CardanoTransactionBuilder {
|
|
|
216
216
|
for (const [i, w] of withdrawals.entries()) {
|
|
217
217
|
if (registeredHere.has(w.rewardAddress.toLowerCase()))
|
|
218
218
|
continue;
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
active = (await this.client.getAccount(w.rewardAddress)).active;
|
|
222
|
-
}
|
|
223
|
-
catch (err) {
|
|
224
|
-
if (!(err instanceof errors_1.NotFoundError))
|
|
225
|
-
throw err;
|
|
226
|
-
active = false;
|
|
227
|
-
}
|
|
228
|
-
if (!active) {
|
|
219
|
+
if (!(await this.client.isRewardAccountRegistered(w.rewardAddress))) {
|
|
229
220
|
throw new errors_1.TransactionValidationError(`withdrawals[${i}] reward account ${w.rewardAddress} is not registered on chain; register the stake credential first`);
|
|
230
221
|
}
|
|
231
222
|
}
|
package/srv/cardano-service.js
CHANGED
|
@@ -92,6 +92,91 @@ function indexOnMissAction(actionName, entity, reqKeyField, validate, indexFn, o
|
|
|
92
92
|
});
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
+
/** Addresses one collection read may index on a miss; more is a 400. */
|
|
96
|
+
const MAX_ADDRESSES_PER_READ = 10;
|
|
97
|
+
const isRef = (t) => typeof t === 'object' && 'ref' in t;
|
|
98
|
+
const isVal = (t) => typeof t === 'object' && 'val' in t;
|
|
99
|
+
const isList = (t) => typeof t === 'object' && 'list' in t;
|
|
100
|
+
const isXpr = (t) => typeof t === 'object' && 'xpr' in t;
|
|
101
|
+
/** `address_address` or the association path `address/address`. */
|
|
102
|
+
function isAddressRef(t) {
|
|
103
|
+
if (!isRef(t))
|
|
104
|
+
return false;
|
|
105
|
+
const path = t.ref;
|
|
106
|
+
return (path.length === 1 && path[0] === 'address_address') || (path.length === 2 && path[0] === 'address' && path[1] === 'address');
|
|
107
|
+
}
|
|
108
|
+
const stringVal = (t) => t !== undefined && isVal(t) && typeof t.val === 'string' ? t.val : undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Addresses a read of an address child set names: the parent of a navigation
|
|
111
|
+
* (`Addresses('…')/utxos`) or the `$filter` terms `address_address eq '…'` (either operand
|
|
112
|
+
* order) and `address_address in ('…', …)`.
|
|
113
|
+
*/
|
|
114
|
+
function addressesInReadQuery(req) {
|
|
115
|
+
const found = new Set();
|
|
116
|
+
const parent = req.data?.address_address;
|
|
117
|
+
if (typeof parent === 'string')
|
|
118
|
+
found.add(parent);
|
|
119
|
+
const walk = (tokens) => {
|
|
120
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
121
|
+
const token = tokens[i];
|
|
122
|
+
if (typeof token === 'string')
|
|
123
|
+
continue;
|
|
124
|
+
if (isXpr(token)) {
|
|
125
|
+
walk(token.xpr);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const op = tokens[i + 1];
|
|
129
|
+
const right = tokens[i + 2];
|
|
130
|
+
if (isAddressRef(token) && op === '=') {
|
|
131
|
+
const value = stringVal(right);
|
|
132
|
+
if (value)
|
|
133
|
+
found.add(value);
|
|
134
|
+
}
|
|
135
|
+
else if (isAddressRef(token) && op === 'in' && right !== undefined && isList(right)) {
|
|
136
|
+
for (const item of right.list) {
|
|
137
|
+
const value = stringVal(item);
|
|
138
|
+
if (value)
|
|
139
|
+
found.add(value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (right !== undefined && isAddressRef(right) && op === '=') {
|
|
143
|
+
const value = stringVal(token);
|
|
144
|
+
if (value)
|
|
145
|
+
found.add(value);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const query = req.query;
|
|
150
|
+
walk(('SELECT' in query && query.SELECT?.where) || []);
|
|
151
|
+
return Array.from(found);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Factory: READ handler for a child set of Addresses with index-on-miss. The address is taken
|
|
155
|
+
* from the navigation parent or the `$filter`; without one the read passes through.
|
|
156
|
+
* `isIndexed` says whether the address needs no fetch, `indexFn` fetches it.
|
|
157
|
+
*/
|
|
158
|
+
function addressChildRead(isIndexed, indexFn) {
|
|
159
|
+
return async (req) => {
|
|
160
|
+
const addresses = addressesInReadQuery(req);
|
|
161
|
+
if (addresses.length > MAX_ADDRESSES_PER_READ) {
|
|
162
|
+
(0, errors_1.rejectInvalid)(req, 'address_address', `A read may name at most ${MAX_ADDRESSES_PER_READ} addresses`, 'address_address');
|
|
163
|
+
}
|
|
164
|
+
for (const address of addresses) {
|
|
165
|
+
if (!(0, validators_1.isValidBech32Address)(address))
|
|
166
|
+
(0, errors_1.rejectInvalid)(req, 'address_address', 'Invalid bech32 address format', 'address_address');
|
|
167
|
+
}
|
|
168
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
169
|
+
if (addresses.length) {
|
|
170
|
+
widenTemporalWindow(req); // before the first DB statement
|
|
171
|
+
for (const address of addresses) {
|
|
172
|
+
if (!(await isIndexed(db, address)))
|
|
173
|
+
await indexFn(db, address);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return db.run(req.query);
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
}
|
|
95
180
|
// ---------------------------------------------------------------------------
|
|
96
181
|
// Service Registration
|
|
97
182
|
// ---------------------------------------------------------------------------
|
|
@@ -208,7 +293,28 @@ module.exports = (srv) => {
|
|
|
208
293
|
return latestSlices(assets, (asset) => asset.unit ?? '');
|
|
209
294
|
});
|
|
210
295
|
});
|
|
211
|
-
//
|
|
296
|
+
// Prefer the full address index; when no configured backend supports getAddress
|
|
297
|
+
// (AllBackendsFailedError with zero collected errors, e.g. Ogmios only), fall back to a
|
|
298
|
+
// UTxO-only index. getAddress is indexAddress's first call, so nothing is persisted before.
|
|
299
|
+
const indexAddressOrUtxos = async (db, address) => {
|
|
300
|
+
try {
|
|
301
|
+
await indexer().indexAddress(db, address);
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
if (err instanceof errors_1.AllBackendsFailedError && err.errors.length === 0) {
|
|
305
|
+
await indexer().indexAddressUtxos(db, address);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
throw err;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
// An address is indexed when its Addresses row is valid. The UTxO-only fallback writes no
|
|
313
|
+
// Addresses row, so for UTxOs a valid AddressUTxOs row counts as well.
|
|
314
|
+
const addressIndexed = async (db, address) => !!(await db.run(SELECT.one.from(Addresses).where({ address })));
|
|
315
|
+
const addressUtxosIndexed = async (db, address) => (await addressIndexed(db, address))
|
|
316
|
+
|| !!(await db.run(SELECT.one.from(AddressUTxOs).where({ address_address: address })));
|
|
317
|
+
// GetUTxOsByAddress — indexes the address if needed, then queries child UTxOs.
|
|
212
318
|
srv.on('GetUTxOsByAddress', async (req) => {
|
|
213
319
|
const { address } = req.data;
|
|
214
320
|
if (!address)
|
|
@@ -217,28 +323,16 @@ module.exports = (srv) => {
|
|
|
217
323
|
(0, errors_1.rejectInvalid)(req, 'GetUTxOsByAddress', 'Invalid bech32 address format', 'address');
|
|
218
324
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
219
325
|
widenTemporalWindow(req); // before the first DB statement
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// UTxO-only index. getAddress is indexAddress's first call, so nothing is persisted before.
|
|
225
|
-
try {
|
|
226
|
-
await indexer().indexAddress(db, address);
|
|
227
|
-
}
|
|
228
|
-
catch (err) {
|
|
229
|
-
if (err instanceof errors_1.AllBackendsFailedError && err.errors.length === 0) {
|
|
230
|
-
await indexer().indexAddressUtxos(db, address);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
throw err;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const fresh = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
|
|
237
|
-
return fresh;
|
|
238
|
-
}
|
|
239
|
-
return latestSlices(existing, (utxo) => `${utxo.hash}#${utxo.index}`);
|
|
326
|
+
if (!(await addressUtxosIndexed(db, address)))
|
|
327
|
+
await indexAddressOrUtxos(db, address);
|
|
328
|
+
const utxos = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
|
|
329
|
+
return latestSlices(utxos, (utxo) => `${utxo.hash}#${utxo.index}`);
|
|
240
330
|
});
|
|
241
331
|
});
|
|
332
|
+
// Collection reads of the address child sets fill like the parent: an address named in the
|
|
333
|
+
// navigation or the $filter is indexed on a miss, then the client's own query runs.
|
|
334
|
+
srv.on('READ', AddressUTxOs, addressChildRead(addressUtxosIndexed, indexAddressOrUtxos));
|
|
335
|
+
srv.on('READ', AddressAssets, addressChildRead(addressIndexed, (db, address) => indexer().indexAddress(db, address)));
|
|
242
336
|
// GetUTxOsByCredential — always-fresh credential-keyed UTxO query (dApp state reads need current
|
|
243
337
|
// data). Crawled UTxO set + node first, else Koios; ProviderUnavailableError without either.
|
|
244
338
|
srv.on('GetUTxOsByCredential', async (req) => {
|