@odatano/core 2.0.0-rc.3 → 2.0.0-rc.31
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 +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoBackendService/index.d.ts +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
- package/@cds-models/CardanoIndexerService/index.js +25 -0
- package/@cds-models/CardanoODataService/index.d.ts +294 -7
- package/@cds-models/CardanoODataService/index.js +33 -0
- package/@cds-models/CardanoSignService/index.d.ts +28 -3
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +52 -19
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +18 -0
- package/@cds-models/index.js +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +408 -7
- package/@cds-models/odatano/cardano/index.js +42 -0
- package/README.md +64 -5
- package/db/schema.cds +677 -13
- package/db/types.cds +27 -0
- package/package.json +182 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +11 -10
- package/src/index.js +28 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +49 -160
- package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
- package/srv/blockchain/backends/cardano-backend.js +19 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +356 -217
- package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
- package/srv/blockchain/backends/odatano-backend.js +170 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
- package/srv/blockchain/backends/ogmios-backend.js +548 -197
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +78 -205
- package/srv/blockchain/cardano-client.js +186 -242
- package/srv/blockchain/cardano-indexer.d.ts +302 -242
- package/srv/blockchain/cardano-indexer.js +1193 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +43 -81
- package/srv/blockchain/cardano-tx-builder.js +177 -132
- package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
- package/srv/blockchain/crawler/certificate-backfill.js +169 -0
- package/srv/blockchain/crawler/crawler.d.ts +139 -54
- package/srv/blockchain/crawler/crawler.js +478 -96
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +46 -28
- package/srv/blockchain/crawler/sync-state.js +128 -43
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
- package/srv/blockchain/crawler/utxo-set-import.js +363 -0
- package/srv/blockchain/ledger-state.d.ts +101 -0
- package/srv/blockchain/ledger-state.js +432 -0
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -49
- package/srv/blockchain/stored-chain.d.ts +33 -0
- package/srv/blockchain/stored-chain.js +234 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +115 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +651 -287
- package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
- package/srv/blockchain/transaction-building/caller-datums.js +139 -0
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +43 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +48 -24
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +244 -0
- package/srv/cardano-indexer-service.cds +201 -73
- package/srv/cardano-indexer-service.js +280 -11
- package/srv/cardano-service.cds +56 -1
- package/srv/cardano-service.js +52 -113
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +439 -364
- package/srv/cardano-tx-service.js +305 -209
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/parse.js +13 -1
- package/srv/server.d.ts +28 -86
- package/srv/server.js +130 -135
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +922 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +30 -67
- package/srv/utils/const.js +32 -72
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +94 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/error-codes.d.ts +20 -73
- package/srv/utils/error-codes.js +19 -70
- package/srv/utils/errors.d.ts +50 -177
- package/srv/utils/errors.js +94 -218
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +40 -0
- package/srv/utils/mappers.d.ts +128 -214
- package/srv/utils/mappers.js +354 -299
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +62 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +56 -0
- package/srv/utils/plutus-placeholders.d.ts +23 -16
- package/srv/utils/plutus-placeholders.js +63 -27
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +26 -92
- package/srv/utils/tx-build-helper.js +68 -123
- package/srv/utils/tx-request-parsers.d.ts +107 -21
- package/srv/utils/tx-request-parsers.js +433 -34
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +238 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Tx } from "@harmoniclabs/cardano-ledger-ts";
|
|
2
|
+
/**
|
|
3
|
+
* Inline datums given as CBOR, keyed by output index. Buildooor writes every datum in its
|
|
4
|
+
* own encoding, so definite lists and maps change bytes and hash. These helpers put the
|
|
5
|
+
* caller's bytes back into the built transaction.
|
|
6
|
+
*/
|
|
7
|
+
export type CallerDatums = Map<number, Uint8Array>;
|
|
8
|
+
/** Bytes one output gains when its datum is written as given; negative when it shrinks. */
|
|
9
|
+
export declare function callerDatumGrowth(datum: Uint8Array): number;
|
|
10
|
+
/** Bytes the whole transaction gains from the caller's datums, never below zero. */
|
|
11
|
+
export declare function callerDatumsGrowth(datums: CallerDatums): number;
|
|
12
|
+
/**
|
|
13
|
+
* Replace Buildooor's datum encoding in the listed outputs with the caller's bytes.
|
|
14
|
+
* Only the datum bytes change. Containers in CBOR count items, not bytes, so the rest stays valid.
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeCallerDatums(tx: Tx, datums: CallerDatums): Tx;
|
|
17
|
+
/** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
|
|
18
|
+
export declare function datumHashOf(datum: Uint8Array): string;
|
|
19
|
+
/** Bytes the witness set gains from the caller's datums, never below zero. */
|
|
20
|
+
export declare function witnessDatumsGrowth(datums: Uint8Array[]): number;
|
|
21
|
+
/**
|
|
22
|
+
* Replace Buildooor's encoding of the witness datums with the caller's bytes, then recompute
|
|
23
|
+
* scriptDataHash over redeemers, datums and language views as they now stand in the transaction.
|
|
24
|
+
* The ledger finds a witness datum by the hash of its bytes, so a re-encoded datum is missing to it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeWitnessDatums(tx: Tx, datums: Uint8Array[], languageViews: Uint8Array): Tx;
|
|
27
|
+
/** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
|
|
28
|
+
export declare function scriptDataHashOf(txBytes: Uint8Array, languageViews: Uint8Array): Uint8Array;
|
|
29
|
+
//# sourceMappingURL=caller-datums.d.ts.map
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
/**
|
|
31
|
+
* Replace Buildooor's datum encoding in the listed outputs with the caller's bytes.
|
|
32
|
+
* Only the datum bytes change. Containers in CBOR count items, not bytes, so the rest stays valid.
|
|
33
|
+
*/
|
|
34
|
+
function writeCallerDatums(tx, datums) {
|
|
35
|
+
if (datums.size === 0)
|
|
36
|
+
return tx;
|
|
37
|
+
let bytes = Buffer.from(tx.toCbor());
|
|
38
|
+
const outputs = cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes)).body.outputs;
|
|
39
|
+
// Last output first, so the offsets of earlier outputs stay valid
|
|
40
|
+
for (const index of [...datums.keys()].sort((a, b) => b - a)) {
|
|
41
|
+
const out = outputs[index];
|
|
42
|
+
const ref = out?.cborRef;
|
|
43
|
+
if (!out || !ref || out.datum === undefined || out.datum instanceof cardano_ledger_ts_1.Hash32) {
|
|
44
|
+
throw new Error(`output ${index} of the built transaction carries no inline datum`);
|
|
45
|
+
}
|
|
46
|
+
const built = inlineDatumEntry((0, plutus_data_1.dataToCbor)(out.datum));
|
|
47
|
+
const at = bytes.subarray(ref.start, ref.end).indexOf(built);
|
|
48
|
+
if (at < 0)
|
|
49
|
+
throw new Error(`inline datum of output ${index} not found in the built transaction`);
|
|
50
|
+
const start = ref.start + at;
|
|
51
|
+
bytes = Buffer.concat([bytes.subarray(0, start), inlineDatumEntry(datums.get(index)), bytes.subarray(start + built.length)]);
|
|
52
|
+
}
|
|
53
|
+
return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
|
|
54
|
+
}
|
|
55
|
+
/** Datum hash as the ledger computes it: blake2b-256 of the datum bytes. */
|
|
56
|
+
function datumHashOf(datum) {
|
|
57
|
+
return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(datum));
|
|
58
|
+
}
|
|
59
|
+
/** Bytes the witness set gains from the caller's datums, never below zero. */
|
|
60
|
+
function witnessDatumsGrowth(datums) {
|
|
61
|
+
let growth = 0;
|
|
62
|
+
for (const datum of datums)
|
|
63
|
+
growth += datum.length - (0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)).length;
|
|
64
|
+
return Math.max(0, growth);
|
|
65
|
+
}
|
|
66
|
+
/** End offset of a parsed item; a tag carries no offset of its own, its content does. */
|
|
67
|
+
function endOf(item) {
|
|
68
|
+
let inner = item;
|
|
69
|
+
while (inner instanceof cbor_1.CborTag)
|
|
70
|
+
inner = inner.data;
|
|
71
|
+
return inner.subCborRef.end;
|
|
72
|
+
}
|
|
73
|
+
/** Length of a CBOR item head, from its first byte. */
|
|
74
|
+
function headLength(first) {
|
|
75
|
+
const info = first & 0x1f;
|
|
76
|
+
return info < 24 || info === 31 ? 1 : info === 24 ? 2 : info === 25 ? 3 : info === 26 ? 5 : 9;
|
|
77
|
+
}
|
|
78
|
+
function entryOf(map, key) {
|
|
79
|
+
return map.map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === key);
|
|
80
|
+
}
|
|
81
|
+
/** Bytes of a map entry's value as they stand in `bytes`. */
|
|
82
|
+
function valueBytes(bytes, entry) {
|
|
83
|
+
return bytes.subarray(entry.k.subCborRef.end, endOf(entry.v));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Replace Buildooor's encoding of the witness datums with the caller's bytes, then recompute
|
|
87
|
+
* scriptDataHash over redeemers, datums and language views as they now stand in the transaction.
|
|
88
|
+
* The ledger finds a witness datum by the hash of its bytes, so a re-encoded datum is missing to it.
|
|
89
|
+
*/
|
|
90
|
+
function writeWitnessDatums(tx, datums, languageViews) {
|
|
91
|
+
const wanted = new Map();
|
|
92
|
+
for (const datum of datums) {
|
|
93
|
+
const built = (0, uint8array_utils_1.toHex)((0, plutus_data_1.dataToCbor)((0, plutus_data_1.dataFromCbor)(datum)));
|
|
94
|
+
if (built !== (0, uint8array_utils_1.toHex)(datum))
|
|
95
|
+
wanted.set(built, datum);
|
|
96
|
+
}
|
|
97
|
+
if (wanted.size === 0)
|
|
98
|
+
return tx;
|
|
99
|
+
let bytes = Buffer.from(tx.toCbor());
|
|
100
|
+
let root = cbor_1.Cbor.parse(bytes, { keepRef: true });
|
|
101
|
+
const datumsEntry = entryOf(root.array[1], 4);
|
|
102
|
+
let list = datumsEntry?.v;
|
|
103
|
+
while (list instanceof cbor_1.CborTag)
|
|
104
|
+
list = list.data;
|
|
105
|
+
if (!(list instanceof cbor_1.CborArray))
|
|
106
|
+
throw new Error('the built transaction carries no witness datums');
|
|
107
|
+
// Rebuild the datum list item by item: head, items, and the break byte of an indefinite list
|
|
108
|
+
const listStart = list.subCborRef.start;
|
|
109
|
+
const listEnd = list.subCborRef.end;
|
|
110
|
+
let at = listStart + headLength(bytes[listStart]);
|
|
111
|
+
const parts = [bytes.subarray(listStart, at)];
|
|
112
|
+
for (const item of list.array) {
|
|
113
|
+
const end = endOf(item);
|
|
114
|
+
parts.push(wanted.get((0, uint8array_utils_1.toHex)(bytes.subarray(at, end))) ?? bytes.subarray(at, end));
|
|
115
|
+
at = end;
|
|
116
|
+
}
|
|
117
|
+
parts.push(bytes.subarray(at, listEnd));
|
|
118
|
+
bytes = Buffer.concat([bytes.subarray(0, listStart), ...parts, bytes.subarray(listEnd)]);
|
|
119
|
+
root = cbor_1.Cbor.parse(bytes, { keepRef: true });
|
|
120
|
+
const hashEntry = entryOf(root.array[0], 11);
|
|
121
|
+
if (!hashEntry)
|
|
122
|
+
throw new Error('the built transaction carries no scriptDataHash');
|
|
123
|
+
bytes.set(scriptDataHashOf(bytes, languageViews), endOf(hashEntry.v) - 32);
|
|
124
|
+
return cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.toHex)(bytes));
|
|
125
|
+
}
|
|
126
|
+
/** scriptDataHash of a transaction over its redeemer and datum bytes as they stand, laid out like Buildooor's getScriptDataHash. */
|
|
127
|
+
function scriptDataHashOf(txBytes, languageViews) {
|
|
128
|
+
const bytes = Buffer.from(txBytes);
|
|
129
|
+
const witnesses = cbor_1.Cbor.parse(bytes, { keepRef: true }).array[1];
|
|
130
|
+
const redeemers = entryOf(witnesses, 5);
|
|
131
|
+
const datums = entryOf(witnesses, 4);
|
|
132
|
+
if (!redeemers && !datums)
|
|
133
|
+
throw new Error('the transaction carries no redeemers and no datums');
|
|
134
|
+
const datumBytes = datums ? valueBytes(bytes, datums) : Buffer.alloc(0);
|
|
135
|
+
return (0, crypto_1.blake2b_256)(redeemers
|
|
136
|
+
? Buffer.concat([valueBytes(bytes, redeemers), datumBytes, languageViews])
|
|
137
|
+
: Buffer.concat([Buffer.from([0xa0]), datumBytes, Buffer.from([0xa0])]));
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=caller-datums.js.map
|
|
@@ -1,47 +1,22 @@
|
|
|
1
|
-
import { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
|
|
1
|
+
import { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildPlutusRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
|
|
2
2
|
import { CardanoClient } from "../cardano-client";
|
|
3
|
-
/**
|
|
4
|
-
* CardanoTxBuilder - Interface Definition for the Cardano transaction builder (Buildooor)
|
|
5
|
-
* Defines the standard methods that any Cardano transaction builder must implement to be used interchangeably.
|
|
6
|
-
*/
|
|
3
|
+
/** Interface for the Cardano transaction builder (Buildooor). */
|
|
7
4
|
export interface CardanoTxBuilder {
|
|
8
|
-
/**
|
|
9
|
-
* Builder name
|
|
10
|
-
*/
|
|
5
|
+
/** Builder name */
|
|
11
6
|
name: string;
|
|
12
7
|
/**
|
|
13
|
-
* Initialize the builder
|
|
14
|
-
* @param
|
|
15
|
-
* @param protocolParams - Optional protocol parameters (if not provided, fetched from backend)
|
|
8
|
+
* Initialize the builder.
|
|
9
|
+
* @param protocolParams - optional; fetched from the backend when omitted
|
|
16
10
|
*/
|
|
17
11
|
init(client: CardanoClient, protocolParams?: LedgerProtocolParameters): Promise<void>;
|
|
18
|
-
/**
|
|
19
|
-
* Build unsigned transfer transaction (ADA-only or with native assets)
|
|
20
|
-
* @param req transaction build request
|
|
21
|
-
* @param ctx transaction build context
|
|
22
|
-
* @returns {Promise<TxBuildResult>} transaction build result
|
|
23
|
-
*/
|
|
12
|
+
/** Build an unsigned transfer transaction (ADA-only or with native assets). */
|
|
24
13
|
buildUnsignedTransfer(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
25
|
-
/**
|
|
26
|
-
* Build unsigned transaction with metadata
|
|
27
|
-
* @param req transaction build request
|
|
28
|
-
* @param ctx transaction build context
|
|
29
|
-
* @returns {Promise<TxBuildResult>} transaction build result
|
|
30
|
-
*/
|
|
14
|
+
/** Build an unsigned transaction with attached metadata. */
|
|
31
15
|
buildUnsignedTransactionWithMetadata(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
32
|
-
/**
|
|
33
|
-
* Build unsigned Plutus SC transaction
|
|
34
|
-
* @param req transaction build request
|
|
35
|
-
* @param ctx transaction build context
|
|
36
|
-
* @returns {Promise<TxBuildResult>} transaction build result
|
|
37
|
-
*/
|
|
16
|
+
/** Build an unsigned Plutus mint transaction. */
|
|
38
17
|
buildUnsignedMintTransaction(req: TxBuildMintRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
39
|
-
/**
|
|
40
|
-
* Build unsigned Plutus spending transaction (consume UTxO at script address)
|
|
41
|
-
* @param req transaction build request with plutusScriptExecution
|
|
42
|
-
* @param ctx transaction build context
|
|
43
|
-
* @returns {Promise<TxBuildResult>} transaction build result
|
|
44
|
-
*/
|
|
18
|
+
/** Build an unsigned Plutus spending transaction (consume a UTxO at a script address). */
|
|
45
19
|
buildUnsignedPlutusSpendTransaction(req: TxBuildPlutusSpendRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
20
|
+
buildUnsignedPlutusTransaction(req: TxBuildPlutusRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
46
21
|
}
|
|
47
22
|
//# sourceMappingURL=cardano-tx.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Transaction as CapTransaction } from '@sap/cds';
|
|
2
|
+
export interface TxKey {
|
|
3
|
+
hash: string;
|
|
4
|
+
txSeq: number | string | null;
|
|
5
|
+
}
|
|
6
|
+
/** `txSeq` as a stable map key: Int64 columns come back as number or string depending on the driver. */
|
|
7
|
+
export declare const seqKey: (txSeq: number | string) => string;
|
|
8
|
+
/** Hash and txSeq of the given transactions that are indexed. */
|
|
9
|
+
export declare function readTxKeys(tx: CapTransaction, hashes: string[]): Promise<TxKey[]>;
|
|
10
|
+
/** Delete transactions with their input/output, asset, metadata, certificate, withdrawal and redeemer rows. */
|
|
11
|
+
export declare function deleteTransactionRows(tx: CapTransaction, keys: TxKey[]): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=transaction-rows.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
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.seqKey = void 0;
|
|
7
|
+
exports.readTxKeys = readTxKeys;
|
|
8
|
+
exports.deleteTransactionRows = deleteTransactionRows;
|
|
9
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
11
|
+
const collections_1 = require("../utils/collections");
|
|
12
|
+
const { SELECT, DELETE } = cds_1.default.ql;
|
|
13
|
+
/** `txSeq` as a stable map key: Int64 columns come back as number or string depending on the driver. */
|
|
14
|
+
const seqKey = (txSeq) => String(Number(txSeq));
|
|
15
|
+
exports.seqKey = seqKey;
|
|
16
|
+
/** Hash and txSeq of the given transactions that are indexed. */
|
|
17
|
+
async function readTxKeys(tx, hashes) {
|
|
18
|
+
const keys = [];
|
|
19
|
+
for (const hashChunk of (0, collections_1.chunk)(hashes, collections_1.IN_CHUNK)) {
|
|
20
|
+
const rows = await tx.run(SELECT.from(cardano_1.Transactions).columns('hash', 'txSeq').where({ hash: { in: hashChunk } }));
|
|
21
|
+
keys.push(...(rows ?? []));
|
|
22
|
+
}
|
|
23
|
+
return keys;
|
|
24
|
+
}
|
|
25
|
+
/** Delete transactions with their input/output, asset, metadata, certificate, withdrawal and redeemer rows. */
|
|
26
|
+
async function deleteTransactionRows(tx, keys) {
|
|
27
|
+
for (const keyChunk of (0, collections_1.chunk)(keys, collections_1.IN_CHUNK)) {
|
|
28
|
+
const hashes = keyChunk.map(k => k.hash);
|
|
29
|
+
const seqs = keyChunk.filter(k => k.txSeq != null).map(k => k.txSeq);
|
|
30
|
+
if (seqs.length) {
|
|
31
|
+
await tx.run(DELETE.from(cardano_1.TransactionInputAssets).where({ input_txSeq: { in: seqs } }));
|
|
32
|
+
await tx.run(DELETE.from(cardano_1.TransactionOutputAssets).where({ output_txSeq: { in: seqs } }));
|
|
33
|
+
await tx.run(DELETE.from(cardano_1.TransactionInputs).where({ txSeq: { in: seqs } }));
|
|
34
|
+
await tx.run(DELETE.from(cardano_1.TransactionOutputs).where({ txSeq: { in: seqs } }));
|
|
35
|
+
}
|
|
36
|
+
await tx.run(DELETE.from(cardano_1.TransactionMetadata_).where({ tx_hash: { in: hashes } }));
|
|
37
|
+
await tx.run(DELETE.from(cardano_1.TransactionCertificates).where({ tx_hash: { in: hashes } }));
|
|
38
|
+
await tx.run(DELETE.from(cardano_1.TransactionWithdrawals).where({ tx_hash: { in: hashes } }));
|
|
39
|
+
await tx.run(DELETE.from(cardano_1.TransactionRedeemers).where({ tx_hash: { in: hashes } }));
|
|
40
|
+
await tx.run(DELETE.from(cardano_1.Transactions).where({ hash: { in: hashes } }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=transaction-rows.js.map
|
|
@@ -2,25 +2,12 @@ import type { TxBuildRequest } from '../../utils/types';
|
|
|
2
2
|
import type { Network } from '../cardano-client';
|
|
3
3
|
import type { WalletJobKindValue } from './job-store';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* mintActions with bigint quantities, parsed metadata, assembled
|
|
9
|
-
* plutusScriptExecution, …).
|
|
10
|
-
*
|
|
11
|
-
* The synchronous CardanoTransactionService handlers do this transformation
|
|
12
|
-
* inline per action; the worker executes the SAME payload asynchronously, so
|
|
13
|
-
* this module mirrors that logic using the shared parsers
|
|
14
|
-
* (srv/utils/tx-request-parsers.ts). Validation failures throw
|
|
15
|
-
* BackendError 400 INVALID_INPUT — deterministic, so the job fails terminally
|
|
16
|
-
* instead of burning retries.
|
|
5
|
+
* Transforms a stored wallet-job request (Build*-action payload shape) into the
|
|
6
|
+
* TxBuildRequest the CardanoIndexer build methods expect, mirroring the synchronous handlers.
|
|
7
|
+
* Validation failures throw BackendError 400 INVALID_INPUT so the job fails terminally, not via retries.
|
|
17
8
|
*/
|
|
18
9
|
type RawRequest = Record<string, unknown>;
|
|
19
|
-
/**
|
|
20
|
-
* Transform the raw job request (documented Build*-action payload) into the
|
|
21
|
-
* TxBuildRequest the matching CardanoIndexer build method expects. Throws
|
|
22
|
-
* BackendError 400 INVALID_INPUT for malformed payloads (terminal job failure).
|
|
23
|
-
*/
|
|
10
|
+
/** Raw job request → TxBuildRequest for the matching build method; malformed payloads throw 400 INVALID_INPUT. */
|
|
24
11
|
export declare function prepareWorkerBuildRequest(kind: WalletJobKindValue, raw: RawRequest, network: Network): TxBuildRequest;
|
|
25
12
|
export {};
|
|
26
13
|
//# sourceMappingURL=build-request.d.ts.map
|
|
@@ -12,12 +12,7 @@ const const_1 = require("../../utils/const");
|
|
|
12
12
|
function fail(message) {
|
|
13
13
|
throw new errors_1.BackendError(message, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Presence-only check for required payload fields. Format validation (bech32,
|
|
17
|
-
* hex, amounts) deliberately stays with the builder/indexer, mirroring what a
|
|
18
|
-
* missing field would produce on the synchronous path — the transform's job is
|
|
19
|
-
* the SHAPE, not re-validating content.
|
|
20
|
-
*/
|
|
15
|
+
/** Presence-only check; format validation (bech32, hex, amounts) stays with the builder/indexer. */
|
|
21
16
|
function requirePresent(raw, required) {
|
|
22
17
|
const missing = required.filter((f) => raw[f] === undefined || raw[f] === null || raw[f] === '');
|
|
23
18
|
if (missing.length > 0)
|
|
@@ -29,7 +24,7 @@ function parseJsonField(raw, field) {
|
|
|
29
24
|
return undefined;
|
|
30
25
|
if (typeof value !== 'string')
|
|
31
26
|
fail(`${field} must be a JSON string`);
|
|
32
|
-
const result = (0, validators_1.validateJsonWithLimits)(value, field);
|
|
27
|
+
const result = validators_1.PLUTUS_JSON_FIELDS.has(field) ? (0, validators_1.validatePlutusJson)(value, field) : (0, validators_1.validateJsonWithLimits)(value, field);
|
|
33
28
|
if (!result.valid)
|
|
34
29
|
fail(result.error);
|
|
35
30
|
return result.parsed;
|
|
@@ -42,12 +37,12 @@ function parseScriptParams(raw) {
|
|
|
42
37
|
fail('scriptParamsJson must be a JSON array');
|
|
43
38
|
return parsed;
|
|
44
39
|
}
|
|
45
|
-
/**
|
|
40
|
+
/** Mint-action parsing as in BuildMint/BuildPlutusSpend (bigint quantities, per-action policy fields). */
|
|
46
41
|
function parseMintActions(raw, allowBareNames) {
|
|
47
42
|
const parsed = parseJsonField(raw, 'mintActionsJson');
|
|
48
43
|
if (!Array.isArray(parsed))
|
|
49
44
|
fail('mintActionsJson must be a JSON array');
|
|
50
|
-
return parsed.map((rawAction) => {
|
|
45
|
+
return parsed.map((rawAction, i) => {
|
|
51
46
|
if (!rawAction || typeof rawAction !== 'object') {
|
|
52
47
|
fail('Each mint action must be an object with assetUnit and quantity');
|
|
53
48
|
}
|
|
@@ -57,14 +52,37 @@ function parseMintActions(raw, allowBareNames) {
|
|
|
57
52
|
}
|
|
58
53
|
if (typeof action.assetUnit !== 'string')
|
|
59
54
|
fail('Each mint action must have an assetUnit string');
|
|
60
|
-
|
|
55
|
+
// Optional per-action mintingPolicyScript + redeemerJson (multi-policy mint).
|
|
56
|
+
const policyFields = (0, tx_request_parsers_1.parseMintActionPolicyFields)(action, i);
|
|
57
|
+
if (policyFields.error)
|
|
58
|
+
fail(policyFields.error);
|
|
59
|
+
let actionPolicyId;
|
|
60
|
+
if (policyFields.script) {
|
|
61
|
+
actionPolicyId = scriptHashOf(policyFields.script, `mintActions[${i}].mintingPolicyScript is not a valid Plutus script`);
|
|
62
|
+
}
|
|
63
|
+
const bareAssetNameForExpansion = (allowBareNames || !!actionPolicyId) &&
|
|
61
64
|
action.assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH &&
|
|
62
65
|
action.assetUnit.length % 2 === 0 &&
|
|
63
66
|
/^[0-9a-fA-F]*$/.test(action.assetUnit);
|
|
64
67
|
if (!(0, validators_1.isAssetUnit)(action.assetUnit) && !bareAssetNameForExpansion) {
|
|
65
|
-
fail(`Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson is set)`);
|
|
68
|
+
fail(`Invalid assetUnit: "${action.assetUnit}" — must be policyId+assetName hex (or a bare assetName hex when scriptParamsJson or a per-action mintingPolicyScript is set)`);
|
|
69
|
+
}
|
|
70
|
+
let assetUnit = action.assetUnit;
|
|
71
|
+
if (actionPolicyId) {
|
|
72
|
+
if (assetUnit.length < const_1.MIN_FULL_ASSET_UNIT_LENGTH) {
|
|
73
|
+
assetUnit = actionPolicyId + assetUnit;
|
|
74
|
+
}
|
|
75
|
+
else if (!assetUnit.toLowerCase().startsWith(actionPolicyId)) {
|
|
76
|
+
fail(`mintActions[${i}].assetUnit "${assetUnit}" does not start with its own policy id ${actionPolicyId}`);
|
|
77
|
+
}
|
|
66
78
|
}
|
|
67
|
-
return {
|
|
79
|
+
return {
|
|
80
|
+
assetUnit,
|
|
81
|
+
quantity: BigInt(action.quantity),
|
|
82
|
+
...(typeof action.redeemer === 'number' ? { redeemer: action.redeemer } : {}),
|
|
83
|
+
...(policyFields.script ? { mintingPolicyScript: policyFields.script } : {}),
|
|
84
|
+
...(policyFields.redeemer !== undefined ? { redeemerJson: policyFields.redeemer } : {})
|
|
85
|
+
};
|
|
68
86
|
});
|
|
69
87
|
}
|
|
70
88
|
function scriptHashOf(scriptHex, context) {
|
|
@@ -76,12 +94,12 @@ function scriptHashOf(scriptHex, context) {
|
|
|
76
94
|
}
|
|
77
95
|
}
|
|
78
96
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* would mint a truncated asset name.
|
|
97
|
+
* Every mint action must carry the effective policy id: parseAssetUnit drops the first
|
|
98
|
+
* 56 hex chars, so a mismatched prefix would mint a truncated asset name.
|
|
82
99
|
*/
|
|
83
100
|
function assertPolicyPrefix(actions, policyId) {
|
|
84
|
-
|
|
101
|
+
// Actions with their own script were already checked against that script's policy id.
|
|
102
|
+
const mismatch = actions.find((a) => !a.mintingPolicyScript && !a.assetUnit.toLowerCase().startsWith(policyId));
|
|
85
103
|
if (mismatch) {
|
|
86
104
|
fail(`assetUnit "${mismatch.assetUnit}" does not start with the minting policy id ${policyId} — pass the full unit as policyId+assetName (asset names longer than 28 bytes cannot be passed bare)`);
|
|
87
105
|
}
|
|
@@ -96,6 +114,8 @@ function prepareSimpleAda(raw, network) {
|
|
|
96
114
|
const clean = { ...raw };
|
|
97
115
|
clean.forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
98
116
|
delete clean.forceInputsJson;
|
|
117
|
+
clean.protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
|
|
118
|
+
delete clean.protectInputsJson;
|
|
99
119
|
const outputDatum = parseJsonField(raw, 'outputDatumJson');
|
|
100
120
|
if (outputDatum !== undefined)
|
|
101
121
|
clean.outputDatum = outputDatum;
|
|
@@ -152,7 +172,9 @@ function prepareMint(raw, network) {
|
|
|
152
172
|
const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
|
|
153
173
|
const mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
|
|
154
174
|
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
175
|
+
const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
|
|
155
176
|
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
177
|
+
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
156
178
|
if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
|
|
157
179
|
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
158
180
|
}
|
|
@@ -171,7 +193,9 @@ function prepareMint(raw, network) {
|
|
|
171
193
|
delete clean.mintRedeemerJson;
|
|
172
194
|
delete clean.lockOnScript;
|
|
173
195
|
delete clean.forceInputsJson;
|
|
196
|
+
delete clean.protectInputsJson;
|
|
174
197
|
delete clean.referenceInputsJson;
|
|
198
|
+
delete clean.extraOutputsJson;
|
|
175
199
|
if (parsedMetadata)
|
|
176
200
|
clean.metadataJson = parsedMetadata;
|
|
177
201
|
else
|
|
@@ -179,8 +203,7 @@ function prepareMint(raw, network) {
|
|
|
179
203
|
if (raw.referenceScriptHex)
|
|
180
204
|
clean.referenceScript = raw.referenceScriptHex;
|
|
181
205
|
delete clean.referenceScriptHex;
|
|
182
|
-
// Apply script parameters
|
|
183
|
-
// route lockOnScript output — mirrors BuildMintTransaction.
|
|
206
|
+
// Apply script parameters, expand bare asset names, route lockOnScript output.
|
|
184
207
|
let finalMintingPolicyScript = raw.mintingPolicyScript;
|
|
185
208
|
let effectivePolicyId;
|
|
186
209
|
if (scriptParams && scriptParams.length > 0) {
|
|
@@ -218,7 +241,9 @@ function prepareMint(raw, network) {
|
|
|
218
241
|
inlineDatum,
|
|
219
242
|
mintRedeemer,
|
|
220
243
|
forceInputs,
|
|
244
|
+
protectInputs,
|
|
221
245
|
referenceInputs,
|
|
246
|
+
extraOutputs,
|
|
222
247
|
};
|
|
223
248
|
}
|
|
224
249
|
function preparePlutusSpend(raw, network) {
|
|
@@ -235,9 +260,10 @@ function preparePlutusSpend(raw, network) {
|
|
|
235
260
|
fail('lockOnScript requires scriptParamsJson to derive script address');
|
|
236
261
|
}
|
|
237
262
|
const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
|
|
263
|
+
const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
|
|
238
264
|
const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
|
|
239
265
|
const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
|
|
240
|
-
// Optional combined spend+mint
|
|
266
|
+
// Optional combined spend+mint.
|
|
241
267
|
const validatorScript = raw.validatorScript;
|
|
242
268
|
const mintingPolicyScript = raw.mintingPolicyScript;
|
|
243
269
|
let mintActions;
|
|
@@ -297,6 +323,7 @@ function preparePlutusSpend(raw, network) {
|
|
|
297
323
|
requiredSigners,
|
|
298
324
|
inlineDatum,
|
|
299
325
|
forceInputs,
|
|
326
|
+
protectInputs,
|
|
300
327
|
referenceInputs,
|
|
301
328
|
extraOutputs,
|
|
302
329
|
mintActions,
|
|
@@ -309,6 +336,7 @@ function preparePlutusSpend(raw, network) {
|
|
|
309
336
|
delete clean.scriptParamsJson;
|
|
310
337
|
delete clean.inlineDatumJson;
|
|
311
338
|
delete clean.forceInputsJson;
|
|
339
|
+
delete clean.protectInputsJson;
|
|
312
340
|
delete clean.referenceInputsJson;
|
|
313
341
|
delete clean.extraOutputsJson;
|
|
314
342
|
delete clean.mintActionsJson;
|
|
@@ -322,11 +350,7 @@ function preparePlutusSpend(raw, network) {
|
|
|
322
350
|
delete clean.lockOnScript;
|
|
323
351
|
return clean;
|
|
324
352
|
}
|
|
325
|
-
/**
|
|
326
|
-
* Transform the raw job request (documented Build*-action payload) into the
|
|
327
|
-
* TxBuildRequest the matching CardanoIndexer build method expects. Throws
|
|
328
|
-
* BackendError 400 INVALID_INPUT for malformed payloads (terminal job failure).
|
|
329
|
-
*/
|
|
353
|
+
/** Raw job request → TxBuildRequest for the matching build method; malformed payloads throw 400 INVALID_INPUT. */
|
|
330
354
|
function prepareWorkerBuildRequest(kind, raw, network) {
|
|
331
355
|
switch (kind) {
|
|
332
356
|
case 'simpleAda': return prepareSimpleAda(raw, network);
|
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
import type { CardanoClient } from '../cardano-client';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* submitted tx hashes and carry the advancing tip; `reorg` events invalidate
|
|
8
|
-
* confirmation points behind the fork and optionally re-submit the SAME
|
|
9
|
-
* signed CBOR (never a rebuild — the double-spend guard).
|
|
10
|
-
* - Polling fallback (always on, hook path just accelerates): every
|
|
11
|
-
* `pollIntervalMs` unfound txs are looked up via `client.getTransaction`
|
|
12
|
-
* and the tip via `client.getLatestBlock`.
|
|
13
|
-
*
|
|
14
|
-
* A tx that stays unseen past `confirmationTimeoutMs` fails as TX_DROPPED —
|
|
15
|
-
* safe to retry from the caller, because the guard is the on-chain lookup itself.
|
|
16
|
-
*
|
|
17
|
-
* Confirmations are counted as `tipHeight - foundHeight + 1`, so depth 1 means
|
|
18
|
-
* "confirmed as soon as included in a block".
|
|
3
|
+
* Watches `submitted` jobs until their tx sits at depth >= `confirmationDepth`, via crawler
|
|
4
|
+
* `blockIndexed`/`reorg` hooks plus an always-on polling fallback. A reorg re-submits the SAME
|
|
5
|
+
* signed CBOR (never a rebuild); a tx unseen past `confirmationTimeoutMs` fails as TX_DROPPED.
|
|
6
|
+
* Depth = `tipHeight - foundHeight + 1`, so depth 1 means "included in a block".
|
|
19
7
|
*/
|
|
20
8
|
export interface TrackedJob {
|
|
21
9
|
jobId: string;
|
|
@@ -28,6 +16,11 @@ export interface TrackedJob {
|
|
|
28
16
|
submittedAt: string;
|
|
29
17
|
foundSlot: number | null;
|
|
30
18
|
foundHeight: number | null;
|
|
19
|
+
/**
|
|
20
|
+
* Polling round in which the tx was last seen on-chain. An inclusion from an earlier
|
|
21
|
+
* round is re-checked before confirming, so a rollback the crawler did not report cannot slip through.
|
|
22
|
+
*/
|
|
23
|
+
seenRound?: number;
|
|
31
24
|
}
|
|
32
25
|
export interface ConfirmationTrackerOptions {
|
|
33
26
|
confirmationDepth: number;
|
|
@@ -59,6 +52,8 @@ export declare class ConfirmationTracker {
|
|
|
59
52
|
private running;
|
|
60
53
|
private polling;
|
|
61
54
|
private lastKnownTipHeight;
|
|
55
|
+
/** Polling round counter; see TrackedJob.seenRound. */
|
|
56
|
+
private round;
|
|
62
57
|
constructor(deps: ConfirmationTrackerDeps);
|
|
63
58
|
start(): void;
|
|
64
59
|
stop(): void;
|
|
@@ -77,10 +72,23 @@ export declare class ConfirmationTracker {
|
|
|
77
72
|
}): void;
|
|
78
73
|
private onBlockIndexed;
|
|
79
74
|
private onReorg;
|
|
75
|
+
/**
|
|
76
|
+
* Inclusion rolled back: back to watching, optionally re-submitting the SAME signed CBOR
|
|
77
|
+
* (never a rebuild — the double-spend guard). "Already known" means the tx survived; success.
|
|
78
|
+
*/
|
|
79
|
+
private forgetInclusion;
|
|
80
80
|
/** One polling round. Public for tests; guarded against overlapping rounds. */
|
|
81
81
|
pollOnce(): Promise<void>;
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Confirm every found job whose depth is met by the known tip. With `revalidate`
|
|
84
|
+
* (polling path) an inclusion not seen in this round is looked up again first.
|
|
85
|
+
*/
|
|
83
86
|
private confirmMature;
|
|
87
|
+
/**
|
|
88
|
+
* Is the tx still on-chain and deep enough? A tx that moved blocks is re-anchored at its
|
|
89
|
+
* new height; one that is gone goes back to watching and the tip is re-learned next round.
|
|
90
|
+
*/
|
|
91
|
+
private stillIncluded;
|
|
84
92
|
private finalize;
|
|
85
93
|
}
|
|
86
94
|
//# sourceMappingURL=confirmation-tracker.d.ts.map
|