@odatano/core 1.9.3 → 1.9.4
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/CardanoODataService/index.d.ts +4 -4
- package/@cds-models/CardanoODataService/index.d.ts.map +1 -1
- package/@cds-models/CardanoODataService/index.ts +3 -3
- package/package.json +1 -3
- package/srv/blockchain/cardano-indexer.d.ts +19 -0
- package/srv/blockchain/cardano-indexer.js +34 -1
- package/srv/blockchain/cardano-tx-builder.js +1 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +39 -1
- package/srv/blockchain/transaction-building/buildooor-tx.js +84 -19
- package/srv/blockchain/transaction-building/keep-relevant.d.ts +29 -0
- package/srv/blockchain/transaction-building/keep-relevant.js +116 -0
- package/srv/cardano-service.cds +1 -1
- package/srv/cardano-service.js +8 -7
- package/srv/cardano-sign-service.js +9 -0
- package/srv/cardano-tx-service.js +17 -9
- package/srv/utils/errors.d.ts +6 -3
- package/srv/utils/errors.js +9 -4
- package/srv/utils/tx-build-helper.d.ts +28 -1
- package/srv/utils/tx-build-helper.js +71 -3
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLovelace = getLovelace;
|
|
4
4
|
exports.assertAdaOnly = assertAdaOnly;
|
|
5
5
|
exports.getTxHashFromCbor = getTxHashFromCbor;
|
|
6
|
+
exports.extractTxCacheTargets = extractTxCacheTargets;
|
|
6
7
|
exports.mapBuilderError = mapBuilderError;
|
|
7
8
|
exports.parseAssetUnit = parseAssetUnit;
|
|
8
9
|
exports.jsonToPlutusData = jsonToPlutusData;
|
|
@@ -16,6 +17,7 @@ const error_codes_1 = require("./error-codes");
|
|
|
16
17
|
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
17
18
|
const uplc_1 = require("@harmoniclabs/uplc");
|
|
18
19
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
20
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
19
21
|
/**
|
|
20
22
|
* Extract lovelace amount from UTxO
|
|
21
23
|
* @param u UTxO to extract from
|
|
@@ -72,6 +74,66 @@ function getTxHashFromCbor(txCbor) {
|
|
|
72
74
|
throw new errors_1.TransactionValidationError('Failed to parse transaction CBOR', err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
|
|
73
75
|
}
|
|
74
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Extract the consumed input refs and the output addresses from a transaction
|
|
79
|
+
* CBOR (signed or unsigned) — the rows a successful submit makes stale in the
|
|
80
|
+
* UTxO cache. Works at the raw-CBOR level for the same reason as
|
|
81
|
+
* getTxHashFromCbor (the high-level Tx.fromCbor rejects its own tag-259
|
|
82
|
+
* AuxiliaryData builds).
|
|
83
|
+
*
|
|
84
|
+
* Outputs whose address bytes cannot be decoded (e.g. Byron bootstrap
|
|
85
|
+
* addresses) are skipped — invalidation is best-effort per address.
|
|
86
|
+
*
|
|
87
|
+
* @param txCbor transaction in CBOR hex format
|
|
88
|
+
* @throws {TransactionValidationError} if the CBOR is not a transaction
|
|
89
|
+
*/
|
|
90
|
+
function extractTxCacheTargets(txCbor) {
|
|
91
|
+
let body;
|
|
92
|
+
try {
|
|
93
|
+
const tx = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(txCbor));
|
|
94
|
+
if (!(tx instanceof cbor_1.CborArray) || !(tx.array[0] instanceof cbor_1.CborMap)) {
|
|
95
|
+
throw new Error('not a transaction');
|
|
96
|
+
}
|
|
97
|
+
body = tx.array[0];
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
throw new errors_1.TransactionValidationError('Failed to parse transaction CBOR', err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
|
|
101
|
+
}
|
|
102
|
+
const bodyValue = (key) => body.map.find(e => e.k instanceof cbor_1.CborUInt && e.k.num === BigInt(key))?.v;
|
|
103
|
+
// key 0: inputs — plain array or a CBOR tag-258 set (Conway)
|
|
104
|
+
const inputs = [];
|
|
105
|
+
let inputsObj = bodyValue(0);
|
|
106
|
+
if (inputsObj instanceof cbor_1.CborTag)
|
|
107
|
+
inputsObj = inputsObj.data;
|
|
108
|
+
if (inputsObj instanceof cbor_1.CborArray) {
|
|
109
|
+
for (const entry of inputsObj.array) {
|
|
110
|
+
if (entry instanceof cbor_1.CborArray &&
|
|
111
|
+
entry.array[0] instanceof cbor_1.CborBytes &&
|
|
112
|
+
entry.array[1] instanceof cbor_1.CborUInt) {
|
|
113
|
+
inputs.push({ txHash: (0, uint8array_utils_1.toHex)(entry.array[0].bytes), outputIndex: Number(entry.array[1].num) });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// key 1: outputs — post-alonzo map form ({0: address, ...}) or legacy array form ([address, amount, ...])
|
|
118
|
+
const outputAddresses = new Set();
|
|
119
|
+
const outputsObj = bodyValue(1);
|
|
120
|
+
if (outputsObj instanceof cbor_1.CborArray) {
|
|
121
|
+
for (const output of outputsObj.array) {
|
|
122
|
+
const addrObj = output instanceof cbor_1.CborMap
|
|
123
|
+
? output.map.find(e => e.k instanceof cbor_1.CborUInt && e.k.num === 0n)?.v
|
|
124
|
+
: output instanceof cbor_1.CborArray ? output.array[0] : undefined;
|
|
125
|
+
if (!(addrObj instanceof cbor_1.CborBytes))
|
|
126
|
+
continue;
|
|
127
|
+
try {
|
|
128
|
+
outputAddresses.add(cardano_ledger_ts_1.Address.fromBuffer(addrObj.bytes).toString());
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// non-Shelley address bytes — nothing cached under a bech32 key for it
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { inputs, outputAddresses: [...outputAddresses] };
|
|
136
|
+
}
|
|
75
137
|
/**
|
|
76
138
|
* Maps builder errors to typed BackendErrors
|
|
77
139
|
* Used by the Buildooor transaction builder.
|
|
@@ -79,10 +141,13 @@ function getTxHashFromCbor(txCbor) {
|
|
|
79
141
|
* (e.g. "not enough <policyId.assetName>"), falling back to 'lovelace'.
|
|
80
142
|
* @param err Error from builder
|
|
81
143
|
* @param assetUnit Optional asset unit override (auto-extracted from error message if omitted)
|
|
144
|
+
* @param context Optional build-flow context (e.g. the collateral/funding partition)
|
|
145
|
+
* appended to the consumer-facing message — the builder's own message
|
|
146
|
+
* has no way of knowing it
|
|
82
147
|
* @throws {InsufficientFundsError} if error is related to insufficient funds
|
|
83
148
|
* @throws {Error} original error if not mappable
|
|
84
149
|
*/
|
|
85
|
-
function mapBuilderError(err, assetUnit) {
|
|
150
|
+
function mapBuilderError(err, assetUnit, context) {
|
|
86
151
|
// Already-typed errors carry their own status + payload (amounts, asset units,
|
|
87
152
|
// validation details) — re-wrapping them into a generic InsufficientFundsError
|
|
88
153
|
// because their MESSAGE happens to contain "balance"/"insufficient" destroys that.
|
|
@@ -90,7 +155,8 @@ function mapBuilderError(err, assetUnit) {
|
|
|
90
155
|
throw err;
|
|
91
156
|
}
|
|
92
157
|
const errObj = err;
|
|
93
|
-
const
|
|
158
|
+
const rawMsg = errObj?.message || errObj?.toString?.() || String(err);
|
|
159
|
+
const msg = rawMsg.toLowerCase();
|
|
94
160
|
if (msg.includes('not enough') ||
|
|
95
161
|
msg.includes('insufficient') ||
|
|
96
162
|
msg.includes('balance')) {
|
|
@@ -98,7 +164,9 @@ function mapBuilderError(err, assetUnit) {
|
|
|
98
164
|
const match = msg.match(/not enough\s+([a-f0-9.]+)/i);
|
|
99
165
|
return match?.[1] || 'lovelace';
|
|
100
166
|
})();
|
|
101
|
-
|
|
167
|
+
// The builder knows no amounts here — surface its own message (plus the build
|
|
168
|
+
// context) instead of a meaningless "required 0, available 0".
|
|
169
|
+
throw new errors_1.InsufficientFundsError(effectiveUnit, 0n, 0n, err, context ? `${rawMsg} (${context})` : rawMsg);
|
|
102
170
|
}
|
|
103
171
|
throw err;
|
|
104
172
|
}
|