@odatano/core 2.0.0-rc.24 → 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/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 -182
- 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 +5 -0
- package/srv/blockchain/backends/odatano-backend.js +12 -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 +11 -5
- package/srv/blockchain/cardano-client.js +51 -16
- package/srv/blockchain/cardano-indexer.d.ts +43 -15
- package/srv/blockchain/cardano-indexer.js +177 -68
- package/srv/blockchain/cardano-tx-builder.d.ts +11 -1
- package/srv/blockchain/cardano-tx-builder.js +57 -2
- 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 +5 -2
- package/srv/blockchain/stored-chain.js +31 -5
- 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.js +35 -8
- 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 +4 -1
- package/srv/utils/agent-grants.js +1 -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
|
@@ -36,7 +36,7 @@ module.exports = (srv) => {
|
|
|
36
36
|
cleanData.forceInputs = forceInputsResult.parsed;
|
|
37
37
|
delete cleanData.forceInputsJson;
|
|
38
38
|
if (outputDatumJson) {
|
|
39
|
-
const jsonResult = (0, validators_1.
|
|
39
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(outputDatumJson, 'outputDatumJson');
|
|
40
40
|
if (!jsonResult.valid)
|
|
41
41
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', jsonResult.error, 'outputDatumJson');
|
|
42
42
|
cleanData.outputDatum = jsonResult.parsed;
|
|
@@ -53,7 +53,7 @@ module.exports = (srv) => {
|
|
|
53
53
|
// Parameters for a parameterized validator
|
|
54
54
|
let scriptParams;
|
|
55
55
|
if (scriptParamsJson) {
|
|
56
|
-
const jsonResult = (0, validators_1.
|
|
56
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
57
57
|
if (!jsonResult.valid)
|
|
58
58
|
return (0, errors_1.rejectInvalid)(req, 'BuildSimpleAdaTransaction', jsonResult.error, 'scriptParamsJson');
|
|
59
59
|
scriptParams = jsonResult.parsed;
|
|
@@ -136,7 +136,7 @@ module.exports = (srv) => {
|
|
|
136
136
|
const cleanData = { ...req.data };
|
|
137
137
|
delete cleanData.assetsJson;
|
|
138
138
|
if (outputDatumJson) {
|
|
139
|
-
const jsonResult = (0, validators_1.
|
|
139
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(outputDatumJson, 'outputDatumJson');
|
|
140
140
|
if (!jsonResult.valid)
|
|
141
141
|
return (0, errors_1.rejectInvalid)(req, 'BuildMultiAssetTransaction', jsonResult.error, 'outputDatumJson');
|
|
142
142
|
cleanData.outputDatum = jsonResult.parsed;
|
|
@@ -227,7 +227,7 @@ module.exports = (srv) => {
|
|
|
227
227
|
const requiredSigners = requiredSignersResult.parsed;
|
|
228
228
|
let scriptParams;
|
|
229
229
|
if (scriptParamsJson) {
|
|
230
|
-
const jsonResult = (0, validators_1.
|
|
230
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
231
231
|
if (!jsonResult.valid)
|
|
232
232
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'scriptParamsJson');
|
|
233
233
|
scriptParams = jsonResult.parsed;
|
|
@@ -237,14 +237,14 @@ module.exports = (srv) => {
|
|
|
237
237
|
}
|
|
238
238
|
let inlineDatum;
|
|
239
239
|
if (inlineDatumJson) {
|
|
240
|
-
const jsonResult = (0, validators_1.
|
|
240
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(inlineDatumJson, 'inlineDatumJson');
|
|
241
241
|
if (!jsonResult.valid)
|
|
242
242
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'inlineDatumJson');
|
|
243
243
|
inlineDatum = jsonResult.parsed;
|
|
244
244
|
}
|
|
245
245
|
let mintRedeemer;
|
|
246
246
|
if (mintRedeemerJson) {
|
|
247
|
-
const jsonResult = (0, validators_1.
|
|
247
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(mintRedeemerJson, 'mintRedeemerJson');
|
|
248
248
|
if (!jsonResult.valid)
|
|
249
249
|
return (0, errors_1.rejectInvalid)(req, 'BuildMintTransaction', jsonResult.error, 'mintRedeemerJson');
|
|
250
250
|
mintRedeemer = jsonResult.parsed;
|
|
@@ -399,7 +399,7 @@ module.exports = (srv) => {
|
|
|
399
399
|
const requiredSigners = requiredSignersResult.parsed;
|
|
400
400
|
let scriptParams;
|
|
401
401
|
if (scriptParamsJson) {
|
|
402
|
-
const jsonResult = (0, validators_1.
|
|
402
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
403
403
|
if (!jsonResult.valid)
|
|
404
404
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'scriptParamsJson');
|
|
405
405
|
scriptParams = jsonResult.parsed;
|
|
@@ -409,7 +409,7 @@ module.exports = (srv) => {
|
|
|
409
409
|
}
|
|
410
410
|
let inlineDatum;
|
|
411
411
|
if (inlineDatumJson) {
|
|
412
|
-
const jsonResult = (0, validators_1.
|
|
412
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(inlineDatumJson, 'inlineDatumJson');
|
|
413
413
|
if (!jsonResult.valid)
|
|
414
414
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', jsonResult.error, 'inlineDatumJson');
|
|
415
415
|
inlineDatum = jsonResult.parsed;
|
|
@@ -494,7 +494,7 @@ module.exports = (srv) => {
|
|
|
494
494
|
};
|
|
495
495
|
});
|
|
496
496
|
if (mintRedeemerJson) {
|
|
497
|
-
const mrJson = (0, validators_1.
|
|
497
|
+
const mrJson = (0, validators_1.validatePlutusJson)(mintRedeemerJson, 'mintRedeemerJson');
|
|
498
498
|
if (!mrJson.valid)
|
|
499
499
|
return (0, errors_1.rejectInvalid)(req, 'BuildPlutusSpendTransaction', mrJson.error, 'mintRedeemerJson');
|
|
500
500
|
parsedMintRedeemer = mrJson.parsed;
|
|
@@ -615,6 +615,78 @@ module.exports = (srv) => {
|
|
|
615
615
|
return buildResult;
|
|
616
616
|
});
|
|
617
617
|
});
|
|
618
|
+
// BuildPlutusTransaction — several script UTxOs in one transaction, each with its own redeemer.
|
|
619
|
+
srv.on('BuildPlutusTransaction', async (req) => {
|
|
620
|
+
const { senderAddress, changeAddress, scriptInputsJson, outputsJson, referenceInputsJson, forceInputsJson, requiredSignersJson, mintActionsJson, validityStartMs, validityEndMs } = req.data;
|
|
621
|
+
const action = 'BuildPlutusTransaction';
|
|
622
|
+
const errors = (0, validators_1.validateTransactionInputs)({ senderAddress, validityStartMs, validityEndMs }, ['senderAddress']);
|
|
623
|
+
(0, errors_1.throwIfValidationErrors)(req, action, errors);
|
|
624
|
+
if (changeAddress && !(0, validators_1.isValidBech32Address)(changeAddress)) {
|
|
625
|
+
return (0, errors_1.rejectInvalid)(req, action, 'Invalid changeAddress format', 'changeAddress');
|
|
626
|
+
}
|
|
627
|
+
const scriptInputsResult = (0, tx_request_parsers_1.parseScriptInputs)(scriptInputsJson);
|
|
628
|
+
if (scriptInputsResult.error)
|
|
629
|
+
return (0, errors_1.rejectInvalid)(req, action, scriptInputsResult.error, 'scriptInputsJson');
|
|
630
|
+
if (!outputsJson)
|
|
631
|
+
return (0, errors_1.rejectMissing)(req, action, 'outputsJson');
|
|
632
|
+
const outputsResult = (0, tx_request_parsers_1.parseOutputList)(outputsJson, 'outputsJson');
|
|
633
|
+
if (outputsResult.error)
|
|
634
|
+
return (0, errors_1.rejectInvalid)(req, action, outputsResult.error, 'outputsJson');
|
|
635
|
+
if (!outputsResult.parsed)
|
|
636
|
+
return (0, errors_1.rejectInvalid)(req, action, 'outputsJson must list at least one output', 'outputsJson');
|
|
637
|
+
const refInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(referenceInputsJson, 'referenceInputsJson');
|
|
638
|
+
if (refInputsResult.error)
|
|
639
|
+
return (0, errors_1.rejectInvalid)(req, action, refInputsResult.error, 'referenceInputsJson');
|
|
640
|
+
const forceInputsResult = (0, tx_request_parsers_1.parseUtxoRefArray)(forceInputsJson, 'forceInputsJson');
|
|
641
|
+
if (forceInputsResult.error)
|
|
642
|
+
return (0, errors_1.rejectInvalid)(req, action, forceInputsResult.error, 'forceInputsJson');
|
|
643
|
+
const signersResult = (0, tx_request_parsers_1.parseRequiredSigners)(requiredSignersJson);
|
|
644
|
+
if (signersResult.error)
|
|
645
|
+
return (0, errors_1.rejectInvalid)(req, action, signersResult.error, 'requiredSignersJson');
|
|
646
|
+
const mintResult = (0, tx_request_parsers_1.parsePolicyMintActions)(mintActionsJson);
|
|
647
|
+
if (mintResult.error)
|
|
648
|
+
return (0, errors_1.rejectInvalid)(req, action, mintResult.error, 'mintActionsJson');
|
|
649
|
+
// Script params are applied here, so the builder sees the final validators
|
|
650
|
+
const scriptInputs = [];
|
|
651
|
+
for (const [i, si] of scriptInputsResult.parsed.entries()) {
|
|
652
|
+
let validatorScript = si.validatorScript;
|
|
653
|
+
if (validatorScript && si.scriptParams) {
|
|
654
|
+
try {
|
|
655
|
+
validatorScript = (0, tx_build_helper_1.applyScriptParameters)(validatorScript, si.scriptParams);
|
|
656
|
+
}
|
|
657
|
+
catch (err) {
|
|
658
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
659
|
+
return (0, errors_1.rejectInvalid)(req, action, `scriptInputs[${i}]: failed to apply script parameters: ${errMsg}`, 'scriptInputsJson');
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
scriptInputs.push({
|
|
663
|
+
txHash: si.txHash,
|
|
664
|
+
outputIndex: si.outputIndex,
|
|
665
|
+
...(validatorScript ? { validatorScript } : { referenceScript: si.referenceScript }),
|
|
666
|
+
redeemer: si.redeemer,
|
|
667
|
+
...(si.redeemerCbor ? { redeemerCbor: si.redeemerCbor } : {}),
|
|
668
|
+
...(si.datum !== undefined ? { datum: si.datum } : {}),
|
|
669
|
+
...(si.datumCbor ? { datumCbor: si.datumCbor } : {}),
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
const buildReq = {
|
|
673
|
+
network: (0, server_1.getCardanoClient)().network,
|
|
674
|
+
senderAddress,
|
|
675
|
+
...(changeAddress ? { changeAddress } : {}),
|
|
676
|
+
scriptInputs,
|
|
677
|
+
outputs: outputsResult.parsed,
|
|
678
|
+
referenceInputs: refInputsResult.parsed,
|
|
679
|
+
forceInputs: forceInputsResult.parsed,
|
|
680
|
+
requiredSigners: signersResult.parsed,
|
|
681
|
+
mintActions: mintResult.parsed,
|
|
682
|
+
validityStartMs,
|
|
683
|
+
validityEndMs,
|
|
684
|
+
};
|
|
685
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
686
|
+
logger.debug({ senderAddress, scriptInputs: scriptInputs.length, outputs: buildReq.outputs.length }, 'Building multi-script Plutus transaction');
|
|
687
|
+
return (0, server_1.getCardanoIndexer)().indexPlutusBuildResult(db, buildReq);
|
|
688
|
+
});
|
|
689
|
+
});
|
|
618
690
|
// GetBuildDetails — an existing transaction build by id.
|
|
619
691
|
srv.on('GetBuildDetails', async (req) => {
|
|
620
692
|
const { buildId } = req.data;
|
|
@@ -627,7 +699,8 @@ module.exports = (srv) => {
|
|
|
627
699
|
return existing;
|
|
628
700
|
});
|
|
629
701
|
});
|
|
630
|
-
// SetCollateral —
|
|
702
|
+
// SetCollateral — collateral is available when the builders would find it: an ADA-only UTxO of
|
|
703
|
+
// >= 5 ADA without a reference script, plus another UTxO to fund with; otherwise a self-send creates one.
|
|
631
704
|
srv.on('SetCollateral', async (req) => {
|
|
632
705
|
const { address } = req.data;
|
|
633
706
|
if (!address)
|
|
@@ -638,12 +711,13 @@ module.exports = (srv) => {
|
|
|
638
711
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
639
712
|
// Inside handleRequest use rejectInvalid (typed BackendError 400), not req.reject,
|
|
640
713
|
// so mapError preserves the status.
|
|
641
|
-
const
|
|
714
|
+
const ledger = await (0, server_1.getCardanoIndexer)().resolveAddressUtxos(db, address);
|
|
715
|
+
const utxos = (0, server_1.getCardanoClient)().pendingSpends?.apply(address, ledger) ?? ledger;
|
|
642
716
|
if (utxos.length === 0) {
|
|
643
717
|
return (0, errors_1.rejectInvalid)(req, 'SetCollateral', 'No UTxOs found at address', 'address');
|
|
644
718
|
}
|
|
645
|
-
const qualifyingUtxos = utxos.filter(u => (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE);
|
|
646
|
-
if (qualifyingUtxos.length >= 2) {
|
|
719
|
+
const qualifyingUtxos = utxos.filter(u => (0, tx_build_helper_1.isCollateralCandidate)(u) && (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE);
|
|
720
|
+
if (qualifyingUtxos.length >= 1 && utxos.length >= 2) {
|
|
647
721
|
return {
|
|
648
722
|
id: cds_1.default.utils.uuid(),
|
|
649
723
|
network: (0, server_1.getCardanoClient)().network,
|
|
@@ -810,7 +884,7 @@ module.exports = (srv) => {
|
|
|
810
884
|
}
|
|
811
885
|
let scriptParams;
|
|
812
886
|
if (scriptParamsJson) {
|
|
813
|
-
const jsonResult = (0, validators_1.
|
|
887
|
+
const jsonResult = (0, validators_1.validatePlutusJson)(scriptParamsJson, 'scriptParamsJson');
|
|
814
888
|
if (!jsonResult.valid)
|
|
815
889
|
return (0, errors_1.rejectInvalid)(req, 'DeriveScriptAddress', jsonResult.error, 'scriptParamsJson');
|
|
816
890
|
if (!Array.isArray(jsonResult.parsed)) {
|
package/srv/server.js
CHANGED
|
@@ -30,6 +30,7 @@ const network_context_1 = require("./utils/network-context");
|
|
|
30
30
|
const db_sanitize_1 = require("./utils/db-sanitize");
|
|
31
31
|
const db_indexes_1 = require("./utils/db-indexes");
|
|
32
32
|
const pg_order_nulls_1 = require("./utils/pg-order-nulls");
|
|
33
|
+
const pg_inline_json_1 = require("./utils/pg-inline-json");
|
|
33
34
|
const crawler_1 = require("./blockchain/crawler");
|
|
34
35
|
const wallet_worker_1 = require("./blockchain/wallet-worker");
|
|
35
36
|
const agent_grants_config_1 = require("./utils/agent-grants-config");
|
|
@@ -77,8 +78,10 @@ let bootstrapError = null;
|
|
|
77
78
|
async function initializeAppContext(config, protocolParams, hsmConfig) {
|
|
78
79
|
logger.debug('Initializing blockchain components...');
|
|
79
80
|
// Database first. Postgres ORDER BY without a NULLS clause on key / NOT NULL columns so
|
|
80
|
-
// the indexes serve `$top` / `$orderby
|
|
81
|
+
// the indexes serve `$top` / `$orderby`, bulk rows inline instead of through a COPY buffer;
|
|
82
|
+
// then the secondary indexes the model cannot declare.
|
|
81
83
|
(0, pg_order_nulls_1.installPostgresOrderNulls)();
|
|
84
|
+
(0, pg_inline_json_1.installPostgresInlineJson)();
|
|
82
85
|
try {
|
|
83
86
|
await (0, db_indexes_1.ensureDbIndexes)();
|
|
84
87
|
}
|
package/srv/utils/const.d.ts
CHANGED
|
@@ -73,6 +73,11 @@ export declare const HRP: {
|
|
|
73
73
|
export declare const MAX_JSON_SIZE = 1048576;
|
|
74
74
|
/** Maximum nesting depth for JSON objects/arrays */
|
|
75
75
|
export declare const MAX_DEPTH = 10;
|
|
76
|
+
/**
|
|
77
|
+
* Nesting depth for PlutusData JSON (redeemers, datums, script params): every constructor takes two
|
|
78
|
+
* levels ({constructor, fields: [...]}), so protocol redeemers go past MAX_DEPTH; size stays capped.
|
|
79
|
+
*/
|
|
80
|
+
export declare const PLUTUS_DATA_MAX_DEPTH = 64;
|
|
76
81
|
/** Maximum number of keys in a JSON object */
|
|
77
82
|
export declare const MAX_KEYS = 100;
|
|
78
83
|
/** Maximum number of elements in a JSON array */
|
package/srv/utils/const.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DREP_ID_REGEX = exports.POOL_ID_REGEX = exports.ASSET_UNIT_REGEX = exports.TX_HASH_REGEX = exports.HEX_56_REGEX = exports.HEX_64_REGEX = exports.MAX_POSIX_MS_DIGITS = exports.DEFAULT_VALIDITY_END_OFFSET_MS = exports.DEFAULT_VALIDITY_START_OFFSET_MS = exports.GENESIS_INFOS_BY_NETWORK = exports.MIN_CHANGE_LOVELACE = exports.ED25519_KEY_HASH_REGEX = exports.ED25519_KEY_HASH_HEX_LENGTH = exports.MIN_FULL_ASSET_UNIT_LENGTH = exports.POLICY_ID_HEX_LENGTH = exports.DREP_ID_BYTES = exports.POOL_ID_BYTES = exports.MAX_EPOCH = exports.MAX_TX_CBOR_HEX_LENGTH = exports.BECH32_MAX_LENGTH = exports.MAX_STRING_LENGTH = exports.MAX_ARRAY_LENGTH = exports.MAX_KEYS = exports.MAX_DEPTH = exports.MAX_JSON_SIZE = exports.HRP = exports.FEE_BUFFER_LOVELACE = exports.COLLATERAL_LOVELACE = exports.ABS_MEM_BUFFER = exports.ABS_CPU_BUFFER = exports.EXECUTION_UNIT_BUFFER = exports.HIGH_EXECUTION_UNITS = exports.DEFAULT_EXECUTION_UNITS = exports.EPOCH_CONFIG_BY_NETWORK = exports.CARDANO_DEFAULTS = void 0;
|
|
3
|
+
exports.DREP_ID_REGEX = exports.POOL_ID_REGEX = exports.ASSET_UNIT_REGEX = exports.TX_HASH_REGEX = exports.HEX_56_REGEX = exports.HEX_64_REGEX = exports.MAX_POSIX_MS_DIGITS = exports.DEFAULT_VALIDITY_END_OFFSET_MS = exports.DEFAULT_VALIDITY_START_OFFSET_MS = exports.GENESIS_INFOS_BY_NETWORK = exports.MIN_CHANGE_LOVELACE = exports.ED25519_KEY_HASH_REGEX = exports.ED25519_KEY_HASH_HEX_LENGTH = exports.MIN_FULL_ASSET_UNIT_LENGTH = exports.POLICY_ID_HEX_LENGTH = exports.DREP_ID_BYTES = exports.POOL_ID_BYTES = exports.MAX_EPOCH = exports.MAX_TX_CBOR_HEX_LENGTH = exports.BECH32_MAX_LENGTH = exports.MAX_STRING_LENGTH = exports.MAX_ARRAY_LENGTH = exports.MAX_KEYS = exports.PLUTUS_DATA_MAX_DEPTH = exports.MAX_DEPTH = exports.MAX_JSON_SIZE = exports.HRP = exports.FEE_BUFFER_LOVELACE = exports.COLLATERAL_LOVELACE = exports.ABS_MEM_BUFFER = exports.ABS_CPU_BUFFER = exports.EXECUTION_UNIT_BUFFER = exports.HIGH_EXECUTION_UNITS = exports.DEFAULT_EXECUTION_UNITS = exports.EPOCH_CONFIG_BY_NETWORK = exports.CARDANO_DEFAULTS = void 0;
|
|
4
4
|
/** Cardano protocol constants */
|
|
5
5
|
exports.CARDANO_DEFAULTS = {
|
|
6
6
|
/** Maximum ADA supply in lovelace (45 billion ADA) */
|
|
@@ -52,6 +52,11 @@ exports.HRP = {
|
|
|
52
52
|
exports.MAX_JSON_SIZE = 1_048_576;
|
|
53
53
|
/** Maximum nesting depth for JSON objects/arrays */
|
|
54
54
|
exports.MAX_DEPTH = 10;
|
|
55
|
+
/**
|
|
56
|
+
* Nesting depth for PlutusData JSON (redeemers, datums, script params): every constructor takes two
|
|
57
|
+
* levels ({constructor, fields: [...]}), so protocol redeemers go past MAX_DEPTH; size stays capped.
|
|
58
|
+
*/
|
|
59
|
+
exports.PLUTUS_DATA_MAX_DEPTH = 64;
|
|
55
60
|
/** Maximum number of keys in a JSON object */
|
|
56
61
|
exports.MAX_KEYS = 100;
|
|
57
62
|
/** Maximum number of elements in a JSON array */
|
|
@@ -14,6 +14,8 @@ export declare const ERROR_CODES: {
|
|
|
14
14
|
readonly TX_PARSE_FAILED: "ODATANO_TX_PARSE_FAILED";
|
|
15
15
|
/** 400: ledger rejected the tx on script evaluation (PlutusFailure, CekError, budget, hash mismatch). */
|
|
16
16
|
readonly SCRIPT_VALIDATION_FAILURE: "ODATANO_SCRIPT_VALIDATION_FAILURE";
|
|
17
|
+
/** 409: a crawler cursor block is not on this instance's chain (orphaned by a reorg). */
|
|
18
|
+
readonly CHAIN_POINT_MISMATCH: "ODATANO_CHAIN_POINT_MISMATCH";
|
|
17
19
|
/** 409: transaction already submitted (duplicate / replay). */
|
|
18
20
|
readonly TX_ALREADY_SUBMITTED: "ODATANO_TX_ALREADY_SUBMITTED";
|
|
19
21
|
/** 429: provider rate limit hit. */
|
package/srv/utils/error-codes.js
CHANGED
|
@@ -17,6 +17,8 @@ exports.ERROR_CODES = {
|
|
|
17
17
|
TX_PARSE_FAILED: 'ODATANO_TX_PARSE_FAILED',
|
|
18
18
|
/** 400: ledger rejected the tx on script evaluation (PlutusFailure, CekError, budget, hash mismatch). */
|
|
19
19
|
SCRIPT_VALIDATION_FAILURE: 'ODATANO_SCRIPT_VALIDATION_FAILURE',
|
|
20
|
+
/** 409: a crawler cursor block is not on this instance's chain (orphaned by a reorg). */
|
|
21
|
+
CHAIN_POINT_MISMATCH: 'ODATANO_CHAIN_POINT_MISMATCH',
|
|
20
22
|
/** 409: transaction already submitted (duplicate / replay). */
|
|
21
23
|
TX_ALREADY_SUBMITTED: 'ODATANO_TX_ALREADY_SUBMITTED',
|
|
22
24
|
/** 429: provider rate limit hit. */
|
package/srv/utils/errors.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ export declare class TransactionValidationError extends BackendError {
|
|
|
22
22
|
export declare class ScriptValidationError extends BackendError {
|
|
23
23
|
constructor(message: string, originalError?: unknown);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* A crawler cursor block this instance does not follow (409). A 4xx keeps its message in production,
|
|
27
|
+
* so a remote crawler receives the `CHAIN_POINT_MISMATCH:` marker it recovers on.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ChainPointMismatchError extends BackendError {
|
|
30
|
+
constructor(message: string, backendName?: string);
|
|
31
|
+
}
|
|
25
32
|
/** Transaction already in mempool or on chain (409). */
|
|
26
33
|
export declare class TransactionAlreadySubmittedError extends BackendError {
|
|
27
34
|
readonly txHash: string;
|
package/srv/utils/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ChainSyncStalledError = exports.ChainSyncClosedError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
|
|
3
|
+
exports.AllBackendsInitFailedError = exports.BackendInitError = exports.ChainSyncFrameError = exports.ChainSyncStalledError = exports.ChainSyncClosedError = exports.ConfigError = exports.HsmError = exports.AllBackendsFailedError = exports.RateLimitError = exports.ProviderUnavailableError = exports.MixedAssetsError = exports.InsufficientFundsError = exports.TransactionAlreadySubmittedError = exports.ChainPointMismatchError = exports.ScriptValidationError = exports.TransactionValidationError = exports.NotFoundError = exports.BackendError = void 0;
|
|
4
4
|
exports.isNotFoundOnAllBackends = isNotFoundOnAllBackends;
|
|
5
5
|
exports.isPostgrestServerErrorCode = isPostgrestServerErrorCode;
|
|
6
6
|
exports.getErrorStatus = getErrorStatus;
|
|
@@ -51,6 +51,16 @@ class ScriptValidationError extends BackendError {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
exports.ScriptValidationError = ScriptValidationError;
|
|
54
|
+
/**
|
|
55
|
+
* A crawler cursor block this instance does not follow (409). A 4xx keeps its message in production,
|
|
56
|
+
* so a remote crawler receives the `CHAIN_POINT_MISMATCH:` marker it recovers on.
|
|
57
|
+
*/
|
|
58
|
+
class ChainPointMismatchError extends BackendError {
|
|
59
|
+
constructor(message, backendName) {
|
|
60
|
+
super(message, 409, error_codes_1.ERROR_CODES.CHAIN_POINT_MISMATCH, backendName);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ChainPointMismatchError = ChainPointMismatchError;
|
|
54
64
|
/** Transaction already in mempool or on chain (409). */
|
|
55
65
|
class TransactionAlreadySubmittedError extends BackendError {
|
|
56
66
|
txHash;
|
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
|