@odatano/core 2.0.0-rc.42 → 2.0.0-rc.44
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 +78 -0
- package/@cds-models/CardanoIndexerService/index.js +11 -0
- package/@cds-models/CardanoODataService/index.d.ts +36 -0
- package/@cds-models/CardanoODataService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +1 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +1 -0
- package/@cds-models/index.d.ts +1 -0
- package/@cds-models/odatano/cardano/index.d.ts +25 -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 -417
- package/package.json +1 -1
- package/srv/blockchain/asset-decimals.d.ts +16 -0
- package/srv/blockchain/asset-decimals.js +86 -0
- package/srv/blockchain/backends/ogmios-backend.js +1 -0
- package/srv/blockchain/cardano-indexer.js +10 -1
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +20 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +59 -0
- package/srv/blockchain/crawler/credential-backfill.d.ts +38 -0
- package/srv/blockchain/crawler/credential-backfill.js +126 -0
- package/srv/blockchain/crawler/transaction-backfill.d.ts +3 -2
- package/srv/blockchain/crawler/transaction-backfill.js +8 -4
- package/srv/blockchain/ledger-state.d.ts +1 -0
- package/srv/blockchain/ledger-state.js +1 -0
- package/srv/blockchain/stored-chain.js +5 -1
- package/srv/blockchain/transaction-rows.d.ts +1 -1
- package/srv/blockchain/transaction-rows.js +2 -1
- package/srv/cardano-indexer-service.cds +48 -2
- package/srv/cardano-indexer-service.js +47 -2
- package/srv/cardano-service.cds +344 -332
- package/srv/cardano-service.js +9 -0
- package/srv/cbor/cip68.d.ts +17 -0
- package/srv/cbor/cip68.js +58 -0
- package/srv/cbor/index.d.ts +2 -0
- package/srv/cbor/index.js +9 -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 +16 -0
- package/srv/utils/types.d.ts +9 -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
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** CIP-67 asset-name labels of the CIP-68 token classes, as the first 4 bytes of the asset name. */
|
|
2
|
+
export declare const CIP68_LABEL: {
|
|
3
|
+
readonly reference: "000643b0";
|
|
4
|
+
readonly nft: "000de140";
|
|
5
|
+
readonly ft: "0014df10";
|
|
6
|
+
readonly rft: "001bc280";
|
|
7
|
+
};
|
|
8
|
+
/** Reference-NFT unit of a CIP-68 user token with label 333 or 444; null for any other unit. */
|
|
9
|
+
export declare function cip68ReferenceUnit(unit: string): string | null;
|
|
10
|
+
/** The label-333 and label-444 units a CIP-68 reference NFT describes; null for any other unit. */
|
|
11
|
+
export declare function cip68UserUnits(referenceUnit: string): string[] | null;
|
|
12
|
+
/**
|
|
13
|
+
* `decimals` of a CIP-68 reference datum: Constr 0 whose first field is the metadata map, keyed
|
|
14
|
+
* by UTF-8 byte strings. null when the datum has no such integer in 0..255 or is not that shape.
|
|
15
|
+
*/
|
|
16
|
+
export declare function cip68DecimalsFromDatum(cborHex: string): number | null;
|
|
17
|
+
//# sourceMappingURL=cip68.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CIP68_LABEL = void 0;
|
|
4
|
+
exports.cip68ReferenceUnit = cip68ReferenceUnit;
|
|
5
|
+
exports.cip68UserUnits = cip68UserUnits;
|
|
6
|
+
exports.cip68DecimalsFromDatum = cip68DecimalsFromDatum;
|
|
7
|
+
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
8
|
+
/** CIP-67 asset-name labels of the CIP-68 token classes, as the first 4 bytes of the asset name. */
|
|
9
|
+
exports.CIP68_LABEL = {
|
|
10
|
+
reference: '000643b0',
|
|
11
|
+
nft: '000de140',
|
|
12
|
+
ft: '0014df10',
|
|
13
|
+
rft: '001bc280',
|
|
14
|
+
};
|
|
15
|
+
/** Labels whose reference datum may carry `decimals`. */
|
|
16
|
+
const USER_LABELS_WITH_DECIMALS = [exports.CIP68_LABEL.ft, exports.CIP68_LABEL.rft];
|
|
17
|
+
const labelOf = (unit) => unit.slice(56, 64);
|
|
18
|
+
/** Reference-NFT unit of a CIP-68 user token with label 333 or 444; null for any other unit. */
|
|
19
|
+
function cip68ReferenceUnit(unit) {
|
|
20
|
+
if (unit.length < 64 || !USER_LABELS_WITH_DECIMALS.includes(labelOf(unit)))
|
|
21
|
+
return null;
|
|
22
|
+
return unit.slice(0, 56) + exports.CIP68_LABEL.reference + unit.slice(64);
|
|
23
|
+
}
|
|
24
|
+
/** The label-333 and label-444 units a CIP-68 reference NFT describes; null for any other unit. */
|
|
25
|
+
function cip68UserUnits(referenceUnit) {
|
|
26
|
+
if (referenceUnit.length < 64 || labelOf(referenceUnit) !== exports.CIP68_LABEL.reference)
|
|
27
|
+
return null;
|
|
28
|
+
return USER_LABELS_WITH_DECIMALS.map((label) => referenceUnit.slice(0, 56) + label + referenceUnit.slice(64));
|
|
29
|
+
}
|
|
30
|
+
const DECIMALS_KEY = Buffer.from('decimals');
|
|
31
|
+
/**
|
|
32
|
+
* `decimals` of a CIP-68 reference datum: Constr 0 whose first field is the metadata map, keyed
|
|
33
|
+
* by UTF-8 byte strings. null when the datum has no such integer in 0..255 or is not that shape.
|
|
34
|
+
*/
|
|
35
|
+
function cip68DecimalsFromDatum(cborHex) {
|
|
36
|
+
let data;
|
|
37
|
+
try {
|
|
38
|
+
data = (0, plutus_data_1.dataFromCbor)(cborHex);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (!(data instanceof plutus_data_1.DataConstr) || data.constr !== 0n)
|
|
44
|
+
return null;
|
|
45
|
+
const metadata = data.fields[0];
|
|
46
|
+
if (!(metadata instanceof plutus_data_1.DataMap))
|
|
47
|
+
return null;
|
|
48
|
+
for (const kv of metadata.map) {
|
|
49
|
+
if (!(kv.fst instanceof plutus_data_1.DataB) || !DECIMALS_KEY.equals(Buffer.from(kv.fst.bytes)))
|
|
50
|
+
continue;
|
|
51
|
+
if (!(kv.snd instanceof plutus_data_1.DataI))
|
|
52
|
+
return null;
|
|
53
|
+
const n = kv.snd.int;
|
|
54
|
+
return n >= 0n && n <= 255n ? Number(n) : null;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=cip68.js.map
|
package/srv/cbor/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
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';
|
|
3
|
+
export { CIP68_LABEL, cip68ReferenceUnit, cip68UserUnits, cip68DecimalsFromDatum } from './cip68';
|
|
2
4
|
//# sourceMappingURL=index.d.ts.map
|
package/srv/cbor/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTransaction = void 0;
|
|
3
|
+
exports.cip68DecimalsFromDatum = exports.cip68UserUnits = exports.cip68ReferenceUnit = exports.CIP68_LABEL = 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; } });
|
|
9
|
+
var cip68_1 = require("./cip68");
|
|
10
|
+
Object.defineProperty(exports, "CIP68_LABEL", { enumerable: true, get: function () { return cip68_1.CIP68_LABEL; } });
|
|
11
|
+
Object.defineProperty(exports, "cip68ReferenceUnit", { enumerable: true, get: function () { return cip68_1.cip68ReferenceUnit; } });
|
|
12
|
+
Object.defineProperty(exports, "cip68UserUnits", { enumerable: true, get: function () { return cip68_1.cip68UserUnits; } });
|
|
13
|
+
Object.defineProperty(exports, "cip68DecimalsFromDatum", { enumerable: true, get: function () { return cip68_1.cip68DecimalsFromDatum; } });
|
|
6
14
|
//# 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"));
|
|
@@ -103,6 +105,7 @@ function mapTransactionInputs(txSeq, txInputs) {
|
|
|
103
105
|
utxoData_referenceScriptHash: input.referenceScriptHash || null,
|
|
104
106
|
utxoData_referenceScriptSize: input.referenceScriptSize ?? null,
|
|
105
107
|
utxoData_referenceScriptType: input.referenceScriptType ?? null,
|
|
108
|
+
utxoData_paymentCredential: paymentCredentialOf(input.address),
|
|
106
109
|
// outpoint of the consumed UTxO
|
|
107
110
|
spentTxHash: input.txHash || null,
|
|
108
111
|
spentOutputIndex: Number.isInteger(input.outputIndex) ? input.outputIndex : null,
|
|
@@ -201,6 +204,10 @@ function mapTransactionRedeemers(txHash, redeemers) {
|
|
|
201
204
|
policyId: r.policyId ?? null,
|
|
202
205
|
}));
|
|
203
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
|
+
}
|
|
204
211
|
/** Provider transaction outputs to TransactionOutputRows. */
|
|
205
212
|
function mapTransactionOutputs(txSeq, txOutputs) {
|
|
206
213
|
return txOutputs.map((output) => {
|
|
@@ -216,6 +223,7 @@ function mapTransactionOutputs(txSeq, txOutputs) {
|
|
|
216
223
|
utxo_referenceScriptHash: output.referenceScriptHash || null,
|
|
217
224
|
utxo_referenceScriptSize: output.referenceScriptSize ?? null,
|
|
218
225
|
utxo_referenceScriptType: output.referenceScriptType ?? null,
|
|
226
|
+
utxo_paymentCredential: paymentCredentialOf(output.address),
|
|
219
227
|
hasAddresses: hasAddresses,
|
|
220
228
|
hasAssets: hasAssets,
|
|
221
229
|
};
|
|
@@ -351,6 +359,7 @@ function mapAddressUtxos(addr, validFrom, validTo, addressUtxosData) {
|
|
|
351
359
|
utxodata_referenceScriptHash: utxo.scriptRef && utxo.scriptRef.length <= 64 ? utxo.scriptRef : null,
|
|
352
360
|
utxodata_referenceScriptSize: utxo.scriptRefSize ?? null,
|
|
353
361
|
utxodata_referenceScriptType: utxo.scriptRefType ?? null,
|
|
362
|
+
utxodata_paymentCredential: paymentCredentialOf(addr),
|
|
354
363
|
lovelace: lovelace,
|
|
355
364
|
validFrom: validFrom,
|
|
356
365
|
validTo: validTo,
|
|
@@ -581,6 +590,8 @@ function mapAsset(providerAssetInfo, max_age) {
|
|
|
581
590
|
registryName: providerAssetInfo.registryName,
|
|
582
591
|
registryTicker: providerAssetInfo.registryTicker,
|
|
583
592
|
registryDecimals: providerAssetInfo.registryDecimals,
|
|
593
|
+
// the registry value until the caller resolves a CIP-68 reference datum
|
|
594
|
+
decimals: providerAssetInfo.registryDecimals,
|
|
584
595
|
registryDescription: providerAssetInfo.registryDescription,
|
|
585
596
|
registryUrl: providerAssetInfo.registryUrl,
|
|
586
597
|
registryLogo: providerAssetInfo.registryLogo,
|
|
@@ -620,6 +631,7 @@ function mapBareAsset(unit) {
|
|
|
620
631
|
registryName: null,
|
|
621
632
|
registryTicker: null,
|
|
622
633
|
registryDecimals: null,
|
|
634
|
+
decimals: null,
|
|
623
635
|
registryDescription: null,
|
|
624
636
|
registryUrl: null,
|
|
625
637
|
registryLogo: null,
|
|
@@ -951,6 +963,10 @@ function decodeShelleyAddress(address) {
|
|
|
951
963
|
return { ...none, networkId };
|
|
952
964
|
}
|
|
953
965
|
}
|
|
966
|
+
/** Payment credential (hex) of a bech32 address; null for Byron, reward and unresolved ('') addresses. */
|
|
967
|
+
function paymentCredentialOf(address) {
|
|
968
|
+
return address ? decodeShelleyAddress(address).paymentCredential : null;
|
|
969
|
+
}
|
|
954
970
|
/** DRep credential to CIP-129 DRep ID (29 bytes): header 0x22 key hash / 0x23 script hash. */
|
|
955
971
|
function credentialToDrepId(credentialHex, isScript) {
|
|
956
972
|
const payload = Buffer.alloc(29);
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -84,6 +84,13 @@ export interface TxRedeemer {
|
|
|
84
84
|
/** mint: the policy. */
|
|
85
85
|
policyId?: Hex | null;
|
|
86
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
|
+
}
|
|
87
94
|
/** Normalized transaction */
|
|
88
95
|
export interface Transaction {
|
|
89
96
|
hash: Hex;
|
|
@@ -122,6 +129,8 @@ export interface Transaction {
|
|
|
122
129
|
withdrawals?: TxWithdrawal[];
|
|
123
130
|
/** Redeemers; `[]` when the tx has none, undefined when the source does not report them (Blockfrost, Koios). */
|
|
124
131
|
redeemers?: TxRedeemer[];
|
|
132
|
+
/** Witness-set datums; same `[]` vs undefined convention as `redeemers`. */
|
|
133
|
+
datums?: TxDatum[];
|
|
125
134
|
}
|
|
126
135
|
/** Address view with current value and known UTxOs */
|
|
127
136
|
export interface Address {
|