@odatano/core 2.0.0-rc.24 → 2.0.0-rc.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoIndexerService/index.d.ts +37 -0
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +27 -2
- package/@cds-models/CardanoODataService/index.js +3 -0
- package/@cds-models/CardanoSignService/index.d.ts +23 -1
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +34 -1
- 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 +49 -2
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/README.md +195 -195
- package/db/schema.cds +74 -3
- package/db/types.cds +27 -0
- package/package.json +182 -182
- package/srv/blockchain/backends/blockfrost-backend.js +4 -2
- package/srv/blockchain/backends/cardano-backend.d.ts +0 -2
- package/srv/blockchain/backends/koios-backend.d.ts +1 -1
- package/srv/blockchain/backends/koios-backend.js +61 -14
- package/srv/blockchain/backends/odatano-backend.d.ts +5 -0
- package/srv/blockchain/backends/odatano-backend.js +12 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +12 -2
- package/srv/blockchain/backends/ogmios-backend.js +91 -21
- package/srv/blockchain/cardano-client.d.ts +11 -5
- package/srv/blockchain/cardano-client.js +51 -16
- package/srv/blockchain/cardano-indexer.d.ts +43 -15
- package/srv/blockchain/cardano-indexer.js +177 -68
- package/srv/blockchain/cardano-tx-builder.d.ts +11 -1
- package/srv/blockchain/cardano-tx-builder.js +57 -2
- package/srv/blockchain/crawler/certificate-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/certificate-backfill.js +49 -30
- package/srv/blockchain/crawler/crawler.d.ts +3 -1
- package/srv/blockchain/crawler/crawler.js +12 -7
- package/srv/blockchain/crawler/sync-state.d.ts +3 -1
- package/srv/blockchain/crawler/sync-state.js +15 -2
- 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 +9 -0
- package/srv/blockchain/crawler/utxo-set-import.js +138 -47
- package/srv/blockchain/ledger-state.d.ts +16 -1
- package/srv/blockchain/ledger-state.js +38 -18
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -0
- package/srv/blockchain/stored-chain.d.ts +5 -2
- package/srv/blockchain/stored-chain.js +31 -5
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +12 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +203 -21
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +2 -1
- package/srv/blockchain/transaction-rows.d.ts +1 -1
- package/srv/blockchain/transaction-rows.js +2 -1
- package/srv/blockchain/wallet-worker/build-request.js +1 -1
- package/srv/cardano-backend-service.js +35 -8
- package/srv/cardano-indexer-service.cds +201 -176
- package/srv/cardano-indexer-service.js +104 -10
- package/srv/cardano-service.cds +5 -0
- package/srv/cardano-service.js +3 -1
- package/srv/cardano-tx-service.cds +39 -0
- package/srv/cardano-tx-service.js +88 -14
- package/srv/server.js +4 -1
- package/srv/utils/agent-grants.js +1 -0
- package/srv/utils/const.d.ts +5 -0
- package/srv/utils/const.js +6 -1
- package/srv/utils/error-codes.d.ts +2 -0
- package/srv/utils/error-codes.js +2 -0
- package/srv/utils/errors.d.ts +7 -0
- package/srv/utils/errors.js +11 -1
- package/srv/utils/mappers.d.ts +24 -2
- package/srv/utils/mappers.js +49 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +63 -0
- package/srv/utils/tx-build-helper.d.ts +2 -0
- package/srv/utils/tx-build-helper.js +12 -0
- package/srv/utils/tx-request-parsers.d.ts +46 -5
- package/srv/utils/tx-request-parsers.js +227 -16
- package/srv/utils/types.d.ts +59 -0
- package/srv/utils/validators.d.ts +5 -1
- package/srv/utils/validators.js +19 -9
|
@@ -1,176 +1,201 @@
|
|
|
1
|
-
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cardano Indexer Service (v2.0)
|
|
5
|
-
*
|
|
6
|
-
* Control + observability surface for the chain crawler / pre-sync engine:
|
|
7
|
-
* - read-only projections of the sync cursor and reorg audit log
|
|
8
|
-
* - status function + pause/resume actions delegating to the crawler singleton
|
|
9
|
-
*
|
|
10
|
-
* Security note: see CardanoODataService (cardano-service.cds) for the rationale on
|
|
11
|
-
* auth. pause/resume are operational actions — gate behind a dedicated Admin scope.
|
|
12
|
-
* Read-only status and audit data remain available to authenticated users.
|
|
13
|
-
*
|
|
14
|
-
* Deliberately NO service-level @requires: CAP checks a service-level requirement
|
|
15
|
-
* on every request BEFORE the operation's own annotation, so an operation-level
|
|
16
|
-
* `@requires: 'any'` can never open a single function on an otherwise
|
|
17
|
-
* authenticated service (anonymous callers get the 401 challenge first). The
|
|
18
|
-
* requirement therefore sits on each element, and getLiveness() alone is 'any'.
|
|
19
|
-
*/
|
|
20
|
-
// Service-level 'any' on purpose: CAP authorizes the service BEFORE the operation and
|
|
21
|
-
// treats a service without a service-level @requires as authenticated-user under
|
|
22
|
-
// NODE_ENV=production, which would 401 the anonymous operation below despite its own
|
|
23
|
-
// 'any'. Every element carries its requirement; the service itself refuses nothing.
|
|
24
|
-
@requires: 'any'
|
|
25
|
-
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
26
|
-
|
|
27
|
-
@readonly
|
|
28
|
-
@requires : 'authenticated-user'
|
|
29
|
-
@title : 'Sync State'
|
|
30
|
-
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
31
|
-
entity SyncState as projection on db.CardanoSyncState;
|
|
32
|
-
|
|
33
|
-
@readonly
|
|
34
|
-
@requires : 'authenticated-user'
|
|
35
|
-
@title : 'Reorg Log'
|
|
36
|
-
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
37
|
-
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
38
|
-
|
|
39
|
-
@title : 'Crawler Status'
|
|
40
|
-
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
41
|
-
type CrawlerStatus {
|
|
42
|
-
running : Boolean;
|
|
43
|
-
syncStatus : String;
|
|
44
|
-
// 'chain-sync' | 'pagination' for the crawler in this process; null when this
|
|
45
|
-
// instance is not the one crawling. Pagination is ~50x slower, and a crawl that
|
|
46
|
-
// degraded to it still advances the cursor — this is how an operator tells.
|
|
47
|
-
source : String;
|
|
48
|
-
lastSlot : String;
|
|
49
|
-
lastHeight : String;
|
|
50
|
-
tipHeight : String;
|
|
51
|
-
syncProgress : String;
|
|
52
|
-
consecutiveErrors : Integer;
|
|
53
|
-
// crawler-fed ledger state (crawler.utxoSet): snapshot anchor + validity
|
|
54
|
-
utxoSet : UtxoSetStatus;
|
|
55
|
-
// one-off certificate/withdrawal backfill over already crawled blocks (this process)
|
|
56
|
-
certificateBackfill : CertificateBackfillStatus;
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
@
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
@
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
@title : '
|
|
173
|
-
@description: '
|
|
174
|
-
@requires : '
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cardano Indexer Service (v2.0)
|
|
5
|
+
*
|
|
6
|
+
* Control + observability surface for the chain crawler / pre-sync engine:
|
|
7
|
+
* - read-only projections of the sync cursor and reorg audit log
|
|
8
|
+
* - status function + pause/resume actions delegating to the crawler singleton
|
|
9
|
+
*
|
|
10
|
+
* Security note: see CardanoODataService (cardano-service.cds) for the rationale on
|
|
11
|
+
* auth. pause/resume are operational actions — gate behind a dedicated Admin scope.
|
|
12
|
+
* Read-only status and audit data remain available to authenticated users.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately NO service-level @requires: CAP checks a service-level requirement
|
|
15
|
+
* on every request BEFORE the operation's own annotation, so an operation-level
|
|
16
|
+
* `@requires: 'any'` can never open a single function on an otherwise
|
|
17
|
+
* authenticated service (anonymous callers get the 401 challenge first). The
|
|
18
|
+
* requirement therefore sits on each element, and getLiveness() alone is 'any'.
|
|
19
|
+
*/
|
|
20
|
+
// Service-level 'any' on purpose: CAP authorizes the service BEFORE the operation and
|
|
21
|
+
// treats a service without a service-level @requires as authenticated-user under
|
|
22
|
+
// NODE_ENV=production, which would 401 the anonymous operation below despite its own
|
|
23
|
+
// 'any'. Every element carries its requirement; the service itself refuses nothing.
|
|
24
|
+
@requires: 'any'
|
|
25
|
+
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
26
|
+
|
|
27
|
+
@readonly
|
|
28
|
+
@requires : 'authenticated-user'
|
|
29
|
+
@title : 'Sync State'
|
|
30
|
+
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
31
|
+
entity SyncState as projection on db.CardanoSyncState;
|
|
32
|
+
|
|
33
|
+
@readonly
|
|
34
|
+
@requires : 'authenticated-user'
|
|
35
|
+
@title : 'Reorg Log'
|
|
36
|
+
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
37
|
+
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
38
|
+
|
|
39
|
+
@title : 'Crawler Status'
|
|
40
|
+
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
41
|
+
type CrawlerStatus {
|
|
42
|
+
running : Boolean;
|
|
43
|
+
syncStatus : String;
|
|
44
|
+
// 'chain-sync' | 'pagination' for the crawler in this process; null when this
|
|
45
|
+
// instance is not the one crawling. Pagination is ~50x slower, and a crawl that
|
|
46
|
+
// degraded to it still advances the cursor — this is how an operator tells.
|
|
47
|
+
source : String;
|
|
48
|
+
lastSlot : String;
|
|
49
|
+
lastHeight : String;
|
|
50
|
+
tipHeight : String;
|
|
51
|
+
syncProgress : String;
|
|
52
|
+
consecutiveErrors : Integer;
|
|
53
|
+
// crawler-fed ledger state (crawler.utxoSet): snapshot anchor + validity
|
|
54
|
+
utxoSet : UtxoSetStatus;
|
|
55
|
+
// one-off certificate/withdrawal backfill over already crawled blocks (this process)
|
|
56
|
+
certificateBackfill : CertificateBackfillStatus;
|
|
57
|
+
// one-off input/redeemer backfill over already crawled blocks (this process)
|
|
58
|
+
transactionBackfill : TransactionBackfillStatus;
|
|
59
|
+
// per-epoch pool/DRep/pot snapshots (crawler.epochSnapshots)
|
|
60
|
+
epochSnapshots : EpochSnapshotStatus;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@title : 'Epoch Snapshot Status'
|
|
64
|
+
@description: 'Latest epoch snapshot and the source this process would use for the next one'
|
|
65
|
+
type EpochSnapshotStatus {
|
|
66
|
+
enabled : Boolean; // crawler.epochSnapshots configured
|
|
67
|
+
source : String; // ogmios | koios | null (no usable backend)
|
|
68
|
+
lastEpoch : Integer; // newest snapshotted epoch; null before the first
|
|
69
|
+
lastSource: String; // source of that snapshot
|
|
70
|
+
lastSlot : String; // block it was taken at
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@title : 'Certificate Backfill Status'
|
|
74
|
+
@description: 'Progress of the certificate/withdrawal backfill started with backfillCertificates; process-local, none after a restart'
|
|
75
|
+
type CertificateBackfillStatus {
|
|
76
|
+
status : String; // none | running | done | failed
|
|
77
|
+
fromSlot : String;
|
|
78
|
+
toSlot : String;
|
|
79
|
+
atSlot : String; // last slot handled
|
|
80
|
+
blocks : Integer64;
|
|
81
|
+
certificates : Integer64;
|
|
82
|
+
withdrawals : Integer64;
|
|
83
|
+
startedAt : Timestamp;
|
|
84
|
+
finishedAt : Timestamp;
|
|
85
|
+
error : String;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@title : 'Transaction Backfill Status'
|
|
89
|
+
@description: 'Progress of the backfill started with backfillTransactions; process-local, none after a restart'
|
|
90
|
+
type TransactionBackfillStatus {
|
|
91
|
+
status : String; // none | running | done | failed
|
|
92
|
+
fromSlot : String;
|
|
93
|
+
toSlot : String;
|
|
94
|
+
atSlot : String; // last slot handled
|
|
95
|
+
blocks : Integer64;
|
|
96
|
+
transactions : Integer64;
|
|
97
|
+
inputs : Integer64; // input rows that got at least one field
|
|
98
|
+
redeemers : Integer64;
|
|
99
|
+
rewritten : Integer64; // transactions whose stored rows differed in order or extent from the ledger view, now rewritten
|
|
100
|
+
skipped : Integer64; // transactions whose stored inputs differ from the stream
|
|
101
|
+
startedAt : Timestamp;
|
|
102
|
+
finishedAt : Timestamp;
|
|
103
|
+
error : String;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@title : 'Certificate Backfill Result'
|
|
107
|
+
type CertificateBackfillResult {
|
|
108
|
+
accepted : Boolean;
|
|
109
|
+
fromSlot : String;
|
|
110
|
+
toSlot : String;
|
|
111
|
+
message : String;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@title : 'UTxO Set Status'
|
|
115
|
+
@description: 'State of the crawler-maintained UTxO set (crawler.utxoSet)'
|
|
116
|
+
type UtxoSetStatus {
|
|
117
|
+
enabled : Boolean; // crawler.utxoSet configured
|
|
118
|
+
status : String; // none | importing | active | invalid
|
|
119
|
+
anchorSlot : String; // null until imported
|
|
120
|
+
anchorHash : String;
|
|
121
|
+
importedAt : Timestamp;
|
|
122
|
+
error : String; // why invalid
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@title : 'UTxO Set Import Result'
|
|
126
|
+
type UtxoSetImportResult {
|
|
127
|
+
accepted : Boolean;
|
|
128
|
+
anchorSlot : String;
|
|
129
|
+
anchorHash : String;
|
|
130
|
+
message : String;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@title : 'Get Crawler Status'
|
|
134
|
+
@description: 'Return the current crawler run state and sync progress'
|
|
135
|
+
/**
|
|
136
|
+
* Emitted AFTER each block is committed. Subscribe instead of polling:
|
|
137
|
+
* (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
138
|
+
* In-process (plugin mode) this needs no messaging service.
|
|
139
|
+
*/
|
|
140
|
+
event blockIndexed {
|
|
141
|
+
hash : String(64);
|
|
142
|
+
slot : Integer64;
|
|
143
|
+
height : Integer64;
|
|
144
|
+
txHashes : many String(64);
|
|
145
|
+
tipSlot : Integer64;
|
|
146
|
+
tipHeight: Integer64;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Emitted AFTER a rollback is committed. Everything above `forkSlot` was removed. */
|
|
150
|
+
event reorg {
|
|
151
|
+
forkSlot : Integer64;
|
|
152
|
+
forkHeight : Integer64;
|
|
153
|
+
blocksRolledBack : Integer;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@requires : 'authenticated-user'
|
|
157
|
+
function getStatus() returns CrawlerStatus;
|
|
158
|
+
|
|
159
|
+
@title : 'Liveness'
|
|
160
|
+
type Liveness {
|
|
161
|
+
status : String; // 'alive'
|
|
162
|
+
timestamp : Timestamp;
|
|
163
|
+
uptime : Integer; // seconds since process start
|
|
164
|
+
version : String; // @odatano/core version
|
|
165
|
+
network : String; // configured network
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Anonymous on purpose: a liveness probe carries no credentials. 200 as long
|
|
169
|
+
// as the process answers — no backend or DB probe, no secrets, no backend
|
|
170
|
+
// names, no API key state. Readiness stays with getStatus and the worker
|
|
171
|
+
// status, which remain authenticated.
|
|
172
|
+
@title : 'Get Liveness'
|
|
173
|
+
@description: 'Unauthenticated liveness probe: 200 while the process answers. Docker HEALTHCHECK and upstream probes use this instead of the service document.'
|
|
174
|
+
@requires : 'any'
|
|
175
|
+
function getLiveness() returns Liveness;
|
|
176
|
+
|
|
177
|
+
@title : 'Pause Crawler'
|
|
178
|
+
@description: 'Stop the crawler (closes the chain-sync stream). Resume continues from the cursor.'
|
|
179
|
+
@requires : 'Admin'
|
|
180
|
+
action pauseCrawler() returns Boolean;
|
|
181
|
+
|
|
182
|
+
@title : 'Resume Crawler'
|
|
183
|
+
@description: 'Start/restart the crawler from the persisted cursor using the configured source.'
|
|
184
|
+
@requires : 'Admin'
|
|
185
|
+
action resumeCrawler() returns Boolean;
|
|
186
|
+
|
|
187
|
+
@title : 'Import UTxO Set'
|
|
188
|
+
@description: 'One-off import of the UTxO set that anchors crawler.utxoSet. Pause the crawler first. source=ogmios acquires the set at the crawler cursor (crawl must be at the tip); source=file loads a cardano-cli query utxo --whole-utxo dump (.json, or .ndjson from jq -c to_entries[]) taken at anchorSlot/anchorHash. source=aggregates rebuilds only the sums (LedgerAddresses, LedgerAddressAssets, LedgerAccounts) from the rows an earlier import left, e.g. after its aggregate phase failed; a cursor past the anchor is set back to it. Runs in the background; progress via getStatus().utxoSet.'
|
|
189
|
+
@requires : 'Admin'
|
|
190
|
+
action importUtxoSet(source: String, filePath: String, anchorSlot: Integer64, anchorHash: String) returns UtxoSetImportResult;
|
|
191
|
+
|
|
192
|
+
@title : 'Backfill Certificates'
|
|
193
|
+
@description: 'Fill TransactionCertificates and TransactionWithdrawals for blocks the crawl already holds, from a second chain-sync stream (Ogmios). fromSlot defaults to the crawl start, toSlot to the cursor. Writes only those two tables; the crawler may keep running. Runs in the background; progress via getStatus().certificateBackfill.'
|
|
194
|
+
@requires : 'Admin'
|
|
195
|
+
action backfillCertificates(fromSlot: Integer64, toSlot: Integer64) returns CertificateBackfillResult;
|
|
196
|
+
|
|
197
|
+
@title : 'Backfill Transactions'
|
|
198
|
+
@description: 'Complete transactions the crawl already holds from a second chain-sync stream (Ogmios): input outpoints, the spent output datum and reference-script hash, missing input addresses, and TransactionRedeemers. Fills empty fields only; a transaction whose stored inputs differ from the stream is skipped. fromSlot defaults to the crawl start, toSlot to the cursor; the crawler may keep running. Runs in the background; progress via getStatus().transactionBackfill.'
|
|
199
|
+
@requires : 'Admin'
|
|
200
|
+
action backfillTransactions(fromSlot: Integer64, toSlot: Integer64) returns CertificateBackfillResult;
|
|
201
|
+
}
|
|
@@ -10,6 +10,7 @@ const crawler_1 = require("./blockchain/crawler");
|
|
|
10
10
|
const sync_state_1 = require("./blockchain/crawler/sync-state");
|
|
11
11
|
const utxo_set_import_1 = require("./blockchain/crawler/utxo-set-import");
|
|
12
12
|
const certificate_backfill_1 = require("./blockchain/crawler/certificate-backfill");
|
|
13
|
+
const transaction_backfill_1 = require("./blockchain/crawler/transaction-backfill");
|
|
13
14
|
const validators_1 = require("./utils/validators");
|
|
14
15
|
const server_1 = require("./server");
|
|
15
16
|
const liveness_1 = require("./utils/liveness");
|
|
@@ -24,6 +25,24 @@ let certificateBackfill = {
|
|
|
24
25
|
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
|
|
25
26
|
startedAt: null, finishedAt: null, error: null,
|
|
26
27
|
};
|
|
28
|
+
let transactionBackfillStarting = false;
|
|
29
|
+
let transactionBackfill = {
|
|
30
|
+
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0,
|
|
31
|
+
startedAt: null, finishedAt: null, error: null,
|
|
32
|
+
};
|
|
33
|
+
/** Slot range of a backfill: defaults to crawl start .. cursor, never past the cursor. */
|
|
34
|
+
async function backfillRange(db, data) {
|
|
35
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
36
|
+
if (!cursor)
|
|
37
|
+
throw new errors_1.TransactionValidationError('No crawler cursor yet — the backfill covers crawled blocks only.');
|
|
38
|
+
const fromSlot = data.fromSlot != null ? Number(data.fromSlot) : (cursor.startSlot ?? 0);
|
|
39
|
+
const toSlot = data.toSlot != null ? Number(data.toSlot) : cursor.lastSlot;
|
|
40
|
+
if (toSlot < fromSlot)
|
|
41
|
+
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} lies before fromSlot ${fromSlot}.`);
|
|
42
|
+
if (toSlot > cursor.lastSlot)
|
|
43
|
+
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} is past the crawler cursor (slot ${cursor.lastSlot}) — only crawled blocks can be backfilled.`);
|
|
44
|
+
return { fromSlot, toSlot };
|
|
45
|
+
}
|
|
27
46
|
function utxoSetConfigured() {
|
|
28
47
|
try {
|
|
29
48
|
return Boolean((0, server_1.loadCrawlerConfigFromEnv)()?.utxoSet);
|
|
@@ -97,6 +116,21 @@ module.exports = (srv) => {
|
|
|
97
116
|
finishedAt: certificateBackfill.finishedAt,
|
|
98
117
|
error: certificateBackfill.error,
|
|
99
118
|
},
|
|
119
|
+
transactionBackfill: {
|
|
120
|
+
status: transactionBackfill.status,
|
|
121
|
+
fromSlot: String(transactionBackfill.fromSlot),
|
|
122
|
+
toSlot: String(transactionBackfill.toSlot),
|
|
123
|
+
atSlot: String(transactionBackfill.atSlot),
|
|
124
|
+
blocks: transactionBackfill.blocks,
|
|
125
|
+
transactions: transactionBackfill.transactions,
|
|
126
|
+
inputs: transactionBackfill.inputs,
|
|
127
|
+
redeemers: transactionBackfill.redeemers,
|
|
128
|
+
rewritten: transactionBackfill.rewritten,
|
|
129
|
+
skipped: transactionBackfill.skipped,
|
|
130
|
+
startedAt: transactionBackfill.startedAt,
|
|
131
|
+
finishedAt: transactionBackfill.finishedAt,
|
|
132
|
+
error: transactionBackfill.error,
|
|
133
|
+
},
|
|
100
134
|
epochSnapshots: {
|
|
101
135
|
enabled: epochSnapshotsConfigured(),
|
|
102
136
|
source: epochSnapshotSource(),
|
|
@@ -122,15 +156,7 @@ module.exports = (srv) => {
|
|
|
122
156
|
certificateBackfillStarting = true;
|
|
123
157
|
try {
|
|
124
158
|
return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
125
|
-
const
|
|
126
|
-
if (!cursor)
|
|
127
|
-
throw new errors_1.TransactionValidationError('No crawler cursor yet — the backfill covers crawled blocks only.');
|
|
128
|
-
const fromSlot = data.fromSlot != null ? Number(data.fromSlot) : (cursor.startSlot ?? 0);
|
|
129
|
-
const toSlot = data.toSlot != null ? Number(data.toSlot) : cursor.lastSlot;
|
|
130
|
-
if (toSlot < fromSlot)
|
|
131
|
-
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} lies before fromSlot ${fromSlot}.`);
|
|
132
|
-
if (toSlot > cursor.lastSlot)
|
|
133
|
-
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} is past the crawler cursor (slot ${cursor.lastSlot}) — only crawled blocks can be backfilled.`);
|
|
159
|
+
const { fromSlot, toSlot } = await backfillRange(db, data);
|
|
134
160
|
certificateBackfill = {
|
|
135
161
|
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
|
|
136
162
|
startedAt: new Date().toISOString(), finishedAt: null, error: null,
|
|
@@ -161,13 +187,81 @@ module.exports = (srv) => {
|
|
|
161
187
|
certificateBackfillStarting = false;
|
|
162
188
|
}
|
|
163
189
|
});
|
|
190
|
+
// backfillTransactions — second chain-sync stream over already crawled blocks; fills empty
|
|
191
|
+
// input fields (outpoint, datum, address) and the redeemers. Validates, then runs detached.
|
|
192
|
+
srv.on('backfillTransactions', async (req) => {
|
|
193
|
+
const data = (req.data ?? {});
|
|
194
|
+
if (data.fromSlot != null && !Number.isInteger(Number(data.fromSlot)))
|
|
195
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'fromSlot must be an integer', 'fromSlot');
|
|
196
|
+
if (data.toSlot != null && !Number.isInteger(Number(data.toSlot)))
|
|
197
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'toSlot must be an integer', 'toSlot');
|
|
198
|
+
if (transactionBackfill.status === 'running' || transactionBackfillStarting)
|
|
199
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'A transaction backfill is already running');
|
|
200
|
+
if (!(0, server_1.getCardanoClient)().getChainSyncBackend())
|
|
201
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'No chain-sync backend available (needs Ogmios)');
|
|
202
|
+
transactionBackfillStarting = true;
|
|
203
|
+
try {
|
|
204
|
+
return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
205
|
+
const { fromSlot, toSlot } = await backfillRange(db, data);
|
|
206
|
+
transactionBackfill = {
|
|
207
|
+
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0,
|
|
208
|
+
startedAt: new Date().toISOString(), finishedAt: null, error: null,
|
|
209
|
+
};
|
|
210
|
+
void (0, transaction_backfill_1.backfillTransactions)({
|
|
211
|
+
client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(), fromSlot, toSlot,
|
|
212
|
+
onProgress: (p) => {
|
|
213
|
+
Object.assign(transactionBackfill, p);
|
|
214
|
+
if (transactionBackfill.blocks % 20_000 < 200)
|
|
215
|
+
logger.info(`Transaction backfill at slot ${p.atSlot}: ${p.blocks} blocks, ${p.inputs} inputs, ${p.redeemers} redeemers`);
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
.then((r) => { Object.assign(transactionBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
|
|
219
|
+
.catch((err) => {
|
|
220
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
221
|
+
Object.assign(transactionBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
|
|
222
|
+
logger.error(`Transaction backfill failed: ${message}`);
|
|
223
|
+
});
|
|
224
|
+
return {
|
|
225
|
+
accepted: true,
|
|
226
|
+
fromSlot: String(fromSlot),
|
|
227
|
+
toSlot: String(toSlot),
|
|
228
|
+
message: `Transaction backfill started for slots ${fromSlot}..${toSlot}; poll getStatus().transactionBackfill.`,
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
transactionBackfillStarting = false;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
164
236
|
// importUtxoSet — one-off snapshot import that anchors crawler.utxoSet. Validates, then
|
|
165
237
|
// runs detached; progress via getStatus().utxoSet.
|
|
166
238
|
srv.on('importUtxoSet', async (req) => {
|
|
167
239
|
const data = (req.data ?? {});
|
|
240
|
+
if (data.source === 'aggregates') {
|
|
241
|
+
if ((0, crawler_1.isCrawlerRunning)())
|
|
242
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'Crawler is running in this process — pauseCrawler first');
|
|
243
|
+
if (utxoSetImportInFlight)
|
|
244
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'A UTxO set import is already running');
|
|
245
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
246
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
247
|
+
const { anchorSlot, anchorHash } = cursor?.utxoSet ?? {};
|
|
248
|
+
if (anchorSlot == null || !anchorHash)
|
|
249
|
+
throw new errors_1.TransactionValidationError('No imported UTxO set to rebuild the sums from — run importUtxoSet first.');
|
|
250
|
+
utxoSetImportInFlight = (0, utxo_set_import_1.rebuildUtxoSetAggregates)({ indexer: (0, server_1.getCardanoIndexer)() })
|
|
251
|
+
.then((r) => logger.info(`UTxO set sums rebuilt: ${r.utxos} rows at ${r.anchor.slot}/${r.anchor.hash}`))
|
|
252
|
+
.catch((err) => logger.error(`UTxO set aggregate rebuild failed: ${err instanceof Error ? err.message : String(err)}`))
|
|
253
|
+
.finally(() => { utxoSetImportInFlight = null; });
|
|
254
|
+
return {
|
|
255
|
+
accepted: true,
|
|
256
|
+
anchorSlot: String(anchorSlot),
|
|
257
|
+
anchorHash,
|
|
258
|
+
message: 'UTxO set sums are rebuilt from the imported rows; poll getStatus().utxoSet, then resumeCrawler.',
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
168
262
|
const source = data.source === 'file' || data.source === 'ogmios' ? data.source : null;
|
|
169
263
|
if (!source)
|
|
170
|
-
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'source must be "ogmios" or "
|
|
264
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'source must be "ogmios", "file" or "aggregates"', 'source');
|
|
171
265
|
if (source === 'file' && !data.filePath)
|
|
172
266
|
return (0, errors_1.rejectMissing)(req, 'importUtxoSet', 'filePath');
|
|
173
267
|
const anchorGiven = data.anchorSlot != null || !!data.anchorHash;
|
package/srv/cardano-service.cds
CHANGED
|
@@ -122,6 +122,11 @@ service CardanoODataService @(impl: './cardano-service') {
|
|
|
122
122
|
@description: 'Projection for Transaction Withdrawals (crawler-fed, crawler.certificates)'
|
|
123
123
|
entity TransactionWithdrawals as projection on db.TransactionWithdrawals;
|
|
124
124
|
|
|
125
|
+
@readonly
|
|
126
|
+
@title : 'Transaction Redeemers'
|
|
127
|
+
@description: 'Projection for Transaction Redeemers (crawler-fed, Ogmios chain-sync)'
|
|
128
|
+
entity TransactionRedeemers as projection on db.TransactionRedeemers;
|
|
129
|
+
|
|
125
130
|
@readonly
|
|
126
131
|
@title : 'Ledger UTxOs'
|
|
127
132
|
@description: 'Crawler-maintained UTxO set (crawler.utxoSet); unspent while spentTxHash is null'
|
package/srv/cardano-service.js
CHANGED
|
@@ -16,7 +16,7 @@ const TEMPORAL_WINDOW_SLACK_MS = 60 * 60 * 1000;
|
|
|
16
16
|
/**
|
|
17
17
|
* Let this request see the temporal slices it writes during index-on-miss: CAP's temporal
|
|
18
18
|
* filter (`validFrom < $valid.to`) defaults to a `now`..`now+1ms` window fixed at transaction
|
|
19
|
-
* start, so a slice stamped after the backend fetch would be invisible to the
|
|
19
|
+
* start, so a slice stamped after the backend fetch would be invisible to the handler's
|
|
20
20
|
* re-read. Only the upper bound moves; explicit `sap-valid-*` options are left alone.
|
|
21
21
|
* Must run before the handler's first DB statement.
|
|
22
22
|
*/
|
|
@@ -189,6 +189,7 @@ module.exports = (srv) => {
|
|
|
189
189
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
190
190
|
(0, errors_1.rejectInvalid)(req, 'GetAssetsByAddress', 'Invalid bech32 address format', 'address');
|
|
191
191
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
192
|
+
widenTemporalWindow(req); // before the first DB statement
|
|
192
193
|
const existing = await db.run(SELECT.one.from(Addresses).where({ address }));
|
|
193
194
|
if (!existing)
|
|
194
195
|
await indexer().indexAddress(db, address);
|
|
@@ -211,6 +212,7 @@ module.exports = (srv) => {
|
|
|
211
212
|
if (!(0, validators_1.isValidBech32Address)(address))
|
|
212
213
|
(0, errors_1.rejectInvalid)(req, 'GetUTxOsByAddress', 'Invalid bech32 address format', 'address');
|
|
213
214
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
215
|
+
widenTemporalWindow(req); // before the first DB statement
|
|
214
216
|
const existing = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
|
|
215
217
|
if (!existing || existing.length === 0) {
|
|
216
218
|
// Prefer the full address index; when no configured backend supports getAddress
|
|
@@ -36,6 +36,11 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
36
36
|
@description: 'Projection for Transaction Build Outputs'
|
|
37
37
|
entity TransactionBuildOutputs as projection on db.TransactionBuildOutputs;
|
|
38
38
|
|
|
39
|
+
@readonly
|
|
40
|
+
@title : 'Transaction Build Redeemers'
|
|
41
|
+
@description: 'Projection for the redeemers of a script build with their execution units'
|
|
42
|
+
entity TransactionBuildRedeemers as projection on db.TransactionBuildRedeemers;
|
|
43
|
+
|
|
39
44
|
@readonly
|
|
40
45
|
@title : 'Transaction Build Input Assets'
|
|
41
46
|
@description: 'Projection for Transaction Build Input Assets'
|
|
@@ -328,6 +333,40 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
328
333
|
@description: 'Optional. Sets the transaction validity-interval end in Posix milliseconds. Required finite value for Plutus validators that call expect Finite(upper) on tx.validity_range.upper_bound. Defaults to now + 3 600 000 ms when omitted.'
|
|
329
334
|
validityEndMs: String) returns TransactionBuilds;
|
|
330
335
|
|
|
336
|
+
@title : 'Build Plutus Transaction'
|
|
337
|
+
@description: 'Spend several script UTxOs in one transaction, each with its own redeemer (inline validator or a reference-script UTxO). The outputs are built exactly in the given order, change comes after them. The execution units of every redeemer are returned under redeemers.'
|
|
338
|
+
action BuildPlutusTransaction(
|
|
339
|
+
@title: 'Sender Address'
|
|
340
|
+
@description: 'Pays the fee, funds the rest and provides the ADA-only collateral'
|
|
341
|
+
senderAddress: Bech32,
|
|
342
|
+
@title: 'Change Address'
|
|
343
|
+
@description: 'Receives the change; defaults to senderAddress'
|
|
344
|
+
changeAddress: Bech32,
|
|
345
|
+
@title: 'Script Inputs JSON'
|
|
346
|
+
@description: 'Required JSON array, 1..16 entries: {txHash, outputIndex, validatorScript (CBOR hex) | referenceScript: {txHash, outputIndex}, scriptParamsJson?, redeemerJson | redeemerCbor, datumJson | datumCbor (hash datums only)}. The *Cbor forms take PlutusData CBOR hex byte for byte. __INPUT_IDX:<txHash>#<n>__ placeholders in any redeemer resolve against the final sorted inputs.'
|
|
347
|
+
scriptInputsJson: String,
|
|
348
|
+
@title: 'Outputs JSON'
|
|
349
|
+
@description: 'Required JSON array of outputs in this order: {address, lovelaceAmount, assets?: [{unit, quantity}], inlineDatumJson? | inlineDatumCbor? | datumHash?, referenceScriptHex?}. Each is min-ADA checked; change is appended after them and never merged into one.'
|
|
350
|
+
outputsJson: String,
|
|
351
|
+
@title: 'Reference Inputs JSON'
|
|
352
|
+
@description: 'Optional JSON array of {txHash, outputIndex} read-only reference inputs; reference-script UTxOs of scriptInputsJson are added automatically.'
|
|
353
|
+
referenceInputsJson: String,
|
|
354
|
+
@title: 'Force Inputs JSON'
|
|
355
|
+
@description: 'Optional JSON array of {txHash, outputIndex} UTxOs of the sender that must be consumed.'
|
|
356
|
+
forceInputsJson: String,
|
|
357
|
+
@title: 'Required Signers JSON'
|
|
358
|
+
@description: 'Optional JSON array of Ed25519 key hashes (hex, 28 bytes each) that must sign the transaction.'
|
|
359
|
+
requiredSignersJson: String,
|
|
360
|
+
@title: 'Mint Actions JSON'
|
|
361
|
+
@description: 'Optional JSON array of [{assetUnit, quantity, mintingPolicyScript, redeemerJson?}]; every action names its own policy script. Minted assets go where outputsJson puts them.'
|
|
362
|
+
mintActionsJson: String,
|
|
363
|
+
@title: 'Validity Start (Posix ms)'
|
|
364
|
+
@description: 'Optional validity-interval start in Posix milliseconds; defaults to now - 120 000 ms.'
|
|
365
|
+
validityStartMs: String,
|
|
366
|
+
@title: 'Validity End (Posix ms)'
|
|
367
|
+
@description: 'Optional validity-interval end in Posix milliseconds; defaults to now + 3 600 000 ms.'
|
|
368
|
+
validityEndMs: String) returns TransactionBuilds;
|
|
369
|
+
|
|
331
370
|
@title : 'Set Collateral'
|
|
332
371
|
@description: 'Ensure a dedicated ADA-only collateral UTxO exists for Plutus transactions. Checks if the address has at least 2 UTxOs with >= 5 ADA each. If not, builds a self-send transaction to create a 5 ADA collateral UTxO.'
|
|
333
372
|
action SetCollateral(
|