@odatano/core 1.11.0 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoIndexerService/index.d.ts +142 -0
- package/@cds-models/CardanoIndexerService/index.js +23 -0
- package/@cds-models/CardanoODataService/index.d.ts +693 -2172
- package/@cds-models/CardanoODataService/index.js +88 -390
- package/@cds-models/CardanoSignService/index.d.ts +443 -1574
- package/@cds-models/CardanoSignService/index.js +62 -293
- package/@cds-models/CardanoTransactionService/index.d.ts +431 -1488
- package/@cds-models/CardanoTransactionService/index.js +60 -271
- package/@cds-models/CardanoWorkerService/index.d.ts +224 -0
- package/@cds-models/CardanoWorkerService/index.js +32 -0
- package/@cds-models/_/index.d.ts +70 -40
- package/@cds-models/_/index.js +17 -32
- package/@cds-models/cds/outbox/index.d.ts +28 -0
- package/@cds-models/index.d.ts +225 -522
- package/@cds-models/index.js +35 -218
- package/@cds-models/odatano/cardano/index.d.ts +896 -2947
- package/@cds-models/odatano/cardano/index.js +109 -536
- package/@cds-models/sap/common/index.d.ts +196 -600
- package/@cds-models/sap/common/index.js +28 -269
- package/README.md +136 -102
- package/db/schema.cds +283 -1
- package/db/types.cds +48 -0
- package/package.json +41 -32
- package/src/index.d.ts +1 -1
- package/src/index.js +10 -2
- package/src/plugin.js +12 -2
- package/srv/blockchain/backends/blockfrost-backend.d.ts +21 -2
- package/srv/blockchain/backends/blockfrost-backend.js +68 -15
- package/srv/blockchain/backends/cardano-backend.d.ts +69 -0
- package/srv/blockchain/backends/cardano-backend.js +13 -0
- package/srv/blockchain/backends/koios-backend.d.ts +26 -2
- package/srv/blockchain/backends/koios-backend.js +147 -15
- package/srv/blockchain/backends/ogmios-backend.d.ts +37 -6
- package/srv/blockchain/backends/ogmios-backend.js +254 -5
- package/srv/blockchain/cardano-client.d.ts +19 -0
- package/srv/blockchain/cardano-client.js +36 -0
- package/srv/blockchain/cardano-indexer.d.ts +50 -1
- package/srv/blockchain/cardano-indexer.js +191 -0
- package/srv/blockchain/crawler/crawler.d.ts +151 -0
- package/srv/blockchain/crawler/crawler.js +677 -0
- package/srv/blockchain/crawler/hooks.d.ts +43 -0
- package/srv/blockchain/crawler/hooks.js +62 -0
- package/srv/blockchain/crawler/index.d.ts +26 -0
- package/srv/blockchain/crawler/index.js +135 -0
- package/srv/blockchain/crawler/sync-state.d.ts +94 -0
- package/srv/blockchain/crawler/sync-state.js +265 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +45 -0
- package/srv/blockchain/signing/hsm-signer.js +8 -1
- package/srv/blockchain/wallet-worker/build-request.d.ts +26 -0
- package/srv/blockchain/wallet-worker/build-request.js +341 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +86 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +228 -0
- package/srv/blockchain/wallet-worker/index.d.ts +14 -0
- package/srv/blockchain/wallet-worker/index.js +80 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +261 -0
- package/srv/blockchain/wallet-worker/job-store.js +564 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +43 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +99 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +57 -0
- package/srv/blockchain/wallet-worker/signers.js +131 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +145 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +542 -0
- package/srv/cardano-indexer-service.cds +73 -0
- package/srv/cardano-indexer-service.d.ts +2 -0
- package/srv/cardano-indexer-service.js +76 -0
- package/srv/cardano-service.js +22 -1
- package/srv/cardano-tx-service.d.ts +1 -11
- package/srv/cardano-tx-service.js +11 -162
- package/srv/cardano-worker-service.cds +125 -0
- package/srv/cardano-worker-service.d.ts +2 -0
- package/srv/cardano-worker-service.js +199 -0
- package/srv/server.d.ts +32 -1
- package/srv/server.js +228 -2
- package/srv/utils/collections.d.ts +13 -0
- package/srv/utils/collections.js +24 -0
- package/srv/utils/crypto.d.ts +16 -0
- package/srv/utils/crypto.js +75 -0
- package/srv/utils/error-codes.d.ts +6 -0
- package/srv/utils/error-codes.js +6 -0
- package/srv/utils/errors.d.ts +12 -0
- package/srv/utils/errors.js +45 -0
- package/srv/utils/mappers.js +13 -3
- package/srv/utils/service-events.d.ts +26 -0
- package/srv/utils/service-events.js +46 -0
- package/srv/utils/tx-request-parsers.d.ts +58 -0
- package/srv/utils/tx-request-parsers.js +170 -0
- package/srv/utils/tx-utils.d.ts +2 -1
- package/srv/utils/tx-utils.js +3 -2
- package/srv/utils/types.d.ts +2 -1
- package/@cds-models/CardanoODataService/index.d.ts.map +0 -1
- package/@cds-models/CardanoODataService/index.js.map +0 -1
- package/@cds-models/CardanoODataService/index.ts +0 -776
- package/@cds-models/CardanoSignService/index.d.ts.map +0 -1
- package/@cds-models/CardanoSignService/index.js.map +0 -1
- package/@cds-models/CardanoSignService/index.ts +0 -569
- package/@cds-models/CardanoTransactionService/index.d.ts.map +0 -1
- package/@cds-models/CardanoTransactionService/index.js.map +0 -1
- package/@cds-models/CardanoTransactionService/index.ts +0 -526
- package/@cds-models/_/index.d.ts.map +0 -1
- package/@cds-models/_/index.js.map +0 -1
- package/@cds-models/_/index.ts +0 -96
- package/@cds-models/cds/outbox/index.ts +0 -27
- package/@cds-models/index.d.ts.map +0 -1
- package/@cds-models/index.js.map +0 -1
- package/@cds-models/index.ts +0 -245
- package/@cds-models/odatano/cardano/index.d.ts.map +0 -1
- package/@cds-models/odatano/cardano/index.js.map +0 -1
- package/@cds-models/odatano/cardano/index.ts +0 -789
- package/@cds-models/sap/common/index.d.ts.map +0 -1
- package/@cds-models/sap/common/index.js.map +0 -1
- package/@cds-models/sap/common/index.ts +0 -249
|
@@ -7,6 +7,12 @@ export declare const ERROR_CODES: {
|
|
|
7
7
|
* Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
|
|
8
8
|
*/
|
|
9
9
|
readonly INVALID_INPUT: "ODATANO_INVALID_INPUT";
|
|
10
|
+
/**
|
|
11
|
+
* 403 – Caller lacks the required role
|
|
12
|
+
* Indicates the caller is authenticated but not authorized for the operation
|
|
13
|
+
* (e.g. HSM-backed signing without the configured hsm.requiresRole)
|
|
14
|
+
*/
|
|
15
|
+
readonly FORBIDDEN: "ODATANO_FORBIDDEN";
|
|
10
16
|
/**
|
|
11
17
|
* 404 – Data not found
|
|
12
18
|
* Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
|
package/srv/utils/error-codes.js
CHANGED
|
@@ -10,6 +10,12 @@ exports.ERROR_CODES = {
|
|
|
10
10
|
* Indicates that the input provided by the client is invalid (malformed address, invalid transaction hash, etc.)
|
|
11
11
|
*/
|
|
12
12
|
INVALID_INPUT: 'ODATANO_INVALID_INPUT',
|
|
13
|
+
/**
|
|
14
|
+
* 403 – Caller lacks the required role
|
|
15
|
+
* Indicates the caller is authenticated but not authorized for the operation
|
|
16
|
+
* (e.g. HSM-backed signing without the configured hsm.requiresRole)
|
|
17
|
+
*/
|
|
18
|
+
FORBIDDEN: 'ODATANO_FORBIDDEN',
|
|
13
19
|
/**
|
|
14
20
|
* 404 – Data not found
|
|
15
21
|
* Indicates that the requested resource could not be found (Empty result set Address with no UTxOs, Transaction hash not found, etc.)
|
package/srv/utils/errors.d.ts
CHANGED
|
@@ -151,6 +151,16 @@ export declare class AllBackendsFailedError extends BackendError {
|
|
|
151
151
|
*/
|
|
152
152
|
constructor(errors: BackendError[], originalError?: unknown);
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* True when the error proves the resource is absent on EVERY backend that was
|
|
156
|
+
* consulted: either a direct NotFoundError, or an AllBackendsFailedError whose
|
|
157
|
+
* collected per-backend errors are all 404s. CardanoClient's failover wraps
|
|
158
|
+
* per-backend errors (including 404s) into AllBackendsFailedError, so callers
|
|
159
|
+
* that need "definitively not found" (e.g. the wallet-worker's dropped-tx
|
|
160
|
+
* detection) must use this instead of `instanceof NotFoundError`. A mixed
|
|
161
|
+
* result (one backend 404, another 500) is NOT proof of absence.
|
|
162
|
+
*/
|
|
163
|
+
export declare function isNotFoundOnAllBackends(err: unknown): boolean;
|
|
154
164
|
/**
|
|
155
165
|
* HttpErrorLike - Simplified interface for HTTP errors from various libraries
|
|
156
166
|
*/
|
|
@@ -169,6 +179,8 @@ export interface HttpErrorLike {
|
|
|
169
179
|
};
|
|
170
180
|
[k: string]: unknown;
|
|
171
181
|
}
|
|
182
|
+
/** True when a PostgREST error body's `code` denotes a provider-side SQL fault. */
|
|
183
|
+
export declare function isPostgrestServerErrorCode(code: unknown): boolean;
|
|
172
184
|
/**
|
|
173
185
|
* Utility functions to extract status and message from HttpErrorLike
|
|
174
186
|
* @param err error object
|
package/srv/utils/errors.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
|
|
4
|
+
exports.isNotFoundOnAllBackends = isNotFoundOnAllBackends;
|
|
5
|
+
exports.isPostgrestServerErrorCode = isPostgrestServerErrorCode;
|
|
4
6
|
exports.getErrorStatus = getErrorStatus;
|
|
5
7
|
exports.getErrorMessage = getErrorMessage;
|
|
6
8
|
exports.normalizeBackendError = normalizeBackendError;
|
|
@@ -217,6 +219,38 @@ class AllBackendsFailedError extends BackendError {
|
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
exports.AllBackendsFailedError = AllBackendsFailedError;
|
|
222
|
+
/**
|
|
223
|
+
* True when the error proves the resource is absent on EVERY backend that was
|
|
224
|
+
* consulted: either a direct NotFoundError, or an AllBackendsFailedError whose
|
|
225
|
+
* collected per-backend errors are all 404s. CardanoClient's failover wraps
|
|
226
|
+
* per-backend errors (including 404s) into AllBackendsFailedError, so callers
|
|
227
|
+
* that need "definitively not found" (e.g. the wallet-worker's dropped-tx
|
|
228
|
+
* detection) must use this instead of `instanceof NotFoundError`. A mixed
|
|
229
|
+
* result (one backend 404, another 500) is NOT proof of absence.
|
|
230
|
+
*/
|
|
231
|
+
function isNotFoundOnAllBackends(err) {
|
|
232
|
+
if (err instanceof NotFoundError)
|
|
233
|
+
return true;
|
|
234
|
+
return err instanceof AllBackendsFailedError
|
|
235
|
+
&& err.errors.length > 0
|
|
236
|
+
&& err.errors.every((e) => e instanceof NotFoundError || e.statusCode === 404);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* PostgreSQL error-code classes that indicate a fault in the provider's own
|
|
240
|
+
* database/deployment rather than in our request. Koios (PostgREST) surfaces
|
|
241
|
+
* these as HTTP 400 — e.g. code '42703' ("column … does not exist") from a
|
|
242
|
+
* half-migrated SQL function on one load-balanced instance, or '57014'
|
|
243
|
+
* (statement timeout) under load. Client-input errors (class 22, invalid text
|
|
244
|
+
* representation etc.) are deliberately NOT listed — those remain 4xx.
|
|
245
|
+
* Classes: 08 connection, 42 syntax/undefined object, 53 insufficient
|
|
246
|
+
* resources, 57 operator intervention (incl. query_canceled), 58 system
|
|
247
|
+
* error, XX internal error.
|
|
248
|
+
*/
|
|
249
|
+
const PG_SERVER_ERROR_CODE_CLASSES = ['08', '42', '53', '57', '58', 'XX'];
|
|
250
|
+
/** True when a PostgREST error body's `code` denotes a provider-side SQL fault. */
|
|
251
|
+
function isPostgrestServerErrorCode(code) {
|
|
252
|
+
return typeof code === 'string' && PG_SERVER_ERROR_CODE_CLASSES.some(c => code.startsWith(c));
|
|
253
|
+
}
|
|
220
254
|
/**
|
|
221
255
|
* Utility functions to extract status and message from HttpErrorLike
|
|
222
256
|
* @param err error object
|
|
@@ -326,6 +360,17 @@ function normalizeBackendError(err, backendName) {
|
|
|
326
360
|
if (validationErrorHints.some(h => messageLower.includes(h))) {
|
|
327
361
|
return new TransactionValidationError(`Transaction validation failed: ${message}`, err);
|
|
328
362
|
}
|
|
363
|
+
// Priority 3b: PostgREST server-side SQL faults surfaced as HTTP 400 (Koios).
|
|
364
|
+
// Body shape: { code: '42703', message: 'column … does not exist' } (broken
|
|
365
|
+
// SQL function on one LB instance) or { code: '57014' } (statement timeout).
|
|
366
|
+
// These are provider faults, not request validation — classify as retry-able
|
|
367
|
+
// 503 so multi-backend failover and the circuit breaker treat them like any
|
|
368
|
+
// other provider outage. Checked before Priority 4: the PostgREST message
|
|
369
|
+
// ("column … does not exist") would otherwise be misread as a resource 404.
|
|
370
|
+
const pgErrorBody = err?.response?.data;
|
|
371
|
+
if ((status === 400 || status === 422) && isPostgrestServerErrorCode(pgErrorBody?.code)) {
|
|
372
|
+
return new ProviderUnavailableError(`Provider database error (${pgErrorBody?.code}): ${pgErrorBody?.message ?? message}`, backendName, undefined, err);
|
|
373
|
+
}
|
|
329
374
|
// Priority 4: Message indicates "not found" or equivalent → always 404.
|
|
330
375
|
// This also handles providers returning wrong status codes for missing
|
|
331
376
|
// resources. Deliberately NOT here: 'not available' / bare 'no data' — those
|
package/srv/utils/mappers.js
CHANGED
|
@@ -36,6 +36,7 @@ exports.scriptHashToEnterpriseAddress = scriptHashToEnterpriseAddress;
|
|
|
36
36
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
37
37
|
const blake2b_1 = __importDefault(require("blake2b"));
|
|
38
38
|
const bech32_1 = require("bech32");
|
|
39
|
+
const client_1 = require("@cardano-ogmios/client");
|
|
39
40
|
const cardano_costmodels_ts_1 = require("@harmoniclabs/cardano-costmodels-ts");
|
|
40
41
|
const logger = cds_1.default.log('mappers');
|
|
41
42
|
const errors_1 = require("./errors");
|
|
@@ -50,7 +51,9 @@ const errors_1 = require("./errors");
|
|
|
50
51
|
*/
|
|
51
52
|
function mapTransaction(providerTx) {
|
|
52
53
|
// determine presence of optional data
|
|
53
|
-
|
|
54
|
+
// length check matters: the Ogmios chain-sync mapper produced `[]` for metadata-less
|
|
55
|
+
// txs, which the old `Array.isArray` test counted as "has metadata"
|
|
56
|
+
const hasMetadata = Array.isArray(providerTx.metadata) && providerTx.metadata.length > 0;
|
|
54
57
|
const hasInputs = Array.isArray(providerTx.inputs) && providerTx.inputs.length > 0;
|
|
55
58
|
const hasOutputs = Array.isArray(providerTx.outputs) && providerTx.outputs.length > 0;
|
|
56
59
|
return {
|
|
@@ -86,7 +89,9 @@ function mapTransactionInputs(txHash, txInputs) {
|
|
|
86
89
|
return {
|
|
87
90
|
tx_hash: txHash,
|
|
88
91
|
inputIndex: inputIndex,
|
|
89
|
-
|
|
92
|
+
// `|| null`: unresolved chain-sync inputs carry '' — persist a null FK, not a
|
|
93
|
+
// dangling empty-string Addresses association (lazy-path inputs are never empty)
|
|
94
|
+
address_address: input.address || null,
|
|
90
95
|
utxoData_dataHash: input.dataHash || null,
|
|
91
96
|
utxoData_inlineDatum: input.inlineDatum || null,
|
|
92
97
|
utxoData_referenceScriptHash: input.referenceScriptHash || null,
|
|
@@ -420,6 +425,8 @@ function mapBlock(providerBlockData, epochData) {
|
|
|
420
425
|
slotLeader: providerBlockData.slotLeader ?? null,
|
|
421
426
|
epochNumber: epochData?.epoch ?? providerBlockData.epoch,
|
|
422
427
|
epoch: epochData,
|
|
428
|
+
// absolute slot — the crawler's reorg cut axis (same axis as Transactions.slot)
|
|
429
|
+
slot: providerBlockData.slot ?? null,
|
|
423
430
|
epochSlot: providerBlockData.epochSlot,
|
|
424
431
|
size: providerBlockData.size,
|
|
425
432
|
txCount: providerBlockData.txCount,
|
|
@@ -465,7 +472,10 @@ function mapTransactionMetadata(providerLabels) {
|
|
|
465
472
|
id: numericId,
|
|
466
473
|
tx_hash: lbl.txHash,
|
|
467
474
|
label: lbl.label.toString(),
|
|
468
|
-
|
|
475
|
+
// Ogmios' parser deliberately exposes numeric metadata as native bigint.
|
|
476
|
+
// Its matching serializer writes those values as exact JSON number tokens;
|
|
477
|
+
// native JSON.stringify would throw, while Number coercion would truncate.
|
|
478
|
+
payload: lbl.json !== undefined ? client_1.safeJSON.stringify(lbl.json) : null,
|
|
469
479
|
});
|
|
470
480
|
}
|
|
471
481
|
return rows;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirror an internal notification onto a CAP service as a declared event, so
|
|
3
|
+
* consumers can subscribe instead of polling:
|
|
4
|
+
*
|
|
5
|
+
* const worker = await cds.connect.to('CardanoWorkerService');
|
|
6
|
+
* worker.on('jobConfirmed', ({ data }) => …);
|
|
7
|
+
*
|
|
8
|
+
* ODATANO ships as a CAP plugin, so a consumer runs in the SAME process — these
|
|
9
|
+
* events therefore need no broker and no `cds.requires.messaging`. Configuring a
|
|
10
|
+
* messaging service later routes the very same emits through it (with the CAP
|
|
11
|
+
* outbox) without a change here.
|
|
12
|
+
*
|
|
13
|
+
* Three properties this helper guarantees, because every caller is a background
|
|
14
|
+
* loop that must not be disturbed by an observer:
|
|
15
|
+
* - **Never throws.** A missing service, a rejected emit or a broken subscriber
|
|
16
|
+
* is logged and swallowed; the crawler/worker carries on.
|
|
17
|
+
* - **Never blocks.** Emission is fire-and-forget; a slow subscriber cannot stall
|
|
18
|
+
* block ingestion.
|
|
19
|
+
* - **Silent when unserved.** In unit tests and before CAP's `served` phase the
|
|
20
|
+
* service simply does not exist yet — that is normal, not an error.
|
|
21
|
+
*
|
|
22
|
+
* Call sites must emit AFTER their transaction commits: an event that names data
|
|
23
|
+
* a subscriber cannot read yet is worse than no event.
|
|
24
|
+
*/
|
|
25
|
+
export declare function emitServiceEvent(serviceName: string, event: string, data: Record<string, unknown>): void;
|
|
26
|
+
//# sourceMappingURL=service-events.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.emitServiceEvent = emitServiceEvent;
|
|
7
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
|
+
const logger = cds_1.default.log('ServiceEvents');
|
|
9
|
+
/**
|
|
10
|
+
* Mirror an internal notification onto a CAP service as a declared event, so
|
|
11
|
+
* consumers can subscribe instead of polling:
|
|
12
|
+
*
|
|
13
|
+
* const worker = await cds.connect.to('CardanoWorkerService');
|
|
14
|
+
* worker.on('jobConfirmed', ({ data }) => …);
|
|
15
|
+
*
|
|
16
|
+
* ODATANO ships as a CAP plugin, so a consumer runs in the SAME process — these
|
|
17
|
+
* events therefore need no broker and no `cds.requires.messaging`. Configuring a
|
|
18
|
+
* messaging service later routes the very same emits through it (with the CAP
|
|
19
|
+
* outbox) without a change here.
|
|
20
|
+
*
|
|
21
|
+
* Three properties this helper guarantees, because every caller is a background
|
|
22
|
+
* loop that must not be disturbed by an observer:
|
|
23
|
+
* - **Never throws.** A missing service, a rejected emit or a broken subscriber
|
|
24
|
+
* is logged and swallowed; the crawler/worker carries on.
|
|
25
|
+
* - **Never blocks.** Emission is fire-and-forget; a slow subscriber cannot stall
|
|
26
|
+
* block ingestion.
|
|
27
|
+
* - **Silent when unserved.** In unit tests and before CAP's `served` phase the
|
|
28
|
+
* service simply does not exist yet — that is normal, not an error.
|
|
29
|
+
*
|
|
30
|
+
* Call sites must emit AFTER their transaction commits: an event that names data
|
|
31
|
+
* a subscriber cannot read yet is worse than no event.
|
|
32
|
+
*/
|
|
33
|
+
function emitServiceEvent(serviceName, event, data) {
|
|
34
|
+
const srv = cds_1.default.services?.[serviceName];
|
|
35
|
+
if (!srv?.emit)
|
|
36
|
+
return; // not served (unit tests, standalone boot) — nothing to notify
|
|
37
|
+
try {
|
|
38
|
+
void Promise.resolve(srv.emit(event, data)).catch((err) => {
|
|
39
|
+
logger.warn(`${serviceName}.${event} subscriber failed (ignored):`, err);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
logger.warn(`${serviceName}.${event} could not be emitted (ignored):`, err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=service-events.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { JSONValue } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Shared parsers for the Build*-action JSON payload fields. Used by the
|
|
4
|
+
* synchronous CardanoTransactionService handlers AND the wallet-worker's
|
|
5
|
+
* request transformation (srv/blockchain/wallet-worker/build-request.ts) so
|
|
6
|
+
* both paths accept exactly the same payload shape.
|
|
7
|
+
*
|
|
8
|
+
* Result contract: { parsed } on success (undefined for absent/empty input →
|
|
9
|
+
* no-op) or { error } with a caller-presentable message.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseUtxoRefArray(json: string | undefined, fieldName: 'forceInputsJson' | 'referenceInputsJson'): {
|
|
12
|
+
parsed?: Array<{
|
|
13
|
+
txHash: string;
|
|
14
|
+
outputIndex: number;
|
|
15
|
+
}>;
|
|
16
|
+
error?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Parse and validate requiredSignersJson (array of 56-hex Ed25519 key hashes).
|
|
20
|
+
* Same result contract as the other parse* helpers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseRequiredSigners(requiredSignersJson: string | undefined): {
|
|
23
|
+
parsed?: string[];
|
|
24
|
+
error?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Parse and validate an assetsJson array ({unit, quantity} entries) with the same
|
|
28
|
+
* per-entry strictness as parseExtraOutputs — unchecked entries previously flowed
|
|
29
|
+
* into the builder and surfaced as 500s.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseAssetsArray(assetsJson: string | undefined, fieldName: string): {
|
|
32
|
+
parsed?: Array<{
|
|
33
|
+
unit: string;
|
|
34
|
+
quantity: string;
|
|
35
|
+
}>;
|
|
36
|
+
error?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Upper bound on extra outputs per transaction (defence against tx-size blow-up). */
|
|
39
|
+
export declare const MAX_EXTRA_OUTPUTS = 32;
|
|
40
|
+
export interface ParsedExtraOutput {
|
|
41
|
+
address: string;
|
|
42
|
+
lovelaceAmount: string;
|
|
43
|
+
assets?: Array<{
|
|
44
|
+
unit: string;
|
|
45
|
+
quantity: string;
|
|
46
|
+
}>;
|
|
47
|
+
inlineDatum?: JSONValue;
|
|
48
|
+
referenceScript?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse and validate extraOutputsJson. Returns { parsed } on success (possibly undefined
|
|
52
|
+
* for empty array → no-op) or { error } on validation failure.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseExtraOutputs(extraOutputsJson: string | undefined): {
|
|
55
|
+
parsed?: ParsedExtraOutput[];
|
|
56
|
+
error?: string;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=tx-request-parsers.d.ts.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
4
|
+
exports.parseUtxoRefArray = parseUtxoRefArray;
|
|
5
|
+
exports.parseRequiredSigners = parseRequiredSigners;
|
|
6
|
+
exports.parseAssetsArray = parseAssetsArray;
|
|
7
|
+
exports.parseExtraOutputs = parseExtraOutputs;
|
|
8
|
+
const validators_1 = require("./validators");
|
|
9
|
+
/**
|
|
10
|
+
* Shared parsers for the Build*-action JSON payload fields. Used by the
|
|
11
|
+
* synchronous CardanoTransactionService handlers AND the wallet-worker's
|
|
12
|
+
* request transformation (srv/blockchain/wallet-worker/build-request.ts) so
|
|
13
|
+
* both paths accept exactly the same payload shape.
|
|
14
|
+
*
|
|
15
|
+
* Result contract: { parsed } on success (undefined for absent/empty input →
|
|
16
|
+
* no-op) or { error } with a caller-presentable message.
|
|
17
|
+
*/
|
|
18
|
+
function parseUtxoRefArray(json, fieldName) {
|
|
19
|
+
if (!json)
|
|
20
|
+
return { parsed: undefined };
|
|
21
|
+
const entryName = fieldName.replace(/Json$/, '');
|
|
22
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, fieldName);
|
|
23
|
+
if (!jsonResult.valid)
|
|
24
|
+
return { error: jsonResult.error };
|
|
25
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
26
|
+
return { error: `${fieldName} must be a JSON array` };
|
|
27
|
+
if (jsonResult.parsed.length === 0)
|
|
28
|
+
return { parsed: undefined };
|
|
29
|
+
const refs = [];
|
|
30
|
+
for (const rawEntry of jsonResult.parsed) {
|
|
31
|
+
if (!rawEntry || typeof rawEntry !== 'object') {
|
|
32
|
+
return { error: `Each ${entryName} entry must be an object with txHash and outputIndex` };
|
|
33
|
+
}
|
|
34
|
+
const entry = rawEntry;
|
|
35
|
+
if (typeof entry.txHash !== 'string' || !(0, validators_1.isTxHash)(entry.txHash)) {
|
|
36
|
+
return { error: `Each ${entryName} entry must have a valid 64-hex txHash` };
|
|
37
|
+
}
|
|
38
|
+
const idx = entry.outputIndex;
|
|
39
|
+
if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0) {
|
|
40
|
+
return { error: `Each ${entryName} entry must have a non-negative integer outputIndex` };
|
|
41
|
+
}
|
|
42
|
+
refs.push({ txHash: entry.txHash, outputIndex: idx });
|
|
43
|
+
}
|
|
44
|
+
return { parsed: refs };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse and validate requiredSignersJson (array of 56-hex Ed25519 key hashes).
|
|
48
|
+
* Same result contract as the other parse* helpers.
|
|
49
|
+
*/
|
|
50
|
+
function parseRequiredSigners(requiredSignersJson) {
|
|
51
|
+
if (!requiredSignersJson)
|
|
52
|
+
return { parsed: undefined };
|
|
53
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(requiredSignersJson, 'requiredSignersJson');
|
|
54
|
+
if (!jsonResult.valid)
|
|
55
|
+
return { error: jsonResult.error };
|
|
56
|
+
try {
|
|
57
|
+
return { parsed: (0, validators_1.validateRequiredSigners)(jsonResult.parsed) };
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse and validate an assetsJson array ({unit, quantity} entries) with the same
|
|
65
|
+
* per-entry strictness as parseExtraOutputs — unchecked entries previously flowed
|
|
66
|
+
* into the builder and surfaced as 500s.
|
|
67
|
+
*/
|
|
68
|
+
function parseAssetsArray(assetsJson, fieldName) {
|
|
69
|
+
if (!assetsJson)
|
|
70
|
+
return { parsed: undefined };
|
|
71
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(assetsJson, fieldName);
|
|
72
|
+
if (!jsonResult.valid)
|
|
73
|
+
return { error: jsonResult.error };
|
|
74
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
75
|
+
return { error: `${fieldName} must be a JSON array` };
|
|
76
|
+
const out = [];
|
|
77
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
78
|
+
const a = jsonResult.parsed[i];
|
|
79
|
+
if (!a || typeof a !== 'object') {
|
|
80
|
+
return { error: `${fieldName}[${i}] must be an object` };
|
|
81
|
+
}
|
|
82
|
+
if (typeof a.unit !== 'string' || a.unit.toLowerCase() === 'lovelace' || !(0, validators_1.isAssetUnit)(a.unit)) {
|
|
83
|
+
return { error: `${fieldName}[${i}].unit must be a valid asset unit (policyId + assetName hex)` };
|
|
84
|
+
}
|
|
85
|
+
if (typeof a.quantity !== 'string' || !/^\d+$/.test(a.quantity) || a.quantity === '0') {
|
|
86
|
+
return { error: `${fieldName}[${i}].quantity must be a positive integer string` };
|
|
87
|
+
}
|
|
88
|
+
out.push({ unit: a.unit, quantity: a.quantity });
|
|
89
|
+
}
|
|
90
|
+
return { parsed: out };
|
|
91
|
+
}
|
|
92
|
+
/** Upper bound on extra outputs per transaction (defence against tx-size blow-up). */
|
|
93
|
+
exports.MAX_EXTRA_OUTPUTS = 32;
|
|
94
|
+
/**
|
|
95
|
+
* Parse and validate extraOutputsJson. Returns { parsed } on success (possibly undefined
|
|
96
|
+
* for empty array → no-op) or { error } on validation failure.
|
|
97
|
+
*/
|
|
98
|
+
function parseExtraOutputs(extraOutputsJson) {
|
|
99
|
+
if (!extraOutputsJson)
|
|
100
|
+
return { parsed: undefined };
|
|
101
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(extraOutputsJson, 'extraOutputsJson');
|
|
102
|
+
if (!jsonResult.valid)
|
|
103
|
+
return { error: jsonResult.error };
|
|
104
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
105
|
+
return { error: 'extraOutputsJson must be a JSON array' };
|
|
106
|
+
if (jsonResult.parsed.length === 0)
|
|
107
|
+
return { parsed: undefined };
|
|
108
|
+
if (jsonResult.parsed.length > exports.MAX_EXTRA_OUTPUTS) {
|
|
109
|
+
return { error: `extraOutputsJson exceeds maximum of ${exports.MAX_EXTRA_OUTPUTS} entries` };
|
|
110
|
+
}
|
|
111
|
+
const out = [];
|
|
112
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
113
|
+
const entry = jsonResult.parsed[i];
|
|
114
|
+
if (!entry || typeof entry !== 'object') {
|
|
115
|
+
return { error: `extraOutputs[${i}] must be an object` };
|
|
116
|
+
}
|
|
117
|
+
if (typeof entry.address !== 'string' || !(0, validators_1.isValidBech32Address)(entry.address)) {
|
|
118
|
+
return { error: `extraOutputs[${i}].address is not a valid Bech32 address` };
|
|
119
|
+
}
|
|
120
|
+
if (typeof entry.lovelaceAmount !== 'string' || !/^\d+$/.test(entry.lovelaceAmount) || entry.lovelaceAmount === '0') {
|
|
121
|
+
return { error: `extraOutputs[${i}].lovelaceAmount must be a positive integer string` };
|
|
122
|
+
}
|
|
123
|
+
let assets;
|
|
124
|
+
if (entry.assets !== undefined && entry.assets !== null) {
|
|
125
|
+
if (!Array.isArray(entry.assets)) {
|
|
126
|
+
return { error: `extraOutputs[${i}].assets must be an array` };
|
|
127
|
+
}
|
|
128
|
+
assets = [];
|
|
129
|
+
for (let j = 0; j < entry.assets.length; j++) {
|
|
130
|
+
const a = entry.assets[j];
|
|
131
|
+
if (!a || typeof a !== 'object') {
|
|
132
|
+
return { error: `extraOutputs[${i}].assets[${j}] must be an object` };
|
|
133
|
+
}
|
|
134
|
+
if (typeof a.unit !== 'string' || a.unit.toLowerCase() === 'lovelace' || !(0, validators_1.isAssetUnit)(a.unit)) {
|
|
135
|
+
return { error: `extraOutputs[${i}].assets[${j}].unit must be a valid asset unit (policyId + assetName hex)` };
|
|
136
|
+
}
|
|
137
|
+
if (typeof a.quantity !== 'string' || !/^\d+$/.test(a.quantity) || a.quantity === '0') {
|
|
138
|
+
return { error: `extraOutputs[${i}].assets[${j}].quantity must be a positive integer string` };
|
|
139
|
+
}
|
|
140
|
+
assets.push({ unit: a.unit, quantity: a.quantity });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let inlineDatum;
|
|
144
|
+
if (entry.inlineDatumJson !== undefined && entry.inlineDatumJson !== null) {
|
|
145
|
+
if (typeof entry.inlineDatumJson !== 'string') {
|
|
146
|
+
return { error: `extraOutputs[${i}].inlineDatumJson must be a JSON string` };
|
|
147
|
+
}
|
|
148
|
+
const datumResult = (0, validators_1.validateJsonWithLimits)(entry.inlineDatumJson, `extraOutputs[${i}].inlineDatumJson`);
|
|
149
|
+
if (!datumResult.valid)
|
|
150
|
+
return { error: datumResult.error };
|
|
151
|
+
inlineDatum = datumResult.parsed;
|
|
152
|
+
}
|
|
153
|
+
let referenceScript;
|
|
154
|
+
if (entry.referenceScriptHex !== undefined && entry.referenceScriptHex !== null) {
|
|
155
|
+
if (typeof entry.referenceScriptHex !== 'string' || !(0, validators_1.isValidCbor)(entry.referenceScriptHex)) {
|
|
156
|
+
return { error: `extraOutputs[${i}].referenceScriptHex must be even-length hex` };
|
|
157
|
+
}
|
|
158
|
+
referenceScript = entry.referenceScriptHex;
|
|
159
|
+
}
|
|
160
|
+
out.push({
|
|
161
|
+
address: entry.address,
|
|
162
|
+
lovelaceAmount: entry.lovelaceAmount,
|
|
163
|
+
assets,
|
|
164
|
+
inlineDatum,
|
|
165
|
+
referenceScript,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return { parsed: out };
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=tx-request-parsers.js.map
|
package/srv/utils/tx-utils.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export declare const DETACHED_TX_TIMEOUT_MS = 10000;
|
|
|
5
5
|
* Run `fn` with `cds.context` cleared, so any `db.run(...)` inside it gets a
|
|
6
6
|
* fresh short-lived transaction instead of joining a long-lived ambient one.
|
|
7
7
|
* Under @cap-js/sqlite (pool.max=1) this is what keeps the single pooled
|
|
8
|
-
* connection free during long awaits (
|
|
8
|
+
* connection free during long awaits (NIGHTGATE lesson 2; used by the
|
|
9
|
+
* wallet-worker job loops).
|
|
9
10
|
*/
|
|
10
11
|
export declare function runWithoutAmbientTx<T>(fn: () => Promise<T>): Promise<T>;
|
|
11
12
|
/**
|
package/srv/utils/tx-utils.js
CHANGED
|
@@ -10,7 +10,7 @@ const cds_1 = __importDefault(require("@sap/cds"));
|
|
|
10
10
|
const errors_1 = require("./errors");
|
|
11
11
|
const error_codes_1 = require("./error-codes");
|
|
12
12
|
/**
|
|
13
|
-
* Transaction utilities
|
|
13
|
+
* Transaction utilities shared by the sign-service and the background workers.
|
|
14
14
|
*
|
|
15
15
|
* Context: @cap-js/sqlite runs on a SINGLE pooled connection. A request
|
|
16
16
|
* transaction begins lazily on its first CQL statement and holds that
|
|
@@ -31,7 +31,8 @@ function effectiveTimeoutMs() {
|
|
|
31
31
|
* Run `fn` with `cds.context` cleared, so any `db.run(...)` inside it gets a
|
|
32
32
|
* fresh short-lived transaction instead of joining a long-lived ambient one.
|
|
33
33
|
* Under @cap-js/sqlite (pool.max=1) this is what keeps the single pooled
|
|
34
|
-
* connection free during long awaits (
|
|
34
|
+
* connection free during long awaits (NIGHTGATE lesson 2; used by the
|
|
35
|
+
* wallet-worker job loops).
|
|
35
36
|
*/
|
|
36
37
|
function runWithoutAmbientTx(fn) {
|
|
37
38
|
return cds_1.default._with(undefined, fn);
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -60,7 +60,8 @@ export interface Transaction {
|
|
|
60
60
|
index: number;
|
|
61
61
|
fee: Lovelace | string;
|
|
62
62
|
deposit: Lovelace | string;
|
|
63
|
-
size
|
|
63
|
+
/** Tx size in bytes; null when the source cannot provide it (Ogmios chain-sync). */
|
|
64
|
+
size: number | null;
|
|
64
65
|
blockTime: number;
|
|
65
66
|
outputAmount?: Amount[];
|
|
66
67
|
inputs: TxInputLine[];
|