@odatano/core 2.0.0-rc.23 → 2.0.0-rc.25
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 +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +37 -0
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +27 -2
- package/@cds-models/CardanoODataService/index.js +3 -0
- package/@cds-models/CardanoSignService/index.d.ts +23 -1
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +34 -1
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +18 -0
- package/@cds-models/index.js +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +49 -2
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/db/schema.cds +74 -3
- package/db/types.cds +27 -0
- package/package.json +182 -181
- package/srv/blockchain/backends/blockfrost-backend.js +4 -2
- package/srv/blockchain/backends/cardano-backend.d.ts +0 -2
- package/srv/blockchain/backends/koios-backend.d.ts +1 -1
- package/srv/blockchain/backends/koios-backend.js +61 -14
- package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
- package/srv/blockchain/backends/odatano-backend.js +166 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +12 -2
- package/srv/blockchain/backends/ogmios-backend.js +91 -21
- package/srv/blockchain/cardano-client.d.ts +23 -9
- package/srv/blockchain/cardano-client.js +77 -25
- package/srv/blockchain/cardano-indexer.d.ts +61 -15
- package/srv/blockchain/cardano-indexer.js +248 -79
- package/srv/blockchain/cardano-tx-builder.d.ts +11 -1
- package/srv/blockchain/cardano-tx-builder.js +59 -4
- package/srv/blockchain/crawler/certificate-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/certificate-backfill.js +49 -30
- package/srv/blockchain/crawler/crawler.d.ts +3 -1
- package/srv/blockchain/crawler/crawler.js +12 -7
- package/srv/blockchain/crawler/sync-state.d.ts +3 -1
- package/srv/blockchain/crawler/sync-state.js +15 -2
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +9 -0
- package/srv/blockchain/crawler/utxo-set-import.js +138 -47
- package/srv/blockchain/ledger-state.d.ts +16 -1
- package/srv/blockchain/ledger-state.js +38 -18
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/stored-chain.d.ts +33 -0
- package/srv/blockchain/stored-chain.js +234 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +12 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +203 -21
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +2 -1
- package/srv/blockchain/transaction-rows.d.ts +1 -1
- package/srv/blockchain/transaction-rows.js +2 -1
- package/srv/blockchain/wallet-worker/build-request.js +1 -1
- package/srv/cardano-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +244 -0
- package/srv/cardano-indexer-service.cds +201 -176
- package/srv/cardano-indexer-service.js +104 -10
- package/srv/cardano-service.cds +5 -0
- package/srv/cardano-tx-service.cds +39 -0
- package/srv/cardano-tx-service.js +88 -14
- package/srv/server.js +20 -2
- package/srv/utils/agent-grants.js +8 -0
- package/srv/utils/const.d.ts +5 -0
- package/srv/utils/const.js +6 -1
- package/srv/utils/error-codes.d.ts +2 -0
- package/srv/utils/error-codes.js +2 -0
- package/srv/utils/errors.d.ts +7 -0
- package/srv/utils/errors.js +11 -1
- package/srv/utils/mappers.d.ts +24 -2
- package/srv/utils/mappers.js +49 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +63 -0
- package/srv/utils/tx-build-helper.d.ts +2 -0
- package/srv/utils/tx-build-helper.js +12 -0
- package/srv/utils/tx-request-parsers.d.ts +46 -5
- package/srv/utils/tx-request-parsers.js +227 -16
- package/srv/utils/types.d.ts +59 -0
- package/srv/utils/validators.d.ts +5 -1
- package/srv/utils/validators.js +19 -9
package/srv/utils/mappers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Transaction as TransactionProviderData, Address as AddressProviderData, UTxO as UtxosProviderData, TxInputLine as TxInputProviderData, TxOutputLine as TxOutputProviderData, TxCertificate as TxCertificateProviderData, TxWithdrawal as TxWithdrawalProviderData, Amount as AmountProviderData, NetworkInformation as NetworkInfoProviderData, BlockData as BlockProviderData, EpochData as EpochProviderData, MetadataLabelTx as MetadataLabelTxProviderData, PoolData as PoolProviderData, DrepData as DrepProviderData, AccountData as AccountProviderData, AssetInfo as AssetInfoProviderData, AssetHistoryEntry as AssetHistoryEntryProviderData, TxBuildResult as TransactionBuildResult, LedgerProtocolParameters as ProtocolParameters } from './types';
|
|
2
|
-
import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as AddressUTxORow, UTxOAsset as UTxOAssetRow, Transaction as TransactionRow, TransactionInput as TransactionInputRow, TransactionInputAsset as TransactionInputAssetRow, TransactionOutput as TransactionOutputRow, TransactionOutputAsset as TransactionOutputAssetRow, TransactionCertificate as TransactionCertificateRow, TransactionWithdrawal as TransactionWithdrawalRow, NetworkInformation as NetworkInfoRow, TransactionMetadata as TransactionMetadataRow, Block as BlockRow, Epoch as EpochRow, Pool as PoolRow, Drep as DrepRow, PoolEpochSnapshot as PoolEpochSnapshotRow, DrepEpochSnapshot as DrepEpochSnapshotRow, Asset as AssetRow, AssetHistory as AssetHistoryRow, Account as AccountRow, LedgerProtocolParameter as ProtocolParameterRow, AddressTransaction as AddressTransactionRow } from '#cds-models/CardanoODataService';
|
|
1
|
+
import { Transaction as TransactionProviderData, Address as AddressProviderData, UTxO as UtxosProviderData, TxInputLine as TxInputProviderData, TxOutputLine as TxOutputProviderData, TxCertificate as TxCertificateProviderData, TxWithdrawal as TxWithdrawalProviderData, TxRedeemer as TxRedeemerProviderData, Amount as AmountProviderData, NetworkInformation as NetworkInfoProviderData, BlockData as BlockProviderData, EpochData as EpochProviderData, MetadataLabelTx as MetadataLabelTxProviderData, PoolData as PoolProviderData, DrepData as DrepProviderData, AccountData as AccountProviderData, AssetInfo as AssetInfoProviderData, AssetHistoryEntry as AssetHistoryEntryProviderData, TxBuildResult as TransactionBuildResult, LedgerProtocolParameters as ProtocolParameters } from './types';
|
|
2
|
+
import { Address as AddressRow, AddressAsset as AddressAssetRow, AddressUTxO as AddressUTxORow, UTxOAsset as UTxOAssetRow, Transaction as TransactionRow, TransactionInput as TransactionInputRow, TransactionInputAsset as TransactionInputAssetRow, TransactionOutput as TransactionOutputRow, TransactionOutputAsset as TransactionOutputAssetRow, TransactionCertificate as TransactionCertificateRow, TransactionWithdrawal as TransactionWithdrawalRow, TransactionRedeemer as TransactionRedeemerRow, NetworkInformation as NetworkInfoRow, TransactionMetadata as TransactionMetadataRow, Block as BlockRow, Epoch as EpochRow, Pool as PoolRow, Drep as DrepRow, PoolEpochSnapshot as PoolEpochSnapshotRow, DrepEpochSnapshot as DrepEpochSnapshotRow, Asset as AssetRow, AssetHistory as AssetHistoryRow, Account as AccountRow, LedgerProtocolParameter as ProtocolParameterRow, AddressTransaction as AddressTransactionRow } from '#cds-models/CardanoODataService';
|
|
3
3
|
import type { TransactionBuild as TransactionBuildRow, TransactionBuildInput as TransactionBuildInputRow, TransactionBuildOutput as TransactionBuildOutputRow, TransactionSubmission as TransactionSubmissionRow, AddressTransactionBuild as AddressTransactionBuildRow } from '#cds-models/CardanoTransactionService';
|
|
4
4
|
import type { AddressSigningRequest as AddressSigningRequestRow } from '#cds-models/CardanoSignService';
|
|
5
5
|
import type { Request } from '@sap/cds';
|
|
@@ -16,6 +16,28 @@ export declare function mapTransactionInputAssets(txSeq: number, inputs: TxInput
|
|
|
16
16
|
export declare function mapTransactionCertificates(txHash: string, certificates: TxCertificateProviderData[]): TransactionCertificateRow[];
|
|
17
17
|
/** Normalized withdrawals to TransactionWithdrawalRows, one per reward account. */
|
|
18
18
|
export declare function mapTransactionWithdrawals(txHash: string, withdrawals: TxWithdrawalProviderData[]): TransactionWithdrawalRow[];
|
|
19
|
+
/** Ledger order of output references: transaction hash bytewise, then output index. */
|
|
20
|
+
export declare function compareOutRef(a: {
|
|
21
|
+
txHash: string;
|
|
22
|
+
outputIndex: number;
|
|
23
|
+
}, b: {
|
|
24
|
+
txHash: string;
|
|
25
|
+
outputIndex: number;
|
|
26
|
+
}): number;
|
|
27
|
+
/**
|
|
28
|
+
* Inputs of a transaction in the order chain-sync reports them: regular, collateral, reference,
|
|
29
|
+
* each sorted like the ledger's input sets. `inputIndex` and spend-redeemer indices rely on it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ledgerInputOrder(inputs: TxInputProviderData[]): TxInputProviderData[];
|
|
32
|
+
/**
|
|
33
|
+
* The transaction as the ledger applied it, the same for every source: inputs in ledger order;
|
|
34
|
+
* after a phase-2 failure only collateral and reference inputs, the collateral return as the only
|
|
35
|
+
* output and no mint; otherwise no collateral return (never produced). Unknown validity
|
|
36
|
+
* (`spendsCollaterals` undefined) keeps what the source reported.
|
|
37
|
+
*/
|
|
38
|
+
export declare function ledgerView<T extends TransactionProviderData>(tx: T): T;
|
|
39
|
+
/** Normalized redeemers to TransactionRedeemerRows, keyed (tx, purpose, index). */
|
|
40
|
+
export declare function mapTransactionRedeemers(txHash: string, redeemers: TxRedeemerProviderData[]): TransactionRedeemerRow[];
|
|
19
41
|
/** Provider transaction outputs to TransactionOutputRows. */
|
|
20
42
|
export declare function mapTransactionOutputs(txSeq: number, txOutputs: TxOutputProviderData[]): TransactionOutputRow[];
|
|
21
43
|
/** Provider transaction output assets to TransactionOutputAssetRows. */
|
package/srv/utils/mappers.js
CHANGED
|
@@ -10,6 +10,10 @@ exports.mapTransactionInputs = mapTransactionInputs;
|
|
|
10
10
|
exports.mapTransactionInputAssets = mapTransactionInputAssets;
|
|
11
11
|
exports.mapTransactionCertificates = mapTransactionCertificates;
|
|
12
12
|
exports.mapTransactionWithdrawals = mapTransactionWithdrawals;
|
|
13
|
+
exports.compareOutRef = compareOutRef;
|
|
14
|
+
exports.ledgerInputOrder = ledgerInputOrder;
|
|
15
|
+
exports.ledgerView = ledgerView;
|
|
16
|
+
exports.mapTransactionRedeemers = mapTransactionRedeemers;
|
|
13
17
|
exports.mapTransactionOutputs = mapTransactionOutputs;
|
|
14
18
|
exports.mapTransactionOutputAssets = mapTransactionOutputAssets;
|
|
15
19
|
exports.mapAddress = mapAddress;
|
|
@@ -150,6 +154,51 @@ function mapTransactionWithdrawals(txHash, withdrawals) {
|
|
|
150
154
|
lovelace: String(w.amount ?? '0'),
|
|
151
155
|
}));
|
|
152
156
|
}
|
|
157
|
+
/** Ledger order of output references: transaction hash bytewise, then output index. */
|
|
158
|
+
function compareOutRef(a, b) {
|
|
159
|
+
const ha = a.txHash.toLowerCase(), hb = b.txHash.toLowerCase();
|
|
160
|
+
return ha < hb ? -1 : ha > hb ? 1 : a.outputIndex - b.outputIndex;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Inputs of a transaction in the order chain-sync reports them: regular, collateral, reference,
|
|
164
|
+
* each sorted like the ledger's input sets. `inputIndex` and spend-redeemer indices rely on it.
|
|
165
|
+
*/
|
|
166
|
+
function ledgerInputOrder(inputs) {
|
|
167
|
+
const rank = (i) => (i.isReference ? 2 : i.isCollateral ? 1 : 0);
|
|
168
|
+
return [...inputs].sort((a, b) => rank(a) - rank(b) || compareOutRef(a, b));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The transaction as the ledger applied it, the same for every source: inputs in ledger order;
|
|
172
|
+
* after a phase-2 failure only collateral and reference inputs, the collateral return as the only
|
|
173
|
+
* output and no mint; otherwise no collateral return (never produced). Unknown validity
|
|
174
|
+
* (`spendsCollaterals` undefined) keeps what the source reported.
|
|
175
|
+
*/
|
|
176
|
+
function ledgerView(tx) {
|
|
177
|
+
const inputs = ledgerInputOrder(tx.inputs ?? []);
|
|
178
|
+
if (tx.spendsCollaterals === undefined)
|
|
179
|
+
return { ...tx, inputs };
|
|
180
|
+
const failed = tx.spendsCollaterals;
|
|
181
|
+
return {
|
|
182
|
+
...tx,
|
|
183
|
+
inputs: failed ? inputs.filter(i => i.isCollateral || i.isReference) : inputs,
|
|
184
|
+
outputs: (tx.outputs ?? []).filter(o => (failed ? o.isCollateral : !o.isCollateral)),
|
|
185
|
+
mint: failed ? undefined : tx.mint,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/** Normalized redeemers to TransactionRedeemerRows, keyed (tx, purpose, index). */
|
|
189
|
+
function mapTransactionRedeemers(txHash, redeemers) {
|
|
190
|
+
return redeemers.map((r) => ({
|
|
191
|
+
tx_hash: txHash,
|
|
192
|
+
purpose: r.purpose,
|
|
193
|
+
redeemerIndex: r.index,
|
|
194
|
+
data: r.data,
|
|
195
|
+
mem: Number(r.mem),
|
|
196
|
+
steps: Number(r.steps),
|
|
197
|
+
spentTxHash: r.txHash ?? null,
|
|
198
|
+
spentOutputIndex: r.outputIndex ?? null,
|
|
199
|
+
policyId: r.policyId ?? null,
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
153
202
|
/** Provider transaction outputs to TransactionOutputRows. */
|
|
154
203
|
function mapTransactionOutputs(txSeq, txOutputs) {
|
|
155
204
|
return txOutputs.map((output) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
/** A JSON row stream the CAP renderer built from an array (it keeps the array as `_raw`). */
|
|
3
|
+
export declare function isInlineRowStream(v: unknown): v is Readable & {
|
|
4
|
+
_raw: unknown[];
|
|
5
|
+
};
|
|
6
|
+
/** Wraps the driver's `_prepareStreams` once; returns false when the driver or the hook is missing. */
|
|
7
|
+
export declare function installPostgresInlineJson(): boolean;
|
|
8
|
+
//# sourceMappingURL=pg-inline-json.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isInlineRowStream = isInlineRowStream;
|
|
7
|
+
exports.installPostgresInlineJson = installPostgresInlineJson;
|
|
8
|
+
/**
|
|
9
|
+
* Bulk INSERT/UPSERT on PostgreSQL: send the rows as one text parameter.
|
|
10
|
+
* @cap-js/postgres turns every `.entries()` row list into a stream and ships it through a
|
|
11
|
+
* per-transaction temp table (`CREATE TEMP TABLE` + `COPY`), three round trips per write plus a
|
|
12
|
+
* table created and dropped per transaction. Row lists built from in-memory arrays are drained
|
|
13
|
+
* into a string instead; streams a caller passes in (media) keep the driver's path.
|
|
14
|
+
*/
|
|
15
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
16
|
+
const stream_1 = require("stream");
|
|
17
|
+
const logger = cds_1.default.log('PgInlineJson');
|
|
18
|
+
const INSTALLED = Symbol.for('odatano.pgInlineJson');
|
|
19
|
+
/** A JSON row stream the CAP renderer built from an array (it keeps the array as `_raw`). */
|
|
20
|
+
function isInlineRowStream(v) {
|
|
21
|
+
return v instanceof stream_1.Readable && Array.isArray(v._raw);
|
|
22
|
+
}
|
|
23
|
+
const dbKind = () => String((cds_1.default.env?.requires?.db)?.kind ?? '');
|
|
24
|
+
async function drain(stream) {
|
|
25
|
+
const parts = [];
|
|
26
|
+
for await (const part of stream)
|
|
27
|
+
parts.push(Buffer.isBuffer(part) ? part : Buffer.from(String(part)));
|
|
28
|
+
return Buffer.concat(parts).toString('utf8');
|
|
29
|
+
}
|
|
30
|
+
/** Wraps the driver's `_prepareStreams` once; returns false when the driver or the hook is missing. */
|
|
31
|
+
function installPostgresInlineJson() {
|
|
32
|
+
let PostgresService;
|
|
33
|
+
try {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
35
|
+
PostgresService = require('@cap-js/postgres/lib/PostgresService');
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (dbKind() === 'postgres')
|
|
39
|
+
logger.warn(`@cap-js/postgres/lib/PostgresService not loadable, bulk writes keep the COPY buffer: ${String(err?.message ?? err)}`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const proto = PostgresService?.prototype;
|
|
43
|
+
const orig = proto?._prepareStreams;
|
|
44
|
+
if (!proto || typeof orig !== 'function') {
|
|
45
|
+
logger.warn('@cap-js/postgres has no _prepareStreams hook; bulk writes keep the COPY buffer');
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (proto[INSTALLED])
|
|
49
|
+
return true;
|
|
50
|
+
proto._prepareStreams = function (query, values) {
|
|
51
|
+
if (!Array.isArray(values) || !values.some(isInlineRowStream))
|
|
52
|
+
return orig.call(this, query, values);
|
|
53
|
+
return (async () => {
|
|
54
|
+
const inlined = await Promise.all(values.map(v => (isInlineRowStream(v) ? drain(v) : v)));
|
|
55
|
+
return orig.call(this, query, inlined);
|
|
56
|
+
})();
|
|
57
|
+
};
|
|
58
|
+
proto[INSTALLED] = true;
|
|
59
|
+
if (dbKind() === 'postgres')
|
|
60
|
+
logger.info('Bulk writes on Postgres: row lists sent inline, no COPY buffer');
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=pg-inline-json.js.map
|
|
@@ -3,6 +3,8 @@ import { type Data } from '@harmoniclabs/plutus-data';
|
|
|
3
3
|
import { UPLCConst } from '@harmoniclabs/uplc';
|
|
4
4
|
/** Lovelace amount of a UTxO. */
|
|
5
5
|
export declare function getLovelace(u: OdatanoUtxo): bigint;
|
|
6
|
+
/** A UTxO the builders may take as collateral: lovelace only and no reference script. */
|
|
7
|
+
export declare function isCollateralCandidate(u: OdatanoUtxo): boolean;
|
|
6
8
|
/** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
|
|
7
9
|
export declare function assertAdaOnly(u: OdatanoUtxo): void;
|
|
8
10
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLovelace = getLovelace;
|
|
4
|
+
exports.isCollateralCandidate = isCollateralCandidate;
|
|
4
5
|
exports.assertAdaOnly = assertAdaOnly;
|
|
5
6
|
exports.getTxHashFromCbor = getTxHashFromCbor;
|
|
6
7
|
exports.extractTxCacheTargets = extractTxCacheTargets;
|
|
@@ -23,6 +24,10 @@ function getLovelace(u) {
|
|
|
23
24
|
const entry = u.amount.find(a => (a.unit).toLowerCase() === "lovelace");
|
|
24
25
|
return BigInt(entry?.quantity ?? "0");
|
|
25
26
|
}
|
|
27
|
+
/** A UTxO the builders may take as collateral: lovelace only and no reference script. */
|
|
28
|
+
function isCollateralCandidate(u) {
|
|
29
|
+
return u.amount.every(a => a.unit.toLowerCase() === 'lovelace' || BigInt(a.quantity) === 0n) && !u.scriptRef && !u.scriptRefCbor;
|
|
30
|
+
}
|
|
26
31
|
/** Throws MixedAssetsError when the UTxO carries non-ADA assets. */
|
|
27
32
|
function assertAdaOnly(u) {
|
|
28
33
|
const nonAda = u.amount.filter(a => (a.unit).toLowerCase() !== "lovelace" && BigInt(a.quantity) !== 0n);
|
|
@@ -118,6 +123,13 @@ function mapBuilderError(err, assetUnit, context) {
|
|
|
118
123
|
const errObj = err;
|
|
119
124
|
const rawMsg = errObj?.message || errObj?.toString?.() || String(err);
|
|
120
125
|
const msg = rawMsg.toLowerCase();
|
|
126
|
+
// An output below the protocol's min-ADA: a request error, not missing funds
|
|
127
|
+
const minAda = rawMsg.match(/tx output at index (\d+) did not have enough lovelaces[\s\S]*?minimum lovelaces required:\s*(\d+)[\s\S]*?output lovelaces\s*:\s*(\d+)/);
|
|
128
|
+
if (minAda) {
|
|
129
|
+
const [, index, minimum, actual] = minAda;
|
|
130
|
+
const withAssets = /tx output:[\s\S]*"[0-9a-f]{56}"\s*:/i.test(rawMsg) ? ', it carries native assets' : '';
|
|
131
|
+
throw new errors_1.TransactionValidationError(`output ${index} needs at least ${minimum} lovelace (has ${actual}${withAssets}); raise its lovelace amount`, err);
|
|
132
|
+
}
|
|
121
133
|
if (msg.includes('not enough') ||
|
|
122
134
|
msg.includes('insufficient') ||
|
|
123
135
|
msg.includes('balance')) {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { JSONValue } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Shared parsers for the Build*-action JSON payload fields (transaction service and wallet worker).
|
|
4
|
-
* Result contract: `{ parsed }` on success (undefined for absent/empty input) or `{ error }` with a client message.
|
|
5
|
-
*/
|
|
1
|
+
import type { JSONValue, MintAction } from './types';
|
|
6
2
|
export declare function parseUtxoRefArray(json: string | undefined, fieldName: 'forceInputsJson' | 'referenceInputsJson'): {
|
|
7
3
|
parsed?: Array<{
|
|
8
4
|
txHash: string;
|
|
@@ -33,6 +29,10 @@ export interface ParsedExtraOutput {
|
|
|
33
29
|
quantity: string;
|
|
34
30
|
}>;
|
|
35
31
|
inlineDatum?: JSONValue;
|
|
32
|
+
/** Hash of a datum the output is locked with (hex, 32 bytes); `outputsJson` only. */
|
|
33
|
+
datumHash?: string;
|
|
34
|
+
/** Inline datum as PlutusData CBOR hex, taken byte for byte; `outputsJson` only. */
|
|
35
|
+
inlineDatumCbor?: string;
|
|
36
36
|
referenceScript?: string;
|
|
37
37
|
}
|
|
38
38
|
/** Parse and validate extraOutputsJson (undefined for an empty array). */
|
|
@@ -40,6 +40,14 @@ export declare function parseExtraOutputs(extraOutputsJson: string | undefined):
|
|
|
40
40
|
parsed?: ParsedExtraOutput[];
|
|
41
41
|
error?: string;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Parse an output list. `outputsJson` (BuildPlutusTransaction) additionally accepts `datumHash`;
|
|
45
|
+
* the entries keep their order, each is min-ADA checked by the builder.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseOutputList(json: string | undefined, fieldName: 'extraOutputsJson' | 'outputsJson'): {
|
|
48
|
+
parsed?: ParsedExtraOutput[];
|
|
49
|
+
error?: string;
|
|
50
|
+
};
|
|
43
51
|
/**
|
|
44
52
|
* Parse the optional per-action policy fields of a mintActionsJson entry: `mintingPolicyScript` (CBOR hex,
|
|
45
53
|
* applied as-is) and `redeemerJson` (JSON string). Absent fields fall back to the top-level script/redeemer.
|
|
@@ -49,4 +57,37 @@ export declare function parseMintActionPolicyFields(entry: Record<string, unknow
|
|
|
49
57
|
redeemer?: JSONValue;
|
|
50
58
|
error?: string;
|
|
51
59
|
};
|
|
60
|
+
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
61
|
+
export declare const MAX_SCRIPT_INPUTS = 16;
|
|
62
|
+
/** One script UTxO of a BuildPlutusTransaction, validated; `validatorScript` still without params applied. */
|
|
63
|
+
export interface ParsedScriptInput {
|
|
64
|
+
txHash: string;
|
|
65
|
+
outputIndex: number;
|
|
66
|
+
validatorScript?: string;
|
|
67
|
+
scriptParams?: JSONValue[];
|
|
68
|
+
referenceScript?: {
|
|
69
|
+
txHash: string;
|
|
70
|
+
outputIndex: number;
|
|
71
|
+
};
|
|
72
|
+
redeemer: JSONValue;
|
|
73
|
+
/** Redeemer as PlutusData CBOR hex (instead of redeemerJson), taken byte for byte. */
|
|
74
|
+
redeemerCbor?: string;
|
|
75
|
+
datum?: JSONValue;
|
|
76
|
+
/** Datum preimage as PlutusData CBOR hex (instead of datumJson). */
|
|
77
|
+
datumCbor?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Parse and validate scriptInputsJson: 1..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
80
|
+
export declare function parseScriptInputs(json: string | undefined): {
|
|
81
|
+
parsed?: ParsedScriptInput[];
|
|
82
|
+
error?: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Parse mintActionsJson for BuildPlutusTransaction: every action carries its own `mintingPolicyScript`
|
|
86
|
+
* (no request-level default) and optional `redeemerJson`; `assetUnit` is policyId+assetName, or a bare
|
|
87
|
+
* assetName that is prefixed with the policy id of the action's script.
|
|
88
|
+
*/
|
|
89
|
+
export declare function parsePolicyMintActions(json: string | undefined): {
|
|
90
|
+
parsed?: MintAction[];
|
|
91
|
+
error?: string;
|
|
92
|
+
};
|
|
52
93
|
//# sourceMappingURL=tx-request-parsers.d.ts.map
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
3
|
+
exports.MAX_SCRIPT_INPUTS = exports.MAX_EXTRA_OUTPUTS = void 0;
|
|
4
4
|
exports.parseUtxoRefArray = parseUtxoRefArray;
|
|
5
5
|
exports.parseRequiredSigners = parseRequiredSigners;
|
|
6
6
|
exports.parseAssetsArray = parseAssetsArray;
|
|
7
7
|
exports.parseExtraOutputs = parseExtraOutputs;
|
|
8
|
+
exports.parseOutputList = parseOutputList;
|
|
8
9
|
exports.parseMintActionPolicyFields = parseMintActionPolicyFields;
|
|
10
|
+
exports.parseScriptInputs = parseScriptInputs;
|
|
11
|
+
exports.parsePolicyMintActions = parsePolicyMintActions;
|
|
9
12
|
const validators_1 = require("./validators");
|
|
13
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
14
|
+
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
15
|
+
const const_1 = require("./const");
|
|
10
16
|
/**
|
|
11
17
|
* Shared parsers for the Build*-action JSON payload fields (transaction service and wallet worker).
|
|
12
18
|
* Result contract: `{ parsed }` on success (undefined for absent/empty input) or `{ error }` with a client message.
|
|
13
19
|
*/
|
|
20
|
+
/** PlutusData as CBOR hex, checked to decode; `field` names it in the error. */
|
|
21
|
+
function parsePlutusCbor(value, field) {
|
|
22
|
+
if (typeof value !== 'string' || !(0, validators_1.isValidCbor)(value))
|
|
23
|
+
return { error: `${field} must be even-length CBOR hex` };
|
|
24
|
+
try {
|
|
25
|
+
(0, plutus_data_1.dataFromCbor)(value);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return { error: `${field} is not PlutusData CBOR: ${err instanceof Error ? err.message : String(err)}` };
|
|
29
|
+
}
|
|
30
|
+
return { hex: value.toLowerCase() };
|
|
31
|
+
}
|
|
14
32
|
function parseUtxoRefArray(json, fieldName) {
|
|
15
33
|
if (!json)
|
|
16
34
|
return { parsed: undefined };
|
|
@@ -82,46 +100,54 @@ function parseAssetsArray(assetsJson, fieldName) {
|
|
|
82
100
|
exports.MAX_EXTRA_OUTPUTS = 32;
|
|
83
101
|
/** Parse and validate extraOutputsJson (undefined for an empty array). */
|
|
84
102
|
function parseExtraOutputs(extraOutputsJson) {
|
|
85
|
-
|
|
103
|
+
return parseOutputList(extraOutputsJson, 'extraOutputsJson');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parse an output list. `outputsJson` (BuildPlutusTransaction) additionally accepts `datumHash`;
|
|
107
|
+
* the entries keep their order, each is min-ADA checked by the builder.
|
|
108
|
+
*/
|
|
109
|
+
function parseOutputList(json, fieldName) {
|
|
110
|
+
if (!json)
|
|
86
111
|
return { parsed: undefined };
|
|
87
|
-
const
|
|
112
|
+
const name = fieldName.replace(/Json$/, '');
|
|
113
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, fieldName);
|
|
88
114
|
if (!jsonResult.valid)
|
|
89
115
|
return { error: jsonResult.error };
|
|
90
116
|
if (!Array.isArray(jsonResult.parsed))
|
|
91
|
-
return { error:
|
|
117
|
+
return { error: `${fieldName} must be a JSON array` };
|
|
92
118
|
if (jsonResult.parsed.length === 0)
|
|
93
119
|
return { parsed: undefined };
|
|
94
120
|
if (jsonResult.parsed.length > exports.MAX_EXTRA_OUTPUTS) {
|
|
95
|
-
return { error:
|
|
121
|
+
return { error: `${fieldName} exceeds maximum of ${exports.MAX_EXTRA_OUTPUTS} entries` };
|
|
96
122
|
}
|
|
97
123
|
const out = [];
|
|
98
124
|
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
99
125
|
const entry = jsonResult.parsed[i];
|
|
100
126
|
if (!entry || typeof entry !== 'object') {
|
|
101
|
-
return { error:
|
|
127
|
+
return { error: `${name}[${i}] must be an object` };
|
|
102
128
|
}
|
|
103
129
|
if (typeof entry.address !== 'string' || !(0, validators_1.isValidBech32Address)(entry.address)) {
|
|
104
|
-
return { error:
|
|
130
|
+
return { error: `${name}[${i}].address is not a valid Bech32 address` };
|
|
105
131
|
}
|
|
106
132
|
if (typeof entry.lovelaceAmount !== 'string' || !/^\d+$/.test(entry.lovelaceAmount) || entry.lovelaceAmount === '0') {
|
|
107
|
-
return { error:
|
|
133
|
+
return { error: `${name}[${i}].lovelaceAmount must be a positive integer string` };
|
|
108
134
|
}
|
|
109
135
|
let assets;
|
|
110
136
|
if (entry.assets !== undefined && entry.assets !== null) {
|
|
111
137
|
if (!Array.isArray(entry.assets)) {
|
|
112
|
-
return { error:
|
|
138
|
+
return { error: `${name}[${i}].assets must be an array` };
|
|
113
139
|
}
|
|
114
140
|
assets = [];
|
|
115
141
|
for (let j = 0; j < entry.assets.length; j++) {
|
|
116
142
|
const a = entry.assets[j];
|
|
117
143
|
if (!a || typeof a !== 'object') {
|
|
118
|
-
return { error:
|
|
144
|
+
return { error: `${name}[${i}].assets[${j}] must be an object` };
|
|
119
145
|
}
|
|
120
146
|
if (typeof a.unit !== 'string' || a.unit.toLowerCase() === 'lovelace' || !(0, validators_1.isAssetUnit)(a.unit)) {
|
|
121
|
-
return { error:
|
|
147
|
+
return { error: `${name}[${i}].assets[${j}].unit must be a valid asset unit (policyId + assetName hex)` };
|
|
122
148
|
}
|
|
123
149
|
if (typeof a.quantity !== 'string' || !/^\d+$/.test(a.quantity) || a.quantity === '0') {
|
|
124
|
-
return { error:
|
|
150
|
+
return { error: `${name}[${i}].assets[${j}].quantity must be a positive integer string` };
|
|
125
151
|
}
|
|
126
152
|
assets.push({ unit: a.unit, quantity: a.quantity });
|
|
127
153
|
}
|
|
@@ -129,17 +155,39 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
129
155
|
let inlineDatum;
|
|
130
156
|
if (entry.inlineDatumJson !== undefined && entry.inlineDatumJson !== null) {
|
|
131
157
|
if (typeof entry.inlineDatumJson !== 'string') {
|
|
132
|
-
return { error:
|
|
158
|
+
return { error: `${name}[${i}].inlineDatumJson must be a JSON string` };
|
|
133
159
|
}
|
|
134
|
-
const datumResult = (0, validators_1.
|
|
160
|
+
const datumResult = (0, validators_1.validatePlutusJson)(entry.inlineDatumJson, `${name}[${i}].inlineDatumJson`);
|
|
135
161
|
if (!datumResult.valid)
|
|
136
162
|
return { error: datumResult.error };
|
|
137
163
|
inlineDatum = datumResult.parsed;
|
|
138
164
|
}
|
|
165
|
+
let inlineDatumCbor;
|
|
166
|
+
if (entry.inlineDatumCbor !== undefined && entry.inlineDatumCbor !== null) {
|
|
167
|
+
if (fieldName !== 'outputsJson')
|
|
168
|
+
return { error: `${name}[${i}].inlineDatumCbor is only supported in outputsJson` };
|
|
169
|
+
if (inlineDatum !== undefined)
|
|
170
|
+
return { error: `${name}[${i}] takes inlineDatumJson or inlineDatumCbor, not both` };
|
|
171
|
+
const cbor = parsePlutusCbor(entry.inlineDatumCbor, `${name}[${i}].inlineDatumCbor`);
|
|
172
|
+
if (cbor.error)
|
|
173
|
+
return { error: cbor.error };
|
|
174
|
+
inlineDatumCbor = cbor.hex;
|
|
175
|
+
}
|
|
176
|
+
let datumHash;
|
|
177
|
+
if (entry.datumHash !== undefined && entry.datumHash !== null) {
|
|
178
|
+
if (fieldName !== 'outputsJson')
|
|
179
|
+
return { error: `${name}[${i}].datumHash is only supported in outputsJson` };
|
|
180
|
+
if (typeof entry.datumHash !== 'string' || !/^[0-9a-fA-F]{64}$/.test(entry.datumHash)) {
|
|
181
|
+
return { error: `${name}[${i}].datumHash must be 64 hex chars` };
|
|
182
|
+
}
|
|
183
|
+
if (inlineDatum !== undefined || inlineDatumCbor !== undefined)
|
|
184
|
+
return { error: `${name}[${i}] takes an inline datum or datumHash, not both` };
|
|
185
|
+
datumHash = entry.datumHash.toLowerCase();
|
|
186
|
+
}
|
|
139
187
|
let referenceScript;
|
|
140
188
|
if (entry.referenceScriptHex !== undefined && entry.referenceScriptHex !== null) {
|
|
141
189
|
if (typeof entry.referenceScriptHex !== 'string' || !(0, validators_1.isValidCbor)(entry.referenceScriptHex)) {
|
|
142
|
-
return { error:
|
|
190
|
+
return { error: `${name}[${i}].referenceScriptHex must be even-length hex` };
|
|
143
191
|
}
|
|
144
192
|
referenceScript = entry.referenceScriptHex;
|
|
145
193
|
}
|
|
@@ -148,6 +196,8 @@ function parseExtraOutputs(extraOutputsJson) {
|
|
|
148
196
|
lovelaceAmount: entry.lovelaceAmount,
|
|
149
197
|
assets,
|
|
150
198
|
inlineDatum,
|
|
199
|
+
...(datumHash ? { datumHash } : {}),
|
|
200
|
+
...(inlineDatumCbor ? { inlineDatumCbor } : {}),
|
|
151
201
|
referenceScript,
|
|
152
202
|
});
|
|
153
203
|
}
|
|
@@ -170,7 +220,7 @@ function parseMintActionPolicyFields(entry, i) {
|
|
|
170
220
|
if (typeof entry.redeemerJson !== 'string') {
|
|
171
221
|
return { error: `mintActions[${i}].redeemerJson must be a JSON string` };
|
|
172
222
|
}
|
|
173
|
-
const jsonResult = (0, validators_1.
|
|
223
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(entry.redeemerJson, `mintActions[${i}].redeemerJson`);
|
|
174
224
|
if (!jsonResult.valid)
|
|
175
225
|
return { error: jsonResult.error };
|
|
176
226
|
redeemer = jsonResult.parsed;
|
|
@@ -180,4 +230,165 @@ function parseMintActionPolicyFields(entry, i) {
|
|
|
180
230
|
}
|
|
181
231
|
return { script, redeemer };
|
|
182
232
|
}
|
|
233
|
+
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
234
|
+
exports.MAX_SCRIPT_INPUTS = 16;
|
|
235
|
+
/** Parse and validate scriptInputsJson: 1..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
236
|
+
function parseScriptInputs(json) {
|
|
237
|
+
if (!json)
|
|
238
|
+
return { error: 'scriptInputsJson is required' };
|
|
239
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'scriptInputsJson');
|
|
240
|
+
if (!jsonResult.valid)
|
|
241
|
+
return { error: jsonResult.error };
|
|
242
|
+
if (!Array.isArray(jsonResult.parsed) || jsonResult.parsed.length === 0) {
|
|
243
|
+
return { error: 'scriptInputsJson must be a non-empty JSON array' };
|
|
244
|
+
}
|
|
245
|
+
if (jsonResult.parsed.length > exports.MAX_SCRIPT_INPUTS) {
|
|
246
|
+
return { error: `scriptInputsJson exceeds maximum of ${exports.MAX_SCRIPT_INPUTS} entries` };
|
|
247
|
+
}
|
|
248
|
+
const parseJsonField = (value, field) => {
|
|
249
|
+
if (typeof value !== 'string')
|
|
250
|
+
return { error: `${field} must be a JSON string` };
|
|
251
|
+
const r = (0, validators_1.validatePlutusJson)(value, field);
|
|
252
|
+
return r.valid ? { parsed: r.parsed } : { error: r.error };
|
|
253
|
+
};
|
|
254
|
+
const out = [];
|
|
255
|
+
const seen = new Set();
|
|
256
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
257
|
+
const entry = jsonResult.parsed[i];
|
|
258
|
+
const at = `scriptInputs[${i}]`;
|
|
259
|
+
if (!entry || typeof entry !== 'object')
|
|
260
|
+
return { error: `${at} must be an object` };
|
|
261
|
+
if (typeof entry.txHash !== 'string' || !(0, validators_1.isTxHash)(entry.txHash))
|
|
262
|
+
return { error: `${at}.txHash must be 64 hex chars` };
|
|
263
|
+
const idx = entry.outputIndex;
|
|
264
|
+
if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0)
|
|
265
|
+
return { error: `${at}.outputIndex must be a non-negative integer` };
|
|
266
|
+
const key = `${entry.txHash.toLowerCase()}#${idx}`;
|
|
267
|
+
if (seen.has(key))
|
|
268
|
+
return { error: `${at} spends ${key} a second time` };
|
|
269
|
+
seen.add(key);
|
|
270
|
+
const hasInline = entry.validatorScript !== undefined && entry.validatorScript !== null;
|
|
271
|
+
const hasRef = entry.referenceScript !== undefined && entry.referenceScript !== null;
|
|
272
|
+
if (hasInline === hasRef)
|
|
273
|
+
return { error: `${at} needs exactly one of validatorScript or referenceScript` };
|
|
274
|
+
const input = { txHash: entry.txHash.toLowerCase(), outputIndex: idx, redeemer: null };
|
|
275
|
+
if (hasInline) {
|
|
276
|
+
if (typeof entry.validatorScript !== 'string' || !(0, validators_1.isValidCbor)(entry.validatorScript)) {
|
|
277
|
+
return { error: `${at}.validatorScript must be even-length CBOR hex` };
|
|
278
|
+
}
|
|
279
|
+
input.validatorScript = entry.validatorScript;
|
|
280
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
281
|
+
const params = parseJsonField(entry.scriptParamsJson, `${at}.scriptParamsJson`);
|
|
282
|
+
if (params.error)
|
|
283
|
+
return { error: params.error };
|
|
284
|
+
if (!Array.isArray(params.parsed))
|
|
285
|
+
return { error: `${at}.scriptParamsJson must be a JSON array` };
|
|
286
|
+
if (params.parsed.length > 0)
|
|
287
|
+
input.scriptParams = params.parsed;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
const ref = entry.referenceScript;
|
|
292
|
+
if (!ref || typeof ref !== 'object' || typeof ref.txHash !== 'string' || !(0, validators_1.isTxHash)(ref.txHash)
|
|
293
|
+
|| typeof ref.outputIndex !== 'number' || !Number.isInteger(ref.outputIndex) || ref.outputIndex < 0) {
|
|
294
|
+
return { error: `${at}.referenceScript must be {txHash, outputIndex} of the UTxO carrying the script` };
|
|
295
|
+
}
|
|
296
|
+
if (entry.scriptParamsJson !== undefined && entry.scriptParamsJson !== null) {
|
|
297
|
+
return { error: `${at}.scriptParamsJson applies to an inline validatorScript only` };
|
|
298
|
+
}
|
|
299
|
+
input.referenceScript = { txHash: ref.txHash.toLowerCase(), outputIndex: ref.outputIndex };
|
|
300
|
+
}
|
|
301
|
+
const hasRedeemerJson = entry.redeemerJson !== undefined && entry.redeemerJson !== null;
|
|
302
|
+
const hasRedeemerCbor = entry.redeemerCbor !== undefined && entry.redeemerCbor !== null;
|
|
303
|
+
if (hasRedeemerJson === hasRedeemerCbor)
|
|
304
|
+
return { error: `${at} needs exactly one of redeemerJson or redeemerCbor` };
|
|
305
|
+
if (hasRedeemerCbor) {
|
|
306
|
+
const cbor = parsePlutusCbor(entry.redeemerCbor, `${at}.redeemerCbor`);
|
|
307
|
+
if (cbor.error)
|
|
308
|
+
return { error: cbor.error };
|
|
309
|
+
input.redeemerCbor = cbor.hex;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const redeemer = parseJsonField(entry.redeemerJson, `${at}.redeemerJson`);
|
|
313
|
+
if (redeemer.error)
|
|
314
|
+
return { error: redeemer.error };
|
|
315
|
+
input.redeemer = redeemer.parsed;
|
|
316
|
+
}
|
|
317
|
+
const hasDatumJson = entry.datumJson !== undefined && entry.datumJson !== null;
|
|
318
|
+
const hasDatumCbor = entry.datumCbor !== undefined && entry.datumCbor !== null;
|
|
319
|
+
if (hasDatumJson && hasDatumCbor)
|
|
320
|
+
return { error: `${at} takes datumJson or datumCbor, not both` };
|
|
321
|
+
if (hasDatumCbor) {
|
|
322
|
+
const cbor = parsePlutusCbor(entry.datumCbor, `${at}.datumCbor`);
|
|
323
|
+
if (cbor.error)
|
|
324
|
+
return { error: cbor.error };
|
|
325
|
+
input.datumCbor = cbor.hex;
|
|
326
|
+
}
|
|
327
|
+
else if (hasDatumJson) {
|
|
328
|
+
const datum = parseJsonField(entry.datumJson, `${at}.datumJson`);
|
|
329
|
+
if (datum.error)
|
|
330
|
+
return { error: datum.error };
|
|
331
|
+
input.datum = datum.parsed;
|
|
332
|
+
}
|
|
333
|
+
out.push(input);
|
|
334
|
+
}
|
|
335
|
+
return { parsed: out };
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Parse mintActionsJson for BuildPlutusTransaction: every action carries its own `mintingPolicyScript`
|
|
339
|
+
* (no request-level default) and optional `redeemerJson`; `assetUnit` is policyId+assetName, or a bare
|
|
340
|
+
* assetName that is prefixed with the policy id of the action's script.
|
|
341
|
+
*/
|
|
342
|
+
function parsePolicyMintActions(json) {
|
|
343
|
+
if (!json)
|
|
344
|
+
return { parsed: undefined };
|
|
345
|
+
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'mintActionsJson');
|
|
346
|
+
if (!jsonResult.valid)
|
|
347
|
+
return { error: jsonResult.error };
|
|
348
|
+
if (!Array.isArray(jsonResult.parsed))
|
|
349
|
+
return { error: 'mintActionsJson must be a JSON array' };
|
|
350
|
+
if (jsonResult.parsed.length === 0)
|
|
351
|
+
return { parsed: undefined };
|
|
352
|
+
const out = [];
|
|
353
|
+
for (let i = 0; i < jsonResult.parsed.length; i++) {
|
|
354
|
+
const entry = jsonResult.parsed[i];
|
|
355
|
+
if (!entry || typeof entry !== 'object')
|
|
356
|
+
return { error: `mintActions[${i}] must be an object` };
|
|
357
|
+
if (typeof entry.quantity !== 'string' || !/^-?\d+$/.test(entry.quantity) || BigInt(entry.quantity) === 0n) {
|
|
358
|
+
return { error: `mintActions[${i}].quantity must be a non-zero integer string` };
|
|
359
|
+
}
|
|
360
|
+
if (entry.mintingPolicyScript === undefined || entry.mintingPolicyScript === null) {
|
|
361
|
+
return { error: `mintActions[${i}].mintingPolicyScript is required` };
|
|
362
|
+
}
|
|
363
|
+
const policy = parseMintActionPolicyFields(entry, i);
|
|
364
|
+
if (policy.error)
|
|
365
|
+
return { error: policy.error };
|
|
366
|
+
let policyId;
|
|
367
|
+
try {
|
|
368
|
+
policyId = cardano_ledger_ts_1.Script.fromCbor(Buffer.from(policy.script, 'hex')).hash.toString();
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
return { error: `mintActions[${i}].mintingPolicyScript is not a valid Plutus script: ${err instanceof Error ? err.message : String(err)}` };
|
|
372
|
+
}
|
|
373
|
+
if (typeof entry.assetUnit !== 'string' || !/^[0-9a-fA-F]*$/.test(entry.assetUnit) || entry.assetUnit.length % 2 !== 0) {
|
|
374
|
+
return { error: `mintActions[${i}].assetUnit must be hex (policyId+assetName, or a bare assetName)` };
|
|
375
|
+
}
|
|
376
|
+
let assetUnit = entry.assetUnit.toLowerCase();
|
|
377
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
378
|
+
assetUnit = policyId + assetUnit;
|
|
379
|
+
}
|
|
380
|
+
else if (!assetUnit.startsWith(policyId)) {
|
|
381
|
+
return { error: `mintActions[${i}].assetUnit does not start with its policy id ${policyId}` };
|
|
382
|
+
}
|
|
383
|
+
if (!(0, validators_1.isAssetUnit)(assetUnit))
|
|
384
|
+
return { error: `mintActions[${i}].assetUnit is not a valid asset unit` };
|
|
385
|
+
out.push({
|
|
386
|
+
assetUnit,
|
|
387
|
+
quantity: BigInt(entry.quantity),
|
|
388
|
+
mintingPolicyScript: policy.script,
|
|
389
|
+
...(policy.redeemer !== undefined ? { redeemerJson: policy.redeemer } : {}),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return { parsed: out };
|
|
393
|
+
}
|
|
183
394
|
//# sourceMappingURL=tx-request-parsers.js.map
|