@odatano/core 2.0.0-rc.19 → 2.0.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +1 -5
- package/@cds-models/CardanoIndexerService/index.d.ts +51 -2
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -10
- package/src/index.js +6 -16
- package/src/plugin.js +11 -27
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +39 -150
- package/srv/blockchain/backends/cardano-backend.d.ts +53 -171
- package/srv/blockchain/backends/cardano-backend.js +1 -5
- package/srv/blockchain/backends/koios-backend.d.ts +26 -71
- package/srv/blockchain/backends/koios-backend.js +50 -132
- package/srv/blockchain/backends/ogmios-backend.d.ts +43 -124
- package/srv/blockchain/backends/ogmios-backend.js +71 -179
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +12 -57
- package/srv/blockchain/backends/ogmios-frame-guard.js +27 -66
- package/srv/blockchain/cardano-client.d.ts +43 -216
- package/srv/blockchain/cardano-client.js +49 -234
- package/srv/blockchain/cardano-indexer.d.ts +79 -357
- package/srv/blockchain/cardano-indexer.js +98 -406
- package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
- package/srv/blockchain/cardano-tx-builder.js +21 -107
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +41 -145
- package/srv/blockchain/crawler/crawler.js +57 -172
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +2 -6
- package/srv/blockchain/crawler/index.js +4 -9
- package/srv/blockchain/crawler/sync-state.d.ts +17 -39
- package/srv/blockchain/crawler/sync-state.js +23 -55
- package/srv/blockchain/crawler/utxo-set-import.d.ts +5 -22
- package/srv/blockchain/crawler/utxo-set-import.js +8 -28
- package/srv/blockchain/ledger-state.d.ts +3 -12
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +65 -174
- package/srv/blockchain/transaction-building/buildooor-tx.js +107 -266
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +9 -22
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +12 -35
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -32
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +33 -111
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +34 -90
- package/srv/cardano-agent-service.cds +1 -5
- package/srv/cardano-agent-service.js +3 -7
- package/srv/cardano-indexer-service.cds +32 -4
- package/srv/cardano-indexer-service.js +83 -15
- package/srv/cardano-service.js +36 -98
- package/srv/cardano-sign-service.cds +1 -1
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +1 -1
- package/srv/cardano-tx-service.js +54 -174
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +27 -86
- package/srv/server.js +52 -148
- package/srv/utils/agent-grants-config.d.ts +11 -50
- package/srv/utils/agent-grants-config.js +12 -45
- package/srv/utils/agent-grants.d.ts +34 -123
- package/srv/utils/agent-grants.js +57 -156
- package/srv/utils/agent-token-auth.d.ts +2 -5
- package/srv/utils/agent-token-auth.js +2 -5
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +2 -7
- package/srv/utils/db-indexes.js +7 -34
- package/srv/utils/db-sanitize.d.ts +5 -18
- package/srv/utils/db-sanitize.js +6 -19
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +29 -191
- package/srv/utils/errors.js +44 -229
- package/srv/utils/liveness.d.ts +2 -9
- package/srv/utils/liveness.js +3 -11
- package/srv/utils/mappers.d.ts +50 -298
- package/srv/utils/mappers.js +80 -386
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.js +4 -23
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +6 -17
- package/srv/utils/rate-limiter.js +5 -15
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +7 -26
- package/srv/utils/tx-request-parsers.js +7 -26
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +67 -206
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
package/srv/utils/mappers.js
CHANGED
|
@@ -53,19 +53,9 @@ const cardano_costmodels_ts_1 = require("@harmoniclabs/cardano-costmodels-ts");
|
|
|
53
53
|
const logger = cds_1.default.log('mappers');
|
|
54
54
|
const errors_1 = require("./errors");
|
|
55
55
|
const const_1 = require("./const");
|
|
56
|
-
/**
|
|
57
|
-
* Maximum age for cached/indexed data in milliseconds
|
|
58
|
-
*/
|
|
59
|
-
/**
|
|
60
|
-
* Map Transaction Data
|
|
61
|
-
* Converts provider transaction data into TransactionRow format
|
|
62
|
-
* @param providerTx
|
|
63
|
-
* @returns {TransactionRow} mapped transaction row
|
|
64
|
-
*/
|
|
56
|
+
/** Provider transaction to TransactionRow. */
|
|
65
57
|
function mapTransaction(providerTx) {
|
|
66
|
-
//
|
|
67
|
-
// length check matters: the Ogmios chain-sync mapper produced `[]` for metadata-less
|
|
68
|
-
// txs, which the old `Array.isArray` test counted as "has metadata"
|
|
58
|
+
// length check: chain-sync delivers `[]` for metadata-less txs
|
|
69
59
|
const hasMetadata = Array.isArray(providerTx.metadata) && providerTx.metadata.length > 0;
|
|
70
60
|
const hasInputs = Array.isArray(providerTx.inputs) && providerTx.inputs.length > 0;
|
|
71
61
|
const hasOutputs = Array.isArray(providerTx.outputs) && providerTx.outputs.length > 0;
|
|
@@ -84,32 +74,22 @@ function mapTransaction(providerTx) {
|
|
|
84
74
|
hasMetadata: hasMetadata,
|
|
85
75
|
};
|
|
86
76
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Map Transaction Inputs
|
|
89
|
-
* Converts provider transaction input data into TransactionInputRow format
|
|
90
|
-
* @param txHash transaction hash
|
|
91
|
-
* @param txInputs transaction inputs from provider
|
|
92
|
-
* @returns {TransactionInputRow[]} mapped transaction input rows
|
|
93
|
-
*/
|
|
77
|
+
/** Provider transaction inputs to TransactionInputRows, keyed by position in the tx. */
|
|
94
78
|
function mapTransactionInputs(txHash, txInputs) {
|
|
95
79
|
return txInputs.map((input, idx) => {
|
|
96
|
-
//
|
|
97
|
-
// Note: input.outputIndex is the output index from the ORIGINAL UTxO being spent, not for keying here
|
|
80
|
+
// Position in this tx's inputs; input.outputIndex is the spent UTxO's index, not a key here
|
|
98
81
|
const inputIndex = idx;
|
|
99
|
-
// check presence of address and amount arrays
|
|
100
82
|
const hasAddress = !!input.address?.length;
|
|
101
83
|
const hasAssets = Array.isArray(input.amount) && input.amount.length > 0;
|
|
102
84
|
return {
|
|
103
85
|
tx_hash: txHash,
|
|
104
86
|
inputIndex: inputIndex,
|
|
105
|
-
//
|
|
106
|
-
// dangling empty-string Addresses association (lazy-path inputs are never empty)
|
|
87
|
+
// unresolved chain-sync inputs carry '': persist a null FK, not an empty-string association
|
|
107
88
|
address_address: input.address || null,
|
|
108
89
|
utxoData_dataHash: input.dataHash || null,
|
|
109
90
|
utxoData_inlineDatum: input.inlineDatum || null,
|
|
110
91
|
utxoData_referenceScriptHash: input.referenceScriptHash || null,
|
|
111
|
-
//
|
|
112
|
-
// path needs it for resolveInputs), the row just never kept it before.
|
|
92
|
+
// outpoint of the consumed UTxO
|
|
113
93
|
spentTxHash: input.txHash || null,
|
|
114
94
|
spentOutputIndex: Number.isInteger(input.outputIndex) ? input.outputIndex : null,
|
|
115
95
|
isCollateral: Boolean(input.isCollateral),
|
|
@@ -119,16 +99,10 @@ function mapTransactionInputs(txHash, txInputs) {
|
|
|
119
99
|
};
|
|
120
100
|
});
|
|
121
101
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Map Transaction Input Assets
|
|
124
|
-
* Converts provider transaction input asset data into TransactionInputAssetRow format
|
|
125
|
-
* @param txHash transaction hash
|
|
126
|
-
* @param inputs transaction inputs from provider
|
|
127
|
-
* @returns {TransactionInputAssetRow[]} mapped transaction input asset rows
|
|
128
|
-
*/
|
|
102
|
+
/** Provider transaction input assets to TransactionInputAssetRows. */
|
|
129
103
|
function mapTransactionInputAssets(txHash, inputs) {
|
|
130
104
|
return inputs.flatMap((input, idx) => {
|
|
131
|
-
//
|
|
105
|
+
// must match mapTransactionInputs
|
|
132
106
|
const inputIndex = idx;
|
|
133
107
|
if (!Array.isArray(input.amount))
|
|
134
108
|
return [];
|
|
@@ -145,12 +119,7 @@ function mapTransactionInputAssets(txHash, inputs) {
|
|
|
145
119
|
});
|
|
146
120
|
});
|
|
147
121
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Map Transaction Certificates (crawler coverage, `crawler.certificates`).
|
|
150
|
-
* @param txHash transaction hash
|
|
151
|
-
* @param certificates normalized certificates from the source
|
|
152
|
-
* @returns {TransactionCertificateRow[]} one row per (certIndex, kind)
|
|
153
|
-
*/
|
|
122
|
+
/** Normalized certificates to TransactionCertificateRows, one per (certIndex, kind). */
|
|
154
123
|
function mapTransactionCertificates(txHash, certificates) {
|
|
155
124
|
return certificates.map((c) => ({
|
|
156
125
|
tx_hash: txHash,
|
|
@@ -163,12 +132,7 @@ function mapTransactionCertificates(txHash, certificates) {
|
|
|
163
132
|
epoch: c.epoch ?? null,
|
|
164
133
|
}));
|
|
165
134
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Map Transaction Withdrawals (crawler coverage, `crawler.certificates`).
|
|
168
|
-
* @param txHash transaction hash
|
|
169
|
-
* @param withdrawals normalized withdrawals from the source
|
|
170
|
-
* @returns {TransactionWithdrawalRow[]} one row per reward account
|
|
171
|
-
*/
|
|
135
|
+
/** Normalized withdrawals to TransactionWithdrawalRows, one per reward account. */
|
|
172
136
|
function mapTransactionWithdrawals(txHash, withdrawals) {
|
|
173
137
|
return withdrawals
|
|
174
138
|
.filter((w) => !!w.stakeAddress)
|
|
@@ -178,13 +142,7 @@ function mapTransactionWithdrawals(txHash, withdrawals) {
|
|
|
178
142
|
lovelace: String(w.amount ?? '0'),
|
|
179
143
|
}));
|
|
180
144
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Map Transaction Outputs
|
|
183
|
-
* Converts provider transaction output data into TransactionOutputRow format
|
|
184
|
-
* @param txHash transaction hash
|
|
185
|
-
* @param txOutputs transaction outputs from provider
|
|
186
|
-
* @returns {TransactionOutputRow[]} mapped transaction output rows
|
|
187
|
-
*/
|
|
145
|
+
/** Provider transaction outputs to TransactionOutputRows. */
|
|
188
146
|
function mapTransactionOutputs(txHash, txOutputs) {
|
|
189
147
|
return txOutputs.map((output) => {
|
|
190
148
|
const outputIndex = output.outputIndex;
|
|
@@ -202,13 +160,7 @@ function mapTransactionOutputs(txHash, txOutputs) {
|
|
|
202
160
|
};
|
|
203
161
|
});
|
|
204
162
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Map Transaction Output Assets
|
|
207
|
-
* Converts provider transaction output asset data into TransactionOutputAssetRow format
|
|
208
|
-
* @param txHash transaction hash
|
|
209
|
-
* @param outputs transaction outputs from provider
|
|
210
|
-
* @returns {TransactionOutputAssetRow[]} mapped transaction output asset rows
|
|
211
|
-
*/
|
|
163
|
+
/** Provider transaction output assets to TransactionOutputAssetRows. */
|
|
212
164
|
function mapTransactionOutputAssets(txHash, outputs) {
|
|
213
165
|
return outputs.flatMap((output) => {
|
|
214
166
|
const outputIndex = output.outputIndex;
|
|
@@ -227,13 +179,7 @@ function mapTransactionOutputAssets(txHash, outputs) {
|
|
|
227
179
|
});
|
|
228
180
|
});
|
|
229
181
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Map Address Data
|
|
232
|
-
* Converts provider address data into AddressRow format
|
|
233
|
-
* @param address address string
|
|
234
|
-
* @param addressData address data from provider
|
|
235
|
-
* @returns {AddressRow} mapped address row
|
|
236
|
-
*/
|
|
182
|
+
/** Provider address to a temporal AddressRow valid for `maxAge` ms. */
|
|
237
183
|
function mapAddress(address, addressData, maxAge) {
|
|
238
184
|
const now = Date.now();
|
|
239
185
|
const nowIso = new Date(now).toISOString();
|
|
@@ -244,7 +190,7 @@ function mapAddress(address, addressData, maxAge) {
|
|
|
244
190
|
const utxoCount = Array.isArray(addressData.utxos) ? addressData.utxos.length : 0;
|
|
245
191
|
const hasUtxos = utxoCount > 0;
|
|
246
192
|
const hasAssets = Array.isArray(addressData.amount) && addressData.amount.some((a) => a.unit !== 'lovelace');
|
|
247
|
-
//
|
|
193
|
+
// set to true by indexAddress() once transactions are indexed
|
|
248
194
|
const hasTransactions = false;
|
|
249
195
|
return {
|
|
250
196
|
address,
|
|
@@ -260,19 +206,9 @@ function mapAddress(address, addressData, maxAge) {
|
|
|
260
206
|
hasTransactions: hasTransactions,
|
|
261
207
|
};
|
|
262
208
|
}
|
|
263
|
-
/**
|
|
264
|
-
* Map Address Transactions
|
|
265
|
-
* Converts provider address transaction data into AddressTransactionRow format
|
|
266
|
-
* @param addr address string
|
|
267
|
-
* @param addressTxsData address transactions data from provider
|
|
268
|
-
* @returns {AddressTransactionRow[]} mapped address transaction rows
|
|
269
|
-
* */
|
|
270
|
-
// AddressTransactions is keyed by (address, tx) and the per-tx net amounts are
|
|
271
|
-
// immutable once confirmed — no temporal validity. The entity has no
|
|
272
|
-
// validFrom/validTo columns, so the previous TTL plumbing was silently dropped.
|
|
209
|
+
/** Provider transactions to AddressTransactionRows with the address's net amounts; non-temporal. */
|
|
273
210
|
function mapAddressTransactions(addr, addressTxsData) {
|
|
274
211
|
return addressTxsData.map((tx) => {
|
|
275
|
-
// Calculate net amounts for this address in this transaction
|
|
276
212
|
const { netLovelace, netAssets } = calculateNetAmounts(addr, tx);
|
|
277
213
|
return {
|
|
278
214
|
address_address: addr,
|
|
@@ -284,17 +220,11 @@ function mapAddressTransactions(addr, addressTxsData) {
|
|
|
284
220
|
};
|
|
285
221
|
});
|
|
286
222
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Calculate net lovelace and asset changes for an address in a transaction
|
|
289
|
-
* @param addr the address to calculate for
|
|
290
|
-
* @param tx the transaction data
|
|
291
|
-
* @returns object with netLovelace and netAssets array
|
|
292
|
-
*/
|
|
223
|
+
/** Net lovelace and asset changes of an address in a transaction (outputs minus inputs). */
|
|
293
224
|
function calculateNetAmounts(addr, tx) {
|
|
294
225
|
let inputLovelace = 0n;
|
|
295
226
|
let outputLovelace = 0n;
|
|
296
227
|
const assetBalances = new Map(); // unit -> net quantity
|
|
297
|
-
// Process inputs belonging to this address (subtract)
|
|
298
228
|
for (const input of tx.inputs ?? []) {
|
|
299
229
|
if (input.address === addr) {
|
|
300
230
|
for (const amount of input.amount ?? []) {
|
|
@@ -302,14 +232,12 @@ function calculateNetAmounts(addr, tx) {
|
|
|
302
232
|
inputLovelace += BigInt(amount.quantity || '0');
|
|
303
233
|
}
|
|
304
234
|
else {
|
|
305
|
-
// Native asset
|
|
306
235
|
const current = assetBalances.get(amount.unit) || 0n;
|
|
307
236
|
assetBalances.set(amount.unit, current - BigInt(amount.quantity || '0'));
|
|
308
237
|
}
|
|
309
238
|
}
|
|
310
239
|
}
|
|
311
240
|
}
|
|
312
|
-
// Process outputs going to this address (add)
|
|
313
241
|
for (const output of tx.outputs ?? []) {
|
|
314
242
|
if (output.address === addr) {
|
|
315
243
|
for (const amount of output.amount ?? []) {
|
|
@@ -317,19 +245,16 @@ function calculateNetAmounts(addr, tx) {
|
|
|
317
245
|
outputLovelace += BigInt(amount.quantity || '0');
|
|
318
246
|
}
|
|
319
247
|
else {
|
|
320
|
-
// Native asset
|
|
321
248
|
const current = assetBalances.get(amount.unit) || 0n;
|
|
322
249
|
assetBalances.set(amount.unit, current + BigInt(amount.quantity || '0'));
|
|
323
250
|
}
|
|
324
251
|
}
|
|
325
252
|
}
|
|
326
253
|
}
|
|
327
|
-
//
|
|
254
|
+
// zero balances are dropped
|
|
328
255
|
const netAssets = [];
|
|
329
256
|
for (const [unit, quantity] of assetBalances) {
|
|
330
257
|
if (quantity !== 0n) {
|
|
331
|
-
// Parse unit into policyId and assetName
|
|
332
|
-
// Format: policyId (56 chars) + assetNameHex
|
|
333
258
|
const policyId = unit.substring(0, 56);
|
|
334
259
|
const assetNameHex = unit.substring(56);
|
|
335
260
|
const assetName = hexToUtf8(assetNameHex);
|
|
@@ -347,14 +272,7 @@ function calculateNetAmounts(addr, tx) {
|
|
|
347
272
|
netAssets
|
|
348
273
|
};
|
|
349
274
|
}
|
|
350
|
-
/**
|
|
351
|
-
* Map Address UTxOs
|
|
352
|
-
* @param addr address string
|
|
353
|
-
* @param validFrom validFrom
|
|
354
|
-
* @param validTo validTo
|
|
355
|
-
* @param addressUtxosData address UTxOs data from provider
|
|
356
|
-
* @returns {AddressUTxORow[]} mapped address UTxO rows
|
|
357
|
-
*/
|
|
275
|
+
/** Provider UTxOs to temporal AddressUTxORows. */
|
|
358
276
|
function mapAddressUtxos(addr, validFrom, validTo, addressUtxosData) {
|
|
359
277
|
return addressUtxosData.map((utxo) => {
|
|
360
278
|
const amounts = Array.isArray(utxo.amount) ? utxo.amount : [];
|
|
@@ -367,10 +285,8 @@ function mapAddressUtxos(addr, validFrom, validTo, addressUtxosData) {
|
|
|
367
285
|
blockHash: utxo.blockHash,
|
|
368
286
|
utxodata_dataHash: utxo.datumHash,
|
|
369
287
|
utxodata_inlineDatum: utxo.inlineDatum || null,
|
|
370
|
-
//
|
|
371
|
-
//
|
|
372
|
-
// script CBOR (used by the tx-builder, but it would truncate this hash
|
|
373
|
-
// column) — only persist hash-length values here.
|
|
288
|
+
// Hash column: Blockfrost/Ogmios give a 56-hex hash, Koios the full script CBOR, so only
|
|
289
|
+
// hash-length values are persisted
|
|
374
290
|
utxodata_referenceScriptHash: utxo.scriptRef && utxo.scriptRef.length <= 64 ? utxo.scriptRef : null,
|
|
375
291
|
lovelace: lovelace,
|
|
376
292
|
validFrom: validFrom,
|
|
@@ -379,15 +295,7 @@ function mapAddressUtxos(addr, validFrom, validTo, addressUtxosData) {
|
|
|
379
295
|
};
|
|
380
296
|
});
|
|
381
297
|
}
|
|
382
|
-
/**
|
|
383
|
-
* Map Address Assets
|
|
384
|
-
* Converts provider address asset data into AddressAssetRow format
|
|
385
|
-
* @param addr address string
|
|
386
|
-
* @param validFrom validFrom
|
|
387
|
-
* @param validTo validTo
|
|
388
|
-
* @param AssetAssets address assets from provider
|
|
389
|
-
* @returns {AddressAssetRow[]} mapped address asset rows
|
|
390
|
-
*/
|
|
298
|
+
/** Provider address amounts (without lovelace) to temporal AddressAssetRows. */
|
|
391
299
|
function mapAddressAssets(addr, validFrom, validTo, AssetAssets) {
|
|
392
300
|
return AssetAssets
|
|
393
301
|
.filter((asset) => asset.unit !== 'lovelace')
|
|
@@ -404,14 +312,7 @@ function mapAddressAssets(addr, validFrom, validTo, AssetAssets) {
|
|
|
404
312
|
};
|
|
405
313
|
});
|
|
406
314
|
}
|
|
407
|
-
/**
|
|
408
|
-
* Map UTxO Assets
|
|
409
|
-
* Converts provider address UTxO asset data into UTxOAssetRow format
|
|
410
|
-
* @param addressUtxosData address UTxOs data from provider
|
|
411
|
-
* @param validFrom validFrom
|
|
412
|
-
* @param validTo validTo
|
|
413
|
-
* @returns {UTxOAssetRow[]} mapped UTxO asset rows
|
|
414
|
-
*/
|
|
315
|
+
/** Native assets of provider UTxOs to temporal UTxOAssetRows. */
|
|
415
316
|
function mapAddressUtxoAssets(addressUtxosData, validFrom, validTo) {
|
|
416
317
|
const assets = [];
|
|
417
318
|
addressUtxosData.forEach((utxo) => {
|
|
@@ -435,12 +336,7 @@ function mapAddressUtxoAssets(addressUtxosData, validFrom, validTo) {
|
|
|
435
336
|
});
|
|
436
337
|
return assets;
|
|
437
338
|
}
|
|
438
|
-
/**
|
|
439
|
-
* Map Network Information
|
|
440
|
-
* Converts provider network information data into NetworkInfoRow format
|
|
441
|
-
* @param providerNetworkData
|
|
442
|
-
* @returns {NetworkInfoRow} mapped network information row
|
|
443
|
-
*/
|
|
339
|
+
/** Provider network information to a temporal NetworkInfoRow. */
|
|
444
340
|
function mapNetworkInfo(providerNetworkData, max_age, network) {
|
|
445
341
|
const now = Date.now();
|
|
446
342
|
const nowIso = new Date(now).toISOString();
|
|
@@ -459,23 +355,16 @@ function mapNetworkInfo(providerNetworkData, max_age, network) {
|
|
|
459
355
|
activeStake: providerNetworkData.stake.active,
|
|
460
356
|
};
|
|
461
357
|
}
|
|
462
|
-
/**
|
|
463
|
-
* Map Block Data
|
|
464
|
-
* Converts provider block data into BlockRow format
|
|
465
|
-
* @param providerBlockData block data from provider
|
|
466
|
-
* @param epochData epoch data for the block's epoch
|
|
467
|
-
* @returns {BlockRow} mapped block row
|
|
468
|
-
*/
|
|
358
|
+
/** Provider block to BlockRow. */
|
|
469
359
|
function mapBlock(providerBlockData, epochData) {
|
|
470
360
|
return {
|
|
471
361
|
time: new Date(providerBlockData.time * 1000).toISOString(),
|
|
472
362
|
height: providerBlockData.height,
|
|
473
363
|
hash: providerBlockData.hash,
|
|
474
|
-
// was `String(x ?? null)` → persisted the literal string "null" when absent
|
|
475
364
|
slotLeader: providerBlockData.slotLeader ?? null,
|
|
476
365
|
epochNumber: epochData?.epoch ?? providerBlockData.epoch,
|
|
477
366
|
epoch: epochData,
|
|
478
|
-
// absolute slot
|
|
367
|
+
// absolute slot: the crawler's reorg cut axis (same as Transactions.slot)
|
|
479
368
|
slot: providerBlockData.slot ?? null,
|
|
480
369
|
epochSlot: providerBlockData.epochSlot,
|
|
481
370
|
size: providerBlockData.size,
|
|
@@ -483,12 +372,7 @@ function mapBlock(providerBlockData, epochData) {
|
|
|
483
372
|
fees: providerBlockData.fees ?? '0',
|
|
484
373
|
};
|
|
485
374
|
}
|
|
486
|
-
/**
|
|
487
|
-
* Map Epoch Data
|
|
488
|
-
* Converts provider epoch data into EpochRow format
|
|
489
|
-
* @param providerEpochData epoch data from provider
|
|
490
|
-
* @returns {EpochRow} mapped epoch row
|
|
491
|
-
*/
|
|
375
|
+
/** Provider epoch to EpochRow. */
|
|
492
376
|
function mapEpoch(providerEpochData) {
|
|
493
377
|
return {
|
|
494
378
|
epoch: providerEpochData.epoch,
|
|
@@ -503,46 +387,31 @@ function mapEpoch(providerEpochData) {
|
|
|
503
387
|
activeStake: providerEpochData.active_stake,
|
|
504
388
|
};
|
|
505
389
|
}
|
|
506
|
-
/**
|
|
507
|
-
* Map Transaction Metadata
|
|
508
|
-
* Converts provider transaction metadata labels into TransactionMetadataRow format
|
|
509
|
-
* @param providerLabels array of metadata label data from provider
|
|
510
|
-
* @returns {TransactionMetadataRow[]} mapped transaction metadata rows
|
|
511
|
-
*/
|
|
390
|
+
/** Provider metadata labels to TransactionMetadataRows; non-uint64 labels are skipped. */
|
|
512
391
|
function mapTransactionMetadata(providerLabels) {
|
|
513
392
|
const rows = [];
|
|
514
393
|
for (const lbl of providerLabels) {
|
|
515
394
|
const id = metadataIdFor(lbl.label);
|
|
516
395
|
if (id === null) {
|
|
517
|
-
//
|
|
518
|
-
// for type bigint") and, in the crawler, count towards the poison-block latch.
|
|
396
|
+
// a NaN key would fail the whole bulk write on PostgreSQL
|
|
519
397
|
logger.warn(`Metadata label ${JSON.stringify(lbl.label)} of tx ${lbl.txHash} is not a uint64 — row skipped`);
|
|
520
398
|
continue;
|
|
521
399
|
}
|
|
522
400
|
rows.push({
|
|
523
|
-
//
|
|
401
|
+
// exact int64 key (see metadataIdFor); `label` keeps the original string
|
|
524
402
|
id: id,
|
|
525
403
|
tx_hash: lbl.txHash,
|
|
526
404
|
label: lbl.label.toString(),
|
|
527
|
-
// Ogmios
|
|
528
|
-
// Its matching serializer writes those values as exact JSON number tokens;
|
|
529
|
-
// native JSON.stringify would throw, while Number coercion would truncate.
|
|
405
|
+
// Ogmios exposes numeric metadata as bigint; safeJSON writes exact number tokens
|
|
530
406
|
payload: lbl.json !== undefined ? client_1.safeJSON.stringify(lbl.json) : null,
|
|
531
407
|
});
|
|
532
408
|
}
|
|
533
409
|
return rows;
|
|
534
410
|
}
|
|
535
411
|
/**
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
* which PostgreSQL rejected as "out of range for type bigint" and halted the
|
|
540
|
-
* crawler. Beyond 2^53 the value is passed as a decimal string so that no
|
|
541
|
-
* precision is lost on the way to the database (CAP accepts strings for
|
|
542
|
-
* Integer64); `label` always keeps the original text.
|
|
543
|
-
*
|
|
544
|
-
* @returns the int64 key, or null when the label is not a non-negative integer
|
|
545
|
-
* (the caller skips the row — a NaN key would fail the whole bulk write)
|
|
412
|
+
* uint64 metadata label to the int64 `TransactionMetadata.id` key: labels >= 2^63 wrap via two's complement,
|
|
413
|
+
* values beyond 2^53 are passed as a decimal string (CAP accepts strings for Integer64).
|
|
414
|
+
* @returns the key, or null when the label is not a non-negative integer
|
|
546
415
|
*/
|
|
547
416
|
function metadataIdFor(label) {
|
|
548
417
|
let big;
|
|
@@ -561,15 +430,7 @@ function metadataIdFor(label) {
|
|
|
561
430
|
const safe = wrapped >= BigInt(Number.MIN_SAFE_INTEGER) && wrapped <= BigInt(Number.MAX_SAFE_INTEGER);
|
|
562
431
|
return safe ? Number(wrapped) : wrapped.toString();
|
|
563
432
|
}
|
|
564
|
-
/**
|
|
565
|
-
* Map a pool observation at an epoch boundary into a snapshot row. Unlike mapPool() this
|
|
566
|
-
* carries no temporal validity: the row is dated by (epoch, snapshotSlot) and stays valid
|
|
567
|
-
* forever, because it states what was true then, not what is cached now.
|
|
568
|
-
* @param providerPoolData pool data from provider
|
|
569
|
-
* @param epoch epoch the snapshot belongs to
|
|
570
|
-
* @param at slot and block time of the block that triggered the snapshot
|
|
571
|
-
* @returns {PoolEpochSnapshotRow} mapped snapshot row
|
|
572
|
-
*/
|
|
433
|
+
/** Pool observation at an epoch boundary to a non-temporal PoolEpochSnapshotRow dated by (epoch, snapshotSlot). */
|
|
573
434
|
function mapPoolSnapshot(providerPoolData, epoch, at) {
|
|
574
435
|
return {
|
|
575
436
|
poolId: providerPoolData.poolId,
|
|
@@ -589,14 +450,7 @@ function mapPoolSnapshot(providerPoolData, epoch, at) {
|
|
|
589
450
|
fixedCost: providerPoolData.fixedCost,
|
|
590
451
|
};
|
|
591
452
|
}
|
|
592
|
-
/**
|
|
593
|
-
* Map a DRep observation at an epoch boundary into a snapshot row. Non-temporal, same
|
|
594
|
-
* reasoning as mapPoolSnapshot().
|
|
595
|
-
* @param providerDrepData drep data from provider
|
|
596
|
-
* @param epoch epoch the snapshot belongs to
|
|
597
|
-
* @param at slot and block time of the block that triggered the snapshot
|
|
598
|
-
* @returns {DrepEpochSnapshotRow} mapped snapshot row
|
|
599
|
-
*/
|
|
453
|
+
/** DRep observation at an epoch boundary to a non-temporal DrepEpochSnapshotRow. */
|
|
600
454
|
function mapDrepSnapshot(providerDrepData, epoch, at) {
|
|
601
455
|
return {
|
|
602
456
|
drepId: providerDrepData.drepId,
|
|
@@ -610,17 +464,9 @@ function mapDrepSnapshot(providerDrepData, epoch, at) {
|
|
|
610
464
|
expired: providerDrepData.expired,
|
|
611
465
|
};
|
|
612
466
|
}
|
|
613
|
-
/**
|
|
614
|
-
* Map Pool Data
|
|
615
|
-
* Converts provider pool data into PoolRow format
|
|
616
|
-
* @param providerPoolData pool data from provider
|
|
617
|
-
* @returns {PoolRow} mapped pool row
|
|
618
|
-
*/
|
|
467
|
+
/** Provider pool to a temporal PoolRow valid for `max_age` ms. */
|
|
619
468
|
function mapPool(providerPoolData, max_age) {
|
|
620
|
-
//
|
|
621
|
-
// epoch, so a slice expires after max_age and the index-on-miss read re-fetches.
|
|
622
|
-
// Read the clock ONCE — separate Date.now() calls for validFrom/validTo let the
|
|
623
|
-
// millisecond tick over between them, making the span max_age+1.
|
|
469
|
+
// one clock read, so validTo - validFrom is exactly max_age
|
|
624
470
|
const now = Date.now();
|
|
625
471
|
const validFrom = new Date(now).toISOString();
|
|
626
472
|
const validTo = new Date(now + max_age).toISOString();
|
|
@@ -643,17 +489,9 @@ function mapPool(providerPoolData, max_age) {
|
|
|
643
489
|
validTo,
|
|
644
490
|
};
|
|
645
491
|
}
|
|
646
|
-
/**
|
|
647
|
-
* Map Asset Info Data
|
|
648
|
-
* Converts provider asset info into AssetRow format. Provider data is already
|
|
649
|
-
* normalized by the backend mapper into the canonical AssetInfo shape, so this
|
|
650
|
-
* function just stamps temporal validity and JSON-stringifies the on-chain metadata.
|
|
651
|
-
* @param providerAssetInfo canonical asset info from backend
|
|
652
|
-
* @param max_age TTL window in ms for the temporal validity
|
|
653
|
-
* @returns {AssetRow} mapped asset row
|
|
654
|
-
*/
|
|
492
|
+
/** Canonical asset info to a temporal AssetRow valid for `max_age` ms; on-chain metadata is JSON-stringified. */
|
|
655
493
|
function mapAsset(providerAssetInfo, max_age) {
|
|
656
|
-
//
|
|
494
|
+
// one clock read (see mapPool)
|
|
657
495
|
const now = Date.now();
|
|
658
496
|
const validFrom = new Date(now).toISOString();
|
|
659
497
|
const validTo = new Date(now + max_age).toISOString();
|
|
@@ -681,36 +519,18 @@ function mapAsset(providerAssetInfo, max_age) {
|
|
|
681
519
|
};
|
|
682
520
|
}
|
|
683
521
|
/**
|
|
684
|
-
* Fixed validity stamp for a crawler-written bare `Assets` row
|
|
685
|
-
*
|
|
686
|
-
* collide with a real, wall-clock-stamped slice from mapAsset().
|
|
522
|
+
* Fixed validity stamp for a crawler-written bare `Assets` row: epoch zero, so the row is born expired
|
|
523
|
+
* (hidden by CAP's temporal filter) and its `(validFrom, unit)` key never collides with a mapAsset() slice.
|
|
687
524
|
*/
|
|
688
525
|
exports.BARE_ASSET_STAMP = '1970-01-01T00:00:00.000Z';
|
|
689
526
|
/**
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
* The row is stamped as ALREADY EXPIRED (`validTo === validFrom`). That is deliberate: CAP's
|
|
696
|
-
* temporal filter hides it from OData reads, so the first keyed read still counts as a miss
|
|
697
|
-
* and the existing lazy path enriches it through indexAsset() with supply and registry data —
|
|
698
|
-
* while an analytics consumer reading the database directly already sees the full catalogue
|
|
699
|
-
* (and can exclude the placeholders with `validTo > validFrom`).
|
|
700
|
-
*
|
|
701
|
-
* Both stamps are the FIXED epoch sentinel, not `now`. `Assets` is temporal, so its primary
|
|
702
|
-
* key is `(validFrom, unit)`: a wall-clock stamp would make the same unit a new row on every
|
|
703
|
-
* sighting and could collide with a slice the lazy path writes in the same millisecond, which
|
|
704
|
-
* inside the crawler's block transaction means a failed block. With the sentinel the bare row
|
|
705
|
-
* is one fixed, idempotent row per unit that no `mapAsset()` slice can ever alias.
|
|
706
|
-
*
|
|
707
|
-
* @param unit asset unit (policyId + assetNameHex)
|
|
708
|
-
* @returns {AssetRow | null} bare row, or null when the unit is not a native asset unit
|
|
527
|
+
* Bare AssetRow from the unit alone (policyId, assetNameHex, decoded name, CIP-14 fingerprint), no provider call.
|
|
528
|
+
* Stamped `validTo === validFrom` with the fixed sentinel: hidden from OData reads, so the first keyed read
|
|
529
|
+
* still misses and the lazy path enriches it; one idempotent row per unit inside the crawler's block tx.
|
|
530
|
+
* @returns the row, or null when the unit is not a native asset unit
|
|
709
531
|
*/
|
|
710
532
|
function mapBareAsset(unit) {
|
|
711
|
-
//
|
|
712
|
-
// Reusing it keeps the catalogue from inventing a second, looser notion of "asset unit"
|
|
713
|
-
// than isAssetUnit() enforces on the API surface.
|
|
533
|
+
// same unit definition isAssetUnit() enforces on the API
|
|
714
534
|
if (!const_1.ASSET_UNIT_REGEX.test(unit))
|
|
715
535
|
return null;
|
|
716
536
|
const policyId = unit.slice(0, 56);
|
|
@@ -719,7 +539,7 @@ function mapBareAsset(unit) {
|
|
|
719
539
|
unit,
|
|
720
540
|
policyId,
|
|
721
541
|
assetNameHex,
|
|
722
|
-
//
|
|
542
|
+
// hex fallback for non-text and NUL-bearing names
|
|
723
543
|
assetName: assetNameHex.length > 0 ? decodeAssetName(assetNameHex) : '',
|
|
724
544
|
fingerprint: computeCip14Fingerprint(policyId, assetNameHex),
|
|
725
545
|
totalSupply: null,
|
|
@@ -737,12 +557,7 @@ function mapBareAsset(unit) {
|
|
|
737
557
|
validTo: exports.BARE_ASSET_STAMP,
|
|
738
558
|
};
|
|
739
559
|
}
|
|
740
|
-
/**
|
|
741
|
-
* Map Asset History entries to row format. No temporal stamping — mint/burn
|
|
742
|
-
* events are immutable; UPSERT keyed on (unit, txHash) is idempotent.
|
|
743
|
-
* @param entries asset history events from backend (already canonical)
|
|
744
|
-
* @returns {AssetHistoryRow[]} mapped rows
|
|
745
|
-
*/
|
|
560
|
+
/** Asset history events to non-temporal AssetHistoryRows (immutable, keyed on unit + txHash). */
|
|
746
561
|
function mapAssetHistory(entries) {
|
|
747
562
|
return entries.map((e) => ({
|
|
748
563
|
unit: e.unit,
|
|
@@ -753,16 +568,9 @@ function mapAssetHistory(entries) {
|
|
|
753
568
|
blockHeight: e.blockHeight,
|
|
754
569
|
}));
|
|
755
570
|
}
|
|
756
|
-
/**
|
|
757
|
-
* Map Drep Data
|
|
758
|
-
* Converts provider drep data into DrepRow format
|
|
759
|
-
* @param providerDrepData drep data from provider
|
|
760
|
-
* @returns {DrepRow} mapped drep row
|
|
761
|
-
*/
|
|
571
|
+
/** Provider DRep to a temporal DrepRow valid for `max_age` ms. */
|
|
762
572
|
function mapDrep(providerDrepData, max_age) {
|
|
763
|
-
//
|
|
764
|
-
// after max_age so the index-on-miss read re-fetches fresh state.
|
|
765
|
-
// Read the clock once so the span is exactly max_age (see mapPool).
|
|
573
|
+
// one clock read (see mapPool)
|
|
766
574
|
const now = Date.now();
|
|
767
575
|
const validFrom = new Date(now).toISOString();
|
|
768
576
|
const validTo = new Date(now + max_age).toISOString();
|
|
@@ -778,14 +586,9 @@ function mapDrep(providerDrepData, max_age) {
|
|
|
778
586
|
validTo,
|
|
779
587
|
};
|
|
780
588
|
}
|
|
781
|
-
/**
|
|
782
|
-
* Map Account Data
|
|
783
|
-
* Converts provider account data into AccountRow format
|
|
784
|
-
* @param providerAccountData account data from provider
|
|
785
|
-
* @returns {AccountRow} mapped account row
|
|
786
|
-
*/
|
|
589
|
+
/** Provider account to a temporal AccountRow valid for `max_age` ms. */
|
|
787
590
|
function mapAccount(providerAccountData, max_age) {
|
|
788
|
-
//
|
|
591
|
+
// one clock read (see mapPool)
|
|
789
592
|
const now = Date.now();
|
|
790
593
|
const validFrom = new Date(now).toISOString();
|
|
791
594
|
const validTo = new Date(now + max_age).toISOString();
|
|
@@ -804,32 +607,19 @@ function mapAccount(providerAccountData, max_age) {
|
|
|
804
607
|
hasAddresses: providerAccountData.addresses.length > 0,
|
|
805
608
|
};
|
|
806
609
|
}
|
|
807
|
-
/**
|
|
808
|
-
* Map Backend Error
|
|
809
|
-
* Converts BackendError or unknown error into OData request rejection
|
|
810
|
-
* @param req OData request
|
|
811
|
-
* @param err error object (BackendError or unknown)
|
|
812
|
-
* @param ctx context string for error message
|
|
813
|
-
*/
|
|
610
|
+
/** Rejects the OData request for a BackendError; unknown errors are logged and answered as a sanitized 500. */
|
|
814
611
|
function mapError(req, err, ctx) {
|
|
815
612
|
if (err instanceof errors_1.BackendError) {
|
|
816
613
|
return req.reject(err.statusCode, fmt(err.code, ctx, err.message), err.target);
|
|
817
614
|
}
|
|
818
|
-
// Handle non-BackendError (plain Error, string, etc.)
|
|
819
|
-
// Log full error server-side, but return sanitized message to client
|
|
820
615
|
const internalMsg = err instanceof Error ? err.message : String(err);
|
|
821
616
|
logger.error({ error: internalMsg }, `Unexpected error in ${ctx}`);
|
|
822
617
|
return req.reject(500, fmt('INTERNAL_ERROR', ctx, 'An internal error occurred'));
|
|
823
618
|
}
|
|
824
|
-
/**
|
|
825
|
-
* Map Transaction Build Result
|
|
826
|
-
* Converts provider transaction build result into TransactionBuildRow format
|
|
827
|
-
* @param txbuildResult transaction build result from provider
|
|
828
|
-
* @returns {TransactionBuildRow} mapped transaction build row
|
|
829
|
-
*/
|
|
619
|
+
/** Build result to a temporal TransactionBuildRow with a fresh build id. */
|
|
830
620
|
function mapBuildResult(txbuildResult, max_age) {
|
|
831
621
|
const buildId = cds_1.default.utils.uuid();
|
|
832
|
-
//
|
|
622
|
+
// one clock read (see mapPool)
|
|
833
623
|
const nowMs = Date.now();
|
|
834
624
|
const now = Math.floor(nowMs / 1000);
|
|
835
625
|
const validFrom = new Date(nowMs).toISOString();
|
|
@@ -847,25 +637,19 @@ function mapBuildResult(txbuildResult, max_age) {
|
|
|
847
637
|
unsignedTxCbor: txbuildResult.unsignedTxCbor,
|
|
848
638
|
txBodyHash: txbuildResult.txBodyHash,
|
|
849
639
|
fee: txbuildResult.feeLovelace,
|
|
850
|
-
size: txbuildResult.sizeBytes, //
|
|
640
|
+
size: txbuildResult.sizeBytes, // bytes
|
|
851
641
|
createdAt: now, // epoch seconds
|
|
852
642
|
submission: null,
|
|
853
|
-
hasInputs: hasInputs,
|
|
854
|
-
hasOutputs: hasOutputs,
|
|
855
|
-
wasSubmitted: false,
|
|
643
|
+
hasInputs: hasInputs,
|
|
644
|
+
hasOutputs: hasOutputs,
|
|
645
|
+
wasSubmitted: false,
|
|
856
646
|
scriptHash: txbuildResult.scriptHash ?? null,
|
|
857
647
|
mintScriptHash: txbuildResult.mintScriptHash ?? null,
|
|
858
648
|
forcedInputsUsed: txbuildResult.forcedInputsUsed ?? 0,
|
|
859
649
|
referenceInputsUsed: txbuildResult.referenceInputsUsed ?? 0,
|
|
860
650
|
};
|
|
861
651
|
}
|
|
862
|
-
/**
|
|
863
|
-
* Map Transaction Build Inputs
|
|
864
|
-
* Converts transaction build result inputs into TransactionBuildInputRow format
|
|
865
|
-
* @param buildId the transaction build ID
|
|
866
|
-
* @param inputs transaction build result inputs
|
|
867
|
-
* @returns {TransactionBuildInputRow[]} mapped transaction build input rows
|
|
868
|
-
*/
|
|
652
|
+
/** Build result inputs to TransactionBuildInputRows. */
|
|
869
653
|
function mapBuildInputs(buildId, inputs) {
|
|
870
654
|
return inputs.map((input, idx) => ({
|
|
871
655
|
build_id: buildId,
|
|
@@ -877,14 +661,7 @@ function mapBuildInputs(buildId, inputs) {
|
|
|
877
661
|
hasAssets: false, // simple ADA transfers don't have assets
|
|
878
662
|
}));
|
|
879
663
|
}
|
|
880
|
-
/**
|
|
881
|
-
* Map Transaction Build Outputs
|
|
882
|
-
* Converts transaction build result outputs into TransactionBuildOutputRow format
|
|
883
|
-
* @param buildId the transaction build ID
|
|
884
|
-
* @param outputs transaction build result outputs
|
|
885
|
-
* @param changeAddress the change address to identify change outputs
|
|
886
|
-
* @returns {TransactionBuildOutputRow[]} mapped transaction build output rows
|
|
887
|
-
*/
|
|
664
|
+
/** Build result outputs to TransactionBuildOutputRows; `changeAddress` marks the change output. */
|
|
888
665
|
function mapBuildOutputs(buildId, outputs, changeAddress) {
|
|
889
666
|
return outputs.map((output, idx) => ({
|
|
890
667
|
build_id: buildId,
|
|
@@ -895,12 +672,7 @@ function mapBuildOutputs(buildId, outputs, changeAddress) {
|
|
|
895
672
|
hasAssets: false, // simple ADA transfers don't have assets
|
|
896
673
|
}));
|
|
897
674
|
}
|
|
898
|
-
/**
|
|
899
|
-
* Map Protocol Parameters
|
|
900
|
-
* Converts provider protocol parameters into ProtocolParameterRow format
|
|
901
|
-
* @param providerParams protocol parameters from provider
|
|
902
|
-
* @returns {ProtocolParameterRow} mapped protocol parameter row
|
|
903
|
-
*/
|
|
675
|
+
/** Provider protocol parameters to ProtocolParameterRow. */
|
|
904
676
|
function mapProtocolParameters(providerParams) {
|
|
905
677
|
return {
|
|
906
678
|
network: providerParams.network,
|
|
@@ -939,13 +711,7 @@ function mapProtocolParameters(providerParams) {
|
|
|
939
711
|
source: providerParams.source,
|
|
940
712
|
};
|
|
941
713
|
}
|
|
942
|
-
/**
|
|
943
|
-
* Map Transaction Submission
|
|
944
|
-
* Converts signed transaction CBOR and hash into TransactionSubmissionRow format
|
|
945
|
-
* @param signedTxCbor signed transaction in CBOR hex format
|
|
946
|
-
* @param txHash transaction hash
|
|
947
|
-
* @returns {TransactionSubmissionRow} mapped transaction submission row
|
|
948
|
-
*/
|
|
714
|
+
/** Signed tx CBOR and hash to a TransactionSubmissionRow stamped now (epoch seconds). */
|
|
949
715
|
function mapTransactionSubmission(signedTxCbor, txHash) {
|
|
950
716
|
const now = Math.floor(Date.now() / 1000);
|
|
951
717
|
return {
|
|
@@ -954,26 +720,14 @@ function mapTransactionSubmission(signedTxCbor, txHash) {
|
|
|
954
720
|
submittedAt: now,
|
|
955
721
|
};
|
|
956
722
|
}
|
|
957
|
-
/**
|
|
958
|
-
* Map Address Signing Requests
|
|
959
|
-
* Creates AddressSigningRequest row for address-signing request association
|
|
960
|
-
* @param addr bech32 address
|
|
961
|
-
* @param signingRequestId signing request UUID
|
|
962
|
-
* @returns {AddressSigningRequestRow} mapped address signing request row
|
|
963
|
-
*/
|
|
723
|
+
/** Address to signing-request association row. */
|
|
964
724
|
function mapAddressSigningRequest(addr, signingRequestId) {
|
|
965
725
|
return {
|
|
966
726
|
address_address: addr,
|
|
967
727
|
signingRequest_id: signingRequestId,
|
|
968
728
|
};
|
|
969
729
|
}
|
|
970
|
-
/**
|
|
971
|
-
* Map Address Transaction Builds
|
|
972
|
-
* Creates AddressTransactionBuild row for address-build association
|
|
973
|
-
* @param addr bech32 address
|
|
974
|
-
* @param buildId transaction build UUID
|
|
975
|
-
* @returns {AddressTransactionBuildRow} mapped address transaction build row
|
|
976
|
-
*/
|
|
730
|
+
/** Address to transaction-build association row. */
|
|
977
731
|
function mapAddressTransactionBuild(addr, buildId) {
|
|
978
732
|
return {
|
|
979
733
|
address_address: addr,
|
|
@@ -984,19 +738,8 @@ function mapAddressTransactionBuild(addr, buildId) {
|
|
|
984
738
|
// Helper Functions
|
|
985
739
|
//-----------------------------------------------------------------------
|
|
986
740
|
/**
|
|
987
|
-
*
|
|
988
|
-
*
|
|
989
|
-
* Blockfrost's cost_models (named keys) has known key-value mapping bugs for
|
|
990
|
-
* PlutusV3 (shifted values in the quotientInteger/remainderInteger region).
|
|
991
|
-
* The Blockfrost backend now prefers cost_models_raw (canonical arrays from the
|
|
992
|
-
* node) which bypasses this issue entirely.
|
|
993
|
-
*
|
|
994
|
-
* For V3 arrays: already in canonical order, just pad to 297 via toCostModelArrV3.
|
|
995
|
-
* For V3 objects (Ogmios named format): toCostModelArrV3(obj) maps via canonical keys.
|
|
996
|
-
* For V1/V2: alphabetical order IS the canonical order (no reordering needed).
|
|
997
|
-
*
|
|
998
|
-
* @param raw - Raw cost models from any backend (Blockfrost, Ogmios, Koios)
|
|
999
|
-
* @returns Object with all cost model values as number arrays in canonical order
|
|
741
|
+
* Cost models to number arrays in canonical Plutus parameter order. V3 goes through toCostModelArrV3
|
|
742
|
+
* (canonical keys, padded to 297); for V1/V2 alphabetical key order is the canonical order.
|
|
1000
743
|
*/
|
|
1001
744
|
function normalizeCostModels(raw) {
|
|
1002
745
|
const result = {};
|
|
@@ -1004,12 +747,10 @@ function normalizeCostModels(raw) {
|
|
|
1004
747
|
const isV3 = key === 'PlutusV3' || key === 'plutus:v3';
|
|
1005
748
|
if (Array.isArray(value)) {
|
|
1006
749
|
if (isV3) {
|
|
1007
|
-
//
|
|
1008
|
-
// toCostModelArrV3 pads to 297 (Chang 2) with defaults if the array is shorter.
|
|
750
|
+
// already canonical; toCostModelArrV3 pads short arrays to 297 with defaults
|
|
1009
751
|
result[key] = Array.from((0, cardano_costmodels_ts_1.toCostModelArrV3)(value)).map(Number);
|
|
1010
752
|
}
|
|
1011
753
|
else {
|
|
1012
|
-
// V1/V2: pass through (already in canonical order)
|
|
1013
754
|
result[key] = value;
|
|
1014
755
|
}
|
|
1015
756
|
}
|
|
@@ -1019,7 +760,6 @@ function normalizeCostModels(raw) {
|
|
|
1019
760
|
result[key] = Array.from((0, cardano_costmodels_ts_1.toCostModelArrV3)(obj)).map(Number);
|
|
1020
761
|
}
|
|
1021
762
|
else {
|
|
1022
|
-
// V1/V2: alphabetical sort IS correct for those versions
|
|
1023
763
|
result[key] = Object.keys(obj).sort()
|
|
1024
764
|
.map(k => obj[k]);
|
|
1025
765
|
}
|
|
@@ -1027,32 +767,15 @@ function normalizeCostModels(raw) {
|
|
|
1027
767
|
}
|
|
1028
768
|
return result;
|
|
1029
769
|
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Convert hex string to UTF-8 string, falling back to hex if conversion fails.
|
|
1032
|
-
* This helper reduces code duplication and improves performance by centralizing
|
|
1033
|
-
* the conversion logic.
|
|
1034
|
-
*
|
|
1035
|
-
* @param hex - Hexadecimal string to convert
|
|
1036
|
-
* @returns {string} UTF-8 string or original hex if conversion fails
|
|
1037
|
-
*/
|
|
770
|
+
/** Hex to UTF-8 display string, hex fallback (see decodeAssetName). */
|
|
1038
771
|
function hexToUtf8(hex) {
|
|
1039
772
|
return decodeAssetName(hex);
|
|
1040
773
|
}
|
|
1041
|
-
// ignoreBOM: a leading U+FEFF is part of the asset name's bytes and must survive the
|
|
1042
|
-
// round trip (Buffer.toString('utf8') kept it; TextDecoder's default drops it).
|
|
774
|
+
// ignoreBOM: a leading U+FEFF is part of the asset name's bytes and must survive the round trip
|
|
1043
775
|
const strictUtf8 = new node_util_1.TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
1044
776
|
/**
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
* Asset names are arbitrary bytes. When they are not valid UTF-8, or when they
|
|
1048
|
-
* contain U+0000, the hex form is returned unchanged: PostgreSQL rejects NUL in
|
|
1049
|
-
* `text` and in the JSON documents @cap-js/postgres uses for bulk INSERT/UPSERT
|
|
1050
|
-
* ("unsupported Unicode escape sequence"), which halted the crawler on preprod
|
|
1051
|
-
* block 4281919 (asset name ending in 0x00). SQLite accepted the same bytes
|
|
1052
|
-
* silently. `assetNameHex` always keeps the exact bytes, so nothing is lost.
|
|
1053
|
-
*
|
|
1054
|
-
* @param hex - asset name as hex string
|
|
1055
|
-
* @returns UTF-8 text, or the hex string when the bytes are not clean text
|
|
777
|
+
* Asset name (hex bytes) to its display string; the hex is returned unchanged for invalid UTF-8 or
|
|
778
|
+
* names containing U+0000 (PostgreSQL rejects NUL in `text`). `assetNameHex` always keeps the exact bytes.
|
|
1056
779
|
*/
|
|
1057
780
|
function decodeAssetName(hex) {
|
|
1058
781
|
if (!hex)
|
|
@@ -1066,12 +789,7 @@ function decodeAssetName(hex) {
|
|
|
1066
789
|
}
|
|
1067
790
|
return text.includes('\u0000') ? hex : text;
|
|
1068
791
|
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Parse asset unit (policyId + assetNameHex) into components.
|
|
1071
|
-
* Optimizes repeated parsing logic across multiple mapper functions.
|
|
1072
|
-
* @param unit - Asset unit string (56 char policyId + asset name hex)
|
|
1073
|
-
* @returns { policyId: string | null; assetName: string | null } Object with policyId and assetName
|
|
1074
|
-
*/
|
|
792
|
+
/** Split an asset unit into policyId and decoded assetName; `lovelace` and malformed units get a null policyId. */
|
|
1075
793
|
function parseAssetUnit(unit) {
|
|
1076
794
|
if (unit === 'lovelace') {
|
|
1077
795
|
return { policyId: null, assetName: 'lovelace' };
|
|
@@ -1084,13 +802,7 @@ function parseAssetUnit(unit) {
|
|
|
1084
802
|
const assetName = assetNameHex.length > 0 ? hexToUtf8(assetNameHex) : '';
|
|
1085
803
|
return { policyId, assetName };
|
|
1086
804
|
}
|
|
1087
|
-
/**
|
|
1088
|
-
* Compute CIP-14 asset fingerprint from policyId and assetName.
|
|
1089
|
-
* Algorithm: bech32_encode("asset", blake2b_160(policyId_bytes + assetName_bytes))
|
|
1090
|
-
* @param policyIdHex - Policy ID as hex string (56 chars / 28 bytes)
|
|
1091
|
-
* @param assetNameHex - Asset name as hex string (variable length)
|
|
1092
|
-
* @returns CIP-14 fingerprint string (e.g. "asset1...")
|
|
1093
|
-
*/
|
|
805
|
+
/** CIP-14 fingerprint: bech32("asset", blake2b_160(policyId_bytes + assetName_bytes)). */
|
|
1094
806
|
function computeCip14Fingerprint(policyIdHex, assetNameHex) {
|
|
1095
807
|
const input = Buffer.from(policyIdHex + assetNameHex, 'hex');
|
|
1096
808
|
const out = Buffer.alloc(20);
|
|
@@ -1098,11 +810,7 @@ function computeCip14Fingerprint(policyIdHex, assetNameHex) {
|
|
|
1098
810
|
const words = bech32_1.bech32.toWords(out);
|
|
1099
811
|
return bech32_1.bech32.encode('asset', words);
|
|
1100
812
|
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Derive an enterprise script address from a script hash and network.
|
|
1103
|
-
* Enterprise address = header_byte + 28-byte script hash, bech32-encoded.
|
|
1104
|
-
* Header: 0x71 (mainnet, type 7 network 1) or 0x70 (testnet, type 7 network 0).
|
|
1105
|
-
*/
|
|
813
|
+
/** Enterprise script address: header 0x71 (mainnet) / 0x70 (testnet) + 28-byte script hash, bech32. */
|
|
1106
814
|
function scriptHashToEnterpriseAddress(scriptHashHex, network) {
|
|
1107
815
|
const headerByte = network === 'mainnet' ? 0x71 : 0x70;
|
|
1108
816
|
const payload = Buffer.alloc(29);
|
|
@@ -1112,10 +820,7 @@ function scriptHashToEnterpriseAddress(scriptHashHex, network) {
|
|
|
1112
820
|
const hrp = network === 'mainnet' ? 'addr' : 'addr_test';
|
|
1113
821
|
return bech32_1.bech32.encode(hrp, words, 120);
|
|
1114
822
|
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Encode a stake credential as a bech32 reward account (stake address).
|
|
1117
|
-
* Header: type nibble 0xe (key) / 0xf (script), network nibble 1 (mainnet) / 0 (testnets).
|
|
1118
|
-
*/
|
|
823
|
+
/** Stake credential to bech32 reward account; header nibbles 0xe key / 0xf script, network 1 mainnet / 0 testnets. */
|
|
1119
824
|
function credentialToStakeAddress(credentialHex, isScript, network) {
|
|
1120
825
|
const header = (isScript ? 0xf0 : 0xe0) | (network === 'mainnet' ? 0x01 : 0x00);
|
|
1121
826
|
const payload = Buffer.alloc(29);
|
|
@@ -1125,9 +830,8 @@ function credentialToStakeAddress(credentialHex, isScript, network) {
|
|
|
1125
830
|
return bech32_1.bech32.encode(hrp, bech32_1.bech32.toWords(payload), 120);
|
|
1126
831
|
}
|
|
1127
832
|
/**
|
|
1128
|
-
* Decode the
|
|
1129
|
-
*
|
|
1130
|
-
* Byron (base58) and anything unparseable come back as `byron` / `unknown` with no stake.
|
|
833
|
+
* Decode the CIP-19 Shelley address header: type, script flag and, for base addresses, the embedded
|
|
834
|
+
* stake credential as a reward account. Byron (base58) and unparseable input yield `byron` / `unknown`.
|
|
1131
835
|
*/
|
|
1132
836
|
function decodeShelleyAddress(address) {
|
|
1133
837
|
const none = { type: 'unknown', isScript: false, stakeAddress: null, networkId: null };
|
|
@@ -1173,24 +877,14 @@ function decodeShelleyAddress(address) {
|
|
|
1173
877
|
return { ...none, networkId };
|
|
1174
878
|
}
|
|
1175
879
|
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Encode a DRep credential as a CIP-129 DRep ID (`drep1…`, 29 bytes).
|
|
1178
|
-
* Header byte: high nibble 0x2 = DRep, low nibble 0x2 = key hash / 0x3 = script hash —
|
|
1179
|
-
* the inverse of `decodeDrepId` in the Ogmios backend.
|
|
1180
|
-
*/
|
|
880
|
+
/** DRep credential to CIP-129 DRep ID (29 bytes): header 0x22 key hash / 0x23 script hash. */
|
|
1181
881
|
function credentialToDrepId(credentialHex, isScript) {
|
|
1182
882
|
const payload = Buffer.alloc(29);
|
|
1183
883
|
payload[0] = isScript ? 0x23 : 0x22;
|
|
1184
884
|
Buffer.from(credentialHex, 'hex').copy(payload, 1);
|
|
1185
885
|
return bech32_1.bech32.encode('drep', bech32_1.bech32.toWords(payload), 120);
|
|
1186
886
|
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Format error message
|
|
1189
|
-
* @param code error code
|
|
1190
|
-
* @param ctx context string
|
|
1191
|
-
* @param msg error message
|
|
1192
|
-
* @returns {string} formatted error message
|
|
1193
|
-
*/
|
|
887
|
+
/** `[code] ctx: msg` */
|
|
1194
888
|
function fmt(code, ctx, msg) {
|
|
1195
889
|
return `[${code}] ${ctx}: ${msg}`;
|
|
1196
890
|
}
|