@odatano/core 2.0.0-rc.49 → 2.0.0-rc.50
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 +6 -12
- package/@cds-models/CardanoIndexerService/index.d.ts +200 -2
- package/@cds-models/CardanoIndexerService/index.js +24 -0
- package/@cds-models/CardanoODataService/index.d.ts +49 -6
- package/@cds-models/CardanoODataService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +3 -3
- package/@cds-models/CardanoWorkerService/index.d.ts +4 -3
- package/@cds-models/index.d.ts +9 -1
- package/@cds-models/index.js +2 -1
- package/@cds-models/odatano/cardano/index.d.ts +59 -5
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/README.md +29 -17
- package/db/schema.cds +117 -24
- package/db/types.cds +8 -0
- package/package.json +17 -15
- package/scripts/migrate-schema.mjs +334 -0
- package/src/index.d.ts +7 -5
- package/src/index.js +12 -10
- package/src/plugin.js +6 -7
- package/srv/blockchain/backends/blockfrost-backend.js +9 -1
- package/srv/blockchain/backends/cardano-backend.d.ts +15 -0
- package/srv/blockchain/backends/cardano-backend.js +5 -0
- package/srv/blockchain/backends/koios-backend.js +16 -10
- package/srv/blockchain/backends/ogmios-backend.d.ts +9 -3
- package/srv/blockchain/backends/ogmios-backend.js +60 -18
- package/srv/blockchain/cardano-client.d.ts +5 -4
- package/srv/blockchain/cardano-client.js +46 -13
- package/srv/blockchain/cardano-indexer.d.ts +116 -9
- package/srv/blockchain/cardano-indexer.js +436 -189
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +153 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +23 -1
- package/srv/blockchain/crawler/asset-registry-backfill.js +91 -1
- package/srv/blockchain/crawler/certificate-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/certificate-backfill.js +10 -3
- package/srv/blockchain/crawler/crawler.d.ts +15 -0
- package/srv/blockchain/crawler/crawler.js +68 -3
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +171 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
- package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/transaction-backfill.js +12 -8
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -1
- package/srv/blockchain/signing/cose-verifier.js +144 -56
- package/srv/blockchain/signing/hsm-signer.js +2 -1
- package/srv/blockchain/signing/submission-finalizer.d.ts +15 -4
- package/srv/blockchain/signing/submission-finalizer.js +201 -69
- package/srv/blockchain/stored-chain.js +1 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +1 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +34 -54
- package/srv/blockchain/transaction-presence.d.ts +5 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.js +1 -1
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -1
- package/srv/blockchain/wallet-worker/build-request.js +25 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +1 -1
- package/srv/blockchain/wallet-worker/job-store.d.ts +17 -7
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +2 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +2 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +42 -32
- package/srv/cardano-agent-service.cds +11 -12
- package/srv/cardano-agent-service.js +2 -0
- package/srv/cardano-backend-service.cds +34 -1
- package/srv/cardano-backend-service.js +20 -17
- package/srv/cardano-indexer-service.cds +153 -12
- package/srv/cardano-indexer-service.js +175 -29
- package/srv/cardano-service.cds +67 -3
- package/srv/cardano-service.js +132 -67
- package/srv/cardano-sign-service.cds +30 -20
- package/srv/cardano-sign-service.js +13 -10
- package/srv/cardano-tx-service.cds +15 -1
- package/srv/cardano-tx-service.js +4 -1
- package/srv/cardano-worker-service.cds +16 -7
- package/srv/cardano-worker-service.js +31 -22
- package/srv/cbor/parse.js +11 -34
- package/srv/config.d.ts +113 -0
- package/srv/config.js +409 -0
- package/srv/server.d.ts +9 -14
- package/srv/server.js +32 -316
- package/srv/utils/agent-access.d.ts +9 -0
- package/srv/utils/agent-access.js +67 -0
- package/srv/utils/agent-grants-config.d.ts +0 -17
- package/srv/utils/agent-grants-config.js +6 -81
- package/srv/utils/agent-grants.d.ts +6 -19
- package/srv/utils/agent-grants.js +69 -130
- package/srv/utils/const.d.ts +4 -0
- package/srv/utils/const.js +5 -1
- package/srv/utils/db-indexes.js +11 -3
- package/srv/utils/error-codes.d.ts +4 -0
- package/srv/utils/error-codes.js +4 -0
- package/srv/utils/errors.d.ts +6 -0
- package/srv/utils/errors.js +23 -1
- package/srv/utils/liveness.js +2 -5
- package/srv/utils/mappers.d.ts +5 -7
- package/srv/utils/mappers.js +22 -9
- package/srv/utils/pg-order-nulls.js +4 -3
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/tx-request-parsers.d.ts +1 -1
- package/srv/utils/tx-request-parsers.js +3 -3
- package/srv/utils/tx-utils.d.ts +3 -0
- package/srv/utils/tx-utils.js +17 -3
- package/srv/utils/types.d.ts +16 -3
- package/scripts/migrate-txseq.mjs +0 -138
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -13
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +0 -71
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -15
- package/srv/blockchain/transaction-building/caller-datums.js +0 -133
- package/srv/cbor/redeemer-tag-patch.d.ts +0 -3
- package/srv/cbor/redeemer-tag-patch.js +0 -61
- package/srv/utils/legacy-service-paths.d.ts +0 -11
- package/srv/utils/legacy-service-paths.js +0 -58
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Rekeys the transaction input and output tables by Transactions.txSeq in one transaction.
|
|
3
|
-
// Run with ODATANO stopped. --dry-run only reports. A database already on this layout is left alone.
|
|
4
|
-
// It also stores the new model in cds_model, so the next schema deploy sees no difference.
|
|
5
|
-
import cds from '@sap/cds';
|
|
6
|
-
|
|
7
|
-
const DRY = process.argv.includes('--dry-run');
|
|
8
|
-
const T = (name) => `odatano_cardano_${name}`;
|
|
9
|
-
const TX_SEQ_SLOT_FACTOR = 65536;
|
|
10
|
-
|
|
11
|
-
/** Old key column -> new key column, and the column the copy is ordered by after the key. */
|
|
12
|
-
const TABLES = [
|
|
13
|
-
{ name: 'TransactionInputs', hashKey: 'tx_hash', seqKey: 'txSeq', order: 'inputIndex' },
|
|
14
|
-
{ name: 'TransactionOutputs', hashKey: 'tx_hash', seqKey: 'txSeq', order: 'outputIndex' },
|
|
15
|
-
{ name: 'TransactionInputAssets', hashKey: 'input_tx_hash', seqKey: 'input_txSeq', order: 'input_inputIndex, unit' },
|
|
16
|
-
{ name: 'TransactionOutputAssets', hashKey: 'output_tx_hash', seqKey: 'output_txSeq', order: 'output_outputIndex, unit' },
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
/** Column names of a table, lower-cased (PostgreSQL folds unquoted identifiers). */
|
|
20
|
-
export async function tableColumns(db, table) {
|
|
21
|
-
const rows = db.kind === 'postgres'
|
|
22
|
-
? await db.run(`SELECT column_name AS name FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = '${table.toLowerCase()}'`)
|
|
23
|
-
: await db.run(`SELECT name FROM pragma_table_info('${table}')`);
|
|
24
|
-
return rows.map(r => String(r.name).toLowerCase());
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** CREATE statements of the compiled model for one table (renamed) and for every view. */
|
|
28
|
-
export function modelStatements(model, options) {
|
|
29
|
-
const sql = cds.compile.to.sql(model, options);
|
|
30
|
-
const views = sql.filter(s => /^CREATE VIEW/i.test(s.trim()));
|
|
31
|
-
const tableDdl = (name) => {
|
|
32
|
-
const stmt = sql.find(s => new RegExp(`^CREATE TABLE ${T(name)} \\(`, 'i').test(s.trim()));
|
|
33
|
-
if (!stmt) throw new Error(`model has no table ${T(name)}`);
|
|
34
|
-
return stmt;
|
|
35
|
-
};
|
|
36
|
-
return { views, tableDdl };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const viewName = (stmt) => stmt.trim().match(/^CREATE VIEW\s+("?[\w.]+"?)/i)[1];
|
|
40
|
-
|
|
41
|
-
/** Copy statement: every column of the old table except the hash key, the new key from Transactions. */
|
|
42
|
-
export function copySql(spec, oldColumns) {
|
|
43
|
-
const others = oldColumns.filter(c => c !== spec.hashKey.toLowerCase());
|
|
44
|
-
const target = [spec.seqKey, ...others].join(', ');
|
|
45
|
-
const source = ['t.txSeq', ...others.map(c => `x.${c}`)].join(', ');
|
|
46
|
-
const order = ['t.txSeq', ...spec.order.split(',').map(c => `x.${c.trim()}`)].join(', ');
|
|
47
|
-
return `INSERT INTO ${T(spec.name)}_txseq_new (${target}) SELECT ${source} FROM ${T(spec.name)} x `
|
|
48
|
-
+ `JOIN ${T('Transactions')} t ON t.hash = x.${spec.hashKey} ORDER BY ${order}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function count(tx, table) {
|
|
52
|
-
const [row] = await tx.run(`SELECT count(*) AS n FROM ${table}`);
|
|
53
|
-
return Number(row.n);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function main() {
|
|
57
|
-
const db = await cds.connect.to('db');
|
|
58
|
-
if (db.kind !== 'postgres' && db.kind !== 'sqlite') throw new Error(`unsupported database kind ${db.kind}: re-crawl instead`);
|
|
59
|
-
|
|
60
|
-
const inputColumns = await tableColumns(db, T('TransactionInputs'));
|
|
61
|
-
if (!inputColumns.includes('tx_hash')) {
|
|
62
|
-
console.log('Already on the txSeq layout; nothing to do.');
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const [lease] = await db.run(`SELECT leaseUntil FROM ${T('CardanoSyncState')}`).catch(() => []);
|
|
67
|
-
const leaseUntil = lease?.leaseUntil ?? lease?.leaseuntil;
|
|
68
|
-
if (leaseUntil && Date.parse(leaseUntil) > Date.now()) {
|
|
69
|
-
throw new Error(`the crawler lease is held until ${leaseUntil}: stop ODATANO first`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// the model exactly as `cds deploy` compiles it
|
|
73
|
-
const model = await cds.load('*').then(cds.minify);
|
|
74
|
-
cds.deploy.exclude_external_entities_in(model);
|
|
75
|
-
const options = { ...db.options };
|
|
76
|
-
const { views, tableDdl } = modelStatements(model, options);
|
|
77
|
-
const [hasModelTable] = await db.run(db.kind === 'postgres'
|
|
78
|
-
? `SELECT 1 AS x FROM pg_tables WHERE tablename = 'cds_model' AND schemaname = current_schema()`
|
|
79
|
-
: `SELECT 1 AS x FROM sqlite_schema WHERE name = 'cds_model'`);
|
|
80
|
-
|
|
81
|
-
const txNull = Number((await db.run(`SELECT count(*) AS n FROM ${T('Transactions')} WHERE slot IS NULL OR txIndex IS NULL`))[0].n);
|
|
82
|
-
if (txNull > 0) throw new Error(`${txNull} transactions have no slot or txIndex; their txSeq cannot be derived`);
|
|
83
|
-
|
|
84
|
-
const plan = [];
|
|
85
|
-
for (const spec of TABLES) plan.push({ spec, columns: await tableColumns(db, T(spec.name)), rows: await count(db, T(spec.name)) });
|
|
86
|
-
for (const p of plan) console.log(`${T(p.spec.name)}: ${p.rows} rows, key ${p.spec.hashKey} -> ${p.spec.seqKey}`);
|
|
87
|
-
console.log(`${views.length} views recreated${hasModelTable ? ', cds_model updated' : ''}`);
|
|
88
|
-
if (DRY) { console.log('dry run: nothing changed'); return; }
|
|
89
|
-
|
|
90
|
-
await db.tx(async (tx) => {
|
|
91
|
-
const started = Date.now();
|
|
92
|
-
const step = (msg) => console.log(`[${Math.round((Date.now() - started) / 1000)}s] ${msg}`);
|
|
93
|
-
|
|
94
|
-
for (const stmt of [...views].reverse()) {
|
|
95
|
-
await tx.run(`DROP VIEW IF EXISTS ${viewName(stmt)}${db.kind === 'postgres' ? ' CASCADE' : ''}`);
|
|
96
|
-
}
|
|
97
|
-
step('views dropped');
|
|
98
|
-
|
|
99
|
-
const txColumns = await tableColumns(tx, T('Transactions'));
|
|
100
|
-
if (!txColumns.includes('txseq')) await tx.run(`ALTER TABLE ${T('Transactions')} ADD COLUMN txSeq BIGINT`);
|
|
101
|
-
await tx.run(`UPDATE ${T('Transactions')} SET txSeq = slot * ${TX_SEQ_SLOT_FACTOR} + txIndex`);
|
|
102
|
-
await tx.run(`CREATE INDEX IF NOT EXISTS odatano_cardano_transactions_txseq ON ${T('Transactions')} (txSeq)`);
|
|
103
|
-
step('Transactions.txSeq filled');
|
|
104
|
-
|
|
105
|
-
for (const { spec, columns, rows } of plan) {
|
|
106
|
-
const table = T(spec.name);
|
|
107
|
-
const newTable = `${table}_txseq_new`;
|
|
108
|
-
await tx.run(tableDdl(spec.name).replace(new RegExp(`^(\\s*CREATE TABLE )${table}\\b`, 'i'), `$1${newTable}`));
|
|
109
|
-
await tx.run(copySql(spec, columns));
|
|
110
|
-
const copied = await count(tx, newTable);
|
|
111
|
-
if (copied !== rows) throw new Error(`${table}: ${rows} rows, ${copied} copied (rows without a Transactions row?)`);
|
|
112
|
-
await tx.run(`DROP TABLE ${table}`);
|
|
113
|
-
await tx.run(`ALTER TABLE ${newTable} RENAME TO ${table}`);
|
|
114
|
-
if (db.kind === 'postgres') {
|
|
115
|
-
await tx.run(`ALTER TABLE ${table} RENAME CONSTRAINT ${newTable.toLowerCase()}_pkey TO ${table.toLowerCase()}_pkey`);
|
|
116
|
-
}
|
|
117
|
-
step(`${table}: ${copied} rows`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
for (const stmt of views) await tx.run(stmt);
|
|
121
|
-
step('views recreated');
|
|
122
|
-
|
|
123
|
-
// fresh planner statistics: without them the rebuilt tables are read by sequential scans
|
|
124
|
-
for (const name of ['Transactions', ...TABLES.map(t => t.name)]) await tx.run(`ANALYZE ${T(name)}`);
|
|
125
|
-
step('statistics updated');
|
|
126
|
-
|
|
127
|
-
if (hasModelTable) {
|
|
128
|
-
const { afterImage } = cds.compile.to.sql.delta(model, options);
|
|
129
|
-
await tx.run(db.kind === 'postgres' ? 'UPDATE cds_model SET csn = $1' : 'UPDATE cds_model SET csn = ?', [JSON.stringify(afterImage)]);
|
|
130
|
-
step('cds_model updated');
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
console.log('Migration to the txSeq layout done. Start ODATANO; it recreates the table indexes.');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (process.argv[1] && import.meta.url === (await import('node:url')).pathToFileURL(process.argv[1]).href) {
|
|
137
|
-
main().then(() => process.exit(0), (err) => { console.error(`FAILED: ${err.message}`); process.exit(1); });
|
|
138
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Tx } from '@harmoniclabs/cardano-ledger-ts';
|
|
2
|
-
/** Conway reference-script fee: the price per byte rises by 1.2 for every tier of this many bytes. */
|
|
3
|
-
export declare const REF_SCRIPT_TIER_BYTES = 25600n;
|
|
4
|
-
export interface Rational {
|
|
5
|
-
num: bigint;
|
|
6
|
-
den: bigint;
|
|
7
|
-
}
|
|
8
|
-
export declare function tierRefScriptFee(totalBytes: bigint, pricePerByte: Rational): bigint;
|
|
9
|
-
/** Reference-script bytes of the inputs and reference inputs as one set. A UTxO in both counts once, the same script on two UTxOs twice. */
|
|
10
|
-
export declare function refScriptBytesOf(tx: Tx): bigint;
|
|
11
|
-
/** Replace `TxBuilder.prototype.calcMinFee` once per process. */
|
|
12
|
-
export declare function installReferenceScriptFeePatch(): void;
|
|
13
|
-
//# sourceMappingURL=buildooor-fee-patch.d.ts.map
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REF_SCRIPT_TIER_BYTES = void 0;
|
|
4
|
-
exports.tierRefScriptFee = tierRefScriptFee;
|
|
5
|
-
exports.refScriptBytesOf = refScriptBytesOf;
|
|
6
|
-
exports.installReferenceScriptFeePatch = installReferenceScriptFeePatch;
|
|
7
|
-
const buildooor_1 = require("@harmoniclabs/buildooor");
|
|
8
|
-
const utils_1 = require("@harmoniclabs/buildooor/dist/TxBuilder/utils");
|
|
9
|
-
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
10
|
-
const reference_script_1 = require("../../utils/reference-script");
|
|
11
|
-
/** Conway reference-script fee: the price per byte rises by 1.2 for every tier of this many bytes. */
|
|
12
|
-
exports.REF_SCRIPT_TIER_BYTES = 25600n;
|
|
13
|
-
// Ledger reference-script fee: priced tier by tier, each tier 1.2 times the previous.
|
|
14
|
-
// Exact rationals, floored once at the end.
|
|
15
|
-
function tierRefScriptFee(totalBytes, pricePerByte) {
|
|
16
|
-
let remaining = totalBytes;
|
|
17
|
-
let priceNum = pricePerByte.num;
|
|
18
|
-
let priceDen = pricePerByte.den;
|
|
19
|
-
let accNum = 0n;
|
|
20
|
-
let accDen = 1n;
|
|
21
|
-
const add = (bytes) => {
|
|
22
|
-
accNum = accNum * priceDen + bytes * priceNum * accDen;
|
|
23
|
-
accDen *= priceDen;
|
|
24
|
-
};
|
|
25
|
-
while (remaining >= exports.REF_SCRIPT_TIER_BYTES) {
|
|
26
|
-
add(exports.REF_SCRIPT_TIER_BYTES);
|
|
27
|
-
priceNum *= 6n;
|
|
28
|
-
priceDen *= 5n;
|
|
29
|
-
remaining -= exports.REF_SCRIPT_TIER_BYTES;
|
|
30
|
-
}
|
|
31
|
-
add(remaining);
|
|
32
|
-
return accNum / accDen;
|
|
33
|
-
}
|
|
34
|
-
/** Reference-script bytes of the inputs and reference inputs as one set. A UTxO in both counts once, the same script on two UTxOs twice. */
|
|
35
|
-
function refScriptBytesOf(tx) {
|
|
36
|
-
const utxos = new Map();
|
|
37
|
-
for (const u of [...tx.body.inputs, ...(tx.body.refInputs ?? [])])
|
|
38
|
-
utxos.set(u.utxoRef.toString(), u);
|
|
39
|
-
return [...utxos.values()].reduce((sum, u) => sum + BigInt(u.resolved.refScript ? (0, reference_script_1.referenceScriptSize)(u.resolved.refScript) : 0), 0n);
|
|
40
|
-
}
|
|
41
|
-
function refScriptPrice(pp) {
|
|
42
|
-
const r = (0, cardano_ledger_ts_1.cborFromRational)(pp.minfeeRefScriptCostPerByte ?? cardano_ledger_ts_1.defaultProtocolParameters.minfeeRefScriptCostPerByte);
|
|
43
|
-
return { num: BigInt(r.num), den: BigInt(r.den) };
|
|
44
|
-
}
|
|
45
|
-
// `TxBuilder.calcMinFee` with the ledger's reference-script rule. Buildooor prices only reference
|
|
46
|
-
// inputs, linearly. The ledger also counts scripts on spent inputs and prices them in tiers.
|
|
47
|
-
function calcMinFeeWithRefScripts(tx, minimum) {
|
|
48
|
-
const self = this;
|
|
49
|
-
const pp = self.protocolParamters;
|
|
50
|
-
const perByte = BigInt(pp.txFeePerByte ?? cardano_ledger_ts_1.defaultProtocolParameters.txFeePerByte);
|
|
51
|
-
const nVkeyWits = BigInt((0, utils_1.estimateMaxSignersNeeded)(tx));
|
|
52
|
-
const minFee = self.calcLinearFee(tx)
|
|
53
|
-
+ tierRefScriptFee(refScriptBytesOf(tx), refScriptPrice(pp))
|
|
54
|
-
// one key witness is 102 CBOR bytes plus 2 for encoding slack, plus the array header
|
|
55
|
-
+ 104n * nVkeyWits * perByte
|
|
56
|
-
+ BigInt(nVkeyWits < 24n ? 1 : nVkeyWits < 256n ? 2 : 4) * perByte;
|
|
57
|
-
if (minimum === undefined || minimum === null)
|
|
58
|
-
return minFee;
|
|
59
|
-
const min = BigInt(minimum);
|
|
60
|
-
return minFee < min ? min : minFee;
|
|
61
|
-
}
|
|
62
|
-
const PATCHED = Symbol.for('odatano.buildooor.refScriptFee');
|
|
63
|
-
/** Replace `TxBuilder.prototype.calcMinFee` once per process. */
|
|
64
|
-
function installReferenceScriptFeePatch() {
|
|
65
|
-
const proto = buildooor_1.TxBuilder.prototype;
|
|
66
|
-
if (proto[PATCHED])
|
|
67
|
-
return;
|
|
68
|
-
proto.calcMinFee = calcMinFeeWithRefScripts;
|
|
69
|
-
proto[PATCHED] = true;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=buildooor-fee-patch.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Tx } from "@harmoniclabs/cardano-ledger-ts";
|
|
2
|
-
export type CallerDatums = Map<number, Uint8Array>;
|
|
3
|
-
/** Bytes one output gains when its datum is written as given; negative when it shrinks. */
|
|
4
|
-
export declare function callerDatumGrowth(datum: Uint8Array): number;
|
|
5
|
-
/** Bytes the whole transaction gains from the caller's datums, never below zero. */
|
|
6
|
-
export declare function callerDatumsGrowth(datums: CallerDatums): number;
|
|
7
|
-
export declare function writeCallerDatums(tx: Tx, datums: CallerDatums): Tx;
|
|
8
|
-
/** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
|
|
9
|
-
export declare function datumHashOf(datum: Uint8Array): string;
|
|
10
|
-
/** Bytes the witness set gains from the caller's datums, never below zero. */
|
|
11
|
-
export declare function witnessDatumsGrowth(datums: Uint8Array[]): number;
|
|
12
|
-
export declare function writeWitnessDatums(tx: Tx, datums: Uint8Array[], languageViews: Uint8Array): Tx;
|
|
13
|
-
/** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
|
|
14
|
-
export declare function scriptDataHashOf(txBytes: Uint8Array, languageViews: Uint8Array): Uint8Array;
|
|
15
|
-
//# sourceMappingURL=caller-datums.d.ts.map
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callerDatumGrowth = callerDatumGrowth;
|
|
4
|
-
exports.callerDatumsGrowth = callerDatumsGrowth;
|
|
5
|
-
exports.writeCallerDatums = writeCallerDatums;
|
|
6
|
-
exports.datumHashOf = datumHashOf;
|
|
7
|
-
exports.witnessDatumsGrowth = witnessDatumsGrowth;
|
|
8
|
-
exports.writeWitnessDatums = writeWitnessDatums;
|
|
9
|
-
exports.scriptDataHashOf = scriptDataHashOf;
|
|
10
|
-
const cbor_1 = require("@harmoniclabs/cbor");
|
|
11
|
-
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
12
|
-
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
13
|
-
const crypto_1 = require("@harmoniclabs/crypto");
|
|
14
|
-
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
15
|
-
/** Output map entry `2 => [1, #6.24(datum)]` that holds an inline datum. */
|
|
16
|
-
function inlineDatumEntry(datum) {
|
|
17
|
-
return Buffer.concat([Buffer.from([0x02, 0x82, 0x01]), Buffer.from(cbor_1.Cbor.encode(new cbor_1.CborTag(24, new cbor_1.CborBytes(datum))))]);
|
|
18
|
-
}
|
|
19
|
-
/** Bytes one output gains when its datum is written as given; negative when it shrinks. */
|
|
20
|
-
function callerDatumGrowth(datum) {
|
|
21
|
-
return inlineDatumEntry(datum).length - inlineDatumEntry((0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum))).length;
|
|
22
|
-
}
|
|
23
|
-
/** Bytes the whole transaction gains from the caller's datums, never below zero. */
|
|
24
|
-
function callerDatumsGrowth(datums) {
|
|
25
|
-
let growth = 0;
|
|
26
|
-
for (const datum of datums.values())
|
|
27
|
-
growth += callerDatumGrowth(datum);
|
|
28
|
-
return Math.max(0, growth);
|
|
29
|
-
}
|
|
30
|
-
// Only the datum bytes change. CBOR containers count items, not bytes, so the rest stays valid.
|
|
31
|
-
function writeCallerDatums(tx, datums) {
|
|
32
|
-
if (datums.size === 0)
|
|
33
|
-
return tx;
|
|
34
|
-
let bytes = Buffer.from(tx.toCbor());
|
|
35
|
-
const outputs = cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes)).body.outputs;
|
|
36
|
-
// Last output first, so the offsets of earlier outputs stay valid
|
|
37
|
-
for (const index of [...datums.keys()].sort((a, b) => b - a)) {
|
|
38
|
-
const out = outputs[index];
|
|
39
|
-
const ref = out?.cborRef;
|
|
40
|
-
if (!out || !ref || out.datum === undefined || out.datum instanceof cardano_ledger_ts_1.Hash32) {
|
|
41
|
-
throw new Error(`output ${index} of the built transaction carries no inline datum`);
|
|
42
|
-
}
|
|
43
|
-
const built = inlineDatumEntry((0, plutus_data_1.dataToCbor)(out.datum));
|
|
44
|
-
const at = bytes.subarray(ref.start, ref.end).indexOf(built);
|
|
45
|
-
if (at < 0)
|
|
46
|
-
throw new Error(`inline datum of output ${index} not found in the built transaction`);
|
|
47
|
-
const start = ref.start + at;
|
|
48
|
-
bytes = Buffer.concat([bytes.subarray(0, start), inlineDatumEntry(datums.get(index)), bytes.subarray(start + built.length)]);
|
|
49
|
-
}
|
|
50
|
-
return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
|
|
51
|
-
}
|
|
52
|
-
/** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
|
|
53
|
-
function datumHashOf(datum) {
|
|
54
|
-
return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(datum));
|
|
55
|
-
}
|
|
56
|
-
/** Bytes the witness set gains from the caller's datums, never below zero. */
|
|
57
|
-
function witnessDatumsGrowth(datums) {
|
|
58
|
-
let growth = 0;
|
|
59
|
-
for (const datum of datums)
|
|
60
|
-
growth += datum.length - (0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)).length;
|
|
61
|
-
return Math.max(0, growth);
|
|
62
|
-
}
|
|
63
|
-
/** End offset of a parsed item; a tag carries no offset of its own, its content does. */
|
|
64
|
-
function endOf(item) {
|
|
65
|
-
let inner = item;
|
|
66
|
-
while (inner instanceof cbor_1.CborTag)
|
|
67
|
-
inner = inner.data;
|
|
68
|
-
return inner.subCborRef.end;
|
|
69
|
-
}
|
|
70
|
-
/** Length of a CBOR item head, from its first byte. */
|
|
71
|
-
function headLength(first) {
|
|
72
|
-
const info = first & 0x1f;
|
|
73
|
-
return info < 24 || info === 31 ? 1 : info === 24 ? 2 : info === 25 ? 3 : info === 26 ? 5 : 9;
|
|
74
|
-
}
|
|
75
|
-
function entryOf(map, key) {
|
|
76
|
-
return map.map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === key);
|
|
77
|
-
}
|
|
78
|
-
/** Bytes of a map entry's value as they stand in `bytes`. */
|
|
79
|
-
function valueBytes(bytes, entry) {
|
|
80
|
-
return bytes.subarray(entry.k.subCborRef.end, endOf(entry.v));
|
|
81
|
-
}
|
|
82
|
-
// The ledger finds a witness datum by the hash of its bytes, so the caller's bytes go back in.
|
|
83
|
-
// Then scriptDataHash is recomputed over redeemers, datums and language views.
|
|
84
|
-
function writeWitnessDatums(tx, datums, languageViews) {
|
|
85
|
-
const wanted = new Map();
|
|
86
|
-
for (const datum of datums) {
|
|
87
|
-
const built = (0, uint8array_utils_1.toHex)((0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)));
|
|
88
|
-
if (built !== (0, uint8array_utils_1.toHex)(datum))
|
|
89
|
-
wanted.set(built, datum);
|
|
90
|
-
}
|
|
91
|
-
if (wanted.size === 0)
|
|
92
|
-
return tx;
|
|
93
|
-
let bytes = Buffer.from(tx.toCbor());
|
|
94
|
-
let root = cbor_1.Cbor.parse(bytes, { keepRef: true });
|
|
95
|
-
const datumsEntry = entryOf(root.array[1], 4);
|
|
96
|
-
let list = datumsEntry?.v;
|
|
97
|
-
while (list instanceof cbor_1.CborTag)
|
|
98
|
-
list = list.data;
|
|
99
|
-
if (!(list instanceof cbor_1.CborArray))
|
|
100
|
-
throw new Error('the built transaction carries no witness datums');
|
|
101
|
-
// Rebuild the datum list item by item: head, items, and the break byte of an indefinite list
|
|
102
|
-
const listStart = list.subCborRef.start;
|
|
103
|
-
const listEnd = list.subCborRef.end;
|
|
104
|
-
let at = listStart + headLength(bytes[listStart]);
|
|
105
|
-
const parts = [bytes.subarray(listStart, at)];
|
|
106
|
-
for (const item of list.array) {
|
|
107
|
-
const end = endOf(item);
|
|
108
|
-
parts.push(wanted.get((0, uint8array_utils_1.toHex)(bytes.subarray(at, end))) ?? bytes.subarray(at, end));
|
|
109
|
-
at = end;
|
|
110
|
-
}
|
|
111
|
-
parts.push(bytes.subarray(at, listEnd));
|
|
112
|
-
bytes = Buffer.concat([bytes.subarray(0, listStart), ...parts, bytes.subarray(listEnd)]);
|
|
113
|
-
root = cbor_1.Cbor.parse(bytes, { keepRef: true });
|
|
114
|
-
const hashEntry = entryOf(root.array[0], 11);
|
|
115
|
-
if (!hashEntry)
|
|
116
|
-
throw new Error('the built transaction carries no scriptDataHash');
|
|
117
|
-
bytes.set(scriptDataHashOf(bytes, languageViews), endOf(hashEntry.v) - 32);
|
|
118
|
-
return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
|
|
119
|
-
}
|
|
120
|
-
/** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
|
|
121
|
-
function scriptDataHashOf(txBytes, languageViews) {
|
|
122
|
-
const bytes = Buffer.from(txBytes);
|
|
123
|
-
const witnesses = cbor_1.Cbor.parse(bytes, { keepRef: true }).array[1];
|
|
124
|
-
const redeemers = entryOf(witnesses, 5);
|
|
125
|
-
const datums = entryOf(witnesses, 4);
|
|
126
|
-
if (!redeemers && !datums)
|
|
127
|
-
throw new Error('the transaction carries no redeemers and no datums');
|
|
128
|
-
const datumBytes = datums ? valueBytes(bytes, datums) : Buffer.alloc(0);
|
|
129
|
-
return (0, crypto_1.blake2b_256)(redeemers
|
|
130
|
-
? Buffer.concat([valueBytes(bytes, redeemers), datumBytes, languageViews])
|
|
131
|
-
: Buffer.concat([Buffer.from([0xa0]), datumBytes, Buffer.from([0xa0])]));
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=caller-datums.js.map
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installRedeemerTagPatch = installRedeemerTagPatch;
|
|
4
|
-
const cbor_1 = require("@harmoniclabs/cbor");
|
|
5
|
-
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
6
|
-
// The TxRedeemer constructor accepts only tags 0 to 3, so Tx.fromCbor throws on Conway voting and
|
|
7
|
-
// proposing redeemers. Decode and clone them with tag 0, then set the real tag.
|
|
8
|
-
const CONWAY_TAGS = new Set([cardano_ledger_ts_1.TxRedeemerTag.Voting, cardano_ledger_ts_1.TxRedeemerTag.Proposing]);
|
|
9
|
-
const PLACEHOLDER = new cbor_1.CborUInt(cardano_ledger_ts_1.TxRedeemerTag.Spend);
|
|
10
|
-
function conwayTag(head) {
|
|
11
|
-
const first = head.array[0];
|
|
12
|
-
if (!(first instanceof cbor_1.CborUInt))
|
|
13
|
-
return undefined;
|
|
14
|
-
const tag = Number(first.num);
|
|
15
|
-
return CONWAY_TAGS.has(tag) ? tag : undefined;
|
|
16
|
-
}
|
|
17
|
-
// Swaps the tag in the parsed CBOR for the call only. The CBOR object keeps its byte reference.
|
|
18
|
-
function decodeWithPlaceholder(head, decode) {
|
|
19
|
-
const tag = conwayTag(head);
|
|
20
|
-
if (tag === undefined)
|
|
21
|
-
return decode();
|
|
22
|
-
const original = head.array[0];
|
|
23
|
-
head.array[0] = PLACEHOLDER;
|
|
24
|
-
try {
|
|
25
|
-
const redeemer = decode();
|
|
26
|
-
redeemer.tag = tag;
|
|
27
|
-
return redeemer;
|
|
28
|
-
}
|
|
29
|
-
finally {
|
|
30
|
-
head.array[0] = original;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const PATCHED = Symbol.for('odatano.ledger-ts.redeemerTags');
|
|
34
|
-
/** Let `TxRedeemer` decode and clone Voting and Proposing redeemers. Once per process. */
|
|
35
|
-
function installRedeemerTagPatch() {
|
|
36
|
-
const cls = cardano_ledger_ts_1.TxRedeemer;
|
|
37
|
-
if (cls[PATCHED])
|
|
38
|
-
return;
|
|
39
|
-
const fromCborObj = cls.fromCborObj;
|
|
40
|
-
const fromCborMapEntry = cls.fromCborMapEntry;
|
|
41
|
-
const clone = cardano_ledger_ts_1.TxRedeemer.prototype.clone;
|
|
42
|
-
cls.fromCborObj = (cObj) => cObj instanceof cbor_1.CborArray ? decodeWithPlaceholder(cObj, () => fromCborObj(cObj)) : fromCborObj(cObj);
|
|
43
|
-
cls.fromCborMapEntry = (entry) => entry?.k instanceof cbor_1.CborArray ? decodeWithPlaceholder(entry.k, () => fromCborMapEntry(entry)) : fromCborMapEntry(entry);
|
|
44
|
-
cardano_ledger_ts_1.TxRedeemer.prototype.clone = function () {
|
|
45
|
-
const self = this;
|
|
46
|
-
const tag = self.tag;
|
|
47
|
-
if (!CONWAY_TAGS.has(tag))
|
|
48
|
-
return clone.call(this);
|
|
49
|
-
self.tag = cardano_ledger_ts_1.TxRedeemerTag.Spend;
|
|
50
|
-
try {
|
|
51
|
-
const copy = clone.call(this);
|
|
52
|
-
copy.tag = tag;
|
|
53
|
-
return copy;
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
self.tag = tag;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
cls[PATCHED] = true;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=redeemer-tag-patch.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
/** Old service path -> the path the service is mounted at. */
|
|
3
|
-
export declare const LEGACY_SERVICE_PATHS: Readonly<Record<string, string>>;
|
|
4
|
-
/** The URL on the new path, or null when it is not on an old path (`/odata/v4/cardano-odata-x` is not). */
|
|
5
|
-
export declare function rewriteLegacyServicePath(url: string): string | null;
|
|
6
|
-
export declare function legacyServicePathMiddleware(req: Request, _res: Response, next: NextFunction): void;
|
|
7
|
-
/** Once per process; the middleware goes onto the app at bootstrap, before the services are mounted. */
|
|
8
|
-
export declare function registerLegacyServicePaths(): void;
|
|
9
|
-
/** Forget the first-use warnings (tests). */
|
|
10
|
-
export declare function __resetLegacyServicePathsForTests(): void;
|
|
11
|
-
//# sourceMappingURL=legacy-service-paths.d.ts.map
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Serves the old service path `/odata/v4/cardano-odata` as `/odata/v4/cardano` until the 2.0.0 release.
|
|
3
|
-
// The rewrite runs before CAP mounts the services; the standalone server and the plugin both register it.
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.LEGACY_SERVICE_PATHS = void 0;
|
|
9
|
-
exports.rewriteLegacyServicePath = rewriteLegacyServicePath;
|
|
10
|
-
exports.legacyServicePathMiddleware = legacyServicePathMiddleware;
|
|
11
|
-
exports.registerLegacyServicePaths = registerLegacyServicePaths;
|
|
12
|
-
exports.__resetLegacyServicePathsForTests = __resetLegacyServicePathsForTests;
|
|
13
|
-
const cds_1 = __importDefault(require("@sap/cds"));
|
|
14
|
-
const logger = cds_1.default.log('ODATANO');
|
|
15
|
-
/** Old service path -> the path the service is mounted at. */
|
|
16
|
-
exports.LEGACY_SERVICE_PATHS = {
|
|
17
|
-
'/odata/v4/cardano-odata': '/odata/v4/cardano',
|
|
18
|
-
};
|
|
19
|
-
let registered = false;
|
|
20
|
-
// Warned once per client address, so the log names every caller still on the old path.
|
|
21
|
-
const warned = new Set();
|
|
22
|
-
/** The URL on the new path, or null when it is not on an old path (`/odata/v4/cardano-odata-x` is not). */
|
|
23
|
-
function rewriteLegacyServicePath(url) {
|
|
24
|
-
for (const [from, to] of Object.entries(exports.LEGACY_SERVICE_PATHS)) {
|
|
25
|
-
if (url === from || url.startsWith(from + '/') || url.startsWith(from + '?'))
|
|
26
|
-
return to + url.slice(from.length);
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
function legacyServicePathMiddleware(req, _res, next) {
|
|
31
|
-
const url = rewriteLegacyServicePath(req.url);
|
|
32
|
-
if (url !== null) {
|
|
33
|
-
const caller = req.ip ?? req.socket?.remoteAddress ?? 'unknown';
|
|
34
|
-
if (!warned.has(caller)) {
|
|
35
|
-
warned.add(caller);
|
|
36
|
-
logger.warn(`${caller} called ${req.url.split('?')[0]}, a deprecated service path; use ${url.split('?')[0]} (the old path goes with the 2.0.0 release)`);
|
|
37
|
-
}
|
|
38
|
-
const original = rewriteLegacyServicePath(req.originalUrl);
|
|
39
|
-
if (original !== null)
|
|
40
|
-
req.originalUrl = original;
|
|
41
|
-
req.url = url;
|
|
42
|
-
}
|
|
43
|
-
next();
|
|
44
|
-
}
|
|
45
|
-
/** Once per process; the middleware goes onto the app at bootstrap, before the services are mounted. */
|
|
46
|
-
function registerLegacyServicePaths() {
|
|
47
|
-
if (registered)
|
|
48
|
-
return;
|
|
49
|
-
registered = true;
|
|
50
|
-
cds_1.default.on('bootstrap', (app) => {
|
|
51
|
-
app.use(legacyServicePathMiddleware);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/** Forget the first-use warnings (tests). */
|
|
55
|
-
function __resetLegacyServicePathsForTests() {
|
|
56
|
-
warned.clear();
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=legacy-service-paths.js.map
|