@odatano/core 2.0.0-rc.18 → 2.0.0-rc.19
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 +52 -0
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/@cds-models/CardanoODataService/index.d.ts +170 -0
- package/@cds-models/CardanoODataService/index.js +21 -0
- package/@cds-models/odatano/cardano/index.d.ts +176 -0
- package/@cds-models/odatano/cardano/index.js +21 -0
- package/README.md +3 -3
- package/db/schema.cds +277 -0
- package/package.json +179 -179
- package/srv/blockchain/backends/cardano-backend.d.ts +16 -0
- package/srv/blockchain/backends/cardano-backend.js +4 -0
- package/srv/blockchain/backends/koios-backend.d.ts +80 -1
- package/srv/blockchain/backends/koios-backend.js +128 -48
- package/srv/blockchain/backends/ogmios-backend.d.ts +21 -2
- package/srv/blockchain/backends/ogmios-backend.js +120 -16
- package/srv/blockchain/cardano-client.d.ts +3 -1
- package/srv/blockchain/cardano-client.js +9 -0
- package/srv/blockchain/cardano-indexer.d.ts +56 -3
- package/srv/blockchain/cardano-indexer.js +124 -3
- package/srv/blockchain/crawler/crawler.d.ts +11 -1
- package/srv/blockchain/crawler/crawler.js +70 -1
- package/srv/blockchain/crawler/sync-state.d.ts +27 -1
- package/srv/blockchain/crawler/sync-state.js +83 -1
- package/srv/blockchain/crawler/utxo-set-import.d.ts +86 -0
- package/srv/blockchain/crawler/utxo-set-import.js +289 -0
- package/srv/blockchain/ledger-state.d.ts +89 -0
- package/srv/blockchain/ledger-state.js +383 -0
- package/srv/cardano-indexer-service.cds +26 -0
- package/srv/cardano-indexer-service.js +71 -0
- package/srv/cardano-service.cds +35 -0
- package/srv/server.js +6 -1
- package/srv/utils/db-indexes.js +12 -0
- package/srv/utils/mappers.d.ts +43 -3
- package/srv/utils/mappers.js +115 -1
- package/srv/utils/types.d.ts +38 -0
package/srv/utils/mappers.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.BARE_ASSET_STAMP = void 0;
|
|
|
7
7
|
exports.mapTransaction = mapTransaction;
|
|
8
8
|
exports.mapTransactionInputs = mapTransactionInputs;
|
|
9
9
|
exports.mapTransactionInputAssets = mapTransactionInputAssets;
|
|
10
|
+
exports.mapTransactionCertificates = mapTransactionCertificates;
|
|
11
|
+
exports.mapTransactionWithdrawals = mapTransactionWithdrawals;
|
|
10
12
|
exports.mapTransactionOutputs = mapTransactionOutputs;
|
|
11
13
|
exports.mapTransactionOutputAssets = mapTransactionOutputAssets;
|
|
12
14
|
exports.mapAddress = mapAddress;
|
|
@@ -39,6 +41,9 @@ exports.normalizeCostModels = normalizeCostModels;
|
|
|
39
41
|
exports.decodeAssetName = decodeAssetName;
|
|
40
42
|
exports.computeCip14Fingerprint = computeCip14Fingerprint;
|
|
41
43
|
exports.scriptHashToEnterpriseAddress = scriptHashToEnterpriseAddress;
|
|
44
|
+
exports.credentialToStakeAddress = credentialToStakeAddress;
|
|
45
|
+
exports.decodeShelleyAddress = decodeShelleyAddress;
|
|
46
|
+
exports.credentialToDrepId = credentialToDrepId;
|
|
42
47
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
43
48
|
const node_util_1 = require("node:util");
|
|
44
49
|
const blake2b_1 = __importDefault(require("blake2b"));
|
|
@@ -103,6 +108,10 @@ function mapTransactionInputs(txHash, txInputs) {
|
|
|
103
108
|
utxoData_dataHash: input.dataHash || null,
|
|
104
109
|
utxoData_inlineDatum: input.inlineDatum || null,
|
|
105
110
|
utxoData_referenceScriptHash: input.referenceScriptHash || null,
|
|
111
|
+
// Outpoint of the consumed UTxO — every source carries it in memory (the chain-sync
|
|
112
|
+
// path needs it for resolveInputs), the row just never kept it before.
|
|
113
|
+
spentTxHash: input.txHash || null,
|
|
114
|
+
spentOutputIndex: Number.isInteger(input.outputIndex) ? input.outputIndex : null,
|
|
106
115
|
isCollateral: Boolean(input.isCollateral),
|
|
107
116
|
isReference: Boolean(input.isReference),
|
|
108
117
|
hasAddresses: hasAddress,
|
|
@@ -136,6 +145,39 @@ function mapTransactionInputAssets(txHash, inputs) {
|
|
|
136
145
|
});
|
|
137
146
|
});
|
|
138
147
|
}
|
|
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
|
+
*/
|
|
154
|
+
function mapTransactionCertificates(txHash, certificates) {
|
|
155
|
+
return certificates.map((c) => ({
|
|
156
|
+
tx_hash: txHash,
|
|
157
|
+
certIndex: c.certIndex,
|
|
158
|
+
kind: c.kind,
|
|
159
|
+
stakeAddress: c.stakeAddress || null,
|
|
160
|
+
poolId: c.poolId || null,
|
|
161
|
+
drepId: c.drepId || null,
|
|
162
|
+
deposit: c.deposit != null ? String(c.deposit) : null,
|
|
163
|
+
epoch: c.epoch ?? null,
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
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
|
+
*/
|
|
172
|
+
function mapTransactionWithdrawals(txHash, withdrawals) {
|
|
173
|
+
return withdrawals
|
|
174
|
+
.filter((w) => !!w.stakeAddress)
|
|
175
|
+
.map((w) => ({
|
|
176
|
+
tx_hash: txHash,
|
|
177
|
+
stakeAddress: w.stakeAddress,
|
|
178
|
+
lovelace: String(w.amount ?? '0'),
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
139
181
|
/**
|
|
140
182
|
* Map Transaction Outputs
|
|
141
183
|
* Converts provider transaction output data into TransactionOutputRow format
|
|
@@ -648,7 +690,7 @@ exports.BARE_ASSET_STAMP = '1970-01-01T00:00:00.000Z';
|
|
|
648
690
|
* Map a bare asset row from an asset unit alone — everything derivable without a provider
|
|
649
691
|
* call: policyId, assetNameHex, the decoded name and the CIP-14 fingerprint. Used by the
|
|
650
692
|
* crawler to keep the `Assets` catalogue complete for units it meets in a block, at zero
|
|
651
|
-
* network cost (
|
|
693
|
+
* network cost (analytics coverage).
|
|
652
694
|
*
|
|
653
695
|
* The row is stamped as ALREADY EXPIRED (`validTo === validFrom`). That is deliberate: CAP's
|
|
654
696
|
* temporal filter hides it from OData reads, so the first keyed read still counts as a miss
|
|
@@ -1070,6 +1112,78 @@ function scriptHashToEnterpriseAddress(scriptHashHex, network) {
|
|
|
1070
1112
|
const hrp = network === 'mainnet' ? 'addr' : 'addr_test';
|
|
1071
1113
|
return bech32_1.bech32.encode(hrp, words, 120);
|
|
1072
1114
|
}
|
|
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
|
+
*/
|
|
1119
|
+
function credentialToStakeAddress(credentialHex, isScript, network) {
|
|
1120
|
+
const header = (isScript ? 0xf0 : 0xe0) | (network === 'mainnet' ? 0x01 : 0x00);
|
|
1121
|
+
const payload = Buffer.alloc(29);
|
|
1122
|
+
payload[0] = header;
|
|
1123
|
+
Buffer.from(credentialHex, 'hex').copy(payload, 1);
|
|
1124
|
+
const hrp = network === 'mainnet' ? 'stake' : 'stake_test';
|
|
1125
|
+
return bech32_1.bech32.encode(hrp, bech32_1.bech32.toWords(payload), 120);
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Decode the Shelley address header (CIP-19) without a provider: type, script flag and,
|
|
1129
|
+
* for base addresses, the embedded stake credential re-encoded as a reward account.
|
|
1130
|
+
* Byron (base58) and anything unparseable come back as `byron` / `unknown` with no stake.
|
|
1131
|
+
*/
|
|
1132
|
+
function decodeShelleyAddress(address) {
|
|
1133
|
+
const none = { type: 'unknown', isScript: false, stakeAddress: null, networkId: null };
|
|
1134
|
+
if (typeof address !== 'string' || !address.length)
|
|
1135
|
+
return none;
|
|
1136
|
+
let bytes;
|
|
1137
|
+
try {
|
|
1138
|
+
const decoded = bech32_1.bech32.decode(address, 120);
|
|
1139
|
+
if (decoded.prefix !== 'addr' && decoded.prefix !== 'addr_test' && decoded.prefix !== 'stake' && decoded.prefix !== 'stake_test')
|
|
1140
|
+
return none;
|
|
1141
|
+
bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
1142
|
+
}
|
|
1143
|
+
catch {
|
|
1144
|
+
// Byron addresses are base58 and start with Ae2 / DdzFF (mainnet) or 2cWKM… (testnets)
|
|
1145
|
+
return /^(Ae2|DdzFF|2cWKM|37btj|KjgoiX)/.test(address) ? { ...none, type: 'byron' } : none;
|
|
1146
|
+
}
|
|
1147
|
+
if (!bytes.length)
|
|
1148
|
+
return none;
|
|
1149
|
+
const header = bytes[0];
|
|
1150
|
+
const type = header >> 4;
|
|
1151
|
+
const networkId = header & 0x0f;
|
|
1152
|
+
const net = networkId === 1 ? 'mainnet' : 'preview';
|
|
1153
|
+
switch (type) {
|
|
1154
|
+
case 0:
|
|
1155
|
+
case 1:
|
|
1156
|
+
case 2:
|
|
1157
|
+
case 3: {
|
|
1158
|
+
const stakeAddress = bytes.length >= 57
|
|
1159
|
+
? credentialToStakeAddress(bytes.subarray(29, 57).toString('hex'), type >= 2, net)
|
|
1160
|
+
: null;
|
|
1161
|
+
return { type: 'base', isScript: type === 1 || type === 3, stakeAddress, networkId };
|
|
1162
|
+
}
|
|
1163
|
+
case 4:
|
|
1164
|
+
case 5:
|
|
1165
|
+
return { type: 'pointer', isScript: type === 5, stakeAddress: null, networkId };
|
|
1166
|
+
case 6:
|
|
1167
|
+
case 7:
|
|
1168
|
+
return { type: 'enterprise', isScript: type === 7, stakeAddress: null, networkId };
|
|
1169
|
+
case 14:
|
|
1170
|
+
case 15:
|
|
1171
|
+
return { type: 'reward', isScript: type === 15, stakeAddress: address, networkId };
|
|
1172
|
+
default:
|
|
1173
|
+
return { ...none, networkId };
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
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
|
+
*/
|
|
1181
|
+
function credentialToDrepId(credentialHex, isScript) {
|
|
1182
|
+
const payload = Buffer.alloc(29);
|
|
1183
|
+
payload[0] = isScript ? 0x23 : 0x22;
|
|
1184
|
+
Buffer.from(credentialHex, 'hex').copy(payload, 1);
|
|
1185
|
+
return bech32_1.bech32.encode('drep', bech32_1.bech32.toWords(payload), 120);
|
|
1186
|
+
}
|
|
1073
1187
|
/**
|
|
1074
1188
|
* Format error message
|
|
1075
1189
|
* @param code error code
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -49,6 +49,36 @@ export interface TxOutputLine {
|
|
|
49
49
|
isCollateral: boolean;
|
|
50
50
|
referenceScriptHash?: Hex | null;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Normalized certificate kinds. Both crawler sources map onto this vocabulary; a type
|
|
54
|
+
* neither knows is passed through as the raw source string so nothing is dropped.
|
|
55
|
+
* A Conway stake+vote delegation is SPLIT into a `pool_delegation` and a `vote_delegation`
|
|
56
|
+
* entry sharing one `certIndex` — Koios (db-sync) reports it that way natively, the
|
|
57
|
+
* Ogmios mapper splits to match, so both sources yield identical rows.
|
|
58
|
+
*/
|
|
59
|
+
export type CertificateKind = 'stake_registration' | 'stake_deregistration' | 'pool_delegation' | 'vote_delegation' | 'pool_registration' | 'pool_retirement' | 'drep_registration' | 'drep_update' | 'drep_retirement' | 'committee_hot_auth' | 'committee_resign' | 'genesis_delegation' | 'treasury_mir' | 'reserve_mir' | 'pot_transfer' | 'param_proposal' | (string & {});
|
|
60
|
+
/** One certificate of a transaction (crawler ledger-state coverage). */
|
|
61
|
+
export interface TxCertificate {
|
|
62
|
+
/** Position in the transaction's certificate list as the source reports it. */
|
|
63
|
+
certIndex: number;
|
|
64
|
+
kind: CertificateKind;
|
|
65
|
+
/** Reward account (bech32) the certificate concerns, when it has one. */
|
|
66
|
+
stakeAddress?: string | null;
|
|
67
|
+
/** Stake pool (bech32) for delegation / registration / retirement. */
|
|
68
|
+
poolId?: string | null;
|
|
69
|
+
/** DRep (CIP-129 bech32), or `drep_always_abstain` / `drep_always_no_confidence`. */
|
|
70
|
+
drepId?: string | null;
|
|
71
|
+
/** Deposit paid or refunded, lovelace as string. */
|
|
72
|
+
deposit?: Lovelace | string | null;
|
|
73
|
+
/** Retirement epoch of a pool retirement. */
|
|
74
|
+
epoch?: number | null;
|
|
75
|
+
}
|
|
76
|
+
/** One reward-account withdrawal of a transaction. */
|
|
77
|
+
export interface TxWithdrawal {
|
|
78
|
+
stakeAddress: string;
|
|
79
|
+
/** Lovelace as string. */
|
|
80
|
+
amount: Lovelace | string;
|
|
81
|
+
}
|
|
52
82
|
/**
|
|
53
83
|
* Transaction Data Structure Type - Normalized transaction structure
|
|
54
84
|
*/
|
|
@@ -94,6 +124,14 @@ export interface Transaction {
|
|
|
94
124
|
inputs: TxInputLine[];
|
|
95
125
|
outputs: TxOutputLine[];
|
|
96
126
|
metadata?: MetadataLabelTx[];
|
|
127
|
+
/**
|
|
128
|
+
* Certificates as the source reports them; `[]` when the transaction carries none,
|
|
129
|
+
* undefined when the source does not report the field at all (Blockfrost — a per-tx
|
|
130
|
+
* enumeration would cost six extra calls per transaction, so it stays unreported there).
|
|
131
|
+
*/
|
|
132
|
+
certificates?: TxCertificate[];
|
|
133
|
+
/** Reward-account withdrawals; same `[]` vs undefined convention as `certificates`. */
|
|
134
|
+
withdrawals?: TxWithdrawal[];
|
|
97
135
|
}
|
|
98
136
|
/**
|
|
99
137
|
* Address Data Structure Type - Address view, including current value and known UTxOs
|