@odatano/core 1.11.0 → 2.0.0-rc.10
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 +255 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +177 -0
- package/@cds-models/CardanoIndexerService/index.js +27 -0
- package/@cds-models/CardanoODataService/index.d.ts +693 -2172
- package/@cds-models/CardanoODataService/index.js +88 -390
- package/@cds-models/CardanoSignService/index.d.ts +448 -1576
- package/@cds-models/CardanoSignService/index.js +62 -293
- package/@cds-models/CardanoTransactionService/index.d.ts +437 -1494
- package/@cds-models/CardanoTransactionService/index.js +60 -271
- package/@cds-models/CardanoWorkerService/index.d.ts +224 -0
- package/@cds-models/CardanoWorkerService/index.js +32 -0
- package/@cds-models/_/index.d.ts +70 -40
- package/@cds-models/_/index.js +17 -32
- package/@cds-models/cds/outbox/index.d.ts +28 -0
- package/@cds-models/index.d.ts +225 -522
- package/@cds-models/index.js +35 -218
- package/@cds-models/odatano/cardano/index.d.ts +919 -2884
- package/@cds-models/odatano/cardano/index.js +115 -536
- package/@cds-models/sap/common/index.d.ts +196 -600
- package/@cds-models/sap/common/index.js +28 -269
- package/README.md +194 -102
- package/db/schema.cds +388 -1
- package/db/types.cds +48 -0
- package/package.json +48 -33
- package/src/index.d.ts +7 -1
- package/src/index.js +30 -2
- package/src/plugin.js +33 -20
- package/srv/blockchain/backends/blockfrost-backend.d.ts +21 -2
- package/srv/blockchain/backends/blockfrost-backend.js +69 -25
- package/srv/blockchain/backends/cardano-backend.d.ts +69 -0
- package/srv/blockchain/backends/cardano-backend.js +13 -0
- package/srv/blockchain/backends/koios-backend.d.ts +26 -2
- package/srv/blockchain/backends/koios-backend.js +148 -25
- package/srv/blockchain/backends/ogmios-backend.d.ts +60 -9
- package/srv/blockchain/backends/ogmios-backend.js +326 -10
- package/srv/blockchain/cardano-client.d.ts +19 -0
- package/srv/blockchain/cardano-client.js +36 -0
- package/srv/blockchain/cardano-indexer.d.ts +50 -1
- package/srv/blockchain/cardano-indexer.js +193 -0
- package/srv/blockchain/crawler/crawler.d.ts +176 -0
- package/srv/blockchain/crawler/crawler.js +744 -0
- package/srv/blockchain/crawler/hooks.d.ts +43 -0
- package/srv/blockchain/crawler/hooks.js +62 -0
- package/srv/blockchain/crawler/index.d.ts +35 -0
- package/srv/blockchain/crawler/index.js +168 -0
- package/srv/blockchain/crawler/sync-state.d.ts +106 -0
- package/srv/blockchain/crawler/sync-state.js +287 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +45 -0
- package/srv/blockchain/signing/hsm-signer.js +8 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +20 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +104 -20
- package/srv/blockchain/wallet-worker/build-request.d.ts +26 -0
- package/srv/blockchain/wallet-worker/build-request.js +370 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +117 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +290 -0
- package/srv/blockchain/wallet-worker/index.d.ts +14 -0
- package/srv/blockchain/wallet-worker/index.js +80 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +272 -0
- package/srv/blockchain/wallet-worker/job-store.js +597 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +43 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +99 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +57 -0
- package/srv/blockchain/wallet-worker/signers.js +131 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +145 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +542 -0
- package/srv/cardano-agent-service.cds +150 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +16 -0
- package/srv/cardano-indexer-service.cds +106 -0
- package/srv/cardano-indexer-service.d.ts +2 -0
- package/srv/cardano-indexer-service.js +79 -0
- package/srv/cardano-service.js +79 -4
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.d.ts +1 -11
- package/srv/cardano-tx-service.js +107 -200
- package/srv/cardano-worker-service.cds +125 -0
- package/srv/cardano-worker-service.d.ts +2 -0
- package/srv/cardano-worker-service.js +199 -0
- package/srv/server.d.ts +34 -2
- package/srv/server.js +246 -36
- package/srv/utils/agent-grants-config.d.ts +65 -0
- package/srv/utils/agent-grants-config.js +148 -0
- package/srv/utils/agent-grants.d.ts +314 -0
- package/srv/utils/agent-grants.js +821 -0
- package/srv/utils/agent-token-auth.d.ts +19 -0
- package/srv/utils/agent-token-auth.js +81 -0
- package/srv/utils/collections.d.ts +13 -0
- package/srv/utils/collections.js +24 -0
- package/srv/utils/crypto.d.ts +16 -0
- package/srv/utils/crypto.js +75 -0
- package/srv/utils/db-sanitize.d.ts +40 -0
- package/srv/utils/db-sanitize.js +98 -0
- package/srv/utils/error-codes.d.ts +6 -0
- package/srv/utils/error-codes.js +6 -0
- package/srv/utils/errors.d.ts +12 -0
- package/srv/utils/errors.js +45 -0
- package/srv/utils/liveness.d.ts +23 -0
- package/srv/utils/liveness.js +49 -0
- package/srv/utils/mappers.d.ts +27 -0
- package/srv/utils/mappers.js +80 -10
- package/srv/utils/rate-limiter.d.ts +57 -0
- package/srv/utils/rate-limiter.js +126 -0
- package/srv/utils/service-events.d.ts +26 -0
- package/srv/utils/service-events.js +46 -0
- package/srv/utils/tx-request-parsers.d.ts +71 -0
- package/srv/utils/tx-request-parsers.js +202 -0
- package/srv/utils/tx-utils.d.ts +2 -1
- package/srv/utils/tx-utils.js +3 -2
- package/srv/utils/types.d.ts +17 -1
- package/@cds-models/CardanoODataService/index.d.ts.map +0 -1
- package/@cds-models/CardanoODataService/index.js.map +0 -1
- package/@cds-models/CardanoODataService/index.ts +0 -776
- package/@cds-models/CardanoSignService/index.d.ts.map +0 -1
- package/@cds-models/CardanoSignService/index.js.map +0 -1
- package/@cds-models/CardanoSignService/index.ts +0 -569
- package/@cds-models/CardanoTransactionService/index.d.ts.map +0 -1
- package/@cds-models/CardanoTransactionService/index.js.map +0 -1
- package/@cds-models/CardanoTransactionService/index.ts +0 -526
- package/@cds-models/_/index.d.ts.map +0 -1
- package/@cds-models/_/index.js.map +0 -1
- package/@cds-models/_/index.ts +0 -96
- package/@cds-models/cds/outbox/index.ts +0 -27
- package/@cds-models/index.d.ts.map +0 -1
- package/@cds-models/index.js.map +0 -1
- package/@cds-models/index.ts +0 -245
- package/@cds-models/odatano/cardano/index.d.ts.map +0 -1
- package/@cds-models/odatano/cardano/index.js.map +0 -1
- package/@cds-models/odatano/cardano/index.ts +0 -789
- package/@cds-models/sap/common/index.d.ts.map +0 -1
- package/@cds-models/sap/common/index.js.map +0 -1
- package/@cds-models/sap/common/index.ts +0 -249
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareWorkerBuildRequest = prepareWorkerBuildRequest;
|
|
4
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
5
|
+
const errors_1 = require("../../utils/errors");
|
|
6
|
+
const error_codes_1 = require("../../utils/error-codes");
|
|
7
|
+
const validators_1 = require("../../utils/validators");
|
|
8
|
+
const tx_request_parsers_1 = require("../../utils/tx-request-parsers");
|
|
9
|
+
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
10
|
+
const mappers_1 = require("../../utils/mappers");
|
|
11
|
+
const const_1 = require("../../utils/const");
|
|
12
|
+
function fail(message) {
|
|
13
|
+
throw new errors_1.BackendError(message, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Presence-only check for required payload fields. Format validation (bech32,
|
|
17
|
+
* hex, amounts) deliberately stays with the builder/indexer, mirroring what a
|
|
18
|
+
* missing field would produce on the synchronous path — the transform's job is
|
|
19
|
+
* the SHAPE, not re-validating content.
|
|
20
|
+
*/
|
|
21
|
+
function requirePresent(raw, required) {
|
|
22
|
+
const missing = required.filter((f) => raw[f] === undefined || raw[f] === null || raw[f] === '');
|
|
23
|
+
if (missing.length > 0)
|
|
24
|
+
fail(`${missing.join(', ')} ${missing.length === 1 ? 'is' : 'are'} required`);
|
|
25
|
+
}
|
|
26
|
+
function parseJsonField(raw, field) {
|
|
27
|
+
const value = raw[field];
|
|
28
|
+
if (value == null)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (typeof value !== 'string')
|
|
31
|
+
fail(`${field} must be a JSON string`);
|
|
32
|
+
const result = (0, validators_1.validateJsonWithLimits)(value, field);
|
|
33
|
+
if (!result.valid)
|
|
34
|
+
fail(result.error);
|
|
35
|
+
return result.parsed;
|
|
36
|
+
}
|
|
37
|
+
function parseScriptParams(raw) {
|
|
38
|
+
const parsed = parseJsonField(raw, 'scriptParamsJson');
|
|
39
|
+
if (parsed === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (!Array.isArray(parsed))
|
|
42
|
+
fail('scriptParamsJson must be a JSON array');
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
/** Mirrors the BuildMint/BuildPlutusSpend mint-action parsing (bigint quantities,
|
|
46
|
+
* multi-policy per-action fields). */
|
|
47
|
+
function parseMintActions(raw, allowBareNames) {
|
|
48
|
+
const parsed = parseJsonField(raw, 'mintActionsJson');
|
|
49
|
+
if (!Array.isArray(parsed))
|
|
50
|
+
fail('mintActionsJson must be a JSON array');
|
|
51
|
+
return parsed.map((rawAction, i) => {
|
|
52
|
+
if (!rawAction || typeof rawAction !== 'object') {
|
|
53
|
+
fail('Each mint action must be an object with assetUnit and quantity');
|
|
54
|
+
}
|
|
55
|
+
const action = rawAction;
|
|
56
|
+
if (typeof action.quantity !== 'string' || !/^-?\d+$/.test(action.quantity)) {
|
|
57
|
+
fail(`Invalid quantity: "${String(action.quantity)}" — must be an integer string`);
|
|
58
|
+
}
|
|
59
|
+
if (typeof action.assetUnit !== 'string')
|
|
60
|
+
fail('Each mint action must have an assetUnit string');
|
|
61
|
+
// Multi-policy mint FR: optional per-action mintingPolicyScript + redeemerJson.
|
|
62
|
+
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, i);
|
|
63
|
+
if (policyFields.error)
|
|
64
|
+
fail(policyFields.error);
|
|
65
|
+
let actionPolicyId;
|
|
66
|
+
if (policyFields.script) {
|
|
67
|
+
actionPolicyId = scriptHashOf(policyFields.script, `mintActions[${i}].mintingPolicyScript is not a valid Plutus script`);
|
|
68
|
+
}
|
|
69
|
+
const bareAssetNameForExpansion = (allowBareNames || !!actionPolicyId) &&
|
|
70
|
+
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
71
|
+
action.assetUnit.length % 2 === 0 &&
|
|
72
|
+
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
73
|
+
if (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion) {
|
|
74
|
+
fail(`Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson or a per-action mintingPolicyScript is set)`);
|
|
75
|
+
}
|
|
76
|
+
let assetUnit = action.assetUnit;
|
|
77
|
+
if (actionPolicyId) {
|
|
78
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
79
|
+
assetUnit = actionPolicyId + assetUnit;
|
|
80
|
+
}
|
|
81
|
+
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
82
|
+
fail(`mintActions[${i}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
assetUnit,
|
|
87
|
+
quantity: BigInt(action.quantity),
|
|
88
|
+
...(typeof action.redeemer === 'number' ? { redeemer: action.redeemer } : {}),
|
|
89
|
+
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
90
|
+
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function scriptHashOf(scriptHex, context) {
|
|
95
|
+
try {
|
|
96
|
+
return cardano_ledger_ts_1.Script.fromCbor(Buffer.from(scriptHex, 'hex')).hash.toString();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
return fail(`${context}: ${err instanceof Error ? err.message : String(err)}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* BUG 9 mirror: every (expanded) mint action must carry the effective policy id —
|
|
104
|
+
* parseAssetUnit silently discards the first 56 hex chars, so a mismatched prefix
|
|
105
|
+
* would mint a truncated asset name.
|
|
106
|
+
*/
|
|
107
|
+
function assertPolicyPrefix(actions, policyId) {
|
|
108
|
+
// Actions with their own per-action script were already checked against THAT
|
|
109
|
+
// script's policy id during parsing.
|
|
110
|
+
const mismatch = actions.find((a) => !a.mintingPolicyScript && !a.assetUnit.toLowerCase().startsWith(policyId));
|
|
111
|
+
if (mismatch) {
|
|
112
|
+
fail(`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)`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function takeParsed(result) {
|
|
116
|
+
if (result.error)
|
|
117
|
+
fail(result.error);
|
|
118
|
+
return result.parsed;
|
|
119
|
+
}
|
|
120
|
+
function prepareSimpleAda(raw, network) {
|
|
121
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
122
|
+
const clean = { ...raw };
|
|
123
|
+
clean.forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
124
|
+
delete clean.forceInputsJson;
|
|
125
|
+
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
126
|
+
if (outputDatum !== undefined)
|
|
127
|
+
clean.outputDatum = outputDatum;
|
|
128
|
+
delete clean.outputDatumJson;
|
|
129
|
+
const assets = takeParsed((0, tx_request_parsers_1.parseAssetsArray)(raw.assetsJson, 'assetsJson'));
|
|
130
|
+
if (assets)
|
|
131
|
+
clean.assets = assets;
|
|
132
|
+
delete clean.assetsJson;
|
|
133
|
+
const scriptParams = parseScriptParams(raw);
|
|
134
|
+
if (raw.lockOnScript) {
|
|
135
|
+
const validatorScript = raw.validatorScript;
|
|
136
|
+
if (typeof validatorScript !== 'string' || !validatorScript) {
|
|
137
|
+
fail('lockOnScript requires validatorScript to derive the script address');
|
|
138
|
+
}
|
|
139
|
+
const finalScript = scriptParams && scriptParams.length > 0
|
|
140
|
+
? (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams)
|
|
141
|
+
: validatorScript;
|
|
142
|
+
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHashOf(finalScript, 'Failed to derive script address'), network);
|
|
143
|
+
}
|
|
144
|
+
delete clean.validatorScript;
|
|
145
|
+
delete clean.scriptParamsJson;
|
|
146
|
+
delete clean.lockOnScript;
|
|
147
|
+
if (raw.referenceScriptHex)
|
|
148
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
149
|
+
delete clean.referenceScriptHex;
|
|
150
|
+
return clean;
|
|
151
|
+
}
|
|
152
|
+
function prepareMetadata(raw) {
|
|
153
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'metadataJson']);
|
|
154
|
+
const parsedMetadata = parseJsonField(raw, 'metadataJson');
|
|
155
|
+
return { ...raw, metadataJson: parsedMetadata };
|
|
156
|
+
}
|
|
157
|
+
function prepareMultiAsset(raw) {
|
|
158
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'assetsJson']);
|
|
159
|
+
const assets = takeParsed((0, tx_request_parsers_1.parseAssetsArray)(raw.assetsJson, 'assetsJson'));
|
|
160
|
+
if (!assets || assets.length === 0)
|
|
161
|
+
fail('assetsJson must contain at least one asset');
|
|
162
|
+
const clean = { ...raw, assets };
|
|
163
|
+
delete clean.assetsJson;
|
|
164
|
+
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
165
|
+
if (outputDatum !== undefined)
|
|
166
|
+
clean.outputDatum = outputDatum;
|
|
167
|
+
delete clean.outputDatumJson;
|
|
168
|
+
if (raw.referenceScriptHex)
|
|
169
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
170
|
+
delete clean.referenceScriptHex;
|
|
171
|
+
return clean;
|
|
172
|
+
}
|
|
173
|
+
function prepareMint(raw, network) {
|
|
174
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
175
|
+
const scriptParams = parseScriptParams(raw);
|
|
176
|
+
const mintActions = parseMintActions(raw, !!scriptParams);
|
|
177
|
+
const requiredSigners = takeParsed((0, tx_request_parsers_1.parseRequiredSigners)(raw.requiredSignersJson));
|
|
178
|
+
const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
|
|
179
|
+
const mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
180
|
+
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
181
|
+
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
182
|
+
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
183
|
+
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
184
|
+
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
185
|
+
}
|
|
186
|
+
let parsedMetadata;
|
|
187
|
+
if (raw.metadataJson) {
|
|
188
|
+
parsedMetadata = parseJsonField(raw, 'metadataJson');
|
|
189
|
+
if (typeof parsedMetadata !== 'object' || parsedMetadata === null || Array.isArray(parsedMetadata)) {
|
|
190
|
+
fail('metadataJson must be an object with numeric label keys');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const clean = { ...raw };
|
|
194
|
+
delete clean.mintActionsJson;
|
|
195
|
+
delete clean.requiredSignersJson;
|
|
196
|
+
delete clean.scriptParamsJson;
|
|
197
|
+
delete clean.inlineDatumJson;
|
|
198
|
+
delete clean.mintRedeemerJson;
|
|
199
|
+
delete clean.lockOnScript;
|
|
200
|
+
delete clean.forceInputsJson;
|
|
201
|
+
delete clean.referenceInputsJson;
|
|
202
|
+
delete clean.extraOutputsJson;
|
|
203
|
+
if (parsedMetadata)
|
|
204
|
+
clean.metadataJson = parsedMetadata;
|
|
205
|
+
else
|
|
206
|
+
delete clean.metadataJson;
|
|
207
|
+
if (raw.referenceScriptHex)
|
|
208
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
209
|
+
delete clean.referenceScriptHex;
|
|
210
|
+
// Apply script parameters (parameterized policies), expand bare asset names,
|
|
211
|
+
// route lockOnScript output — mirrors BuildMintTransaction.
|
|
212
|
+
let finalMintingPolicyScript = raw.mintingPolicyScript;
|
|
213
|
+
let effectivePolicyId;
|
|
214
|
+
if (scriptParams && scriptParams.length > 0) {
|
|
215
|
+
try {
|
|
216
|
+
finalMintingPolicyScript = (0, tx_build_helper_1.applyScriptParameters)(raw.mintingPolicyScript, scriptParams);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
fail(`Failed to apply script parameters: ${err instanceof Error ? err.message : String(err)}`);
|
|
220
|
+
}
|
|
221
|
+
effectivePolicyId = scriptHashOf(finalMintingPolicyScript, 'Failed to hash applied script');
|
|
222
|
+
for (const action of mintActions) {
|
|
223
|
+
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
224
|
+
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (raw.lockOnScript) {
|
|
228
|
+
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, network);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
try {
|
|
233
|
+
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(raw.mintingPolicyScript, 'hex')).hash.toString();
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (effectivePolicyId)
|
|
240
|
+
assertPolicyPrefix(mintActions, effectivePolicyId);
|
|
241
|
+
return {
|
|
242
|
+
...clean,
|
|
243
|
+
mintActions,
|
|
244
|
+
mintingPolicyScript: finalMintingPolicyScript,
|
|
245
|
+
requiredSigners,
|
|
246
|
+
inlineDatum,
|
|
247
|
+
mintRedeemer,
|
|
248
|
+
forceInputs,
|
|
249
|
+
referenceInputs,
|
|
250
|
+
extraOutputs,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function preparePlutusSpend(raw, network) {
|
|
254
|
+
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'validatorScript', 'scriptTxHash', 'redeemerJson']);
|
|
255
|
+
if (raw.scriptOutputIndex === undefined || raw.scriptOutputIndex === null) {
|
|
256
|
+
fail('scriptOutputIndex is required');
|
|
257
|
+
}
|
|
258
|
+
const parsedRedeemer = parseJsonField(raw, 'redeemerJson');
|
|
259
|
+
const parsedDatum = parseJsonField(raw, 'datumJson');
|
|
260
|
+
const requiredSigners = takeParsed((0, tx_request_parsers_1.parseRequiredSigners)(raw.requiredSignersJson));
|
|
261
|
+
const scriptParams = parseScriptParams(raw);
|
|
262
|
+
const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
|
|
263
|
+
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
264
|
+
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
265
|
+
}
|
|
266
|
+
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
267
|
+
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
268
|
+
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
269
|
+
// Optional combined spend+mint (FR-1) — mirrors BuildPlutusSpendTransaction.
|
|
270
|
+
const validatorScript = raw.validatorScript;
|
|
271
|
+
const mintingPolicyScript = raw.mintingPolicyScript;
|
|
272
|
+
let mintActions;
|
|
273
|
+
let mintRedeemer;
|
|
274
|
+
if (raw.mintActionsJson) {
|
|
275
|
+
if (!mintingPolicyScript)
|
|
276
|
+
fail('mintActionsJson requires mintingPolicyScript');
|
|
277
|
+
mintActions = parseMintActions(raw, !!scriptParams && mintingPolicyScript === validatorScript);
|
|
278
|
+
mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
279
|
+
}
|
|
280
|
+
else if (mintingPolicyScript || raw.mintRedeemerJson) {
|
|
281
|
+
fail('mintingPolicyScript / mintRedeemerJson require mintActionsJson');
|
|
282
|
+
}
|
|
283
|
+
let finalValidatorScript = validatorScript;
|
|
284
|
+
if (scriptParams && scriptParams.length > 0) {
|
|
285
|
+
try {
|
|
286
|
+
finalValidatorScript = (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams);
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
fail(`Failed to apply script parameters: ${err instanceof Error ? err.message : String(err)}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
let finalMintingPolicyScript;
|
|
293
|
+
if (mintActions) {
|
|
294
|
+
finalMintingPolicyScript = (mintingPolicyScript === validatorScript) ? finalValidatorScript : mintingPolicyScript;
|
|
295
|
+
if (finalMintingPolicyScript && scriptParams && scriptParams.length > 0 && mintingPolicyScript === validatorScript) {
|
|
296
|
+
const appliedPolicyId = scriptHashOf(finalMintingPolicyScript, 'Failed to hash applied script');
|
|
297
|
+
for (const action of mintActions) {
|
|
298
|
+
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
299
|
+
action.assetUnit = appliedPolicyId + action.assetUnit;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (finalMintingPolicyScript) {
|
|
304
|
+
let mintPolicyId;
|
|
305
|
+
try {
|
|
306
|
+
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// invalid script CBOR — skip the prefix check; the builder rejects it with its own message
|
|
310
|
+
}
|
|
311
|
+
if (mintPolicyId)
|
|
312
|
+
assertPolicyPrefix(mintActions, mintPolicyId);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const clean = {
|
|
316
|
+
...raw,
|
|
317
|
+
plutusScriptExecution: {
|
|
318
|
+
validatorScript: finalValidatorScript,
|
|
319
|
+
scriptUtxo: {
|
|
320
|
+
txHash: raw.scriptTxHash,
|
|
321
|
+
outputIndex: raw.scriptOutputIndex,
|
|
322
|
+
},
|
|
323
|
+
redeemer: parsedRedeemer,
|
|
324
|
+
datum: parsedDatum,
|
|
325
|
+
},
|
|
326
|
+
requiredSigners,
|
|
327
|
+
inlineDatum,
|
|
328
|
+
forceInputs,
|
|
329
|
+
referenceInputs,
|
|
330
|
+
extraOutputs,
|
|
331
|
+
mintActions,
|
|
332
|
+
mintingPolicyScript: finalMintingPolicyScript,
|
|
333
|
+
mintRedeemer,
|
|
334
|
+
};
|
|
335
|
+
if (raw.referenceScriptHex)
|
|
336
|
+
clean.referenceScript = raw.referenceScriptHex;
|
|
337
|
+
delete clean.requiredSignersJson;
|
|
338
|
+
delete clean.scriptParamsJson;
|
|
339
|
+
delete clean.inlineDatumJson;
|
|
340
|
+
delete clean.forceInputsJson;
|
|
341
|
+
delete clean.referenceInputsJson;
|
|
342
|
+
delete clean.extraOutputsJson;
|
|
343
|
+
delete clean.mintActionsJson;
|
|
344
|
+
delete clean.mintRedeemerJson;
|
|
345
|
+
delete clean.referenceScriptHex;
|
|
346
|
+
delete clean.redeemerJson;
|
|
347
|
+
delete clean.datumJson;
|
|
348
|
+
if (raw.lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
349
|
+
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHashOf(finalValidatorScript, 'Failed to derive script address'), network);
|
|
350
|
+
}
|
|
351
|
+
delete clean.lockOnScript;
|
|
352
|
+
return clean;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Transform the raw job request (documented Build*-action payload) into the
|
|
356
|
+
* TxBuildRequest the matching CardanoIndexer build method expects. Throws
|
|
357
|
+
* BackendError 400 INVALID_INPUT for malformed payloads (terminal job failure).
|
|
358
|
+
*/
|
|
359
|
+
function prepareWorkerBuildRequest(kind, raw, network) {
|
|
360
|
+
switch (kind) {
|
|
361
|
+
case 'simpleAda': return prepareSimpleAda(raw, network);
|
|
362
|
+
case 'metadata': return prepareMetadata(raw);
|
|
363
|
+
case 'multiAsset': return prepareMultiAsset(raw);
|
|
364
|
+
case 'mint': return prepareMint(raw, network);
|
|
365
|
+
case 'plutusSpend': return preparePlutusSpend(raw, network);
|
|
366
|
+
default:
|
|
367
|
+
return fail(`Unsupported job kind "${String(kind)}"`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=build-request.js.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CardanoClient } from '../cardano-client';
|
|
2
|
+
/**
|
|
3
|
+
* Confirmation tracker (v2.0, design §7).
|
|
4
|
+
*
|
|
5
|
+
* Watches `submitted` jobs until their tx sits at depth ≥ `confirmationDepth`:
|
|
6
|
+
* - Crawler hook (preferred, zero extra load): `blockIndexed` events match
|
|
7
|
+
* submitted tx hashes and carry the advancing tip; `reorg` events invalidate
|
|
8
|
+
* confirmation points behind the fork and optionally re-submit the SAME
|
|
9
|
+
* signed CBOR (never a rebuild — the double-spend guard).
|
|
10
|
+
* - Polling fallback (always on, hook path just accelerates): every
|
|
11
|
+
* `pollIntervalMs` unfound txs are looked up via `client.getTransaction`
|
|
12
|
+
* and the tip via `client.getLatestBlock`.
|
|
13
|
+
*
|
|
14
|
+
* A tx that stays unseen past `confirmationTimeoutMs` fails as TX_DROPPED —
|
|
15
|
+
* safe to retry from the caller, because the guard is the on-chain lookup itself.
|
|
16
|
+
*
|
|
17
|
+
* Confirmations are counted as `tipHeight - foundHeight + 1`, so depth 1 means
|
|
18
|
+
* "confirmed as soon as included in a block".
|
|
19
|
+
*/
|
|
20
|
+
export interface TrackedJob {
|
|
21
|
+
jobId: string;
|
|
22
|
+
walletId: string;
|
|
23
|
+
/** Job kind, carried so terminal events can name it without a DB read. */
|
|
24
|
+
kind: string | null;
|
|
25
|
+
txHash: string;
|
|
26
|
+
signedTxCbor: string | null;
|
|
27
|
+
/** ISO timestamp of mempool acceptance (timeout base). */
|
|
28
|
+
submittedAt: string;
|
|
29
|
+
foundSlot: number | null;
|
|
30
|
+
foundHeight: number | null;
|
|
31
|
+
/**
|
|
32
|
+
* Polling round in which the tx was last SEEN on-chain (found or
|
|
33
|
+
* re-validated). A job found in the current round needs no second lookup
|
|
34
|
+
* before it is confirmed; one found in an earlier round is re-checked, so a
|
|
35
|
+
* rollback the crawler did not report (crawler off) cannot slip through.
|
|
36
|
+
*/
|
|
37
|
+
seenRound?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ConfirmationTrackerOptions {
|
|
40
|
+
confirmationDepth: number;
|
|
41
|
+
confirmationTimeoutMs: number;
|
|
42
|
+
pollIntervalMs: number;
|
|
43
|
+
resubmitOnRollback: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface ConfirmationTrackerDeps {
|
|
46
|
+
client: CardanoClient;
|
|
47
|
+
options: ConfirmationTrackerOptions;
|
|
48
|
+
/** Called exactly once per job when it reaches a terminal state. */
|
|
49
|
+
onFinal?: (job: {
|
|
50
|
+
jobId: string;
|
|
51
|
+
walletId: string;
|
|
52
|
+
outcome: 'confirmed' | 'failed';
|
|
53
|
+
kind: string | null;
|
|
54
|
+
/** The tracked transaction — present even on failure (it was submitted). */
|
|
55
|
+
txHash: string;
|
|
56
|
+
errorCode?: string;
|
|
57
|
+
errorMessage?: string;
|
|
58
|
+
}) => void;
|
|
59
|
+
}
|
|
60
|
+
export declare class ConfirmationTracker {
|
|
61
|
+
private readonly deps;
|
|
62
|
+
private readonly pending;
|
|
63
|
+
private readonly blockListener;
|
|
64
|
+
private readonly reorgListener;
|
|
65
|
+
private pollTimer;
|
|
66
|
+
private running;
|
|
67
|
+
private polling;
|
|
68
|
+
private lastKnownTipHeight;
|
|
69
|
+
/** Polling round counter; see TrackedJob.seenRound. */
|
|
70
|
+
private round;
|
|
71
|
+
constructor(deps: ConfirmationTrackerDeps);
|
|
72
|
+
start(): void;
|
|
73
|
+
stop(): void;
|
|
74
|
+
/** Number of jobs currently awaiting confirmation. */
|
|
75
|
+
size(): number;
|
|
76
|
+
/** Register a submitted job for confirmation watching. Idempotent per jobId. */
|
|
77
|
+
track(job: {
|
|
78
|
+
jobId: string;
|
|
79
|
+
walletId: string;
|
|
80
|
+
kind?: string | null;
|
|
81
|
+
txHash: string;
|
|
82
|
+
signedTxCbor: string | null;
|
|
83
|
+
submittedAt?: string | null;
|
|
84
|
+
confirmedSlot?: number | null;
|
|
85
|
+
confirmedHeight?: number | null;
|
|
86
|
+
}): void;
|
|
87
|
+
private onBlockIndexed;
|
|
88
|
+
private onReorg;
|
|
89
|
+
/**
|
|
90
|
+
* The recorded inclusion is gone (a reorg the crawler reported, or a polling
|
|
91
|
+
* re-check that no longer finds the tx): back to watching, and optionally
|
|
92
|
+
* re-submit the SAME signed CBOR — never a rebuild, that is the double-spend
|
|
93
|
+
* guard. "Already known" means the tx survived into the new chain's mempool;
|
|
94
|
+
* that is success, not an error.
|
|
95
|
+
*/
|
|
96
|
+
private forgetInclusion;
|
|
97
|
+
/** One polling round. Public for tests; guarded against overlapping rounds. */
|
|
98
|
+
pollOnce(): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Confirm every found job whose depth requirement is met by the known tip.
|
|
101
|
+
* `revalidate` (polling path): an inclusion not seen in THIS round is looked
|
|
102
|
+
* up again first — the crawler's reorg events are the only rollback signal,
|
|
103
|
+
* and with the crawler off there is none, so a tx that was found at height N
|
|
104
|
+
* and then rolled back would otherwise be confirmed on the tip alone.
|
|
105
|
+
*/
|
|
106
|
+
private confirmMature;
|
|
107
|
+
/**
|
|
108
|
+
* Is the tx still on-chain, and still deep enough? Re-reads it; a tx that
|
|
109
|
+
* moved to another block (re-included after a rollback) gets its new point
|
|
110
|
+
* and is judged at the new height; one that is gone is forgotten (back to
|
|
111
|
+
* watching, optional same-CBOR re-submit) and the tip is re-learned next
|
|
112
|
+
* round, because the pre-rollback tip may overstate the depth.
|
|
113
|
+
*/
|
|
114
|
+
private stillIncluded;
|
|
115
|
+
private finalize;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=confirmation-tracker.d.ts.map
|