@odatano/core 2.0.0-rc.41 → 2.0.0-rc.43
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 +47 -0
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/@cds-models/CardanoODataService/index.d.ts +44 -0
- package/@cds-models/CardanoODataService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +3 -0
- package/@cds-models/index.d.ts +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +33 -0
- package/@cds-models/odatano/cardano/index.js +3 -0
- package/README.md +195 -195
- package/db/schema.cds +27 -0
- package/db/types.cds +421 -409
- package/package.json +1 -1
- package/srv/blockchain/backends/blockfrost-backend.js +1 -0
- package/srv/blockchain/backends/koios-backend.js +19 -0
- package/srv/blockchain/backends/ogmios-backend.js +16 -12
- package/srv/blockchain/cardano-indexer.js +26 -9
- package/srv/blockchain/crawler/credential-backfill.d.ts +37 -0
- package/srv/blockchain/crawler/credential-backfill.js +124 -0
- package/srv/blockchain/crawler/transaction-backfill.d.ts +3 -2
- package/srv/blockchain/crawler/transaction-backfill.js +14 -4
- package/srv/blockchain/crawler/utxo-set-import.d.ts +20 -1
- package/srv/blockchain/crawler/utxo-set-import.js +71 -3
- package/srv/blockchain/ledger-state.d.ts +6 -1
- package/srv/blockchain/ledger-state.js +3 -0
- package/srv/blockchain/stored-chain.js +9 -1
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +17 -0
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +74 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +10 -1
- package/srv/blockchain/transaction-building/buildooor-tx.js +55 -19
- package/srv/blockchain/transaction-rows.d.ts +1 -1
- package/srv/blockchain/transaction-rows.js +2 -1
- package/srv/cardano-indexer-service.cds +30 -3
- package/srv/cardano-indexer-service.js +48 -3
- package/srv/cardano-service.cds +344 -332
- package/srv/cardano-service.js +9 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +4 -1
- package/srv/cbor/plutus-data-json.d.ts +24 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/utils/agent-grants.js +1 -1
- package/srv/utils/db-indexes.js +5 -0
- package/srv/utils/mappers.d.ts +6 -2
- package/srv/utils/mappers.js +20 -0
- package/srv/utils/reference-script.d.ts +37 -0
- package/srv/utils/reference-script.js +95 -0
- package/srv/utils/types.d.ts +19 -0
package/srv/cardano-service.js
CHANGED
|
@@ -404,6 +404,15 @@ module.exports = (srv) => {
|
|
|
404
404
|
}
|
|
405
405
|
return (0, backend_request_handler_1.handleRequest)(req, async () => (0, cbor_1.parseTransaction)(cbor));
|
|
406
406
|
});
|
|
407
|
+
srv.on('DecodePlutusData', async (req) => {
|
|
408
|
+
const { cbor } = req.data;
|
|
409
|
+
if (cbor == null || cbor === '')
|
|
410
|
+
(0, errors_1.rejectMissing)(req, 'DecodePlutusData', 'cbor');
|
|
411
|
+
if (!(0, validators_1.isValidTxCborHex)(cbor)) {
|
|
412
|
+
(0, errors_1.rejectInvalid)(req, 'DecodePlutusData', 'Invalid CBOR hex or exceeds size limit', 'cbor');
|
|
413
|
+
}
|
|
414
|
+
return (0, backend_request_handler_1.handleRequest)(req, async () => JSON.stringify((0, cbor_1.decodePlutusData)(cbor)));
|
|
415
|
+
});
|
|
407
416
|
// ---------------------------------------------------------------------------
|
|
408
417
|
// Address Transactions
|
|
409
418
|
// ---------------------------------------------------------------------------
|
package/srv/cbor/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { parseTransaction, type ParsedTransaction, type ParsedInput, type ParsedOutput, type ParsedAsset, type ParsedWitnesses, type ParsedWithdrawal, type ParsedCertificate, } from './parse';
|
|
2
|
+
export { decodePlutusData, plutusDataToJson, type PlutusDataJson } from './plutus-data-json';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
package/srv/cbor/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTransaction = void 0;
|
|
3
|
+
exports.plutusDataToJson = exports.decodePlutusData = exports.parseTransaction = void 0;
|
|
4
4
|
var parse_1 = require("./parse");
|
|
5
5
|
Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return parse_1.parseTransaction; } });
|
|
6
|
+
var plutus_data_json_1 = require("./plutus-data-json");
|
|
7
|
+
Object.defineProperty(exports, "decodePlutusData", { enumerable: true, get: function () { return plutus_data_json_1.decodePlutusData; } });
|
|
8
|
+
Object.defineProperty(exports, "plutusDataToJson", { enumerable: true, get: function () { return plutus_data_json_1.plutusDataToJson; } });
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Data } from '@harmoniclabs/plutus-data';
|
|
2
|
+
/**
|
|
3
|
+
* PlutusData as cardano-cli DetailedSchema JSON, the shape the build actions accept as
|
|
4
|
+
* outputDatumJson. Integers beyond the safe JS range are decimal strings so no digit is lost.
|
|
5
|
+
*/
|
|
6
|
+
export type PlutusDataJson = {
|
|
7
|
+
constructor: number;
|
|
8
|
+
fields: PlutusDataJson[];
|
|
9
|
+
} | {
|
|
10
|
+
int: number | string;
|
|
11
|
+
} | {
|
|
12
|
+
bytes: string;
|
|
13
|
+
} | {
|
|
14
|
+
list: PlutusDataJson[];
|
|
15
|
+
} | {
|
|
16
|
+
map: {
|
|
17
|
+
k: PlutusDataJson;
|
|
18
|
+
v: PlutusDataJson;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
export declare function plutusDataToJson(data: Data): PlutusDataJson;
|
|
22
|
+
/** @throws TransactionValidationError (`TX_PARSE_FAILED`) when the hex is not PlutusData CBOR. */
|
|
23
|
+
export declare function decodePlutusData(cborHex: string): PlutusDataJson;
|
|
24
|
+
//# sourceMappingURL=plutus-data-json.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plutusDataToJson = plutusDataToJson;
|
|
4
|
+
exports.decodePlutusData = decodePlutusData;
|
|
5
|
+
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
6
|
+
const errors_1 = require("../utils/errors");
|
|
7
|
+
const error_codes_1 = require("../utils/error-codes");
|
|
8
|
+
function plutusDataToJson(data) {
|
|
9
|
+
if (data instanceof plutus_data_1.DataConstr)
|
|
10
|
+
return { constructor: Number(data.constr), fields: data.fields.map(plutusDataToJson) };
|
|
11
|
+
if (data instanceof plutus_data_1.DataI) {
|
|
12
|
+
const i = data.int;
|
|
13
|
+
return { int: i >= BigInt(Number.MIN_SAFE_INTEGER) && i <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(i) : i.toString() };
|
|
14
|
+
}
|
|
15
|
+
if (data instanceof plutus_data_1.DataB)
|
|
16
|
+
return { bytes: Buffer.from(data.bytes).toString('hex') };
|
|
17
|
+
if (data instanceof plutus_data_1.DataList)
|
|
18
|
+
return { list: data.list.map(plutusDataToJson) };
|
|
19
|
+
if (data instanceof plutus_data_1.DataMap)
|
|
20
|
+
return { map: data.map.map((kv) => ({ k: plutusDataToJson(kv.fst), v: plutusDataToJson(kv.snd) })) };
|
|
21
|
+
throw new TypeError('unknown PlutusData node');
|
|
22
|
+
}
|
|
23
|
+
/** @throws TransactionValidationError (`TX_PARSE_FAILED`) when the hex is not PlutusData CBOR. */
|
|
24
|
+
function decodePlutusData(cborHex) {
|
|
25
|
+
try {
|
|
26
|
+
return plutusDataToJson((0, plutus_data_1.dataFromCbor)(cborHex.trim().toLowerCase()));
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new errors_1.TransactionValidationError(`Not PlutusData CBOR: ${err instanceof Error ? err.message : String(err)}`, err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=plutus-data-json.js.map
|
|
@@ -105,7 +105,7 @@ exports.AGENT_ALWAYS_ALLOWED_EVENTS = new Set([
|
|
|
105
105
|
'GetAssetInfo', 'GetAssetHistory', 'GetAccountByStakeAddress', 'GetTransactionByHash',
|
|
106
106
|
'GetTransactionConfirmations', 'GetMetadataByTxHash', 'GetAddressByBech32', 'GetUTxOsByAddress', 'GetUTxOsByCredential',
|
|
107
107
|
'GetAssetsByAddress', 'GetLatestTransactionsByAddress', 'GetLatestBlock', 'GetLatestEpoch',
|
|
108
|
-
'GetLedgerProtocolParameters', 'ParseTransactionCbor',
|
|
108
|
+
'GetLedgerProtocolParameters', 'ParseTransactionCbor', 'DecodePlutusData',
|
|
109
109
|
// CardanoTransactionService: compute-only
|
|
110
110
|
'GetBuildDetails', 'GetTransactionBuildsByAddress', 'DeriveScriptAddress', 'ExtractPaymentKeyHash',
|
|
111
111
|
// CardanoSignService: reads and stateless verification
|
package/srv/utils/db-indexes.js
CHANGED
|
@@ -47,6 +47,10 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
47
47
|
{ name: 'odatano_cardano_cardanoagentgrants_token', table: 'odatano_cardano_CardanoAgentGrants', columns: 'tokenHash' },
|
|
48
48
|
// crawler-fed ledger state: "who spent this output" and delegation per stake key / pool / DRep
|
|
49
49
|
{ name: 'odatano_cardano_transactioninputs_spent', table: 'odatano_cardano_TransactionInputs', columns: 'spentTxHash, spentOutputIndex' },
|
|
50
|
+
// outputs to / inputs from a payment credential in slot order (txSeq); datum lookup by hash across txs
|
|
51
|
+
{ name: 'odatano_cardano_transactionoutputs_paycred', table: 'odatano_cardano_TransactionOutputs', columns: 'utxo_paymentCredential, txSeq' },
|
|
52
|
+
{ name: 'odatano_cardano_transactioninputs_paycred', table: 'odatano_cardano_TransactionInputs', columns: 'utxoData_paymentCredential, txSeq' },
|
|
53
|
+
{ name: 'odatano_cardano_transactiondatums_hash', table: 'odatano_cardano_TransactionDatums', columns: 'dataHash' },
|
|
50
54
|
{ name: 'odatano_cardano_transactioncertificates_stake', table: 'odatano_cardano_TransactionCertificates', columns: 'stakeAddress' },
|
|
51
55
|
{ name: 'odatano_cardano_transactioncertificates_pool', table: 'odatano_cardano_TransactionCertificates', columns: 'poolId' },
|
|
52
56
|
{ name: 'odatano_cardano_transactioncertificates_drep', table: 'odatano_cardano_TransactionCertificates', columns: 'drepId' },
|
|
@@ -54,6 +58,7 @@ exports.DB_INDEXES = Object.freeze([
|
|
|
54
58
|
// crawler-fed UTxO set: open rows per address, "who spent", stake-key rollups, asset holders
|
|
55
59
|
{ name: 'odatano_cardano_ledgerutxos_address', table: 'odatano_cardano_LedgerUTxOs', columns: 'address, spentTxHash' },
|
|
56
60
|
{ name: 'odatano_cardano_ledgerutxos_spent', table: 'odatano_cardano_LedgerUTxOs', columns: 'spentTxHash' },
|
|
61
|
+
{ name: 'odatano_cardano_ledgerutxos_paycred', table: 'odatano_cardano_LedgerUTxOs', columns: 'utxo_paymentCredential, spentTxHash' },
|
|
57
62
|
{ name: 'odatano_cardano_ledgeraddresses_stake', table: 'odatano_cardano_LedgerAddresses', columns: 'stakeAddress' },
|
|
58
63
|
{ name: 'odatano_cardano_ledgeraddresses_paycred', table: 'odatano_cardano_LedgerAddresses', columns: 'paymentCredential' },
|
|
59
64
|
{ name: 'odatano_cardano_ledgerutxoassets_unit', table: 'odatano_cardano_LedgerUTxOAssets', columns: 'unit' },
|
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, 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';
|
|
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, TxDatum as TxDatumProviderData, 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, TransactionDatum as TransactionDatumRow, 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';
|
|
@@ -38,6 +38,8 @@ export declare function ledgerInputOrder(inputs: TxInputProviderData[]): TxInput
|
|
|
38
38
|
export declare function ledgerView<T extends TransactionProviderData>(tx: T): T;
|
|
39
39
|
/** Normalized redeemers to TransactionRedeemerRows, keyed (tx, purpose, index). */
|
|
40
40
|
export declare function mapTransactionRedeemers(txHash: string, redeemers: TxRedeemerProviderData[]): TransactionRedeemerRow[];
|
|
41
|
+
/** Witness-set datums to TransactionDatumRows, keyed (tx, dataHash). */
|
|
42
|
+
export declare function mapTransactionDatums(txHash: string, datums: TxDatumProviderData[]): TransactionDatumRow[];
|
|
41
43
|
/** Provider transaction outputs to TransactionOutputRows. */
|
|
42
44
|
export declare function mapTransactionOutputs(txSeq: number, txOutputs: TxOutputProviderData[]): TransactionOutputRow[];
|
|
43
45
|
/** Provider transaction output assets to TransactionOutputAssetRows. */
|
|
@@ -159,6 +161,8 @@ export interface DecodedAddress {
|
|
|
159
161
|
* stake credential as a reward account. Byron (base58) and unparseable input yield `byron` / `unknown`.
|
|
160
162
|
*/
|
|
161
163
|
export declare function decodeShelleyAddress(address: string): DecodedAddress;
|
|
164
|
+
/** Payment credential (hex) of a bech32 address; null for Byron, reward and unresolved ('') addresses. */
|
|
165
|
+
export declare function paymentCredentialOf(address: string | null | undefined): string | null;
|
|
162
166
|
/** DRep credential to CIP-129 DRep ID (29 bytes): header 0x22 key hash / 0x23 script hash. */
|
|
163
167
|
export declare function credentialToDrepId(credentialHex: string, isScript: boolean): string;
|
|
164
168
|
/** Address balance from its UTxOs: lovelace first, then every native asset summed per unit. */
|
package/srv/utils/mappers.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.compareOutRef = compareOutRef;
|
|
|
14
14
|
exports.ledgerInputOrder = ledgerInputOrder;
|
|
15
15
|
exports.ledgerView = ledgerView;
|
|
16
16
|
exports.mapTransactionRedeemers = mapTransactionRedeemers;
|
|
17
|
+
exports.mapTransactionDatums = mapTransactionDatums;
|
|
17
18
|
exports.mapTransactionOutputs = mapTransactionOutputs;
|
|
18
19
|
exports.mapTransactionOutputAssets = mapTransactionOutputAssets;
|
|
19
20
|
exports.mapAddress = mapAddress;
|
|
@@ -48,6 +49,7 @@ exports.computeCip14Fingerprint = computeCip14Fingerprint;
|
|
|
48
49
|
exports.scriptHashToEnterpriseAddress = scriptHashToEnterpriseAddress;
|
|
49
50
|
exports.credentialToStakeAddress = credentialToStakeAddress;
|
|
50
51
|
exports.decodeShelleyAddress = decodeShelleyAddress;
|
|
52
|
+
exports.paymentCredentialOf = paymentCredentialOf;
|
|
51
53
|
exports.credentialToDrepId = credentialToDrepId;
|
|
52
54
|
exports.sumUtxoAmounts = sumUtxoAmounts;
|
|
53
55
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
@@ -101,6 +103,9 @@ function mapTransactionInputs(txSeq, txInputs) {
|
|
|
101
103
|
utxoData_dataHash: input.dataHash || null,
|
|
102
104
|
utxoData_inlineDatum: input.inlineDatum || null,
|
|
103
105
|
utxoData_referenceScriptHash: input.referenceScriptHash || null,
|
|
106
|
+
utxoData_referenceScriptSize: input.referenceScriptSize ?? null,
|
|
107
|
+
utxoData_referenceScriptType: input.referenceScriptType ?? null,
|
|
108
|
+
utxoData_paymentCredential: paymentCredentialOf(input.address),
|
|
104
109
|
// outpoint of the consumed UTxO
|
|
105
110
|
spentTxHash: input.txHash || null,
|
|
106
111
|
spentOutputIndex: Number.isInteger(input.outputIndex) ? input.outputIndex : null,
|
|
@@ -199,6 +204,10 @@ function mapTransactionRedeemers(txHash, redeemers) {
|
|
|
199
204
|
policyId: r.policyId ?? null,
|
|
200
205
|
}));
|
|
201
206
|
}
|
|
207
|
+
/** Witness-set datums to TransactionDatumRows, keyed (tx, dataHash). */
|
|
208
|
+
function mapTransactionDatums(txHash, datums) {
|
|
209
|
+
return datums.map((d) => ({ tx_hash: txHash, dataHash: d.hash, datum: d.cbor }));
|
|
210
|
+
}
|
|
202
211
|
/** Provider transaction outputs to TransactionOutputRows. */
|
|
203
212
|
function mapTransactionOutputs(txSeq, txOutputs) {
|
|
204
213
|
return txOutputs.map((output) => {
|
|
@@ -212,6 +221,9 @@ function mapTransactionOutputs(txSeq, txOutputs) {
|
|
|
212
221
|
utxo_dataHash: output.dataHash || null,
|
|
213
222
|
utxo_inlineDatum: output.inlineDatum || null,
|
|
214
223
|
utxo_referenceScriptHash: output.referenceScriptHash || null,
|
|
224
|
+
utxo_referenceScriptSize: output.referenceScriptSize ?? null,
|
|
225
|
+
utxo_referenceScriptType: output.referenceScriptType ?? null,
|
|
226
|
+
utxo_paymentCredential: paymentCredentialOf(output.address),
|
|
215
227
|
hasAddresses: hasAddresses,
|
|
216
228
|
hasAssets: hasAssets,
|
|
217
229
|
};
|
|
@@ -345,6 +357,9 @@ function mapAddressUtxos(addr, validFrom, validTo, addressUtxosData) {
|
|
|
345
357
|
// Hash column: Blockfrost/Ogmios give a 56-hex hash, Koios the full script CBOR, so only
|
|
346
358
|
// hash-length values are persisted
|
|
347
359
|
utxodata_referenceScriptHash: utxo.scriptRef && utxo.scriptRef.length <= 64 ? utxo.scriptRef : null,
|
|
360
|
+
utxodata_referenceScriptSize: utxo.scriptRefSize ?? null,
|
|
361
|
+
utxodata_referenceScriptType: utxo.scriptRefType ?? null,
|
|
362
|
+
utxodata_paymentCredential: paymentCredentialOf(addr),
|
|
348
363
|
lovelace: lovelace,
|
|
349
364
|
validFrom: validFrom,
|
|
350
365
|
validTo: validTo,
|
|
@@ -773,6 +788,7 @@ function mapProtocolParameters(providerParams) {
|
|
|
773
788
|
collateralPercent: providerParams.collateralPercent,
|
|
774
789
|
maxCollateralInputs: providerParams.maxCollateralInputs,
|
|
775
790
|
coinsPerUtxoSize: providerParams.coinsPerUtxoSize,
|
|
791
|
+
minFeeRefScriptCostPerByte: providerParams.minFeeRefScriptCostPerByte,
|
|
776
792
|
fetchedAt: providerParams.fetchedAt,
|
|
777
793
|
source: providerParams.source,
|
|
778
794
|
};
|
|
@@ -944,6 +960,10 @@ function decodeShelleyAddress(address) {
|
|
|
944
960
|
return { ...none, networkId };
|
|
945
961
|
}
|
|
946
962
|
}
|
|
963
|
+
/** Payment credential (hex) of a bech32 address; null for Byron, reward and unresolved ('') addresses. */
|
|
964
|
+
function paymentCredentialOf(address) {
|
|
965
|
+
return address ? decodeShelleyAddress(address).paymentCredential : null;
|
|
966
|
+
}
|
|
947
967
|
/** DRep credential to CIP-129 DRep ID (29 bytes): header 0x22 key hash / 0x23 script hash. */
|
|
948
968
|
function credentialToDrepId(credentialHex, isScript) {
|
|
949
969
|
const payload = Buffer.alloc(29);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Script } from '@harmoniclabs/cardano-ledger-ts';
|
|
2
|
+
/** Script language of a reference script as the entities expose it. */
|
|
3
|
+
export type ReferenceScriptType = 'native' | 'plutusV1' | 'plutusV2' | 'plutusV3';
|
|
4
|
+
/** Hash, ledger byte size and type of a reference script; `cbor` holds the Plutus script bytes when known. */
|
|
5
|
+
export interface ReferenceScriptInfo {
|
|
6
|
+
hash: string;
|
|
7
|
+
size: number;
|
|
8
|
+
type: ReferenceScriptType;
|
|
9
|
+
cbor: string | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Provider spelling of a script type to ours: Ogmios `plutus:v3` / `native`, Koios and cardano-cli
|
|
13
|
+
* `plutusV3` / `PlutusScriptV3` / `timelock` / `multisig` / `SimpleScript`. Null when unknown.
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeScriptType(raw: unknown): ReferenceScriptType | null;
|
|
16
|
+
/** Ledger script hash: blake2b-224 over the language tag byte followed by the script bytes. */
|
|
17
|
+
export declare function referenceScriptHash(type: ReferenceScriptType, bytes: Uint8Array): string;
|
|
18
|
+
/**
|
|
19
|
+
* Bytes the ledger charges for a reference script: for Plutus the script bytestring as the
|
|
20
|
+
* compiler emits it, for a native script its CBOR.
|
|
21
|
+
*/
|
|
22
|
+
export declare function referenceScriptSize(script: Script): number;
|
|
23
|
+
/**
|
|
24
|
+
* A Plutus script object of the given ledger size and no content: lets the fee count the bytes of
|
|
25
|
+
* a reference script whose bytes are not at hand (hash and size only). Never a witness, never
|
|
26
|
+
* serialized; its hash matches no real script.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sizePlaceholderScript(size: number): Script;
|
|
29
|
+
/** Hash, size and type of an Ogmios `script` object (`{ language, cbor }`); null without one. */
|
|
30
|
+
export declare function ogmiosReferenceScript(script: unknown): ReferenceScriptInfo | null;
|
|
31
|
+
/**
|
|
32
|
+
* Hash, size and type of a cardano-cli dump's `referenceScript`. The Plutus TextEnvelope
|
|
33
|
+
* `cborHex` wraps the script bytestring once more than the ledger does; the inner bytes are
|
|
34
|
+
* what the ledger hashes and charges for. A native script is given as its JSON.
|
|
35
|
+
*/
|
|
36
|
+
export declare function cliReferenceScript(ref: unknown): ReferenceScriptInfo | null;
|
|
37
|
+
//# sourceMappingURL=reference-script.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeScriptType = normalizeScriptType;
|
|
4
|
+
exports.referenceScriptHash = referenceScriptHash;
|
|
5
|
+
exports.referenceScriptSize = referenceScriptSize;
|
|
6
|
+
exports.sizePlaceholderScript = sizePlaceholderScript;
|
|
7
|
+
exports.ogmiosReferenceScript = ogmiosReferenceScript;
|
|
8
|
+
exports.cliReferenceScript = cliReferenceScript;
|
|
9
|
+
const crypto_1 = require("@harmoniclabs/crypto");
|
|
10
|
+
const cbor_1 = require("@harmoniclabs/cbor");
|
|
11
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
12
|
+
const LANGUAGE_TAG = { native: 0, plutusV1: 1, plutusV2: 2, plutusV3: 3 };
|
|
13
|
+
/**
|
|
14
|
+
* Provider spelling of a script type to ours: Ogmios `plutus:v3` / `native`, Koios and cardano-cli
|
|
15
|
+
* `plutusV3` / `PlutusScriptV3` / `timelock` / `multisig` / `SimpleScript`. Null when unknown.
|
|
16
|
+
*/
|
|
17
|
+
function normalizeScriptType(raw) {
|
|
18
|
+
if (typeof raw !== 'string')
|
|
19
|
+
return null;
|
|
20
|
+
const m = /^(?:plutus:?(?:script)?v?)([1-3])$/i.exec(raw.replace(/\s+/g, ''));
|
|
21
|
+
if (m)
|
|
22
|
+
return `plutusV${m[1]}`;
|
|
23
|
+
return /^(native|timelock|multisig|simplescript)/i.test(raw) ? 'native' : null;
|
|
24
|
+
}
|
|
25
|
+
/** Ledger script hash: blake2b-224 over the language tag byte followed by the script bytes. */
|
|
26
|
+
function referenceScriptHash(type, bytes) {
|
|
27
|
+
const tagged = Uint8Array.from(Buffer.concat([Buffer.from([LANGUAGE_TAG[type]]), Buffer.from(bytes)]));
|
|
28
|
+
return Buffer.from((0, crypto_1.blake2b_224)(tagged)).toString('hex');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Bytes the ledger charges for a reference script: for Plutus the script bytestring as the
|
|
32
|
+
* compiler emits it, for a native script its CBOR.
|
|
33
|
+
*/
|
|
34
|
+
function referenceScriptSize(script) {
|
|
35
|
+
if (script.type === 'NativeScript')
|
|
36
|
+
return script.bytes.length;
|
|
37
|
+
const n = script.bytes.length;
|
|
38
|
+
// definite-length CBOR bytestring header
|
|
39
|
+
const header = n < 24 ? 1 : n < 0x100 ? 2 : n < 0x10000 ? 3 : 5;
|
|
40
|
+
return n + header;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A Plutus script object of the given ledger size and no content: lets the fee count the bytes of
|
|
44
|
+
* a reference script whose bytes are not at hand (hash and size only). Never a witness, never
|
|
45
|
+
* serialized; its hash matches no real script.
|
|
46
|
+
*/
|
|
47
|
+
function sizePlaceholderScript(size) {
|
|
48
|
+
for (let n = Math.max(0, size - 5); n <= size; n++) {
|
|
49
|
+
const header = n < 24 ? 1 : n < 0x100 ? 2 : n < 0x10000 ? 3 : 5;
|
|
50
|
+
if (n + header === size)
|
|
51
|
+
return cardano_ledger_ts_1.Script.plutusV3(new Uint8Array(n));
|
|
52
|
+
}
|
|
53
|
+
return cardano_ledger_ts_1.Script.plutusV3(new Uint8Array(Math.max(0, size - 1)));
|
|
54
|
+
}
|
|
55
|
+
/** Hash, size and type of an Ogmios `script` object (`{ language, cbor }`); null without one. */
|
|
56
|
+
function ogmiosReferenceScript(script) {
|
|
57
|
+
const s = script;
|
|
58
|
+
const type = normalizeScriptType(s?.language);
|
|
59
|
+
if (!type || typeof s?.cbor !== 'string' || s.cbor.length === 0)
|
|
60
|
+
return null;
|
|
61
|
+
const bytes = Buffer.from(s.cbor, 'hex');
|
|
62
|
+
return { hash: referenceScriptHash(type, bytes), size: bytes.length, type, cbor: type === 'native' ? null : s.cbor };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hash, size and type of a cardano-cli dump's `referenceScript`. The Plutus TextEnvelope
|
|
66
|
+
* `cborHex` wraps the script bytestring once more than the ledger does; the inner bytes are
|
|
67
|
+
* what the ledger hashes and charges for. A native script is given as its JSON.
|
|
68
|
+
*/
|
|
69
|
+
function cliReferenceScript(ref) {
|
|
70
|
+
const r = ref;
|
|
71
|
+
const script = r?.script;
|
|
72
|
+
if (!script || typeof script !== 'object')
|
|
73
|
+
return null;
|
|
74
|
+
const envelope = script;
|
|
75
|
+
const type = normalizeScriptType(envelope.type) ?? normalizeScriptType(r?.scriptLanguage);
|
|
76
|
+
try {
|
|
77
|
+
if (type && type !== 'native' && typeof envelope.cborHex === 'string') {
|
|
78
|
+
const outer = cbor_1.Cbor.parse(Buffer.from(envelope.cborHex, 'hex'));
|
|
79
|
+
if (!(outer instanceof cbor_1.CborBytes))
|
|
80
|
+
return null;
|
|
81
|
+
const inner = Buffer.from(outer.bytes);
|
|
82
|
+
return { hash: referenceScriptHash(type, inner), size: inner.length, type, cbor: inner.toString('hex') };
|
|
83
|
+
}
|
|
84
|
+
if (type === 'native' || r?.scriptLanguage?.startsWith('SimpleScript')) {
|
|
85
|
+
// the cli prints a native script as its JSON (sig / all / any / atLeast / after / before)
|
|
86
|
+
const native = cardano_ledger_ts_1.Script.native(script);
|
|
87
|
+
return { hash: native.hash.toString(), size: native.bytes.length, type: 'native', cbor: null };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=reference-script.js.map
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { LedgerProtocolParameter } from "#cds-models/odatano/cardano";
|
|
2
|
+
import type { ReferenceScriptType } from "./reference-script";
|
|
3
|
+
export type { ReferenceScriptType };
|
|
2
4
|
/** Hex-encoded string (case depends on source) */
|
|
3
5
|
export type Hex = string;
|
|
4
6
|
/** Lovelace amount; a string preserves precision above Number.MAX_SAFE_INTEGER (max supply is 4.5e16). */
|
|
@@ -21,6 +23,8 @@ export interface TxInputLine {
|
|
|
21
23
|
dataHash?: Hex | null;
|
|
22
24
|
inlineDatum?: string | null;
|
|
23
25
|
referenceScriptHash?: Hex | null;
|
|
26
|
+
referenceScriptSize?: number | null;
|
|
27
|
+
referenceScriptType?: ReferenceScriptType | null;
|
|
24
28
|
isCollateral?: boolean;
|
|
25
29
|
isReference?: boolean;
|
|
26
30
|
}
|
|
@@ -34,6 +38,8 @@ export interface TxOutputLine {
|
|
|
34
38
|
inlineDatum: string | null;
|
|
35
39
|
isCollateral: boolean;
|
|
36
40
|
referenceScriptHash?: Hex | null;
|
|
41
|
+
referenceScriptSize?: number | null;
|
|
42
|
+
referenceScriptType?: ReferenceScriptType | null;
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Normalized certificate kinds; unknown types pass through as the raw source string. A Conway
|
|
@@ -78,6 +84,13 @@ export interface TxRedeemer {
|
|
|
78
84
|
/** mint: the policy. */
|
|
79
85
|
policyId?: Hex | null;
|
|
80
86
|
}
|
|
87
|
+
/** One datum of a transaction witness set. */
|
|
88
|
+
export interface TxDatum {
|
|
89
|
+
/** Blake2b-256 of the datum bytes. */
|
|
90
|
+
hash: Hex;
|
|
91
|
+
/** PlutusData CBOR hex, the original bytes. */
|
|
92
|
+
cbor: string;
|
|
93
|
+
}
|
|
81
94
|
/** Normalized transaction */
|
|
82
95
|
export interface Transaction {
|
|
83
96
|
hash: Hex;
|
|
@@ -116,6 +129,8 @@ export interface Transaction {
|
|
|
116
129
|
withdrawals?: TxWithdrawal[];
|
|
117
130
|
/** Redeemers; `[]` when the tx has none, undefined when the source does not report them (Blockfrost, Koios). */
|
|
118
131
|
redeemers?: TxRedeemer[];
|
|
132
|
+
/** Witness-set datums; same `[]` vs undefined convention as `redeemers`. */
|
|
133
|
+
datums?: TxDatum[];
|
|
119
134
|
}
|
|
120
135
|
/** Address view with current value and known UTxOs */
|
|
121
136
|
export interface Address {
|
|
@@ -138,6 +153,9 @@ export interface UTxO {
|
|
|
138
153
|
scriptRef?: Hex | null;
|
|
139
154
|
/** Full CBOR of the reference script (Plutus) when the source delivers it; builder use only. */
|
|
140
155
|
scriptRefCbor?: Hex | null;
|
|
156
|
+
/** Bytes the ledger charges for the reference script; null when the source reports the hash only. */
|
|
157
|
+
scriptRefSize?: number | null;
|
|
158
|
+
scriptRefType?: ReferenceScriptType | null;
|
|
141
159
|
inlineDatum?: string | null;
|
|
142
160
|
}
|
|
143
161
|
/** Basic block information */
|
|
@@ -307,6 +325,7 @@ export type LedgerProtocolParameters = {
|
|
|
307
325
|
collateralPercent: number | null;
|
|
308
326
|
maxCollateralInputs: number | null;
|
|
309
327
|
coinsPerUtxoSize: string | null;
|
|
328
|
+
minFeeRefScriptCostPerByte: number | null;
|
|
310
329
|
fetchedAt: string;
|
|
311
330
|
source: string;
|
|
312
331
|
};
|