@odatano/core 2.0.0-rc.50 → 2.0.0-rc.51
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/CardanoBackendService/index.d.ts +14 -3
- package/@cds-models/CardanoBackendService/index.js +1 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +98 -0
- package/@cds-models/CardanoIndexerService/index.js +10 -0
- package/@cds-models/CardanoODataService/index.d.ts +3 -0
- package/@cds-models/CardanoSignService/index.d.ts +13 -0
- package/@cds-models/CardanoSignService/index.js +1 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +12 -0
- package/@cds-models/CardanoTransactionService/index.js +1 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +28 -0
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +13 -3
- package/@cds-models/index.js +4 -3
- package/@cds-models/odatano/cardano/index.d.ts +14 -0
- package/README.md +45 -149
- package/db/schema.cds +63 -10
- package/db/types.cds +10 -0
- package/package.json +7 -44
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +209 -15
- package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -4
- package/srv/blockchain/backends/blockfrost-backend.js +61 -45
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +6 -3
- package/srv/blockchain/backends/koios-backend.d.ts +9 -6
- package/srv/blockchain/backends/koios-backend.js +145 -207
- package/srv/blockchain/backends/odatano-backend.d.ts +2 -1
- package/srv/blockchain/backends/odatano-backend.js +51 -9
- package/srv/blockchain/backends/ogmios-backend.d.ts +1 -2
- package/srv/blockchain/backends/ogmios-backend.js +82 -48
- package/srv/blockchain/cardano-client.d.ts +15 -5
- package/srv/blockchain/cardano-client.js +143 -71
- package/srv/blockchain/cardano-indexer.d.ts +27 -16
- package/srv/blockchain/cardano-indexer.js +223 -102
- package/srv/blockchain/circuit-breaker.d.ts +1 -0
- package/srv/blockchain/circuit-breaker.js +6 -0
- package/srv/blockchain/crawler/account-snapshots.js +22 -2
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +29 -29
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +3 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +4 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +4 -0
- package/srv/blockchain/crawler/certificate-backfill.js +15 -3
- package/srv/blockchain/crawler/crawler.d.ts +22 -1
- package/srv/blockchain/crawler/crawler.js +223 -24
- package/srv/blockchain/crawler/credential-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/credential-backfill.js +43 -66
- package/srv/blockchain/crawler/input-asset-copies.d.ts +4 -4
- package/srv/blockchain/crawler/input-asset-copies.js +17 -27
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +6 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +23 -19
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +3 -1
- package/srv/blockchain/crawler/output-datum-backfill.js +8 -18
- package/srv/blockchain/crawler/sync-state.d.ts +5 -1
- package/srv/blockchain/crawler/sync-state.js +63 -106
- package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
- package/srv/blockchain/crawler/transaction-backfill.js +6 -13
- package/srv/blockchain/crawler/utxo-set-import.js +2 -2
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +2 -2
- package/srv/blockchain/ledger-state.js +139 -37
- package/srv/blockchain/signing/external-signer.js +5 -5
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.js +10 -13
- package/srv/blockchain/signing/submission-finalizer.d.ts +17 -3
- package/srv/blockchain/signing/submission-finalizer.js +90 -29
- package/srv/blockchain/stored-chain.d.ts +1 -2
- package/srv/blockchain/stored-chain.js +36 -15
- package/srv/blockchain/transaction-building/buildooor-tx.js +16 -10
- package/srv/blockchain/transaction-presence.d.ts +8 -1
- package/srv/blockchain/transaction-presence.js +12 -12
- package/srv/blockchain/wallet-worker/build-request.d.ts +6 -6
- package/srv/blockchain/wallet-worker/build-request.js +35 -365
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +23 -2
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +140 -23
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +28 -2
- package/srv/blockchain/wallet-worker/job-store.js +107 -80
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +21 -2
- package/srv/blockchain/wallet-worker/wallet-worker.js +241 -57
- package/srv/cardano-agent-service.cds +1 -1
- package/srv/cardano-agent-service.js +8 -0
- package/srv/cardano-backend-service.cds +4 -1
- package/srv/cardano-backend-service.js +26 -9
- package/srv/cardano-indexer-service.cds +448 -387
- package/srv/cardano-indexer-service.js +226 -281
- package/srv/cardano-service.cds +7 -5
- package/srv/cardano-service.js +404 -69
- package/srv/cardano-sign-service.cds +11 -1
- package/srv/cardano-sign-service.js +161 -108
- package/srv/cardano-tx-service.cds +15 -4
- package/srv/cardano-tx-service.js +105 -604
- package/srv/cardano-worker-service.cds +25 -2
- package/srv/cardano-worker-service.js +56 -4
- package/srv/config.d.ts +4 -0
- package/srv/config.js +10 -0
- package/srv/server.js +5 -7
- package/srv/utils/agent-access.d.ts +4 -2
- package/srv/utils/agent-access.js +26 -7
- package/srv/utils/agent-grants.d.ts +1 -1
- package/srv/utils/agent-grants.js +7 -8
- package/srv/utils/agent-token-auth.js +45 -5
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +1 -0
- package/srv/utils/collections.js +11 -0
- package/srv/utils/const.d.ts +10 -2
- package/srv/utils/const.js +13 -6
- package/srv/utils/crypto.js +5 -4
- package/srv/utils/db-indexes.d.ts +5 -1
- package/srv/utils/db-indexes.js +79 -14
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +1 -0
- package/srv/utils/epoch-slots.js +7 -0
- package/srv/utils/error-codes.d.ts +4 -0
- package/srv/utils/error-codes.js +4 -0
- package/srv/utils/errors.d.ts +10 -1
- package/srv/utils/errors.js +51 -9
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/mappers.d.ts +9 -0
- package/srv/utils/mappers.js +57 -67
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +8 -3
- package/srv/utils/pg-inline-json.js +3 -3
- package/srv/utils/pg-order-nulls.js +3 -3
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/tx-build-helper.d.ts +15 -0
- package/srv/utils/tx-build-helper.js +28 -13
- package/srv/utils/types.d.ts +35 -43
- package/srv/utils/types.js +1 -17
- package/srv/utils/validators.d.ts +2 -2
- package/srv/utils/validators.js +14 -25
|
@@ -137,8 +137,8 @@ function aggregateStatements() {
|
|
|
137
137
|
`SELECT address, MIN(stakeAddress), MIN(addressType), ` +
|
|
138
138
|
`CASE WHEN MAX(CASE WHEN isScript THEN 1 ELSE 0 END) = 1 THEN TRUE ELSE FALSE END, ` +
|
|
139
139
|
`SUM(lovelace), COUNT(*), NULL, NULL FROM ${T.utxos} WHERE spentTxHash IS NULL GROUP BY address`,
|
|
140
|
-
`INSERT INTO ${T.addressAssets} (address_address, unit, asset_quantity, asset_policyId, asset_assetNameHex, asset_assetName) ` +
|
|
141
|
-
`SELECT u.address, a.unit, SUM(a.asset_quantity), MIN(a.asset_policyId), MIN(a.asset_assetNameHex), MIN(a.asset_assetName) ` +
|
|
140
|
+
`INSERT INTO ${T.addressAssets} (address_address, unit, asset_quantity, asset_policyId, asset_assetNameHex, asset_assetName, asset_fingerprint) ` +
|
|
141
|
+
`SELECT u.address, a.unit, SUM(a.asset_quantity), MIN(a.asset_policyId), MIN(a.asset_assetNameHex), MIN(a.asset_assetName), MIN(a.asset_fingerprint) ` +
|
|
142
142
|
`FROM ${T.utxoAssets} a JOIN ${T.utxos} u ON a.utxo_txHash = u.txHash AND a.utxo_outputIndex = u.outputIndex ` +
|
|
143
143
|
`WHERE u.spentTxHash IS NULL GROUP BY u.address, a.unit`,
|
|
144
144
|
`INSERT INTO ${T.accounts} (stakeAddress, controlledAmount, addressCount, utxoCount, lastActiveSlot) ` +
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Transaction as CapTransaction } from '@sap/cds';
|
|
2
|
+
/** Planner settings of a slot window walk on PostgreSQL. They end with the transaction. */
|
|
3
|
+
export declare const KEY_LOOKUPS_ONLY = "SELECT set_config('enable_seqscan', 'off', true), set_config('enable_hashjoin', 'off', true), set_config('enable_mergejoin', 'off', true)";
|
|
4
|
+
/** Window rows found through an index, joined to a value list by hash; never a scan of the table. */
|
|
5
|
+
export declare const INDEXED_JOIN = "SELECT set_config('enable_seqscan', 'off', true)";
|
|
6
|
+
/** How a window statement reaches its rows; `join` for a statement that matches window rows against a list. */
|
|
7
|
+
export type WindowPlan = 'keys' | 'join';
|
|
8
|
+
export declare function yieldToEventLoop(): Promise<void>;
|
|
9
|
+
/** Slots per window unless the caller names another size. */
|
|
10
|
+
export declare const DEFAULT_SLOT_WINDOW = 20000;
|
|
11
|
+
export declare function lookupsByKey(tx: CapTransaction, plan?: WindowPlan): Promise<void>;
|
|
12
|
+
/** First and last slot of a walk, both included. */
|
|
13
|
+
export interface SlotRange {
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function slotRangeOf(entity: unknown, asked?: {
|
|
18
|
+
fromSlot?: number | null;
|
|
19
|
+
toSlot?: number | null;
|
|
20
|
+
}): Promise<SlotRange | null>;
|
|
21
|
+
export interface SlotWalkOptions {
|
|
22
|
+
slotWindow?: number;
|
|
23
|
+
/** Stops the walk before the next window. */
|
|
24
|
+
shouldStop?: () => boolean;
|
|
25
|
+
/** Called after each window is committed, with its last slot. */
|
|
26
|
+
afterWindow?: (atSlot: number) => void;
|
|
27
|
+
/** Planner settings per window; default `keys`. */
|
|
28
|
+
plan?: WindowPlan;
|
|
29
|
+
}
|
|
30
|
+
export declare function walkSlotWindows(range: SlotRange, opts: SlotWalkOptions, step: (tx: CapTransaction, window: [lo: number, hi: number]) => Promise<void>): Promise<boolean>;
|
|
31
|
+
//# sourceMappingURL=window-plan.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_SLOT_WINDOW = exports.INDEXED_JOIN = exports.KEY_LOOKUPS_ONLY = void 0;
|
|
7
|
+
exports.yieldToEventLoop = yieldToEventLoop;
|
|
8
|
+
exports.lookupsByKey = lookupsByKey;
|
|
9
|
+
exports.slotRangeOf = slotRangeOf;
|
|
10
|
+
exports.walkSlotWindows = walkSlotWindows;
|
|
11
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
12
|
+
const mappers_1 = require("../../utils/mappers");
|
|
13
|
+
const db_kind_1 = require("../../utils/db-kind");
|
|
14
|
+
const { SELECT } = cds_1.default.ql;
|
|
15
|
+
/** Planner settings of a slot window walk on PostgreSQL. They end with the transaction. */
|
|
16
|
+
exports.KEY_LOOKUPS_ONLY = "SELECT set_config('enable_seqscan', 'off', true), set_config('enable_hashjoin', 'off', true), set_config('enable_mergejoin', 'off', true)";
|
|
17
|
+
/** Window rows found through an index, joined to a value list by hash; never a scan of the table. */
|
|
18
|
+
exports.INDEXED_JOIN = "SELECT set_config('enable_seqscan', 'off', true)";
|
|
19
|
+
// node:sqlite answers synchronously, so a loop of database statements alone never lets the server
|
|
20
|
+
// read its sockets. Awaiting this between steps keeps requests and cancelMaintenance served.
|
|
21
|
+
function yieldToEventLoop() {
|
|
22
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
23
|
+
}
|
|
24
|
+
/** Slots per window unless the caller names another size. */
|
|
25
|
+
exports.DEFAULT_SLOT_WINDOW = 20_000;
|
|
26
|
+
// A window statement touches the rows of a few slots and finds each by key. From its row estimate
|
|
27
|
+
// PostgreSQL may still plan to read a whole table for every window. This rules that plan out.
|
|
28
|
+
async function lookupsByKey(tx, plan = 'keys') {
|
|
29
|
+
if ((0, db_kind_1.connectedDbKind)() === 'postgres')
|
|
30
|
+
await tx.run(plan === 'join' ? exports.INDEXED_JOIN : exports.KEY_LOOKUPS_ONLY);
|
|
31
|
+
}
|
|
32
|
+
// The asked slots cut to the slots of the rows `entity` holds, read from its txSeq column.
|
|
33
|
+
// Null when there is nothing to walk.
|
|
34
|
+
async function slotRangeOf(entity, asked = {}) {
|
|
35
|
+
const stored = (await cds_1.default.tx((tx) => tx.run(SELECT.one.from(entity).columns('min(txSeq) as lo', 'max(txSeq) as hi'))));
|
|
36
|
+
if (stored?.lo == null || stored.hi == null)
|
|
37
|
+
return null;
|
|
38
|
+
const from = Math.max(asked.fromSlot ?? 0, Math.floor(Number(stored.lo) / mappers_1.TX_SEQ_SLOT_FACTOR));
|
|
39
|
+
const to = Math.min(asked.toSlot ?? Number.MAX_SAFE_INTEGER, Math.floor(Number(stored.hi) / mappers_1.TX_SEQ_SLOT_FACTOR));
|
|
40
|
+
return from <= to ? { from, to } : null;
|
|
41
|
+
}
|
|
42
|
+
// Calls `step` with the txSeq bounds [lo, hi) of each slot window of `range`, each window in a
|
|
43
|
+
// transaction of its own that finds rows by key. Returns false when `shouldStop` ended the walk.
|
|
44
|
+
async function walkSlotWindows(range, opts, step) {
|
|
45
|
+
const slotWindow = opts.slotWindow ?? exports.DEFAULT_SLOT_WINDOW;
|
|
46
|
+
for (let slot = range.from; slot <= range.to; slot += slotWindow) {
|
|
47
|
+
await yieldToEventLoop();
|
|
48
|
+
if (opts.shouldStop?.())
|
|
49
|
+
return false;
|
|
50
|
+
const window = [slot * mappers_1.TX_SEQ_SLOT_FACTOR, Math.min(slot + slotWindow, range.to + 1) * mappers_1.TX_SEQ_SLOT_FACTOR];
|
|
51
|
+
await cds_1.default.tx(async (tx) => {
|
|
52
|
+
await lookupsByKey(tx, opts.plan);
|
|
53
|
+
await step(tx, window);
|
|
54
|
+
});
|
|
55
|
+
opts.afterWindow?.(Math.min(slot + slotWindow - 1, range.to));
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=window-plan.js.map
|
|
@@ -23,7 +23,7 @@ export type LedgerUtxoRow = Required<Omit<LedgerUTxO, 'assets' | 'lovelace' | 'u
|
|
|
23
23
|
utxo_referenceScriptType: ReferenceScriptType | null;
|
|
24
24
|
};
|
|
25
25
|
/** A `LedgerUTxOAssets` row as the block path writes it. */
|
|
26
|
-
export type LedgerUtxoAssetRow = Required<Omit<LedgerUTxOAsset, 'utxo' | '
|
|
26
|
+
export type LedgerUtxoAssetRow = Required<Omit<LedgerUTxOAsset, 'utxo' | 'asset_quantity'>> & {
|
|
27
27
|
asset_quantity: string;
|
|
28
28
|
};
|
|
29
29
|
/** Minimal output shape the row builder needs, shared by the block path and the import. */
|
|
@@ -54,7 +54,7 @@ export declare function readLedgerOutputs(tx: CapTransaction, txHashes: Iterable
|
|
|
54
54
|
/** Amount list (lovelace + native assets) of a ledger row, the shape a resolved input carries. */
|
|
55
55
|
export declare function ledgerRowAmount(row: LedgerUtxoRow, assets: LedgerUtxoAssetRow[] | undefined): Amount[];
|
|
56
56
|
export declare function applyBlockToLedger(tx: CapTransaction, block: BlockData, txs: ProviderTransaction[], lookup?: LedgerLookup): Promise<LedgerApplyResult>;
|
|
57
|
-
export declare function undoLedgerForTransactions(tx: CapTransaction, txHashes: string[]): Promise<string[]>;
|
|
57
|
+
export declare function undoLedgerForTransactions(tx: CapTransaction, txHashes: string[], forkSlot: number): Promise<string[]>;
|
|
58
58
|
export declare function recountLedgerAddresses(tx: CapTransaction, addresses: string[]): Promise<void>;
|
|
59
59
|
/** Recount `LedgerAccounts` for the given stake keys from `LedgerAddresses`. */
|
|
60
60
|
export declare function recountLedgerAccounts(tx: CapTransaction, stakeAddresses: string[]): Promise<void>;
|
|
@@ -22,18 +22,6 @@ const lovelaceOf = (amount) => BigInt(amount?.find(a => a.unit === 'lovelace')?.
|
|
|
22
22
|
const nativeAssets = (amount) => (amount ?? []).filter(a => a.unit !== 'lovelace' && a.quantity !== '0');
|
|
23
23
|
const big = (v) => (v == null || v === '' ? 0n : BigInt(String(v)));
|
|
24
24
|
const num = (v) => Number(v ?? 0);
|
|
25
|
-
function decodeAssetName(hex) {
|
|
26
|
-
if (!hex)
|
|
27
|
-
return null;
|
|
28
|
-
try {
|
|
29
|
-
const text = Buffer.from(hex, 'hex').toString('utf8');
|
|
30
|
-
// printable only, a binary asset name has no useful decoded form
|
|
31
|
-
return /^[\x20-\x7e]*$/.test(text) ? text : null;
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
25
|
/** Build the `LedgerUTxOs` row (+ asset rows) for one output. */
|
|
38
26
|
function buildLedgerUtxoRows(o, createdSlot) {
|
|
39
27
|
const decoded = (0, mappers_1.decodeShelleyAddress)(o.address);
|
|
@@ -41,10 +29,7 @@ function buildLedgerUtxoRows(o, createdSlot) {
|
|
|
41
29
|
utxo_txHash: o.txHash,
|
|
42
30
|
utxo_outputIndex: o.outputIndex,
|
|
43
31
|
unit: a.unit,
|
|
44
|
-
|
|
45
|
-
asset_policyId: a.unit.length >= 56 ? a.unit.slice(0, 56) : null,
|
|
46
|
-
asset_assetNameHex: a.unit.length > 56 ? a.unit.slice(56) : '',
|
|
47
|
-
asset_assetName: a.unit.length > 56 ? decodeAssetName(a.unit.slice(56)) : null,
|
|
32
|
+
...(0, mappers_1.assetSlice)(a.unit, a.quantity),
|
|
48
33
|
}));
|
|
49
34
|
return {
|
|
50
35
|
row: {
|
|
@@ -248,10 +233,7 @@ async function applyBlockToLedger(tx, block, txs, lookup) {
|
|
|
248
233
|
assetRows.push({
|
|
249
234
|
address_address: address,
|
|
250
235
|
unit,
|
|
251
|
-
|
|
252
|
-
asset_policyId: unit.length >= 56 ? unit.slice(0, 56) : null,
|
|
253
|
-
asset_assetNameHex: unit.length > 56 ? unit.slice(56) : '',
|
|
254
|
-
asset_assetName: unit.length > 56 ? decodeAssetName(unit.slice(56)) : null,
|
|
236
|
+
...(0, mappers_1.assetSlice)(unit, next),
|
|
255
237
|
});
|
|
256
238
|
}
|
|
257
239
|
}
|
|
@@ -291,26 +273,149 @@ async function applyBlockToLedger(tx, block, txs, lookup) {
|
|
|
291
273
|
}
|
|
292
274
|
return { created: created.size, spent: spentInBlock.size + spentRows.length, missing, addresses: touched.length };
|
|
293
275
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
276
|
+
/** Asset rows of the given ledger rows, keyed `txHash#outputIndex`. Reads only rows that have assets. */
|
|
277
|
+
async function assetsOfRows(tx, rows) {
|
|
278
|
+
const byKey = new Map();
|
|
279
|
+
const wanted = new Set(rows.filter(r => Boolean(r.hasAssets)).map(r => outpoint(r.txHash, num(r.outputIndex))));
|
|
280
|
+
const hashes = [...new Set(rows.filter(r => Boolean(r.hasAssets)).map(r => r.txHash))];
|
|
281
|
+
for (const hashChunk of (0, collections_1.chunk)(hashes, collections_1.IN_CHUNK)) {
|
|
282
|
+
const assets = await tx.run(SELECT.from(cardano_1.LedgerUTxOAssets).where({ utxo_txHash: { in: hashChunk } }));
|
|
283
|
+
for (const a of assets ?? []) {
|
|
284
|
+
const k = outpoint(a.utxo_txHash, num(a.utxo_outputIndex));
|
|
285
|
+
if (!wanted.has(k))
|
|
286
|
+
continue;
|
|
287
|
+
byKey.set(k, [...(byKey.get(k) ?? []), a]);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return byKey;
|
|
291
|
+
}
|
|
292
|
+
/** Latest slot at or before `forkSlot` at which a row of `address` was created or spent. */
|
|
293
|
+
async function lastActiveSlotUpTo(tx, address, forkSlot) {
|
|
294
|
+
const [created, spent] = await Promise.all([
|
|
295
|
+
tx.run(SELECT.one.from(cardano_1.LedgerUTxOs).columns('max(createdSlot) as slot').where({ address, createdSlot: { '<=': forkSlot } })),
|
|
296
|
+
tx.run(SELECT.one.from(cardano_1.LedgerUTxOs).columns('max(spentSlot) as slot').where({ address, spentSlot: { '<=': forkSlot } })),
|
|
297
|
+
]);
|
|
298
|
+
const slots = [created?.slot, spent?.slot].filter(s => s != null).map(num);
|
|
299
|
+
return slots.length ? Math.max(...slots) : null;
|
|
300
|
+
}
|
|
301
|
+
// Undo rolled-back transactions: drop what they created, reopen what they spent, and take the
|
|
302
|
+
// same amounts off the address and account sums that the apply added. `forkSlot` is the slot the
|
|
303
|
+
// chain rolled back to. Returns the touched addresses.
|
|
304
|
+
async function undoLedgerForTransactions(tx, txHashes, forkSlot) {
|
|
297
305
|
if (!txHashes.length)
|
|
298
306
|
return [];
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
307
|
+
const rolledBack = new Set(txHashes);
|
|
308
|
+
const deltas = new Map();
|
|
309
|
+
const hashChunks = (0, collections_1.chunk)(txHashes, collections_1.IN_CHUNK);
|
|
310
|
+
// Every chunk is read before the first write: a reopen in one chunk would otherwise change
|
|
311
|
+
// what a later chunk reads about the outputs its transactions created.
|
|
312
|
+
for (const hashChunk of hashChunks) {
|
|
313
|
+
const [created, spent] = await Promise.all([
|
|
314
|
+
tx.run(SELECT.from(cardano_1.LedgerUTxOs).where({ txHash: { in: hashChunk } })),
|
|
315
|
+
tx.run(SELECT.from(cardano_1.LedgerUTxOs).where({ spentTxHash: { in: hashChunk } })),
|
|
304
316
|
]);
|
|
305
|
-
|
|
306
|
-
|
|
317
|
+
// A row a rolled-back transaction created and another one spent added nothing to the sums.
|
|
318
|
+
const openCreated = (created ?? []).filter(r => r.spentTxHash == null);
|
|
319
|
+
const reopened = (spent ?? []).filter(r => !rolledBack.has(r.txHash));
|
|
320
|
+
const assets = await assetsOfRows(tx, [...openCreated, ...reopened]);
|
|
321
|
+
for (const r of openCreated)
|
|
322
|
+
applyDelta(deltaFor(deltas, r), r, assets.get(outpoint(r.txHash, num(r.outputIndex))), -1n);
|
|
323
|
+
for (const r of reopened)
|
|
324
|
+
applyDelta(deltaFor(deltas, r), r, assets.get(outpoint(r.txHash, num(r.outputIndex))), 1n);
|
|
325
|
+
}
|
|
326
|
+
for (const hashChunk of hashChunks) {
|
|
307
327
|
await tx.run(DELETE.from(cardano_1.LedgerUTxOAssets).where({ utxo_txHash: { in: hashChunk } }));
|
|
308
328
|
await tx.run(DELETE.from(cardano_1.LedgerUTxOs).where({ txHash: { in: hashChunk } }));
|
|
329
|
+
}
|
|
330
|
+
for (const hashChunk of hashChunks) {
|
|
309
331
|
await tx.run(UPDATE.entity(cardano_1.LedgerUTxOs).set({ spentTxHash: null, spentSlot: null }).where({ spentTxHash: { in: hashChunk } }));
|
|
310
332
|
}
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
333
|
+
const touched = [...deltas.keys()];
|
|
334
|
+
const stakeDeltas = new Map();
|
|
335
|
+
for (const addrChunk of (0, collections_1.chunk)(touched, collections_1.IN_CHUNK)) {
|
|
336
|
+
const [existing, existingAssets] = await Promise.all([
|
|
337
|
+
tx.run(SELECT.from(cardano_1.LedgerAddresses).where({ address: { in: addrChunk } })),
|
|
338
|
+
tx.run(SELECT.from(cardano_1.LedgerAddressAssets).where({ address_address: { in: addrChunk } })),
|
|
339
|
+
]);
|
|
340
|
+
const byAddress = new Map((existing ?? []).map(e => [String(e.address), e]));
|
|
341
|
+
const assetQty = new Map();
|
|
342
|
+
for (const a of existingAssets ?? [])
|
|
343
|
+
assetQty.set(`${a.address_address}|${a.unit}`, big(a.asset_quantity));
|
|
344
|
+
for (const address of addrChunk) {
|
|
345
|
+
const d = deltas.get(address);
|
|
346
|
+
const prev = byAddress.get(address);
|
|
347
|
+
if (!prev)
|
|
348
|
+
continue;
|
|
349
|
+
const count = num(prev.utxoCount) + d.utxos;
|
|
350
|
+
const stake = prev.stakeAddress ?? d.stakeAddress;
|
|
351
|
+
// An address the rolled-back blocks brought in did not exist at the fork.
|
|
352
|
+
const firstSeen = prev.firstSeenSlot == null ? null : num(prev.firstSeenSlot);
|
|
353
|
+
const bornAfterFork = firstSeen != null && firstSeen > forkSlot && count <= 0;
|
|
354
|
+
if (bornAfterFork) {
|
|
355
|
+
await tx.run(DELETE.from(cardano_1.LedgerAddressAssets).where({ address_address: address }));
|
|
356
|
+
await tx.run(DELETE.from(cardano_1.LedgerAddresses).where({ address }));
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
const lastActive = prev.lastActiveSlot == null ? null : num(prev.lastActiveSlot);
|
|
360
|
+
await tx.run(UPSERT.into(cardano_1.LedgerAddresses).entries({
|
|
361
|
+
...prev,
|
|
362
|
+
totalLovelace: (big(prev.totalLovelace) + d.lovelace).toString(),
|
|
363
|
+
utxoCount: count,
|
|
364
|
+
lastActiveSlot: lastActive != null && lastActive > forkSlot ? await lastActiveSlotUpTo(tx, address, forkSlot) : lastActive,
|
|
365
|
+
}));
|
|
366
|
+
for (const [unit, delta] of d.assets) {
|
|
367
|
+
if (delta === 0n)
|
|
368
|
+
continue;
|
|
369
|
+
const k = `${address}|${unit}`;
|
|
370
|
+
const next = (assetQty.get(k) ?? 0n) + delta;
|
|
371
|
+
if (next === 0n) {
|
|
372
|
+
await tx.run(DELETE.from(cardano_1.LedgerAddressAssets).where({ address_address: address, unit }));
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
await tx.run(UPSERT.into(cardano_1.LedgerAddressAssets).entries({
|
|
376
|
+
address_address: address,
|
|
377
|
+
unit,
|
|
378
|
+
...(0, mappers_1.assetSlice)(unit, next),
|
|
379
|
+
}));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (stake) {
|
|
384
|
+
const s = stakeDeltas.get(stake) ?? { lovelace: 0n, utxos: 0, removedAddresses: 0 };
|
|
385
|
+
s.lovelace += d.lovelace;
|
|
386
|
+
s.utxos += d.utxos;
|
|
387
|
+
if (bornAfterFork)
|
|
388
|
+
s.removedAddresses++;
|
|
389
|
+
stakeDeltas.set(stake, s);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
for (const stakeChunk of (0, collections_1.chunk)([...stakeDeltas.keys()], collections_1.IN_CHUNK)) {
|
|
394
|
+
const existing = await tx.run(SELECT.from(cardano_1.LedgerAccounts).where({ stakeAddress: { in: stakeChunk } }));
|
|
395
|
+
for (const prev of existing ?? []) {
|
|
396
|
+
const stakeAddress = String(prev.stakeAddress);
|
|
397
|
+
const d = stakeDeltas.get(stakeAddress);
|
|
398
|
+
const addressCount = num(prev.addressCount) - d.removedAddresses;
|
|
399
|
+
if (addressCount <= 0) {
|
|
400
|
+
await tx.run(DELETE.from(cardano_1.LedgerAccounts).where({ stakeAddress }));
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
const lastActive = prev.lastActiveSlot == null ? null : num(prev.lastActiveSlot);
|
|
404
|
+
let lastActiveSlot = lastActive;
|
|
405
|
+
if (lastActive != null && lastActive > forkSlot) {
|
|
406
|
+
const latest = await tx.run(SELECT.one.from(cardano_1.LedgerAddresses).columns('max(lastActiveSlot) as slot').where({ stakeAddress, lastActiveSlot: { '<=': forkSlot } }));
|
|
407
|
+
lastActiveSlot = latest?.slot == null ? null : num(latest.slot);
|
|
408
|
+
}
|
|
409
|
+
await tx.run(UPSERT.into(cardano_1.LedgerAccounts).entries({
|
|
410
|
+
stakeAddress,
|
|
411
|
+
controlledAmount: (big(prev.controlledAmount) + d.lovelace).toString(),
|
|
412
|
+
addressCount,
|
|
413
|
+
utxoCount: num(prev.utxoCount) + d.utxos,
|
|
414
|
+
lastActiveSlot,
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return touched;
|
|
314
419
|
}
|
|
315
420
|
// Recount the sums of these addresses and their stake keys from open rows. Also repairs a drifted sum.
|
|
316
421
|
async function recountLedgerAddresses(tx, addresses) {
|
|
@@ -350,10 +455,7 @@ async function recountLedgerAddresses(tx, addresses) {
|
|
|
350
455
|
const assetRows = [...assetSums].filter(([, q]) => q !== 0n).map(([unit, q]) => ({
|
|
351
456
|
address_address: address,
|
|
352
457
|
unit,
|
|
353
|
-
|
|
354
|
-
asset_policyId: unit.length >= 56 ? unit.slice(0, 56) : null,
|
|
355
|
-
asset_assetNameHex: unit.length > 56 ? unit.slice(56) : '',
|
|
356
|
-
asset_assetName: unit.length > 56 ? decodeAssetName(unit.slice(56)) : null,
|
|
458
|
+
...(0, mappers_1.assetSlice)(unit, q),
|
|
357
459
|
}));
|
|
358
460
|
for (const rows of (0, collections_1.chunk)(assetRows, collections_1.IN_CHUNK))
|
|
359
461
|
await tx.run(UPSERT.into(cardano_1.LedgerAddressAssets).entries(rows));
|
|
@@ -121,7 +121,7 @@ class ExternalSignerModule {
|
|
|
121
121
|
/** Initial (pending) workflow state for a signing request. */
|
|
122
122
|
createWorkflowState(signingRequest) {
|
|
123
123
|
return {
|
|
124
|
-
status:
|
|
124
|
+
status: 'pending',
|
|
125
125
|
request: signingRequest,
|
|
126
126
|
timestamps: {
|
|
127
127
|
created: signingRequest.createdAt,
|
|
@@ -132,7 +132,7 @@ class ExternalSignerModule {
|
|
|
132
132
|
markAsSigned(state, signedTxCbor) {
|
|
133
133
|
return {
|
|
134
134
|
...state,
|
|
135
|
-
status:
|
|
135
|
+
status: 'signed',
|
|
136
136
|
signedTxCbor,
|
|
137
137
|
timestamps: {
|
|
138
138
|
...state.timestamps,
|
|
@@ -147,7 +147,7 @@ class ExternalSignerModule {
|
|
|
147
147
|
}
|
|
148
148
|
return {
|
|
149
149
|
...state,
|
|
150
|
-
status:
|
|
150
|
+
status: 'verified',
|
|
151
151
|
verificationResult,
|
|
152
152
|
timestamps: {
|
|
153
153
|
...state.timestamps,
|
|
@@ -159,7 +159,7 @@ class ExternalSignerModule {
|
|
|
159
159
|
markAsSubmitted(state, txHash) {
|
|
160
160
|
return {
|
|
161
161
|
...state,
|
|
162
|
-
status:
|
|
162
|
+
status: 'submitted',
|
|
163
163
|
txHash,
|
|
164
164
|
timestamps: {
|
|
165
165
|
...state.timestamps,
|
|
@@ -171,7 +171,7 @@ class ExternalSignerModule {
|
|
|
171
171
|
markAsFailed(state, errorMessage) {
|
|
172
172
|
return {
|
|
173
173
|
...state,
|
|
174
|
-
status:
|
|
174
|
+
status: 'failed',
|
|
175
175
|
errorMessage,
|
|
176
176
|
timestamps: {
|
|
177
177
|
...state.timestamps,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PresenceIndexer, type TransactionLookup } from '../transaction-presence';
|
|
2
|
+
import type { CardanoIndexer } from '../cardano-indexer';
|
|
3
|
+
export interface FailedRecheckProgress {
|
|
4
|
+
submissions: number;
|
|
5
|
+
requests: number;
|
|
6
|
+
jobs: number;
|
|
7
|
+
restored: number;
|
|
8
|
+
}
|
|
9
|
+
export interface FailedRecheckDeps {
|
|
10
|
+
indexer: PresenceIndexer & Pick<CardanoIndexer, 'indexVerifiedTransactionSubmission'>;
|
|
11
|
+
client: TransactionLookup;
|
|
12
|
+
}
|
|
13
|
+
export declare function recheckFailed(deps: FailedRecheckDeps, opts?: {
|
|
14
|
+
shouldStop?: () => boolean;
|
|
15
|
+
onProgress?: (p: FailedRecheckProgress) => void;
|
|
16
|
+
}): Promise<FailedRecheckProgress>;
|
|
17
|
+
//# sourceMappingURL=failed-recheck.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.recheckFailed = recheckFailed;
|
|
7
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
8
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
9
|
+
const tx_utils_1 = require("../../utils/tx-utils");
|
|
10
|
+
const transaction_presence_1 = require("../transaction-presence");
|
|
11
|
+
const external_signer_1 = require("./external-signer");
|
|
12
|
+
const job_store_1 = require("../wallet-worker/job-store");
|
|
13
|
+
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
14
|
+
const logger = cds_1.default.log('FailedRecheck');
|
|
15
|
+
const SIGNING_REQUESTS = 'odatano.cardano.SigningRequests';
|
|
16
|
+
const PAGE = 200;
|
|
17
|
+
function note(slot) {
|
|
18
|
+
return `re-checked at ${new Date().toISOString()}: on chain${slot != null ? ` at slot ${slot}` : ''}`;
|
|
19
|
+
}
|
|
20
|
+
// Where the chain holds the transaction with passing scripts, or null. A crawled row that cannot tell
|
|
21
|
+
// whether its scripts passed asks a backend that can; without such an answer the row stays failed.
|
|
22
|
+
async function onChainWithPassingScripts(deps, txHash) {
|
|
23
|
+
try {
|
|
24
|
+
let presence = await (0, transaction_presence_1.findOnChain)(deps.indexer, deps.client, txHash);
|
|
25
|
+
if (presence && !presence.validityKnown && deps.client.supports('getTransaction')) {
|
|
26
|
+
const found = await deps.client.getTransaction(txHash);
|
|
27
|
+
presence = { slot: presence.slot, height: presence.height, scriptFailed: found.spendsCollaterals === true, validityKnown: typeof found.spendsCollaterals === 'boolean' };
|
|
28
|
+
}
|
|
29
|
+
return presence && presence.validityKnown && !presence.scriptFailed ? { slot: presence.slot } : null;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
logger.debug({ txHash, error: err instanceof Error ? err.message : String(err) }, 'Lookup gave no answer; the row stays failed');
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Ids after `after`, in id order, from one page. */
|
|
37
|
+
async function page(read, after) {
|
|
38
|
+
return (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx((db) => read(db, after)));
|
|
39
|
+
}
|
|
40
|
+
async function recheckFailed(deps, opts = {}) {
|
|
41
|
+
const progress = { submissions: 0, requests: 0, jobs: 0, restored: 0 };
|
|
42
|
+
for (let after = '';;) {
|
|
43
|
+
if (opts.shouldStop?.())
|
|
44
|
+
return progress;
|
|
45
|
+
const rows = await page((db, a) => db.run(SELECT.from(cardano_1.TransactionSubmissions).columns('id', 'txHash')
|
|
46
|
+
.where({ status: 'failed', id: { '>': a } }).orderBy('id').limit(PAGE)), after);
|
|
47
|
+
if (!rows.length)
|
|
48
|
+
break;
|
|
49
|
+
after = rows[rows.length - 1].id;
|
|
50
|
+
for (const row of rows) {
|
|
51
|
+
progress.submissions++;
|
|
52
|
+
const found = await onChainWithPassingScripts(deps, row.txHash);
|
|
53
|
+
if (!found)
|
|
54
|
+
continue;
|
|
55
|
+
const moved = await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx((db) => db.run(UPDATE.entity(cardano_1.TransactionSubmissions)
|
|
56
|
+
.set({ status: 'submitted', errorMessage: null, resolution: note(found.slot) }).where({ id: row.id, status: 'failed' }))));
|
|
57
|
+
if (Number(moved) > 0) {
|
|
58
|
+
progress.restored++;
|
|
59
|
+
logger.warn({ submissionId: row.id, txHash: row.txHash }, 'Failed submission is on chain; moved back to submitted');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
opts.onProgress?.({ ...progress });
|
|
63
|
+
}
|
|
64
|
+
for (let after = '';;) {
|
|
65
|
+
if (opts.shouldStop?.())
|
|
66
|
+
return progress;
|
|
67
|
+
const rows = await page((db, a) => db.run(SELECT.from(SIGNING_REQUESTS)
|
|
68
|
+
.columns('id', 'build_id', 'txBodyHash', 'signedTxCbor', 'signerType', 'signerInfo', 'submission_id')
|
|
69
|
+
.where({ status: 'failed', id: { '>': a } }).and('signedTxCbor is not null').orderBy('id').limit(PAGE)), after);
|
|
70
|
+
if (!rows.length)
|
|
71
|
+
break;
|
|
72
|
+
after = rows[rows.length - 1].id;
|
|
73
|
+
for (const row of rows) {
|
|
74
|
+
progress.requests++;
|
|
75
|
+
const found = await onChainWithPassingScripts(deps, row.txBodyHash);
|
|
76
|
+
if (!found)
|
|
77
|
+
continue;
|
|
78
|
+
try {
|
|
79
|
+
const moved = await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx(async (db) => {
|
|
80
|
+
const won = await db.run(UPDATE.entity(SIGNING_REQUESTS)
|
|
81
|
+
.set({ status: 'submitted', errorMessage: null, resolution: note(found.slot) }).where({ id: row.id, status: 'failed' }));
|
|
82
|
+
if (Number(won) === 0 || row.submission_id || !row.build_id)
|
|
83
|
+
return Number(won) > 0;
|
|
84
|
+
// the submission record a submit writes, from the stored bytes
|
|
85
|
+
await deps.indexer.indexVerifiedTransactionSubmission(db, {
|
|
86
|
+
signingRequestId: row.id, buildId: row.build_id, fullSignedTxCbor: row.signedTxCbor, txHash: row.txBodyHash,
|
|
87
|
+
verificationResult: (0, external_signer_1.getExternalSignerModule)().verifyOrThrow(row.signedTxCbor, row.txBodyHash),
|
|
88
|
+
signerType: row.signerType ?? undefined, signerInfo: row.signerInfo ?? undefined,
|
|
89
|
+
});
|
|
90
|
+
return true;
|
|
91
|
+
}));
|
|
92
|
+
if (moved) {
|
|
93
|
+
progress.restored++;
|
|
94
|
+
logger.warn({ signingRequestId: row.id, txHash: row.txBodyHash }, 'Failed signing request is on chain; moved back to submitted');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
logger.error({ err, signingRequestId: row.id }, 'Failed signing request is on chain but could not be restored');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
opts.onProgress?.({ ...progress });
|
|
102
|
+
}
|
|
103
|
+
// Jobs failed on time or a refusal alone. Back to submitted, the tracker confirms them by depth,
|
|
104
|
+
// and their submission row follows.
|
|
105
|
+
for (let after = '';;) {
|
|
106
|
+
if (opts.shouldStop?.())
|
|
107
|
+
return progress;
|
|
108
|
+
const rows = await page((db, a) => db.run(SELECT.from(cardano_1.CardanoWalletJobs).columns('ID as id', 'txHash')
|
|
109
|
+
.where({ status: 'failed', errorCode: { in: [job_store_1.JOB_ERROR_CODES.TX_DROPPED, job_store_1.JOB_ERROR_CODES.SUBMIT_REJECTED] }, ID: { '>': a } })
|
|
110
|
+
.and('txHash is not null').orderBy('ID').limit(PAGE)), after);
|
|
111
|
+
if (!rows.length)
|
|
112
|
+
break;
|
|
113
|
+
after = rows[rows.length - 1].id;
|
|
114
|
+
for (const row of rows) {
|
|
115
|
+
progress.jobs++;
|
|
116
|
+
const found = await onChainWithPassingScripts(deps, row.txHash);
|
|
117
|
+
if (!found)
|
|
118
|
+
continue;
|
|
119
|
+
const moved = await (0, tx_utils_1.runWithoutAmbientTx)(() => cds_1.default.tx(async (db) => {
|
|
120
|
+
if (!(await (0, job_store_1.reopenFailedJob)(db, row.id, note(found.slot))))
|
|
121
|
+
return false;
|
|
122
|
+
await db.run(UPDATE.entity(cardano_1.TransactionSubmissions).set({ status: 'submitted', errorMessage: null, resolution: note(found.slot) })
|
|
123
|
+
.where({ txHash: row.txHash, status: 'failed' }));
|
|
124
|
+
return true;
|
|
125
|
+
}));
|
|
126
|
+
if (moved) {
|
|
127
|
+
progress.restored++;
|
|
128
|
+
logger.warn({ jobId: row.id, txHash: row.txHash }, 'Failed wallet job is on chain; moved back to submitted');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
opts.onProgress?.({ ...progress });
|
|
132
|
+
}
|
|
133
|
+
return progress;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=failed-recheck.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PresenceIndexer, type TransactionLookup } from '../transaction-presence';
|
|
2
|
+
import type { CardanoClient, Network } from '../cardano-client';
|
|
3
|
+
/** Slots an indexer may lag the node; added to the horizon when the ledger read came from one. */
|
|
4
|
+
export declare const PROVIDER_LAG_SLOTS = 3600;
|
|
5
|
+
/** Slots past its expiry after which a transaction can no longer land on the chain the node follows. */
|
|
6
|
+
export declare function settleSlots(network: Network): number;
|
|
7
|
+
export type LandingClient = TransactionLookup & Pick<CardanoClient, 'network' | 'isUtxoUnspent' | 'readLedger'>;
|
|
8
|
+
export type LandingIndexer = PresenceIndexer;
|
|
9
|
+
export type LandingVerdict = {
|
|
10
|
+
verdict: 'onChain';
|
|
11
|
+
} | {
|
|
12
|
+
verdict: 'scriptFailed';
|
|
13
|
+
reason: string;
|
|
14
|
+
} | {
|
|
15
|
+
verdict: 'neverLands';
|
|
16
|
+
reason: string;
|
|
17
|
+
} | {
|
|
18
|
+
verdict: 'unresolved';
|
|
19
|
+
reason: string;
|
|
20
|
+
} | {
|
|
21
|
+
verdict: 'stale';
|
|
22
|
+
reason: string;
|
|
23
|
+
unspentInputs: Array<{
|
|
24
|
+
txHash: string;
|
|
25
|
+
outputIndex: number;
|
|
26
|
+
}>;
|
|
27
|
+
} | {
|
|
28
|
+
verdict: 'open';
|
|
29
|
+
};
|
|
30
|
+
export declare function isFinalRefusal(err: unknown): boolean;
|
|
31
|
+
export interface LandingFacts {
|
|
32
|
+
ttlSlot: number | null;
|
|
33
|
+
inputs: Array<{
|
|
34
|
+
txHash: string;
|
|
35
|
+
outputIndex: number;
|
|
36
|
+
}>;
|
|
37
|
+
outputCount: number;
|
|
38
|
+
isValid: boolean;
|
|
39
|
+
collateralInputs: Array<{
|
|
40
|
+
txHash: string;
|
|
41
|
+
outputIndex: number;
|
|
42
|
+
}>;
|
|
43
|
+
hasCollateralReturn: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Expiry, inputs, outputs and collateral of a signed transaction. */
|
|
46
|
+
export declare function landingFacts(signedTxCbor: string): LandingFacts;
|
|
47
|
+
export declare function sendProblem(signedTxCbor: string, network: Network, nowMs?: number): string | null;
|
|
48
|
+
/** True once the expiry has passed by the wall clock: then no node accepts the bytes any more. */
|
|
49
|
+
export declare function isExpired(signedTxCbor: string, network: Network, nowMs?: number): boolean;
|
|
50
|
+
/** Own output indexes read for landing evidence: the last (the builder puts the change there), then the first. */
|
|
51
|
+
export declare function outputsToCheck(outputCount: number): number[];
|
|
52
|
+
/** True when one of the transaction's own outputs is unspent: then it landed with passing scripts. */
|
|
53
|
+
export declare function hasUnspentOutput(signedTxCbor: string, txHash: string, client: Pick<CardanoClient, 'isUtxoUnspent'>): Promise<boolean>;
|
|
54
|
+
/** Forgets what this process remembers about spent inputs; for tests. */
|
|
55
|
+
export declare function resetLandingMemory(): void;
|
|
56
|
+
export declare function judgeLanding(signedTxCbor: string, txHash: string, { indexer, client }: {
|
|
57
|
+
indexer: LandingIndexer;
|
|
58
|
+
client: LandingClient;
|
|
59
|
+
}, sentAtMs?: number | null, nowMs?: number): Promise<LandingVerdict>;
|
|
60
|
+
//# sourceMappingURL=landing-proof.d.ts.map
|