@odatano/core 2.0.0-rc.4 → 2.0.0-rc.40
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 +305 -7
- package/@cds-models/CardanoODataService/index.js +34 -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 +46 -13
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +72 -0
- package/@cds-models/index.js +12 -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 +2297 -1633
- package/db/types.cds +114 -0
- package/package.json +27 -6
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +18 -11
- package/src/index.js +44 -14
- package/src/plugin.js +42 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +53 -162
- 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 +376 -235
- 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 +556 -201
- 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 +87 -202
- package/srv/blockchain/cardano-client.js +210 -240
- package/srv/blockchain/cardano-indexer.d.ts +311 -242
- package/srv/blockchain/cardano-indexer.js +1238 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
- package/srv/blockchain/cardano-tx-builder.js +173 -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 +14 -45
- package/srv/blockchain/signing/signature-verifier.js +73 -76
- 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 +111 -173
- package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
- 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 +18 -23
- 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 +65 -2
- package/srv/cardano-service.js +170 -129
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +57 -184
- package/srv/cardano-tx-service.cds +439 -370
- package/srv/cardano-tx-service.js +231 -190
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/index.d.ts +1 -1
- package/srv/cbor/parse.d.ts +27 -0
- package/srv/cbor/parse.js +63 -2
- package/srv/server.d.ts +28 -86
- package/srv/server.js +132 -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 +20 -0
- package/srv/utils/epoch-slots.js +43 -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/legacy-service-paths.d.ts +11 -0
- package/srv/utils/legacy-service-paths.js +58 -0
- 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 +6 -16
- package/srv/utils/signing-helper.js +36 -60
- package/srv/utils/tx-build-helper.d.ts +28 -93
- package/srv/utils/tx-build-helper.js +75 -124
- package/srv/utils/tx-request-parsers.d.ts +101 -28
- package/srv/utils/tx-request-parsers.js +410 -43
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +252 -179
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
|
@@ -12,47 +12,52 @@ const tx_build_helper_1 = require("./utils/tx-build-helper");
|
|
|
12
12
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
13
13
|
const mappers_1 = require("./utils/mappers");
|
|
14
14
|
const server_1 = require("./server");
|
|
15
|
+
const signing_helper_1 = require("./utils/signing-helper");
|
|
15
16
|
const const_1 = require("./utils/const");
|
|
16
17
|
const tx_request_parsers_1 = require("./utils/tx-request-parsers");
|
|
17
18
|
const VALID_DERIVE_NETWORKS = ['mainnet', 'preview', 'preprod'];
|
|
18
19
|
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
19
20
|
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
|
-
*/
|
|
21
|
+
/** CardanoTransactionService handlers: transaction building, submission and script helpers. */
|
|
24
22
|
module.exports = (srv) => {
|
|
25
23
|
logger.debug('Module loaded - registering handlers');
|
|
26
24
|
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
|
-
*/
|
|
25
|
+
// BuildSimpleAdaTransaction — ADA (optionally with assets / datum) to one recipient or a script.
|
|
32
26
|
srv.on('BuildSimpleAdaTransaction', async (req) => {
|
|
33
27
|
const { senderAddress, recipientAddress, lovelaceAmount, outputDatumJson, assetsJson, forceInputsJson, validatorScript, scriptParamsJson, lockOnScript, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
34
|
-
// validate inputs
|
|
35
28
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
36
29
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildSimpleAdaTransaction', errors);
|
|
37
30
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
38
31
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
39
32
|
}
|
|
40
|
-
// parse optional output datum
|
|
41
33
|
const cleanData = { ...req.data };
|
|
42
|
-
// parse optional forceInputsJson
|
|
43
34
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
44
35
|
if (forceInputsResult.error)
|
|
45
36
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
46
37
|
cleanData.forceInputs = forceInputsResult.parsed;
|
|
47
38
|
delete cleanData.forceInputsJson;
|
|
39
|
+
const protectInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(req.data.protectInputsJson, 'protectInputsJson');
|
|
40
|
+
if (protectInputsResult.error)
|
|
41
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', protectInputsResult.error, 'protectInputsJson');
|
|
42
|
+
cleanData.protectInputs = protectInputsResult.parsed;
|
|
43
|
+
delete cleanData.protectInputsJson;
|
|
48
44
|
if (outputDatumJson) {
|
|
49
|
-
const jsonResult = (0, validators_1.
|
|
45
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(outputDatumJson, 'outputDatumJson');
|
|
50
46
|
if (!jsonResult.valid)
|
|
51
47
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', jsonResult.error, 'outputDatumJson');
|
|
52
48
|
cleanData.outputDatum = jsonResult.parsed;
|
|
53
49
|
delete cleanData.outputDatumJson;
|
|
54
50
|
}
|
|
55
|
-
|
|
51
|
+
delete cleanData.outputDatumCbor;
|
|
52
|
+
if (req.data.outputDatumCbor != null) {
|
|
53
|
+
if (outputDatumJson)
|
|
54
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'outputDatumJson and outputDatumCbor exclude each other; pass one', 'outputDatumCbor');
|
|
55
|
+
const cbor = (0, tx_request_parsers_1.parsePlutusCbor)(req.data.outputDatumCbor, 'outputDatumCbor');
|
|
56
|
+
if (cbor.error)
|
|
57
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', cbor.error, 'outputDatumCbor');
|
|
58
|
+
cleanData.outputDatumCbor = cbor.hex;
|
|
59
|
+
}
|
|
60
|
+
// Native assets to lock at a script address
|
|
56
61
|
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
57
62
|
if (assetsResult.error)
|
|
58
63
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', assetsResult.error, 'assetsJson');
|
|
@@ -60,10 +65,10 @@ module.exports = (srv) => {
|
|
|
60
65
|
cleanData.assets = assetsResult.parsed;
|
|
61
66
|
delete cleanData.assetsJson;
|
|
62
67
|
}
|
|
63
|
-
//
|
|
68
|
+
// Parameters for a parameterized validator
|
|
64
69
|
let scriptParams;
|
|
65
70
|
if (scriptParamsJson) {
|
|
66
|
-
const jsonResult = (0, validators_1.
|
|
71
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
67
72
|
if (!jsonResult.valid)
|
|
68
73
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', jsonResult.error, 'scriptParamsJson');
|
|
69
74
|
scriptParams = jsonResult.parsed;
|
|
@@ -71,11 +76,10 @@ module.exports = (srv) => {
|
|
|
71
76
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
|
-
// lockOnScript requires a validatorScript to derive the target address from
|
|
75
79
|
if (lockOnScript && !validatorScript) {
|
|
76
80
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'lockOnScript requires validatorScript to derive the script address', 'validatorScript');
|
|
77
81
|
}
|
|
78
|
-
//
|
|
82
|
+
// lockOnScript: derive script hash + address and override the recipient before the build.
|
|
79
83
|
let derivedScriptHash;
|
|
80
84
|
let derivedScriptAddress;
|
|
81
85
|
if (lockOnScript && validatorScript) {
|
|
@@ -99,11 +103,10 @@ module.exports = (srv) => {
|
|
|
99
103
|
cleanData.referenceScript = referenceScriptHex;
|
|
100
104
|
}
|
|
101
105
|
delete cleanData.referenceScriptHex;
|
|
102
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
103
106
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
104
107
|
logger.debug({ senderAddress, recipientAddress: cleanData.recipientAddress, lovelaceAmount, hasDatum: !!outputDatumJson, hasAssets: !!assetsJson, lockOnScript: !!lockOnScript }, 'Building simple ADA transaction');
|
|
105
108
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexSimpleBuildResult(db, cleanData);
|
|
106
|
-
// Persist derived script address + hash on the build record
|
|
109
|
+
// Persist the derived script address + hash on the build record
|
|
107
110
|
if (lockOnScript && derivedScriptHash && derivedScriptAddress && buildResult.id) {
|
|
108
111
|
buildResult.scriptHash = derivedScriptHash;
|
|
109
112
|
buildResult.scriptAddress = derivedScriptAddress;
|
|
@@ -115,41 +118,29 @@ module.exports = (srv) => {
|
|
|
115
118
|
return buildResult;
|
|
116
119
|
});
|
|
117
120
|
});
|
|
118
|
-
|
|
119
|
-
* Build a transaction with metadata
|
|
120
|
-
* @param req - CDS request object
|
|
121
|
-
* @returns {TransactionBuild} Transaction build details
|
|
122
|
-
*/
|
|
121
|
+
// BuildTransactionWithMetadata — ADA transfer with auxiliary metadata.
|
|
123
122
|
srv.on('BuildTransactionWithMetadata', async (req) => {
|
|
124
123
|
const { senderAddress, recipientAddress, lovelaceAmount, metadataJson } = req.data;
|
|
125
|
-
// validate inputs (includes JSON parsing validation)
|
|
126
124
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, metadataJson }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'metadataJson']);
|
|
127
125
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildTransactionWithMetadata', errors);
|
|
128
126
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
129
127
|
return (0, errors_1.rejectInvalid)(req, 'BuildTransactionWithMetadata', 'Invalid changeAddress format', 'changeAddress');
|
|
130
128
|
}
|
|
131
|
-
//
|
|
129
|
+
// Already validated as JSON above
|
|
132
130
|
const parsedMetadata = JSON.parse(metadataJson);
|
|
133
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
134
131
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
135
132
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, metadataKeyCount: Object.keys(parsedMetadata).length }, 'Building transaction with metadata');
|
|
136
133
|
return await (0, server_1.getCardanoIndexer)().indexMetadataBuildResult(db, { ...req.data, metadataJson: parsedMetadata });
|
|
137
134
|
});
|
|
138
135
|
});
|
|
139
|
-
|
|
140
|
-
* Build a multi-asset transaction
|
|
141
|
-
* @param req CDS request object
|
|
142
|
-
* @returns {TransactionBuild} Transaction build details
|
|
143
|
-
*/
|
|
136
|
+
// BuildMultiAssetTransaction — ADA plus native assets to one recipient.
|
|
144
137
|
srv.on('BuildMultiAssetTransaction', async (req) => {
|
|
145
138
|
const { senderAddress, recipientAddress, lovelaceAmount, assetsJson, outputDatumJson, referenceScriptHex, validityStartMs, validityEndMs } = req.data;
|
|
146
|
-
// validate inputs (includes JSON parsing validation)
|
|
147
139
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, assetsJson, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'assetsJson']);
|
|
148
140
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildMultiAssetTransaction', errors);
|
|
149
141
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
150
142
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
151
143
|
}
|
|
152
|
-
// Parse and validate assetsJson entries (unit + quantity, like parseExtraOutputs)
|
|
153
144
|
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
154
145
|
if (assetsResult.error)
|
|
155
146
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', assetsResult.error, 'assetsJson');
|
|
@@ -157,22 +148,28 @@ module.exports = (srv) => {
|
|
|
157
148
|
if (!parsedAssets || parsedAssets.length === 0) {
|
|
158
149
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'assetsJson must contain at least one asset', 'assetsJson');
|
|
159
150
|
}
|
|
160
|
-
// Validation BEFORE handleRequest
|
|
161
151
|
const cleanData = { ...req.data };
|
|
162
152
|
delete cleanData.assetsJson;
|
|
163
|
-
// parse optional output datum
|
|
164
153
|
if (outputDatumJson) {
|
|
165
|
-
const jsonResult = (0, validators_1.
|
|
154
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(outputDatumJson, 'outputDatumJson');
|
|
166
155
|
if (!jsonResult.valid)
|
|
167
156
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', jsonResult.error, 'outputDatumJson');
|
|
168
157
|
cleanData.outputDatum = jsonResult.parsed;
|
|
169
158
|
delete cleanData.outputDatumJson;
|
|
170
159
|
}
|
|
160
|
+
delete cleanData.outputDatumCbor;
|
|
161
|
+
if (req.data.outputDatumCbor != null) {
|
|
162
|
+
if (outputDatumJson)
|
|
163
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'outputDatumJson and outputDatumCbor exclude each other; pass one', 'outputDatumCbor');
|
|
164
|
+
const cbor = (0, tx_request_parsers_1.parsePlutusCbor)(req.data.outputDatumCbor, 'outputDatumCbor');
|
|
165
|
+
if (cbor.error)
|
|
166
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', cbor.error, 'outputDatumCbor');
|
|
167
|
+
cleanData.outputDatumCbor = cbor.hex;
|
|
168
|
+
}
|
|
171
169
|
if (referenceScriptHex) {
|
|
172
170
|
cleanData.referenceScript = referenceScriptHex;
|
|
173
171
|
}
|
|
174
172
|
delete cleanData.referenceScriptHex;
|
|
175
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
176
173
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
177
174
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, assets: parsedAssets, hasDatum: !!outputDatumJson }, 'Building multi-asset transaction');
|
|
178
175
|
const result = await (0, server_1.getCardanoIndexer)().indexMultiAssetBuildResult(db, { ...cleanData, assets: parsedAssets });
|
|
@@ -180,20 +177,15 @@ module.exports = (srv) => {
|
|
|
180
177
|
return result;
|
|
181
178
|
});
|
|
182
179
|
});
|
|
183
|
-
|
|
184
|
-
* Build a minting transaction
|
|
185
|
-
* @param req CDS request object
|
|
186
|
-
* @returns {TransactionBuild} Transaction build details
|
|
187
|
-
*/
|
|
180
|
+
// BuildMintTransaction — mint/burn under one or more Plutus policies.
|
|
188
181
|
srv.on('BuildMintTransaction', async (req) => {
|
|
189
182
|
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
183
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, referenceScriptHex, metadataJson, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
192
184
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildMintTransaction', errors);
|
|
193
185
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
194
186
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
195
187
|
}
|
|
196
|
-
//
|
|
188
|
+
// Mint actions: quantities become bigint; bare asset names are expanded with the policy id.
|
|
197
189
|
const parsedMintActionsRaw = JSON.parse(mintActionsJson);
|
|
198
190
|
if (!Array.isArray(parsedMintActionsRaw)) {
|
|
199
191
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'mintActionsJson must be a JSON array', 'mintActionsJson');
|
|
@@ -202,7 +194,7 @@ module.exports = (srv) => {
|
|
|
202
194
|
if (!action || typeof action !== 'object') {
|
|
203
195
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Each mint action must be an object with assetUnit and quantity', 'mintActionsJson');
|
|
204
196
|
}
|
|
205
|
-
//
|
|
197
|
+
// Optional per-action mintingPolicyScript + redeemerJson
|
|
206
198
|
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
207
199
|
if (policyFields.error) {
|
|
208
200
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', policyFields.error, 'mintActionsJson');
|
|
@@ -253,15 +245,13 @@ module.exports = (srv) => {
|
|
|
253
245
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid quantity: "${action.quantity}" — cannot parse as integer`, 'mintActionsJson');
|
|
254
246
|
}
|
|
255
247
|
});
|
|
256
|
-
// Parse and validate optional requiredSignersJson
|
|
257
248
|
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
258
249
|
if (requiredSignersResult.error)
|
|
259
250
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
260
251
|
const requiredSigners = requiredSignersResult.parsed;
|
|
261
|
-
// Parse and validate optional scriptParamsJson
|
|
262
252
|
let scriptParams;
|
|
263
253
|
if (scriptParamsJson) {
|
|
264
|
-
const jsonResult = (0, validators_1.
|
|
254
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
265
255
|
if (!jsonResult.valid)
|
|
266
256
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'scriptParamsJson');
|
|
267
257
|
scriptParams = jsonResult.parsed;
|
|
@@ -269,43 +259,41 @@ module.exports = (srv) => {
|
|
|
269
259
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
270
260
|
}
|
|
271
261
|
}
|
|
272
|
-
// Parse and validate optional inlineDatumJson
|
|
273
262
|
let inlineDatum;
|
|
274
263
|
if (inlineDatumJson) {
|
|
275
|
-
const jsonResult = (0, validators_1.
|
|
264
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(inlineDatumJson, 'inlineDatumJson');
|
|
276
265
|
if (!jsonResult.valid)
|
|
277
266
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'inlineDatumJson');
|
|
278
267
|
inlineDatum = jsonResult.parsed;
|
|
279
268
|
}
|
|
280
|
-
// Parse and validate optional mintRedeemerJson
|
|
281
269
|
let mintRedeemer;
|
|
282
270
|
if (mintRedeemerJson) {
|
|
283
|
-
const jsonResult = (0, validators_1.
|
|
271
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(mintRedeemerJson, 'mintRedeemerJson');
|
|
284
272
|
if (!jsonResult.valid)
|
|
285
273
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'mintRedeemerJson');
|
|
286
274
|
mintRedeemer = jsonResult.parsed;
|
|
287
275
|
}
|
|
288
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
289
276
|
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
290
277
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
291
278
|
}
|
|
292
|
-
//
|
|
293
|
-
// token can sit on its own output with its own inline datum)
|
|
279
|
+
// extraOutputsJson: each minted token can sit on its own output with its own inline datum
|
|
294
280
|
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
295
281
|
if (extraOutputsResult.error)
|
|
296
282
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
297
283
|
const extraOutputs = extraOutputsResult.parsed;
|
|
298
|
-
// Parse and validate optional forceInputsJson
|
|
299
284
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
300
285
|
if (forceInputsResult.error)
|
|
301
286
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
302
287
|
const forceInputs = forceInputsResult.parsed;
|
|
303
|
-
|
|
288
|
+
const protectInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(req.data.protectInputsJson, 'protectInputsJson');
|
|
289
|
+
if (protectInputsResult.error)
|
|
290
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', protectInputsResult.error, 'protectInputsJson');
|
|
291
|
+
const protectInputs = protectInputsResult.parsed;
|
|
292
|
+
// CIP-31 reference inputs
|
|
304
293
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
305
294
|
if (refInputsResult.error)
|
|
306
295
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
307
296
|
const referenceInputs = refInputsResult.parsed;
|
|
308
|
-
// Parse and validate optional metadataJson
|
|
309
297
|
let parsedMetadata;
|
|
310
298
|
if (metadataJson) {
|
|
311
299
|
try {
|
|
@@ -319,10 +307,8 @@ module.exports = (srv) => {
|
|
|
319
307
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'metadataJson must be an object with numeric label keys', 'metadataJson');
|
|
320
308
|
}
|
|
321
309
|
}
|
|
322
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
323
310
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
324
311
|
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
312
|
const cleanData = { ...req.data };
|
|
327
313
|
delete cleanData.mintActionsJson;
|
|
328
314
|
delete cleanData.requiredSignersJson;
|
|
@@ -331,6 +317,7 @@ module.exports = (srv) => {
|
|
|
331
317
|
delete cleanData.mintRedeemerJson;
|
|
332
318
|
delete cleanData.lockOnScript;
|
|
333
319
|
delete cleanData.forceInputsJson;
|
|
320
|
+
delete cleanData.protectInputsJson;
|
|
334
321
|
delete cleanData.referenceInputsJson;
|
|
335
322
|
delete cleanData.extraOutputsJson;
|
|
336
323
|
if (parsedMetadata) {
|
|
@@ -343,13 +330,12 @@ module.exports = (srv) => {
|
|
|
343
330
|
cleanData.referenceScript = referenceScriptHex;
|
|
344
331
|
}
|
|
345
332
|
delete cleanData.referenceScriptHex;
|
|
346
|
-
//
|
|
333
|
+
// Parameterized policy: apply params, then expand bare asset names with the applied hash.
|
|
347
334
|
let finalMintingPolicyScript = mintingPolicyScript;
|
|
348
335
|
let effectivePolicyId;
|
|
349
336
|
if (scriptParams && scriptParams.length > 0) {
|
|
350
337
|
try {
|
|
351
338
|
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
339
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex'));
|
|
354
340
|
effectivePolicyId = appliedScript.hash.toString();
|
|
355
341
|
}
|
|
@@ -362,7 +348,7 @@ module.exports = (srv) => {
|
|
|
362
348
|
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
363
349
|
}
|
|
364
350
|
}
|
|
365
|
-
// lockOnScript: route output to the enterprise
|
|
351
|
+
// lockOnScript: route the output to the enterprise address of the applied script
|
|
366
352
|
if (lockOnScript) {
|
|
367
353
|
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, (0, server_1.getCardanoClient)().network);
|
|
368
354
|
cleanData.recipientAddress = scriptAddr;
|
|
@@ -374,9 +360,10 @@ module.exports = (srv) => {
|
|
|
374
360
|
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(mintingPolicyScript, 'hex')).hash.toString();
|
|
375
361
|
}
|
|
376
362
|
catch {
|
|
377
|
-
//
|
|
363
|
+
// Invalid script CBOR: skip the prefix check, the builder rejects it with its own message.
|
|
378
364
|
}
|
|
379
365
|
}
|
|
366
|
+
// Every action without its own policy must carry the top-level policy id prefix.
|
|
380
367
|
if (effectivePolicyId) {
|
|
381
368
|
const policyId = effectivePolicyId;
|
|
382
369
|
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
@@ -392,19 +379,16 @@ module.exports = (srv) => {
|
|
|
392
379
|
inlineDatum,
|
|
393
380
|
mintRedeemer,
|
|
394
381
|
forceInputs,
|
|
382
|
+
protectInputs,
|
|
395
383
|
referenceInputs,
|
|
396
384
|
extraOutputs
|
|
397
385
|
});
|
|
398
|
-
// Post-build:
|
|
386
|
+
// Post-build: CIP-14 fingerprint and scriptAddress
|
|
399
387
|
if (buildResult.scriptHash) {
|
|
400
388
|
const policyId = buildResult.scriptHash;
|
|
401
389
|
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.
|
|
390
|
+
// Fingerprint of the first minted asset. The policy id is taken from the unit, not from
|
|
391
|
+
// buildResult.scriptHash: a per-action policy may differ from the top-level script.
|
|
408
392
|
if (parsedMintActions.length > 0) {
|
|
409
393
|
const firstAssetUnit = parsedMintActions[0].assetUnit;
|
|
410
394
|
const firstPolicyId = firstAssetUnit.slice(0, const_1.POLICY_ID_HEX_LENGTH);
|
|
@@ -412,7 +396,7 @@ module.exports = (srv) => {
|
|
|
412
396
|
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(firstPolicyId, assetNameHex);
|
|
413
397
|
updates.fingerprint = buildResult.fingerprint;
|
|
414
398
|
}
|
|
415
|
-
// lockOnScript: persist the derived script address on the build record
|
|
399
|
+
// lockOnScript: persist the derived script address on the build record
|
|
416
400
|
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
417
401
|
buildResult.scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(policyId, (0, server_1.getCardanoClient)().network);
|
|
418
402
|
updates.scriptAddress = buildResult.scriptAddress;
|
|
@@ -425,36 +409,27 @@ module.exports = (srv) => {
|
|
|
425
409
|
return buildResult;
|
|
426
410
|
});
|
|
427
411
|
});
|
|
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
|
-
*/
|
|
412
|
+
// BuildPlutusSpendTransaction — consume a UTxO at a script address, optionally minting too.
|
|
433
413
|
srv.on('BuildPlutusSpendTransaction', async (req) => {
|
|
434
414
|
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
415
|
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'validatorScript', 'scriptTxHash', 'redeemerJson']);
|
|
437
416
|
(0, errors_1.throwIfValidationErrors)(req, 'BuildPlutusSpendTransaction', errors);
|
|
438
417
|
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
439
418
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
440
419
|
}
|
|
441
|
-
//
|
|
420
|
+
// A number: not covered by the required-fields check
|
|
442
421
|
if (scriptOutputIndex === undefined || scriptOutputIndex === null) {
|
|
443
422
|
return (0, errors_1.rejectMissing)(req, 'BuildPlutusSpendTransaction', 'scriptOutputIndex');
|
|
444
423
|
}
|
|
445
|
-
// Parse redeemer JSON
|
|
446
424
|
const parsedRedeemer = JSON.parse(redeemerJson);
|
|
447
|
-
// Parse optional datum JSON
|
|
448
425
|
const parsedDatum = datumJson ? JSON.parse(datumJson) : undefined;
|
|
449
|
-
// Parse and validate optional requiredSignersJson
|
|
450
426
|
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
451
427
|
if (requiredSignersResult.error)
|
|
452
428
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
453
429
|
const requiredSigners = requiredSignersResult.parsed;
|
|
454
|
-
// Parse and validate optional scriptParamsJson
|
|
455
430
|
let scriptParams;
|
|
456
431
|
if (scriptParamsJson) {
|
|
457
|
-
const jsonResult = (0, validators_1.
|
|
432
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
458
433
|
if (!jsonResult.valid)
|
|
459
434
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'scriptParamsJson');
|
|
460
435
|
scriptParams = jsonResult.parsed;
|
|
@@ -462,29 +437,29 @@ module.exports = (srv) => {
|
|
|
462
437
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
463
438
|
}
|
|
464
439
|
}
|
|
465
|
-
// Parse and validate optional inlineDatumJson
|
|
466
440
|
let inlineDatum;
|
|
467
441
|
if (inlineDatumJson) {
|
|
468
|
-
const jsonResult = (0, validators_1.
|
|
442
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(inlineDatumJson, 'inlineDatumJson');
|
|
469
443
|
if (!jsonResult.valid)
|
|
470
444
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'inlineDatumJson');
|
|
471
445
|
inlineDatum = jsonResult.parsed;
|
|
472
446
|
}
|
|
473
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
474
447
|
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
475
448
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
476
449
|
}
|
|
477
|
-
// Parse and validate optional forceInputsJson
|
|
478
450
|
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
479
451
|
if (forceInputsResult.error)
|
|
480
452
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
481
453
|
const forceInputs = forceInputsResult.parsed;
|
|
482
|
-
|
|
454
|
+
const protectInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(req.data.protectInputsJson, 'protectInputsJson');
|
|
455
|
+
if (protectInputsResult.error)
|
|
456
|
+
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', protectInputsResult.error, 'protectInputsJson');
|
|
457
|
+
const protectInputs = protectInputsResult.parsed;
|
|
458
|
+
// CIP-31 reference inputs
|
|
483
459
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
484
460
|
if (refInputsResult.error)
|
|
485
461
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
486
462
|
const referenceInputs = refInputsResult.parsed;
|
|
487
|
-
// Parse and validate optional extraOutputsJson
|
|
488
463
|
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
489
464
|
if (extraOutputsResult.error)
|
|
490
465
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
@@ -513,8 +488,7 @@ module.exports = (srv) => {
|
|
|
513
488
|
if (typeof action.assetUnit !== 'string') {
|
|
514
489
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Each mint action must have assetUnit string', 'mintActionsJson');
|
|
515
490
|
}
|
|
516
|
-
//
|
|
517
|
-
// (same rules as BuildMintTransaction).
|
|
491
|
+
// Optional per-action mintingPolicyScript + redeemerJson (same rules as BuildMintTransaction)
|
|
518
492
|
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
519
493
|
if (policyFields.error) {
|
|
520
494
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', policyFields.error, 'mintActionsJson');
|
|
@@ -554,7 +528,7 @@ module.exports = (srv) => {
|
|
|
554
528
|
};
|
|
555
529
|
});
|
|
556
530
|
if (mintRedeemerJson) {
|
|
557
|
-
const mrJson = (0, validators_1.
|
|
531
|
+
const mrJson = (0, validators_1.validatePlutusJson)(mintRedeemerJson, 'mintRedeemerJson');
|
|
558
532
|
if (!mrJson.valid)
|
|
559
533
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', mrJson.error, 'mintRedeemerJson');
|
|
560
534
|
parsedMintRedeemer = mrJson.parsed;
|
|
@@ -565,7 +539,6 @@ module.exports = (srv) => {
|
|
|
565
539
|
}
|
|
566
540
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
567
541
|
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, scriptTxHash, scriptOutputIndex }, 'Building Plutus spending transaction');
|
|
568
|
-
// Apply script parameters if provided (for parameterized validators)
|
|
569
542
|
let finalValidatorScript = validatorScript;
|
|
570
543
|
if (scriptParams && scriptParams.length > 0) {
|
|
571
544
|
try {
|
|
@@ -576,8 +549,8 @@ module.exports = (srv) => {
|
|
|
576
549
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Failed to apply script parameters: ${errMsg}`, 'scriptParamsJson');
|
|
577
550
|
}
|
|
578
551
|
}
|
|
579
|
-
//
|
|
580
|
-
//
|
|
552
|
+
// A mint policy byte-equal to the validator (multi-purpose script) reuses the
|
|
553
|
+
// params-applied validator hex; any other policy passes through unchanged.
|
|
581
554
|
let finalMintingPolicyScript;
|
|
582
555
|
if (parsedMintActions) {
|
|
583
556
|
finalMintingPolicyScript = (mintingPolicyScript === validatorScript)
|
|
@@ -598,22 +571,19 @@ module.exports = (srv) => {
|
|
|
598
571
|
}
|
|
599
572
|
}
|
|
600
573
|
}
|
|
601
|
-
//
|
|
602
|
-
//
|
|
603
|
-
// discards the unit's first 56 hex chars, so a mismatched prefix would mint a
|
|
604
|
-
// truncated asset name.
|
|
574
|
+
// Policy-id prefix check as in BuildMintTransaction: the builder discards the unit's
|
|
575
|
+
// first 56 hex chars, so a mismatched prefix would mint a truncated asset name.
|
|
605
576
|
if (finalMintingPolicyScript) {
|
|
606
577
|
let mintPolicyId;
|
|
607
578
|
try {
|
|
608
579
|
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
609
580
|
}
|
|
610
581
|
catch {
|
|
611
|
-
//
|
|
582
|
+
// Invalid script CBOR: skip the prefix check, the builder rejects it with its own message.
|
|
612
583
|
}
|
|
613
584
|
if (mintPolicyId) {
|
|
614
585
|
const policyId = mintPolicyId;
|
|
615
|
-
// Actions with
|
|
616
|
-
// against THAT script's policy id during parsing.
|
|
586
|
+
// Actions with a per-action script were already checked against that policy id.
|
|
617
587
|
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
618
588
|
if (mismatch) {
|
|
619
589
|
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');
|
|
@@ -635,6 +605,7 @@ module.exports = (srv) => {
|
|
|
635
605
|
requiredSigners,
|
|
636
606
|
inlineDatum,
|
|
637
607
|
forceInputs,
|
|
608
|
+
protectInputs,
|
|
638
609
|
referenceInputs,
|
|
639
610
|
extraOutputs,
|
|
640
611
|
mintActions: parsedMintActions,
|
|
@@ -649,12 +620,13 @@ module.exports = (srv) => {
|
|
|
649
620
|
delete cleanData.inlineDatumJson;
|
|
650
621
|
delete cleanData.lockOnScript;
|
|
651
622
|
delete cleanData.forceInputsJson;
|
|
623
|
+
delete cleanData.protectInputsJson;
|
|
652
624
|
delete cleanData.referenceInputsJson;
|
|
653
625
|
delete cleanData.extraOutputsJson;
|
|
654
626
|
delete cleanData.mintActionsJson;
|
|
655
627
|
delete cleanData.mintRedeemerJson;
|
|
656
628
|
delete cleanData.referenceScriptHex;
|
|
657
|
-
// lockOnScript: route continuing output to enterprise script address
|
|
629
|
+
// lockOnScript: route the continuing output to the enterprise script address
|
|
658
630
|
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
659
631
|
try {
|
|
660
632
|
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalValidatorScript, 'hex'));
|
|
@@ -669,7 +641,7 @@ module.exports = (srv) => {
|
|
|
669
641
|
}
|
|
670
642
|
}
|
|
671
643
|
const buildResult = await (0, server_1.getCardanoIndexer)().indexPlutusSpendBuildResult(db, cleanData);
|
|
672
|
-
// lockOnScript: persist the derived script address on the build record
|
|
644
|
+
// lockOnScript: persist the derived script address on the build record
|
|
673
645
|
if (lockOnScript && scriptParams && scriptParams.length > 0 && buildResult.scriptHash && buildResult.id) {
|
|
674
646
|
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(buildResult.scriptHash, (0, server_1.getCardanoClient)().network);
|
|
675
647
|
buildResult.scriptAddress = scriptAddr;
|
|
@@ -679,17 +651,130 @@ module.exports = (srv) => {
|
|
|
679
651
|
return buildResult;
|
|
680
652
|
});
|
|
681
653
|
});
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
654
|
+
// BuildPlutusTransaction — several script UTxOs in one transaction, each with its own redeemer.
|
|
655
|
+
srv.on('BuildPlutusTransaction', async (req) => {
|
|
656
|
+
const { senderAddress, changeAddress, scriptInputsJson, outputsJson, referenceInputsJson, forceInputsJson, protectInputsJson, withdrawalsJson, certificatesJson, requiredSignersJson, mintActionsJson, validityStartMs, validityEndMs } = req.data;
|
|
657
|
+
const action = 'BuildPlutusTransaction';
|
|
658
|
+
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, validityStartMs, validityEndMs }, ['senderAddress']);
|
|
659
|
+
(0, errors_1.throwIfValidationErrors)(req, action, errors);
|
|
660
|
+
if (changeAddress && !(0, validators_1.isValidBech32Address)(changeAddress)) {
|
|
661
|
+
return (0, errors_1.rejectInvalid)(req, action, 'Invalid changeAddress format', 'changeAddress');
|
|
662
|
+
}
|
|
663
|
+
const scriptInputsResult = (0, tx_request_parsers_1.parseScriptInputs)(scriptInputsJson);
|
|
664
|
+
if (scriptInputsResult.error)
|
|
665
|
+
return (0, errors_1.rejectInvalid)(req, action, scriptInputsResult.error, 'scriptInputsJson');
|
|
666
|
+
if (!outputsJson)
|
|
667
|
+
return (0, errors_1.rejectMissing)(req, action, 'outputsJson');
|
|
668
|
+
const outputsResult = (0, tx_request_parsers_1.parseOutputList)(outputsJson, 'outputsJson');
|
|
669
|
+
if (outputsResult.error)
|
|
670
|
+
return (0, errors_1.rejectInvalid)(req, action, outputsResult.error, 'outputsJson');
|
|
671
|
+
if (!outputsResult.parsed)
|
|
672
|
+
return (0, errors_1.rejectInvalid)(req, action, 'outputsJson must list at least one output', 'outputsJson');
|
|
673
|
+
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
674
|
+
if (refInputsResult.error)
|
|
675
|
+
return (0, errors_1.rejectInvalid)(req, action, refInputsResult.error, 'referenceInputsJson');
|
|
676
|
+
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
677
|
+
if (forceInputsResult.error)
|
|
678
|
+
return (0, errors_1.rejectInvalid)(req, action, forceInputsResult.error, 'forceInputsJson');
|
|
679
|
+
const protectInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(protectInputsJson, 'protectInputsJson');
|
|
680
|
+
if (protectInputsResult.error)
|
|
681
|
+
return (0, errors_1.rejectInvalid)(req, action, protectInputsResult.error, 'protectInputsJson');
|
|
682
|
+
const withdrawalsResult = (0, tx_request_parsers_1.parseWithdrawals)(withdrawalsJson);
|
|
683
|
+
if (withdrawalsResult.error)
|
|
684
|
+
return (0, errors_1.rejectInvalid)(req, action, withdrawalsResult.error, 'withdrawalsJson');
|
|
685
|
+
const certificatesResult = (0, tx_request_parsers_1.parseCertificates)(certificatesJson);
|
|
686
|
+
if (certificatesResult.error)
|
|
687
|
+
return (0, errors_1.rejectInvalid)(req, action, certificatesResult.error, 'certificatesJson');
|
|
688
|
+
const signersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
689
|
+
if (signersResult.error)
|
|
690
|
+
return (0, errors_1.rejectInvalid)(req, action, signersResult.error, 'requiredSignersJson');
|
|
691
|
+
const mintResult = (0, tx_request_parsers_1.parsePolicyMintActions)(mintActionsJson);
|
|
692
|
+
if (mintResult.error)
|
|
693
|
+
return (0, errors_1.rejectInvalid)(req, action, mintResult.error, 'mintActionsJson');
|
|
694
|
+
// Script params are applied here, so the builder sees the final validators
|
|
695
|
+
const scriptInputs = [];
|
|
696
|
+
for (const [i, si] of scriptInputsResult.parsed.entries()) {
|
|
697
|
+
let validatorScript = si.validatorScript;
|
|
698
|
+
if (validatorScript && si.scriptParams) {
|
|
699
|
+
try {
|
|
700
|
+
validatorScript = (0, tx_build_helper_1.applyScriptParameters)(validatorScript, si.scriptParams);
|
|
701
|
+
}
|
|
702
|
+
catch (err) {
|
|
703
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
704
|
+
return (0, errors_1.rejectInvalid)(req, action, `scriptInputs[${i}]: failed to apply script parameters: ${errMsg}`, 'scriptInputsJson');
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
scriptInputs.push({
|
|
708
|
+
txHash: si.txHash,
|
|
709
|
+
outputIndex: si.outputIndex,
|
|
710
|
+
...(validatorScript ? { validatorScript } : { referenceScript: si.referenceScript }),
|
|
711
|
+
redeemer: si.redeemer,
|
|
712
|
+
...(si.redeemerCbor ? { redeemerCbor: si.redeemerCbor } : {}),
|
|
713
|
+
...(si.datum !== undefined ? { datum: si.datum } : {}),
|
|
714
|
+
...(si.datumCbor ? { datumCbor: si.datumCbor } : {}),
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
// Same for the staking scripts of withdrawals and certificates
|
|
718
|
+
const stakingWitness = (w, at, field) => {
|
|
719
|
+
let stakingScript = w.stakingScript;
|
|
720
|
+
if (stakingScript && w.scriptParams) {
|
|
721
|
+
try {
|
|
722
|
+
stakingScript = (0, tx_build_helper_1.applyScriptParameters)(stakingScript, w.scriptParams);
|
|
723
|
+
}
|
|
724
|
+
catch (err) {
|
|
725
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
726
|
+
return { error: (0, errors_1.rejectInvalid)(req, action, `${at}: failed to apply script parameters: ${errMsg}`, field) };
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
parsed: {
|
|
731
|
+
...(stakingScript ? { stakingScript } : {}),
|
|
732
|
+
...(w.referenceScript ? { referenceScript: w.referenceScript } : {}),
|
|
733
|
+
...(w.redeemer !== undefined ? { redeemer: w.redeemer } : {}),
|
|
734
|
+
...(w.redeemerCbor ? { redeemerCbor: w.redeemerCbor } : {}),
|
|
735
|
+
},
|
|
736
|
+
};
|
|
737
|
+
};
|
|
738
|
+
const withdrawals = [];
|
|
739
|
+
for (const [i, w] of (withdrawalsResult.parsed ?? []).entries()) {
|
|
740
|
+
const witness = stakingWitness(w, `withdrawals[${i}]`, 'withdrawalsJson');
|
|
741
|
+
if ('error' in witness)
|
|
742
|
+
return witness.error;
|
|
743
|
+
withdrawals.push({ rewardAddress: w.rewardAddress, lovelace: w.lovelace, ...witness.parsed });
|
|
744
|
+
}
|
|
745
|
+
const certificates = [];
|
|
746
|
+
for (const [i, c] of (certificatesResult.parsed ?? []).entries()) {
|
|
747
|
+
const witness = stakingWitness(c, `certificates[${i}]`, 'certificatesJson');
|
|
748
|
+
if ('error' in witness)
|
|
749
|
+
return witness.error;
|
|
750
|
+
certificates.push({ type: c.type, stakeAddress: c.stakeAddress, ...(c.deposit ? { deposit: c.deposit } : {}), ...witness.parsed });
|
|
751
|
+
}
|
|
752
|
+
const buildReq = {
|
|
753
|
+
network: (0, server_1.getCardanoClient)().network,
|
|
754
|
+
senderAddress,
|
|
755
|
+
...(changeAddress ? { changeAddress } : {}),
|
|
756
|
+
scriptInputs,
|
|
757
|
+
outputs: outputsResult.parsed,
|
|
758
|
+
referenceInputs: refInputsResult.parsed,
|
|
759
|
+
forceInputs: forceInputsResult.parsed,
|
|
760
|
+
protectInputs: protectInputsResult.parsed,
|
|
761
|
+
...(withdrawals.length > 0 ? { withdrawals } : {}),
|
|
762
|
+
...(certificates.length > 0 ? { certificates } : {}),
|
|
763
|
+
requiredSigners: signersResult.parsed,
|
|
764
|
+
mintActions: mintResult.parsed,
|
|
765
|
+
validityStartMs,
|
|
766
|
+
validityEndMs,
|
|
767
|
+
};
|
|
768
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
769
|
+
logger.debug({ senderAddress, scriptInputs: scriptInputs.length, outputs: buildReq.outputs.length }, 'Building multi-script Plutus transaction');
|
|
770
|
+
return (0, server_1.getCardanoIndexer)().indexPlutusBuildResult(db, buildReq);
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
// GetBuildDetails — an existing transaction build by id.
|
|
687
774
|
srv.on('GetBuildDetails', async (req) => {
|
|
688
775
|
const { buildId } = req.data;
|
|
689
|
-
// Validate inputs
|
|
690
776
|
const errors = (0, validators_1.validateTransactionInputs)({ buildId }, ['buildId']);
|
|
691
777
|
(0, errors_1.throwIfValidationErrors)(req, 'GetBuildDetails', errors);
|
|
692
|
-
// handle the request / fetching the build details
|
|
693
778
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
694
779
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
695
780
|
if (!existing)
|
|
@@ -697,13 +782,8 @@ module.exports = (srv) => {
|
|
|
697
782
|
return existing;
|
|
698
783
|
});
|
|
699
784
|
});
|
|
700
|
-
|
|
701
|
-
|
|
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
|
-
*/
|
|
785
|
+
// SetCollateral — collateral is available when the builders would find it: an ADA-only UTxO of
|
|
786
|
+
// >= 5 ADA without a reference script, plus another UTxO to fund with; otherwise a self-send creates one.
|
|
707
787
|
srv.on('SetCollateral', async (req) => {
|
|
708
788
|
const { address } = req.data;
|
|
709
789
|
if (!address)
|
|
@@ -712,17 +792,15 @@ module.exports = (srv) => {
|
|
|
712
792
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'Invalid Bech32 address format', 'address');
|
|
713
793
|
}
|
|
714
794
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
715
|
-
// Inside handleRequest
|
|
716
|
-
//
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
// mapError sees a typed BackendError and preserves the 400 status.
|
|
720
|
-
const utxos = await (0, server_1.getCardanoClient)().getAddressUtxos(address);
|
|
795
|
+
// Inside handleRequest use rejectInvalid (typed BackendError 400), not req.reject,
|
|
796
|
+
// so mapError preserves the status.
|
|
797
|
+
const ledger = await (0, server_1.getCardanoIndexer)().resolveAddressUtxos(db, address);
|
|
798
|
+
const utxos = (0, server_1.getCardanoClient)().pendingSpends?.apply(address, ledger) ?? ledger;
|
|
721
799
|
if (utxos.length === 0) {
|
|
722
800
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'No UTxOs found at address', 'address');
|
|
723
801
|
}
|
|
724
|
-
const qualifyingUtxos = utxos.filter(u => (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE);
|
|
725
|
-
if (qualifyingUtxos.length >= 2) {
|
|
802
|
+
const qualifyingUtxos = utxos.filter(u => (0, tx_build_helper_1.isCollateralCandidate)(u) && (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE);
|
|
803
|
+
if (qualifyingUtxos.length >= 1 && utxos.length >= 2) {
|
|
726
804
|
return {
|
|
727
805
|
id: cds_1.default.utils.uuid(),
|
|
728
806
|
network: (0, server_1.getCardanoClient)().network,
|
|
@@ -745,32 +823,26 @@ module.exports = (srv) => {
|
|
|
745
823
|
return { ...result, collateralAvailable: false };
|
|
746
824
|
});
|
|
747
825
|
});
|
|
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
|
-
*/
|
|
826
|
+
// SubmitTransaction — submit the signed CBOR of a previous build.
|
|
754
827
|
srv.on('SubmitTransaction', async (req) => {
|
|
755
828
|
logger.debug('SubmitTransaction Action handler called');
|
|
756
|
-
const { buildId, signedTxCbor } = req.data;
|
|
757
|
-
|
|
758
|
-
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor }, ['buildId', 'signedTxCbor']);
|
|
829
|
+
const { buildId, signedTxCbor: signedInput } = req.data;
|
|
830
|
+
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor: signedInput }, ['buildId', 'signedTxCbor']);
|
|
759
831
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitTransaction', errors);
|
|
760
832
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
761
833
|
logger.debug({ buildId }, 'Submitting signed transaction');
|
|
762
|
-
// Validate build exists
|
|
763
834
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
764
835
|
if (!existing)
|
|
765
836
|
throw new errors_1.NotFoundError(`Build '${buildId}'`);
|
|
766
|
-
//
|
|
837
|
+
// A CIP-30 wallet returns only the witness set; cardano-cli a full signed tx.
|
|
838
|
+
const signedTxCbor = (0, signing_helper_1.toSignedTransaction)(existing.unsignedTxCbor, signedInput);
|
|
839
|
+
// The signed CBOR must belong to this build (audit-trail integrity)
|
|
767
840
|
const signedTxHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
768
841
|
if (signedTxHash !== existing.txBodyHash) {
|
|
769
842
|
return (0, errors_1.rejectInvalid)(req, 'SubmitTransaction', `signedTxCbor hash '${signedTxHash}' does not match build txBodyHash '${existing.txBodyHash}'`, 'signedTxCbor');
|
|
770
843
|
}
|
|
771
|
-
// Use txBodyHash from build
|
|
772
844
|
const txHash = existing.txBodyHash;
|
|
773
|
-
// Two-phase submit: persist
|
|
845
|
+
// Two-phase submit: persist as 'pending', then submit
|
|
774
846
|
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
775
847
|
signedTxCbor,
|
|
776
848
|
txHash,
|
|
@@ -781,9 +853,8 @@ module.exports = (srv) => {
|
|
|
781
853
|
logger.info({ txHash }, 'Transaction submitted to blockchain');
|
|
782
854
|
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
783
855
|
submissionRecord.status = 'submitted';
|
|
784
|
-
//
|
|
785
|
-
//
|
|
786
|
-
// failure here must not fail the already-successful submit.
|
|
856
|
+
// Best-effort UTxO cache invalidation (spent inputs, output addresses, sender);
|
|
857
|
+
// a failure must not fail the successful submit.
|
|
787
858
|
try {
|
|
788
859
|
const addrBuild = await db.run(SELECT.one.from(AddressTransactionBuilds).where({ txBuild_id: buildId }));
|
|
789
860
|
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor), addrBuild?.address_address ? [addrBuild.address_address] : []);
|
|
@@ -801,29 +872,20 @@ module.exports = (srv) => {
|
|
|
801
872
|
return submissionRecord;
|
|
802
873
|
});
|
|
803
874
|
});
|
|
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
|
-
*/
|
|
875
|
+
// SubmitSignedTransaction — submit externally built signed CBOR (no prior build).
|
|
811
876
|
srv.on('SubmitSignedTransaction', async (req) => {
|
|
812
877
|
logger.debug('SubmitSignedTransaction Action handler called');
|
|
813
878
|
const { signedTxCbor, network } = req.data;
|
|
814
|
-
// Validate inputs (includes CBOR format validation)
|
|
815
879
|
const errors = (0, validators_1.validateTransactionInputs)({ signedTxCbor }, ['signedTxCbor']);
|
|
816
880
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitSignedTransaction', errors);
|
|
817
881
|
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.
|
|
882
|
+
// A caller targeting the wrong deployment gets a clear 400
|
|
820
883
|
const configuredNetwork = (0, server_1.getCardanoClient)().network;
|
|
821
884
|
if (network && network !== configuredNetwork) {
|
|
822
885
|
return (0, errors_1.rejectInvalid)(req, 'SubmitSignedTransaction', `network '${network}' does not match this deployment's network '${configuredNetwork}'`, 'network');
|
|
823
886
|
}
|
|
824
|
-
// Extract txHash from signed CBOR
|
|
825
887
|
const txHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
826
|
-
// Two-phase submit: persist
|
|
888
|
+
// Two-phase submit: persist as 'pending', then submit
|
|
827
889
|
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
828
890
|
signedTxCbor,
|
|
829
891
|
txHash,
|
|
@@ -834,7 +896,7 @@ module.exports = (srv) => {
|
|
|
834
896
|
logger.info({ txHash }, 'External transaction submitted');
|
|
835
897
|
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
836
898
|
submissionRecord.status = 'submitted';
|
|
837
|
-
//
|
|
899
|
+
// Best-effort UTxO cache invalidation
|
|
838
900
|
try {
|
|
839
901
|
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor));
|
|
840
902
|
}
|
|
@@ -851,24 +913,18 @@ module.exports = (srv) => {
|
|
|
851
913
|
return submissionRecord;
|
|
852
914
|
});
|
|
853
915
|
});
|
|
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
|
-
*/
|
|
916
|
+
// CheckSubmissionStatus — bound action; the @from: [#submitted] state gate is enforced by CAP.
|
|
861
917
|
srv.on('CheckSubmissionStatus', async (req) => {
|
|
862
918
|
logger.debug('CheckSubmissionStatus Action handler called');
|
|
863
919
|
const { id: submissionId } = req.params[0];
|
|
864
|
-
// @from: [#submitted] validated by framework — no manual status check needed
|
|
865
920
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
866
921
|
const submission = await db.run(SELECT.one.from(TransactionSubmissions).where({ id: submissionId }));
|
|
867
922
|
if (!submission)
|
|
868
923
|
throw new errors_1.NotFoundError(`Submission '${submissionId}'`);
|
|
869
|
-
// Query blockchain for confirmation
|
|
870
924
|
try {
|
|
871
|
-
|
|
925
|
+
// the local index first (filled by the crawler), then the backends
|
|
926
|
+
const txDetails = await (0, server_1.getCardanoIndexer)().findIndexedTransaction(db, submission.txHash)
|
|
927
|
+
?? await (0, server_1.getCardanoClient)().getTransaction(submission.txHash);
|
|
872
928
|
if (txDetails) {
|
|
873
929
|
await db.run(UPDATE.entity(TransactionSubmissions)
|
|
874
930
|
.set({ status: 'confirmed' })
|
|
@@ -880,11 +936,10 @@ module.exports = (srv) => {
|
|
|
880
936
|
catch (err) {
|
|
881
937
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
882
938
|
if (err instanceof errors_1.NotFoundError || err?.statusCode === 404) {
|
|
883
|
-
// Transaction genuinely not yet confirmed on chain
|
|
884
939
|
logger.debug({ submissionId, txHash: submission.txHash }, 'Transaction not yet confirmed on chain');
|
|
885
940
|
}
|
|
886
941
|
else {
|
|
887
|
-
//
|
|
942
|
+
// A provider error must not be masked as "pending"
|
|
888
943
|
logger.warn({ submissionId, txHash: submission.txHash, error: errMsg }, 'Failed to check transaction confirmation status');
|
|
889
944
|
throw err;
|
|
890
945
|
}
|
|
@@ -892,28 +947,19 @@ module.exports = (srv) => {
|
|
|
892
947
|
return submission;
|
|
893
948
|
});
|
|
894
949
|
});
|
|
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
|
-
*/
|
|
950
|
+
// GetTransactionBuildsByAddress — address ↔ build associations.
|
|
900
951
|
srv.on('GetTransactionBuildsByAddress', async (req) => {
|
|
901
952
|
logger.debug('GetTransactionBuildsByAddress Action handler called');
|
|
902
953
|
const { address } = req.data;
|
|
903
|
-
// Validate inputs
|
|
904
954
|
if (!address)
|
|
905
955
|
return (0, errors_1.rejectMissing)(req, 'GetTransactionBuildsByAddress', 'address');
|
|
906
956
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
907
957
|
return (0, errors_1.rejectInvalid)(req, 'GetTransactionBuildsByAddress', 'Invalid bech32 address format', 'address');
|
|
908
|
-
// Fetch the address-build associations
|
|
909
958
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
910
959
|
return db.run(SELECT.from(AddressTransactionBuilds).where({ address_address: address }));
|
|
911
960
|
});
|
|
912
961
|
});
|
|
913
|
-
|
|
914
|
-
* Derive the enterprise script address + script hash for a validator script,
|
|
915
|
-
* optionally after applying PlutusData parameters. No transaction is built.
|
|
916
|
-
*/
|
|
962
|
+
// DeriveScriptAddress — enterprise address + hash of a validator, optionally parameterized.
|
|
917
963
|
srv.on('DeriveScriptAddress', async (req) => {
|
|
918
964
|
const { validatorScript, scriptParamsJson, network } = req.data;
|
|
919
965
|
if (!validatorScript)
|
|
@@ -923,7 +969,7 @@ module.exports = (srv) => {
|
|
|
923
969
|
}
|
|
924
970
|
let scriptParams;
|
|
925
971
|
if (scriptParamsJson) {
|
|
926
|
-
const jsonResult = (0, validators_1.
|
|
972
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
927
973
|
if (!jsonResult.valid)
|
|
928
974
|
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', jsonResult.error, 'scriptParamsJson');
|
|
929
975
|
if (!Array.isArray(jsonResult.parsed)) {
|
|
@@ -935,9 +981,7 @@ module.exports = (srv) => {
|
|
|
935
981
|
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', `Invalid network "${network}". Must be one of: ${VALID_DERIVE_NETWORKS.join(', ')}`, 'network');
|
|
936
982
|
}
|
|
937
983
|
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.
|
|
984
|
+
// Resolved outside the CBOR try/catch so an uninitialized client stays a 503, not a 400.
|
|
941
985
|
const targetNetwork = network
|
|
942
986
|
? network
|
|
943
987
|
: (0, server_1.getCardanoClient)().network;
|
|
@@ -955,10 +999,7 @@ module.exports = (srv) => {
|
|
|
955
999
|
}
|
|
956
1000
|
});
|
|
957
1001
|
});
|
|
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
|
-
*/
|
|
1002
|
+
// ExtractPaymentKeyHash — 28-byte payment credential of a bech32 address; pure local decoding.
|
|
962
1003
|
srv.on('ExtractPaymentKeyHash', async (req) => {
|
|
963
1004
|
const { address } = req.data;
|
|
964
1005
|
if (!address)
|
|
@@ -969,7 +1010,7 @@ module.exports = (srv) => {
|
|
|
969
1010
|
try {
|
|
970
1011
|
const decoded = bech32_1.bech32.decode(address, const_1.BECH32_MAX_LENGTH);
|
|
971
1012
|
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
972
|
-
//
|
|
1013
|
+
// 1 header byte + 28-byte payment credential (+ optional 28-byte stake credential)
|
|
973
1014
|
if (bytes.length < 29) {
|
|
974
1015
|
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Address is too short to contain a payment credential', 'address');
|
|
975
1016
|
}
|