@odatano/core 2.0.0-rc.19 → 2.0.0-rc.20
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 +1 -5
- package/@cds-models/CardanoIndexerService/index.d.ts +51 -2
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -10
- package/src/index.js +6 -16
- package/src/plugin.js +11 -27
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +39 -150
- package/srv/blockchain/backends/cardano-backend.d.ts +53 -171
- package/srv/blockchain/backends/cardano-backend.js +1 -5
- package/srv/blockchain/backends/koios-backend.d.ts +26 -71
- package/srv/blockchain/backends/koios-backend.js +50 -132
- package/srv/blockchain/backends/ogmios-backend.d.ts +43 -124
- package/srv/blockchain/backends/ogmios-backend.js +71 -179
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +12 -57
- package/srv/blockchain/backends/ogmios-frame-guard.js +27 -66
- package/srv/blockchain/cardano-client.d.ts +43 -216
- package/srv/blockchain/cardano-client.js +49 -234
- package/srv/blockchain/cardano-indexer.d.ts +79 -357
- package/srv/blockchain/cardano-indexer.js +98 -406
- package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
- package/srv/blockchain/cardano-tx-builder.js +21 -107
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +41 -145
- package/srv/blockchain/crawler/crawler.js +57 -172
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +2 -6
- package/srv/blockchain/crawler/index.js +4 -9
- package/srv/blockchain/crawler/sync-state.d.ts +17 -39
- package/srv/blockchain/crawler/sync-state.js +23 -55
- package/srv/blockchain/crawler/utxo-set-import.d.ts +5 -22
- package/srv/blockchain/crawler/utxo-set-import.js +8 -28
- package/srv/blockchain/ledger-state.d.ts +3 -12
- 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 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +65 -174
- package/srv/blockchain/transaction-building/buildooor-tx.js +107 -266
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +9 -22
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +12 -35
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -32
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +33 -111
- 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 +34 -90
- package/srv/cardano-agent-service.cds +1 -5
- package/srv/cardano-agent-service.js +3 -7
- package/srv/cardano-indexer-service.cds +32 -4
- package/srv/cardano-indexer-service.js +83 -15
- package/srv/cardano-service.js +36 -98
- package/srv/cardano-sign-service.cds +1 -1
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +1 -1
- package/srv/cardano-tx-service.js +54 -174
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +27 -86
- package/srv/server.js +52 -148
- package/srv/utils/agent-grants-config.d.ts +11 -50
- package/srv/utils/agent-grants-config.js +12 -45
- package/srv/utils/agent-grants.d.ts +34 -123
- package/srv/utils/agent-grants.js +57 -156
- package/srv/utils/agent-token-auth.d.ts +2 -5
- package/srv/utils/agent-token-auth.js +2 -5
- 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 +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +2 -7
- package/srv/utils/db-indexes.js +7 -34
- package/srv/utils/db-sanitize.d.ts +5 -18
- package/srv/utils/db-sanitize.js +6 -19
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +29 -191
- package/srv/utils/errors.js +44 -229
- package/srv/utils/liveness.d.ts +2 -9
- package/srv/utils/liveness.js +3 -11
- package/srv/utils/mappers.d.ts +50 -298
- package/srv/utils/mappers.js +80 -386
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.js +4 -23
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +6 -17
- package/srv/utils/rate-limiter.js +5 -15
- 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 +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +7 -26
- package/srv/utils/tx-request-parsers.js +7 -26
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +67 -206
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -17,29 +17,19 @@ const tx_request_parsers_1 = require("./utils/tx-request-parsers");
|
|
|
17
17
|
const VALID_DERIVE_NETWORKS = ['mainnet', 'preview', 'preprod'];
|
|
18
18
|
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
19
19
|
const logger = cds_1.default.log('CardanoTxService');
|
|
20
|
-
/**
|
|
21
|
-
* Cardano Transaction Service Implementation
|
|
22
|
-
* Handles transaction building and submission operations & some additional data queries.
|
|
23
|
-
*/
|
|
20
|
+
/** CardanoTransactionService handlers: transaction building, submission and script helpers. */
|
|
24
21
|
module.exports = (srv) => {
|
|
25
22
|
logger.debug('Module loaded - registering handlers');
|
|
26
23
|
const { TransactionBuilds, TransactionSubmissions, AddressTransactionBuilds } = require('#cds-models/CardanoTransactionService');
|
|
27
|
-
|
|
28
|
-
* Build a simple ADA-only transaction
|
|
29
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, changeAddress)
|
|
30
|
-
* @returns {TransactionBuild} Transaction build details
|
|
31
|
-
*/
|
|
24
|
+
// BuildSimpleAdaTransaction — ADA (optionally with assets / datum) to one recipient or a script.
|
|
32
25
|
srv.on('BuildSimpleAdaTransaction', async (req) => {
|
|
33
26
|
const { senderAddress, recipientAddress, lovelaceAmount, outputDatumJson, assetsJson, forceInputsJson, validatorScript, scriptParamsJson, lockOnScript, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
34
|
-
// validate inputs
|
|
35
27
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
36
28
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildSimpleAdaTransaction', errors);
|
|
37
29
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
38
30
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
39
31
|
}
|
|
40
|
-
// parse optional output datum
|
|
41
32
|
const cleanData = { ...req.data };
|
|
42
|
-
// parse optional forceInputsJson
|
|
43
33
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
44
34
|
if (forceInputsResult.error)
|
|
45
35
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
@@ -52,7 +42,7 @@ module.exports = (srv) => {
|
|
|
52
42
|
cleanData.outputDatum = jsonResult.parsed;
|
|
53
43
|
delete cleanData.outputDatumJson;
|
|
54
44
|
}
|
|
55
|
-
//
|
|
45
|
+
// Native assets to lock at a script address
|
|
56
46
|
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
57
47
|
if (assetsResult.error)
|
|
58
48
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', assetsResult.error, 'assetsJson');
|
|
@@ -60,7 +50,7 @@ module.exports = (srv) => {
|
|
|
60
50
|
cleanData.assets = assetsResult.parsed;
|
|
61
51
|
delete cleanData.assetsJson;
|
|
62
52
|
}
|
|
63
|
-
//
|
|
53
|
+
// Parameters for a parameterized validator
|
|
64
54
|
let scriptParams;
|
|
65
55
|
if (scriptParamsJson) {
|
|
66
56
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
@@ -71,11 +61,10 @@ module.exports = (srv) => {
|
|
|
71
61
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
|
-
// lockOnScript requires a validatorScript to derive the target address from
|
|
75
64
|
if (lockOnScript && !validatorScript) {
|
|
76
65
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'lockOnScript requires validatorScript to derive the script address', 'validatorScript');
|
|
77
66
|
}
|
|
78
|
-
//
|
|
67
|
+
// lockOnScript: derive script hash + address and override the recipient before the build.
|
|
79
68
|
let derivedScriptHash;
|
|
80
69
|
let derivedScriptAddress;
|
|
81
70
|
if (lockOnScript && validatorScript) {
|
|
@@ -99,11 +88,10 @@ module.exports = (srv) => {
|
|
|
99
88
|
cleanData.referenceScript = referenceScriptHex;
|
|
100
89
|
}
|
|
101
90
|
delete cleanData.referenceScriptHex;
|
|
102
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
103
91
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
104
92
|
logger.debug({ senderAddress, recipientAddress: cleanData.recipientAddress, lovelaceAmount, hasDatum: !!outputDatumJson, hasAssets: !!assetsJson, lockOnScript: !!lockOnScript }, 'Building simple ADA transaction');
|
|
105
93
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexSimpleBuildResult(db, cleanData);
|
|
106
|
-
// Persist derived script address + hash on the build record
|
|
94
|
+
// Persist the derived script address + hash on the build record
|
|
107
95
|
if (lockOnScript && derivedScriptHash && derivedScriptAddress && buildResult.id) {
|
|
108
96
|
buildResult.scriptHash = derivedScriptHash;
|
|
109
97
|
buildResult.scriptAddress = derivedScriptAddress;
|
|
@@ -115,41 +103,29 @@ module.exports = (srv) => {
|
|
|
115
103
|
return buildResult;
|
|
116
104
|
});
|
|
117
105
|
});
|
|
118
|
-
|
|
119
|
-
* Build a transaction with metadata
|
|
120
|
-
* @param req - CDS request object
|
|
121
|
-
* @returns {TransactionBuild} Transaction build details
|
|
122
|
-
*/
|
|
106
|
+
// BuildTransactionWithMetadata — ADA transfer with auxiliary metadata.
|
|
123
107
|
srv.on('BuildTransactionWithMetadata', async (req) => {
|
|
124
108
|
const { senderAddress, recipientAddress, lovelaceAmount, metadataJson } = req.data;
|
|
125
|
-
// validate inputs (includes JSON parsing validation)
|
|
126
109
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, metadataJson }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'metadataJson']);
|
|
127
110
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildTransactionWithMetadata', errors);
|
|
128
111
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
129
112
|
return (0, errors_1.rejectInvalid)(req, 'BuildTransactionWithMetadata', 'Invalid changeAddress format', 'changeAddress');
|
|
130
113
|
}
|
|
131
|
-
//
|
|
114
|
+
// Already validated as JSON above
|
|
132
115
|
const parsedMetadata = JSON.parse(metadataJson);
|
|
133
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
134
116
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
135
117
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, metadataKeyCount: Object.keys(parsedMetadata).length }, 'Building transaction with metadata');
|
|
136
118
|
return await (0, server_1.getCardanoIndexer)().indexMetadataBuildResult(db, { ...req.data, metadataJson: parsedMetadata });
|
|
137
119
|
});
|
|
138
120
|
});
|
|
139
|
-
|
|
140
|
-
* Build a multi-asset transaction
|
|
141
|
-
* @param req CDS request object
|
|
142
|
-
* @returns {TransactionBuild} Transaction build details
|
|
143
|
-
*/
|
|
121
|
+
// BuildMultiAssetTransaction — ADA plus native assets to one recipient.
|
|
144
122
|
srv.on('BuildMultiAssetTransaction', async (req) => {
|
|
145
123
|
const { senderAddress, recipientAddress, lovelaceAmount, assetsJson, outputDatumJson, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
146
|
-
// validate inputs (includes JSON parsing validation)
|
|
147
124
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, assetsJson, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'assetsJson']);
|
|
148
125
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildMultiAssetTransaction', errors);
|
|
149
126
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
150
127
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
151
128
|
}
|
|
152
|
-
// Parse and validate assetsJson entries (unit + quantity, like parseExtraOutputs)
|
|
153
129
|
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
154
130
|
if (assetsResult.error)
|
|
155
131
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', assetsResult.error, 'assetsJson');
|
|
@@ -157,10 +133,8 @@ module.exports = (srv) => {
|
|
|
157
133
|
if (!parsedAssets || parsedAssets.length === 0) {
|
|
158
134
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'assetsJson must contain at least one asset', 'assetsJson');
|
|
159
135
|
}
|
|
160
|
-
// Validation BEFORE handleRequest
|
|
161
136
|
const cleanData = { ...req.data };
|
|
162
137
|
delete cleanData.assetsJson;
|
|
163
|
-
// parse optional output datum
|
|
164
138
|
if (outputDatumJson) {
|
|
165
139
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(outputDatumJson, 'outputDatumJson');
|
|
166
140
|
if (!jsonResult.valid)
|
|
@@ -172,7 +146,6 @@ module.exports = (srv) => {
|
|
|
172
146
|
cleanData.referenceScript = referenceScriptHex;
|
|
173
147
|
}
|
|
174
148
|
delete cleanData.referenceScriptHex;
|
|
175
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
176
149
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
177
150
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, assets: parsedAssets, hasDatum: !!outputDatumJson }, 'Building multi-asset transaction');
|
|
178
151
|
const result = await (0, server_1.getCardanoIndexer)().indexMultiAssetBuildResult(db, { ...cleanData, assets: parsedAssets });
|
|
@@ -180,20 +153,15 @@ module.exports = (srv) => {
|
|
|
180
153
|
return result;
|
|
181
154
|
});
|
|
182
155
|
});
|
|
183
|
-
|
|
184
|
-
* Build a minting transaction
|
|
185
|
-
* @param req CDS request object
|
|
186
|
-
* @returns {TransactionBuild} Transaction build details
|
|
187
|
-
*/
|
|
156
|
+
// BuildMintTransaction — mint/burn under one or more Plutus policies.
|
|
188
157
|
srv.on('BuildMintTransaction', async (req) => {
|
|
189
158
|
const { senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, referenceInputsJson, referenceScriptHex, extraOutputsJson, metadataJson, validityStartMs, validityEndMs } = req.data;
|
|
190
|
-
// validate inputs (includes JSON and CBOR validation)
|
|
191
159
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, referenceScriptHex, metadataJson, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
192
160
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildMintTransaction', errors);
|
|
193
161
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
194
162
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
195
163
|
}
|
|
196
|
-
//
|
|
164
|
+
// Mint actions: quantities become bigint; bare asset names are expanded with the policy id.
|
|
197
165
|
const parsedMintActionsRaw = JSON.parse(mintActionsJson);
|
|
198
166
|
if (!Array.isArray(parsedMintActionsRaw)) {
|
|
199
167
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'mintActionsJson must be a JSON array', 'mintActionsJson');
|
|
@@ -202,7 +170,7 @@ module.exports = (srv) => {
|
|
|
202
170
|
if (!action || typeof action !== 'object') {
|
|
203
171
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Each mint action must be an object with assetUnit and quantity', 'mintActionsJson');
|
|
204
172
|
}
|
|
205
|
-
//
|
|
173
|
+
// Optional per-action mintingPolicyScript + redeemerJson
|
|
206
174
|
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
207
175
|
if (policyFields.error) {
|
|
208
176
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', policyFields.error, 'mintActionsJson');
|
|
@@ -253,12 +221,10 @@ module.exports = (srv) => {
|
|
|
253
221
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid quantity: "${action.quantity}" — cannot parse as integer`, 'mintActionsJson');
|
|
254
222
|
}
|
|
255
223
|
});
|
|
256
|
-
// Parse and validate optional requiredSignersJson
|
|
257
224
|
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
258
225
|
if (requiredSignersResult.error)
|
|
259
226
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
260
227
|
const requiredSigners = requiredSignersResult.parsed;
|
|
261
|
-
// Parse and validate optional scriptParamsJson
|
|
262
228
|
let scriptParams;
|
|
263
229
|
if (scriptParamsJson) {
|
|
264
230
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
@@ -269,7 +235,6 @@ module.exports = (srv) => {
|
|
|
269
235
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
270
236
|
}
|
|
271
237
|
}
|
|
272
|
-
// Parse and validate optional inlineDatumJson
|
|
273
238
|
let inlineDatum;
|
|
274
239
|
if (inlineDatumJson) {
|
|
275
240
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(inlineDatumJson, 'inlineDatumJson');
|
|
@@ -277,7 +242,6 @@ module.exports = (srv) => {
|
|
|
277
242
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'inlineDatumJson');
|
|
278
243
|
inlineDatum = jsonResult.parsed;
|
|
279
244
|
}
|
|
280
|
-
// Parse and validate optional mintRedeemerJson
|
|
281
245
|
let mintRedeemer;
|
|
282
246
|
if (mintRedeemerJson) {
|
|
283
247
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(mintRedeemerJson, 'mintRedeemerJson');
|
|
@@ -285,27 +249,23 @@ module.exports = (srv) => {
|
|
|
285
249
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'mintRedeemerJson');
|
|
286
250
|
mintRedeemer = jsonResult.parsed;
|
|
287
251
|
}
|
|
288
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
289
252
|
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
290
253
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
291
254
|
}
|
|
292
|
-
//
|
|
293
|
-
// token can sit on its own output with its own inline datum)
|
|
255
|
+
// extraOutputsJson: each minted token can sit on its own output with its own inline datum
|
|
294
256
|
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
295
257
|
if (extraOutputsResult.error)
|
|
296
258
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
297
259
|
const extraOutputs = extraOutputsResult.parsed;
|
|
298
|
-
// Parse and validate optional forceInputsJson
|
|
299
260
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
300
261
|
if (forceInputsResult.error)
|
|
301
262
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
302
263
|
const forceInputs = forceInputsResult.parsed;
|
|
303
|
-
//
|
|
264
|
+
// CIP-31 reference inputs
|
|
304
265
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
305
266
|
if (refInputsResult.error)
|
|
306
267
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
307
268
|
const referenceInputs = refInputsResult.parsed;
|
|
308
|
-
// Parse and validate optional metadataJson
|
|
309
269
|
let parsedMetadata;
|
|
310
270
|
if (metadataJson) {
|
|
311
271
|
try {
|
|
@@ -319,10 +279,8 @@ module.exports = (srv) => {
|
|
|
319
279
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'metadataJson must be an object with numeric label keys', 'metadataJson');
|
|
320
280
|
}
|
|
321
281
|
}
|
|
322
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
323
282
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
324
283
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, mintActions: parsedMintActions, forceInputs: forceInputs?.length ?? 0, referenceInputs: referenceInputs?.length ?? 0, hasMetadata: !!parsedMetadata }, 'Building minting transaction');
|
|
325
|
-
// Create clean request object with parsed mintActions (remove mintActionsJson, add mintActions)
|
|
326
284
|
const cleanData = { ...req.data };
|
|
327
285
|
delete cleanData.mintActionsJson;
|
|
328
286
|
delete cleanData.requiredSignersJson;
|
|
@@ -343,13 +301,12 @@ module.exports = (srv) => {
|
|
|
343
301
|
cleanData.referenceScript = referenceScriptHex;
|
|
344
302
|
}
|
|
345
303
|
delete cleanData.referenceScriptHex;
|
|
346
|
-
//
|
|
304
|
+
// Parameterized policy: apply params, then expand bare asset names with the applied hash.
|
|
347
305
|
let finalMintingPolicyScript = mintingPolicyScript;
|
|
348
306
|
let effectivePolicyId;
|
|
349
307
|
if (scriptParams && scriptParams.length > 0) {
|
|
350
308
|
try {
|
|
351
309
|
finalMintingPolicyScript = (0, tx_build_helper_1.applyScriptParameters)(mintingPolicyScript, scriptParams);
|
|
352
|
-
// BUG 7 fix: expand assetName-only entries to full assetUnit using the applied script's policyId.
|
|
353
310
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex'));
|
|
354
311
|
effectivePolicyId = appliedScript.hash.toString();
|
|
355
312
|
}
|
|
@@ -362,7 +319,7 @@ module.exports = (srv) => {
|
|
|
362
319
|
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
363
320
|
}
|
|
364
321
|
}
|
|
365
|
-
// lockOnScript: route output to the enterprise
|
|
322
|
+
// lockOnScript: route the output to the enterprise address of the applied script
|
|
366
323
|
if (lockOnScript) {
|
|
367
324
|
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, (0, server_1.getCardanoClient)().network);
|
|
368
325
|
cleanData.recipientAddress = scriptAddr;
|
|
@@ -374,9 +331,10 @@ module.exports = (srv) => {
|
|
|
374
331
|
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(mintingPolicyScript, 'hex')).hash.toString();
|
|
375
332
|
}
|
|
376
333
|
catch {
|
|
377
|
-
//
|
|
334
|
+
// Invalid script CBOR: skip the prefix check, the builder rejects it with its own message.
|
|
378
335
|
}
|
|
379
336
|
}
|
|
337
|
+
// Every action without its own policy must carry the top-level policy id prefix.
|
|
380
338
|
if (effectivePolicyId) {
|
|
381
339
|
const policyId = effectivePolicyId;
|
|
382
340
|
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
@@ -395,16 +353,12 @@ module.exports = (srv) => {
|
|
|
395
353
|
referenceInputs,
|
|
396
354
|
extraOutputs
|
|
397
355
|
});
|
|
398
|
-
// Post-build:
|
|
356
|
+
// Post-build: CIP-14 fingerprint and scriptAddress
|
|
399
357
|
if (buildResult.scriptHash) {
|
|
400
358
|
const policyId = buildResult.scriptHash;
|
|
401
359
|
const updates = {};
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
// the prefix checks rejected everything else (a 56-hex unit is an empty
|
|
405
|
-
// asset name, not a bare 28-byte name). The policy id comes from the UNIT,
|
|
406
|
-
// not from buildResult.scriptHash: with a per-action mintingPolicyScript the
|
|
407
|
-
// first action may mint under a different policy than the top-level script.
|
|
360
|
+
// Fingerprint of the first minted asset. The policy id is taken from the unit, not from
|
|
361
|
+
// buildResult.scriptHash: a per-action policy may differ from the top-level script.
|
|
408
362
|
if (parsedMintActions.length > 0) {
|
|
409
363
|
const firstAssetUnit = parsedMintActions[0].assetUnit;
|
|
410
364
|
const firstPolicyId = firstAssetUnit.slice(0, const_1.POLICY_ID_HEX_LENGTH);
|
|
@@ -412,7 +366,7 @@ module.exports = (srv) => {
|
|
|
412
366
|
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(firstPolicyId, assetNameHex);
|
|
413
367
|
updates.fingerprint = buildResult.fingerprint;
|
|
414
368
|
}
|
|
415
|
-
// lockOnScript: persist the derived script address on the build record
|
|
369
|
+
// lockOnScript: persist the derived script address on the build record
|
|
416
370
|
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
417
371
|
buildResult.scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(policyId, (0, server_1.getCardanoClient)().network);
|
|
418
372
|
updates.scriptAddress = buildResult.scriptAddress;
|
|
@@ -425,33 +379,24 @@ module.exports = (srv) => {
|
|
|
425
379
|
return buildResult;
|
|
426
380
|
});
|
|
427
381
|
});
|
|
428
|
-
|
|
429
|
-
* Build a Plutus spending transaction (consume UTxO at script address)
|
|
430
|
-
* @param req - CDS request object (with senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, changeAddress)
|
|
431
|
-
* @returns {TransactionBuild} Transaction build details
|
|
432
|
-
*/
|
|
382
|
+
// BuildPlutusSpendTransaction — consume a UTxO at a script address, optionally minting too.
|
|
433
383
|
srv.on('BuildPlutusSpendTransaction', async (req) => {
|
|
434
384
|
const { senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, requiredSignersJson, scriptParamsJson, inlineDatumJson, lockOnScript, forceInputsJson, extraOutputsJson, mintActionsJson, mintingPolicyScript, mintRedeemerJson, referenceInputsJson, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
435
|
-
// Validate inputs
|
|
436
385
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'validatorScript', 'scriptTxHash', 'redeemerJson']);
|
|
437
386
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildPlutusSpendTransaction', errors);
|
|
438
387
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
439
388
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
440
389
|
}
|
|
441
|
-
//
|
|
390
|
+
// A number: not covered by the required-fields check
|
|
442
391
|
if (scriptOutputIndex === undefined || scriptOutputIndex === null) {
|
|
443
392
|
return (0, errors_1.rejectMissing)(req, 'BuildPlutusSpendTransaction', 'scriptOutputIndex');
|
|
444
393
|
}
|
|
445
|
-
// Parse redeemer JSON
|
|
446
394
|
const parsedRedeemer = JSON.parse(redeemerJson);
|
|
447
|
-
// Parse optional datum JSON
|
|
448
395
|
const parsedDatum = datumJson ? JSON.parse(datumJson) : undefined;
|
|
449
|
-
// Parse and validate optional requiredSignersJson
|
|
450
396
|
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
451
397
|
if (requiredSignersResult.error)
|
|
452
398
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
453
399
|
const requiredSigners = requiredSignersResult.parsed;
|
|
454
|
-
// Parse and validate optional scriptParamsJson
|
|
455
400
|
let scriptParams;
|
|
456
401
|
if (scriptParamsJson) {
|
|
457
402
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
@@ -462,7 +407,6 @@ module.exports = (srv) => {
|
|
|
462
407
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
463
408
|
}
|
|
464
409
|
}
|
|
465
|
-
// Parse and validate optional inlineDatumJson
|
|
466
410
|
let inlineDatum;
|
|
467
411
|
if (inlineDatumJson) {
|
|
468
412
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(inlineDatumJson, 'inlineDatumJson');
|
|
@@ -470,21 +414,18 @@ module.exports = (srv) => {
|
|
|
470
414
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'inlineDatumJson');
|
|
471
415
|
inlineDatum = jsonResult.parsed;
|
|
472
416
|
}
|
|
473
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
474
417
|
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
475
418
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
476
419
|
}
|
|
477
|
-
// Parse and validate optional forceInputsJson
|
|
478
420
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
479
421
|
if (forceInputsResult.error)
|
|
480
422
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
481
423
|
const forceInputs = forceInputsResult.parsed;
|
|
482
|
-
//
|
|
424
|
+
// CIP-31 reference inputs
|
|
483
425
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
484
426
|
if (refInputsResult.error)
|
|
485
427
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
486
428
|
const referenceInputs = refInputsResult.parsed;
|
|
487
|
-
// Parse and validate optional extraOutputsJson
|
|
488
429
|
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
489
430
|
if (extraOutputsResult.error)
|
|
490
431
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
@@ -513,8 +454,7 @@ module.exports = (srv) => {
|
|
|
513
454
|
if (typeof action.assetUnit !== 'string') {
|
|
514
455
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Each mint action must have assetUnit string', 'mintActionsJson');
|
|
515
456
|
}
|
|
516
|
-
//
|
|
517
|
-
// (same rules as BuildMintTransaction).
|
|
457
|
+
// Optional per-action mintingPolicyScript + redeemerJson (same rules as BuildMintTransaction)
|
|
518
458
|
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
519
459
|
if (policyFields.error) {
|
|
520
460
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', policyFields.error, 'mintActionsJson');
|
|
@@ -565,7 +505,6 @@ module.exports = (srv) => {
|
|
|
565
505
|
}
|
|
566
506
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
567
507
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, scriptTxHash, scriptOutputIndex }, 'Building Plutus spending transaction');
|
|
568
|
-
// Apply script parameters if provided (for parameterized validators)
|
|
569
508
|
let finalValidatorScript = validatorScript;
|
|
570
509
|
if (scriptParams && scriptParams.length > 0) {
|
|
571
510
|
try {
|
|
@@ -576,8 +515,8 @@ module.exports = (srv) => {
|
|
|
576
515
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Failed to apply script parameters: ${errMsg}`, 'scriptParamsJson');
|
|
577
516
|
}
|
|
578
517
|
}
|
|
579
|
-
//
|
|
580
|
-
//
|
|
518
|
+
// A mint policy byte-equal to the validator (multi-purpose script) reuses the
|
|
519
|
+
// params-applied validator hex; any other policy passes through unchanged.
|
|
581
520
|
let finalMintingPolicyScript;
|
|
582
521
|
if (parsedMintActions) {
|
|
583
522
|
finalMintingPolicyScript = (mintingPolicyScript === validatorScript)
|
|
@@ -598,22 +537,19 @@ module.exports = (srv) => {
|
|
|
598
537
|
}
|
|
599
538
|
}
|
|
600
539
|
}
|
|
601
|
-
//
|
|
602
|
-
//
|
|
603
|
-
// discards the unit's first 56 hex chars, so a mismatched prefix would mint a
|
|
604
|
-
// truncated asset name.
|
|
540
|
+
// Policy-id prefix check as in BuildMintTransaction: the builder discards the unit's
|
|
541
|
+
// first 56 hex chars, so a mismatched prefix would mint a truncated asset name.
|
|
605
542
|
if (finalMintingPolicyScript) {
|
|
606
543
|
let mintPolicyId;
|
|
607
544
|
try {
|
|
608
545
|
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
609
546
|
}
|
|
610
547
|
catch {
|
|
611
|
-
//
|
|
548
|
+
// Invalid script CBOR: skip the prefix check, the builder rejects it with its own message.
|
|
612
549
|
}
|
|
613
550
|
if (mintPolicyId) {
|
|
614
551
|
const policyId = mintPolicyId;
|
|
615
|
-
// Actions with
|
|
616
|
-
// against THAT script's policy id during parsing.
|
|
552
|
+
// Actions with a per-action script were already checked against that policy id.
|
|
617
553
|
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
618
554
|
if (mismatch) {
|
|
619
555
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `assetUnit "${mismatch.assetUnit}" does not start with the minting policy id ${policyId} — pass the full unit as policyId+assetName (asset names longer than 28 bytes cannot be passed bare)`, 'mintActionsJson');
|
|
@@ -654,7 +590,7 @@ module.exports = (srv) => {
|
|
|
654
590
|
delete cleanData.mintActionsJson;
|
|
655
591
|
delete cleanData.mintRedeemerJson;
|
|
656
592
|
delete cleanData.referenceScriptHex;
|
|
657
|
-
// lockOnScript: route continuing output to enterprise script address
|
|
593
|
+
// lockOnScript: route the continuing output to the enterprise script address
|
|
658
594
|
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
659
595
|
try {
|
|
660
596
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalValidatorScript, 'hex'));
|
|
@@ -669,7 +605,7 @@ module.exports = (srv) => {
|
|
|
669
605
|
}
|
|
670
606
|
}
|
|
671
607
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexPlutusSpendBuildResult(db, cleanData);
|
|
672
|
-
// lockOnScript: persist the derived script address on the build record
|
|
608
|
+
// lockOnScript: persist the derived script address on the build record
|
|
673
609
|
if (lockOnScript && scriptParams && scriptParams.length > 0 && buildResult.scriptHash && buildResult.id) {
|
|
674
610
|
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(buildResult.scriptHash, (0, server_1.getCardanoClient)().network);
|
|
675
611
|
buildResult.scriptAddress = scriptAddr;
|
|
@@ -679,17 +615,11 @@ module.exports = (srv) => {
|
|
|
679
615
|
return buildResult;
|
|
680
616
|
});
|
|
681
617
|
});
|
|
682
|
-
|
|
683
|
-
* Get build details for previously built transaction
|
|
684
|
-
* @param req - CDS request object (with buildId)
|
|
685
|
-
* @returns {TransactionBuild} Transaction build details
|
|
686
|
-
*/
|
|
618
|
+
// GetBuildDetails — an existing transaction build by id.
|
|
687
619
|
srv.on('GetBuildDetails', async (req) => {
|
|
688
620
|
const { buildId } = req.data;
|
|
689
|
-
// Validate inputs
|
|
690
621
|
const errors = (0, validators_1.validateTransactionInputs)({ buildId }, ['buildId']);
|
|
691
622
|
(0, errors_1.throwIfValidationErrors)(req, 'GetBuildDetails', errors);
|
|
692
|
-
// handle the request / fetching the build details
|
|
693
623
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
694
624
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
695
625
|
if (!existing)
|
|
@@ -697,13 +627,7 @@ module.exports = (srv) => {
|
|
|
697
627
|
return existing;
|
|
698
628
|
});
|
|
699
629
|
});
|
|
700
|
-
|
|
701
|
-
* Set up a collateral UTxO for Plutus transactions.
|
|
702
|
-
* Checks if the address already has >= 2 UTxOs with >= 5 ADA each.
|
|
703
|
-
* If not, builds a self-send transaction to create a 5 ADA collateral UTxO.
|
|
704
|
-
* @param req - CDS request object (with address)
|
|
705
|
-
* @returns {TransactionBuild} Transaction build details for the collateral setup
|
|
706
|
-
*/
|
|
630
|
+
// SetCollateral — ensures >= 2 UTxOs of >= 5 ADA; otherwise builds a self-send that creates one.
|
|
707
631
|
srv.on('SetCollateral', async (req) => {
|
|
708
632
|
const { address } = req.data;
|
|
709
633
|
if (!address)
|
|
@@ -712,11 +636,8 @@ module.exports = (srv) => {
|
|
|
712
636
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'Invalid Bech32 address format', 'address');
|
|
713
637
|
}
|
|
714
638
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
715
|
-
// Inside handleRequest
|
|
716
|
-
//
|
|
717
|
-
// getAddressUtxos both get caught and properly mapped via mapError.
|
|
718
|
-
// Use rejectInvalid (throws BackendError 400) instead of req.reject so
|
|
719
|
-
// mapError sees a typed BackendError and preserves the 400 status.
|
|
639
|
+
// Inside handleRequest use rejectInvalid (typed BackendError 400), not req.reject,
|
|
640
|
+
// so mapError preserves the status.
|
|
720
641
|
const utxos = await (0, server_1.getCardanoClient)().getAddressUtxos(address);
|
|
721
642
|
if (utxos.length === 0) {
|
|
722
643
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'No UTxOs found at address', 'address');
|
|
@@ -745,32 +666,24 @@ module.exports = (srv) => {
|
|
|
745
666
|
return { ...result, collateralAvailable: false };
|
|
746
667
|
});
|
|
747
668
|
});
|
|
748
|
-
|
|
749
|
-
* Submit signed transaction built previously
|
|
750
|
-
* Handler validates, checks build exists, submits to blockchain, delegates persistence to indexer
|
|
751
|
-
* @param req - CDS request object (with buildId, signedTxCbor)
|
|
752
|
-
* @returns {TransactionSubmission} Transaction submission details
|
|
753
|
-
*/
|
|
669
|
+
// SubmitTransaction — submit the signed CBOR of a previous build.
|
|
754
670
|
srv.on('SubmitTransaction', async (req) => {
|
|
755
671
|
logger.debug('SubmitTransaction Action handler called');
|
|
756
672
|
const { buildId, signedTxCbor } = req.data;
|
|
757
|
-
// Validate inputs (includes CBOR format validation)
|
|
758
673
|
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor }, ['buildId', 'signedTxCbor']);
|
|
759
674
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitTransaction', errors);
|
|
760
675
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
761
676
|
logger.debug({ buildId }, 'Submitting signed transaction');
|
|
762
|
-
// Validate build exists
|
|
763
677
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
764
678
|
if (!existing)
|
|
765
679
|
throw new errors_1.NotFoundError(`Build '${buildId}'`);
|
|
766
|
-
//
|
|
680
|
+
// The signed CBOR must belong to this build (audit-trail integrity)
|
|
767
681
|
const signedTxHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
768
682
|
if (signedTxHash !== existing.txBodyHash) {
|
|
769
683
|
return (0, errors_1.rejectInvalid)(req, 'SubmitTransaction', `signedTxCbor hash '${signedTxHash}' does not match build txBodyHash '${existing.txBodyHash}'`, 'signedTxCbor');
|
|
770
684
|
}
|
|
771
|
-
// Use txBodyHash from build
|
|
772
685
|
const txHash = existing.txBodyHash;
|
|
773
|
-
// Two-phase submit: persist
|
|
686
|
+
// Two-phase submit: persist as 'pending', then submit
|
|
774
687
|
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
775
688
|
signedTxCbor,
|
|
776
689
|
txHash,
|
|
@@ -781,9 +694,8 @@ module.exports = (srv) => {
|
|
|
781
694
|
logger.info({ txHash }, 'Transaction submitted to blockchain');
|
|
782
695
|
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
783
696
|
submissionRecord.status = 'submitted';
|
|
784
|
-
//
|
|
785
|
-
//
|
|
786
|
-
// failure here must not fail the already-successful submit.
|
|
697
|
+
// Best-effort UTxO cache invalidation (spent inputs, output addresses, sender);
|
|
698
|
+
// a failure must not fail the successful submit.
|
|
787
699
|
try {
|
|
788
700
|
const addrBuild = await db.run(SELECT.one.from(AddressTransactionBuilds).where({ txBuild_id: buildId }));
|
|
789
701
|
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor), addrBuild?.address_address ? [addrBuild.address_address] : []);
|
|
@@ -801,29 +713,20 @@ module.exports = (srv) => {
|
|
|
801
713
|
return submissionRecord;
|
|
802
714
|
});
|
|
803
715
|
});
|
|
804
|
-
|
|
805
|
-
* Submit signed transaction without prior build
|
|
806
|
-
* Handler validates, submits to blockchain, delegates persistence to indexer
|
|
807
|
-
* Two-phase: persist with 'pending' first, then update to 'submitted' or 'failed'
|
|
808
|
-
* @param req - CDS request object (with signedTxCbor, network)
|
|
809
|
-
* @returns {TransactionSubmission} Transaction submission details
|
|
810
|
-
*/
|
|
716
|
+
// SubmitSignedTransaction — submit externally built signed CBOR (no prior build).
|
|
811
717
|
srv.on('SubmitSignedTransaction', async (req) => {
|
|
812
718
|
logger.debug('SubmitSignedTransaction Action handler called');
|
|
813
719
|
const { signedTxCbor, network } = req.data;
|
|
814
|
-
// Validate inputs (includes CBOR format validation)
|
|
815
720
|
const errors = (0, validators_1.validateTransactionInputs)({ signedTxCbor }, ['signedTxCbor']);
|
|
816
721
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitSignedTransaction', errors);
|
|
817
722
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
818
|
-
//
|
|
819
|
-
// configured network so a caller targeting the wrong deployment gets a clear 400.
|
|
723
|
+
// A caller targeting the wrong deployment gets a clear 400
|
|
820
724
|
const configuredNetwork = (0, server_1.getCardanoClient)().network;
|
|
821
725
|
if (network && network !== configuredNetwork) {
|
|
822
726
|
return (0, errors_1.rejectInvalid)(req, 'SubmitSignedTransaction', `network '${network}' does not match this deployment's network '${configuredNetwork}'`, 'network');
|
|
823
727
|
}
|
|
824
|
-
// Extract txHash from signed CBOR
|
|
825
728
|
const txHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
826
|
-
// Two-phase submit: persist
|
|
729
|
+
// Two-phase submit: persist as 'pending', then submit
|
|
827
730
|
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
828
731
|
signedTxCbor,
|
|
829
732
|
txHash,
|
|
@@ -834,7 +737,7 @@ module.exports = (srv) => {
|
|
|
834
737
|
logger.info({ txHash }, 'External transaction submitted');
|
|
835
738
|
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
836
739
|
submissionRecord.status = 'submitted';
|
|
837
|
-
//
|
|
740
|
+
// Best-effort UTxO cache invalidation
|
|
838
741
|
try {
|
|
839
742
|
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor));
|
|
840
743
|
}
|
|
@@ -851,22 +754,14 @@ module.exports = (srv) => {
|
|
|
851
754
|
return submissionRecord;
|
|
852
755
|
});
|
|
853
756
|
});
|
|
854
|
-
|
|
855
|
-
* Check submission status (bound action on TransactionSubmissions)
|
|
856
|
-
* @flow.status validates @from: [#submitted] automatically (409 if wrong state)
|
|
857
|
-
* Queries blockchain for transaction confirmation and updates status accordingly
|
|
858
|
-
* @param req - CDS request with entity key in params
|
|
859
|
-
* @returns {TransactionSubmission} The updated transaction submission status
|
|
860
|
-
*/
|
|
757
|
+
// CheckSubmissionStatus — bound action; the @from: [#submitted] state gate is enforced by CAP.
|
|
861
758
|
srv.on('CheckSubmissionStatus', async (req) => {
|
|
862
759
|
logger.debug('CheckSubmissionStatus Action handler called');
|
|
863
760
|
const { id: submissionId } = req.params[0];
|
|
864
|
-
// @from: [#submitted] validated by framework — no manual status check needed
|
|
865
761
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
866
762
|
const submission = await db.run(SELECT.one.from(TransactionSubmissions).where({ id: submissionId }));
|
|
867
763
|
if (!submission)
|
|
868
764
|
throw new errors_1.NotFoundError(`Submission '${submissionId}'`);
|
|
869
|
-
// Query blockchain for confirmation
|
|
870
765
|
try {
|
|
871
766
|
const txDetails = await (0, server_1.getCardanoClient)().getTransaction(submission.txHash);
|
|
872
767
|
if (txDetails) {
|
|
@@ -880,11 +775,10 @@ module.exports = (srv) => {
|
|
|
880
775
|
catch (err) {
|
|
881
776
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
882
777
|
if (err instanceof errors_1.NotFoundError || err?.statusCode === 404) {
|
|
883
|
-
// Transaction genuinely not yet confirmed on chain
|
|
884
778
|
logger.debug({ submissionId, txHash: submission.txHash }, 'Transaction not yet confirmed on chain');
|
|
885
779
|
}
|
|
886
780
|
else {
|
|
887
|
-
//
|
|
781
|
+
// A provider error must not be masked as "pending"
|
|
888
782
|
logger.warn({ submissionId, txHash: submission.txHash, error: errMsg }, 'Failed to check transaction confirmation status');
|
|
889
783
|
throw err;
|
|
890
784
|
}
|
|
@@ -892,28 +786,19 @@ module.exports = (srv) => {
|
|
|
892
786
|
return submission;
|
|
893
787
|
});
|
|
894
788
|
});
|
|
895
|
-
|
|
896
|
-
* Get all existing transaction builds by address
|
|
897
|
-
* @param req - CDS request object (with address)
|
|
898
|
-
* @returns {AddressTransactionBuilds} Address transaction build associations
|
|
899
|
-
*/
|
|
789
|
+
// GetTransactionBuildsByAddress — address ↔ build associations.
|
|
900
790
|
srv.on('GetTransactionBuildsByAddress', async (req) => {
|
|
901
791
|
logger.debug('GetTransactionBuildsByAddress Action handler called');
|
|
902
792
|
const { address } = req.data;
|
|
903
|
-
// Validate inputs
|
|
904
793
|
if (!address)
|
|
905
794
|
return (0, errors_1.rejectMissing)(req, 'GetTransactionBuildsByAddress', 'address');
|
|
906
795
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
907
796
|
return (0, errors_1.rejectInvalid)(req, 'GetTransactionBuildsByAddress', 'Invalid bech32 address format', 'address');
|
|
908
|
-
// Fetch the address-build associations
|
|
909
797
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
910
798
|
return db.run(SELECT.from(AddressTransactionBuilds).where({ address_address: address }));
|
|
911
799
|
});
|
|
912
800
|
});
|
|
913
|
-
|
|
914
|
-
* Derive the enterprise script address + script hash for a validator script,
|
|
915
|
-
* optionally after applying PlutusData parameters. No transaction is built.
|
|
916
|
-
*/
|
|
801
|
+
// DeriveScriptAddress — enterprise address + hash of a validator, optionally parameterized.
|
|
917
802
|
srv.on('DeriveScriptAddress', async (req) => {
|
|
918
803
|
const { validatorScript, scriptParamsJson, network } = req.data;
|
|
919
804
|
if (!validatorScript)
|
|
@@ -935,9 +820,7 @@ module.exports = (srv) => {
|
|
|
935
820
|
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', `Invalid network "${network}". Must be one of: ${VALID_DERIVE_NETWORKS.join(', ')}`, 'network');
|
|
936
821
|
}
|
|
937
822
|
return (0, backend_request_handler_1.handleRequest)(req, async () => {
|
|
938
|
-
//
|
|
939
|
-
// is uninitialized. Resolving the network outside the inner CBOR try/catch
|
|
940
|
-
// keeps that 503 distinct from the 400 used for malformed validatorScript bytes.
|
|
823
|
+
// Resolved outside the CBOR try/catch so an uninitialized client stays a 503, not a 400.
|
|
941
824
|
const targetNetwork = network
|
|
942
825
|
? network
|
|
943
826
|
: (0, server_1.getCardanoClient)().network;
|
|
@@ -955,10 +838,7 @@ module.exports = (srv) => {
|
|
|
955
838
|
}
|
|
956
839
|
});
|
|
957
840
|
});
|
|
958
|
-
|
|
959
|
-
* Extract the 28-byte payment credential (key hash or script hash) from a Bech32
|
|
960
|
-
* Cardano address. Pure local decoding — no blockchain call.
|
|
961
|
-
*/
|
|
841
|
+
// ExtractPaymentKeyHash — 28-byte payment credential of a bech32 address; pure local decoding.
|
|
962
842
|
srv.on('ExtractPaymentKeyHash', async (req) => {
|
|
963
843
|
const { address } = req.data;
|
|
964
844
|
if (!address)
|
|
@@ -969,7 +849,7 @@ module.exports = (srv) => {
|
|
|
969
849
|
try {
|
|
970
850
|
const decoded = bech32_1.bech32.decode(address, const_1.BECH32_MAX_LENGTH);
|
|
971
851
|
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
972
|
-
//
|
|
852
|
+
// 1 header byte + 28-byte payment credential (+ optional 28-byte stake credential)
|
|
973
853
|
if (bytes.length < 29) {
|
|
974
854
|
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Address is too short to contain a payment credential', 'address');
|
|
975
855
|
}
|