@odatano/core 2.0.0-rc.1 → 2.0.0-rc.2
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/README.md +136 -136
- package/package.json +173 -173
- package/srv/cardano-indexer-service.cds +73 -73
- package/srv/cardano-service.js +54 -4
- package/srv/cardano-worker-service.cds +125 -125
- package/srv/server.js +1 -34
package/README.md
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# Enterprise OData Services for the Cardano Blockchain
|
|
4
|
-
|
|
5
|
-
Funded by [Cardano Catalyst Fund 14](https://projectcatalyst.io/funds/14/sponsored-by-leftovers/sap-cardano-odata-v4-api-with-cap-and-sap-cardano-sdk) all four milestones completed and approved (April 2026).
|
|
6
|
-
|
|
7
|
-
**ODATANO** is an SAP CAP–based service that exposes the Cardano blockchain via a standardized **OData V4** interface, enabling enterprise-grade read and write access with native transaction building.
|
|
8
|
-
|
|
9
|
-
[](https://github.com/ODATANO/ODATANO/actions/workflows/test.yaml)
|
|
10
|
-
[](https://codecov.io/gh/ODATANO/ODATANO)
|
|
11
|
-
[](https://www.npmjs.com/package/@odatano/core)
|
|
12
|
-
[](https://www.npmjs.com/package/@odatano/core)
|
|
13
|
-
[](LICENSE)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Quick Start
|
|
17
|
-
|
|
18
|
-
### As CAP Plugin (recommended)
|
|
19
|
-
|
|
20
|
-
Add ODATANO to any existing SAP CAP project:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install @odatano/core @cap-js/sqlite
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
```json
|
|
27
|
-
{
|
|
28
|
-
"cds": {
|
|
29
|
-
"requires": {
|
|
30
|
-
"db": { "kind": "sqlite" },
|
|
31
|
-
"odatano-core": {
|
|
32
|
-
"network": "preview",
|
|
33
|
-
"backends": ["blockfrost"]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Put your API key in a `.env` file in the project root (loaded automatically by `cds serve` / `cds watch`) — don't commit it to `package.json`:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
# .env
|
|
44
|
-
BLOCKFROST_API_KEY=preview_your_api_key_here
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
cds deploy --to sqlite
|
|
49
|
-
cds serve
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
> Config in `cds.requires.odatano-core` takes precedence over environment
|
|
53
|
-
> variables; a `blockfrostApiKey` set there would override the `.env` value.
|
|
54
|
-
|
|
55
|
-
> **Self-hosted Blockfrost-compatible node?** (Dolos MiniBF, Demeter Self-Hosted)
|
|
56
|
-
> Set `blockfrostCustomBackend` to the node's base URL (e.g. `http://localhost:3010/api/v0`).
|
|
57
|
-
> When set, `blockfrostApiKey` becomes optional. See the [Backend Configuration Guide](docs/guides/BACKEND_CONFIGURATION.md#self-hosted-blockfrost-compatible-backends).
|
|
58
|
-
|
|
59
|
-
### Standalone
|
|
60
|
-
|
|
61
|
-
Run ODATANO as a self-contained service (no host CAP project needed):
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
git clone https://github.com/ODATANO/ODATANO && cd ODATANO
|
|
65
|
-
npm ci
|
|
66
|
-
cp .env.example .env # set BLOCKFROST_API_KEY, NETWORK, BACKENDS
|
|
67
|
-
cds deploy --to sqlite
|
|
68
|
-
cds serve
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Or with Docker — this brings up a local **cardano-node + Ogmios + ODATANO** stack
|
|
72
|
-
(Preview), with the service pre-wired to the local Ogmios backend:
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
docker compose up -d # full stack
|
|
76
|
-
docker compose up -d cardano-node ogmios # just the chain backend (pre-sync)
|
|
77
|
-
docker compose logs -f ogmios # watch sync (/health: 202 syncing, 200 near tip)
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
> First sync from genesis takes hours; the node DB persists in a Docker volume so
|
|
81
|
-
> restarts resume. Until Ogmios catches up, historical queries fall back to
|
|
82
|
-
> Blockfrost (set `BLOCKFROST_API_KEY`).
|
|
83
|
-
|
|
84
|
-
Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/QUICK_START.md#local-ogmios--cardano-node-docker) for the local Ogmios stack and full details.
|
|
85
|
-
|
|
86
|
-
## Dev Mode: Mocked Authentication
|
|
87
|
-
|
|
88
|
-
> **Heads-up.** `cds serve` uses CAP's mocked auth: `@requires: 'authenticated-user'` accepts any Basic-Auth header against a mock user (`alice`, `bob`, …) — passwords are not checked. Anonymous requests get 401, but anyone reaching the port can authenticate.
|
|
89
|
-
>
|
|
90
|
-
> Production needs the `[production]` profile (`NODE_ENV=production`), which switches to `auth: xsuaa`. Don't expose a dev-mode instance. See the [Security Guide](docs/guides/SECURITY_GUIDE.md#authentication-xsuaa).
|
|
91
|
-
|
|
92
|
-
## Services
|
|
93
|
-
|
|
94
|
-
| Service | Path | Purpose |
|
|
95
|
-
|---|---|---|
|
|
96
|
-
| CardanoODataService | `/odata/v4/cardano-odata/` | Read blockchain data (20 entities, 19 actions) |
|
|
97
|
-
| CardanoTransactionService | `/odata/v4/cardano-transaction/` | Build & submit transactions (13 actions) |
|
|
98
|
-
| CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
|
|
99
|
-
| CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (v2.0, off by default) |
|
|
100
|
-
| CardanoWorkerService | `/odata/v4/cardano-worker/` | Asynchronous wallet jobs (v2.0, off by default) |
|
|
101
|
-
|
|
102
|
-
Both v2.0 services also publish **CAP events**, so a consumer can subscribe instead of polling —
|
|
103
|
-
in-process, no broker required:
|
|
104
|
-
|
|
105
|
-
```js
|
|
106
|
-
(await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
|
|
107
|
-
(await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## Requirements
|
|
111
|
-
|
|
112
|
-
- **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
|
|
113
|
-
- Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds four tables (`CardanoSyncState`,
|
|
114
|
-
`CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`) plus a `dedupKey` column; without
|
|
115
|
-
the redeploy the new services answer `no such table` while the old ones keep working.
|
|
116
|
-
|
|
117
|
-
## Documentation
|
|
118
|
-
|
|
119
|
-
| Guide | Description |
|
|
120
|
-
|-------|-------------|
|
|
121
|
-
| [Quick Start](docs/QUICK_START.md) | Get running in 5 minutes |
|
|
122
|
-
| [User Guide](docs/guides/USER_GUIDE.md) | API usage, entities, and examples |
|
|
123
|
-
| [Developer Guide](docs/guides/DEVELOPER_GUIDE.md) | Architecture and development |
|
|
124
|
-
| [Transaction Workflow](docs/guides/TRANSACTION_WORKFLOW.md) | Build → Sign → Submit flow |
|
|
125
|
-
| [Security Guide](docs/guides/SECURITY_GUIDE.md) | Authentication, signing security, HSM |
|
|
126
|
-
| [Docker Deployment](docs/guides/DOCKER_DEPLOYMENT.md) | Container deployment |
|
|
127
|
-
|
|
128
|
-
## License
|
|
129
|
-
|
|
130
|
-
Apache License 2.0 - see [LICENSE](LICENSE)
|
|
131
|
-
|
|
132
|
-
## Support
|
|
133
|
-
|
|
134
|
-
- **Issues**: [GitHub Issues](https://github.com/ODATANO/ODATANO/issues)
|
|
135
|
-
- **Project Lead**: Max Weber
|
|
136
|
-
- **Contact**: info@odatano.dev
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Enterprise OData Services for the Cardano Blockchain
|
|
4
|
+
|
|
5
|
+
Funded by [Cardano Catalyst Fund 14](https://projectcatalyst.io/funds/14/sponsored-by-leftovers/sap-cardano-odata-v4-api-with-cap-and-sap-cardano-sdk) all four milestones completed and approved (April 2026).
|
|
6
|
+
|
|
7
|
+
**ODATANO** is an SAP CAP–based service that exposes the Cardano blockchain via a standardized **OData V4** interface, enabling enterprise-grade read and write access with native transaction building.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/ODATANO/ODATANO/actions/workflows/test.yaml)
|
|
10
|
+
[](https://codecov.io/gh/ODATANO/ODATANO)
|
|
11
|
+
[](https://www.npmjs.com/package/@odatano/core)
|
|
12
|
+
[](https://www.npmjs.com/package/@odatano/core)
|
|
13
|
+
[](LICENSE)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### As CAP Plugin (recommended)
|
|
19
|
+
|
|
20
|
+
Add ODATANO to any existing SAP CAP project:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @odatano/core @cap-js/sqlite
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"cds": {
|
|
29
|
+
"requires": {
|
|
30
|
+
"db": { "kind": "sqlite" },
|
|
31
|
+
"odatano-core": {
|
|
32
|
+
"network": "preview",
|
|
33
|
+
"backends": ["blockfrost"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Put your API key in a `.env` file in the project root (loaded automatically by `cds serve` / `cds watch`) — don't commit it to `package.json`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# .env
|
|
44
|
+
BLOCKFROST_API_KEY=preview_your_api_key_here
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
cds deploy --to sqlite
|
|
49
|
+
cds serve
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> Config in `cds.requires.odatano-core` takes precedence over environment
|
|
53
|
+
> variables; a `blockfrostApiKey` set there would override the `.env` value.
|
|
54
|
+
|
|
55
|
+
> **Self-hosted Blockfrost-compatible node?** (Dolos MiniBF, Demeter Self-Hosted)
|
|
56
|
+
> Set `blockfrostCustomBackend` to the node's base URL (e.g. `http://localhost:3010/api/v0`).
|
|
57
|
+
> When set, `blockfrostApiKey` becomes optional. See the [Backend Configuration Guide](docs/guides/BACKEND_CONFIGURATION.md#self-hosted-blockfrost-compatible-backends).
|
|
58
|
+
|
|
59
|
+
### Standalone
|
|
60
|
+
|
|
61
|
+
Run ODATANO as a self-contained service (no host CAP project needed):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/ODATANO/ODATANO && cd ODATANO
|
|
65
|
+
npm ci
|
|
66
|
+
cp .env.example .env # set BLOCKFROST_API_KEY, NETWORK, BACKENDS
|
|
67
|
+
cds deploy --to sqlite
|
|
68
|
+
cds serve
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Or with Docker — this brings up a local **cardano-node + Ogmios + ODATANO** stack
|
|
72
|
+
(Preview), with the service pre-wired to the local Ogmios backend:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
docker compose up -d # full stack
|
|
76
|
+
docker compose up -d cardano-node ogmios # just the chain backend (pre-sync)
|
|
77
|
+
docker compose logs -f ogmios # watch sync (/health: 202 syncing, 200 near tip)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
> First sync from genesis takes hours; the node DB persists in a Docker volume so
|
|
81
|
+
> restarts resume. Until Ogmios catches up, historical queries fall back to
|
|
82
|
+
> Blockfrost (set `BLOCKFROST_API_KEY`).
|
|
83
|
+
|
|
84
|
+
Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/QUICK_START.md#local-ogmios--cardano-node-docker) for the local Ogmios stack and full details.
|
|
85
|
+
|
|
86
|
+
## Dev Mode: Mocked Authentication
|
|
87
|
+
|
|
88
|
+
> **Heads-up.** `cds serve` uses CAP's mocked auth: `@requires: 'authenticated-user'` accepts any Basic-Auth header against a mock user (`alice`, `bob`, …) — passwords are not checked. Anonymous requests get 401, but anyone reaching the port can authenticate.
|
|
89
|
+
>
|
|
90
|
+
> Production needs the `[production]` profile (`NODE_ENV=production`), which switches to `auth: xsuaa`. Don't expose a dev-mode instance. See the [Security Guide](docs/guides/SECURITY_GUIDE.md#authentication-xsuaa).
|
|
91
|
+
|
|
92
|
+
## Services
|
|
93
|
+
|
|
94
|
+
| Service | Path | Purpose |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| CardanoODataService | `/odata/v4/cardano-odata/` | Read blockchain data (20 entities, 19 actions) |
|
|
97
|
+
| CardanoTransactionService | `/odata/v4/cardano-transaction/` | Build & submit transactions (13 actions) |
|
|
98
|
+
| CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
|
|
99
|
+
| CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (v2.0, off by default) |
|
|
100
|
+
| CardanoWorkerService | `/odata/v4/cardano-worker/` | Asynchronous wallet jobs (v2.0, off by default) |
|
|
101
|
+
|
|
102
|
+
Both v2.0 services also publish **CAP events**, so a consumer can subscribe instead of polling —
|
|
103
|
+
in-process, no broker required:
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
(await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
|
|
107
|
+
(await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Requirements
|
|
111
|
+
|
|
112
|
+
- **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
|
|
113
|
+
- Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds four tables (`CardanoSyncState`,
|
|
114
|
+
`CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`) plus a `dedupKey` column; without
|
|
115
|
+
the redeploy the new services answer `no such table` while the old ones keep working.
|
|
116
|
+
|
|
117
|
+
## Documentation
|
|
118
|
+
|
|
119
|
+
| Guide | Description |
|
|
120
|
+
|-------|-------------|
|
|
121
|
+
| [Quick Start](docs/QUICK_START.md) | Get running in 5 minutes |
|
|
122
|
+
| [User Guide](docs/guides/USER_GUIDE.md) | API usage, entities, and examples |
|
|
123
|
+
| [Developer Guide](docs/guides/DEVELOPER_GUIDE.md) | Architecture and development |
|
|
124
|
+
| [Transaction Workflow](docs/guides/TRANSACTION_WORKFLOW.md) | Build → Sign → Submit flow |
|
|
125
|
+
| [Security Guide](docs/guides/SECURITY_GUIDE.md) | Authentication, signing security, HSM |
|
|
126
|
+
| [Docker Deployment](docs/guides/DOCKER_DEPLOYMENT.md) | Container deployment |
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
Apache License 2.0 - see [LICENSE](LICENSE)
|
|
131
|
+
|
|
132
|
+
## Support
|
|
133
|
+
|
|
134
|
+
- **Issues**: [GitHub Issues](https://github.com/ODATANO/ODATANO/issues)
|
|
135
|
+
- **Project Lead**: Max Weber
|
|
136
|
+
- **Contact**: info@odatano.dev
|
package/package.json
CHANGED
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@odatano/core",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
4
|
-
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
|
-
"imports": {
|
|
6
|
-
"#cds-models/*": "./@cds-models/*/index.js"
|
|
7
|
-
},
|
|
8
|
-
"main": "src/index.js",
|
|
9
|
-
"types": "src/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"cds-plugin.js",
|
|
12
|
-
"src/**/*.js",
|
|
13
|
-
"src/**/*.d.ts",
|
|
14
|
-
"srv/**/*.js",
|
|
15
|
-
"srv/**/*.d.ts",
|
|
16
|
-
"srv/**/*.cds",
|
|
17
|
-
"db/**/*.cds",
|
|
18
|
-
"@cds-models/"
|
|
19
|
-
],
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=22.5"
|
|
22
|
-
},
|
|
23
|
-
"peerDependencies": {
|
|
24
|
-
"@sap/cds": ">=10"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@blockfrost/blockfrost-js": "~6.0.0",
|
|
28
|
-
"@cap-js/hana": "^3",
|
|
29
|
-
"@cardano-ogmios/client": "^6.14.0",
|
|
30
|
-
"@harmoniclabs/buildooor": "0.2.9",
|
|
31
|
-
"@harmoniclabs/cardano-costmodels-ts": "~1.6.1",
|
|
32
|
-
"@harmoniclabs/cardano-ledger-ts": "^0.5.6",
|
|
33
|
-
"@harmoniclabs/cbor": "^2.0.1",
|
|
34
|
-
"@harmoniclabs/crypto": "^0.3.0",
|
|
35
|
-
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
36
|
-
"@sap/xssec": "^4",
|
|
37
|
-
"axios": "^1.18.0",
|
|
38
|
-
"bech32": "^2.0.0",
|
|
39
|
-
"blake2b": "^2.1.4"
|
|
40
|
-
},
|
|
41
|
-
"optionalDependencies": {
|
|
42
|
-
"pkcs11js": "^2.1.6"
|
|
43
|
-
},
|
|
44
|
-
"overrides": {
|
|
45
|
-
"axios": "^1.18.0",
|
|
46
|
-
"esbuild": "0.28.1",
|
|
47
|
-
"form-data": "^4.0.6",
|
|
48
|
-
"fast-uri": "^3.1.5",
|
|
49
|
-
"ws": "7.5.11",
|
|
50
|
-
"@sap/approuter": {
|
|
51
|
-
"body-parser": "^2.2.3"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@cap-js/cds-test": "^0.4.1",
|
|
56
|
-
"@cap-js/cds-typer": "^0.40.0",
|
|
57
|
-
"@cap-js/cds-types": "^0.18.0",
|
|
58
|
-
"@cap-js/sqlite": "^3",
|
|
59
|
-
"@sap/cds": "^10",
|
|
60
|
-
"@sap/cds-dk": "^10",
|
|
61
|
-
"@sap/eslint-plugin-cds": "^4.2.4",
|
|
62
|
-
"@types/blake2b": "^2.1.3",
|
|
63
|
-
"@types/node": "^22.19.7",
|
|
64
|
-
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
65
|
-
"@typescript-eslint/parser": "^8.50.1",
|
|
66
|
-
"@vitest/coverage-v8": "^4.1.10",
|
|
67
|
-
"dotenv": "^16.3.1",
|
|
68
|
-
"eslint": "^9.39.2",
|
|
69
|
-
"nock": "^13.5.6",
|
|
70
|
-
"ts-node": "^10.9.2",
|
|
71
|
-
"tsx": "^4.21.0",
|
|
72
|
-
"typescript": "^5.9.3",
|
|
73
|
-
"vitest": "^4.1.10"
|
|
74
|
-
},
|
|
75
|
-
"cds": {
|
|
76
|
-
"typer": {
|
|
77
|
-
"ieee754compatible": true
|
|
78
|
-
},
|
|
79
|
-
"build": {
|
|
80
|
-
"tasks": [
|
|
81
|
-
{
|
|
82
|
-
"for": "node-cf",
|
|
83
|
-
"src": "srv",
|
|
84
|
-
"dest": "../gen/srv"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"for": "hana",
|
|
88
|
-
"src": "db",
|
|
89
|
-
"dest": "../gen/db"
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
},
|
|
93
|
-
"requires": {
|
|
94
|
-
"db": {
|
|
95
|
-
"kind": "sqlite",
|
|
96
|
-
"credentials": {
|
|
97
|
-
"url": "db.sqlite"
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
"[production]": {
|
|
101
|
-
"db": {
|
|
102
|
-
"kind": "hana",
|
|
103
|
-
"pool": {
|
|
104
|
-
"acquireTimeoutMillis": 30000,
|
|
105
|
-
"min": 0,
|
|
106
|
-
"max": 10
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
"auth": "xsuaa"
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
"scripts": {
|
|
114
|
-
"clean": "node -e \"const fs=require('fs');fs.globSync('{srv,db,src}/**/*.{js,js.map,d.ts,d.ts.map}').filter(f=>!f.includes('node_modules')).forEach(f=>fs.unlinkSync(f));console.log('Clean complete')\"",
|
|
115
|
-
"clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
|
|
116
|
-
"build": "npm run cds:types && tsc",
|
|
117
|
-
"build:plugin": "npm run cds:types && tsc -p tsconfig.build.json",
|
|
118
|
-
"build:package": "npm run clean && npm run clean:models && npm run build:plugin",
|
|
119
|
-
"prepare": "npm run build:package",
|
|
120
|
-
"start": "cds-serve",
|
|
121
|
-
"cds:watch": "cds watch",
|
|
122
|
-
"cds:serve": "cds serve --with-mocks",
|
|
123
|
-
"cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
|
|
124
|
-
"lint": "eslint .",
|
|
125
|
-
"typecheck": "tsc --noEmit",
|
|
126
|
-
"db:deploy": "cds deploy",
|
|
127
|
-
"pretest": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
128
|
-
"test": "vitest run",
|
|
129
|
-
"pretest:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
130
|
-
"test:coverage": "vitest run --coverage",
|
|
131
|
-
"pretest:ci": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
132
|
-
"test:ci": "vitest run --exclude \"**/core-ogmios.test.ts\"",
|
|
133
|
-
"pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
134
|
-
"test:ci:coverage": "vitest run --coverage --exclude \"**/core-ogmios.test.ts\"",
|
|
135
|
-
"pretest:integration": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
136
|
-
"test:integration": "vitest run --project integration",
|
|
137
|
-
"test:integration:blockfrost": "vitest run test/integration/core.blockfrost.test.ts",
|
|
138
|
-
"test:integration:koios": "vitest run test/integration/core.koios.test.ts",
|
|
139
|
-
"test:integration:ogmios": "vitest run test/integration/core-ogmios.test.ts",
|
|
140
|
-
"test:integration:both": "npm run test:integration:blockfrost && npm run test:integration:koios",
|
|
141
|
-
"pretest:unit": "npm run cds:types",
|
|
142
|
-
"test:unit": "vitest run --project unit",
|
|
143
|
-
"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"
|
|
145
|
-
},
|
|
146
|
-
"sapux": [
|
|
147
|
-
"app/odatano"
|
|
148
|
-
],
|
|
149
|
-
"directories": {
|
|
150
|
-
"doc": "docs",
|
|
151
|
-
"test": "test"
|
|
152
|
-
},
|
|
153
|
-
"repository": {
|
|
154
|
-
"type": "git",
|
|
155
|
-
"url": "git+https://github.com/ODATANO/ODATANO.git"
|
|
156
|
-
},
|
|
157
|
-
"keywords": [
|
|
158
|
-
"CAP",
|
|
159
|
-
"CDS",
|
|
160
|
-
"plugin",
|
|
161
|
-
"Cardano",
|
|
162
|
-
"blockchain",
|
|
163
|
-
"OData",
|
|
164
|
-
"SAP"
|
|
165
|
-
],
|
|
166
|
-
"author": "Maximilian Weber",
|
|
167
|
-
"license": "Apache-2.0",
|
|
168
|
-
"type": "commonjs",
|
|
169
|
-
"bugs": {
|
|
170
|
-
"url": "https://github.com/ODATANO/ODATANO/issues"
|
|
171
|
-
},
|
|
172
|
-
"homepage": "https://github.com/ODATANO/ODATANO#readme"
|
|
173
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@odatano/core",
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
|
+
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
|
+
"imports": {
|
|
6
|
+
"#cds-models/*": "./@cds-models/*/index.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "src/index.js",
|
|
9
|
+
"types": "src/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"cds-plugin.js",
|
|
12
|
+
"src/**/*.js",
|
|
13
|
+
"src/**/*.d.ts",
|
|
14
|
+
"srv/**/*.js",
|
|
15
|
+
"srv/**/*.d.ts",
|
|
16
|
+
"srv/**/*.cds",
|
|
17
|
+
"db/**/*.cds",
|
|
18
|
+
"@cds-models/"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.5"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@sap/cds": ">=10"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@blockfrost/blockfrost-js": "~6.0.0",
|
|
28
|
+
"@cap-js/hana": "^3",
|
|
29
|
+
"@cardano-ogmios/client": "^6.14.0",
|
|
30
|
+
"@harmoniclabs/buildooor": "0.2.9",
|
|
31
|
+
"@harmoniclabs/cardano-costmodels-ts": "~1.6.1",
|
|
32
|
+
"@harmoniclabs/cardano-ledger-ts": "^0.5.6",
|
|
33
|
+
"@harmoniclabs/cbor": "^2.0.1",
|
|
34
|
+
"@harmoniclabs/crypto": "^0.3.0",
|
|
35
|
+
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
36
|
+
"@sap/xssec": "^4",
|
|
37
|
+
"axios": "^1.18.0",
|
|
38
|
+
"bech32": "^2.0.0",
|
|
39
|
+
"blake2b": "^2.1.4"
|
|
40
|
+
},
|
|
41
|
+
"optionalDependencies": {
|
|
42
|
+
"pkcs11js": "^2.1.6"
|
|
43
|
+
},
|
|
44
|
+
"overrides": {
|
|
45
|
+
"axios": "^1.18.0",
|
|
46
|
+
"esbuild": "0.28.1",
|
|
47
|
+
"form-data": "^4.0.6",
|
|
48
|
+
"fast-uri": "^3.1.5",
|
|
49
|
+
"ws": "7.5.11",
|
|
50
|
+
"@sap/approuter": {
|
|
51
|
+
"body-parser": "^2.2.3"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@cap-js/cds-test": "^0.4.1",
|
|
56
|
+
"@cap-js/cds-typer": "^0.40.0",
|
|
57
|
+
"@cap-js/cds-types": "^0.18.0",
|
|
58
|
+
"@cap-js/sqlite": "^3",
|
|
59
|
+
"@sap/cds": "^10",
|
|
60
|
+
"@sap/cds-dk": "^10",
|
|
61
|
+
"@sap/eslint-plugin-cds": "^4.2.4",
|
|
62
|
+
"@types/blake2b": "^2.1.3",
|
|
63
|
+
"@types/node": "^22.19.7",
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
65
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
67
|
+
"dotenv": "^16.3.1",
|
|
68
|
+
"eslint": "^9.39.2",
|
|
69
|
+
"nock": "^13.5.6",
|
|
70
|
+
"ts-node": "^10.9.2",
|
|
71
|
+
"tsx": "^4.21.0",
|
|
72
|
+
"typescript": "^5.9.3",
|
|
73
|
+
"vitest": "^4.1.10"
|
|
74
|
+
},
|
|
75
|
+
"cds": {
|
|
76
|
+
"typer": {
|
|
77
|
+
"ieee754compatible": true
|
|
78
|
+
},
|
|
79
|
+
"build": {
|
|
80
|
+
"tasks": [
|
|
81
|
+
{
|
|
82
|
+
"for": "node-cf",
|
|
83
|
+
"src": "srv",
|
|
84
|
+
"dest": "../gen/srv"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"for": "hana",
|
|
88
|
+
"src": "db",
|
|
89
|
+
"dest": "../gen/db"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
"requires": {
|
|
94
|
+
"db": {
|
|
95
|
+
"kind": "sqlite",
|
|
96
|
+
"credentials": {
|
|
97
|
+
"url": "db.sqlite"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"[production]": {
|
|
101
|
+
"db": {
|
|
102
|
+
"kind": "hana",
|
|
103
|
+
"pool": {
|
|
104
|
+
"acquireTimeoutMillis": 30000,
|
|
105
|
+
"min": 0,
|
|
106
|
+
"max": 10
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"auth": "xsuaa"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"scripts": {
|
|
114
|
+
"clean": "node -e \"const fs=require('fs');fs.globSync('{srv,db,src}/**/*.{js,js.map,d.ts,d.ts.map}').filter(f=>!f.includes('node_modules')).forEach(f=>fs.unlinkSync(f));console.log('Clean complete')\"",
|
|
115
|
+
"clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
|
|
116
|
+
"build": "npm run cds:types && tsc",
|
|
117
|
+
"build:plugin": "npm run cds:types && tsc -p tsconfig.build.json",
|
|
118
|
+
"build:package": "npm run clean && npm run clean:models && npm run build:plugin",
|
|
119
|
+
"prepare": "npm run build:package",
|
|
120
|
+
"start": "cds-serve",
|
|
121
|
+
"cds:watch": "cds watch",
|
|
122
|
+
"cds:serve": "cds serve --with-mocks",
|
|
123
|
+
"cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
|
|
124
|
+
"lint": "eslint .",
|
|
125
|
+
"typecheck": "tsc --noEmit",
|
|
126
|
+
"db:deploy": "cds deploy",
|
|
127
|
+
"pretest": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
128
|
+
"test": "vitest run",
|
|
129
|
+
"pretest:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
130
|
+
"test:coverage": "vitest run --coverage",
|
|
131
|
+
"pretest:ci": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
132
|
+
"test:ci": "vitest run --exclude \"**/core-ogmios.test.ts\"",
|
|
133
|
+
"pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
134
|
+
"test:ci:coverage": "vitest run --coverage --exclude \"**/core-ogmios.test.ts\"",
|
|
135
|
+
"pretest:integration": "npm run clean && npm run cds:types && npm run db:deploy",
|
|
136
|
+
"test:integration": "vitest run --project integration",
|
|
137
|
+
"test:integration:blockfrost": "vitest run test/integration/core.blockfrost.test.ts",
|
|
138
|
+
"test:integration:koios": "vitest run test/integration/core.koios.test.ts",
|
|
139
|
+
"test:integration:ogmios": "vitest run test/integration/core-ogmios.test.ts",
|
|
140
|
+
"test:integration:both": "npm run test:integration:blockfrost && npm run test:integration:koios",
|
|
141
|
+
"pretest:unit": "npm run cds:types",
|
|
142
|
+
"test:unit": "vitest run --project unit",
|
|
143
|
+
"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"
|
|
145
|
+
},
|
|
146
|
+
"sapux": [
|
|
147
|
+
"app/odatano"
|
|
148
|
+
],
|
|
149
|
+
"directories": {
|
|
150
|
+
"doc": "docs",
|
|
151
|
+
"test": "test"
|
|
152
|
+
},
|
|
153
|
+
"repository": {
|
|
154
|
+
"type": "git",
|
|
155
|
+
"url": "git+https://github.com/ODATANO/ODATANO.git"
|
|
156
|
+
},
|
|
157
|
+
"keywords": [
|
|
158
|
+
"CAP",
|
|
159
|
+
"CDS",
|
|
160
|
+
"plugin",
|
|
161
|
+
"Cardano",
|
|
162
|
+
"blockchain",
|
|
163
|
+
"OData",
|
|
164
|
+
"SAP"
|
|
165
|
+
],
|
|
166
|
+
"author": "Maximilian Weber",
|
|
167
|
+
"license": "Apache-2.0",
|
|
168
|
+
"type": "commonjs",
|
|
169
|
+
"bugs": {
|
|
170
|
+
"url": "https://github.com/ODATANO/ODATANO/issues"
|
|
171
|
+
},
|
|
172
|
+
"homepage": "https://github.com/ODATANO/ODATANO#readme"
|
|
173
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
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
|
-
* service-level auth. pause/resume are operational actions — gate behind a dedicated
|
|
12
|
-
* Admin scope. Read-only status and audit data remain available to authenticated users.
|
|
13
|
-
*/
|
|
14
|
-
@requires: 'authenticated-user'
|
|
15
|
-
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
16
|
-
|
|
17
|
-
@readonly
|
|
18
|
-
@title : 'Sync State'
|
|
19
|
-
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
20
|
-
entity SyncState as projection on db.CardanoSyncState;
|
|
21
|
-
|
|
22
|
-
@readonly
|
|
23
|
-
@title : 'Reorg Log'
|
|
24
|
-
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
25
|
-
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
26
|
-
|
|
27
|
-
@title : 'Crawler Status'
|
|
28
|
-
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
29
|
-
type CrawlerStatus {
|
|
30
|
-
running : Boolean;
|
|
31
|
-
syncStatus : String;
|
|
32
|
-
lastSlot : String;
|
|
33
|
-
lastHeight : String;
|
|
34
|
-
tipHeight : String;
|
|
35
|
-
syncProgress : String;
|
|
36
|
-
consecutiveErrors : Integer;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@title : 'Get Crawler Status'
|
|
40
|
-
@description: 'Return the current crawler run state and sync progress'
|
|
41
|
-
/**
|
|
42
|
-
* Emitted AFTER each block is committed. Subscribe instead of polling:
|
|
43
|
-
* (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
44
|
-
* In-process (plugin mode) this needs no messaging service.
|
|
45
|
-
*/
|
|
46
|
-
event blockIndexed {
|
|
47
|
-
hash : String(64);
|
|
48
|
-
slot : Integer64;
|
|
49
|
-
height : Integer64;
|
|
50
|
-
txHashes : many String(64);
|
|
51
|
-
tipSlot : Integer64;
|
|
52
|
-
tipHeight: Integer64;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Emitted AFTER a rollback is committed. Everything above `forkSlot` was removed. */
|
|
56
|
-
event reorg {
|
|
57
|
-
forkSlot : Integer64;
|
|
58
|
-
forkHeight : Integer64;
|
|
59
|
-
blocksRolledBack : Integer;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function getStatus() returns CrawlerStatus;
|
|
63
|
-
|
|
64
|
-
@title : 'Pause Crawler'
|
|
65
|
-
@description: 'Stop the crawler (closes the chain-sync stream). Resume continues from the cursor.'
|
|
66
|
-
@requires : 'Admin'
|
|
67
|
-
action pauseCrawler() returns Boolean;
|
|
68
|
-
|
|
69
|
-
@title : 'Resume Crawler'
|
|
70
|
-
@description: 'Start/restart the crawler from the persisted cursor using the configured source.'
|
|
71
|
-
@requires : 'Admin'
|
|
72
|
-
action resumeCrawler() returns Boolean;
|
|
73
|
-
}
|
|
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
|
+
* service-level auth. pause/resume are operational actions — gate behind a dedicated
|
|
12
|
+
* Admin scope. Read-only status and audit data remain available to authenticated users.
|
|
13
|
+
*/
|
|
14
|
+
@requires: 'authenticated-user'
|
|
15
|
+
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
16
|
+
|
|
17
|
+
@readonly
|
|
18
|
+
@title : 'Sync State'
|
|
19
|
+
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
20
|
+
entity SyncState as projection on db.CardanoSyncState;
|
|
21
|
+
|
|
22
|
+
@readonly
|
|
23
|
+
@title : 'Reorg Log'
|
|
24
|
+
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
25
|
+
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
26
|
+
|
|
27
|
+
@title : 'Crawler Status'
|
|
28
|
+
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
29
|
+
type CrawlerStatus {
|
|
30
|
+
running : Boolean;
|
|
31
|
+
syncStatus : String;
|
|
32
|
+
lastSlot : String;
|
|
33
|
+
lastHeight : String;
|
|
34
|
+
tipHeight : String;
|
|
35
|
+
syncProgress : String;
|
|
36
|
+
consecutiveErrors : Integer;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@title : 'Get Crawler Status'
|
|
40
|
+
@description: 'Return the current crawler run state and sync progress'
|
|
41
|
+
/**
|
|
42
|
+
* Emitted AFTER each block is committed. Subscribe instead of polling:
|
|
43
|
+
* (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
44
|
+
* In-process (plugin mode) this needs no messaging service.
|
|
45
|
+
*/
|
|
46
|
+
event blockIndexed {
|
|
47
|
+
hash : String(64);
|
|
48
|
+
slot : Integer64;
|
|
49
|
+
height : Integer64;
|
|
50
|
+
txHashes : many String(64);
|
|
51
|
+
tipSlot : Integer64;
|
|
52
|
+
tipHeight: Integer64;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Emitted AFTER a rollback is committed. Everything above `forkSlot` was removed. */
|
|
56
|
+
event reorg {
|
|
57
|
+
forkSlot : Integer64;
|
|
58
|
+
forkHeight : Integer64;
|
|
59
|
+
blocksRolledBack : Integer;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getStatus() returns CrawlerStatus;
|
|
63
|
+
|
|
64
|
+
@title : 'Pause Crawler'
|
|
65
|
+
@description: 'Stop the crawler (closes the chain-sync stream). Resume continues from the cursor.'
|
|
66
|
+
@requires : 'Admin'
|
|
67
|
+
action pauseCrawler() returns Boolean;
|
|
68
|
+
|
|
69
|
+
@title : 'Resume Crawler'
|
|
70
|
+
@description: 'Start/restart the crawler from the persisted cursor using the configured source.'
|
|
71
|
+
@requires : 'Admin'
|
|
72
|
+
action resumeCrawler() returns Boolean;
|
|
73
|
+
}
|
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,18 @@ 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 }));
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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.
|
|
79
|
+
const indexed = existing ? undefined : await indexFn(db, key);
|
|
80
|
+
const result = await db.run(req.query);
|
|
81
|
+
// Safety net: if the freshly written slice is still outside the session's
|
|
82
|
+
// temporal window (widening had no effect, e.g. the transaction was already
|
|
83
|
+
// open), degrade to the pre-#13 behaviour — bare row instead of a wrong 404.
|
|
84
|
+
return result ?? indexed ?? existing;
|
|
35
85
|
}
|
|
36
86
|
return db.run(req.query);
|
|
37
87
|
});
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cardano Wallet Worker Service (v2.0)
|
|
5
|
-
*
|
|
6
|
-
* Control + observability surface for the wallet worker / job engine:
|
|
7
|
-
* - job submission (async build → sign → submit → confirm from server-side wallets)
|
|
8
|
-
* - job status polling + cancellation
|
|
9
|
-
* - read-only projections of jobs and registered worker wallets
|
|
10
|
-
* - pause/resume of the local worker instance (admin)
|
|
11
|
-
*
|
|
12
|
-
* Security note: SubmitWalletJob executes value transfers with server-held keys —
|
|
13
|
-
* the service requires authentication throughout; control actions and foreign-job
|
|
14
|
-
* visibility are gated behind the Admin role. Jobs on HSM-backed wallets addition-
|
|
15
|
-
* ally require the configured hsm.requiresRole (HSM_REQUIRES_ROLE), the same gate
|
|
16
|
-
* the synchronous SignWithHsm path enforces. Keys are NEVER accepted or exposed
|
|
17
|
-
* through this surface.
|
|
18
|
-
*/
|
|
19
|
-
@requires: 'authenticated-user'
|
|
20
|
-
service CardanoWorkerService @(impl: './cardano-worker-service') {
|
|
21
|
-
|
|
22
|
-
@readonly
|
|
23
|
-
@title : 'Wallet Jobs'
|
|
24
|
-
@description: 'Asynchronous wallet-worker jobs. Non-admin callers see their own jobs only.'
|
|
25
|
-
@restrict : [
|
|
26
|
-
{ grant: 'READ', to: 'Admin' },
|
|
27
|
-
{ grant: 'READ', where: 'createdBy = $user' }
|
|
28
|
-
]
|
|
29
|
-
// dedupKey is the internal backing column of the idempotency constraint.
|
|
30
|
-
entity WalletJobs as projection on db.CardanoWalletJobs excluding { dedupKey };
|
|
31
|
-
|
|
32
|
-
@readonly
|
|
33
|
-
@title : 'Worker Wallets'
|
|
34
|
-
@description: 'Registered server-side worker wallets (addresses and stats only — no key material, no lease internals)'
|
|
35
|
-
entity WorkerWallets as projection on db.CardanoWorkerWallets excluding { leaseOwner, leaseUntil };
|
|
36
|
-
|
|
37
|
-
@title : 'Wallet Job Submission Result'
|
|
38
|
-
type JobSubmissionResult {
|
|
39
|
-
jobId : UUID;
|
|
40
|
-
status : String(12);
|
|
41
|
-
deduplicated : Boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@title : 'Wallet Job Status'
|
|
45
|
-
type JobStatus {
|
|
46
|
-
jobId : UUID;
|
|
47
|
-
walletId : String(50);
|
|
48
|
-
kind : String(12);
|
|
49
|
-
status : String(12);
|
|
50
|
-
attempt : Integer;
|
|
51
|
-
txHash : String(64);
|
|
52
|
-
fee : String;
|
|
53
|
-
errorCode : String(50);
|
|
54
|
-
errorMessage : String(500);
|
|
55
|
-
submittedAt : Timestamp;
|
|
56
|
-
confirmedAt : Timestamp;
|
|
57
|
-
finishedAt : Timestamp;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@title : 'Worker Status'
|
|
61
|
-
type WorkerStatus {
|
|
62
|
-
running : Boolean;
|
|
63
|
-
wallets : many String;
|
|
64
|
-
executing : many String;
|
|
65
|
-
awaitingConfirmation : Integer;
|
|
66
|
-
pendingJobs : Integer;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Terminal job outcomes. Subscribing removes the need for a GetJobStatus poll loop:
|
|
71
|
-
* (await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
|
|
72
|
-
*/
|
|
73
|
-
event jobConfirmed {
|
|
74
|
-
jobId : UUID;
|
|
75
|
-
walletId : String(50);
|
|
76
|
-
kind : String(12);
|
|
77
|
-
txHash : String(64);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
event jobFailed {
|
|
81
|
-
jobId : UUID;
|
|
82
|
-
walletId : String(50);
|
|
83
|
-
kind : String(12);
|
|
84
|
-
txHash : String(64); // null when the job never reached the chain
|
|
85
|
-
errorCode : String(50);
|
|
86
|
-
errorMessage : String(500);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@title : 'Submit Wallet Job'
|
|
90
|
-
@description: 'Queue an asynchronous transaction job for a worker wallet. Returns immediately with a jobId; poll GetJobStatus for the outcome. The request JSON is the same payload shape as the corresponding Build* action; senderAddress is always overridden with the wallet address.'
|
|
91
|
-
action SubmitWalletJob(
|
|
92
|
-
@title: 'Wallet Id' walletId : String(50),
|
|
93
|
-
@title: 'Job Kind' kind : String(12),
|
|
94
|
-
@title: 'Request JSON' requestJson : LargeString,
|
|
95
|
-
@title: 'Idempotency Key' idempotencyKey : String(100),
|
|
96
|
-
@title: 'Priority' priority : Integer,
|
|
97
|
-
@title: 'Not Before' notBefore : Timestamp
|
|
98
|
-
) returns JobSubmissionResult;
|
|
99
|
-
|
|
100
|
-
@title : 'Cancel Job'
|
|
101
|
-
@description: 'Cancel a still-pending job. Jobs that started building may already reach the chain and cannot be cancelled.'
|
|
102
|
-
action CancelJob(
|
|
103
|
-
@title: 'Job Id' jobId : UUID
|
|
104
|
-
) returns Boolean;
|
|
105
|
-
|
|
106
|
-
@title : 'Get Job Status'
|
|
107
|
-
@description: 'Current lifecycle state of a wallet job (non-admins: own jobs only)'
|
|
108
|
-
function GetJobStatus(
|
|
109
|
-
@title: 'Job Id' jobId : UUID
|
|
110
|
-
) returns JobStatus;
|
|
111
|
-
|
|
112
|
-
@title : 'Get Worker Status'
|
|
113
|
-
@description: 'Live worker summary: running state, wallets, in-flight executions, confirmation backlog, queue depth'
|
|
114
|
-
function GetWorkerStatus() returns WorkerStatus;
|
|
115
|
-
|
|
116
|
-
@title : 'Pause Worker'
|
|
117
|
-
@description: 'Stop the local worker instance (finishes in-flight steps; queued jobs stay pending).'
|
|
118
|
-
@requires : 'Admin'
|
|
119
|
-
action PauseWorker() returns Boolean;
|
|
120
|
-
|
|
121
|
-
@title : 'Resume Worker'
|
|
122
|
-
@description: 'Start/restart the local worker instance using the configured wallets.'
|
|
123
|
-
@requires : 'Admin'
|
|
124
|
-
action ResumeWorker() returns Boolean;
|
|
125
|
-
}
|
|
1
|
+
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cardano Wallet Worker Service (v2.0)
|
|
5
|
+
*
|
|
6
|
+
* Control + observability surface for the wallet worker / job engine:
|
|
7
|
+
* - job submission (async build → sign → submit → confirm from server-side wallets)
|
|
8
|
+
* - job status polling + cancellation
|
|
9
|
+
* - read-only projections of jobs and registered worker wallets
|
|
10
|
+
* - pause/resume of the local worker instance (admin)
|
|
11
|
+
*
|
|
12
|
+
* Security note: SubmitWalletJob executes value transfers with server-held keys —
|
|
13
|
+
* the service requires authentication throughout; control actions and foreign-job
|
|
14
|
+
* visibility are gated behind the Admin role. Jobs on HSM-backed wallets addition-
|
|
15
|
+
* ally require the configured hsm.requiresRole (HSM_REQUIRES_ROLE), the same gate
|
|
16
|
+
* the synchronous SignWithHsm path enforces. Keys are NEVER accepted or exposed
|
|
17
|
+
* through this surface.
|
|
18
|
+
*/
|
|
19
|
+
@requires: 'authenticated-user'
|
|
20
|
+
service CardanoWorkerService @(impl: './cardano-worker-service') {
|
|
21
|
+
|
|
22
|
+
@readonly
|
|
23
|
+
@title : 'Wallet Jobs'
|
|
24
|
+
@description: 'Asynchronous wallet-worker jobs. Non-admin callers see their own jobs only.'
|
|
25
|
+
@restrict : [
|
|
26
|
+
{ grant: 'READ', to: 'Admin' },
|
|
27
|
+
{ grant: 'READ', where: 'createdBy = $user' }
|
|
28
|
+
]
|
|
29
|
+
// dedupKey is the internal backing column of the idempotency constraint.
|
|
30
|
+
entity WalletJobs as projection on db.CardanoWalletJobs excluding { dedupKey };
|
|
31
|
+
|
|
32
|
+
@readonly
|
|
33
|
+
@title : 'Worker Wallets'
|
|
34
|
+
@description: 'Registered server-side worker wallets (addresses and stats only — no key material, no lease internals)'
|
|
35
|
+
entity WorkerWallets as projection on db.CardanoWorkerWallets excluding { leaseOwner, leaseUntil };
|
|
36
|
+
|
|
37
|
+
@title : 'Wallet Job Submission Result'
|
|
38
|
+
type JobSubmissionResult {
|
|
39
|
+
jobId : UUID;
|
|
40
|
+
status : String(12);
|
|
41
|
+
deduplicated : Boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@title : 'Wallet Job Status'
|
|
45
|
+
type JobStatus {
|
|
46
|
+
jobId : UUID;
|
|
47
|
+
walletId : String(50);
|
|
48
|
+
kind : String(12);
|
|
49
|
+
status : String(12);
|
|
50
|
+
attempt : Integer;
|
|
51
|
+
txHash : String(64);
|
|
52
|
+
fee : String;
|
|
53
|
+
errorCode : String(50);
|
|
54
|
+
errorMessage : String(500);
|
|
55
|
+
submittedAt : Timestamp;
|
|
56
|
+
confirmedAt : Timestamp;
|
|
57
|
+
finishedAt : Timestamp;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@title : 'Worker Status'
|
|
61
|
+
type WorkerStatus {
|
|
62
|
+
running : Boolean;
|
|
63
|
+
wallets : many String;
|
|
64
|
+
executing : many String;
|
|
65
|
+
awaitingConfirmation : Integer;
|
|
66
|
+
pendingJobs : Integer;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Terminal job outcomes. Subscribing removes the need for a GetJobStatus poll loop:
|
|
71
|
+
* (await cds.connect.to('CardanoWorkerService')).on('jobConfirmed', ({ data }) => …)
|
|
72
|
+
*/
|
|
73
|
+
event jobConfirmed {
|
|
74
|
+
jobId : UUID;
|
|
75
|
+
walletId : String(50);
|
|
76
|
+
kind : String(12);
|
|
77
|
+
txHash : String(64);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
event jobFailed {
|
|
81
|
+
jobId : UUID;
|
|
82
|
+
walletId : String(50);
|
|
83
|
+
kind : String(12);
|
|
84
|
+
txHash : String(64); // null when the job never reached the chain
|
|
85
|
+
errorCode : String(50);
|
|
86
|
+
errorMessage : String(500);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@title : 'Submit Wallet Job'
|
|
90
|
+
@description: 'Queue an asynchronous transaction job for a worker wallet. Returns immediately with a jobId; poll GetJobStatus for the outcome. The request JSON is the same payload shape as the corresponding Build* action; senderAddress is always overridden with the wallet address.'
|
|
91
|
+
action SubmitWalletJob(
|
|
92
|
+
@title: 'Wallet Id' walletId : String(50),
|
|
93
|
+
@title: 'Job Kind' kind : String(12),
|
|
94
|
+
@title: 'Request JSON' requestJson : LargeString,
|
|
95
|
+
@title: 'Idempotency Key' idempotencyKey : String(100),
|
|
96
|
+
@title: 'Priority' priority : Integer,
|
|
97
|
+
@title: 'Not Before' notBefore : Timestamp
|
|
98
|
+
) returns JobSubmissionResult;
|
|
99
|
+
|
|
100
|
+
@title : 'Cancel Job'
|
|
101
|
+
@description: 'Cancel a still-pending job. Jobs that started building may already reach the chain and cannot be cancelled.'
|
|
102
|
+
action CancelJob(
|
|
103
|
+
@title: 'Job Id' jobId : UUID
|
|
104
|
+
) returns Boolean;
|
|
105
|
+
|
|
106
|
+
@title : 'Get Job Status'
|
|
107
|
+
@description: 'Current lifecycle state of a wallet job (non-admins: own jobs only)'
|
|
108
|
+
function GetJobStatus(
|
|
109
|
+
@title: 'Job Id' jobId : UUID
|
|
110
|
+
) returns JobStatus;
|
|
111
|
+
|
|
112
|
+
@title : 'Get Worker Status'
|
|
113
|
+
@description: 'Live worker summary: running state, wallets, in-flight executions, confirmation backlog, queue depth'
|
|
114
|
+
function GetWorkerStatus() returns WorkerStatus;
|
|
115
|
+
|
|
116
|
+
@title : 'Pause Worker'
|
|
117
|
+
@description: 'Stop the local worker instance (finishes in-flight steps; queued jobs stay pending).'
|
|
118
|
+
@requires : 'Admin'
|
|
119
|
+
action PauseWorker() returns Boolean;
|
|
120
|
+
|
|
121
|
+
@title : 'Resume Worker'
|
|
122
|
+
@description: 'Start/restart the local worker instance using the configured wallets.'
|
|
123
|
+
@requires : 'Admin'
|
|
124
|
+
action ResumeWorker() returns Boolean;
|
|
125
|
+
}
|
package/srv/server.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
@@ -578,7 +545,7 @@ async function redriveInterruptedSubmissionsIfConfigured() {
|
|
|
578
545
|
if (process_1.env.SKIP_AUTO_INIT === 'true' || !appContext)
|
|
579
546
|
return;
|
|
580
547
|
try {
|
|
581
|
-
const { redriveInterruptedSubmissions } =
|
|
548
|
+
const { redriveInterruptedSubmissions } = require('./blockchain/signing/submission-finalizer');
|
|
582
549
|
const attempted = await redriveInterruptedSubmissions();
|
|
583
550
|
if (attempted > 0)
|
|
584
551
|
logger.info(`Re-drove ${attempted} interrupted deferred submission(s)`);
|