@odatano/core 2.0.0-rc.3 → 2.0.0-rc.31
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 +1193 -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 +115 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +651 -287
- package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
- package/srv/blockchain/transaction-building/caller-datums.js +139 -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 +130 -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
|
@@ -1,20 +1,37 @@
|
|
|
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;
|
|
10
|
+
exports.parseMintActionPolicyFields = parseMintActionPolicyFields;
|
|
11
|
+
exports.parseScriptInputs = parseScriptInputs;
|
|
12
|
+
exports.parseWithdrawals = parseWithdrawals;
|
|
13
|
+
exports.parseCertificates = parseCertificates;
|
|
14
|
+
exports.parsePolicyMintActions = parsePolicyMintActions;
|
|
8
15
|
const validators_1 = require("./validators");
|
|
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");
|
|
9
19
|
/**
|
|
10
|
-
* Shared parsers for the Build*-action JSON payload fields
|
|
11
|
-
*
|
|
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.
|
|
20
|
+
* Shared parsers for the Build*-action JSON payload fields (transaction service and wallet worker).
|
|
21
|
+
* Result contract: `{ parsed }` on success (undefined for absent/empty input) or `{ error }` with a client message.
|
|
17
22
|
*/
|
|
23
|
+
/** PlutusData as CBOR hex, checked to decode; `field` names it in the error. */
|
|
24
|
+
function parsePlutusCbor(value, field) {
|
|
25
|
+
if (typeof value !== 'string' || !(0, validators_1.isValidCbor)(value))
|
|
26
|
+
return { error: `${field} must be even-length CBOR hex` };
|
|
27
|
+
try {
|
|
28
|
+
(0, plutus_data_1.dataFromCbor)(value);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return { error: `${field} is not PlutusData CBOR: ${err instanceof Error ? err.message : String(err)}` };
|
|
32
|
+
}
|
|
33
|
+
return { hex: value.toLowerCase() };
|
|
34
|
+
}
|
|
18
35
|
function parseUtxoRefArray(json, fieldName) {
|
|
19
36
|
if (!json)
|
|
20
37
|
return { parsed: undefined };
|
|
@@ -43,10 +60,7 @@ function parseUtxoRefArray(json, fieldName) {
|
|
|
43
60
|
}
|
|
44
61
|
return { parsed: refs };
|
|
45
62
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Parse and validate requiredSignersJson (array of 56-hex Ed25519 key hashes).
|
|
48
|
-
* Same result contract as the other parse* helpers.
|
|
49
|
-
*/
|
|
63
|
+
/** Parse and validate requiredSignersJson (array of 56-hex Ed25519 key hashes). */
|
|
50
64
|
function parseRequiredSigners(requiredSignersJson) {
|
|
51
65
|
if (!requiredSignersJson)
|
|
52
66
|
return { parsed: undefined };
|
|
@@ -60,11 +74,7 @@ function parseRequiredSigners(requiredSignersJson) {
|
|
|
60
74
|
return { error: err instanceof Error ? err.message : String(err) };
|
|
61
75
|
}
|
|
62
76
|
}
|
|
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
|
-
*/
|
|
77
|
+
/** Parse and validate an assetsJson array of `{unit, quantity}` entries. */
|
|
68
78
|
function parseAssetsArray(assetsJson, fieldName) {
|
|
69
79
|
if (!assetsJson)
|
|
70
80
|
return { parsed: undefined };
|
|
@@ -91,51 +101,56 @@ function parseAssetsArray(assetsJson, fieldName) {
|
|
|
91
101
|
}
|
|
92
102
|
/** Upper bound on extra outputs per transaction (defence against tx-size blow-up). */
|
|
93
103
|
exports.MAX_EXTRA_OUTPUTS = 32;
|
|
104
|
+
/** Parse and validate extraOutputsJson (undefined for an empty array). */
|
|
105
|
+
function parseExtraOutputs(extraOutputsJson) {
|
|
106
|
+
return parseOutputList(extraOutputsJson, 'extraOutputsJson');
|
|
107
|
+
}
|
|
94
108
|
/**
|
|
95
|
-
* Parse
|
|
96
|
-
*
|
|
109
|
+
* Parse an output list. `outputsJson` (BuildPlutusTransaction) additionally accepts `datumHash`;
|
|
110
|
+
* the entries keep their order, each is min-ADA checked by the builder.
|
|
97
111
|
*/
|
|
98
|
-
function
|
|
99
|
-
if (!
|
|
112
|
+
function parseOutputList(json, fieldName) {
|
|
113
|
+
if (!json)
|
|
100
114
|
return { parsed: undefined };
|
|
101
|
-
const
|
|
115
|
+
const name = fieldName.replace(/Json$/, '');
|
|
116
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, fieldName);
|
|
102
117
|
if (!jsonResult.valid)
|
|
103
118
|
return { error: jsonResult.error };
|
|
104
119
|
if (!Array.isArray(jsonResult.parsed))
|
|
105
|
-
return { error:
|
|
120
|
+
return { error: `${fieldName} must be a JSON array` };
|
|
106
121
|
if (jsonResult.parsed.length === 0)
|
|
107
122
|
return { parsed: undefined };
|
|
108
123
|
if (jsonResult.parsed.length > exports.MAX_EXTRA_OUTPUTS) {
|
|
109
|
-
return { error:
|
|
124
|
+
return { error: `${fieldName} exceeds maximum of ${exports.MAX_EXTRA_OUTPUTS} entries` };
|
|
110
125
|
}
|
|
111
126
|
const out = [];
|
|
112
127
|
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
113
128
|
const entry = jsonResult.parsed[i];
|
|
114
129
|
if (!entry || typeof entry !== 'object') {
|
|
115
|
-
return { error:
|
|
130
|
+
return { error: `${name}[${i}] must be an object` };
|
|
116
131
|
}
|
|
117
132
|
if (typeof entry.address !== 'string' || !(0, validators_1.isValidBech32Address)(entry.address)) {
|
|
118
|
-
return { error:
|
|
133
|
+
return { error: `${name}[${i}].address is not a valid Bech32 address` };
|
|
119
134
|
}
|
|
120
135
|
if (typeof entry.lovelaceAmount !== 'string' || !/^\d+$/.test(entry.lovelaceAmount) || entry.lovelaceAmount === '0') {
|
|
121
|
-
return { error:
|
|
136
|
+
return { error: `${name}[${i}].lovelaceAmount must be a positive integer string` };
|
|
122
137
|
}
|
|
123
138
|
let assets;
|
|
124
139
|
if (entry.assets !== undefined && entry.assets !== null) {
|
|
125
140
|
if (!Array.isArray(entry.assets)) {
|
|
126
|
-
return { error:
|
|
141
|
+
return { error: `${name}[${i}].assets must be an array` };
|
|
127
142
|
}
|
|
128
143
|
assets = [];
|
|
129
144
|
for (let j = 0; j < entry.assets.length; j++) {
|
|
130
145
|
const a = entry.assets[j];
|
|
131
146
|
if (!a || typeof a !== 'object') {
|
|
132
|
-
return { error:
|
|
147
|
+
return { error: `${name}[${i}].assets[${j}] must be an object` };
|
|
133
148
|
}
|
|
134
149
|
if (typeof a.unit !== 'string' || a.unit.toLowerCase() === 'lovelace' || !(0, validators_1.isAssetUnit)(a.unit)) {
|
|
135
|
-
return { error:
|
|
150
|
+
return { error: `${name}[${i}].assets[${j}].unit must be a valid asset unit (policyId + assetName hex)` };
|
|
136
151
|
}
|
|
137
152
|
if (typeof a.quantity !== 'string' || !/^\d+$/.test(a.quantity) || a.quantity === '0') {
|
|
138
|
-
return { error:
|
|
153
|
+
return { error: `${name}[${i}].assets[${j}].quantity must be a positive integer string` };
|
|
139
154
|
}
|
|
140
155
|
assets.push({ unit: a.unit, quantity: a.quantity });
|
|
141
156
|
}
|
|
@@ -143,17 +158,39 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
143
158
|
let inlineDatum;
|
|
144
159
|
if (entry.inlineDatumJson !== undefined && entry.inlineDatumJson !== null) {
|
|
145
160
|
if (typeof entry.inlineDatumJson !== 'string') {
|
|
146
|
-
return { error:
|
|
161
|
+
return { error: `${name}[${i}].inlineDatumJson must be a JSON string` };
|
|
147
162
|
}
|
|
148
|
-
const datumResult = (0, validators_1.
|
|
163
|
+
const datumResult = (0, validators_1.validatePlutusJson)(entry.inlineDatumJson, `${name}[${i}].inlineDatumJson`);
|
|
149
164
|
if (!datumResult.valid)
|
|
150
165
|
return { error: datumResult.error };
|
|
151
166
|
inlineDatum = datumResult.parsed;
|
|
152
167
|
}
|
|
168
|
+
let inlineDatumCbor;
|
|
169
|
+
if (entry.inlineDatumCbor !== undefined && entry.inlineDatumCbor !== null) {
|
|
170
|
+
if (fieldName !== 'outputsJson')
|
|
171
|
+
return { error: `${name}[${i}].inlineDatumCbor is only supported in outputsJson` };
|
|
172
|
+
if (inlineDatum !== undefined)
|
|
173
|
+
return { error: `${name}[${i}] takes inlineDatumJson or inlineDatumCbor, not both` };
|
|
174
|
+
const cbor = parsePlutusCbor(entry.inlineDatumCbor, `${name}[${i}].inlineDatumCbor`);
|
|
175
|
+
if (cbor.error)
|
|
176
|
+
return { error: cbor.error };
|
|
177
|
+
inlineDatumCbor = cbor.hex;
|
|
178
|
+
}
|
|
179
|
+
let datumHash;
|
|
180
|
+
if (entry.datumHash !== undefined && entry.datumHash !== null) {
|
|
181
|
+
if (fieldName !== 'outputsJson')
|
|
182
|
+
return { error: `${name}[${i}].datumHash is only supported in outputsJson` };
|
|
183
|
+
if (typeof entry.datumHash !== 'string' || !/^[0-9a-fA-F]{64}$/.test(entry.datumHash)) {
|
|
184
|
+
return { error: `${name}[${i}].datumHash must be 64 hex chars` };
|
|
185
|
+
}
|
|
186
|
+
if (inlineDatum !== undefined || inlineDatumCbor !== undefined)
|
|
187
|
+
return { error: `${name}[${i}] takes an inline datum or datumHash, not both` };
|
|
188
|
+
datumHash = entry.datumHash.toLowerCase();
|
|
189
|
+
}
|
|
153
190
|
let referenceScript;
|
|
154
191
|
if (entry.referenceScriptHex !== undefined && entry.referenceScriptHex !== null) {
|
|
155
192
|
if (typeof entry.referenceScriptHex !== 'string' || !(0, validators_1.isValidCbor)(entry.referenceScriptHex)) {
|
|
156
|
-
return { error:
|
|
193
|
+
return { error: `${name}[${i}].referenceScriptHex must be even-length hex` };
|
|
157
194
|
}
|
|
158
195
|
referenceScript = entry.referenceScriptHex;
|
|
159
196
|
}
|
|
@@ -162,9 +199,371 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
162
199
|
lovelaceAmount: entry.lovelaceAmount,
|
|
163
200
|
assets,
|
|
164
201
|
inlineDatum,
|
|
202
|
+
...(datumHash ? { datumHash } : {}),
|
|
203
|
+
...(inlineDatumCbor ? { inlineDatumCbor } : {}),
|
|
165
204
|
referenceScript,
|
|
166
205
|
});
|
|
167
206
|
}
|
|
168
207
|
return { parsed: out };
|
|
169
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Parse the optional per-action policy fields of a mintActionsJson entry: `mintingPolicyScript` (CBOR hex,
|
|
211
|
+
* applied as-is) and `redeemerJson` (JSON string). Absent fields fall back to the top-level script/redeemer.
|
|
212
|
+
*/
|
|
213
|
+
function parseMintActionPolicyFields(entry, i, byReference = false) {
|
|
214
|
+
let script;
|
|
215
|
+
if (entry.mintingPolicyScript !== undefined && entry.mintingPolicyScript !== null) {
|
|
216
|
+
if (typeof entry.mintingPolicyScript !== 'string' || !(0, validators_1.isValidCbor)(entry.mintingPolicyScript)) {
|
|
217
|
+
return { error: `mintActions[${i}].mintingPolicyScript must be even-length CBOR hex` };
|
|
218
|
+
}
|
|
219
|
+
script = entry.mintingPolicyScript;
|
|
220
|
+
}
|
|
221
|
+
let redeemer;
|
|
222
|
+
if (entry.redeemerJson !== undefined && entry.redeemerJson !== null) {
|
|
223
|
+
if (typeof entry.redeemerJson !== 'string') {
|
|
224
|
+
return { error: `mintActions[${i}].redeemerJson must be a JSON string` };
|
|
225
|
+
}
|
|
226
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(entry.redeemerJson, `mintActions[${i}].redeemerJson`);
|
|
227
|
+
if (!jsonResult.valid)
|
|
228
|
+
return { error: jsonResult.error };
|
|
229
|
+
redeemer = jsonResult.parsed;
|
|
230
|
+
}
|
|
231
|
+
if (redeemer !== undefined && script === undefined && !byReference) {
|
|
232
|
+
return { error: `mintActions[${i}].redeemerJson requires mintActions[${i}].mintingPolicyScript` };
|
|
233
|
+
}
|
|
234
|
+
return { script, redeemer };
|
|
235
|
+
}
|
|
236
|
+
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
237
|
+
exports.MAX_SCRIPT_INPUTS = 16;
|
|
238
|
+
/** Parse and validate scriptInputsJson: 1..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
239
|
+
function parseScriptInputs(json) {
|
|
240
|
+
if (!json)
|
|
241
|
+
return { error: 'scriptInputsJson is required' };
|
|
242
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'scriptInputsJson');
|
|
243
|
+
if (!jsonResult.valid)
|
|
244
|
+
return { error: jsonResult.error };
|
|
245
|
+
if (!Array.isArray(jsonResult.parsed) || jsonResult.parsed.length === 0) {
|
|
246
|
+
return { error: 'scriptInputsJson must be a non-empty JSON array' };
|
|
247
|
+
}
|
|
248
|
+
if (jsonResult.parsed.length > exports.MAX_SCRIPT_INPUTS) {
|
|
249
|
+
return { error: `scriptInputsJson exceeds maximum of ${exports.MAX_SCRIPT_INPUTS} entries` };
|
|
250
|
+
}
|
|
251
|
+
const parseJsonField = (value, field) => {
|
|
252
|
+
if (typeof value !== 'string')
|
|
253
|
+
return { error: `${field} must be a JSON string` };
|
|
254
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
255
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
256
|
+
};
|
|
257
|
+
const out = [];
|
|
258
|
+
const seen = new Set();
|
|
259
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
260
|
+
const entry = jsonResult.parsed[i];
|
|
261
|
+
const at = `scriptInputs[${i}]`;
|
|
262
|
+
if (!entry || typeof entry !== 'object')
|
|
263
|
+
return { error: `${at} must be an object` };
|
|
264
|
+
if (typeof entry.txHash !== 'string' || !(0, validators_1.isTxHash)(entry.txHash))
|
|
265
|
+
return { error: `${at}.txHash must be 64 hex chars` };
|
|
266
|
+
const idx = entry.outputIndex;
|
|
267
|
+
if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0)
|
|
268
|
+
return { error: `${at}.outputIndex must be a non-negative integer` };
|
|
269
|
+
const key = `${entry.txHash.toLowerCase()}#${idx}`;
|
|
270
|
+
if (seen.has(key))
|
|
271
|
+
return { error: `${at} spends ${key} a second time` };
|
|
272
|
+
seen.add(key);
|
|
273
|
+
const hasInline = entry.validatorScript !== undefined && entry.validatorScript !== null;
|
|
274
|
+
const hasRef = entry.referenceScript !== undefined && entry.referenceScript !== null;
|
|
275
|
+
if (hasInline === hasRef)
|
|
276
|
+
return { error: `${at} needs exactly one of validatorScript or referenceScript` };
|
|
277
|
+
const input = { txHash: entry.txHash.toLowerCase(), outputIndex: idx, redeemer: null };
|
|
278
|
+
if (hasInline) {
|
|
279
|
+
if (typeof entry.validatorScript !== 'string' || !(0, validators_1.isValidCbor)(entry.validatorScript)) {
|
|
280
|
+
return { error: `${at}.validatorScript must be even-length CBOR hex` };
|
|
281
|
+
}
|
|
282
|
+
input.validatorScript = entry.validatorScript;
|
|
283
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
284
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
285
|
+
if (params.error)
|
|
286
|
+
return { error: params.error };
|
|
287
|
+
if (!Array.isArray(params.parsed))
|
|
288
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
289
|
+
if (params.parsed.length > 0)
|
|
290
|
+
input.scriptParams = params.parsed;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
const ref = entry.referenceScript;
|
|
295
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
296
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
297
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
298
|
+
}
|
|
299
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
300
|
+
return { error: `${at}.scriptParamsJson applies to an inline validatorScript only` };
|
|
301
|
+
}
|
|
302
|
+
input.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
303
|
+
}
|
|
304
|
+
const hasRedeemerJson = entry.redeemerJson !== undefined && entry.redeemerJson !== null;
|
|
305
|
+
const hasRedeemerCbor = entry.redeemerCbor !== undefined && entry.redeemerCbor !== null;
|
|
306
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
307
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
308
|
+
if (hasRedeemerCbor) {
|
|
309
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
310
|
+
if (cbor.error)
|
|
311
|
+
return { error: cbor.error };
|
|
312
|
+
input.redeemerCbor = cbor.hex;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
316
|
+
if (redeemer.error)
|
|
317
|
+
return { error: redeemer.error };
|
|
318
|
+
input.redeemer = redeemer.parsed;
|
|
319
|
+
}
|
|
320
|
+
const hasDatumJson = entry.datumJson !== undefined && entry.datumJson !== null;
|
|
321
|
+
const hasDatumCbor = entry.datumCbor !== undefined && entry.datumCbor !== null;
|
|
322
|
+
if (hasDatumJson && hasDatumCbor)
|
|
323
|
+
return { error: `${at} takes datumJson or datumCbor, not both` };
|
|
324
|
+
if (hasDatumCbor) {
|
|
325
|
+
const cbor = parsePlutusCbor(entry.datumCbor, `${at}.datumCbor`);
|
|
326
|
+
if (cbor.error)
|
|
327
|
+
return { error: cbor.error };
|
|
328
|
+
input.datumCbor = cbor.hex;
|
|
329
|
+
}
|
|
330
|
+
else if (hasDatumJson) {
|
|
331
|
+
const datum = parseJsonField(entry.datumJson, `${at}.datumJson`);
|
|
332
|
+
if (datum.error)
|
|
333
|
+
return { error: datum.error };
|
|
334
|
+
input.datum = datum.parsed;
|
|
335
|
+
}
|
|
336
|
+
out.push(input);
|
|
337
|
+
}
|
|
338
|
+
return { parsed: out };
|
|
339
|
+
}
|
|
340
|
+
/** Upper bound on withdrawals per BuildPlutusTransaction. */
|
|
341
|
+
exports.MAX_WITHDRAWALS = 16;
|
|
342
|
+
/**
|
|
343
|
+
* Parse and validate withdrawalsJson: distinct reward accounts, lovelace >= 0, optionally a staking
|
|
344
|
+
* script (inline or by reference) with exactly one redeemer form; without a script no redeemer.
|
|
345
|
+
*/
|
|
346
|
+
function parseWithdrawals(json) {
|
|
347
|
+
if (!json)
|
|
348
|
+
return { parsed: undefined };
|
|
349
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'withdrawalsJson');
|
|
350
|
+
if (!jsonResult.valid)
|
|
351
|
+
return { error: jsonResult.error };
|
|
352
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
353
|
+
return { error: 'withdrawalsJson must be a JSON array' };
|
|
354
|
+
if (jsonResult.parsed.length === 0)
|
|
355
|
+
return { parsed: undefined };
|
|
356
|
+
if (jsonResult.parsed.length > exports.MAX_WITHDRAWALS) {
|
|
357
|
+
return { error: `withdrawalsJson exceeds maximum of ${exports.MAX_WITHDRAWALS} entries` };
|
|
358
|
+
}
|
|
359
|
+
const out = [];
|
|
360
|
+
const seen = new Set();
|
|
361
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
362
|
+
const entry = jsonResult.parsed[i];
|
|
363
|
+
const at = `withdrawals[${i}]`;
|
|
364
|
+
if (!entry || typeof entry !== 'object')
|
|
365
|
+
return { error: `${at} must be an object` };
|
|
366
|
+
if (typeof entry.rewardAddress !== 'string' || !(0, validators_1.isValidBech32StakeAddress)(entry.rewardAddress)) {
|
|
367
|
+
return { error: `${at}.rewardAddress must be a Bech32 stake address` };
|
|
368
|
+
}
|
|
369
|
+
const rewardAddress = entry.rewardAddress.toLowerCase();
|
|
370
|
+
if (seen.has(rewardAddress))
|
|
371
|
+
return { error: `${at} withdraws from ${rewardAddress} a second time` };
|
|
372
|
+
seen.add(rewardAddress);
|
|
373
|
+
const lovelace = typeof entry.lovelace === 'number' && Number.isInteger(entry.lovelace) && entry.lovelace >= 0
|
|
374
|
+
? String(entry.lovelace)
|
|
375
|
+
: typeof entry.lovelace === 'string' && /^\d+$/.test(entry.lovelace) ? entry.lovelace : undefined;
|
|
376
|
+
if (lovelace === undefined)
|
|
377
|
+
return { error: `${at}.lovelace must be a non-negative integer (0 for withdraw-zero)` };
|
|
378
|
+
const witness = parseStakingScriptWitness(entry, at, 'withdrawal');
|
|
379
|
+
if (witness.error)
|
|
380
|
+
return { error: witness.error };
|
|
381
|
+
out.push({ rewardAddress, lovelace, ...witness.parsed });
|
|
382
|
+
}
|
|
383
|
+
return { parsed: out };
|
|
384
|
+
}
|
|
385
|
+
function parseStakingScriptWitness(entry, at, kind) {
|
|
386
|
+
const present = (v) => v !== undefined && v !== null;
|
|
387
|
+
const parseJsonField = (value, field) => {
|
|
388
|
+
if (typeof value !== 'string')
|
|
389
|
+
return { error: `${field} must be a JSON string` };
|
|
390
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
391
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
392
|
+
};
|
|
393
|
+
const w = {};
|
|
394
|
+
const hasInline = present(entry.stakingScript);
|
|
395
|
+
const hasRef = present(entry.referenceScript);
|
|
396
|
+
if (hasInline && hasRef)
|
|
397
|
+
return { error: `${at} takes stakingScript or referenceScript, not both` };
|
|
398
|
+
if (hasInline) {
|
|
399
|
+
if (typeof entry.stakingScript !== 'string' || !(0, validators_1.isValidCbor)(entry.stakingScript)) {
|
|
400
|
+
return { error: `${at}.stakingScript must be even-length CBOR hex` };
|
|
401
|
+
}
|
|
402
|
+
w.stakingScript = entry.stakingScript;
|
|
403
|
+
if (present(entry.scriptParamsJson)) {
|
|
404
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
405
|
+
if (params.error)
|
|
406
|
+
return { error: params.error };
|
|
407
|
+
if (!Array.isArray(params.parsed))
|
|
408
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
409
|
+
if (params.parsed.length > 0)
|
|
410
|
+
w.scriptParams = params.parsed;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else if (hasRef) {
|
|
414
|
+
const ref = entry.referenceScript;
|
|
415
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
416
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
417
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
418
|
+
}
|
|
419
|
+
if (present(entry.scriptParamsJson))
|
|
420
|
+
return { error: `${at}.scriptParamsJson applies to an inline stakingScript only` };
|
|
421
|
+
w.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
422
|
+
}
|
|
423
|
+
else if (present(entry.scriptParamsJson)) {
|
|
424
|
+
return { error: `${at}.scriptParamsJson applies to an inline stakingScript only` };
|
|
425
|
+
}
|
|
426
|
+
const hasRedeemerJson = present(entry.redeemerJson);
|
|
427
|
+
const hasRedeemerCbor = present(entry.redeemerCbor);
|
|
428
|
+
if (hasInline || hasRef) {
|
|
429
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
430
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
431
|
+
if (hasRedeemerCbor) {
|
|
432
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
433
|
+
if (cbor.error)
|
|
434
|
+
return { error: cbor.error };
|
|
435
|
+
w.redeemerCbor = cbor.hex;
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
439
|
+
if (redeemer.error)
|
|
440
|
+
return { error: redeemer.error };
|
|
441
|
+
w.redeemer = redeemer.parsed;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
else if (hasRedeemerJson || hasRedeemerCbor) {
|
|
445
|
+
return { error: `${at} has a redeemer but no staking script; a key-witnessed ${kind} takes none` };
|
|
446
|
+
}
|
|
447
|
+
return { parsed: w };
|
|
448
|
+
}
|
|
449
|
+
/** Upper bound on certificates per BuildPlutusTransaction. */
|
|
450
|
+
exports.MAX_CERTIFICATES = 16;
|
|
451
|
+
/**
|
|
452
|
+
* Parse and validate certificatesJson: stake registrations and deregistrations, each with an
|
|
453
|
+
* optional staking script (inline or by reference) and exactly one redeemer form when scripted.
|
|
454
|
+
*/
|
|
455
|
+
function parseCertificates(json) {
|
|
456
|
+
if (!json)
|
|
457
|
+
return { parsed: undefined };
|
|
458
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'certificatesJson');
|
|
459
|
+
if (!jsonResult.valid)
|
|
460
|
+
return { error: jsonResult.error };
|
|
461
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
462
|
+
return { error: 'certificatesJson must be a JSON array' };
|
|
463
|
+
if (jsonResult.parsed.length === 0)
|
|
464
|
+
return { parsed: undefined };
|
|
465
|
+
if (jsonResult.parsed.length > exports.MAX_CERTIFICATES) {
|
|
466
|
+
return { error: `certificatesJson exceeds maximum of ${exports.MAX_CERTIFICATES} entries` };
|
|
467
|
+
}
|
|
468
|
+
const out = [];
|
|
469
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
470
|
+
const entry = jsonResult.parsed[i];
|
|
471
|
+
const at = `certificates[${i}]`;
|
|
472
|
+
if (!entry || typeof entry !== 'object')
|
|
473
|
+
return { error: `${at} must be an object` };
|
|
474
|
+
if (entry.type !== 'registerStake' && entry.type !== 'deregisterStake') {
|
|
475
|
+
return { error: `${at}.type must be registerStake or deregisterStake` };
|
|
476
|
+
}
|
|
477
|
+
if (typeof entry.stakeAddress !== 'string' || !(0, validators_1.isValidBech32StakeAddress)(entry.stakeAddress)) {
|
|
478
|
+
return { error: `${at}.stakeAddress must be a Bech32 stake address` };
|
|
479
|
+
}
|
|
480
|
+
let deposit;
|
|
481
|
+
if (entry.deposit !== undefined && entry.deposit !== null) {
|
|
482
|
+
deposit = typeof entry.deposit === 'number' && Number.isInteger(entry.deposit) && entry.deposit > 0
|
|
483
|
+
? String(entry.deposit)
|
|
484
|
+
: typeof entry.deposit === 'string' && /^\d+$/.test(entry.deposit) && entry.deposit !== '0' ? entry.deposit : undefined;
|
|
485
|
+
if (deposit === undefined)
|
|
486
|
+
return { error: `${at}.deposit must be a positive integer (lovelace)` };
|
|
487
|
+
}
|
|
488
|
+
const witness = parseStakingScriptWitness(entry, at, 'certificate');
|
|
489
|
+
if (witness.error)
|
|
490
|
+
return { error: witness.error };
|
|
491
|
+
out.push({ type: entry.type, stakeAddress: entry.stakeAddress.toLowerCase(), ...(deposit ? { deposit } : {}), ...witness.parsed });
|
|
492
|
+
}
|
|
493
|
+
return { parsed: out };
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Parse mintActionsJson for BuildPlutusTransaction: every action carries its own `mintingPolicyScript`
|
|
497
|
+
* or `referenceScript` (no request-level default) and optional `redeemerJson`; `assetUnit` is
|
|
498
|
+
* policyId+assetName, or with an inline script a bare assetName prefixed with the script's policy id.
|
|
499
|
+
*/
|
|
500
|
+
function parsePolicyMintActions(json) {
|
|
501
|
+
if (!json)
|
|
502
|
+
return { parsed: undefined };
|
|
503
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'mintActionsJson');
|
|
504
|
+
if (!jsonResult.valid)
|
|
505
|
+
return { error: jsonResult.error };
|
|
506
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
507
|
+
return { error: 'mintActionsJson must be a JSON array' };
|
|
508
|
+
if (jsonResult.parsed.length === 0)
|
|
509
|
+
return { parsed: undefined };
|
|
510
|
+
const out = [];
|
|
511
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
512
|
+
const entry = jsonResult.parsed[i];
|
|
513
|
+
if (!entry || typeof entry !== 'object')
|
|
514
|
+
return { error: `mintActions[${i}] must be an object` };
|
|
515
|
+
if (typeof entry.quantity !== 'string' || !/^-?\d+$/.test(entry.quantity) || BigInt(entry.quantity) === 0n) {
|
|
516
|
+
return { error: `mintActions[${i}].quantity must be a non-zero integer string` };
|
|
517
|
+
}
|
|
518
|
+
const present = (v) => v !== undefined && v !== null;
|
|
519
|
+
const hasRef = present(entry.referenceScript);
|
|
520
|
+
if (present(entry.mintingPolicyScript) === hasRef) {
|
|
521
|
+
return { error: `mintActions[${i}] needs exactly one of mintingPolicyScript or referenceScript` };
|
|
522
|
+
}
|
|
523
|
+
const policy = parseMintActionPolicyFields(entry, i, hasRef);
|
|
524
|
+
if (policy.error)
|
|
525
|
+
return { error: policy.error };
|
|
526
|
+
if (typeof entry.assetUnit !== 'string' || !/^[0-9a-fA-F]*$/.test(entry.assetUnit) || entry.assetUnit.length % 2 !== 0) {
|
|
527
|
+
return { error: `mintActions[${i}].assetUnit must be hex (policyId+assetName, or a bare assetName)` };
|
|
528
|
+
}
|
|
529
|
+
let assetUnit = entry.assetUnit.toLowerCase();
|
|
530
|
+
let referenceScript;
|
|
531
|
+
if (hasRef) {
|
|
532
|
+
const ref = entry.referenceScript;
|
|
533
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
534
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
535
|
+
return { error: `mintActions[${i}].referenceScript must be {txHash, outputIndex} of the UTxO carrying the policy` };
|
|
536
|
+
}
|
|
537
|
+
referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
538
|
+
// the policy id is known only once the builder has read the reference script
|
|
539
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
540
|
+
return { error: `mintActions[${i}].assetUnit must be policyId+assetName when the policy is a referenceScript` };
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
let policyId;
|
|
545
|
+
try {
|
|
546
|
+
policyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policy.script, 'hex')).hash.toString();
|
|
547
|
+
}
|
|
548
|
+
catch (err) {
|
|
549
|
+
return { error: `mintActions[${i}].mintingPolicyScript is not a valid Plutus script: ${err instanceof Error ? err.message : String(err)}` };
|
|
550
|
+
}
|
|
551
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
552
|
+
assetUnit = policyId + assetUnit;
|
|
553
|
+
}
|
|
554
|
+
else if (!assetUnit.startsWith(policyId)) {
|
|
555
|
+
return { error: `mintActions[${i}].assetUnit does not start with its policy id ${policyId}` };
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (!(0, validators_1.isAssetUnit)(assetUnit))
|
|
559
|
+
return { error: `mintActions[${i}].assetUnit is not a valid asset unit` };
|
|
560
|
+
out.push({
|
|
561
|
+
assetUnit,
|
|
562
|
+
quantity: BigInt(entry.quantity),
|
|
563
|
+
...(policy.script ? { mintingPolicyScript: policy.script } : { referenceScript }),
|
|
564
|
+
...(policy.redeemer !== undefined ? { redeemerJson: policy.redeemer } : {}),
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
return { parsed: out };
|
|
568
|
+
}
|
|
170
569
|
//# sourceMappingURL=tx-request-parsers.js.map
|
package/srv/utils/tx-utils.d.ts
CHANGED
|
@@ -2,32 +2,13 @@ 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
4
|
/**
|
|
5
|
-
* Run `fn` with `cds.context` cleared
|
|
6
|
-
*
|
|
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).
|
|
5
|
+
* Run `fn` with `cds.context` cleared so inner `db.run` calls get short-lived transactions instead of
|
|
6
|
+
* joining a long-lived ambient one; keeps the single sqlite connection free during long awaits.
|
|
10
7
|
*/
|
|
11
8
|
export declare function runWithoutAmbientTx<T>(fn: () => Promise<T>): Promise<T>;
|
|
12
9
|
/**
|
|
13
|
-
* `cds.tx(fn)` with a deadlock guard:
|
|
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.)
|
|
10
|
+
* `cds.tx(fn)` as a new root transaction with a deadlock guard: throws BackendError 503
|
|
11
|
+
* `ODATANO_NESTED_TX_TIMEOUT` when no pooled connection arrives in time, and a late grant does no work.
|
|
31
12
|
*/
|
|
32
13
|
export declare function detachedTx<T>(label: string, fn: (db: cds.Transaction) => Promise<T>, timeoutMs?: number): Promise<T>;
|
|
33
14
|
//# sourceMappingURL=tx-utils.d.ts.map
|