@odatano/core 2.0.0-rc.5 → 2.0.0-rc.50
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 +347 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
- package/@cds-models/CardanoIndexerService/index.js +64 -0
- package/@cds-models/CardanoODataService/index.d.ts +414 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +32 -19
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
- package/@cds-models/index.d.ts +101 -1
- package/@cds-models/index.js +16 -1
- package/@cds-models/odatano/cardano/index.d.ts +437 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +207 -167
- package/db/schema.cds +2402 -1705
- package/db/types.cds +446 -295
- package/package.json +41 -16
- package/scripts/migrate-schema.mjs +334 -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 -135
- package/srv/blockchain/backends/blockfrost-backend.js +66 -172
- package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +103 -168
- package/srv/blockchain/backends/koios-backend.js +428 -360
- package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
- package/srv/blockchain/backends/odatano-backend.js +169 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
- package/srv/blockchain/backends/ogmios-backend.js +637 -315
- 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 +61 -241
- package/srv/blockchain/cardano-client.js +253 -293
- package/srv/blockchain/cardano-indexer.d.ts +282 -281
- package/srv/blockchain/cardano-indexer.js +1551 -484
- 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 +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/certificate-backfill.js +162 -0
- package/srv/blockchain/crawler/crawler.d.ts +104 -81
- package/srv/blockchain/crawler/crawler.js +532 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
- package/srv/blockchain/crawler/credential-backfill.js +124 -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 +171 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
- package/srv/blockchain/crawler/sync-state.d.ts +27 -47
- package/srv/blockchain/crawler/sync-state.js +113 -63
- package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
- package/srv/blockchain/crawler/transaction-backfill.js +278 -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/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +419 -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 +17 -126
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +70 -83
- package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
- package/srv/blockchain/signing/submission-finalizer.js +219 -86
- package/srv/blockchain/stored-chain.d.ts +20 -0
- package/srv/blockchain/stored-chain.js +237 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +5 -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 +5 -20
- package/srv/blockchain/wallet-worker/build-request.js +47 -30
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
- package/srv/blockchain/wallet-worker/job-store.js +101 -201
- 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 +8 -80
- package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +4 -9
- package/srv/cardano-backend-service.cds +78 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +242 -0
- package/srv/cardano-indexer-service.cds +387 -73
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +532 -16
- package/srv/cardano-service.cds +424 -269
- package/srv/cardano-service.js +289 -201
- package/srv/cardano-sign-service.cds +201 -180
- package/srv/cardano-sign-service.js +71 -201
- package/srv/cardano-tx-service.cds +451 -370
- package/srv/cardano-tx-service.js +271 -289
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +118 -125
- package/srv/cardano-worker-service.js +52 -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 +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +84 -404
- package/srv/utils/agent-access.d.ts +9 -0
- package/srv/utils/agent-access.js +67 -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 -236
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +18 -182
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +3 -10
- package/srv/utils/collections.js +3 -10
- package/srv/utils/const.d.ts +23 -74
- package/srv/utils/const.js +32 -79
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +6 -21
- package/srv/utils/db-indexes.d.ts +27 -0
- package/srv/utils/db-indexes.js +120 -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/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +38 -0
- package/srv/utils/error-codes.d.ts +22 -75
- package/srv/utils/error-codes.js +23 -72
- package/srv/utils/errors.d.ts +46 -187
- package/srv/utils/errors.js +114 -230
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +102 -223
- package/srv/utils/mappers.js +387 -316
- package/srv/utils/network-context.js +2 -13
- 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/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -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 +10 -105
- package/srv/utils/tx-build-helper.js +81 -144
- 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 +261 -191
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +50 -149
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
3
|
+
exports.MAX_CERTIFICATES = exports.MAX_WITHDRAWALS = exports.MAX_SCRIPT_INPUTS = exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
4
|
+
exports.parsePlutusCbor = parsePlutusCbor;
|
|
4
5
|
exports.parseUtxoRefArray = parseUtxoRefArray;
|
|
5
6
|
exports.parseRequiredSigners = parseRequiredSigners;
|
|
6
7
|
exports.parseAssetsArray = parseAssetsArray;
|
|
7
8
|
exports.parseExtraOutputs = parseExtraOutputs;
|
|
9
|
+
exports.parseOutputList = parseOutputList;
|
|
8
10
|
exports.parseMintActionPolicyFields = parseMintActionPolicyFields;
|
|
11
|
+
exports.parseScriptInputs = parseScriptInputs;
|
|
12
|
+
exports.parseWithdrawals = parseWithdrawals;
|
|
13
|
+
exports.parseCertificates = parseCertificates;
|
|
14
|
+
exports.parsePolicyMintActions = parsePolicyMintActions;
|
|
9
15
|
const validators_1 = require("./validators");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
17
|
+
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
18
|
+
const const_1 = require("./const");
|
|
19
|
+
// Parsers for the JSON fields of the Build actions, shared with the wallet worker.
|
|
20
|
+
// Each returns `{ parsed }`, undefined for empty input, or `{ error }` with a client message.
|
|
21
|
+
/** PlutusData as CBOR hex, checked to decode; `field` names it in the error. */
|
|
22
|
+
function parsePlutusCbor(value, field) {
|
|
23
|
+
if (typeof value !== 'string' || !(0, validators_1.isValidCbor)(value))
|
|
24
|
+
return { error: `${field} must be even-length CBOR hex` };
|
|
25
|
+
try {
|
|
26
|
+
(0, plutus_data_1.dataFromCbor)(value);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return { error: `${field} is not PlutusData CBOR: ${err instanceof Error ? err.message : String(err)}` };
|
|
30
|
+
}
|
|
31
|
+
return { hex: value.toLowerCase() };
|
|
32
|
+
}
|
|
19
33
|
function parseUtxoRefArray(json, fieldName) {
|
|
20
34
|
if (!json)
|
|
21
35
|
return { parsed: undefined };
|
|
@@ -44,10 +58,7 @@ function parseUtxoRefArray(json, fieldName) {
|
|
|
44
58
|
}
|
|
45
59
|
return { parsed: refs };
|
|
46
60
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Parse and validate requiredSignersJson (array of 56-hex Ed25519 key hashes).
|
|
49
|
-
* Same result contract as the other parse* helpers.
|
|
50
|
-
*/
|
|
61
|
+
/** Parse and validate requiredSignersJson (array of 56-hex Ed25519 key hashes). */
|
|
51
62
|
function parseRequiredSigners(requiredSignersJson) {
|
|
52
63
|
if (!requiredSignersJson)
|
|
53
64
|
return { parsed: undefined };
|
|
@@ -61,11 +72,7 @@ function parseRequiredSigners(requiredSignersJson) {
|
|
|
61
72
|
return { error: err instanceof Error ? err.message : String(err) };
|
|
62
73
|
}
|
|
63
74
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Parse and validate an assetsJson array ({unit, quantity} entries) with the same
|
|
66
|
-
* per-entry strictness as parseExtraOutputs — unchecked entries previously flowed
|
|
67
|
-
* into the builder and surfaced as 500s.
|
|
68
|
-
*/
|
|
75
|
+
/** Parse and validate an assetsJson array of `{unit, quantity}` entries. */
|
|
69
76
|
function parseAssetsArray(assetsJson, fieldName) {
|
|
70
77
|
if (!assetsJson)
|
|
71
78
|
return { parsed: undefined };
|
|
@@ -92,51 +99,53 @@ function parseAssetsArray(assetsJson, fieldName) {
|
|
|
92
99
|
}
|
|
93
100
|
/** Upper bound on extra outputs per transaction (defence against tx-size blow-up). */
|
|
94
101
|
exports.MAX_EXTRA_OUTPUTS = 32;
|
|
95
|
-
/**
|
|
96
|
-
* Parse and validate extraOutputsJson. Returns { parsed } on success (possibly undefined
|
|
97
|
-
* for empty array → no-op) or { error } on validation failure.
|
|
98
|
-
*/
|
|
102
|
+
/** Parse and validate extraOutputsJson (undefined for an empty array). */
|
|
99
103
|
function parseExtraOutputs(extraOutputsJson) {
|
|
100
|
-
|
|
104
|
+
return parseOutputList(extraOutputsJson, 'extraOutputsJson');
|
|
105
|
+
}
|
|
106
|
+
/** Entries keep their order. `outputsJson` also accepts `datumHash`. */
|
|
107
|
+
function parseOutputList(json, fieldName, maxEntries = exports.MAX_EXTRA_OUTPUTS) {
|
|
108
|
+
if (!json)
|
|
101
109
|
return { parsed: undefined };
|
|
102
|
-
const
|
|
110
|
+
const name = fieldName.replace(/Json$/, '');
|
|
111
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, fieldName);
|
|
103
112
|
if (!jsonResult.valid)
|
|
104
113
|
return { error: jsonResult.error };
|
|
105
114
|
if (!Array.isArray(jsonResult.parsed))
|
|
106
|
-
return { error:
|
|
115
|
+
return { error: `${fieldName} must be a JSON array` };
|
|
107
116
|
if (jsonResult.parsed.length === 0)
|
|
108
117
|
return { parsed: undefined };
|
|
109
|
-
if (jsonResult.parsed.length >
|
|
110
|
-
return { error:
|
|
118
|
+
if (jsonResult.parsed.length > maxEntries) {
|
|
119
|
+
return { error: `${fieldName} exceeds maximum of ${maxEntries} entries` };
|
|
111
120
|
}
|
|
112
121
|
const out = [];
|
|
113
122
|
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
114
123
|
const entry = jsonResult.parsed[i];
|
|
115
124
|
if (!entry || typeof entry !== 'object') {
|
|
116
|
-
return { error:
|
|
125
|
+
return { error: `${name}[${i}] must be an object` };
|
|
117
126
|
}
|
|
118
127
|
if (typeof entry.address !== 'string' || !(0, validators_1.isValidBech32Address)(entry.address)) {
|
|
119
|
-
return { error:
|
|
128
|
+
return { error: `${name}[${i}].address is not a valid Bech32 address` };
|
|
120
129
|
}
|
|
121
130
|
if (typeof entry.lovelaceAmount !== 'string' || !/^\d+$/.test(entry.lovelaceAmount) || entry.lovelaceAmount === '0') {
|
|
122
|
-
return { error:
|
|
131
|
+
return { error: `${name}[${i}].lovelaceAmount must be a positive integer string` };
|
|
123
132
|
}
|
|
124
133
|
let assets;
|
|
125
134
|
if (entry.assets !== undefined && entry.assets !== null) {
|
|
126
135
|
if (!Array.isArray(entry.assets)) {
|
|
127
|
-
return { error:
|
|
136
|
+
return { error: `${name}[${i}].assets must be an array` };
|
|
128
137
|
}
|
|
129
138
|
assets = [];
|
|
130
139
|
for (let j = 0; j < entry.assets.length; j++) {
|
|
131
140
|
const a = entry.assets[j];
|
|
132
141
|
if (!a || typeof a !== 'object') {
|
|
133
|
-
return { error:
|
|
142
|
+
return { error: `${name}[${i}].assets[${j}] must be an object` };
|
|
134
143
|
}
|
|
135
144
|
if (typeof a.unit !== 'string' || a.unit.toLowerCase() === 'lovelace' || !(0, validators_1.isAssetUnit)(a.unit)) {
|
|
136
|
-
return { error:
|
|
145
|
+
return { error: `${name}[${i}].assets[${j}].unit must be a valid asset unit (policyId + assetName hex)` };
|
|
137
146
|
}
|
|
138
147
|
if (typeof a.quantity !== 'string' || !/^\d+$/.test(a.quantity) || a.quantity === '0') {
|
|
139
|
-
return { error:
|
|
148
|
+
return { error: `${name}[${i}].assets[${j}].quantity must be a positive integer string` };
|
|
140
149
|
}
|
|
141
150
|
assets.push({ unit: a.unit, quantity: a.quantity });
|
|
142
151
|
}
|
|
@@ -144,17 +153,39 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
144
153
|
let inlineDatum;
|
|
145
154
|
if (entry.inlineDatumJson !== undefined && entry.inlineDatumJson !== null) {
|
|
146
155
|
if (typeof entry.inlineDatumJson !== 'string') {
|
|
147
|
-
return { error:
|
|
156
|
+
return { error: `${name}[${i}].inlineDatumJson must be a JSON string` };
|
|
148
157
|
}
|
|
149
|
-
const datumResult = (0, validators_1.
|
|
158
|
+
const datumResult = (0, validators_1.validatePlutusJson)(entry.inlineDatumJson, `${name}[${i}].inlineDatumJson`);
|
|
150
159
|
if (!datumResult.valid)
|
|
151
160
|
return { error: datumResult.error };
|
|
152
161
|
inlineDatum = datumResult.parsed;
|
|
153
162
|
}
|
|
163
|
+
let inlineDatumCbor;
|
|
164
|
+
if (entry.inlineDatumCbor !== undefined && entry.inlineDatumCbor !== null) {
|
|
165
|
+
if (fieldName !== 'outputsJson')
|
|
166
|
+
return { error: `${name}[${i}].inlineDatumCbor is only supported in outputsJson` };
|
|
167
|
+
if (inlineDatum !== undefined)
|
|
168
|
+
return { error: `${name}[${i}] takes inlineDatumJson or inlineDatumCbor, not both` };
|
|
169
|
+
const cbor = parsePlutusCbor(entry.inlineDatumCbor, `${name}[${i}].inlineDatumCbor`);
|
|
170
|
+
if (cbor.error)
|
|
171
|
+
return { error: cbor.error };
|
|
172
|
+
inlineDatumCbor = cbor.hex;
|
|
173
|
+
}
|
|
174
|
+
let datumHash;
|
|
175
|
+
if (entry.datumHash !== undefined && entry.datumHash !== null) {
|
|
176
|
+
if (fieldName !== 'outputsJson')
|
|
177
|
+
return { error: `${name}[${i}].datumHash is only supported in outputsJson` };
|
|
178
|
+
if (typeof entry.datumHash !== 'string' || !/^[0-9a-fA-F]{64}$/.test(entry.datumHash)) {
|
|
179
|
+
return { error: `${name}[${i}].datumHash must be 64 hex chars` };
|
|
180
|
+
}
|
|
181
|
+
if (inlineDatum !== undefined || inlineDatumCbor !== undefined)
|
|
182
|
+
return { error: `${name}[${i}] takes an inline datum or datumHash, not both` };
|
|
183
|
+
datumHash = entry.datumHash.toLowerCase();
|
|
184
|
+
}
|
|
154
185
|
let referenceScript;
|
|
155
186
|
if (entry.referenceScriptHex !== undefined && entry.referenceScriptHex !== null) {
|
|
156
187
|
if (typeof entry.referenceScriptHex !== 'string' || !(0, validators_1.isValidCbor)(entry.referenceScriptHex)) {
|
|
157
|
-
return { error:
|
|
188
|
+
return { error: `${name}[${i}].referenceScriptHex must be even-length hex` };
|
|
158
189
|
}
|
|
159
190
|
referenceScript = entry.referenceScriptHex;
|
|
160
191
|
}
|
|
@@ -163,20 +194,16 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
163
194
|
lovelaceAmount: entry.lovelaceAmount,
|
|
164
195
|
assets,
|
|
165
196
|
inlineDatum,
|
|
197
|
+
...(datumHash ? { datumHash } : {}),
|
|
198
|
+
...(inlineDatumCbor ? { inlineDatumCbor } : {}),
|
|
166
199
|
referenceScript,
|
|
167
200
|
});
|
|
168
201
|
}
|
|
169
202
|
return { parsed: out };
|
|
170
203
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* parameterized per-action script must be pre-applied by the caller) and
|
|
175
|
-
* `redeemerJson` (a JSON-encoded string, same convention as extraOutputs'
|
|
176
|
-
* inlineDatumJson). Absent fields fall back to the action's top-level
|
|
177
|
-
* script/redeemer at build time.
|
|
178
|
-
*/
|
|
179
|
-
function parseMintActionPolicyFields(entry, i) {
|
|
204
|
+
// Optional per-action `mintingPolicyScript` and `redeemerJson` of a mintActionsJson entry.
|
|
205
|
+
// Absent fields fall back to the request's script and redeemer.
|
|
206
|
+
function parseMintActionPolicyFields(entry, i, byReference = false) {
|
|
180
207
|
let script;
|
|
181
208
|
if (entry.mintingPolicyScript !== undefined && entry.mintingPolicyScript !== null) {
|
|
182
209
|
if (typeof entry.mintingPolicyScript !== 'string' || !(0, validators_1.isValidCbor)(entry.mintingPolicyScript)) {
|
|
@@ -189,14 +216,339 @@ function parseMintActionPolicyFields(entry, i) {
|
|
|
189
216
|
if (typeof entry.redeemerJson !== 'string') {
|
|
190
217
|
return { error: `mintActions[${i}].redeemerJson must be a JSON string` };
|
|
191
218
|
}
|
|
192
|
-
const jsonResult = (0, validators_1.
|
|
219
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(entry.redeemerJson, `mintActions[${i}].redeemerJson`);
|
|
193
220
|
if (!jsonResult.valid)
|
|
194
221
|
return { error: jsonResult.error };
|
|
195
222
|
redeemer = jsonResult.parsed;
|
|
196
223
|
}
|
|
197
|
-
if (redeemer !== undefined && script === undefined) {
|
|
224
|
+
if (redeemer !== undefined && script === undefined && !byReference) {
|
|
198
225
|
return { error: `mintActions[${i}].redeemerJson requires mintActions[${i}].mintingPolicyScript` };
|
|
199
226
|
}
|
|
200
227
|
return { script, redeemer };
|
|
201
228
|
}
|
|
229
|
+
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
230
|
+
exports.MAX_SCRIPT_INPUTS = 16;
|
|
231
|
+
/** Parse and validate scriptInputsJson: 0..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
232
|
+
function parseScriptInputs(json) {
|
|
233
|
+
if (!json)
|
|
234
|
+
return { parsed: [] };
|
|
235
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'scriptInputsJson');
|
|
236
|
+
if (!jsonResult.valid)
|
|
237
|
+
return { error: jsonResult.error };
|
|
238
|
+
if (!Array.isArray(jsonResult.parsed)) {
|
|
239
|
+
return { error: 'scriptInputsJson must be a JSON array' };
|
|
240
|
+
}
|
|
241
|
+
if (jsonResult.parsed.length > exports.MAX_SCRIPT_INPUTS) {
|
|
242
|
+
return { error: `scriptInputsJson exceeds maximum of ${exports.MAX_SCRIPT_INPUTS} entries` };
|
|
243
|
+
}
|
|
244
|
+
const parseJsonField = (value, field) => {
|
|
245
|
+
if (typeof value !== 'string')
|
|
246
|
+
return { error: `${field} must be a JSON string` };
|
|
247
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
248
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
249
|
+
};
|
|
250
|
+
const out = [];
|
|
251
|
+
const seen = new Set();
|
|
252
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
253
|
+
const entry = jsonResult.parsed[i];
|
|
254
|
+
const at = `scriptInputs[${i}]`;
|
|
255
|
+
if (!entry || typeof entry !== 'object')
|
|
256
|
+
return { error: `${at} must be an object` };
|
|
257
|
+
if (typeof entry.txHash !== 'string' || !(0, validators_1.isTxHash)(entry.txHash))
|
|
258
|
+
return { error: `${at}.txHash must be 64 hex chars` };
|
|
259
|
+
const idx = entry.outputIndex;
|
|
260
|
+
if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0)
|
|
261
|
+
return { error: `${at}.outputIndex must be a non-negative integer` };
|
|
262
|
+
const key = `${entry.txHash.toLowerCase()}#${idx}`;
|
|
263
|
+
if (seen.has(key))
|
|
264
|
+
return { error: `${at} spends ${key} a second time` };
|
|
265
|
+
seen.add(key);
|
|
266
|
+
const hasInline = entry.validatorScript !== undefined && entry.validatorScript !== null;
|
|
267
|
+
const hasRef = entry.referenceScript !== undefined && entry.referenceScript !== null;
|
|
268
|
+
if (hasInline === hasRef)
|
|
269
|
+
return { error: `${at} needs exactly one of validatorScript or referenceScript` };
|
|
270
|
+
const input = { txHash: entry.txHash.toLowerCase(), outputIndex: idx, redeemer: null };
|
|
271
|
+
if (hasInline) {
|
|
272
|
+
if (typeof entry.validatorScript !== 'string' || !(0, validators_1.isValidCbor)(entry.validatorScript)) {
|
|
273
|
+
return { error: `${at}.validatorScript must be even-length CBOR hex` };
|
|
274
|
+
}
|
|
275
|
+
input.validatorScript = entry.validatorScript;
|
|
276
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
277
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
278
|
+
if (params.error)
|
|
279
|
+
return { error: params.error };
|
|
280
|
+
if (!Array.isArray(params.parsed))
|
|
281
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
282
|
+
if (params.parsed.length > 0)
|
|
283
|
+
input.scriptParams = params.parsed;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const ref = entry.referenceScript;
|
|
288
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
289
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
290
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
291
|
+
}
|
|
292
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
293
|
+
return { error: `${at}.scriptParamsJson applies to an inline validatorScript only` };
|
|
294
|
+
}
|
|
295
|
+
input.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
296
|
+
}
|
|
297
|
+
const hasRedeemerJson = entry.redeemerJson !== undefined && entry.redeemerJson !== null;
|
|
298
|
+
const hasRedeemerCbor = entry.redeemerCbor !== undefined && entry.redeemerCbor !== null;
|
|
299
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
300
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
301
|
+
if (hasRedeemerCbor) {
|
|
302
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
303
|
+
if (cbor.error)
|
|
304
|
+
return { error: cbor.error };
|
|
305
|
+
input.redeemerCbor = cbor.hex;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
309
|
+
if (redeemer.error)
|
|
310
|
+
return { error: redeemer.error };
|
|
311
|
+
input.redeemer = redeemer.parsed;
|
|
312
|
+
}
|
|
313
|
+
const hasDatumJson = entry.datumJson !== undefined && entry.datumJson !== null;
|
|
314
|
+
const hasDatumCbor = entry.datumCbor !== undefined && entry.datumCbor !== null;
|
|
315
|
+
if (hasDatumJson && hasDatumCbor)
|
|
316
|
+
return { error: `${at} takes datumJson or datumCbor, not both` };
|
|
317
|
+
if (hasDatumCbor) {
|
|
318
|
+
const cbor = parsePlutusCbor(entry.datumCbor, `${at}.datumCbor`);
|
|
319
|
+
if (cbor.error)
|
|
320
|
+
return { error: cbor.error };
|
|
321
|
+
input.datumCbor = cbor.hex;
|
|
322
|
+
}
|
|
323
|
+
else if (hasDatumJson) {
|
|
324
|
+
const datum = parseJsonField(entry.datumJson, `${at}.datumJson`);
|
|
325
|
+
if (datum.error)
|
|
326
|
+
return { error: datum.error };
|
|
327
|
+
input.datum = datum.parsed;
|
|
328
|
+
}
|
|
329
|
+
out.push(input);
|
|
330
|
+
}
|
|
331
|
+
return { parsed: out };
|
|
332
|
+
}
|
|
333
|
+
/** Upper bound on withdrawals per BuildPlutusTransaction. */
|
|
334
|
+
exports.MAX_WITHDRAWALS = 16;
|
|
335
|
+
// Distinct reward accounts and lovelace >= 0. A staking script needs exactly one redeemer form.
|
|
336
|
+
// Without a script no redeemer is allowed.
|
|
337
|
+
function parseWithdrawals(json) {
|
|
338
|
+
if (!json)
|
|
339
|
+
return { parsed: undefined };
|
|
340
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'withdrawalsJson');
|
|
341
|
+
if (!jsonResult.valid)
|
|
342
|
+
return { error: jsonResult.error };
|
|
343
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
344
|
+
return { error: 'withdrawalsJson must be a JSON array' };
|
|
345
|
+
if (jsonResult.parsed.length === 0)
|
|
346
|
+
return { parsed: undefined };
|
|
347
|
+
if (jsonResult.parsed.length > exports.MAX_WITHDRAWALS) {
|
|
348
|
+
return { error: `withdrawalsJson exceeds maximum of ${exports.MAX_WITHDRAWALS} entries` };
|
|
349
|
+
}
|
|
350
|
+
const out = [];
|
|
351
|
+
const seen = new Set();
|
|
352
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
353
|
+
const entry = jsonResult.parsed[i];
|
|
354
|
+
const at = `withdrawals[${i}]`;
|
|
355
|
+
if (!entry || typeof entry !== 'object')
|
|
356
|
+
return { error: `${at} must be an object` };
|
|
357
|
+
if (typeof entry.rewardAddress !== 'string' || !(0, validators_1.isValidBech32StakeAddress)(entry.rewardAddress)) {
|
|
358
|
+
return { error: `${at}.rewardAddress must be a Bech32 stake address` };
|
|
359
|
+
}
|
|
360
|
+
const rewardAddress = entry.rewardAddress.toLowerCase();
|
|
361
|
+
if (seen.has(rewardAddress))
|
|
362
|
+
return { error: `${at} withdraws from ${rewardAddress} a second time` };
|
|
363
|
+
seen.add(rewardAddress);
|
|
364
|
+
const lovelace = typeof entry.lovelace === 'number' && Number.isInteger(entry.lovelace) && entry.lovelace >= 0
|
|
365
|
+
? String(entry.lovelace)
|
|
366
|
+
: typeof entry.lovelace === 'string' && /^\d+$/.test(entry.lovelace) ? entry.lovelace : undefined;
|
|
367
|
+
if (lovelace === undefined)
|
|
368
|
+
return { error: `${at}.lovelace must be a non-negative integer (0 for withdraw-zero)` };
|
|
369
|
+
const witness = parseStakingScriptWitness(entry, at, 'withdrawal');
|
|
370
|
+
if (witness.error)
|
|
371
|
+
return { error: witness.error };
|
|
372
|
+
out.push({ rewardAddress, lovelace, ...witness.parsed });
|
|
373
|
+
}
|
|
374
|
+
return { parsed: out };
|
|
375
|
+
}
|
|
376
|
+
function parseStakingScriptWitness(entry, at, kind) {
|
|
377
|
+
const present = (v) => v !== undefined && v !== null;
|
|
378
|
+
const parseJsonField = (value, field) => {
|
|
379
|
+
if (typeof value !== 'string')
|
|
380
|
+
return { error: `${field} must be a JSON string` };
|
|
381
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
382
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
383
|
+
};
|
|
384
|
+
const w = {};
|
|
385
|
+
const hasInline = present(entry.stakingScript);
|
|
386
|
+
const hasRef = present(entry.referenceScript);
|
|
387
|
+
if (hasInline && hasRef)
|
|
388
|
+
return { error: `${at} takes stakingScript or referenceScript, not both` };
|
|
389
|
+
if (hasInline) {
|
|
390
|
+
if (typeof entry.stakingScript !== 'string' || !(0, validators_1.isValidCbor)(entry.stakingScript)) {
|
|
391
|
+
return { error: `${at}.stakingScript must be even-length CBOR hex` };
|
|
392
|
+
}
|
|
393
|
+
w.stakingScript = entry.stakingScript;
|
|
394
|
+
if (present(entry.scriptParamsJson)) {
|
|
395
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
396
|
+
if (params.error)
|
|
397
|
+
return { error: params.error };
|
|
398
|
+
if (!Array.isArray(params.parsed))
|
|
399
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
400
|
+
if (params.parsed.length > 0)
|
|
401
|
+
w.scriptParams = params.parsed;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else if (hasRef) {
|
|
405
|
+
const ref = entry.referenceScript;
|
|
406
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
407
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
408
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
409
|
+
}
|
|
410
|
+
if (present(entry.scriptParamsJson))
|
|
411
|
+
return { error: `${at}.scriptParamsJson applies to an inline stakingScript only` };
|
|
412
|
+
w.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
413
|
+
}
|
|
414
|
+
else if (present(entry.scriptParamsJson)) {
|
|
415
|
+
return { error: `${at}.scriptParamsJson applies to an inline stakingScript only` };
|
|
416
|
+
}
|
|
417
|
+
const hasRedeemerJson = present(entry.redeemerJson);
|
|
418
|
+
const hasRedeemerCbor = present(entry.redeemerCbor);
|
|
419
|
+
if (hasInline || hasRef) {
|
|
420
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
421
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
422
|
+
if (hasRedeemerCbor) {
|
|
423
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
424
|
+
if (cbor.error)
|
|
425
|
+
return { error: cbor.error };
|
|
426
|
+
w.redeemerCbor = cbor.hex;
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
430
|
+
if (redeemer.error)
|
|
431
|
+
return { error: redeemer.error };
|
|
432
|
+
w.redeemer = redeemer.parsed;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else if (hasRedeemerJson || hasRedeemerCbor) {
|
|
436
|
+
return { error: `${at} has a redeemer but no staking script; a key-witnessed ${kind} takes none` };
|
|
437
|
+
}
|
|
438
|
+
return { parsed: w };
|
|
439
|
+
}
|
|
440
|
+
/** Upper bound on certificates per BuildPlutusTransaction. */
|
|
441
|
+
exports.MAX_CERTIFICATES = 16;
|
|
442
|
+
// Stake registrations and deregistrations. A scripted one needs exactly one redeemer form.
|
|
443
|
+
function parseCertificates(json) {
|
|
444
|
+
if (!json)
|
|
445
|
+
return { parsed: undefined };
|
|
446
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'certificatesJson');
|
|
447
|
+
if (!jsonResult.valid)
|
|
448
|
+
return { error: jsonResult.error };
|
|
449
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
450
|
+
return { error: 'certificatesJson must be a JSON array' };
|
|
451
|
+
if (jsonResult.parsed.length === 0)
|
|
452
|
+
return { parsed: undefined };
|
|
453
|
+
if (jsonResult.parsed.length > exports.MAX_CERTIFICATES) {
|
|
454
|
+
return { error: `certificatesJson exceeds maximum of ${exports.MAX_CERTIFICATES} entries` };
|
|
455
|
+
}
|
|
456
|
+
const out = [];
|
|
457
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
458
|
+
const entry = jsonResult.parsed[i];
|
|
459
|
+
const at = `certificates[${i}]`;
|
|
460
|
+
if (!entry || typeof entry !== 'object')
|
|
461
|
+
return { error: `${at} must be an object` };
|
|
462
|
+
if (entry.type !== 'registerStake' && entry.type !== 'deregisterStake') {
|
|
463
|
+
return { error: `${at}.type must be registerStake or deregisterStake` };
|
|
464
|
+
}
|
|
465
|
+
if (typeof entry.stakeAddress !== 'string' || !(0, validators_1.isValidBech32StakeAddress)(entry.stakeAddress)) {
|
|
466
|
+
return { error: `${at}.stakeAddress must be a Bech32 stake address` };
|
|
467
|
+
}
|
|
468
|
+
let deposit;
|
|
469
|
+
if (entry.deposit !== undefined && entry.deposit !== null) {
|
|
470
|
+
deposit = typeof entry.deposit === 'number' && Number.isInteger(entry.deposit) && entry.deposit > 0
|
|
471
|
+
? String(entry.deposit)
|
|
472
|
+
: typeof entry.deposit === 'string' && /^\d+$/.test(entry.deposit) && entry.deposit !== '0' ? entry.deposit : undefined;
|
|
473
|
+
if (deposit === undefined)
|
|
474
|
+
return { error: `${at}.deposit must be a positive integer (lovelace)` };
|
|
475
|
+
}
|
|
476
|
+
const witness = parseStakingScriptWitness(entry, at, 'certificate');
|
|
477
|
+
if (witness.error)
|
|
478
|
+
return { error: witness.error };
|
|
479
|
+
out.push({ type: entry.type, stakeAddress: entry.stakeAddress.toLowerCase(), ...(deposit ? { deposit } : {}), ...witness.parsed });
|
|
480
|
+
}
|
|
481
|
+
return { parsed: out };
|
|
482
|
+
}
|
|
483
|
+
// Every action carries its own `mintingPolicyScript` or `referenceScript`, with no request default.
|
|
484
|
+
// With an inline script, `assetUnit` may be a bare asset name, prefixed with the script's policy id.
|
|
485
|
+
function parsePolicyMintActions(json) {
|
|
486
|
+
if (!json)
|
|
487
|
+
return { parsed: undefined };
|
|
488
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'mintActionsJson');
|
|
489
|
+
if (!jsonResult.valid)
|
|
490
|
+
return { error: jsonResult.error };
|
|
491
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
492
|
+
return { error: 'mintActionsJson must be a JSON array' };
|
|
493
|
+
if (jsonResult.parsed.length === 0)
|
|
494
|
+
return { parsed: undefined };
|
|
495
|
+
const out = [];
|
|
496
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
497
|
+
const entry = jsonResult.parsed[i];
|
|
498
|
+
if (!entry || typeof entry !== 'object')
|
|
499
|
+
return { error: `mintActions[${i}] must be an object` };
|
|
500
|
+
if (typeof entry.quantity !== 'string' || !/^-?\d+$/.test(entry.quantity) || BigInt(entry.quantity) === 0n) {
|
|
501
|
+
return { error: `mintActions[${i}].quantity must be a non-zero integer string` };
|
|
502
|
+
}
|
|
503
|
+
const present = (v) => v !== undefined && v !== null;
|
|
504
|
+
const hasRef = present(entry.referenceScript);
|
|
505
|
+
if (present(entry.mintingPolicyScript) === hasRef) {
|
|
506
|
+
return { error: `mintActions[${i}] needs exactly one of mintingPolicyScript or referenceScript` };
|
|
507
|
+
}
|
|
508
|
+
const policy = parseMintActionPolicyFields(entry, i, hasRef);
|
|
509
|
+
if (policy.error)
|
|
510
|
+
return { error: policy.error };
|
|
511
|
+
if (typeof entry.assetUnit !== 'string' || !/^[0-9a-fA-F]*$/.test(entry.assetUnit) || entry.assetUnit.length % 2 !== 0) {
|
|
512
|
+
return { error: `mintActions[${i}].assetUnit must be hex (policyId+assetName, or a bare assetName)` };
|
|
513
|
+
}
|
|
514
|
+
let assetUnit = entry.assetUnit.toLowerCase();
|
|
515
|
+
let referenceScript;
|
|
516
|
+
if (hasRef) {
|
|
517
|
+
const ref = entry.referenceScript;
|
|
518
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
519
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
520
|
+
return { error: `mintActions[${i}].referenceScript must be {txHash, outputIndex} of the UTxO carrying the policy` };
|
|
521
|
+
}
|
|
522
|
+
referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
523
|
+
// the policy id is known only once the builder has read the reference script
|
|
524
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
525
|
+
return { error: `mintActions[${i}].assetUnit must be policyId+assetName when the policy is a referenceScript` };
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
let policyId;
|
|
530
|
+
try {
|
|
531
|
+
policyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policy.script, 'hex')).hash.toString();
|
|
532
|
+
}
|
|
533
|
+
catch (err) {
|
|
534
|
+
return { error: `mintActions[${i}].mintingPolicyScript is not a valid Plutus script: ${err instanceof Error ? err.message : String(err)}` };
|
|
535
|
+
}
|
|
536
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
537
|
+
assetUnit = policyId + assetUnit;
|
|
538
|
+
}
|
|
539
|
+
else if (!assetUnit.startsWith(policyId)) {
|
|
540
|
+
return { error: `mintActions[${i}].assetUnit does not start with its policy id ${policyId}` };
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (!(0, validators_1.isAssetUnit)(assetUnit))
|
|
544
|
+
return { error: `mintActions[${i}].assetUnit is not a valid asset unit` };
|
|
545
|
+
out.push({
|
|
546
|
+
assetUnit,
|
|
547
|
+
quantity: BigInt(entry.quantity),
|
|
548
|
+
...(policy.script ? { mintingPolicyScript: policy.script } : { referenceScript }),
|
|
549
|
+
...(policy.redeemer !== undefined ? { redeemerJson: policy.redeemer } : {}),
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return { parsed: out };
|
|
553
|
+
}
|
|
202
554
|
//# sourceMappingURL=tx-request-parsers.js.map
|
package/srv/utils/tx-utils.d.ts
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
import cds from '@sap/cds';
|
|
2
2
|
/** Default acquire budget for detached bookkeeping transactions. */
|
|
3
3
|
export declare const DETACHED_TX_TIMEOUT_MS = 10000;
|
|
4
|
-
/**
|
|
5
|
-
* Run `fn` with `cds.context` cleared, so any `db.run(...)` inside it gets a
|
|
6
|
-
* fresh short-lived transaction instead of joining a long-lived ambient one.
|
|
7
|
-
* Under @cap-js/sqlite (pool.max=1) this is what keeps the single pooled
|
|
8
|
-
* connection free during long awaits (NIGHTGATE lesson 2; used by the
|
|
9
|
-
* wallet-worker job loops).
|
|
10
|
-
*/
|
|
11
4
|
export declare function runWithoutAmbientTx<T>(fn: () => Promise<T>): Promise<T>;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* Why: the sign-service must commit its submit bookkeeping (claim, finalize,
|
|
17
|
-
* failure marker) independently of the caller's request transaction. When an
|
|
18
|
-
* in-process consumer awaits the action while its own request transaction
|
|
19
|
-
* holds the single pooled sqlite connection, the acquire can never succeed —
|
|
20
|
-
* without this guard that is a silent, zero-CPU, infinite hang.
|
|
21
|
-
*
|
|
22
|
-
* Guarantees:
|
|
23
|
-
* - On timeout, throws `BackendError` 503 `ODATANO_NESTED_TX_TIMEOUT` with a
|
|
24
|
-
* diagnosis pointing at KNOWN_ISSUES #11.
|
|
25
|
-
* - A late connection grant (after the timeout already fired) performs NO
|
|
26
|
-
* work: the callback forces the acquire via an explicit `begin()` and
|
|
27
|
-
* checks the abort flag right after it, so it rolls back immediately and
|
|
28
|
-
* the caller never observes an error for work that then silently happened
|
|
29
|
-
* anyway. (A flag check at callback ENTRY would run long before the lazy
|
|
30
|
-
* acquire and miss the timeout.)
|
|
31
|
-
*/
|
|
5
|
+
/** True once the transaction has taken its database connection. */
|
|
6
|
+
export declare function holdsConnection(tx: unknown): boolean;
|
|
7
|
+
export declare function readOutside<T>(tx: cds.Transaction, read: (db: cds.Transaction) => Promise<T>): Promise<T>;
|
|
32
8
|
export declare function detachedTx<T>(label: string, fn: (db: cds.Transaction) => Promise<T>, timeoutMs?: number): Promise<T>;
|
|
33
9
|
//# sourceMappingURL=tx-utils.d.ts.map
|