@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
|
@@ -4,692 +4,259 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
7
|
-
const bech32_1 = require("bech32");
|
|
8
7
|
const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
9
8
|
const errors_1 = require("./utils/errors");
|
|
9
|
+
const resolution_1 = require("./utils/resolution");
|
|
10
10
|
const validators_1 = require("./utils/validators");
|
|
11
11
|
const tx_build_helper_1 = require("./utils/tx-build-helper");
|
|
12
|
-
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
13
12
|
const mappers_1 = require("./utils/mappers");
|
|
14
13
|
const server_1 = require("./server");
|
|
14
|
+
const signing_helper_1 = require("./utils/signing-helper");
|
|
15
|
+
const tx_utils_1 = require("./utils/tx-utils");
|
|
16
|
+
const paging_1 = require("./utils/paging");
|
|
17
|
+
const submission_finalizer_1 = require("./blockchain/signing/submission-finalizer");
|
|
18
|
+
const landing_proof_1 = require("./blockchain/signing/landing-proof");
|
|
19
|
+
const CardanoTransactionService_1 = require("#cds-models/CardanoTransactionService");
|
|
15
20
|
const const_1 = require("./utils/const");
|
|
21
|
+
const result_numbers_1 = require("./utils/result-numbers");
|
|
16
22
|
const tx_request_parsers_1 = require("./utils/tx-request-parsers");
|
|
17
|
-
const
|
|
23
|
+
const build_request_1 = require("./utils/build-request");
|
|
18
24
|
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
25
|
+
/** Blocks on top of a submitted transaction, its own included, before CheckSubmissionStatus confirms it. */
|
|
26
|
+
const SUBMISSION_CONFIRMATION_DEPTH = 3;
|
|
19
27
|
const logger = cds_1.default.log('CardanoTxService');
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
/** The network, read only where a script address is derived. */
|
|
29
|
+
const networkOf = () => (0, server_1.getCardanoClient)().network;
|
|
30
|
+
/** Answers a request the shared preparation refused: a missing field, or the reason and its field. */
|
|
31
|
+
function refuse(req, action, refusal) {
|
|
32
|
+
if (refusal.missing && refusal.field)
|
|
33
|
+
return (0, errors_1.rejectMissing)(req, action, refusal.field);
|
|
34
|
+
return (0, errors_1.rejectInvalid)(req, action, refusal.error, refusal.field);
|
|
35
|
+
}
|
|
36
|
+
/** The prepared request, or the answer: a refusal, or what a server that is not ready says. */
|
|
37
|
+
function prepareOrAnswer(req, action, prepare) {
|
|
38
|
+
let result;
|
|
39
|
+
try {
|
|
40
|
+
result = prepare();
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
return (0, mappers_1.mapError)(req, err, action);
|
|
44
|
+
}
|
|
45
|
+
if ('error' in result)
|
|
46
|
+
return refuse(req, action, result);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
/** CardanoTransactionService handlers: transaction building, submission and script helpers. */
|
|
24
50
|
module.exports = (srv) => {
|
|
51
|
+
(0, result_numbers_1.answerNumbersAsText)(srv);
|
|
25
52
|
logger.debug('Module loaded - registering handlers');
|
|
26
|
-
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
|
-
*/
|
|
53
|
+
const { TransactionBuilds, TransactionBuildRedeemers, TransactionSubmissions, AddressTransactionBuilds } = require('#cds-models/CardanoTransactionService');
|
|
54
|
+
// BuildSimpleAdaTransaction: ADA (optionally with assets / datum) to one recipient or a script.
|
|
32
55
|
srv.on('BuildSimpleAdaTransaction', async (req) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, referenceScriptHex, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
36
|
-
(0, errors_1.throwIfValidationErrors)(req, 'BuildSimpleAdaTransaction', errors);
|
|
37
|
-
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
38
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
39
|
-
}
|
|
40
|
-
// parse optional output datum
|
|
41
|
-
const cleanData = { ...req.data };
|
|
42
|
-
// parse optional forceInputsJson
|
|
43
|
-
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
44
|
-
if (forceInputsResult.error)
|
|
45
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
46
|
-
cleanData.forceInputs = forceInputsResult.parsed;
|
|
47
|
-
delete cleanData.forceInputsJson;
|
|
48
|
-
if (outputDatumJson) {
|
|
49
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(outputDatumJson, 'outputDatumJson');
|
|
50
|
-
if (!jsonResult.valid)
|
|
51
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', jsonResult.error, 'outputDatumJson');
|
|
52
|
-
cleanData.outputDatum = jsonResult.parsed;
|
|
53
|
-
delete cleanData.outputDatumJson;
|
|
54
|
-
}
|
|
55
|
-
// parse optional assets JSON (for locking native assets at script addresses)
|
|
56
|
-
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
57
|
-
if (assetsResult.error)
|
|
58
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', assetsResult.error, 'assetsJson');
|
|
59
|
-
if (assetsResult.parsed) {
|
|
60
|
-
cleanData.assets = assetsResult.parsed;
|
|
61
|
-
delete cleanData.assetsJson;
|
|
62
|
-
}
|
|
63
|
-
// parse optional scriptParamsJson (for parameterized validators)
|
|
64
|
-
let scriptParams;
|
|
65
|
-
if (scriptParamsJson) {
|
|
66
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
67
|
-
if (!jsonResult.valid)
|
|
68
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', jsonResult.error, 'scriptParamsJson');
|
|
69
|
-
scriptParams = jsonResult.parsed;
|
|
70
|
-
if (!Array.isArray(scriptParams)) {
|
|
71
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// lockOnScript requires a validatorScript to derive the target address from
|
|
75
|
-
if (lockOnScript && !validatorScript) {
|
|
76
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', 'lockOnScript requires validatorScript to derive the script address', 'validatorScript');
|
|
77
|
-
}
|
|
78
|
-
// Pre-compute script hash + address when lockOnScript is set; override recipient before build.
|
|
79
|
-
let derivedScriptHash;
|
|
80
|
-
let derivedScriptAddress;
|
|
81
|
-
if (lockOnScript && validatorScript) {
|
|
82
|
-
try {
|
|
83
|
-
const finalScript = scriptParams && scriptParams.length > 0
|
|
84
|
-
? (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams)
|
|
85
|
-
: validatorScript;
|
|
86
|
-
derivedScriptHash = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalScript, 'hex')).hash.toString();
|
|
87
|
-
derivedScriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(derivedScriptHash, (0, server_1.getCardanoClient)().network);
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
91
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', `Failed to derive script address: ${errMsg}`, 'validatorScript');
|
|
92
|
-
}
|
|
93
|
-
cleanData.recipientAddress = derivedScriptAddress;
|
|
94
|
-
}
|
|
95
|
-
delete cleanData.validatorScript;
|
|
96
|
-
delete cleanData.scriptParamsJson;
|
|
97
|
-
delete cleanData.lockOnScript;
|
|
98
|
-
if (referenceScriptHex) {
|
|
99
|
-
cleanData.referenceScript = referenceScriptHex;
|
|
100
|
-
}
|
|
101
|
-
delete cleanData.referenceScriptHex;
|
|
102
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
56
|
+
const action = 'BuildSimpleAdaTransaction';
|
|
57
|
+
const { request, scriptHash, scriptAddress } = prepareOrAnswer(req, action, () => (0, build_request_1.prepareSimpleAdaRequest)(req.data, networkOf));
|
|
103
58
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
104
|
-
logger.debug({ senderAddress, recipientAddress:
|
|
105
|
-
const buildResult = await (0, server_1.getCardanoIndexer)().indexSimpleBuildResult(db,
|
|
106
|
-
//
|
|
107
|
-
if (
|
|
108
|
-
buildResult.scriptHash =
|
|
109
|
-
buildResult.scriptAddress =
|
|
110
|
-
|
|
111
|
-
await db.run(UPDATE.entity(TransactionBuilds)
|
|
112
|
-
.set({ scriptHash: derivedScriptHash, scriptAddress: derivedScriptAddress })
|
|
113
|
-
.where({ id: buildResult.id }));
|
|
59
|
+
logger.debug({ senderAddress: request.senderAddress, recipientAddress: request.recipientAddress, lockOnScript: !!scriptAddress }, 'Building simple ADA transaction');
|
|
60
|
+
const buildResult = await (0, server_1.getCardanoIndexer)().indexSimpleBuildResult(db, request);
|
|
61
|
+
// the derived script address and hash go on the build record
|
|
62
|
+
if (scriptHash && scriptAddress && buildResult.id) {
|
|
63
|
+
buildResult.scriptHash = scriptHash;
|
|
64
|
+
buildResult.scriptAddress = scriptAddress;
|
|
65
|
+
await db.run(UPDATE.entity(TransactionBuilds).set({ scriptHash, scriptAddress }).where({ id: buildResult.id }));
|
|
114
66
|
}
|
|
115
67
|
return buildResult;
|
|
116
68
|
});
|
|
117
69
|
});
|
|
118
|
-
|
|
119
|
-
* Build a transaction with metadata
|
|
120
|
-
* @param req - CDS request object
|
|
121
|
-
* @returns {TransactionBuild} Transaction build details
|
|
122
|
-
*/
|
|
70
|
+
// BuildTransactionWithMetadata: ADA transfer with auxiliary metadata.
|
|
123
71
|
srv.on('BuildTransactionWithMetadata', async (req) => {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
(0, errors_1.throwIfValidationErrors)(req, 'BuildTransactionWithMetadata', errors);
|
|
128
|
-
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
129
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildTransactionWithMetadata', 'Invalid changeAddress format', 'changeAddress');
|
|
130
|
-
}
|
|
131
|
-
// Parse metadataJson (already validated as valid JSON)
|
|
132
|
-
const parsedMetadata = JSON.parse(metadataJson);
|
|
133
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
72
|
+
const prepared = (0, build_request_1.prepareMetadataRequest)(req.data);
|
|
73
|
+
if ('error' in prepared)
|
|
74
|
+
return refuse(req, 'BuildTransactionWithMetadata', prepared);
|
|
134
75
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
135
|
-
logger.debug({ senderAddress, recipientAddress
|
|
136
|
-
return
|
|
76
|
+
logger.debug({ senderAddress: prepared.request.senderAddress, recipientAddress: prepared.request.recipientAddress }, 'Building transaction with metadata');
|
|
77
|
+
return (0, server_1.getCardanoIndexer)().indexMetadataBuildResult(db, prepared.request);
|
|
137
78
|
});
|
|
138
79
|
});
|
|
139
|
-
|
|
140
|
-
* Build a multi-asset transaction
|
|
141
|
-
* @param req CDS request object
|
|
142
|
-
* @returns {TransactionBuild} Transaction build details
|
|
143
|
-
*/
|
|
80
|
+
// BuildMultiAssetTransaction: ADA plus native assets to one recipient.
|
|
144
81
|
srv.on('BuildMultiAssetTransaction', async (req) => {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(0, errors_1.throwIfValidationErrors)(req, 'BuildMultiAssetTransaction', errors);
|
|
149
|
-
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
150
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
151
|
-
}
|
|
152
|
-
// Parse and validate assetsJson entries (unit + quantity, like parseExtraOutputs)
|
|
153
|
-
const assetsResult = (0, tx_request_parsers_1.parseAssetsArray)(assetsJson, 'assetsJson');
|
|
154
|
-
if (assetsResult.error)
|
|
155
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', assetsResult.error, 'assetsJson');
|
|
156
|
-
const parsedAssets = assetsResult.parsed;
|
|
157
|
-
if (!parsedAssets || parsedAssets.length === 0) {
|
|
158
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', 'assetsJson must contain at least one asset', 'assetsJson');
|
|
159
|
-
}
|
|
160
|
-
// Validation BEFORE handleRequest
|
|
161
|
-
const cleanData = { ...req.data };
|
|
162
|
-
delete cleanData.assetsJson;
|
|
163
|
-
// parse optional output datum
|
|
164
|
-
if (outputDatumJson) {
|
|
165
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(outputDatumJson, 'outputDatumJson');
|
|
166
|
-
if (!jsonResult.valid)
|
|
167
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', jsonResult.error, 'outputDatumJson');
|
|
168
|
-
cleanData.outputDatum = jsonResult.parsed;
|
|
169
|
-
delete cleanData.outputDatumJson;
|
|
170
|
-
}
|
|
171
|
-
if (referenceScriptHex) {
|
|
172
|
-
cleanData.referenceScript = referenceScriptHex;
|
|
173
|
-
}
|
|
174
|
-
delete cleanData.referenceScriptHex;
|
|
175
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
82
|
+
const prepared = (0, build_request_1.prepareMultiAssetRequest)(req.data);
|
|
83
|
+
if ('error' in prepared)
|
|
84
|
+
return refuse(req, 'BuildMultiAssetTransaction', prepared);
|
|
176
85
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
177
|
-
logger.debug({ senderAddress
|
|
178
|
-
const result = await (0, server_1.getCardanoIndexer)().indexMultiAssetBuildResult(db,
|
|
86
|
+
logger.debug({ senderAddress: prepared.request.senderAddress, assets: prepared.request.assets?.length ?? 0 }, 'Building multi-asset transaction');
|
|
87
|
+
const result = await (0, server_1.getCardanoIndexer)().indexMultiAssetBuildResult(db, prepared.request);
|
|
179
88
|
logger.debug({ id: result.id, fee: result.fee, size: result.size }, 'Multi-asset transaction build result');
|
|
180
89
|
return result;
|
|
181
90
|
});
|
|
182
91
|
});
|
|
183
|
-
|
|
184
|
-
* Build a minting transaction
|
|
185
|
-
* @param req CDS request object
|
|
186
|
-
* @returns {TransactionBuild} Transaction build details
|
|
187
|
-
*/
|
|
92
|
+
// BuildMintTransaction: mint/burn under one or more Plutus policies.
|
|
188
93
|
srv.on('BuildMintTransaction', async (req) => {
|
|
189
|
-
const {
|
|
190
|
-
|
|
191
|
-
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, referenceScriptHex, metadataJson, validityStartMs, validityEndMs }, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
192
|
-
(0, errors_1.throwIfValidationErrors)(req, 'BuildMintTransaction', errors);
|
|
193
|
-
if (req.data.changeAddress && !(0, validators_1.isValidBech32Address)(req.data.changeAddress)) {
|
|
194
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Invalid changeAddress format', 'changeAddress');
|
|
195
|
-
}
|
|
196
|
-
// Parse mintActionsJson and convert quantity strings to bigint
|
|
197
|
-
const parsedMintActionsRaw = JSON.parse(mintActionsJson);
|
|
198
|
-
if (!Array.isArray(parsedMintActionsRaw)) {
|
|
199
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'mintActionsJson must be a JSON array', 'mintActionsJson');
|
|
200
|
-
}
|
|
201
|
-
const parsedMintActions = parsedMintActionsRaw.map((action, actionIndex) => {
|
|
202
|
-
if (!action || typeof action !== 'object') {
|
|
203
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Each mint action must be an object with assetUnit and quantity', 'mintActionsJson');
|
|
204
|
-
}
|
|
205
|
-
// Multi-policy mint FR: optional per-action mintingPolicyScript + redeemerJson.
|
|
206
|
-
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
207
|
-
if (policyFields.error) {
|
|
208
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', policyFields.error, 'mintActionsJson');
|
|
209
|
-
}
|
|
210
|
-
let actionPolicyId;
|
|
211
|
-
if (policyFields.script) {
|
|
212
|
-
try {
|
|
213
|
-
actionPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policyFields.script, 'hex')).hash.toString();
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
217
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `mintActions[${actionIndex}].mintingPolicyScript is not a valid Plutus script: ${errMsg}`, 'mintActionsJson');
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const bareAssetNameForExpansion = (!!scriptParamsJson || !!actionPolicyId) &&
|
|
221
|
-
typeof action.assetUnit === 'string' &&
|
|
222
|
-
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
223
|
-
action.assetUnit.length % 2 === 0 &&
|
|
224
|
-
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
225
|
-
if (typeof action.assetUnit !== 'string' || (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion)) {
|
|
226
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson or a per-action mintingPolicyScript is set)`, 'mintActionsJson');
|
|
227
|
-
}
|
|
228
|
-
let assetUnit = action.assetUnit;
|
|
229
|
-
if (actionPolicyId) {
|
|
230
|
-
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
231
|
-
assetUnit = actionPolicyId + assetUnit;
|
|
232
|
-
}
|
|
233
|
-
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
234
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `mintActions[${actionIndex}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`, 'mintActionsJson');
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (typeof action.quantity !== 'string') {
|
|
238
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'Each mint action must have a string quantity', 'mintActionsJson');
|
|
239
|
-
}
|
|
240
|
-
if (!/^-?\d+$/.test(action.quantity)) {
|
|
241
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid quantity format: "${action.quantity}" — must be an integer string`, 'mintActionsJson');
|
|
242
|
-
}
|
|
243
|
-
try {
|
|
244
|
-
return {
|
|
245
|
-
assetUnit,
|
|
246
|
-
quantity: BigInt(action.quantity),
|
|
247
|
-
...(action.redeemer !== undefined ? { redeemer: action.redeemer } : {}),
|
|
248
|
-
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
249
|
-
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
catch {
|
|
253
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid quantity: "${action.quantity}" — cannot parse as integer`, 'mintActionsJson');
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
// Parse and validate optional requiredSignersJson
|
|
257
|
-
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
258
|
-
if (requiredSignersResult.error)
|
|
259
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
260
|
-
const requiredSigners = requiredSignersResult.parsed;
|
|
261
|
-
// Parse and validate optional scriptParamsJson
|
|
262
|
-
let scriptParams;
|
|
263
|
-
if (scriptParamsJson) {
|
|
264
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
265
|
-
if (!jsonResult.valid)
|
|
266
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'scriptParamsJson');
|
|
267
|
-
scriptParams = jsonResult.parsed;
|
|
268
|
-
if (!Array.isArray(scriptParams)) {
|
|
269
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// Parse and validate optional inlineDatumJson
|
|
273
|
-
let inlineDatum;
|
|
274
|
-
if (inlineDatumJson) {
|
|
275
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(inlineDatumJson, 'inlineDatumJson');
|
|
276
|
-
if (!jsonResult.valid)
|
|
277
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'inlineDatumJson');
|
|
278
|
-
inlineDatum = jsonResult.parsed;
|
|
279
|
-
}
|
|
280
|
-
// Parse and validate optional mintRedeemerJson
|
|
281
|
-
let mintRedeemer;
|
|
282
|
-
if (mintRedeemerJson) {
|
|
283
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(mintRedeemerJson, 'mintRedeemerJson');
|
|
284
|
-
if (!jsonResult.valid)
|
|
285
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'mintRedeemerJson');
|
|
286
|
-
mintRedeemer = jsonResult.parsed;
|
|
287
|
-
}
|
|
288
|
-
// Validate lockOnScript requires scriptParamsJson
|
|
289
|
-
if (lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
290
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'lockOnScript requires scriptParamsJson to derive script address', 'lockOnScript');
|
|
291
|
-
}
|
|
292
|
-
// Parse and validate optional extraOutputsJson (FR-2 on mint: each minted
|
|
293
|
-
// token can sit on its own output with its own inline datum)
|
|
294
|
-
const extraOutputsResult = (0, tx_request_parsers_1.parseExtraOutputs)(extraOutputsJson);
|
|
295
|
-
if (extraOutputsResult.error)
|
|
296
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', extraOutputsResult.error, 'extraOutputsJson');
|
|
297
|
-
const extraOutputs = extraOutputsResult.parsed;
|
|
298
|
-
// Parse and validate optional forceInputsJson
|
|
299
|
-
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
300
|
-
if (forceInputsResult.error)
|
|
301
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', forceInputsResult.error, 'forceInputsJson');
|
|
302
|
-
const forceInputs = forceInputsResult.parsed;
|
|
303
|
-
// Parse and validate optional referenceInputsJson (CIP-31)
|
|
304
|
-
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
305
|
-
if (refInputsResult.error)
|
|
306
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', refInputsResult.error, 'referenceInputsJson');
|
|
307
|
-
const referenceInputs = refInputsResult.parsed;
|
|
308
|
-
// Parse and validate optional metadataJson
|
|
309
|
-
let parsedMetadata;
|
|
310
|
-
if (metadataJson) {
|
|
311
|
-
try {
|
|
312
|
-
parsedMetadata = JSON.parse(metadataJson);
|
|
313
|
-
}
|
|
314
|
-
catch (err) {
|
|
315
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
316
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Invalid metadataJson: ${errMsg}`, 'metadataJson');
|
|
317
|
-
}
|
|
318
|
-
if (typeof parsedMetadata !== 'object' || parsedMetadata === null || Array.isArray(parsedMetadata)) {
|
|
319
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', 'metadataJson must be an object with numeric label keys', 'metadataJson');
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
// handle the request / building the transaction / indexing the build result / returning build details
|
|
94
|
+
const { request, scriptAddress } = prepareOrAnswer(req, 'BuildMintTransaction', () => (0, build_request_1.prepareMintRequest)(req.data, networkOf));
|
|
95
|
+
const mintActions = request.mintActions ?? [];
|
|
323
96
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
324
|
-
logger.debug({ senderAddress
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
delete cleanData.mintActionsJson;
|
|
328
|
-
delete cleanData.requiredSignersJson;
|
|
329
|
-
delete cleanData.scriptParamsJson;
|
|
330
|
-
delete cleanData.inlineDatumJson;
|
|
331
|
-
delete cleanData.mintRedeemerJson;
|
|
332
|
-
delete cleanData.lockOnScript;
|
|
333
|
-
delete cleanData.forceInputsJson;
|
|
334
|
-
delete cleanData.referenceInputsJson;
|
|
335
|
-
delete cleanData.extraOutputsJson;
|
|
336
|
-
if (parsedMetadata) {
|
|
337
|
-
cleanData.metadataJson = parsedMetadata;
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
delete cleanData.metadataJson;
|
|
341
|
-
}
|
|
342
|
-
if (referenceScriptHex) {
|
|
343
|
-
cleanData.referenceScript = referenceScriptHex;
|
|
344
|
-
}
|
|
345
|
-
delete cleanData.referenceScriptHex;
|
|
346
|
-
// Apply script parameters if provided (for parameterized validators)
|
|
347
|
-
let finalMintingPolicyScript = mintingPolicyScript;
|
|
348
|
-
let effectivePolicyId;
|
|
349
|
-
if (scriptParams && scriptParams.length > 0) {
|
|
350
|
-
try {
|
|
351
|
-
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
|
-
const appliedScript = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex'));
|
|
354
|
-
effectivePolicyId = appliedScript.hash.toString();
|
|
355
|
-
}
|
|
356
|
-
catch (err) {
|
|
357
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
358
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `Failed to apply script parameters: ${errMsg}`, 'scriptParamsJson');
|
|
359
|
-
}
|
|
360
|
-
for (const action of parsedMintActions) {
|
|
361
|
-
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
362
|
-
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
// lockOnScript: route output to the enterprise script address derived from applied script hash
|
|
366
|
-
if (lockOnScript) {
|
|
367
|
-
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, (0, server_1.getCardanoClient)().network);
|
|
368
|
-
cleanData.recipientAddress = scriptAddr;
|
|
369
|
-
logger.debug({ scriptAddress: scriptAddr, scriptHash: effectivePolicyId }, 'lockOnScript: routing output to script address');
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
try {
|
|
374
|
-
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(mintingPolicyScript, 'hex')).hash.toString();
|
|
375
|
-
}
|
|
376
|
-
catch {
|
|
377
|
-
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (effectivePolicyId) {
|
|
381
|
-
const policyId = effectivePolicyId;
|
|
382
|
-
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
383
|
-
if (mismatch) {
|
|
384
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', `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');
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
const buildResult = await (0, server_1.getCardanoIndexer)().indexMintBuildResult(db, {
|
|
388
|
-
...cleanData,
|
|
389
|
-
mintActions: parsedMintActions,
|
|
390
|
-
mintingPolicyScript: finalMintingPolicyScript,
|
|
391
|
-
requiredSigners,
|
|
392
|
-
inlineDatum,
|
|
393
|
-
mintRedeemer,
|
|
394
|
-
forceInputs,
|
|
395
|
-
referenceInputs,
|
|
396
|
-
extraOutputs
|
|
397
|
-
});
|
|
398
|
-
// Post-build: compute CIP-14 fingerprint and scriptAddress
|
|
97
|
+
logger.debug({ senderAddress: request.senderAddress, mintActions: mintActions.length }, 'Building minting transaction');
|
|
98
|
+
const buildResult = await (0, server_1.getCardanoIndexer)().indexMintBuildResult(db, request);
|
|
99
|
+
// CIP-14 fingerprint of the first minted asset, and the script address of lockOnScript
|
|
399
100
|
if (buildResult.scriptHash) {
|
|
400
|
-
const policyId = buildResult.scriptHash;
|
|
401
101
|
const updates = {};
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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.
|
|
408
|
-
if (parsedMintActions.length > 0) {
|
|
409
|
-
const firstAssetUnit = parsedMintActions[0].assetUnit;
|
|
410
|
-
const firstPolicyId = firstAssetUnit.slice(0, const_1.POLICY_ID_HEX_LENGTH);
|
|
411
|
-
const assetNameHex = firstAssetUnit.slice(const_1.POLICY_ID_HEX_LENGTH);
|
|
412
|
-
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(firstPolicyId, assetNameHex);
|
|
102
|
+
if (mintActions.length > 0) {
|
|
103
|
+
// the policy id comes from the unit: a per-action policy may differ from the top-level script
|
|
104
|
+
const firstUnit = mintActions[0].assetUnit;
|
|
105
|
+
buildResult.fingerprint = (0, mappers_1.computeCip14Fingerprint)(firstUnit.slice(0, const_1.POLICY_ID_HEX_LENGTH), firstUnit.slice(const_1.POLICY_ID_HEX_LENGTH));
|
|
413
106
|
updates.fingerprint = buildResult.fingerprint;
|
|
414
107
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
buildResult.scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(policyId, (0, server_1.getCardanoClient)().network);
|
|
108
|
+
if (scriptAddress) {
|
|
109
|
+
buildResult.scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(buildResult.scriptHash, networkOf());
|
|
418
110
|
updates.scriptAddress = buildResult.scriptAddress;
|
|
419
111
|
}
|
|
420
112
|
if (buildResult.id && Object.keys(updates).length > 0) {
|
|
421
|
-
const { TransactionBuilds } = cds_1.default.entities('CardanoTransactionService');
|
|
422
113
|
await db.run(UPDATE.entity(TransactionBuilds).set(updates).where({ id: buildResult.id }));
|
|
423
114
|
}
|
|
424
115
|
}
|
|
425
116
|
return buildResult;
|
|
426
117
|
});
|
|
427
118
|
});
|
|
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
|
-
*/
|
|
119
|
+
// BuildPlutusSpendTransaction: consume a UTxO at a script address, optionally minting too.
|
|
433
120
|
srv.on('BuildPlutusSpendTransaction', async (req) => {
|
|
434
|
-
const {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (scriptOutputIndex === undefined || scriptOutputIndex === null) {
|
|
443
|
-
return (0, errors_1.rejectMissing)(req, 'BuildPlutusSpendTransaction', 'scriptOutputIndex');
|
|
444
|
-
}
|
|
445
|
-
// Parse redeemer JSON
|
|
446
|
-
const parsedRedeemer = JSON.parse(redeemerJson);
|
|
447
|
-
// Parse optional datum JSON
|
|
448
|
-
const parsedDatum = datumJson ? JSON.parse(datumJson) : undefined;
|
|
449
|
-
// Parse and validate optional requiredSignersJson
|
|
450
|
-
const requiredSignersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
451
|
-
if (requiredSignersResult.error)
|
|
452
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', requiredSignersResult.error, 'requiredSignersJson');
|
|
453
|
-
const requiredSigners = requiredSignersResult.parsed;
|
|
454
|
-
// Parse and validate optional scriptParamsJson
|
|
455
|
-
let scriptParams;
|
|
456
|
-
if (scriptParamsJson) {
|
|
457
|
-
const jsonResult = (0, validators_1.validateJsonWithLimits)(scriptParamsJson, 'scriptParamsJson');
|
|
458
|
-
if (!jsonResult.valid)
|
|
459
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'scriptParamsJson');
|
|
460
|
-
scriptParams = jsonResult.parsed;
|
|
461
|
-
if (!Array.isArray(scriptParams)) {
|
|
462
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'scriptParamsJson must be a JSON array', 'scriptParamsJson');
|
|
121
|
+
const { request, scriptAddress } = prepareOrAnswer(req, 'BuildPlutusSpendTransaction', () => (0, build_request_1.preparePlutusSpendRequest)(req.data, networkOf));
|
|
122
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
123
|
+
logger.debug({ senderAddress: request.senderAddress, scriptUtxo: request.plutusScriptExecution.scriptUtxo }, 'Building Plutus spending transaction');
|
|
124
|
+
const buildResult = await (0, server_1.getCardanoIndexer)().indexPlutusSpendBuildResult(db, request);
|
|
125
|
+
// lockOnScript: the derived script address goes on the build record
|
|
126
|
+
if (scriptAddress && buildResult.scriptHash && buildResult.id) {
|
|
127
|
+
buildResult.scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(buildResult.scriptHash, networkOf());
|
|
128
|
+
await db.run(UPDATE.entity(TransactionBuilds).set({ scriptAddress: buildResult.scriptAddress }).where({ id: buildResult.id }));
|
|
463
129
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (
|
|
480
|
-
return (0, errors_1.
|
|
481
|
-
const
|
|
482
|
-
|
|
130
|
+
return buildResult;
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
// BuildPlutusTransaction: several script UTxOs in one transaction, each with its own redeemer.
|
|
134
|
+
srv.on('BuildPlutusTransaction', async (req) => {
|
|
135
|
+
const { senderAddress, changeAddress, scriptInputsJson, outputsJson, referenceInputsJson, forceInputsJson, protectInputsJson, withdrawalsJson, certificatesJson, requiredSignersJson, mintActionsJson, validityStartMs, validityEndMs } = req.data;
|
|
136
|
+
const action = 'BuildPlutusTransaction';
|
|
137
|
+
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, validityStartMs, validityEndMs }, ['senderAddress']);
|
|
138
|
+
(0, errors_1.throwIfValidationErrors)(req, action, errors);
|
|
139
|
+
if (changeAddress && !(0, validators_1.isValidBech32Address)(changeAddress)) {
|
|
140
|
+
return (0, errors_1.rejectInvalid)(req, action, 'Invalid changeAddress format', 'changeAddress');
|
|
141
|
+
}
|
|
142
|
+
const scriptInputsResult = (0, tx_request_parsers_1.parseScriptInputs)(scriptInputsJson);
|
|
143
|
+
if (scriptInputsResult.error)
|
|
144
|
+
return (0, errors_1.rejectInvalid)(req, action, scriptInputsResult.error, 'scriptInputsJson');
|
|
145
|
+
if (!outputsJson)
|
|
146
|
+
return (0, errors_1.rejectMissing)(req, action, 'outputsJson');
|
|
147
|
+
const outputsResult = (0, tx_request_parsers_1.parseOutputList)(outputsJson, 'outputsJson');
|
|
148
|
+
if (outputsResult.error)
|
|
149
|
+
return (0, errors_1.rejectInvalid)(req, action, outputsResult.error, 'outputsJson');
|
|
150
|
+
if (!outputsResult.parsed)
|
|
151
|
+
return (0, errors_1.rejectInvalid)(req, action, 'outputsJson must list at least one output', 'outputsJson');
|
|
483
152
|
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
484
153
|
if (refInputsResult.error)
|
|
485
|
-
return (0, errors_1.rejectInvalid)(req,
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const action = rawAction;
|
|
510
|
-
if (typeof action.quantity !== 'string' || !/^-?\d+$/.test(action.quantity)) {
|
|
511
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Invalid quantity: "${action.quantity}" — must be an integer string`, 'mintActionsJson');
|
|
512
|
-
}
|
|
513
|
-
if (typeof action.assetUnit !== 'string') {
|
|
514
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'Each mint action must have assetUnit string', 'mintActionsJson');
|
|
515
|
-
}
|
|
516
|
-
// Multi-policy mint FR: optional per-action mintingPolicyScript + redeemerJson
|
|
517
|
-
// (same rules as BuildMintTransaction).
|
|
518
|
-
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, actionIndex);
|
|
519
|
-
if (policyFields.error) {
|
|
520
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', policyFields.error, 'mintActionsJson');
|
|
521
|
-
}
|
|
522
|
-
let actionPolicyId;
|
|
523
|
-
if (policyFields.script) {
|
|
524
|
-
try {
|
|
525
|
-
actionPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policyFields.script, 'hex')).hash.toString();
|
|
526
|
-
}
|
|
527
|
-
catch (err) {
|
|
528
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
529
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `mintActions[${actionIndex}].mintingPolicyScript is not a valid Plutus script: ${errMsg}`, 'mintActionsJson');
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
const bareAssetNameForExpansion = ((!!scriptParamsJson && mintingPolicyScript === validatorScript) || !!actionPolicyId) &&
|
|
533
|
-
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
534
|
-
action.assetUnit.length % 2 === 0 &&
|
|
535
|
-
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
536
|
-
if (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion) {
|
|
537
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when a per-action mintingPolicyScript is set, or scriptParamsJson is set and the policy equals the validator)`, 'mintActionsJson');
|
|
538
|
-
}
|
|
539
|
-
let assetUnit = action.assetUnit;
|
|
540
|
-
if (actionPolicyId) {
|
|
541
|
-
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
542
|
-
assetUnit = actionPolicyId + assetUnit;
|
|
543
|
-
}
|
|
544
|
-
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
545
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `mintActions[${actionIndex}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`, 'mintActionsJson');
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return {
|
|
549
|
-
assetUnit,
|
|
550
|
-
quantity: BigInt(action.quantity),
|
|
551
|
-
...(typeof action.redeemer === 'number' ? { redeemer: action.redeemer } : {}),
|
|
552
|
-
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
553
|
-
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
554
|
-
};
|
|
555
|
-
});
|
|
556
|
-
if (mintRedeemerJson) {
|
|
557
|
-
const mrJson = (0, validators_1.validateJsonWithLimits)(mintRedeemerJson, 'mintRedeemerJson');
|
|
558
|
-
if (!mrJson.valid)
|
|
559
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', mrJson.error, 'mintRedeemerJson');
|
|
560
|
-
parsedMintRedeemer = mrJson.parsed;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
else if (mintingPolicyScript || mintRedeemerJson) {
|
|
564
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', 'mintingPolicyScript / mintRedeemerJson require mintActionsJson', 'mintActionsJson');
|
|
565
|
-
}
|
|
566
|
-
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
567
|
-
logger.debug({ senderAddress, recipientAddress, lovelaceAmount, scriptTxHash, scriptOutputIndex }, 'Building Plutus spending transaction');
|
|
568
|
-
// Apply script parameters if provided (for parameterized validators)
|
|
569
|
-
let finalValidatorScript = validatorScript;
|
|
570
|
-
if (scriptParams && scriptParams.length > 0) {
|
|
154
|
+
return (0, errors_1.rejectInvalid)(req, action, refInputsResult.error, 'referenceInputsJson');
|
|
155
|
+
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
156
|
+
if (forceInputsResult.error)
|
|
157
|
+
return (0, errors_1.rejectInvalid)(req, action, forceInputsResult.error, 'forceInputsJson');
|
|
158
|
+
const protectInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(protectInputsJson, 'protectInputsJson');
|
|
159
|
+
if (protectInputsResult.error)
|
|
160
|
+
return (0, errors_1.rejectInvalid)(req, action, protectInputsResult.error, 'protectInputsJson');
|
|
161
|
+
const withdrawalsResult = (0, tx_request_parsers_1.parseWithdrawals)(withdrawalsJson);
|
|
162
|
+
if (withdrawalsResult.error)
|
|
163
|
+
return (0, errors_1.rejectInvalid)(req, action, withdrawalsResult.error, 'withdrawalsJson');
|
|
164
|
+
const certificatesResult = (0, tx_request_parsers_1.parseCertificates)(certificatesJson);
|
|
165
|
+
if (certificatesResult.error)
|
|
166
|
+
return (0, errors_1.rejectInvalid)(req, action, certificatesResult.error, 'certificatesJson');
|
|
167
|
+
const signersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
168
|
+
if (signersResult.error)
|
|
169
|
+
return (0, errors_1.rejectInvalid)(req, action, signersResult.error, 'requiredSignersJson');
|
|
170
|
+
const mintResult = (0, tx_request_parsers_1.parsePolicyMintActions)(mintActionsJson);
|
|
171
|
+
if (mintResult.error)
|
|
172
|
+
return (0, errors_1.rejectInvalid)(req, action, mintResult.error, 'mintActionsJson');
|
|
173
|
+
// Script params are applied here, so the builder sees the final validators
|
|
174
|
+
const scriptInputs = [];
|
|
175
|
+
for (const [i, si] of scriptInputsResult.parsed.entries()) {
|
|
176
|
+
let validatorScript = si.validatorScript;
|
|
177
|
+
if (validatorScript && si.scriptParams) {
|
|
571
178
|
try {
|
|
572
|
-
|
|
179
|
+
validatorScript = (0, tx_build_helper_1.applyScriptParameters)(validatorScript, si.scriptParams);
|
|
573
180
|
}
|
|
574
181
|
catch (err) {
|
|
575
182
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
576
|
-
return (0, errors_1.rejectInvalid)(req,
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
// FR-1: when the mint policy is byte-equal to the validator (multi-purpose script),
|
|
580
|
-
// re-use the script-params-applied validator hex. Otherwise pass the policy through unchanged.
|
|
581
|
-
let finalMintingPolicyScript;
|
|
582
|
-
if (parsedMintActions) {
|
|
583
|
-
finalMintingPolicyScript = (mintingPolicyScript === validatorScript)
|
|
584
|
-
? finalValidatorScript
|
|
585
|
-
: mintingPolicyScript;
|
|
586
|
-
if (finalMintingPolicyScript && scriptParams && scriptParams.length > 0 && mintingPolicyScript === validatorScript) {
|
|
587
|
-
let appliedPolicyId;
|
|
588
|
-
try {
|
|
589
|
-
appliedPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
590
|
-
}
|
|
591
|
-
catch (err) {
|
|
592
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
593
|
-
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', `Failed to hash applied script: ${errMsg}`, 'mintingPolicyScript');
|
|
594
|
-
}
|
|
595
|
-
for (const action of parsedMintActions) {
|
|
596
|
-
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
597
|
-
action.assetUnit = appliedPolicyId + action.assetUnit;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
// BUG 9 fix: same policyId-prefix check as BuildMintTransaction — the builder
|
|
602
|
-
// mints every action under the mint script's hash and parseAssetUnit silently
|
|
603
|
-
// discards the unit's first 56 hex chars, so a mismatched prefix would mint a
|
|
604
|
-
// truncated asset name.
|
|
605
|
-
if (finalMintingPolicyScript) {
|
|
606
|
-
let mintPolicyId;
|
|
607
|
-
try {
|
|
608
|
-
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
609
|
-
}
|
|
610
|
-
catch {
|
|
611
|
-
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
612
|
-
}
|
|
613
|
-
if (mintPolicyId) {
|
|
614
|
-
const policyId = mintPolicyId;
|
|
615
|
-
// Actions with their own per-action script were already checked
|
|
616
|
-
// against THAT script's policy id during parsing.
|
|
617
|
-
const mismatch = parsedMintActions.find((action) => !action.mintingPolicyScript && !action.assetUnit.toLowerCase().startsWith(policyId));
|
|
618
|
-
if (mismatch) {
|
|
619
|
-
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');
|
|
620
|
-
}
|
|
621
|
-
}
|
|
183
|
+
return (0, errors_1.rejectInvalid)(req, action, `scriptInputs[${i}]: failed to apply script parameters: ${errMsg}`, 'scriptInputsJson');
|
|
622
184
|
}
|
|
623
185
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
referenceInputs,
|
|
639
|
-
extraOutputs,
|
|
640
|
-
mintActions: parsedMintActions,
|
|
641
|
-
mintingPolicyScript: finalMintingPolicyScript,
|
|
642
|
-
mintRedeemer: parsedMintRedeemer
|
|
643
|
-
};
|
|
644
|
-
if (referenceScriptHex) {
|
|
645
|
-
cleanData.referenceScript = referenceScriptHex;
|
|
646
|
-
}
|
|
647
|
-
delete cleanData.requiredSignersJson;
|
|
648
|
-
delete cleanData.scriptParamsJson;
|
|
649
|
-
delete cleanData.inlineDatumJson;
|
|
650
|
-
delete cleanData.lockOnScript;
|
|
651
|
-
delete cleanData.forceInputsJson;
|
|
652
|
-
delete cleanData.referenceInputsJson;
|
|
653
|
-
delete cleanData.extraOutputsJson;
|
|
654
|
-
delete cleanData.mintActionsJson;
|
|
655
|
-
delete cleanData.mintRedeemerJson;
|
|
656
|
-
delete cleanData.referenceScriptHex;
|
|
657
|
-
// lockOnScript: route continuing output to enterprise script address
|
|
658
|
-
if (lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
186
|
+
scriptInputs.push({
|
|
187
|
+
txHash: si.txHash,
|
|
188
|
+
outputIndex: si.outputIndex,
|
|
189
|
+
...(validatorScript ? { validatorScript } : { referenceScript: si.referenceScript }),
|
|
190
|
+
redeemer: si.redeemer,
|
|
191
|
+
...(si.redeemerCbor ? { redeemerCbor: si.redeemerCbor } : {}),
|
|
192
|
+
...(si.datum !== undefined ? { datum: si.datum } : {}),
|
|
193
|
+
...(si.datumCbor ? { datumCbor: si.datumCbor } : {}),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// Same for the staking scripts of withdrawals and certificates
|
|
197
|
+
const stakingWitness = (w, at, field) => {
|
|
198
|
+
let stakingScript = w.stakingScript;
|
|
199
|
+
if (stakingScript && w.scriptParams) {
|
|
659
200
|
try {
|
|
660
|
-
|
|
661
|
-
const derivedScriptHash = appliedScript.hash.toString();
|
|
662
|
-
const scriptAddr = (0, mappers_1.scriptHashToEnterpriseAddress)(derivedScriptHash, (0, server_1.getCardanoClient)().network);
|
|
663
|
-
cleanData.recipientAddress = scriptAddr;
|
|
664
|
-
logger.debug({ scriptAddress: scriptAddr, scriptHash: derivedScriptHash }, 'lockOnScript: routing continuing output to script address');
|
|
201
|
+
stakingScript = (0, tx_build_helper_1.applyScriptParameters)(stakingScript, w.scriptParams);
|
|
665
202
|
}
|
|
666
203
|
catch (err) {
|
|
667
204
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
668
|
-
return (0, errors_1.rejectInvalid)(req,
|
|
205
|
+
return { error: (0, errors_1.rejectInvalid)(req, action, `${at}: failed to apply script parameters: ${errMsg}`, field) };
|
|
669
206
|
}
|
|
670
207
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
|
|
208
|
+
return {
|
|
209
|
+
parsed: {
|
|
210
|
+
...(stakingScript ? { stakingScript } : {}),
|
|
211
|
+
...(w.referenceScript ? { referenceScript: w.referenceScript } : {}),
|
|
212
|
+
...(w.redeemer !== undefined ? { redeemer: w.redeemer } : {}),
|
|
213
|
+
...(w.redeemerCbor ? { redeemerCbor: w.redeemerCbor } : {}),
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
const withdrawals = [];
|
|
218
|
+
for (const [i, w] of (withdrawalsResult.parsed ?? []).entries()) {
|
|
219
|
+
const witness = stakingWitness(w, `withdrawals[${i}]`, 'withdrawalsJson');
|
|
220
|
+
if ('error' in witness)
|
|
221
|
+
return witness.error;
|
|
222
|
+
withdrawals.push({ rewardAddress: w.rewardAddress, lovelace: w.lovelace, ...witness.parsed });
|
|
223
|
+
}
|
|
224
|
+
const certificates = [];
|
|
225
|
+
for (const [i, c] of (certificatesResult.parsed ?? []).entries()) {
|
|
226
|
+
const witness = stakingWitness(c, `certificates[${i}]`, 'certificatesJson');
|
|
227
|
+
if ('error' in witness)
|
|
228
|
+
return witness.error;
|
|
229
|
+
certificates.push({ type: c.type, stakeAddress: c.stakeAddress, ...(c.deposit ? { deposit: c.deposit } : {}), ...witness.parsed });
|
|
230
|
+
}
|
|
231
|
+
const buildReq = {
|
|
232
|
+
network: (0, server_1.getCardanoClient)().network,
|
|
233
|
+
senderAddress,
|
|
234
|
+
...(changeAddress ? { changeAddress } : {}),
|
|
235
|
+
scriptInputs,
|
|
236
|
+
outputs: outputsResult.parsed,
|
|
237
|
+
referenceInputs: refInputsResult.parsed,
|
|
238
|
+
forceInputs: forceInputsResult.parsed,
|
|
239
|
+
protectInputs: protectInputsResult.parsed,
|
|
240
|
+
...(withdrawals.length > 0 ? { withdrawals } : {}),
|
|
241
|
+
...(certificates.length > 0 ? { certificates } : {}),
|
|
242
|
+
requiredSigners: signersResult.parsed,
|
|
243
|
+
mintActions: mintResult.parsed,
|
|
244
|
+
validityStartMs,
|
|
245
|
+
validityEndMs,
|
|
246
|
+
};
|
|
247
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
248
|
+
logger.debug({ senderAddress, scriptInputs: scriptInputs.length, outputs: buildReq.outputs.length }, 'Building multi-script Plutus transaction');
|
|
249
|
+
const build = await (0, server_1.getCardanoIndexer)().indexPlutusBuildResult(db, buildReq);
|
|
250
|
+
// the answer carries the execution units of every redeemer, as stored with the build
|
|
251
|
+
const redeemers = await db.run(SELECT.from(TransactionBuildRedeemers).columns('tag', 'redeemerIndex', 'mem', 'steps').where({ build_id: build.id }).orderBy('tag', 'redeemerIndex'));
|
|
252
|
+
return { ...build, redeemers };
|
|
680
253
|
});
|
|
681
254
|
});
|
|
682
|
-
|
|
683
|
-
* Get build details for previously built transaction
|
|
684
|
-
* @param req - CDS request object (with buildId)
|
|
685
|
-
* @returns {TransactionBuild} Transaction build details
|
|
686
|
-
*/
|
|
255
|
+
// GetBuildDetails: an existing transaction build by id.
|
|
687
256
|
srv.on('GetBuildDetails', async (req) => {
|
|
688
257
|
const { buildId } = req.data;
|
|
689
|
-
// Validate inputs
|
|
690
258
|
const errors = (0, validators_1.validateTransactionInputs)({ buildId }, ['buildId']);
|
|
691
259
|
(0, errors_1.throwIfValidationErrors)(req, 'GetBuildDetails', errors);
|
|
692
|
-
// handle the request / fetching the build details
|
|
693
260
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
694
261
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
695
262
|
if (!existing)
|
|
@@ -697,13 +264,8 @@ module.exports = (srv) => {
|
|
|
697
264
|
return existing;
|
|
698
265
|
});
|
|
699
266
|
});
|
|
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
|
-
*/
|
|
267
|
+
// SetCollateral: collateral is available when the builders would find it: an ADA-only UTxO of
|
|
268
|
+
// >= 5 ADA without a reference script, plus another UTxO to fund with; otherwise a self-send creates one.
|
|
707
269
|
srv.on('SetCollateral', async (req) => {
|
|
708
270
|
const { address } = req.data;
|
|
709
271
|
if (!address)
|
|
@@ -712,17 +274,15 @@ module.exports = (srv) => {
|
|
|
712
274
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'Invalid Bech32 address format', 'address');
|
|
713
275
|
}
|
|
714
276
|
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);
|
|
277
|
+
// Inside handleRequest use rejectInvalid (typed BackendError 400), not req.reject,
|
|
278
|
+
// so mapError preserves the status.
|
|
279
|
+
const ledger = await (0, server_1.getCardanoIndexer)().resolveAddressUtxos(db, address);
|
|
280
|
+
const utxos = (0, server_1.getCardanoClient)().pendingSpends?.apply(address, ledger) ?? ledger;
|
|
721
281
|
if (utxos.length === 0) {
|
|
722
282
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'No UTxOs found at address', 'address');
|
|
723
283
|
}
|
|
724
|
-
const qualifyingUtxos = utxos.filter(u => (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE);
|
|
725
|
-
if (qualifyingUtxos.length >= 2) {
|
|
284
|
+
const qualifyingUtxos = utxos.filter(u => (0, tx_build_helper_1.isCollateralCandidate)(u) && (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE);
|
|
285
|
+
if (qualifyingUtxos.length >= 1 && utxos.length >= 2) {
|
|
726
286
|
return {
|
|
727
287
|
id: cds_1.default.utils.uuid(),
|
|
728
288
|
network: (0, server_1.getCardanoClient)().network,
|
|
@@ -732,7 +292,7 @@ module.exports = (srv) => {
|
|
|
732
292
|
}
|
|
733
293
|
const totalLovelace = utxos.reduce((sum, u) => sum + (0, tx_build_helper_1.getLovelace)(u), 0n);
|
|
734
294
|
if (totalLovelace < const_1.COLLATERAL_LOVELACE + const_1.FEE_BUFFER_LOVELACE) {
|
|
735
|
-
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', `Insufficient funds
|
|
295
|
+
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', `Insufficient funds: need at least ${Number(const_1.COLLATERAL_LOVELACE + const_1.FEE_BUFFER_LOVELACE) / 1_000_000} ADA, have ${Number(totalLovelace) / 1_000_000} ADA`, 'address');
|
|
736
296
|
}
|
|
737
297
|
logger.debug({ address, existingQualifying: qualifyingUtxos.length }, 'Building collateral setup transaction');
|
|
738
298
|
const result = await (0, server_1.getCardanoIndexer)().indexSimpleBuildResult(db, {
|
|
@@ -745,175 +305,114 @@ module.exports = (srv) => {
|
|
|
745
305
|
return { ...result, collateralAvailable: false };
|
|
746
306
|
});
|
|
747
307
|
});
|
|
748
|
-
|
|
749
|
-
|
|
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
|
-
*/
|
|
754
|
-
srv.on('SubmitTransaction', async (req) => {
|
|
308
|
+
// SubmitTransaction: submit the signed CBOR of a previous build.
|
|
309
|
+
srv.on(CardanoTransactionService_1.SubmitTransaction, async (req) => {
|
|
755
310
|
logger.debug('SubmitTransaction Action handler called');
|
|
756
|
-
const { buildId, signedTxCbor } = req.data;
|
|
757
|
-
|
|
758
|
-
|
|
311
|
+
const { buildId, signedTxCbor: signedInput } = req.data;
|
|
312
|
+
if (!buildId)
|
|
313
|
+
return (0, errors_1.rejectMissing)(req, 'SubmitTransaction', 'buildId');
|
|
314
|
+
if (!signedInput)
|
|
315
|
+
return (0, errors_1.rejectMissing)(req, 'SubmitTransaction', 'signedTxCbor');
|
|
316
|
+
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor: signedInput }, ['buildId', 'signedTxCbor']);
|
|
759
317
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitTransaction', errors);
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
764
|
-
if (!existing)
|
|
318
|
+
try {
|
|
319
|
+
const build = await (0, tx_utils_1.detachedTx)('load build for submit', (db) => db.run(SELECT.one.from(TransactionBuilds).columns('unsignedTxCbor', 'txBodyHash').where({ id: buildId })));
|
|
320
|
+
if (!build)
|
|
765
321
|
throw new errors_1.NotFoundError(`Build '${buildId}'`);
|
|
766
|
-
//
|
|
322
|
+
// A CIP-30 wallet returns only the witness set; cardano-cli a full signed tx.
|
|
323
|
+
const signedTxCbor = (0, signing_helper_1.toSignedTransaction)(build.unsignedTxCbor, signedInput);
|
|
324
|
+
// The signed CBOR must belong to this build (audit-trail integrity)
|
|
767
325
|
const signedTxHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
768
|
-
if (signedTxHash !==
|
|
769
|
-
|
|
770
|
-
}
|
|
771
|
-
// Use txBodyHash from build
|
|
772
|
-
const txHash = existing.txBodyHash;
|
|
773
|
-
// Two-phase submit: persist with 'pending', then submit to blockchain
|
|
774
|
-
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
775
|
-
signedTxCbor,
|
|
776
|
-
txHash,
|
|
777
|
-
buildId,
|
|
778
|
-
});
|
|
779
|
-
try {
|
|
780
|
-
await (0, server_1.getCardanoClient)().submitTransaction(signedTxCbor);
|
|
781
|
-
logger.info({ txHash }, 'Transaction submitted to blockchain');
|
|
782
|
-
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
783
|
-
submissionRecord.status = 'submitted';
|
|
784
|
-
// Invalidate stale UTxO cache: spent input refs + output addresses from
|
|
785
|
-
// the signed CBOR, plus the build's sender address. Best-effort — a
|
|
786
|
-
// failure here must not fail the already-successful submit.
|
|
787
|
-
try {
|
|
788
|
-
const addrBuild = await db.run(SELECT.one.from(AddressTransactionBuilds).where({ txBuild_id: buildId }));
|
|
789
|
-
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor), addrBuild?.address_address ? [addrBuild.address_address] : []);
|
|
790
|
-
}
|
|
791
|
-
catch (invalidateErr) {
|
|
792
|
-
logger.warn(`UTxO cache invalidation failed (submit unaffected): ${invalidateErr instanceof Error ? invalidateErr.message : String(invalidateErr)}`);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
catch (err) {
|
|
796
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
797
|
-
logger.error({ txHash, error: errMsg }, 'Transaction submission failed');
|
|
798
|
-
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'failed', errMsg);
|
|
799
|
-
throw err;
|
|
326
|
+
if (signedTxHash !== build.txBodyHash) {
|
|
327
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitTransaction', `signedTxCbor hash '${signedTxHash}' does not match build txBodyHash '${build.txBodyHash}'`, 'signedTxCbor');
|
|
800
328
|
}
|
|
801
|
-
|
|
802
|
-
|
|
329
|
+
// the body hash leaves isValid out, and a build stored by an earlier version may have no expiry
|
|
330
|
+
const problem = (0, landing_proof_1.sendProblem)(signedTxCbor, (0, server_1.getCardanoClient)().network);
|
|
331
|
+
if (problem)
|
|
332
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitTransaction', problem, 'signedTxCbor');
|
|
333
|
+
return await (0, submission_finalizer_1.submitRecorded)({ signedTxCbor, txHash: build.txBodyHash, buildId });
|
|
334
|
+
}
|
|
335
|
+
catch (e) {
|
|
336
|
+
return (0, mappers_1.mapError)(req, e, 'SubmitTransaction');
|
|
337
|
+
}
|
|
803
338
|
});
|
|
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
|
-
*/
|
|
339
|
+
// SubmitSignedTransaction: submit externally built signed CBOR (no prior build).
|
|
811
340
|
srv.on('SubmitSignedTransaction', async (req) => {
|
|
812
341
|
logger.debug('SubmitSignedTransaction Action handler called');
|
|
813
342
|
const { signedTxCbor, network } = req.data;
|
|
814
|
-
// Validate inputs (includes CBOR format validation)
|
|
815
343
|
const errors = (0, validators_1.validateTransactionInputs)({ signedTxCbor }, ['signedTxCbor']);
|
|
816
344
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitSignedTransaction', errors);
|
|
817
|
-
|
|
818
|
-
//
|
|
819
|
-
// configured network so a caller targeting the wrong deployment gets a clear 400.
|
|
345
|
+
try {
|
|
346
|
+
// A caller targeting the wrong deployment gets a clear 400
|
|
820
347
|
const configuredNetwork = (0, server_1.getCardanoClient)().network;
|
|
821
348
|
if (network && network !== configuredNetwork) {
|
|
822
|
-
|
|
823
|
-
}
|
|
824
|
-
// Extract txHash from signed CBOR
|
|
825
|
-
const txHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
826
|
-
// Two-phase submit: persist with 'pending', then submit to blockchain
|
|
827
|
-
const submissionRecord = await (0, server_1.getCardanoIndexer)().persistTransactionSubmission(db, {
|
|
828
|
-
signedTxCbor,
|
|
829
|
-
txHash,
|
|
830
|
-
buildId: null,
|
|
831
|
-
});
|
|
832
|
-
try {
|
|
833
|
-
await (0, server_1.getCardanoClient)().submitTransaction(signedTxCbor);
|
|
834
|
-
logger.info({ txHash }, 'External transaction submitted');
|
|
835
|
-
await (0, server_1.getCardanoIndexer)().updateSubmissionStatus(db, submissionRecord.id, 'submitted');
|
|
836
|
-
submissionRecord.status = 'submitted';
|
|
837
|
-
// Invalidate stale UTxO cache (spent inputs + output addresses) — best-effort
|
|
838
|
-
try {
|
|
839
|
-
await (0, server_1.getCardanoIndexer)().invalidateUtxoCacheForTx(db, (0, tx_build_helper_1.extractTxCacheTargets)(signedTxCbor));
|
|
840
|
-
}
|
|
841
|
-
catch (invalidateErr) {
|
|
842
|
-
logger.warn(`UTxO cache invalidation failed (submit unaffected): ${invalidateErr instanceof Error ? invalidateErr.message : String(invalidateErr)}`);
|
|
843
|
-
}
|
|
349
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitSignedTransaction', `network '${network}' does not match this deployment's network '${configuredNetwork}'`, 'network');
|
|
844
350
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
351
|
+
// without an expiry within the cap an unanswered submit could stay undecided; isValid false only spends collateral
|
|
352
|
+
const expiry = (0, landing_proof_1.sendProblem)(signedTxCbor, configuredNetwork);
|
|
353
|
+
if (expiry)
|
|
354
|
+
(0, errors_1.rejectInvalid)(req, 'SubmitSignedTransaction', expiry, 'signedTxCbor');
|
|
355
|
+
return await (0, submission_finalizer_1.submitRecorded)({ signedTxCbor, txHash: (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor), buildId: null });
|
|
356
|
+
}
|
|
357
|
+
catch (e) {
|
|
358
|
+
return (0, mappers_1.mapError)(req, e, 'SubmitSignedTransaction');
|
|
359
|
+
}
|
|
853
360
|
});
|
|
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
|
-
*/
|
|
361
|
+
// CheckSubmissionStatus: bound action; the @from: [#submitted] state gate is enforced by CAP.
|
|
861
362
|
srv.on('CheckSubmissionStatus', async (req) => {
|
|
862
363
|
logger.debug('CheckSubmissionStatus Action handler called');
|
|
863
364
|
const { id: submissionId } = req.params[0];
|
|
864
|
-
// @from: [#submitted] validated by framework — no manual status check needed
|
|
865
365
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
866
|
-
|
|
366
|
+
// read outside the request transaction: the confirmation lookup below may ask a backend
|
|
367
|
+
const submission = await (0, tx_utils_1.readOutside)(db, (d) => d.run(SELECT.one.from(TransactionSubmissions).where({ id: submissionId })));
|
|
867
368
|
if (!submission)
|
|
868
369
|
throw new errors_1.NotFoundError(`Submission '${submissionId}'`);
|
|
869
|
-
//
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
.where({ id: submissionId }));
|
|
876
|
-
submission.status = 'confirmed';
|
|
877
|
-
logger.info({ submissionId, txHash: submission.txHash }, 'Transaction confirmed on chain');
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
catch (err) {
|
|
881
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
882
|
-
if (err instanceof errors_1.NotFoundError || err?.statusCode === 404) {
|
|
883
|
-
// Transaction genuinely not yet confirmed on chain
|
|
884
|
-
logger.debug({ submissionId, txHash: submission.txHash }, 'Transaction not yet confirmed on chain');
|
|
885
|
-
}
|
|
886
|
-
else {
|
|
887
|
-
// Provider error — don't mask as "pending", let caller know
|
|
888
|
-
logger.warn({ submissionId, txHash: submission.txHash, error: errMsg }, 'Failed to check transaction confirmation status');
|
|
889
|
-
throw err;
|
|
890
|
-
}
|
|
370
|
+
// a block this deep is not rolled back in practice; a status set here is never reverted
|
|
371
|
+
const { confirmations } = await (0, server_1.getCardanoIndexer)().resolveTransactionConfirmations(db, submission.txHash);
|
|
372
|
+
if (confirmations >= SUBMISSION_CONFIRMATION_DEPTH) {
|
|
373
|
+
await db.run(UPDATE.entity(TransactionSubmissions).set({ status: 'confirmed' }).where({ id: submissionId }));
|
|
374
|
+
submission.status = 'confirmed';
|
|
375
|
+
logger.info({ submissionId, txHash: submission.txHash, confirmations }, 'Transaction confirmed on chain');
|
|
891
376
|
}
|
|
892
377
|
return submission;
|
|
893
378
|
});
|
|
894
379
|
});
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
380
|
+
// ResolveSubmission (Admin): settles an unresolved submission as an operator read it on the chain.
|
|
381
|
+
// Confirmed makes it submitted, so CheckSubmissionStatus counts its depth; failed ends it.
|
|
382
|
+
srv.on('ResolveSubmission', async (req) => {
|
|
383
|
+
const { submissionId, outcome, txHash, note } = req.data;
|
|
384
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
385
|
+
// read and ask the chain before the request takes its connection
|
|
386
|
+
const submission = await (0, tx_utils_1.readOutside)(db, (d) => d.run(SELECT.one.from(TransactionSubmissions).where({ id: submissionId })));
|
|
387
|
+
if (!submission)
|
|
388
|
+
throw new errors_1.NotFoundError(`Submission '${submissionId}'`);
|
|
389
|
+
if (submission.status !== 'unresolved') {
|
|
390
|
+
(0, errors_1.rejectInvalid)(req, 'ResolveSubmission', `Submission status is '${submission.status}': only an unresolved submission can be resolved`, 'submissionId');
|
|
391
|
+
}
|
|
392
|
+
(0, resolution_1.checkResolvedTxHash)(req, 'ResolveSubmission', txHash, submission.txHash);
|
|
393
|
+
const resolved = outcome === 'confirmed' ? 'confirmed' : 'failed';
|
|
394
|
+
await (0, resolution_1.refuseFailedWhileItCanLand)('ResolveSubmission', resolved, submission.signedTxCbor, (0, server_1.getCardanoClient)());
|
|
395
|
+
const won = await db.run(UPDATE.entity(TransactionSubmissions)
|
|
396
|
+
.set({ status: resolved === 'confirmed' ? 'submitted' : 'failed', resolution: (0, resolution_1.resolutionNote)(resolved, req.user?.id, note) })
|
|
397
|
+
.where({ id: submissionId, status: 'unresolved' }));
|
|
398
|
+
if (won === 0)
|
|
399
|
+
throw (0, resolution_1.resolvedConcurrently)('ResolveSubmission');
|
|
400
|
+
logger.warn({ submissionId, outcome: resolved, by: req.user?.id }, 'Unresolved submission resolved by an operator');
|
|
401
|
+
return db.run(SELECT.one.from(TransactionSubmissions).where({ id: submissionId }));
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
// GetTransactionBuildsByAddress: address ↔ build associations.
|
|
900
405
|
srv.on('GetTransactionBuildsByAddress', async (req) => {
|
|
901
406
|
logger.debug('GetTransactionBuildsByAddress Action handler called');
|
|
902
407
|
const { address } = req.data;
|
|
903
|
-
// Validate inputs
|
|
904
408
|
if (!address)
|
|
905
409
|
return (0, errors_1.rejectMissing)(req, 'GetTransactionBuildsByAddress', 'address');
|
|
906
410
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
907
411
|
return (0, errors_1.rejectInvalid)(req, 'GetTransactionBuildsByAddress', 'Invalid bech32 address format', 'address');
|
|
908
|
-
|
|
909
|
-
return (0, backend_request_handler_1.handleRequest)(req,
|
|
910
|
-
return db.run(SELECT.from(AddressTransactionBuilds).where({ address_address: address }));
|
|
911
|
-
});
|
|
412
|
+
const { limit, skip } = (0, paging_1.pageOf)(req.data, 1000);
|
|
413
|
+
return (0, backend_request_handler_1.handleRequest)(req, (db) => db.run(SELECT.from(AddressTransactionBuilds).where({ address_address: address }).orderBy('txBuild_id').limit(limit, skip)));
|
|
912
414
|
});
|
|
913
|
-
|
|
914
|
-
* Derive the enterprise script address + script hash for a validator script,
|
|
915
|
-
* optionally after applying PlutusData parameters. No transaction is built.
|
|
916
|
-
*/
|
|
415
|
+
// DeriveScriptAddress: enterprise address + hash of a validator, optionally parameterized.
|
|
917
416
|
srv.on('DeriveScriptAddress', async (req) => {
|
|
918
417
|
const { validatorScript, scriptParamsJson, network } = req.data;
|
|
919
418
|
if (!validatorScript)
|
|
@@ -923,7 +422,7 @@ module.exports = (srv) => {
|
|
|
923
422
|
}
|
|
924
423
|
let scriptParams;
|
|
925
424
|
if (scriptParamsJson) {
|
|
926
|
-
const jsonResult = (0, validators_1.
|
|
425
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
927
426
|
if (!jsonResult.valid)
|
|
928
427
|
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', jsonResult.error, 'scriptParamsJson');
|
|
929
428
|
if (!Array.isArray(jsonResult.parsed)) {
|
|
@@ -931,21 +430,14 @@ module.exports = (srv) => {
|
|
|
931
430
|
}
|
|
932
431
|
scriptParams = jsonResult.parsed;
|
|
933
432
|
}
|
|
934
|
-
if (network && !VALID_DERIVE_NETWORKS.includes(network)) {
|
|
935
|
-
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', `Invalid network "${network}". Must be one of: ${VALID_DERIVE_NETWORKS.join(', ')}`, 'network');
|
|
936
|
-
}
|
|
937
433
|
return (0, backend_request_handler_1.handleRequest)(req, async () => {
|
|
938
|
-
//
|
|
939
|
-
|
|
940
|
-
// keeps that 503 distinct from the 400 used for malformed validatorScript bytes.
|
|
941
|
-
const targetNetwork = network
|
|
942
|
-
? network
|
|
943
|
-
: (0, server_1.getCardanoClient)().network;
|
|
434
|
+
// Resolved outside the CBOR try/catch so an uninitialized client stays a 503, not a 400.
|
|
435
|
+
const targetNetwork = network ?? (0, server_1.getCardanoClient)().network;
|
|
944
436
|
try {
|
|
945
437
|
const finalScript = scriptParams && scriptParams.length > 0
|
|
946
438
|
? (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams)
|
|
947
439
|
: validatorScript;
|
|
948
|
-
const scriptHash =
|
|
440
|
+
const scriptHash = (0, build_request_1.scriptHashOf)(finalScript);
|
|
949
441
|
const scriptAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHash, targetNetwork);
|
|
950
442
|
return { scriptAddress, scriptHash };
|
|
951
443
|
}
|
|
@@ -955,10 +447,7 @@ module.exports = (srv) => {
|
|
|
955
447
|
}
|
|
956
448
|
});
|
|
957
449
|
});
|
|
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
|
-
*/
|
|
450
|
+
// ExtractPaymentKeyHash: 28-byte payment credential of a bech32 address; pure local decoding.
|
|
962
451
|
srv.on('ExtractPaymentKeyHash', async (req) => {
|
|
963
452
|
const { address } = req.data;
|
|
964
453
|
if (!address)
|
|
@@ -966,20 +455,14 @@ module.exports = (srv) => {
|
|
|
966
455
|
if (!(0, validators_1.isValidBech32Address)(address)) {
|
|
967
456
|
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Invalid bech32 address format', 'address');
|
|
968
457
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
// Cardano address: 1 header byte + 28-byte payment credential + (optional 28-byte stake credential)
|
|
973
|
-
if (bytes.length < 29) {
|
|
974
|
-
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Address is too short to contain a payment credential', 'address');
|
|
975
|
-
}
|
|
976
|
-
const paymentKeyHash = bytes.slice(1, 29).toString('hex');
|
|
977
|
-
return { paymentKeyHash };
|
|
458
|
+
const decoded = (0, mappers_1.decodeShelleyAddress)(address);
|
|
459
|
+
if (!decoded.paymentCredential) {
|
|
460
|
+
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Address carries no payment credential', 'address');
|
|
978
461
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', `Failed to decode address: ${errMsg}`, 'address');
|
|
462
|
+
if (decoded.isScript) {
|
|
463
|
+
return (0, errors_1.rejectInvalid)(req, 'ExtractPaymentKeyHash', 'Address has a script payment credential, not a key hash', 'address');
|
|
982
464
|
}
|
|
465
|
+
return { paymentKeyHash: decoded.paymentCredential };
|
|
983
466
|
});
|
|
984
467
|
};
|
|
985
468
|
//# sourceMappingURL=cardano-tx-service.js.map
|