@odatano/core 2.0.0-rc.1 → 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 +37 -2
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
- package/@cds-models/odatano/cardano/index.d.ts +86 -0
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/README.md +62 -4
- package/db/schema.cds +105 -0
- package/package.json +9 -3
- package/src/index.d.ts +6 -0
- package/src/index.js +21 -1
- package/src/plugin.js +33 -30
- package/srv/blockchain/backends/blockfrost-backend.js +1 -10
- package/srv/blockchain/backends/koios-backend.js +1 -10
- package/srv/blockchain/backends/ogmios-backend.d.ts +23 -3
- package/srv/blockchain/backends/ogmios-backend.js +72 -5
- package/srv/blockchain/cardano-indexer.js +3 -1
- package/srv/blockchain/crawler/crawler.d.ts +25 -0
- package/srv/blockchain/crawler/crawler.js +68 -1
- package/srv/blockchain/crawler/index.d.ts +9 -0
- package/srv/blockchain/crawler/index.js +37 -4
- package/srv/blockchain/crawler/sync-state.d.ts +13 -1
- package/srv/blockchain/crawler/sync-state.js +24 -2
- 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.js +35 -6
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +32 -1
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +91 -29
- package/srv/blockchain/wallet-worker/job-store.d.ts +11 -0
- package/srv/blockchain/wallet-worker/job-store.js +42 -9
- 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 +36 -3
- package/srv/cardano-indexer-service.js +3 -0
- package/srv/cardano-service.js +57 -3
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +96 -38
- package/srv/cardano-worker-service.cds +125 -125
- package/srv/server.d.ts +2 -1
- package/srv/server.js +18 -34
- 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/db-sanitize.d.ts +40 -0
- package/srv/utils/db-sanitize.js +98 -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 +67 -7
- package/srv/utils/rate-limiter.d.ts +57 -0
- package/srv/utils/rate-limiter.js +126 -0
- package/srv/utils/tx-request-parsers.d.ts +13 -0
- package/srv/utils/tx-request-parsers.js +32 -0
- package/srv/utils/types.d.ts +15 -0
package/db/schema.cds
CHANGED
|
@@ -1631,3 +1631,108 @@ entity CardanoWalletJobs {
|
|
|
1631
1631
|
@description: 'Timestamp the job reached a terminal state (confirmed | failed | cancelled)'
|
|
1632
1632
|
finishedAt : Timestamp;
|
|
1633
1633
|
}
|
|
1634
|
+
|
|
1635
|
+
/**
|
|
1636
|
+
* Agent grants (v2.0): scoped bearer capabilities an Admin hands to an agent
|
|
1637
|
+
* instead of a full user. The token is a capability, not an identity — it is
|
|
1638
|
+
* stored as SHA-256 only, and a request carrying it runs as the principal
|
|
1639
|
+
* `agent:<ID>` with the role `agent-grant`, never as the operator. Enforcement
|
|
1640
|
+
* (allow list, wallet pinning, daily budget) lives in srv/utils/agent-grants.ts;
|
|
1641
|
+
* the transport lane that admits `x-agent-token` in srv/utils/agent-token-auth.ts.
|
|
1642
|
+
* Admin-only table: creation and revocation happen through CardanoAgentService
|
|
1643
|
+
* actions, a token request may read its own row only.
|
|
1644
|
+
*/
|
|
1645
|
+
@title : 'Agent Grants'
|
|
1646
|
+
@description: 'Scoped, budgeted bearer capabilities for agents (token stored as SHA-256 only)'
|
|
1647
|
+
entity CardanoAgentGrants {
|
|
1648
|
+
|
|
1649
|
+
@title : 'Grant Id (Key)'
|
|
1650
|
+
key ID : UUID;
|
|
1651
|
+
|
|
1652
|
+
@title : 'Operator'
|
|
1653
|
+
@description: 'User id of the Admin that issued the grant (audit; the token never runs as this user)'
|
|
1654
|
+
userId : String(200) not null;
|
|
1655
|
+
|
|
1656
|
+
@title : 'Agent Label'
|
|
1657
|
+
@description: 'Human-readable agent name, informational'
|
|
1658
|
+
agentLabel : String(100);
|
|
1659
|
+
|
|
1660
|
+
@title : 'Token Hash'
|
|
1661
|
+
@description: 'SHA-256 of the bearer token; the token itself is shown once and never stored'
|
|
1662
|
+
tokenHash : String(64) not null;
|
|
1663
|
+
|
|
1664
|
+
@title : 'Allowed Actions'
|
|
1665
|
+
@description: 'JSON array of allow-listed action names (builds, signing-request lifecycle, submits, wallet jobs)'
|
|
1666
|
+
allowedActions : LargeString not null;
|
|
1667
|
+
|
|
1668
|
+
@title : 'Wallet Id'
|
|
1669
|
+
@description: 'Worker wallet this grant is pinned to; required for SubmitWalletJob / CancelJob, injected into those requests'
|
|
1670
|
+
walletId : String(50);
|
|
1671
|
+
|
|
1672
|
+
@title : 'Allowed Job Kinds'
|
|
1673
|
+
@description: 'JSON array of WalletJobKind values the grant may queue; null = every kind'
|
|
1674
|
+
allowedJobKinds : LargeString;
|
|
1675
|
+
|
|
1676
|
+
@title : 'Max Jobs Per Day'
|
|
1677
|
+
@description: 'Daily budget of allow-listed action calls (UTC day); null = unlimited'
|
|
1678
|
+
maxJobsPerDay : Integer;
|
|
1679
|
+
|
|
1680
|
+
@title : 'Jobs Used Today'
|
|
1681
|
+
@description: 'Budget consumed inside budgetWindow'
|
|
1682
|
+
jobsUsedToday : Integer default 0;
|
|
1683
|
+
|
|
1684
|
+
@title : 'Budget Window'
|
|
1685
|
+
@description: 'UTC day YYYY-MM-DD the counter belongs to'
|
|
1686
|
+
budgetWindow : String(10);
|
|
1687
|
+
|
|
1688
|
+
@title : 'Valid Until'
|
|
1689
|
+
@description: 'Expiry; null = no expiry'
|
|
1690
|
+
validUntil : Timestamp;
|
|
1691
|
+
|
|
1692
|
+
@title : 'Is Active'
|
|
1693
|
+
@description: 'False once revoked; a revoked token is an unknown token'
|
|
1694
|
+
isActive : Boolean default true;
|
|
1695
|
+
|
|
1696
|
+
@title : 'Revoked At'
|
|
1697
|
+
revokedAt : Timestamp;
|
|
1698
|
+
|
|
1699
|
+
@title : 'Created At'
|
|
1700
|
+
createdAt : Timestamp;
|
|
1701
|
+
|
|
1702
|
+
@title : 'Last Used At'
|
|
1703
|
+
@description: 'Last request admitted under this token (updated at most once a minute)'
|
|
1704
|
+
lastUsedAt : Timestamp;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
/**
|
|
1708
|
+
* Daily per-action counters of admitted calls under a grant (feeds
|
|
1709
|
+
* CardanoAgentService.GetGrantUsage). Written by the enforcement hook next to
|
|
1710
|
+
* the daily budget: `calls + 1` when a call is admitted, `refunded + 1` when the
|
|
1711
|
+
* handler then refuses its input. Not exposed as an entity — the function is
|
|
1712
|
+
* the contract. A few dozen rows per grant and day at most; no retention job yet.
|
|
1713
|
+
*/
|
|
1714
|
+
entity CardanoAgentGrantUsage {
|
|
1715
|
+
|
|
1716
|
+
@title : 'Grant'
|
|
1717
|
+
key grant : Association to CardanoAgentGrants;
|
|
1718
|
+
|
|
1719
|
+
@title : 'Day'
|
|
1720
|
+
@description: 'UTC day YYYY-MM-DD the call was admitted on'
|
|
1721
|
+
key day : String(10);
|
|
1722
|
+
|
|
1723
|
+
@title : 'Service'
|
|
1724
|
+
@description: 'CAP service name (CardanoTransactionService, CardanoSignService, ...)'
|
|
1725
|
+
key service : String(60);
|
|
1726
|
+
|
|
1727
|
+
@title : 'Action'
|
|
1728
|
+
@description: 'Action name (BuildSimpleAdaTransaction, SubmitTransaction, ...)'
|
|
1729
|
+
key action : String(100);
|
|
1730
|
+
|
|
1731
|
+
@title : 'Calls'
|
|
1732
|
+
@description: 'Admitted calls (budget charged where the grant has one)'
|
|
1733
|
+
calls : Integer default 0;
|
|
1734
|
+
|
|
1735
|
+
@title : 'Refunded'
|
|
1736
|
+
@description: 'Admitted calls whose handler refused the input (400..428); their unit was given back'
|
|
1737
|
+
refunded : Integer default 0;
|
|
1738
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odatano/core",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.10",
|
|
4
4
|
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#cds-models/*": "./@cds-models/*/index.js"
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@harmoniclabs/cbor": "^2.0.1",
|
|
34
34
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
35
35
|
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
36
|
+
"@odatano/cap-auth": "^0.1.0",
|
|
36
37
|
"@sap/xssec": "^4",
|
|
37
38
|
"axios": "^1.18.0",
|
|
38
39
|
"bech32": "^2.0.0",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"axios": "^1.18.0",
|
|
46
47
|
"esbuild": "0.28.1",
|
|
47
48
|
"form-data": "^4.0.6",
|
|
48
|
-
"fast-uri": "^3.1.
|
|
49
|
+
"fast-uri": "^3.1.7",
|
|
49
50
|
"ws": "7.5.11",
|
|
50
51
|
"@sap/approuter": {
|
|
51
52
|
"body-parser": "^2.2.3"
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"@cap-js/cds-test": "^0.4.1",
|
|
56
57
|
"@cap-js/cds-typer": "^0.40.0",
|
|
57
58
|
"@cap-js/cds-types": "^0.18.0",
|
|
59
|
+
"@cap-js/postgres": "^3.1.1",
|
|
58
60
|
"@cap-js/sqlite": "^3",
|
|
59
61
|
"@sap/cds": "^10",
|
|
60
62
|
"@sap/cds-dk": "^10",
|
|
@@ -95,6 +97,9 @@
|
|
|
95
97
|
"kind": "sqlite",
|
|
96
98
|
"credentials": {
|
|
97
99
|
"url": "db.sqlite"
|
|
100
|
+
},
|
|
101
|
+
"client": {
|
|
102
|
+
"timeout": 5000
|
|
98
103
|
}
|
|
99
104
|
},
|
|
100
105
|
"[production]": {
|
|
@@ -141,7 +146,8 @@
|
|
|
141
146
|
"pretest:unit": "npm run cds:types",
|
|
142
147
|
"test:unit": "vitest run --project unit",
|
|
143
148
|
"watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
|
|
144
|
-
"watch-wallet": "cds watch --open wallet/webapp/index.html"
|
|
149
|
+
"watch-wallet": "cds watch --open wallet/webapp/index.html",
|
|
150
|
+
"release:check": "node scripts/release-check.mjs"
|
|
145
151
|
},
|
|
146
152
|
"sapux": [
|
|
147
153
|
"app/odatano"
|
package/src/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export { CardanoIndexer } from '../srv/blockchain/cardano-indexer';
|
|
|
4
4
|
export { CardanoTransactionBuilder } from '../srv/blockchain/cardano-tx-builder';
|
|
5
5
|
export { getAppContext, getCardanoIndexer, getCardanoClient, getCardanoTxBuilder, loadConfigFromEnv, loadHsmConfigFromEnv, loadCrawlerConfigFromEnv, startCrawlerIfConfigured, loadWalletWorkerConfigFromEnv, startWalletWorkerIfConfigured, shutdownAppContext, } from '../srv/server';
|
|
6
6
|
export { getHsmSigner } from '../srv/blockchain/signing/hsm-signer';
|
|
7
|
+
export { issueAgentGrant, updateAgentGrant, rotateAgentGrantToken, revokeAgentGrantById, getGrantUsage, resolveUsageWindow, hashAgentToken, AGENT_TOKEN_HEADER, AGENT_TOKEN_PREFIX, AGENT_ROLE, AGENT_ALLOWLISTABLE_ACTIONS, AGENT_ALWAYS_ALLOWED_EVENTS, } from '../srv/utils/agent-grants';
|
|
8
|
+
export type { IssueAgentGrantInput, IssuedAgentGrant, AgentGrantStatus, UpdateAgentGrantInput, UpdateAgentGrantResult, RotatedAgentGrant, AgentGrantUsage, GrantUsageCall, UsageWindow, } from '../srv/utils/agent-grants';
|
|
9
|
+
export { registerTransportLane } from '@odatano/cap-auth';
|
|
10
|
+
export type { TransportLane, LaneOutcome } from '@odatano/cap-auth';
|
|
11
|
+
export { loadAgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
|
12
|
+
export type { AgentGrantsConfig } from '../srv/utils/agent-grants-config';
|
|
7
13
|
export type { HsmConfig, HsmSignResult } from '../srv/utils/types';
|
|
8
14
|
export { parseTransaction } from '../srv/cbor';
|
|
9
15
|
export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, } from '../srv/cbor';
|
package/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.parseTransaction = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
|
|
39
|
+
exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
|
|
40
40
|
exports.initialize = initialize;
|
|
41
41
|
exports.shutdown = shutdown;
|
|
42
42
|
exports.getStatus = getStatus;
|
|
@@ -65,6 +65,26 @@ Object.defineProperty(exports, "shutdownAppContext", { enumerable: true, get: fu
|
|
|
65
65
|
// Re-export HSM signer for programmatic access
|
|
66
66
|
var hsm_signer_1 = require("../srv/blockchain/signing/hsm-signer");
|
|
67
67
|
Object.defineProperty(exports, "getHsmSigner", { enumerable: true, get: function () { return hsm_signer_1.getHsmSigner; } });
|
|
68
|
+
// Agent grants (v2.0, AGENT_GRANTS_DESIGN.md): the programmatic seams other
|
|
69
|
+
// packages build on — @odatano/x402 sells grants through issueAgentGrant and
|
|
70
|
+
// adds its payment lane through registerTransportLane.
|
|
71
|
+
var agent_grants_1 = require("../srv/utils/agent-grants");
|
|
72
|
+
Object.defineProperty(exports, "issueAgentGrant", { enumerable: true, get: function () { return agent_grants_1.issueAgentGrant; } });
|
|
73
|
+
Object.defineProperty(exports, "updateAgentGrant", { enumerable: true, get: function () { return agent_grants_1.updateAgentGrant; } });
|
|
74
|
+
Object.defineProperty(exports, "rotateAgentGrantToken", { enumerable: true, get: function () { return agent_grants_1.rotateAgentGrantToken; } });
|
|
75
|
+
Object.defineProperty(exports, "revokeAgentGrantById", { enumerable: true, get: function () { return agent_grants_1.revokeAgentGrantById; } });
|
|
76
|
+
Object.defineProperty(exports, "getGrantUsage", { enumerable: true, get: function () { return agent_grants_1.getGrantUsage; } });
|
|
77
|
+
Object.defineProperty(exports, "resolveUsageWindow", { enumerable: true, get: function () { return agent_grants_1.resolveUsageWindow; } });
|
|
78
|
+
Object.defineProperty(exports, "hashAgentToken", { enumerable: true, get: function () { return agent_grants_1.hashAgentToken; } });
|
|
79
|
+
Object.defineProperty(exports, "AGENT_TOKEN_HEADER", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_HEADER; } });
|
|
80
|
+
Object.defineProperty(exports, "AGENT_TOKEN_PREFIX", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_PREFIX; } });
|
|
81
|
+
Object.defineProperty(exports, "AGENT_ROLE", { enumerable: true, get: function () { return agent_grants_1.AGENT_ROLE; } });
|
|
82
|
+
Object.defineProperty(exports, "AGENT_ALLOWLISTABLE_ACTIONS", { enumerable: true, get: function () { return agent_grants_1.AGENT_ALLOWLISTABLE_ACTIONS; } });
|
|
83
|
+
Object.defineProperty(exports, "AGENT_ALWAYS_ALLOWED_EVENTS", { enumerable: true, get: function () { return agent_grants_1.AGENT_ALWAYS_ALLOWED_EVENTS; } });
|
|
84
|
+
var cap_auth_1 = require("@odatano/cap-auth");
|
|
85
|
+
Object.defineProperty(exports, "registerTransportLane", { enumerable: true, get: function () { return cap_auth_1.registerTransportLane; } });
|
|
86
|
+
var agent_grants_config_1 = require("../srv/utils/agent-grants-config");
|
|
87
|
+
Object.defineProperty(exports, "loadAgentGrantsConfig", { enumerable: true, get: function () { return agent_grants_config_1.loadAgentGrantsConfig; } });
|
|
68
88
|
// Re-export pure CBOR utilities (no CAP round-trip needed)
|
|
69
89
|
var cbor_1 = require("../srv/cbor");
|
|
70
90
|
Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return cbor_1.parseTransaction; } });
|
package/src/plugin.js
CHANGED
|
@@ -52,32 +52,46 @@ if (!cds_1.default.env.requires) {
|
|
|
52
52
|
if (!cds_1.default.env.requires.kinds) {
|
|
53
53
|
cds_1.default.env.requires.kinds = {};
|
|
54
54
|
}
|
|
55
|
+
/** The schema and the six CDS services this package ships, package-qualified. */
|
|
56
|
+
const PLUGIN_MODEL = [
|
|
57
|
+
'@odatano/core/db/schema',
|
|
58
|
+
'@odatano/core/srv/cardano-service',
|
|
59
|
+
'@odatano/core/srv/cardano-tx-service',
|
|
60
|
+
'@odatano/core/srv/cardano-sign-service',
|
|
61
|
+
'@odatano/core/srv/cardano-indexer-service',
|
|
62
|
+
'@odatano/core/srv/cardano-worker-service',
|
|
63
|
+
'@odatano/core/srv/cardano-agent-service'
|
|
64
|
+
];
|
|
65
|
+
/** Relative `@impl` values used in the CDS files (rewritten in plugin mode, see below). */
|
|
66
|
+
const IMPL_PATHS = [
|
|
67
|
+
'srv/cardano-service',
|
|
68
|
+
'srv/cardano-tx-service',
|
|
69
|
+
'srv/cardano-sign-service',
|
|
70
|
+
'srv/cardano-indexer-service',
|
|
71
|
+
'srv/cardano-worker-service',
|
|
72
|
+
'srv/cardano-agent-service'
|
|
73
|
+
];
|
|
55
74
|
cds_1.default.env.requires.kinds['odatano-core'] = {
|
|
56
75
|
impl: '@odatano/core',
|
|
57
|
-
model: [
|
|
58
|
-
'@odatano/core/db/schema',
|
|
59
|
-
'@odatano/core/srv/cardano-service',
|
|
60
|
-
'@odatano/core/srv/cardano-tx-service',
|
|
61
|
-
'@odatano/core/srv/cardano-sign-service',
|
|
62
|
-
'@odatano/core/srv/cardano-indexer-service',
|
|
63
|
-
'@odatano/core/srv/cardano-worker-service'
|
|
64
|
-
]
|
|
76
|
+
model: [...PLUGIN_MODEL]
|
|
65
77
|
};
|
|
66
78
|
// CRITICAL: Also set model directly on the requires entry.
|
|
67
79
|
// CAP's _link_required_services() merges kind→requires BEFORE cds-plugin.js runs,
|
|
68
80
|
// so the model array on the kind is never merged. Set it directly.
|
|
69
81
|
const req = cds_1.default.env.requires['odatano-core'];
|
|
70
82
|
if (req) {
|
|
71
|
-
req.model = [
|
|
72
|
-
'@odatano/core/db/schema',
|
|
73
|
-
'@odatano/core/srv/cardano-service',
|
|
74
|
-
'@odatano/core/srv/cardano-tx-service',
|
|
75
|
-
'@odatano/core/srv/cardano-sign-service',
|
|
76
|
-
'@odatano/core/srv/cardano-indexer-service',
|
|
77
|
-
'@odatano/core/srv/cardano-worker-service'
|
|
78
|
-
];
|
|
83
|
+
req.model = [...PLUGIN_MODEL];
|
|
79
84
|
}
|
|
80
85
|
logger.debug('Plugin registered');
|
|
86
|
+
/**
|
|
87
|
+
* Agent grants (AGENT_GRANTS_DESIGN.md). Off by default; switched on by
|
|
88
|
+
* cds.requires.odatano-core.agentGrants.enabled / AGENT_GRANTS_ENABLED=true.
|
|
89
|
+
* Has to run at plugin load, before CAP builds its middlewares (the auth impl
|
|
90
|
+
* is swapped here). srv/server.ts makes the same call for standalone mode, where
|
|
91
|
+
* this file is never loaded; the call is idempotent and never throws.
|
|
92
|
+
*/
|
|
93
|
+
require('../srv/utils/agent-grants-config')
|
|
94
|
+
.activateAgentGrants();
|
|
81
95
|
/**
|
|
82
96
|
* Rewrite @impl paths for plugin mode.
|
|
83
97
|
* CDS files use relative @impl (e.g. 'srv/cardano-service') which resolves from cds.root.
|
|
@@ -90,20 +104,9 @@ cds_1.default.on('loaded', (model) => {
|
|
|
90
104
|
return;
|
|
91
105
|
const defs = model.definitions ?? {};
|
|
92
106
|
for (const def of Object.values(defs)) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
else if (def['@impl'] === 'srv/cardano-tx-service') {
|
|
97
|
-
def['@impl'] = '@odatano/core/srv/cardano-tx-service';
|
|
98
|
-
}
|
|
99
|
-
else if (def['@impl'] === 'srv/cardano-sign-service') {
|
|
100
|
-
def['@impl'] = '@odatano/core/srv/cardano-sign-service';
|
|
101
|
-
}
|
|
102
|
-
else if (def['@impl'] === 'srv/cardano-indexer-service') {
|
|
103
|
-
def['@impl'] = '@odatano/core/srv/cardano-indexer-service';
|
|
104
|
-
}
|
|
105
|
-
else if (def['@impl'] === 'srv/cardano-worker-service') {
|
|
106
|
-
def['@impl'] = '@odatano/core/srv/cardano-worker-service';
|
|
107
|
+
const impl = def['@impl'];
|
|
108
|
+
if (impl && IMPL_PATHS.includes(impl)) {
|
|
109
|
+
def['@impl'] = `@odatano/core/${impl}`;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
});
|
|
@@ -274,16 +274,7 @@ class BlockfrostBackend {
|
|
|
274
274
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
275
275
|
const a = await this.api.assetsById(unit);
|
|
276
276
|
const reg = a.metadata ?? null;
|
|
277
|
-
const decodeUtf8 = (hex) =>
|
|
278
|
-
if (!hex)
|
|
279
|
-
return null;
|
|
280
|
-
try {
|
|
281
|
-
return Buffer.from(hex, 'hex').toString('utf8');
|
|
282
|
-
}
|
|
283
|
-
catch {
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
};
|
|
277
|
+
const decodeUtf8 = (hex) => (hex ? (0, mappers_1.decodeAssetName)(hex) : null);
|
|
287
278
|
return {
|
|
288
279
|
unit: a.asset,
|
|
289
280
|
policyId: a.policy_id,
|
|
@@ -519,16 +519,7 @@ class KoiosBackend {
|
|
|
519
519
|
const onchainMetadata = mintMeta && typeof mintMeta === 'object'
|
|
520
520
|
? (mintMeta['721'] ?? mintMeta)
|
|
521
521
|
: null;
|
|
522
|
-
const decodeUtf8 = (hex) =>
|
|
523
|
-
if (!hex)
|
|
524
|
-
return null;
|
|
525
|
-
try {
|
|
526
|
-
return Buffer.from(hex, 'hex').toString('utf8');
|
|
527
|
-
}
|
|
528
|
-
catch {
|
|
529
|
-
return null;
|
|
530
|
-
}
|
|
531
|
-
};
|
|
522
|
+
const decodeUtf8 = (hex) => (hex ? (0, mappers_1.decodeAssetName)(hex) : null);
|
|
532
523
|
const mintCnt = typeof a.mint_cnt === 'number' ? a.mint_cnt : 0;
|
|
533
524
|
const burnCnt = typeof a.burn_cnt === 'number' ? a.burn_cnt : 0;
|
|
534
525
|
return {
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, AccountData, DrepData, AssetInfo, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
|
|
2
2
|
import { EvaluatingBackend, ChainSyncBackend, ChainSyncCallbacks, ChainSyncHandle, ChainPoint } from './cardano-backend';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
|
+
/**
|
|
5
|
+
* Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into its credential hash and
|
|
6
|
+
* type. Header byte: high nibble 0x2 = DRep, low nibble 0x2 = key hash /
|
|
7
|
+
* 0x3 = script hash. The validators already enforce HRP + length before the
|
|
8
|
+
* request reaches a backend, so this only has to split the payload.
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeDrepId(drepId: string): {
|
|
11
|
+
hashHex: string;
|
|
12
|
+
isScript: boolean;
|
|
13
|
+
};
|
|
4
14
|
/** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
|
|
5
15
|
export declare function resolveOgmiosTip(tip: 'origin' | {
|
|
6
16
|
slot: number;
|
|
@@ -107,11 +117,21 @@ export declare class OgmiosBackend implements EvaluatingBackend, ChainSyncBacken
|
|
|
107
117
|
*/
|
|
108
118
|
getTransactionMetadata(_tx_hash: string): Promise<MetadataLabelTx[]>;
|
|
109
119
|
/**
|
|
110
|
-
* Get
|
|
111
|
-
*
|
|
120
|
+
* Get DRep data from the live ledger state (`queryLedgerState/delegateRepresentatives`).
|
|
121
|
+
*
|
|
122
|
+
* The client package (6.14) ships the schema types but no wrapper for this query,
|
|
123
|
+
* so it goes through the exported `Method()` primitive on our interaction context —
|
|
124
|
+
* the same building block the client uses for `stakePools` & co.
|
|
125
|
+
*
|
|
126
|
+
* Semantics vs. Blockfrost/Koios: Ogmios only lists REGISTERED DReps, so a retired
|
|
127
|
+
* or unknown DRep is a NotFoundError here (never `retired: true`), and there is no
|
|
128
|
+
* last-activity epoch — `expired` is derived from the mandate epoch instead.
|
|
129
|
+
* Routing keeps `getDrep` historical-preferred; this is the Ogmios-only fallback.
|
|
130
|
+
*
|
|
131
|
+
* @param drepId CIP-129 bech32 DRep ID (`drep1…`)
|
|
112
132
|
* @returns {Promise<DrepData>} drep data
|
|
113
133
|
*/
|
|
114
|
-
getDrep(
|
|
134
|
+
getDrep(drepId: string): Promise<DrepData>;
|
|
115
135
|
/**
|
|
116
136
|
* Get Asset Info (not supported for Ogmios — no aggregate-supply query in the protocol)
|
|
117
137
|
* @param _unit asset unit (policyId + assetNameHex)
|
|
@@ -4,11 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OgmiosBackend = void 0;
|
|
7
|
+
exports.decodeDrepId = decodeDrepId;
|
|
7
8
|
exports.resolveOgmiosTip = resolveOgmiosTip;
|
|
8
9
|
exports.resolveOgmiosHeight = resolveOgmiosHeight;
|
|
9
10
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
11
|
const node_http_1 = __importDefault(require("node:http"));
|
|
11
12
|
const client_1 = require("@cardano-ogmios/client");
|
|
13
|
+
const bech32_1 = require("bech32");
|
|
12
14
|
const backend_request_handler_1 = require("../../utils/backend-request-handler");
|
|
13
15
|
const errors_1 = require("../../utils/errors");
|
|
14
16
|
const mappers_1 = require("../../utils/mappers");
|
|
@@ -63,6 +65,23 @@ function ogmiosValueToLovelaceString(value) {
|
|
|
63
65
|
const lovelace = value.ada?.lovelace;
|
|
64
66
|
return lovelace === undefined ? '0' : String(lovelace);
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Decode a CIP-129 DRep ID (`drep1…`, 29 bytes) into its credential hash and
|
|
70
|
+
* type. Header byte: high nibble 0x2 = DRep, low nibble 0x2 = key hash /
|
|
71
|
+
* 0x3 = script hash. The validators already enforce HRP + length before the
|
|
72
|
+
* request reaches a backend, so this only has to split the payload.
|
|
73
|
+
*/
|
|
74
|
+
function decodeDrepId(drepId) {
|
|
75
|
+
const decoded = bech32_1.bech32.decode(drepId, const_1.BECH32_MAX_LENGTH);
|
|
76
|
+
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
77
|
+
if (decoded.prefix !== 'drep' || bytes.length !== 29) {
|
|
78
|
+
throw new errors_1.NotFoundError('Drep', 'ogmios');
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
hashHex: bytes.subarray(1).toString('hex'),
|
|
82
|
+
isScript: (bytes[0] & 0x0f) === 0x03,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
66
85
|
/** Resolve Ogmios ledger tip which may be 'origin' (genesis block) or a point */
|
|
67
86
|
function resolveOgmiosTip(tip) {
|
|
68
87
|
return tip === 'origin' ? { slot: 0, hash: '' } : { slot: tip.slot, hash: tip.id };
|
|
@@ -88,7 +107,8 @@ class OgmiosBackend {
|
|
|
88
107
|
'getTransaction',
|
|
89
108
|
'getTransactionMetadata',
|
|
90
109
|
'getAddressTransactions',
|
|
91
|
-
|
|
110
|
+
// getDrep is NOT listed: served from the live ledger state via
|
|
111
|
+
// queryLedgerState/delegateRepresentatives (Ogmios ≥ 6.4).
|
|
92
112
|
'getAssetInfo',
|
|
93
113
|
'getAddress',
|
|
94
114
|
'getNetworkInformation',
|
|
@@ -305,13 +325,60 @@ class OgmiosBackend {
|
|
|
305
325
|
}, this.name);
|
|
306
326
|
}
|
|
307
327
|
/**
|
|
308
|
-
* Get
|
|
309
|
-
*
|
|
328
|
+
* Get DRep data from the live ledger state (`queryLedgerState/delegateRepresentatives`).
|
|
329
|
+
*
|
|
330
|
+
* The client package (6.14) ships the schema types but no wrapper for this query,
|
|
331
|
+
* so it goes through the exported `Method()` primitive on our interaction context —
|
|
332
|
+
* the same building block the client uses for `stakePools` & co.
|
|
333
|
+
*
|
|
334
|
+
* Semantics vs. Blockfrost/Koios: Ogmios only lists REGISTERED DReps, so a retired
|
|
335
|
+
* or unknown DRep is a NotFoundError here (never `retired: true`), and there is no
|
|
336
|
+
* last-activity epoch — `expired` is derived from the mandate epoch instead.
|
|
337
|
+
* Routing keeps `getDrep` historical-preferred; this is the Ogmios-only fallback.
|
|
338
|
+
*
|
|
339
|
+
* @param drepId CIP-129 bech32 DRep ID (`drep1…`)
|
|
310
340
|
* @returns {Promise<DrepData>} drep data
|
|
311
341
|
*/
|
|
312
|
-
async getDrep(
|
|
342
|
+
async getDrep(drepId) {
|
|
313
343
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
314
|
-
|
|
344
|
+
await this.ensureConnected();
|
|
345
|
+
if (!this.context) {
|
|
346
|
+
throw new errors_1.ProviderUnavailableError('Ogmios interaction context not available', this.name);
|
|
347
|
+
}
|
|
348
|
+
const { hashHex, isScript } = decodeDrepId(drepId);
|
|
349
|
+
const [summaries, currentEpoch] = await Promise.all([
|
|
350
|
+
(0, client_1.Method)({
|
|
351
|
+
method: 'queryLedgerState/delegateRepresentatives',
|
|
352
|
+
params: isScript ? { scripts: [hashHex] } : { keys: [hashHex] },
|
|
353
|
+
}, {
|
|
354
|
+
handler: (response, resolve, reject) => {
|
|
355
|
+
if (response.error) {
|
|
356
|
+
reject(new Error(response.error.message ?? `Ogmios error ${response.error.code ?? ''}`.trim()));
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
resolve(Array.isArray(response.result) ? response.result : []);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
}, this.context),
|
|
363
|
+
this.stateQueryClient.epoch(),
|
|
364
|
+
]);
|
|
365
|
+
// Filter by id: the query is already credential-scoped, but never trust a
|
|
366
|
+
// broader answer (abstain/noConfidence rows carry no id and are dropped here).
|
|
367
|
+
const drep = summaries.find((s) => s.type === 'registered' && s.id?.toLowerCase() === hashHex);
|
|
368
|
+
if (!drep)
|
|
369
|
+
throw new errors_1.NotFoundError('Drep', this.name);
|
|
370
|
+
const mandateEpoch = drep.mandate?.epoch;
|
|
371
|
+
return {
|
|
372
|
+
drepId,
|
|
373
|
+
hex: hashHex,
|
|
374
|
+
amount: ogmiosValueToLovelaceString(drep.stake),
|
|
375
|
+
hasScript: isScript || drep.from === 'script',
|
|
376
|
+
// Ogmios reports the mandate (expiry) epoch, not the last activity — keep 0,
|
|
377
|
+
// matching what the Koios mapper does since its schema change.
|
|
378
|
+
lastActiveEpoch: 0,
|
|
379
|
+
expired: typeof mandateEpoch === 'number' && mandateEpoch < Number(currentEpoch),
|
|
380
|
+
retired: false,
|
|
381
|
+
};
|
|
315
382
|
}, this.name);
|
|
316
383
|
}
|
|
317
384
|
/**
|
|
@@ -496,7 +496,9 @@ class CardanoIndexer {
|
|
|
496
496
|
await tx.run(UPSERT.into(CardanoODataService_1.Block).entries((0, mappers_1.mapBlock)(blockData, epoch)));
|
|
497
497
|
// Backfill chain-sync inputs (empty address/amount) from local outputs
|
|
498
498
|
await this.resolveInputs(tx, txs);
|
|
499
|
-
// Accumulate rows across the whole block, then one bulk UPSERT per table
|
|
499
|
+
// Accumulate rows across the whole block, then one bulk UPSERT per table.
|
|
500
|
+
// NUL safety (PostgreSQL rejects U+0000 in text/JSON) is enforced for every write
|
|
501
|
+
// of this plugin by the db-level hook in srv/utils/db-sanitize.ts, not per call site.
|
|
500
502
|
const txRows = txs.map(t => (0, mappers_1.mapTransaction)(t));
|
|
501
503
|
const inputRows = txs.flatMap(t => (0, mappers_1.mapTransactionInputs)(t.hash, t.inputs ?? []));
|
|
502
504
|
const inputAssetRows = txs.flatMap(t => (0, mappers_1.mapTransactionInputAssets)(t.hash, t.inputs ?? []));
|
|
@@ -41,6 +41,23 @@ export declare class CardanoCrawler {
|
|
|
41
41
|
private readonly leaseOwner?;
|
|
42
42
|
/** Transient-failure retries per block before giving up. */
|
|
43
43
|
private static readonly PERSIST_RETRIES;
|
|
44
|
+
/**
|
|
45
|
+
* A block whose persist keeps failing across crawler restarts is a poison block
|
|
46
|
+
* (e.g. data PostgreSQL rejects). After this many failed persistBlock() calls for
|
|
47
|
+
* the same hash the crawler latches off (desiredRunning=false) instead of
|
|
48
|
+
* restarting forever; an operator fixes the cause and calls resumeCrawler().
|
|
49
|
+
*/
|
|
50
|
+
private static readonly POISON_BLOCK_THRESHOLD;
|
|
51
|
+
/** Process-wide, survives instance restarts: the block currently failing and how often. */
|
|
52
|
+
private static poison;
|
|
53
|
+
/**
|
|
54
|
+
* Database errors that are deterministic for the block's data — the same bytes fail
|
|
55
|
+
* the same way on every restart. Only these count towards the poison-block latch:
|
|
56
|
+
* a DB outage, a statement timeout or an exhausted pool fails the same block too,
|
|
57
|
+
* but a restart fixes those, and latching on them would disable the pre-sync for
|
|
58
|
+
* good (the contract of halt()).
|
|
59
|
+
*/
|
|
60
|
+
private static readonly DATA_REJECTION_PATTERNS;
|
|
44
61
|
/** Timeout for direct backend calls (the crawler bypasses the client's resilience layer). */
|
|
45
62
|
private static readonly CALL_TIMEOUT_MS;
|
|
46
63
|
private running;
|
|
@@ -64,6 +81,8 @@ export declare class CardanoCrawler {
|
|
|
64
81
|
/** Present for production instances created by index.ts; omitted in engine unit tests. */
|
|
65
82
|
leaseOwner?: string | undefined);
|
|
66
83
|
isRunning(): boolean;
|
|
84
|
+
/** True once the crawler halted because of a failure (not via stop() or a lost lease). */
|
|
85
|
+
haltedWithError(): boolean;
|
|
67
86
|
/**
|
|
68
87
|
* Start crawling. Does NOT await the ingest pipeline (fire-and-forget).
|
|
69
88
|
* Refuses to start without a resume point: an explicit configured start block or an
|
|
@@ -142,6 +161,12 @@ export declare class CardanoCrawler {
|
|
|
142
161
|
private handleReorg;
|
|
143
162
|
/** Renew the lease while an Ogmios stream is idle; block writes renew it transactionally. */
|
|
144
163
|
private startLeaseHeartbeat;
|
|
164
|
+
/** Whether a persist error is deterministic for the block's data (see DATA_REJECTION_PATTERNS). */
|
|
165
|
+
static isDataRejection(err: unknown): boolean;
|
|
166
|
+
/** Count final persist failures per block hash (a different hash resets the count). */
|
|
167
|
+
private static notePersistFailure;
|
|
168
|
+
/** Test seam: forget the poison-block memory (process-wide state). */
|
|
169
|
+
static resetPoisonMemory(): void;
|
|
145
170
|
/** Record state only while this instance still owns the lease. */
|
|
146
171
|
private recordCrawlerError;
|
|
147
172
|
private leaseSleep;
|