@odatano/core 2.0.0-rc.50 → 2.0.0-rc.52
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/CardanoBackendService/index.d.ts +14 -3
- package/@cds-models/CardanoBackendService/index.js +1 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +98 -0
- package/@cds-models/CardanoIndexerService/index.js +10 -0
- package/@cds-models/CardanoODataService/index.d.ts +3 -0
- package/@cds-models/CardanoSignService/index.d.ts +13 -0
- package/@cds-models/CardanoSignService/index.js +1 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +12 -0
- package/@cds-models/CardanoTransactionService/index.js +1 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +28 -0
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +13 -3
- package/@cds-models/index.js +4 -3
- package/@cds-models/odatano/cardano/index.d.ts +14 -0
- package/README.md +45 -149
- package/db/schema.cds +63 -10
- package/db/types.cds +10 -0
- package/package.json +7 -44
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +209 -15
- package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -4
- package/srv/blockchain/backends/blockfrost-backend.js +61 -45
- 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 +6 -3
- package/srv/blockchain/backends/koios-backend.d.ts +9 -6
- package/srv/blockchain/backends/koios-backend.js +145 -207
- package/srv/blockchain/backends/odatano-backend.d.ts +2 -1
- package/srv/blockchain/backends/odatano-backend.js +51 -9
- package/srv/blockchain/backends/ogmios-backend.d.ts +1 -2
- package/srv/blockchain/backends/ogmios-backend.js +82 -48
- package/srv/blockchain/cardano-client.d.ts +15 -5
- package/srv/blockchain/cardano-client.js +143 -71
- package/srv/blockchain/cardano-indexer.d.ts +27 -16
- package/srv/blockchain/cardano-indexer.js +223 -102
- package/srv/blockchain/circuit-breaker.d.ts +1 -0
- package/srv/blockchain/circuit-breaker.js +6 -0
- package/srv/blockchain/crawler/account-snapshots.js +22 -2
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +29 -29
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +3 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +4 -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 +4 -0
- package/srv/blockchain/crawler/certificate-backfill.js +15 -3
- package/srv/blockchain/crawler/crawler.d.ts +22 -1
- package/srv/blockchain/crawler/crawler.js +223 -24
- package/srv/blockchain/crawler/credential-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/credential-backfill.js +43 -66
- package/srv/blockchain/crawler/input-asset-copies.d.ts +4 -4
- package/srv/blockchain/crawler/input-asset-copies.js +17 -27
- 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 +6 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +23 -19
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +3 -1
- package/srv/blockchain/crawler/output-datum-backfill.js +8 -18
- package/srv/blockchain/crawler/sync-state.d.ts +5 -1
- package/srv/blockchain/crawler/sync-state.js +63 -106
- package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/transaction-backfill.js +6 -13
- package/srv/blockchain/crawler/utxo-set-import.js +2 -2
- 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 +2 -2
- package/srv/blockchain/ledger-state.js +139 -37
- package/srv/blockchain/signing/external-signer.js +5 -5
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- 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.js +10 -13
- package/srv/blockchain/signing/submission-finalizer.d.ts +17 -3
- package/srv/blockchain/signing/submission-finalizer.js +90 -29
- package/srv/blockchain/stored-chain.d.ts +1 -2
- package/srv/blockchain/stored-chain.js +36 -15
- package/srv/blockchain/transaction-building/buildooor-tx.js +16 -10
- package/srv/blockchain/transaction-presence.d.ts +8 -1
- package/srv/blockchain/transaction-presence.js +12 -12
- package/srv/blockchain/wallet-worker/build-request.d.ts +6 -6
- package/srv/blockchain/wallet-worker/build-request.js +35 -365
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +23 -2
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +140 -23
- 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 +28 -2
- package/srv/blockchain/wallet-worker/job-store.js +107 -80
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +21 -2
- package/srv/blockchain/wallet-worker/wallet-worker.js +241 -57
- package/srv/cardano-agent-service.cds +1 -1
- package/srv/cardano-agent-service.js +8 -0
- package/srv/cardano-backend-service.cds +4 -1
- package/srv/cardano-backend-service.js +26 -9
- package/srv/cardano-indexer-service.cds +448 -387
- package/srv/cardano-indexer-service.js +226 -281
- package/srv/cardano-service.cds +7 -5
- package/srv/cardano-service.js +404 -69
- package/srv/cardano-sign-service.cds +11 -1
- package/srv/cardano-sign-service.js +161 -108
- package/srv/cardano-tx-service.cds +23 -12
- package/srv/cardano-tx-service.js +105 -604
- package/srv/cardano-worker-service.cds +25 -2
- package/srv/cardano-worker-service.js +56 -4
- package/srv/config.d.ts +4 -0
- package/srv/config.js +10 -0
- package/srv/server.js +5 -7
- package/srv/utils/agent-access.d.ts +4 -2
- package/srv/utils/agent-access.js +26 -7
- package/srv/utils/agent-grants.d.ts +1 -1
- package/srv/utils/agent-grants.js +7 -8
- package/srv/utils/agent-token-auth.js +45 -5
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +1 -0
- package/srv/utils/collections.js +11 -0
- package/srv/utils/const.d.ts +10 -2
- package/srv/utils/const.js +13 -6
- package/srv/utils/crypto.js +5 -4
- package/srv/utils/db-indexes.d.ts +5 -1
- package/srv/utils/db-indexes.js +79 -14
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -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 +1 -0
- package/srv/utils/epoch-slots.js +7 -0
- package/srv/utils/error-codes.d.ts +4 -0
- package/srv/utils/error-codes.js +4 -0
- package/srv/utils/errors.d.ts +10 -1
- package/srv/utils/errors.js +51 -9
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/mappers.d.ts +9 -0
- package/srv/utils/mappers.js +57 -67
- 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 +8 -3
- package/srv/utils/pg-inline-json.js +3 -3
- package/srv/utils/pg-order-nulls.js +3 -3
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/tx-build-helper.d.ts +15 -0
- package/srv/utils/tx-build-helper.js +28 -13
- package/srv/utils/types.d.ts +36 -44
- package/srv/utils/types.js +1 -17
- package/srv/utils/validators.d.ts +2 -2
- package/srv/utils/validators.js +14 -25
|
@@ -2,386 +2,56 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MAX_PAYOUT_OUTPUTS = void 0;
|
|
4
4
|
exports.preparePayoutRequest = preparePayoutRequest;
|
|
5
|
+
exports.parseJobRequest = parseJobRequest;
|
|
6
|
+
exports.submitSignedProblem = submitSignedProblem;
|
|
5
7
|
exports.prepareWorkerBuildRequest = prepareWorkerBuildRequest;
|
|
6
|
-
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
7
8
|
const errors_1 = require("../../utils/errors");
|
|
8
9
|
const error_codes_1 = require("../../utils/error-codes");
|
|
10
|
+
const build_request_1 = require("../../utils/build-request");
|
|
9
11
|
const validators_1 = require("../../utils/validators");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const landing_proof_1 = require("../signing/landing-proof");
|
|
13
|
+
var build_request_2 = require("../../utils/build-request");
|
|
14
|
+
Object.defineProperty(exports, "MAX_PAYOUT_OUTPUTS", { enumerable: true, get: function () { return build_request_2.MAX_PAYOUT_OUTPUTS; } });
|
|
15
|
+
// A stored wallet-job request becomes the request the build methods take, checked as the Build*
|
|
16
|
+
// action of the same kind checks it. Invalid input throws 400 so the job fails at once.
|
|
17
|
+
function requestOf(result) {
|
|
18
|
+
if ('error' in result)
|
|
19
|
+
throw new errors_1.BackendError(result.error, 400, error_codes_1.ERROR_CODES.INVALID_INPUT, undefined, undefined, result.field);
|
|
20
|
+
return result.request;
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const missing = required.filter((f) => raw[f] === undefined || raw[f] === null || raw[f] === '');
|
|
20
|
-
if (missing.length > 0)
|
|
21
|
-
fail(`${missing.join(', ')} ${missing.length === 1 ? 'is' : 'are'} required`);
|
|
22
|
-
}
|
|
23
|
-
function parseJsonField(raw, field) {
|
|
24
|
-
const value = raw[field];
|
|
25
|
-
if (value == null)
|
|
26
|
-
return undefined;
|
|
27
|
-
if (typeof value !== 'string')
|
|
28
|
-
fail(`${field} must be a JSON string`);
|
|
29
|
-
const result = validators_1.PLUTUS_JSON_FIELDS.has(field) ? (0, validators_1.validatePlutusJson)(value, field) : (0, validators_1.validateJsonWithLimits)(value, field);
|
|
30
|
-
if (!result.valid)
|
|
31
|
-
fail(result.error);
|
|
32
|
-
return result.parsed;
|
|
33
|
-
}
|
|
34
|
-
function parseScriptParams(raw) {
|
|
35
|
-
const parsed = parseJsonField(raw, 'scriptParamsJson');
|
|
36
|
-
if (parsed === undefined)
|
|
37
|
-
return undefined;
|
|
38
|
-
if (!Array.isArray(parsed))
|
|
39
|
-
fail('scriptParamsJson must be a JSON array');
|
|
40
|
-
return parsed;
|
|
41
|
-
}
|
|
42
|
-
/** Mint-action parsing as in BuildMint/BuildPlutusSpend (bigint quantities, per-action policy fields). */
|
|
43
|
-
function parseMintActions(raw, allowBareNames) {
|
|
44
|
-
const parsed = parseJsonField(raw, 'mintActionsJson');
|
|
45
|
-
if (!Array.isArray(parsed))
|
|
46
|
-
fail('mintActionsJson must be a JSON array');
|
|
47
|
-
return parsed.map((rawAction, i) => {
|
|
48
|
-
if (!rawAction || typeof rawAction !== 'object') {
|
|
49
|
-
fail('Each mint action must be an object with assetUnit and quantity');
|
|
50
|
-
}
|
|
51
|
-
const action = rawAction;
|
|
52
|
-
if (typeof action.quantity !== 'string' || !/^-?\d+$/.test(action.quantity)) {
|
|
53
|
-
fail(`Invalid quantity: "${String(action.quantity)}": must be an integer string`);
|
|
54
|
-
}
|
|
55
|
-
if (typeof action.assetUnit !== 'string')
|
|
56
|
-
fail('Each mint action must have an assetUnit string');
|
|
57
|
-
// Optional per-action mintingPolicyScript + redeemerJson (multi-policy mint).
|
|
58
|
-
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, i);
|
|
59
|
-
if (policyFields.error)
|
|
60
|
-
fail(policyFields.error);
|
|
61
|
-
let actionPolicyId;
|
|
62
|
-
if (policyFields.script) {
|
|
63
|
-
actionPolicyId = scriptHashOf(policyFields.script, `mintActions[${i}].mintingPolicyScript is not a valid Plutus script`);
|
|
64
|
-
}
|
|
65
|
-
const bareAssetNameForExpansion = (allowBareNames || !!actionPolicyId) &&
|
|
66
|
-
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
67
|
-
action.assetUnit.length % 2 === 0 &&
|
|
68
|
-
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
69
|
-
if (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion) {
|
|
70
|
-
fail(`Invalid assetUnit: "${action.assetUnit}": must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson or a per-action mintingPolicyScript is set)`);
|
|
71
|
-
}
|
|
72
|
-
let assetUnit = action.assetUnit;
|
|
73
|
-
if (actionPolicyId) {
|
|
74
|
-
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
75
|
-
assetUnit = actionPolicyId + assetUnit;
|
|
76
|
-
}
|
|
77
|
-
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
78
|
-
fail(`mintActions[${i}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
assetUnit,
|
|
83
|
-
quantity: BigInt(action.quantity),
|
|
84
|
-
...(typeof action.redeemer === 'number' ? { redeemer: action.redeemer } : {}),
|
|
85
|
-
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
86
|
-
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
87
|
-
};
|
|
88
|
-
});
|
|
22
|
+
function preparePayoutRequest(raw) {
|
|
23
|
+
return requestOf((0, build_request_1.preparePayoutRequest)(raw));
|
|
89
24
|
}
|
|
90
|
-
|
|
25
|
+
/** A job's requestJson as an object, or null when it is not a JSON object. */
|
|
26
|
+
function parseJobRequest(requestJson) {
|
|
91
27
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
catch (err) {
|
|
95
|
-
return fail(`${context}: ${err instanceof Error ? err.message : String(err)}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/** parseAssetUnit drops the first 56 hex chars, so a wrong policy prefix would mint a truncated name. */
|
|
99
|
-
function assertPolicyPrefix(actions, policyId) {
|
|
100
|
-
// Actions with their own script were already checked against that script's policy id.
|
|
101
|
-
const mismatch = actions.find((a) => !a.mintingPolicyScript && !a.assetUnit.toLowerCase().startsWith(policyId));
|
|
102
|
-
if (mismatch) {
|
|
103
|
-
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)`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function takeParsed(result) {
|
|
107
|
-
if (result.error)
|
|
108
|
-
fail(result.error);
|
|
109
|
-
return result.parsed;
|
|
110
|
-
}
|
|
111
|
-
function prepareSimpleAda(raw, network) {
|
|
112
|
-
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount']);
|
|
113
|
-
const clean = { ...raw };
|
|
114
|
-
clean.forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
115
|
-
delete clean.forceInputsJson;
|
|
116
|
-
clean.protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
|
|
117
|
-
delete clean.protectInputsJson;
|
|
118
|
-
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
119
|
-
if (outputDatum !== undefined)
|
|
120
|
-
clean.outputDatum = outputDatum;
|
|
121
|
-
delete clean.outputDatumJson;
|
|
122
|
-
const assets = takeParsed((0, tx_request_parsers_1.parseAssetsArray)(raw.assetsJson, 'assetsJson'));
|
|
123
|
-
if (assets)
|
|
124
|
-
clean.assets = assets;
|
|
125
|
-
delete clean.assetsJson;
|
|
126
|
-
const scriptParams = parseScriptParams(raw);
|
|
127
|
-
if (raw.lockOnScript) {
|
|
128
|
-
const validatorScript = raw.validatorScript;
|
|
129
|
-
if (typeof validatorScript !== 'string' || !validatorScript) {
|
|
130
|
-
fail('lockOnScript requires validatorScript to derive the script address');
|
|
131
|
-
}
|
|
132
|
-
const finalScript = scriptParams && scriptParams.length > 0
|
|
133
|
-
? (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams)
|
|
134
|
-
: validatorScript;
|
|
135
|
-
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHashOf(finalScript, 'Failed to derive script address'), network);
|
|
136
|
-
}
|
|
137
|
-
delete clean.validatorScript;
|
|
138
|
-
delete clean.scriptParamsJson;
|
|
139
|
-
delete clean.lockOnScript;
|
|
140
|
-
if (raw.referenceScriptHex)
|
|
141
|
-
clean.referenceScript = raw.referenceScriptHex;
|
|
142
|
-
delete clean.referenceScriptHex;
|
|
143
|
-
return clean;
|
|
144
|
-
}
|
|
145
|
-
function prepareMetadata(raw) {
|
|
146
|
-
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'metadataJson']);
|
|
147
|
-
const parsedMetadata = parseJsonField(raw, 'metadataJson');
|
|
148
|
-
return { ...raw, metadataJson: parsedMetadata };
|
|
149
|
-
}
|
|
150
|
-
function prepareMultiAsset(raw) {
|
|
151
|
-
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'assetsJson']);
|
|
152
|
-
const assets = takeParsed((0, tx_request_parsers_1.parseAssetsArray)(raw.assetsJson, 'assetsJson'));
|
|
153
|
-
if (!assets || assets.length === 0)
|
|
154
|
-
fail('assetsJson must contain at least one asset');
|
|
155
|
-
const clean = { ...raw, assets };
|
|
156
|
-
delete clean.assetsJson;
|
|
157
|
-
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
158
|
-
if (outputDatum !== undefined)
|
|
159
|
-
clean.outputDatum = outputDatum;
|
|
160
|
-
delete clean.outputDatumJson;
|
|
161
|
-
if (raw.referenceScriptHex)
|
|
162
|
-
clean.referenceScript = raw.referenceScriptHex;
|
|
163
|
-
delete clean.referenceScriptHex;
|
|
164
|
-
return clean;
|
|
165
|
-
}
|
|
166
|
-
function prepareMint(raw, network) {
|
|
167
|
-
requirePresent(raw, ['senderAddress', 'recipientAddress', 'lovelaceAmount', 'mintActionsJson', 'mintingPolicyScript']);
|
|
168
|
-
const scriptParams = parseScriptParams(raw);
|
|
169
|
-
const mintActions = parseMintActions(raw, !!scriptParams);
|
|
170
|
-
const requiredSigners = takeParsed((0, tx_request_parsers_1.parseRequiredSigners)(raw.requiredSignersJson));
|
|
171
|
-
const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
|
|
172
|
-
const mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
173
|
-
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
174
|
-
const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
|
|
175
|
-
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
176
|
-
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
177
|
-
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
178
|
-
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
179
|
-
}
|
|
180
|
-
let parsedMetadata;
|
|
181
|
-
if (raw.metadataJson) {
|
|
182
|
-
parsedMetadata = parseJsonField(raw, 'metadataJson');
|
|
183
|
-
if (typeof parsedMetadata !== 'object' || parsedMetadata === null || Array.isArray(parsedMetadata)) {
|
|
184
|
-
fail('metadataJson must be an object with numeric label keys');
|
|
185
|
-
}
|
|
28
|
+
const value = JSON.parse(requestJson ?? '');
|
|
29
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
186
30
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
delete clean.requiredSignersJson;
|
|
190
|
-
delete clean.scriptParamsJson;
|
|
191
|
-
delete clean.inlineDatumJson;
|
|
192
|
-
delete clean.mintRedeemerJson;
|
|
193
|
-
delete clean.lockOnScript;
|
|
194
|
-
delete clean.forceInputsJson;
|
|
195
|
-
delete clean.protectInputsJson;
|
|
196
|
-
delete clean.referenceInputsJson;
|
|
197
|
-
delete clean.extraOutputsJson;
|
|
198
|
-
if (parsedMetadata)
|
|
199
|
-
clean.metadataJson = parsedMetadata;
|
|
200
|
-
else
|
|
201
|
-
delete clean.metadataJson;
|
|
202
|
-
if (raw.referenceScriptHex)
|
|
203
|
-
clean.referenceScript = raw.referenceScriptHex;
|
|
204
|
-
delete clean.referenceScriptHex;
|
|
205
|
-
// Apply script parameters, expand bare asset names, route lockOnScript output.
|
|
206
|
-
let finalMintingPolicyScript = raw.mintingPolicyScript;
|
|
207
|
-
let effectivePolicyId;
|
|
208
|
-
if (scriptParams && scriptParams.length > 0) {
|
|
209
|
-
try {
|
|
210
|
-
finalMintingPolicyScript = (0, tx_build_helper_1.applyScriptParameters)(raw.mintingPolicyScript, scriptParams);
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
fail(`Failed to apply script parameters: ${err instanceof Error ? err.message : String(err)}`);
|
|
214
|
-
}
|
|
215
|
-
effectivePolicyId = scriptHashOf(finalMintingPolicyScript, 'Failed to hash applied script');
|
|
216
|
-
for (const action of mintActions) {
|
|
217
|
-
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
218
|
-
action.assetUnit = effectivePolicyId + action.assetUnit;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (raw.lockOnScript) {
|
|
222
|
-
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(effectivePolicyId, network);
|
|
223
|
-
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
224
33
|
}
|
|
225
|
-
else {
|
|
226
|
-
try {
|
|
227
|
-
effectivePolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(raw.mintingPolicyScript, 'hex')).hash.toString();
|
|
228
|
-
}
|
|
229
|
-
catch {
|
|
230
|
-
// Invalid script CBOR. The builder rejects it with its own message.
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (effectivePolicyId)
|
|
234
|
-
assertPolicyPrefix(mintActions, effectivePolicyId);
|
|
235
|
-
return {
|
|
236
|
-
...clean,
|
|
237
|
-
mintActions,
|
|
238
|
-
mintingPolicyScript: finalMintingPolicyScript,
|
|
239
|
-
requiredSigners,
|
|
240
|
-
inlineDatum,
|
|
241
|
-
mintRedeemer,
|
|
242
|
-
forceInputs,
|
|
243
|
-
protectInputs,
|
|
244
|
-
referenceInputs,
|
|
245
|
-
extraOutputs,
|
|
246
|
-
};
|
|
247
34
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
259
|
-
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
260
|
-
}
|
|
261
|
-
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
262
|
-
const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
|
|
263
|
-
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
264
|
-
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
265
|
-
// Optional combined spend+mint.
|
|
266
|
-
const validatorScript = raw.validatorScript;
|
|
267
|
-
const mintingPolicyScript = raw.mintingPolicyScript;
|
|
268
|
-
let mintActions;
|
|
269
|
-
let mintRedeemer;
|
|
270
|
-
if (raw.mintActionsJson) {
|
|
271
|
-
if (!mintingPolicyScript)
|
|
272
|
-
fail('mintActionsJson requires mintingPolicyScript');
|
|
273
|
-
mintActions = parseMintActions(raw, !!scriptParams && mintingPolicyScript === validatorScript);
|
|
274
|
-
mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
275
|
-
}
|
|
276
|
-
else if (mintingPolicyScript || raw.mintRedeemerJson) {
|
|
277
|
-
fail('mintingPolicyScript / mintRedeemerJson require mintActionsJson');
|
|
278
|
-
}
|
|
279
|
-
let finalValidatorScript = validatorScript;
|
|
280
|
-
if (scriptParams && scriptParams.length > 0) {
|
|
281
|
-
try {
|
|
282
|
-
finalValidatorScript = (0, tx_build_helper_1.applyScriptParameters)(validatorScript, scriptParams);
|
|
283
|
-
}
|
|
284
|
-
catch (err) {
|
|
285
|
-
fail(`Failed to apply script parameters: ${err instanceof Error ? err.message : String(err)}`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
let finalMintingPolicyScript;
|
|
289
|
-
if (mintActions) {
|
|
290
|
-
finalMintingPolicyScript = (mintingPolicyScript === validatorScript) ? finalValidatorScript : mintingPolicyScript;
|
|
291
|
-
if (finalMintingPolicyScript && scriptParams && scriptParams.length > 0 && mintingPolicyScript === validatorScript) {
|
|
292
|
-
const appliedPolicyId = scriptHashOf(finalMintingPolicyScript, 'Failed to hash applied script');
|
|
293
|
-
for (const action of mintActions) {
|
|
294
|
-
if (action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
295
|
-
action.assetUnit = appliedPolicyId + action.assetUnit;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (finalMintingPolicyScript) {
|
|
300
|
-
let mintPolicyId;
|
|
301
|
-
try {
|
|
302
|
-
mintPolicyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(finalMintingPolicyScript, 'hex')).hash.toString();
|
|
303
|
-
}
|
|
304
|
-
catch {
|
|
305
|
-
// Invalid script CBOR. The builder rejects it with its own message.
|
|
306
|
-
}
|
|
307
|
-
if (mintPolicyId)
|
|
308
|
-
assertPolicyPrefix(mintActions, mintPolicyId);
|
|
309
|
-
}
|
|
35
|
+
// Why a submitSigned request cannot be run, or null. The transaction needs an expiry within the cap,
|
|
36
|
+
// and passing scripts: otherwise an unanswered submit stays undecided, or only the collateral goes.
|
|
37
|
+
function submitSignedProblem(raw, network) {
|
|
38
|
+
const cbor = raw.signedTxCbor;
|
|
39
|
+
if (typeof cbor !== 'string' || !cbor)
|
|
40
|
+
return 'submitSigned needs signedTxCbor in its request';
|
|
41
|
+
if (!(0, validators_1.isValidCbor)(cbor))
|
|
42
|
+
return 'signedTxCbor must be a hex string';
|
|
43
|
+
try {
|
|
44
|
+
return (0, landing_proof_1.sendProblem)(cbor, network);
|
|
310
45
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
plutusScriptExecution: {
|
|
314
|
-
validatorScript: finalValidatorScript,
|
|
315
|
-
scriptUtxo: {
|
|
316
|
-
txHash: raw.scriptTxHash,
|
|
317
|
-
outputIndex: raw.scriptOutputIndex,
|
|
318
|
-
},
|
|
319
|
-
redeemer: parsedRedeemer,
|
|
320
|
-
datum: parsedDatum,
|
|
321
|
-
},
|
|
322
|
-
requiredSigners,
|
|
323
|
-
inlineDatum,
|
|
324
|
-
forceInputs,
|
|
325
|
-
protectInputs,
|
|
326
|
-
referenceInputs,
|
|
327
|
-
extraOutputs,
|
|
328
|
-
mintActions,
|
|
329
|
-
mintingPolicyScript: finalMintingPolicyScript,
|
|
330
|
-
mintRedeemer,
|
|
331
|
-
};
|
|
332
|
-
if (raw.referenceScriptHex)
|
|
333
|
-
clean.referenceScript = raw.referenceScriptHex;
|
|
334
|
-
delete clean.requiredSignersJson;
|
|
335
|
-
delete clean.scriptParamsJson;
|
|
336
|
-
delete clean.inlineDatumJson;
|
|
337
|
-
delete clean.forceInputsJson;
|
|
338
|
-
delete clean.protectInputsJson;
|
|
339
|
-
delete clean.referenceInputsJson;
|
|
340
|
-
delete clean.extraOutputsJson;
|
|
341
|
-
delete clean.mintActionsJson;
|
|
342
|
-
delete clean.mintRedeemerJson;
|
|
343
|
-
delete clean.referenceScriptHex;
|
|
344
|
-
delete clean.redeemerJson;
|
|
345
|
-
delete clean.datumJson;
|
|
346
|
-
if (raw.lockOnScript && scriptParams && scriptParams.length > 0) {
|
|
347
|
-
clean.recipientAddress = (0, mappers_1.scriptHashToEnterpriseAddress)(scriptHashOf(finalValidatorScript, 'Failed to derive script address'), network);
|
|
46
|
+
catch {
|
|
47
|
+
return 'signedTxCbor is not a readable transaction';
|
|
348
48
|
}
|
|
349
|
-
delete clean.lockOnScript;
|
|
350
|
-
return clean;
|
|
351
|
-
}
|
|
352
|
-
/** Most recipients one payout job takes; the transaction size limit may be reached earlier. */
|
|
353
|
-
exports.MAX_PAYOUT_OUTPUTS = 150;
|
|
354
|
-
// payout: the outputs of `outputsJson` in the given order, paid from the wallet in one transaction.
|
|
355
|
-
// Entries read like those of BuildPlutusTransaction. No script runs.
|
|
356
|
-
function preparePayoutRequest(raw) {
|
|
357
|
-
requirePresent(raw, ['senderAddress', 'outputsJson']);
|
|
358
|
-
if (typeof raw.outputsJson !== 'string')
|
|
359
|
-
fail('outputsJson must be a JSON string');
|
|
360
|
-
const outputs = takeParsed((0, tx_request_parsers_1.parseOutputList)(raw.outputsJson, 'outputsJson', exports.MAX_PAYOUT_OUTPUTS));
|
|
361
|
-
if (!outputs)
|
|
362
|
-
fail('outputsJson must list at least one output');
|
|
363
|
-
return {
|
|
364
|
-
network: raw.network,
|
|
365
|
-
senderAddress: raw.senderAddress,
|
|
366
|
-
changeAddress: raw.changeAddress,
|
|
367
|
-
scriptInputs: [],
|
|
368
|
-
outputs,
|
|
369
|
-
forceInputs: takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson')),
|
|
370
|
-
protectInputs: takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson')),
|
|
371
|
-
validityStartMs: raw.validityStartMs,
|
|
372
|
-
validityEndMs: raw.validityEndMs,
|
|
373
|
-
};
|
|
374
49
|
}
|
|
375
50
|
/** Raw job request → TxBuildRequest for the matching build method; malformed payloads throw 400 INVALID_INPUT. */
|
|
376
51
|
function prepareWorkerBuildRequest(kind, raw, network) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
case 'metadata': return prepareMetadata(raw);
|
|
380
|
-
case 'multiAsset': return prepareMultiAsset(raw);
|
|
381
|
-
case 'mint': return prepareMint(raw, network);
|
|
382
|
-
case 'plutusSpend': return preparePlutusSpend(raw, network);
|
|
383
|
-
default:
|
|
384
|
-
return fail(`Unsupported job kind "${String(kind)}"`);
|
|
52
|
+
if (kind === 'payout' || kind === 'submitSigned') {
|
|
53
|
+
throw new errors_1.BackendError(`Unsupported job kind "${kind}"`, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
|
|
385
54
|
}
|
|
55
|
+
return requestOf((0, build_request_1.prepareBuildRequest)(kind, raw, () => network));
|
|
386
56
|
}
|
|
387
57
|
//# sourceMappingURL=build-request.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CardanoClient } from '../cardano-client';
|
|
2
|
+
import { type LandingIndexer } from '../signing/landing-proof';
|
|
2
3
|
export interface TrackedJob {
|
|
3
4
|
jobId: string;
|
|
4
5
|
walletId: string;
|
|
@@ -12,6 +13,11 @@ export interface TrackedJob {
|
|
|
12
13
|
foundHeight: number | null;
|
|
13
14
|
/** Polling round that last saw the tx. Older inclusions are re-checked to catch unreported rollbacks. */
|
|
14
15
|
seenRound?: number;
|
|
16
|
+
/** Epoch ms before which an overdue job has no chain read. */
|
|
17
|
+
nextLandingCheckAt?: number;
|
|
18
|
+
/** Epoch ms before which an overdue job is not sent again, and how often it was. */
|
|
19
|
+
nextResendAt?: number;
|
|
20
|
+
resends?: number;
|
|
15
21
|
}
|
|
16
22
|
export interface ConfirmationTrackerOptions {
|
|
17
23
|
confirmationDepth: number;
|
|
@@ -21,18 +27,28 @@ export interface ConfirmationTrackerOptions {
|
|
|
21
27
|
}
|
|
22
28
|
export interface ConfirmationTrackerDeps {
|
|
23
29
|
client: CardanoClient;
|
|
30
|
+
/** The local index, read before any backend. */
|
|
31
|
+
indexer: LandingIndexer;
|
|
24
32
|
options: ConfirmationTrackerOptions;
|
|
25
33
|
/** Called exactly once per job when it reaches a terminal state. */
|
|
26
34
|
onFinal?: (job: {
|
|
27
35
|
jobId: string;
|
|
28
36
|
walletId: string;
|
|
29
|
-
outcome: 'confirmed' | 'failed';
|
|
37
|
+
outcome: 'confirmed' | 'failed' | 'unresolved';
|
|
30
38
|
kind: string | null;
|
|
31
39
|
/** Set even on failure, since the tx was submitted. */
|
|
32
40
|
txHash: string;
|
|
33
41
|
errorCode?: string;
|
|
34
42
|
errorMessage?: string;
|
|
35
43
|
}) => void;
|
|
44
|
+
/** Called when a job's transaction has no expiry, has not landed and still can through these inputs. */
|
|
45
|
+
onStale?: (job: {
|
|
46
|
+
jobId: string;
|
|
47
|
+
walletId: string;
|
|
48
|
+
}, unspentInputs: Array<{
|
|
49
|
+
txHash: string;
|
|
50
|
+
outputIndex: number;
|
|
51
|
+
}>) => void;
|
|
36
52
|
}
|
|
37
53
|
export declare class ConfirmationTracker {
|
|
38
54
|
private readonly deps;
|
|
@@ -50,6 +66,8 @@ export declare class ConfirmationTracker {
|
|
|
50
66
|
stop(): void;
|
|
51
67
|
/** Number of jobs currently awaiting confirmation. */
|
|
52
68
|
size(): number;
|
|
69
|
+
/** Stops watching a job another path finalized. */
|
|
70
|
+
untrack(jobId: string): void;
|
|
53
71
|
/** Register a submitted job for confirmation watching. Idempotent per jobId. */
|
|
54
72
|
track(job: {
|
|
55
73
|
jobId: string;
|
|
@@ -63,10 +81,13 @@ export declare class ConfirmationTracker {
|
|
|
63
81
|
}): void;
|
|
64
82
|
private onBlockIndexed;
|
|
65
83
|
private onReorg;
|
|
66
|
-
/** Back to watching
|
|
84
|
+
/** Back to watching. After a rollback it re-submits the same signed CBOR, never a rebuild, to avoid a double spend. */
|
|
67
85
|
private forgetInclusion;
|
|
68
86
|
/** One polling round. Public for tests; guarded against overlapping rounds. */
|
|
69
87
|
pollOnce(): Promise<void>;
|
|
88
|
+
private settleOverdue;
|
|
89
|
+
private locate;
|
|
90
|
+
private stillOnLedger;
|
|
70
91
|
/** Confirms found jobs deep enough. With revalidate, an inclusion not seen this round is looked up again. */
|
|
71
92
|
private confirmMature;
|
|
72
93
|
/** True if the tx is still on-chain and deep enough. A moved tx takes its new height, a vanished one is watched again. */
|