@odatano/core 1.11.0 → 2.0.0-rc.10
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 +255 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +177 -0
- package/@cds-models/CardanoIndexerService/index.js +27 -0
- package/@cds-models/CardanoODataService/index.d.ts +693 -2172
- package/@cds-models/CardanoODataService/index.js +88 -390
- package/@cds-models/CardanoSignService/index.d.ts +448 -1576
- package/@cds-models/CardanoSignService/index.js +62 -293
- package/@cds-models/CardanoTransactionService/index.d.ts +437 -1494
- package/@cds-models/CardanoTransactionService/index.js +60 -271
- package/@cds-models/CardanoWorkerService/index.d.ts +224 -0
- package/@cds-models/CardanoWorkerService/index.js +32 -0
- package/@cds-models/_/index.d.ts +70 -40
- package/@cds-models/_/index.js +17 -32
- package/@cds-models/cds/outbox/index.d.ts +28 -0
- package/@cds-models/index.d.ts +225 -522
- package/@cds-models/index.js +35 -218
- package/@cds-models/odatano/cardano/index.d.ts +919 -2884
- package/@cds-models/odatano/cardano/index.js +115 -536
- package/@cds-models/sap/common/index.d.ts +196 -600
- package/@cds-models/sap/common/index.js +28 -269
- package/README.md +194 -102
- package/db/schema.cds +388 -1
- package/db/types.cds +48 -0
- package/package.json +48 -33
- package/src/index.d.ts +7 -1
- package/src/index.js +30 -2
- package/src/plugin.js +33 -20
- package/srv/blockchain/backends/blockfrost-backend.d.ts +21 -2
- package/srv/blockchain/backends/blockfrost-backend.js +69 -25
- package/srv/blockchain/backends/cardano-backend.d.ts +69 -0
- package/srv/blockchain/backends/cardano-backend.js +13 -0
- package/srv/blockchain/backends/koios-backend.d.ts +26 -2
- package/srv/blockchain/backends/koios-backend.js +148 -25
- package/srv/blockchain/backends/ogmios-backend.d.ts +60 -9
- package/srv/blockchain/backends/ogmios-backend.js +326 -10
- package/srv/blockchain/cardano-client.d.ts +19 -0
- package/srv/blockchain/cardano-client.js +36 -0
- package/srv/blockchain/cardano-indexer.d.ts +50 -1
- package/srv/blockchain/cardano-indexer.js +193 -0
- package/srv/blockchain/crawler/crawler.d.ts +176 -0
- package/srv/blockchain/crawler/crawler.js +744 -0
- package/srv/blockchain/crawler/hooks.d.ts +43 -0
- package/srv/blockchain/crawler/hooks.js +62 -0
- package/srv/blockchain/crawler/index.d.ts +35 -0
- package/srv/blockchain/crawler/index.js +168 -0
- package/srv/blockchain/crawler/sync-state.d.ts +106 -0
- package/srv/blockchain/crawler/sync-state.js +287 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +45 -0
- package/srv/blockchain/signing/hsm-signer.js +8 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +20 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +104 -20
- package/srv/blockchain/wallet-worker/build-request.d.ts +26 -0
- package/srv/blockchain/wallet-worker/build-request.js +370 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +117 -0
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +290 -0
- package/srv/blockchain/wallet-worker/index.d.ts +14 -0
- package/srv/blockchain/wallet-worker/index.js +80 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +272 -0
- package/srv/blockchain/wallet-worker/job-store.js +597 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +43 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +99 -0
- package/srv/blockchain/wallet-worker/signers.d.ts +57 -0
- package/srv/blockchain/wallet-worker/signers.js +131 -0
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +145 -0
- package/srv/blockchain/wallet-worker/wallet-worker.js +542 -0
- package/srv/cardano-agent-service.cds +150 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +16 -0
- package/srv/cardano-indexer-service.cds +106 -0
- package/srv/cardano-indexer-service.d.ts +2 -0
- package/srv/cardano-indexer-service.js +79 -0
- package/srv/cardano-service.js +79 -4
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.d.ts +1 -11
- package/srv/cardano-tx-service.js +107 -200
- package/srv/cardano-worker-service.cds +125 -0
- package/srv/cardano-worker-service.d.ts +2 -0
- package/srv/cardano-worker-service.js +199 -0
- package/srv/server.d.ts +34 -2
- package/srv/server.js +246 -36
- package/srv/utils/agent-grants-config.d.ts +65 -0
- package/srv/utils/agent-grants-config.js +148 -0
- package/srv/utils/agent-grants.d.ts +314 -0
- package/srv/utils/agent-grants.js +821 -0
- package/srv/utils/agent-token-auth.d.ts +19 -0
- package/srv/utils/agent-token-auth.js +81 -0
- package/srv/utils/collections.d.ts +13 -0
- package/srv/utils/collections.js +24 -0
- package/srv/utils/crypto.d.ts +16 -0
- package/srv/utils/crypto.js +75 -0
- package/srv/utils/db-sanitize.d.ts +40 -0
- package/srv/utils/db-sanitize.js +98 -0
- package/srv/utils/error-codes.d.ts +6 -0
- package/srv/utils/error-codes.js +6 -0
- package/srv/utils/errors.d.ts +12 -0
- package/srv/utils/errors.js +45 -0
- package/srv/utils/liveness.d.ts +23 -0
- package/srv/utils/liveness.js +49 -0
- package/srv/utils/mappers.d.ts +27 -0
- package/srv/utils/mappers.js +80 -10
- package/srv/utils/rate-limiter.d.ts +57 -0
- package/srv/utils/rate-limiter.js +126 -0
- package/srv/utils/service-events.d.ts +26 -0
- package/srv/utils/service-events.js +46 -0
- package/srv/utils/tx-request-parsers.d.ts +71 -0
- package/srv/utils/tx-request-parsers.js +202 -0
- package/srv/utils/tx-utils.d.ts +2 -1
- package/srv/utils/tx-utils.js +3 -2
- package/srv/utils/types.d.ts +17 -1
- package/@cds-models/CardanoODataService/index.d.ts.map +0 -1
- package/@cds-models/CardanoODataService/index.js.map +0 -1
- package/@cds-models/CardanoODataService/index.ts +0 -776
- package/@cds-models/CardanoSignService/index.d.ts.map +0 -1
- package/@cds-models/CardanoSignService/index.js.map +0 -1
- package/@cds-models/CardanoSignService/index.ts +0 -569
- package/@cds-models/CardanoTransactionService/index.d.ts.map +0 -1
- package/@cds-models/CardanoTransactionService/index.js.map +0 -1
- package/@cds-models/CardanoTransactionService/index.ts +0 -526
- package/@cds-models/_/index.d.ts.map +0 -1
- package/@cds-models/_/index.js.map +0 -1
- package/@cds-models/_/index.ts +0 -96
- package/@cds-models/cds/outbox/index.ts +0 -27
- package/@cds-models/index.d.ts.map +0 -1
- package/@cds-models/index.js.map +0 -1
- package/@cds-models/index.ts +0 -245
- package/@cds-models/odatano/cardano/index.d.ts.map +0 -1
- package/@cds-models/odatano/cardano/index.js.map +0 -1
- package/@cds-models/odatano/cardano/index.ts +0 -789
- package/@cds-models/sap/common/index.d.ts.map +0 -1
- package/@cds-models/sap/common/index.js.map +0 -1
- package/@cds-models/sap/common/index.ts +0 -249
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cardano Agent Service (v2.0)
|
|
5
|
+
*
|
|
6
|
+
* Agent grants: scoped, budgeted bearer capabilities an Admin hands to an agent
|
|
7
|
+
* instead of a full user (see AGENT_GRANTS_DESIGN.md).
|
|
8
|
+
*
|
|
9
|
+
* - CreateAgentGrant / UpdateAgentGrant / RotateAgentGrantToken / RevokeAgentGrant:
|
|
10
|
+
* Admin-only administration, rate limited per principal per hour
|
|
11
|
+
* (AGENT_GRANT_ADMIN_RATE_LIMIT, default 10). The token is returned ONCE from
|
|
12
|
+
* CreateAgentGrant and RotateAgentGrantToken and stored as SHA-256 only.
|
|
13
|
+
* - AgentGrants: Admin-only projection (no token hash). A request carrying a token
|
|
14
|
+
* runs as the principal `agent:<grantId>` with the role `agent-grant` and sees
|
|
15
|
+
* exactly its own row through the row-level restriction below.
|
|
16
|
+
* - GetGrantStatus: token self-service — what am I allowed to do, how much budget
|
|
17
|
+
* is left, when do I expire. What an MCP tool needs to describe itself honestly.
|
|
18
|
+
* - GetGrantUsage: admitted calls per service and action over a window — an Admin
|
|
19
|
+
* for any grant, a token for its own (a partner usage view, ledger reconciliation).
|
|
20
|
+
*
|
|
21
|
+
* Names are this repo's PascalCase; semantics mirror NIGHTGATE's agent grants
|
|
22
|
+
* (createAgentGrant / updateAgentGrant / rotateAgentGrantToken / revokeAgentGrant /
|
|
23
|
+
* getGrantUsage), so a gateway drives both products with one code path.
|
|
24
|
+
*
|
|
25
|
+
* A token request never inherits the operator's roles: `@requires: 'Admin'` on the
|
|
26
|
+
* four actions, on PauseWorker / ResumeWorker / pauseCrawler / resumeCrawler and on
|
|
27
|
+
* every other Admin surface therefore refuses it by construction. The allow list,
|
|
28
|
+
* wallet pinning and daily budget are enforced by a before('*') hook on all six
|
|
29
|
+
* ODATANO services (srv/utils/agent-grants.ts). The `x-agent-token` header only
|
|
30
|
+
* reaches the services when cds.requires.odatano-core.agentGrants.enabled is set
|
|
31
|
+
* (srv/utils/agent-token-auth.ts).
|
|
32
|
+
*/
|
|
33
|
+
@requires: 'authenticated-user'
|
|
34
|
+
service CardanoAgentService @(impl: './cardano-agent-service') {
|
|
35
|
+
|
|
36
|
+
@readonly
|
|
37
|
+
@title : 'Agent Grants'
|
|
38
|
+
@description: 'Issued grants (token hash excluded). Admins see all, a token sees its own row.'
|
|
39
|
+
@restrict : [
|
|
40
|
+
{ grant: 'READ', to: 'Admin' },
|
|
41
|
+
{ grant: 'READ', to: 'agent-grant', where: 'ID = $user.grantId' }
|
|
42
|
+
]
|
|
43
|
+
entity AgentGrants as projection on db.CardanoAgentGrants excluding { tokenHash };
|
|
44
|
+
|
|
45
|
+
@title : 'Grant Status'
|
|
46
|
+
type GrantStatus {
|
|
47
|
+
grantId : UUID;
|
|
48
|
+
agentLabel : String(100);
|
|
49
|
+
allowedActions : many String;
|
|
50
|
+
walletId : String(50);
|
|
51
|
+
allowedJobKinds : many String;
|
|
52
|
+
maxJobsPerDay : Integer;
|
|
53
|
+
jobsUsedToday : Integer;
|
|
54
|
+
budgetWindow : String(10);
|
|
55
|
+
validUntil : Timestamp;
|
|
56
|
+
isActive : Boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@title : 'Issued Grant'
|
|
60
|
+
type IssuedGrant {
|
|
61
|
+
grantId : UUID;
|
|
62
|
+
token : String; // shown once, never stored
|
|
63
|
+
allowedActions : many String;
|
|
64
|
+
walletId : String(50);
|
|
65
|
+
allowedJobKinds : many String;
|
|
66
|
+
maxJobsPerDay : Integer;
|
|
67
|
+
validUntil : Timestamp;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@title : 'Get Grant Status'
|
|
71
|
+
@description: 'The calling token''s own grant: allow list, wallet, remaining daily budget, expiry. 400 without a token — an operator lists AgentGrants instead.'
|
|
72
|
+
function GetGrantStatus() returns GrantStatus;
|
|
73
|
+
|
|
74
|
+
@title : 'Create Agent Grant'
|
|
75
|
+
@description: 'Issue a scoped bearer token for an agent. Admin only. The token is returned once and stored as SHA-256. allowedActions must be a non-empty subset of the grantable set; walletId is required when SubmitWalletJob or CancelJob is allowed.'
|
|
76
|
+
@requires : 'Admin'
|
|
77
|
+
action CreateAgentGrant(
|
|
78
|
+
@title: 'Allowed Actions' allowedActions : many String,
|
|
79
|
+
@title: 'Wallet Id' walletId : String(50),
|
|
80
|
+
@title: 'Allowed Job Kinds' allowedJobKinds : many String,
|
|
81
|
+
@title: 'Max Jobs Per Day' maxJobsPerDay : Integer,
|
|
82
|
+
@title: 'Valid Until' validUntil : Timestamp,
|
|
83
|
+
@title: 'Agent Label' agentLabel : String(100)
|
|
84
|
+
) returns IssuedGrant;
|
|
85
|
+
|
|
86
|
+
@title : 'Revoke Agent Grant'
|
|
87
|
+
@description: 'Deactivate a grant. Admin only. Its token becomes an unknown token immediately.'
|
|
88
|
+
@requires : 'Admin'
|
|
89
|
+
action RevokeAgentGrant(
|
|
90
|
+
@title: 'Grant Id' grantId : UUID
|
|
91
|
+
) returns Boolean;
|
|
92
|
+
|
|
93
|
+
@title : 'Rotated Grant'
|
|
94
|
+
type RotatedGrant {
|
|
95
|
+
grantId : UUID;
|
|
96
|
+
token : String; // shown once, never stored
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@title : 'Rotate Agent Grant Token'
|
|
100
|
+
@description: 'Replace the grant token; the old token is unknown from the next request. Budget, wallet, allow list and expiry survive. Admin only. 404 when the grant does not exist or is revoked.'
|
|
101
|
+
@requires : 'Admin'
|
|
102
|
+
action RotateAgentGrantToken(
|
|
103
|
+
@title: 'Grant Id' grantId : UUID
|
|
104
|
+
) returns RotatedGrant;
|
|
105
|
+
|
|
106
|
+
@title : 'Updated Grant'
|
|
107
|
+
type UpdatedGrant {
|
|
108
|
+
grantId : UUID;
|
|
109
|
+
updated : many String; // parameter names that were applied
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@title : 'Update Agent Grant'
|
|
113
|
+
@description: 'Change label, allow list, job kinds, daily budget or expiry of an active grant. An absent parameter stays as it is; an explicit null clears agentLabel, allowedJobKinds, maxJobsPerDay or validUntil. allowedActions cannot be emptied; the wallet binding is immutable (issue a new grant). Admin only. 404 unknown grant, 409 GRANT_REVOKED.'
|
|
114
|
+
@requires : 'Admin'
|
|
115
|
+
action UpdateAgentGrant(
|
|
116
|
+
@title: 'Grant Id' grantId : UUID,
|
|
117
|
+
@title: 'Agent Label' agentLabel : String(100),
|
|
118
|
+
@title: 'Allowed Actions' allowedActions : many String,
|
|
119
|
+
@title: 'Allowed Job Kinds' allowedJobKinds : many String,
|
|
120
|
+
@title: 'Max Jobs Per Day' maxJobsPerDay : Integer,
|
|
121
|
+
@title: 'Valid Until' validUntil : Timestamp
|
|
122
|
+
) returns UpdatedGrant;
|
|
123
|
+
|
|
124
|
+
@title : 'Grant Usage Call'
|
|
125
|
+
type GrantUsageCall {
|
|
126
|
+
service : String(60); // CardanoTransactionService, CardanoSignService, ...
|
|
127
|
+
action : String(100); // BuildSimpleAdaTransaction, SubmitTransaction, ...
|
|
128
|
+
count : Integer; // admitted and kept (budget charged and not refunded)
|
|
129
|
+
refunded : Integer; // admitted, then refunded because the handler refused the input
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@title : 'Grant Usage'
|
|
133
|
+
type GrantUsage {
|
|
134
|
+
grantId : UUID;
|
|
135
|
+
since : Timestamp;
|
|
136
|
+
until : Timestamp;
|
|
137
|
+
calls : many GrantUsageCall;
|
|
138
|
+
total : Integer;
|
|
139
|
+
jobsUsedToday : Integer;
|
|
140
|
+
maxJobsPerDay : Integer;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@title : 'Get Grant Usage'
|
|
144
|
+
@description: 'Admitted calls under a grant between since (default until - 30 days) and until (default now), at most 366 days, per UTC day, grouped by service and action. An Admin sees any grant (revoked ones keep their history); a token sees only its own.'
|
|
145
|
+
function GetGrantUsage(
|
|
146
|
+
@title: 'Grant Id' grantId : UUID,
|
|
147
|
+
@title: 'Since' since : Timestamp,
|
|
148
|
+
@title: 'Until' until : Timestamp
|
|
149
|
+
) returns GrantUsage;
|
|
150
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const agent_grants_1 = require("./utils/agent-grants");
|
|
4
|
+
/**
|
|
5
|
+
* CardanoAgentService handlers — grant administration (Admin) and token
|
|
6
|
+
* self-service. Everything lives in srv/utils/agent-grants.ts so the
|
|
7
|
+
* programmatic API (`issueAgentGrant`, used by @odatano/x402 to sell grants) and
|
|
8
|
+
* the OData actions share one code path.
|
|
9
|
+
*
|
|
10
|
+
* The enforcement hook for token requests is attached to all six services from
|
|
11
|
+
* src/plugin.ts (cds.on('serving')), not here.
|
|
12
|
+
*/
|
|
13
|
+
module.exports = (srv) => {
|
|
14
|
+
(0, agent_grants_1.registerAgentGrantHandlers)(srv);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=cardano-agent-service.js.map
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
* the same layout as NIGHTGATE's indexer service.
|
|
20
|
+
*/
|
|
21
|
+
// Service-level 'any' on purpose: CAP authorizes the service BEFORE the operation and
|
|
22
|
+
// treats a service without a service-level @requires as authenticated-user under
|
|
23
|
+
// NODE_ENV=production, which would 401 the anonymous operation below despite its own
|
|
24
|
+
// 'any'. Every element carries its requirement; the service itself refuses nothing.
|
|
25
|
+
@requires: 'any'
|
|
26
|
+
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
27
|
+
|
|
28
|
+
@readonly
|
|
29
|
+
@requires : 'authenticated-user'
|
|
30
|
+
@title : 'Sync State'
|
|
31
|
+
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
32
|
+
entity SyncState as projection on db.CardanoSyncState;
|
|
33
|
+
|
|
34
|
+
@readonly
|
|
35
|
+
@requires : 'authenticated-user'
|
|
36
|
+
@title : 'Reorg Log'
|
|
37
|
+
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
38
|
+
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
39
|
+
|
|
40
|
+
@title : 'Crawler Status'
|
|
41
|
+
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
42
|
+
type CrawlerStatus {
|
|
43
|
+
running : Boolean;
|
|
44
|
+
syncStatus : String;
|
|
45
|
+
lastSlot : String;
|
|
46
|
+
lastHeight : String;
|
|
47
|
+
tipHeight : String;
|
|
48
|
+
syncProgress : String;
|
|
49
|
+
consecutiveErrors : Integer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@title : 'Get Crawler Status'
|
|
53
|
+
@description: 'Return the current crawler run state and sync progress'
|
|
54
|
+
/**
|
|
55
|
+
* Emitted AFTER each block is committed. Subscribe instead of polling:
|
|
56
|
+
* (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
57
|
+
* In-process (plugin mode) this needs no messaging service.
|
|
58
|
+
*/
|
|
59
|
+
event blockIndexed {
|
|
60
|
+
hash : String(64);
|
|
61
|
+
slot : Integer64;
|
|
62
|
+
height : Integer64;
|
|
63
|
+
txHashes : many String(64);
|
|
64
|
+
tipSlot : Integer64;
|
|
65
|
+
tipHeight: Integer64;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Emitted AFTER a rollback is committed. Everything above `forkSlot` was removed. */
|
|
69
|
+
event reorg {
|
|
70
|
+
forkSlot : Integer64;
|
|
71
|
+
forkHeight : Integer64;
|
|
72
|
+
blocksRolledBack : Integer;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@requires : 'authenticated-user'
|
|
76
|
+
function getStatus() returns CrawlerStatus;
|
|
77
|
+
|
|
78
|
+
@title : 'Liveness'
|
|
79
|
+
type Liveness {
|
|
80
|
+
status : String; // 'alive'
|
|
81
|
+
timestamp : Timestamp;
|
|
82
|
+
uptime : Integer; // seconds since process start
|
|
83
|
+
version : String; // @odatano/core version
|
|
84
|
+
network : String; // configured network
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Anonymous on purpose: a liveness probe carries no credentials. 200 as long
|
|
88
|
+
// as the process answers — no backend or DB probe, no secrets, no backend
|
|
89
|
+
// names, no API key state. Readiness stays with getStatus and the worker
|
|
90
|
+
// status, which remain authenticated. Mirrors NIGHTGATE's
|
|
91
|
+
// `/api/v1/indexer/getLiveness()`, so a gateway probes both products the same way.
|
|
92
|
+
@title : 'Get Liveness'
|
|
93
|
+
@description: 'Unauthenticated liveness probe: 200 while the process answers. Docker HEALTHCHECK and upstream probes use this instead of the service document.'
|
|
94
|
+
@requires : 'any'
|
|
95
|
+
function getLiveness() returns Liveness;
|
|
96
|
+
|
|
97
|
+
@title : 'Pause Crawler'
|
|
98
|
+
@description: 'Stop the crawler (closes the chain-sync stream). Resume continues from the cursor.'
|
|
99
|
+
@requires : 'Admin'
|
|
100
|
+
action pauseCrawler() returns Boolean;
|
|
101
|
+
|
|
102
|
+
@title : 'Resume Crawler'
|
|
103
|
+
@description: 'Start/restart the crawler from the persisted cursor using the configured source.'
|
|
104
|
+
@requires : 'Admin'
|
|
105
|
+
action resumeCrawler() returns Boolean;
|
|
106
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
7
|
+
const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
8
|
+
const errors_1 = require("./utils/errors");
|
|
9
|
+
const crawler_1 = require("./blockchain/crawler");
|
|
10
|
+
const sync_state_1 = require("./blockchain/crawler/sync-state");
|
|
11
|
+
const server_1 = require("./server");
|
|
12
|
+
const liveness_1 = require("./utils/liveness");
|
|
13
|
+
const logger = cds_1.default.log('CardanoIndexerService');
|
|
14
|
+
/**
|
|
15
|
+
* CardanoIndexerService handlers — thin control/observability surface over the crawler
|
|
16
|
+
* singleton (srv/blockchain/crawler). Engine logic lives there; this only reads the
|
|
17
|
+
* cursor and starts/stops the crawler.
|
|
18
|
+
*/
|
|
19
|
+
module.exports = (srv) => {
|
|
20
|
+
// getLiveness — unauthenticated probe (@requires: 'any'); no handleRequest, no app context.
|
|
21
|
+
srv.on('getLiveness', async () => (0, liveness_1.buildLiveness)());
|
|
22
|
+
// getStatus — live run state + sync progress (numeric fields as strings, CAP-10 aligned)
|
|
23
|
+
srv.on('getStatus', async (req) => {
|
|
24
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
25
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
26
|
+
const lastHeight = cursor?.lastHeight ?? 0;
|
|
27
|
+
const tipHeight = cursor?.tipHeight ?? 0;
|
|
28
|
+
const progress = tipHeight > 0 ? Math.min(100, (lastHeight / tipHeight) * 100) : 0;
|
|
29
|
+
return {
|
|
30
|
+
running: (0, sync_state_1.isCrawlerLeaseActive)(cursor),
|
|
31
|
+
syncStatus: cursor?.syncStatus ?? 'stopped',
|
|
32
|
+
lastSlot: String(cursor?.lastSlot ?? 0),
|
|
33
|
+
lastHeight: String(lastHeight),
|
|
34
|
+
tipHeight: String(tipHeight),
|
|
35
|
+
syncProgress: progress.toFixed(2),
|
|
36
|
+
consecutiveErrors: cursor?.consecutiveErrors ?? 0,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
// pauseCrawler — stop the stream; the cursor is preserved so resume continues.
|
|
41
|
+
srv.on('pauseCrawler', async (req) => {
|
|
42
|
+
return (0, backend_request_handler_1.handleRequest)(req, async () => {
|
|
43
|
+
await (0, crawler_1.stopCrawler)(true);
|
|
44
|
+
logger.info('Crawler paused via control action');
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
// resumeCrawler — (re)start from the persisted cursor using the configured source.
|
|
49
|
+
// Gated on config.enabled: the control action must not start a crawler the operator
|
|
50
|
+
// never configured (an unconfigured start would otherwise sync from genesis).
|
|
51
|
+
// NOTE: to apply CHANGED config to a running crawler, call pauseCrawler first —
|
|
52
|
+
// resume on a running crawler is a no-op by design.
|
|
53
|
+
srv.on('resumeCrawler', async (req) => {
|
|
54
|
+
let config;
|
|
55
|
+
try {
|
|
56
|
+
config = (0, server_1.loadCrawlerConfigFromEnv)();
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// e.g. ConfigError: enabled but no start block — a config problem is the
|
|
60
|
+
// caller's 400, not a raw 500 from an escaping throw
|
|
61
|
+
return (0, errors_1.rejectInvalid)(req, 'resumeCrawler', err instanceof Error ? err.message : String(err));
|
|
62
|
+
}
|
|
63
|
+
if (!config.enabled) {
|
|
64
|
+
return (0, errors_1.rejectInvalid)(req, 'resumeCrawler', 'Crawler is not enabled — set cds.requires.odatano-core.crawler.enabled (or CRAWLER_ENABLED=true) with a start block before resuming.');
|
|
65
|
+
}
|
|
66
|
+
return (0, backend_request_handler_1.handleRequest)(req, async () => {
|
|
67
|
+
const client = (0, server_1.getCardanoClient)();
|
|
68
|
+
await (0, crawler_1.startCrawler)({
|
|
69
|
+
client,
|
|
70
|
+
indexer: (0, server_1.getCardanoIndexer)(),
|
|
71
|
+
network: client.network,
|
|
72
|
+
config,
|
|
73
|
+
}, true);
|
|
74
|
+
logger.info('Crawler resumed via control action');
|
|
75
|
+
return (0, crawler_1.isCrawlerRunningInCluster)();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=cardano-indexer-service.js.map
|
package/srv/cardano-service.js
CHANGED
|
@@ -11,9 +11,52 @@ const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
|
11
11
|
const cbor_1 = require("./cbor");
|
|
12
12
|
const { SELECT } = cds_1.default.ql;
|
|
13
13
|
const logger = cds_1.default.log(`CardanoService`);
|
|
14
|
+
/**
|
|
15
|
+
* Upper bound of the temporal window opened by {@link widenTemporalWindow}.
|
|
16
|
+
* Generous on purpose: it only has to outlast the slowest index-on-miss (chained
|
|
17
|
+
* backend timeouts of several calls) within ONE request.
|
|
18
|
+
*/
|
|
19
|
+
const TEMPORAL_WINDOW_SLACK_MS = 60 * 60 * 1000;
|
|
20
|
+
/**
|
|
21
|
+
* Let this request see temporal slices that IT writes during index-on-miss.
|
|
22
|
+
*
|
|
23
|
+
* CAP filters temporal entities (Pools, Assets, Dreps, Addresses, Accounts, …)
|
|
24
|
+
* with `validFrom < $valid.to AND validTo > $valid.from`. The DB session reads
|
|
25
|
+
* both bounds from the request's `_` bag (`VALID-FROM` / `VALID-TO`) when the
|
|
26
|
+
* transaction begins (HANA) or on first use (sqlite) and otherwise defaults to
|
|
27
|
+
* `now` / `now + 1ms` — a window that is closed long before the backend fetch
|
|
28
|
+
* returns, so a slice stamped after the fetch would be invisible to the
|
|
29
|
+
* `req.query` re-read that honours `$expand` / `$select` (KNOWN_ISSUES #13).
|
|
30
|
+
*
|
|
31
|
+
* Only the UPPER bound is moved. No slice is ever future-dated (every mapper
|
|
32
|
+
* stamps `validFrom = now`), so the only additional rows this admits are the
|
|
33
|
+
* ones this very request writes; expired rows stay hidden (`validTo >
|
|
34
|
+
* $valid.from` is untouched). Explicit `sap-valid-*` query options are left
|
|
35
|
+
* alone. Must run before the handler's first DB statement.
|
|
36
|
+
*/
|
|
37
|
+
function widenTemporalWindow(req) {
|
|
38
|
+
const q = req.http?.req?.query;
|
|
39
|
+
if (q && (q['sap-valid-at'] || q['sap-valid-from'] || q['sap-valid-to']))
|
|
40
|
+
return;
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
const from = new Date(now).toISOString();
|
|
43
|
+
const to = new Date(now + TEMPORAL_WINDOW_SLACK_MS).toISOString();
|
|
44
|
+
// The DB session context is built from the context the transaction was opened
|
|
45
|
+
// with — `req` for our `cds.tx(req)`, the root context if a generic handler got
|
|
46
|
+
// there first — so stamp both bags.
|
|
47
|
+
const r = req;
|
|
48
|
+
for (const bag of new Set([r._, r.context?._])) {
|
|
49
|
+
if (!bag)
|
|
50
|
+
continue;
|
|
51
|
+
bag['VALID-FROM'] = from;
|
|
52
|
+
bag['VALID-TO'] = to;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
14
55
|
/**
|
|
15
56
|
* Factory: READ handler with index-on-miss behavior.
|
|
16
|
-
* If a key is provided, checks cache first; indexes if missing
|
|
57
|
+
* If a key is provided, checks cache first; indexes if missing — then runs the
|
|
58
|
+
* client's own query so `$expand` / `$select` are honoured on the keyed branch
|
|
59
|
+
* too (KNOWN_ISSUES #13: returning the bare row silently dropped them).
|
|
17
60
|
* If no key, passes through to generic req.query.
|
|
18
61
|
*/
|
|
19
62
|
function indexOnMissRead(entity, reqKeyField, validate, indexFn, options) {
|
|
@@ -27,11 +70,22 @@ function indexOnMissRead(entity, reqKeyField, validate, indexFn, options) {
|
|
|
27
70
|
(0, errors_1.rejectInvalid)(req, dbKey, errMsg, reqKeyField);
|
|
28
71
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
29
72
|
if (key !== undefined && key !== null) {
|
|
73
|
+
widenTemporalWindow(req); // before the first DB statement — see doc comment
|
|
30
74
|
// CAP temporal aspect auto-filters expired records (validTo < now → not returned)
|
|
31
75
|
const existing = await db.run(SELECT.one.from(entity).where({ [dbKey]: key }));
|
|
76
|
+
// Populate the row (+ compositions) on a miss, then let CAP run the client's
|
|
77
|
+
// query — one extra SELECT per keyed read, but $expand/$select (and the
|
|
78
|
+
// temporal filter of the projection) apply exactly as on the un-keyed path.
|
|
32
79
|
if (!existing)
|
|
33
|
-
|
|
34
|
-
|
|
80
|
+
await indexFn(db, key);
|
|
81
|
+
// The client's query is the ONLY authority on what comes back. Falling back
|
|
82
|
+
// to `existing` (or the indexer's return value) when it matches nothing
|
|
83
|
+
// answers a request the client never made — a second key that does not
|
|
84
|
+
// match, or an excluding $filter, would get a sibling row with a 200
|
|
85
|
+
// instead of a 404 (KNOWN_ISSUES #15). Non-temporal entities always see
|
|
86
|
+
// their fresh rows here; temporal ones rely on widenTemporalWindow above,
|
|
87
|
+
// and if that ever stops working the failure is a loud 404 covered by
|
|
88
|
+
// test/integration/keyed-read-expand.test.ts, not silently wrong data.
|
|
35
89
|
}
|
|
36
90
|
return db.run(req.query);
|
|
37
91
|
});
|
|
@@ -67,7 +121,28 @@ function indexOnMissAction(actionName, entity, reqKeyField, validate, indexFn, o
|
|
|
67
121
|
*/
|
|
68
122
|
module.exports = (srv) => {
|
|
69
123
|
logger.debug('Module loaded - registering handlers');
|
|
70
|
-
|
|
124
|
+
// NOTE: for entities whose name is already plural-shaped (NetworkInformation,
|
|
125
|
+
// TransactionMetadata, AssetHistory) cds-typer exports the SINGULAR class under the
|
|
126
|
+
// plain name and the plural (entity-set) class with a trailing underscore. Handler
|
|
127
|
+
// registration must use the plural class — under cds 10 registering `srv.on('READ',
|
|
128
|
+
// <singular proxy>)` no longer matches incoming OData READs, so the generic CRUD
|
|
129
|
+
// handler silently served those entities (empty results / 404 instead of
|
|
130
|
+
// index-on-miss). All other names below already resolve to plural classes.
|
|
131
|
+
const { NetworkInformation_: NetworkInformation, Blocks, Epochs, Addresses, AddressAssets, AddressUTxOs, Transactions, TransactionMetadata_: TransactionMetadata, Pools, Accounts, Dreps, Assets, AssetHistory_: AssetHistory, LedgerProtocolParameters, AddressTransactions } = require('#cds-models/CardanoODataService');
|
|
132
|
+
// Fail fast if a future edit reintroduces a SINGULAR class here (the cds-10 trap
|
|
133
|
+
// above): a singular registration silently degrades to the generic CRUD handler.
|
|
134
|
+
// Every cds-typer proxy carries an explicit is_singular marker we can assert on.
|
|
135
|
+
for (const [name, entity] of Object.entries({
|
|
136
|
+
NetworkInformation, Blocks, Epochs, Addresses, AddressAssets, AddressUTxOs,
|
|
137
|
+
Transactions, TransactionMetadata, Pools, Accounts, Dreps, Assets, AssetHistory,
|
|
138
|
+
LedgerProtocolParameters, AddressTransactions,
|
|
139
|
+
})) {
|
|
140
|
+
if (entity?.is_singular) {
|
|
141
|
+
throw new Error(`CardanoODataService: '${name}' resolves to the SINGULAR cds-typer class — ` +
|
|
142
|
+
`READ handlers registered with it never match under cds 10. Destructure the ` +
|
|
143
|
+
`plural entity-set class instead (e.g. '${name}_ as ${name}').`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
71
146
|
// Helper: shorthand for indexer access
|
|
72
147
|
const indexer = () => (0, server_1.getCardanoIndexer)();
|
|
73
148
|
// ---------------------------------------------------------------------------
|