@odatano/core 2.0.0-rc.49 → 2.0.0-rc.50

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.
Files changed (120) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +6 -12
  2. package/@cds-models/CardanoIndexerService/index.d.ts +200 -2
  3. package/@cds-models/CardanoIndexerService/index.js +24 -0
  4. package/@cds-models/CardanoODataService/index.d.ts +49 -6
  5. package/@cds-models/CardanoODataService/index.js +4 -0
  6. package/@cds-models/CardanoSignService/index.d.ts +3 -3
  7. package/@cds-models/CardanoWorkerService/index.d.ts +4 -3
  8. package/@cds-models/index.d.ts +9 -1
  9. package/@cds-models/index.js +2 -1
  10. package/@cds-models/odatano/cardano/index.d.ts +59 -5
  11. package/@cds-models/odatano/cardano/index.js +6 -0
  12. package/README.md +29 -17
  13. package/db/schema.cds +117 -24
  14. package/db/types.cds +8 -0
  15. package/package.json +17 -15
  16. package/scripts/migrate-schema.mjs +334 -0
  17. package/src/index.d.ts +7 -5
  18. package/src/index.js +12 -10
  19. package/src/plugin.js +6 -7
  20. package/srv/blockchain/backends/blockfrost-backend.js +9 -1
  21. package/srv/blockchain/backends/cardano-backend.d.ts +15 -0
  22. package/srv/blockchain/backends/cardano-backend.js +5 -0
  23. package/srv/blockchain/backends/koios-backend.js +16 -10
  24. package/srv/blockchain/backends/ogmios-backend.d.ts +9 -3
  25. package/srv/blockchain/backends/ogmios-backend.js +60 -18
  26. package/srv/blockchain/cardano-client.d.ts +5 -4
  27. package/srv/blockchain/cardano-client.js +46 -13
  28. package/srv/blockchain/cardano-indexer.d.ts +116 -9
  29. package/srv/blockchain/cardano-indexer.js +436 -189
  30. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  31. package/srv/blockchain/crawler/account-snapshots.js +153 -0
  32. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +23 -1
  33. package/srv/blockchain/crawler/asset-registry-backfill.js +91 -1
  34. package/srv/blockchain/crawler/certificate-backfill.d.ts +2 -0
  35. package/srv/blockchain/crawler/certificate-backfill.js +10 -3
  36. package/srv/blockchain/crawler/crawler.d.ts +15 -0
  37. package/srv/blockchain/crawler/crawler.js +68 -3
  38. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  39. package/srv/blockchain/crawler/input-asset-copies.js +171 -0
  40. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
  41. package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
  42. package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
  43. package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
  44. package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
  45. package/srv/blockchain/crawler/transaction-backfill.js +12 -8
  46. package/srv/blockchain/pool-metadata.d.ts +15 -0
  47. package/srv/blockchain/pool-metadata.js +132 -0
  48. package/srv/blockchain/signing/cose-verifier.d.ts +3 -1
  49. package/srv/blockchain/signing/cose-verifier.js +144 -56
  50. package/srv/blockchain/signing/hsm-signer.js +2 -1
  51. package/srv/blockchain/signing/submission-finalizer.d.ts +15 -4
  52. package/srv/blockchain/signing/submission-finalizer.js +201 -69
  53. package/srv/blockchain/stored-chain.js +1 -1
  54. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +1 -3
  55. package/srv/blockchain/transaction-building/buildooor-tx.js +34 -54
  56. package/srv/blockchain/transaction-presence.d.ts +5 -0
  57. package/srv/blockchain/transaction-presence.js +29 -0
  58. package/srv/blockchain/transaction-rows.js +1 -1
  59. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -1
  60. package/srv/blockchain/wallet-worker/build-request.js +25 -0
  61. package/srv/blockchain/wallet-worker/confirmation-tracker.js +1 -1
  62. package/srv/blockchain/wallet-worker/job-store.d.ts +17 -7
  63. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  64. package/srv/blockchain/wallet-worker/signers.d.ts +2 -0
  65. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +2 -0
  66. package/srv/blockchain/wallet-worker/wallet-worker.js +42 -32
  67. package/srv/cardano-agent-service.cds +11 -12
  68. package/srv/cardano-agent-service.js +2 -0
  69. package/srv/cardano-backend-service.cds +34 -1
  70. package/srv/cardano-backend-service.js +20 -17
  71. package/srv/cardano-indexer-service.cds +153 -12
  72. package/srv/cardano-indexer-service.js +175 -29
  73. package/srv/cardano-service.cds +67 -3
  74. package/srv/cardano-service.js +132 -67
  75. package/srv/cardano-sign-service.cds +30 -20
  76. package/srv/cardano-sign-service.js +13 -10
  77. package/srv/cardano-tx-service.cds +15 -1
  78. package/srv/cardano-tx-service.js +4 -1
  79. package/srv/cardano-worker-service.cds +16 -7
  80. package/srv/cardano-worker-service.js +31 -22
  81. package/srv/cbor/parse.js +11 -34
  82. package/srv/config.d.ts +113 -0
  83. package/srv/config.js +409 -0
  84. package/srv/server.d.ts +9 -14
  85. package/srv/server.js +32 -316
  86. package/srv/utils/agent-access.d.ts +9 -0
  87. package/srv/utils/agent-access.js +67 -0
  88. package/srv/utils/agent-grants-config.d.ts +0 -17
  89. package/srv/utils/agent-grants-config.js +6 -81
  90. package/srv/utils/agent-grants.d.ts +6 -19
  91. package/srv/utils/agent-grants.js +69 -130
  92. package/srv/utils/const.d.ts +4 -0
  93. package/srv/utils/const.js +5 -1
  94. package/srv/utils/db-indexes.js +11 -3
  95. package/srv/utils/error-codes.d.ts +4 -0
  96. package/srv/utils/error-codes.js +4 -0
  97. package/srv/utils/errors.d.ts +6 -0
  98. package/srv/utils/errors.js +23 -1
  99. package/srv/utils/liveness.js +2 -5
  100. package/srv/utils/mappers.d.ts +5 -7
  101. package/srv/utils/mappers.js +22 -9
  102. package/srv/utils/pg-order-nulls.js +4 -3
  103. package/srv/utils/readiness.d.ts +12 -0
  104. package/srv/utils/readiness.js +29 -0
  105. package/srv/utils/result-numbers.d.ts +15 -0
  106. package/srv/utils/result-numbers.js +61 -0
  107. package/srv/utils/tx-request-parsers.d.ts +1 -1
  108. package/srv/utils/tx-request-parsers.js +3 -3
  109. package/srv/utils/tx-utils.d.ts +3 -0
  110. package/srv/utils/tx-utils.js +17 -3
  111. package/srv/utils/types.d.ts +16 -3
  112. package/scripts/migrate-txseq.mjs +0 -138
  113. package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -13
  114. package/srv/blockchain/transaction-building/buildooor-fee-patch.js +0 -71
  115. package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -15
  116. package/srv/blockchain/transaction-building/caller-datums.js +0 -133
  117. package/srv/cbor/redeemer-tag-patch.d.ts +0 -3
  118. package/srv/cbor/redeemer-tag-patch.js +0 -61
  119. package/srv/utils/legacy-service-paths.d.ts +0 -11
  120. package/srv/utils/legacy-service-paths.js +0 -58
@@ -32,7 +32,7 @@ export class NetworkInformation_ extends Array<NetworkInformation> {
32
32
  export declare function _BlockAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
33
33
  new (...args: any[]): {
34
34
  hash?: __.Key<string>
35
- time?: string | null
35
+ time?: __.CdsTimestamp | null
36
36
  height?: number | null
37
37
  slotLeader?: string | null
38
38
  epochNumber?: number | null
@@ -98,6 +98,12 @@ export declare function _PoolAspect<TBase extends new (...args: any[]) => object
98
98
  margin?: (number | string) | null
99
99
  fixedCost?: _.Lovelace | null
100
100
  rewardAccount?: string | null
101
+ metadataUrl?: string | null
102
+ metadataHash?: _.Blake2b256 | null
103
+ name?: string | null
104
+ ticker?: string | null
105
+ homepage?: string | null
106
+ description?: string | null
101
107
  } & InstanceType<ReturnType<typeof _._temporalAspect<TBase>>>
102
108
  readonly kind: 'entity';
103
109
  readonly keys: __.KeysOf<Pool>;
@@ -188,6 +194,8 @@ export declare function _EpochLedgerSnapshotAspect<TBase extends new (...args: a
188
194
  drepCount?: number | null
189
195
  drepAbstainStake?: _.Lovelace | null
190
196
  drepNoConfidenceStake?: _.Lovelace | null
197
+ accountCount?: number | null
198
+ accountSnapshotSlot?: number | null
191
199
  } & InstanceType<TBase>
192
200
  readonly kind: 'entity';
193
201
  readonly keys: __.KeysOf<EpochLedgerSnapshot>;
@@ -200,6 +208,28 @@ export class EpochLedgerSnapshots extends Array<EpochLedgerSnapshot> {
200
208
  $count?: number
201
209
  }
202
210
 
211
+ // entity 'AccountEpochSnapshot'
212
+ export declare function _AccountEpochSnapshotAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
213
+ new (...args: any[]): {
214
+ stakeAddress?: __.Key<_.Bech32>
215
+ epoch?: __.Key<number>
216
+ withdrawableAmount?: _.Lovelace | null
217
+ creditedAmount?: _.Lovelace | null
218
+ deposit?: _.Lovelace | null
219
+ poolId?: _.Bech32 | null
220
+ drepId?: _.Bech32 | null
221
+ } & InstanceType<TBase>
222
+ readonly kind: 'entity';
223
+ readonly keys: __.KeysOf<AccountEpochSnapshot>;
224
+ readonly elements: __.ElementsOf<AccountEpochSnapshot>;
225
+ readonly actions: globalThis.Record<never, never>;
226
+ };
227
+ export class AccountEpochSnapshot extends _AccountEpochSnapshotAspect(__.Entity) {
228
+ }
229
+ export class AccountEpochSnapshots extends Array<AccountEpochSnapshot> {
230
+ $count?: number
231
+ }
232
+
203
233
  // entity 'Asset'
204
234
  export declare function _AssetAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
205
235
  new (...args: any[]): {
@@ -473,9 +503,10 @@ export declare function _TransactionInputAspect<TBase extends new (...args: any[
473
503
  utxoData_paymentCredential?: string | null
474
504
  spentTxHash?: _.Blake2b256 | null
475
505
  spentOutputIndex?: number | null
506
+ spentTxSeq?: number | null
476
507
  isCollateral?: boolean | null
477
508
  isReference?: boolean | null
478
- assets?: __.Composition.of.many<TransactionInputAssets>
509
+ assets?: __.Association.to.many<TransactionInputAssets>
479
510
  hasAddresses?: boolean | null
480
511
  hasAssets?: boolean | null
481
512
  } & InstanceType<TBase>
@@ -490,10 +521,33 @@ export class TransactionInputs extends Array<TransactionInput> {
490
521
  $count?: number
491
522
  }
492
523
 
524
+ // entity 'TransactionInputAssetCopy'
525
+ export declare function _TransactionInputAssetCopyAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
526
+ new (...args: any[]): {
527
+ input?: __.Key<__.Association.to<TransactionInput>>
528
+ input_txSeq?: __.Key<number>
529
+ input_inputIndex?: __.Key<number>
530
+ unit?: __.Key<_.AssetUnit>
531
+ asset_quantity?: _.Lovelace | null
532
+ asset_policyId?: _.Blake2b224 | null
533
+ asset_assetNameHex?: _.HexBytes | null
534
+ asset_assetName?: string | null
535
+ asset_fingerprint?: string | null
536
+ } & InstanceType<TBase>
537
+ readonly kind: 'entity';
538
+ readonly keys: __.KeysOf<TransactionInputAssetCopy>;
539
+ readonly elements: __.ElementsOf<TransactionInputAssetCopy>;
540
+ readonly actions: globalThis.Record<never, never>;
541
+ };
542
+ export class TransactionInputAssetCopy extends _TransactionInputAssetCopyAspect(__.Entity) {
543
+ }
544
+ export class TransactionInputAssetCopies extends Array<TransactionInputAssetCopy> {
545
+ $count?: number
546
+ }
547
+
493
548
  // entity 'TransactionInputAsset'
494
549
  export declare function _TransactionInputAssetAspect<TBase extends new (...args: any[]) => object>(Base: TBase): {
495
550
  new (...args: any[]): {
496
- input?: __.Key<__.Association.to<TransactionInput>>
497
551
  input_txSeq?: __.Key<number>
498
552
  input_inputIndex?: __.Key<number>
499
553
  unit?: __.Key<_.AssetUnit>
@@ -789,6 +843,7 @@ export declare function _TransactionMetadataAspect<TBase extends new (...args: a
789
843
  tx_hash?: __.Key<_.Blake2b256>
790
844
  label?: _.MetadataLabel | null
791
845
  payload?: string | null
846
+ txSeq?: number | null
792
847
  } & InstanceType<TBase>
793
848
  readonly kind: 'entity';
794
849
  readonly keys: __.KeysOf<TransactionMetadata>;
@@ -1251,6 +1306,7 @@ export declare function _CardanoWorkerWalletAspect<TBase extends new (...args: a
1251
1306
  signerType?: _.WorkerSignerType | null
1252
1307
  address?: _.Bech32 | null
1253
1308
  publicKeyHash?: _.Blake2b224 | null
1309
+ requiresRole?: string | null
1254
1310
  enabled?: boolean | null
1255
1311
  leaseOwner?: string | null
1256
1312
  leaseUntil?: __.CdsTimestamp | null
@@ -1316,8 +1372,6 @@ export declare function _CardanoAgentGrantAspect<TBase extends new (...args: any
1316
1372
  agentLabel?: string | null
1317
1373
  tokenHash?: string
1318
1374
  allowedActions?: string
1319
- walletId?: string | null
1320
- allowedJobKinds?: string | null
1321
1375
  maxJobsPerDay?: number | null
1322
1376
  jobsUsedToday?: number | null
1323
1377
  budgetWindow?: string | null
@@ -21,6 +21,9 @@ module.exports.DrepEpochSnapshots = createEntityProxy(['odatano.cardano', 'DrepE
21
21
  // EpochLedgerSnapshots
22
22
  module.exports.EpochLedgerSnapshot = createEntityProxy(['odatano.cardano', 'EpochLedgerSnapshots'], { target: { is_singular: true } })
23
23
  module.exports.EpochLedgerSnapshots = createEntityProxy(['odatano.cardano', 'EpochLedgerSnapshots'], { target: { is_singular: false }})
24
+ // AccountEpochSnapshots
25
+ module.exports.AccountEpochSnapshot = createEntityProxy(['odatano.cardano', 'AccountEpochSnapshots'], { target: { is_singular: true } })
26
+ module.exports.AccountEpochSnapshots = createEntityProxy(['odatano.cardano', 'AccountEpochSnapshots'], { target: { is_singular: false }})
24
27
  // Assets
25
28
  module.exports.Asset = createEntityProxy(['odatano.cardano', 'Assets'], { target: { is_singular: true } })
26
29
  module.exports.Assets = createEntityProxy(['odatano.cardano', 'Assets'], { target: { is_singular: false }})
@@ -51,6 +54,9 @@ module.exports.Transactions = createEntityProxy(['odatano.cardano', 'Transaction
51
54
  // TransactionInputs
52
55
  module.exports.TransactionInput = createEntityProxy(['odatano.cardano', 'TransactionInputs'], { target: { is_singular: true } })
53
56
  module.exports.TransactionInputs = createEntityProxy(['odatano.cardano', 'TransactionInputs'], { target: { is_singular: false }})
57
+ // TransactionInputAssetCopies
58
+ module.exports.TransactionInputAssetCopy = createEntityProxy(['odatano.cardano', 'TransactionInputAssetCopies'], { target: { is_singular: true } })
59
+ module.exports.TransactionInputAssetCopies = createEntityProxy(['odatano.cardano', 'TransactionInputAssetCopies'], { target: { is_singular: false }})
54
60
  // TransactionInputAssets
55
61
  module.exports.TransactionInputAsset = createEntityProxy(['odatano.cardano', 'TransactionInputAssets'], { target: { is_singular: true } })
56
62
  module.exports.TransactionInputAssets = createEntityProxy(['odatano.cardano', 'TransactionInputAssets'], { target: { is_singular: false }})
package/README.md CHANGED
@@ -33,6 +33,7 @@ npm install @odatano/core @cap-js/sqlite
33
33
  "cds": {
34
34
  "requires": {
35
35
  "db": { "kind": "sqlite" },
36
+ "auth": { "users": { "alice": { "roles": ["Read", "Transact", "Sign"] } } },
36
37
  "odatano-core": {
37
38
  "network": "preview",
38
39
  "backends": ["koios"]
@@ -42,6 +43,9 @@ npm install @odatano/core @cap-js/sqlite
42
43
  }
43
44
  ```
44
45
 
46
+ The services ask for the roles `Read`, `Transact` and `Sign` (`Admin` for operator actions). The `auth`
47
+ entry gives them to CAP's development user `alice`; in production your own authentication assigns them.
48
+
45
49
  ```bash
46
50
  cds deploy --to sqlite
47
51
  cds serve
@@ -90,11 +94,11 @@ Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/Q
90
94
 
91
95
  ## Dev Mode: Mocked Authentication
92
96
 
93
- > **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.
97
+ > **Heads-up.** `cds serve` uses CAP's mocked auth: any Basic-Auth header logs in as the named mock user and passwords are not checked. This repository gives `alice` and `bob` the roles `Read`, `Transact` and `Sign`, `carol` only `Read`, and `admin` all four (`.cdsrc.json`); any other name is logged in without a role and gets 403. Anonymous requests get 401, but anyone reaching the port can authenticate.
94
98
  >
95
99
  > 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).
96
100
  >
97
- > The Docker image runs `NODE_ENV=production` with HTTP basic auth via `@odatano/cap-auth` (`ODATANO_HTTP_PASSWORD` required, user `ODATANO_HTTP_USER` default `odatano`, roles `ODATANO_HTTP_ROLES` default `Admin`; 20 failed attempts per 15 min per client address and user, then 429). `ODATANO_AUTH=dummy` disables authentication for local testing only. `getLiveness()` and `VerifyDataSignature` stay anonymous.
101
+ > The Docker image runs `NODE_ENV=production` with HTTP basic auth via `@odatano/cap-auth` (`ODATANO_HTTP_PASSWORD` required, user `ODATANO_HTTP_USER` default `odatano`, roles `ODATANO_HTTP_ROLES` default `Read,Transact,Sign,Admin`; 20 failed attempts per 15 min per client address and user, then 429). `ODATANO_AUTH=dummy` disables authentication for local testing only. `getLiveness()` and `VerifyDataSignature` stay anonymous.
98
102
  >
99
103
  > Database of the image: `ODATANO_DB_URL=postgres://user:pw@host:5432/db` selects PostgreSQL (schema deployed on every boot); otherwise SQLite at `ODATANO_DB_PATH` (default `/data/db.sqlite`). `docker compose run --rm --no-deps odatano migrate --from /data/db.sqlite` copies an existing SQLite file into a freshly deployed PostgreSQL.
100
104
 
@@ -102,14 +106,15 @@ Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/Q
102
106
 
103
107
  | Service | Path | Purpose |
104
108
  |---|---|---|
105
- | CardanoODataService | `/odata/v4/cardano/` | Read blockchain data (32 entities, 21 actions) |
109
+ | CardanoODataService | `/odata/v4/cardano/` | Read blockchain data (33 entities, 22 actions) |
106
110
  | CardanoTransactionService | `/odata/v4/cardano-transaction/` | Build & submit transactions (14 actions) |
107
111
  | CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
108
112
  | CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (off by default) |
109
113
  | CardanoWorkerService | `/odata/v4/cardano-worker/` | Asynchronous wallet jobs (off by default) |
114
+ | CardanoBackendService | `/odata/v4/cardano-backend/` | Chain data in provider shape for another ODATANO that uses this one as its `odatano` backend |
110
115
  | CardanoAgentService | `/odata/v4/cardano-agent/` | Agent grants: scoped bearer tokens for agents (off by default) |
111
116
 
112
- Both services also publish **CAP events**, so a consumer can subscribe instead of polling —
117
+ The indexer and the worker service also publish **CAP events**, so a consumer can subscribe instead of polling —
113
118
  in-process, no broker required:
114
119
 
115
120
  ```js
@@ -126,48 +131,54 @@ AGENT_GRANTS_ENABLED=true # or cds.requires.odatano-core.agentGrants.
126
131
  AGENT_GRANTS_DELEGATE=mocked # CAP auth kind that keeps authenticating non-token requests (default: configured kind)
127
132
  AGENT_GRANT_ADMIN_RATE_LIMIT=10 # grant administration calls per principal per hour (or agentGrants.adminRateLimit)
128
133
  AGENT_TOKEN_CACHE_MS=10000 # a resolved token is reused this long before the row is read again; 0 = off (or agentGrants.tokenCacheMs)
134
+ AGENT_GRANT_USAGE_RETENTION_DAYS=400 # usage counters older than this are deleted once a day; 0 = keep all (or agentGrants.usageRetentionDays)
129
135
  ```
130
136
 
131
137
  1. An **Admin** issues a grant (`POST /odata/v4/cardano-agent/CreateAgentGrant`): an allow list of
132
- actions, optionally a worker `walletId` (required for `SubmitWalletJob`/`CancelJob`), allowed job
133
- kinds, a daily budget and an expiry. The response carries the token `odat_…` **once**; the
138
+ actions, a daily budget and an expiry. The response carries the token `odat_…` **once**; the
134
139
  server stores only its SHA-256.
135
- 2. The agent sends `x-agent-token: odat_…` on any of the six service paths. It runs as the principal
140
+ 2. The agent sends `x-agent-token: odat_…` on the service paths. It runs as the principal
136
141
  `agent:<grantId>` with the single role `agent-grant`, never as the operator: every
137
142
  `@requires: 'Admin'` surface (pause/resume, HSM signing, grant administration) refuses it by
138
143
  construction. Reads and compute-only actions are always allowed; allow-listed actions each cost
139
144
  one budget unit per UTC day (a build is the service an agent buys); everything else is 403.
140
- Wallet jobs are pinned to the grant's wallet and visible only to the grant that queued them.
145
+ An agent signs its transactions itself: the wallet worker, which signs with server-held keys,
146
+ answers every token request with 403.
141
147
  3. `GET /odata/v4/cardano-agent/GetGrantStatus()` tells the agent what it may do and how much budget
142
148
  is left; `RevokeAgentGrant` turns the token into an unknown token immediately.
143
149
  4. Lifecycle (Admin; the same semantics as the gateway's peer services, so one client drives
144
- them all): `UpdateAgentGrant` changes label, allow list, job kinds, daily budget or expiry
145
- (absent = untouched, explicit `null` = cleared; the wallet binding is immutable, 409
146
- `GRANT_REVOKED` on a revoked grant); `RotateAgentGrantToken` returns a fresh token once, the old
150
+ them all): `UpdateAgentGrant` changes label, allow list, daily budget or expiry
151
+ (absent = untouched, explicit `null` = cleared; 409 `GRANT_REVOKED` on a revoked grant); `RotateAgentGrantToken` returns a fresh token once, the old
147
152
  one is unknown from the next request; `GetGrantUsage(grantId, since, until)` lists admitted calls
148
153
  per service and action over up to 366 days (an Admin for any grant, a token for its own). All
149
154
  administration calls share the per-principal hourly rate limit above.
150
155
 
151
- Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `Submit*`,
152
- `CheckSubmissionStatus`, `SubmitWalletJob`, `CancelJob`. Never: `SignWithHsm*`, `Pause*`/`Resume*`,
153
- `pauseCrawler`/`resumeCrawler`, grant administration.
156
+ Grantable: `Build*`, `SetCollateral`, `CreateSigningRequest`, `VerifySignature`, `SubmitTransaction`,
157
+ `SubmitSignedTransaction`, `SubmitVerifiedTransaction`, `CheckSubmissionStatus`. Never: `SignWithHsm*`,
158
+ `SubmitWalletJob`, `CancelJob`, `Pause*`/`Resume*`, `pauseCrawler`/`resumeCrawler`, grant administration.
154
159
 
155
160
  Programmatic seams for other packages (`@odatano/x402` sells grants against a 402 payment):
156
161
  `issueAgentGrant()`, `updateAgentGrant()`, `rotateAgentGrantToken()`, `revokeAgentGrantById()`,
157
162
  `getGrantUsage()`, `registerTransportLane()` from `@odatano/core`.
158
163
 
159
- ## Liveness probe
164
+ ## Liveness and readiness probes
160
165
 
161
166
  `GET /odata/v4/cardano-indexer/getLiveness()` answers `200 { status: "alive", timestamp, uptime,
162
167
  version, network }` **without credentials** (`@requires: 'any'`) as long as the process runs — no
163
168
  backend or DB probe, no secrets. The Docker `HEALTHCHECK`, compose and upstream probes use it
164
169
  instead of the service document, so a wrong operator password no longer reads as "ODATANO down".
165
- Readiness (crawler, worker, backends) stays authenticated: `getStatus()`, `GetWorkerStatus()`,
170
+
171
+ `GET /odata/v4/cardano-indexer/getReadiness()` answers, also without credentials, whether this
172
+ instance can serve requests: `200 { status: "ready", timestamp, context, database, hsm }`, or `503`
173
+ with the same body and `status: "not_ready"` while the app context, the database or a configured
174
+ HSM is missing (`hsm` is `null` without an HSM). Point a load balancer or an upstream gateway at it.
175
+
176
+ The state of crawler, worker and backends stays authenticated: `getStatus()`, `GetWorkerStatus()`,
166
177
  `GetNetworkInformation`.
167
178
 
168
179
  ## Requirements
169
180
 
170
- - **Node.js >= 22.5** and **@sap/cds >= 10** (peer dependency). CAP 9 hosts cannot load `@odatano/core@2`.
181
+ - **Node.js >= 22.5** and **@sap/cds 10** (peer dependency `^10`). CAP 9 hosts cannot load `@odatano/core@2`.
171
182
  - Upgrading a consumer from 1.x: run **`cds deploy`**. 2.0 adds six tables (`CardanoSyncState`,
172
183
  `CardanoReorgLog`, `CardanoWorkerWallets`, `CardanoWalletJobs`, `CardanoAgentGrants`,
173
184
  `CardanoAgentGrantUsage`) plus a `dedupKey` column; without the redeploy the new services answer
@@ -183,6 +194,7 @@ Readiness (crawler, worker, backends) stays authenticated: `getStatus()`, `GetWo
183
194
  | [Transaction Workflow](docs/guides/TRANSACTION_WORKFLOW.md) | Build → Sign → Submit flow |
184
195
  | [Security Guide](docs/guides/SECURITY_GUIDE.md) | Authentication, signing security, HSM |
185
196
  | [Docker Deployment](docs/guides/DOCKER_DEPLOYMENT.md) | Container deployment |
197
+ | [Upgrading to 2.0](docs/guides/UPGRADE_2.0.md) | What a 1.x deployment and its clients change |
186
198
 
187
199
  ## License
188
200
 
package/db/schema.cds CHANGED
@@ -1,5 +1,5 @@
1
1
  using {temporal, } from '@sap/cds/common';
2
- using {Lovelace, Blake2b224, Blake2b256, HexBytes, Bech32, AssetUnit, AssetSlice, AssetSumSlice, SigningStatus,SubmissionStatus, UTxODataSlice, MetadataLabel, CrawlSyncStatus, ReorgStatus, WalletJobStatus, WalletJobKind, WorkerSignerType} from '../db/types';
2
+ using {Lovelace, Blake2b224, Blake2b256, Bech32, AssetUnit, AssetSlice, AssetSumSlice, SigningStatus,SubmissionStatus, UTxODataSlice, MetadataLabel, CrawlSyncStatus, ReorgStatus, WalletJobStatus, WalletJobKind, WorkerSignerType} from '../db/types';
3
3
 
4
4
  namespace odatano.cardano;
5
5
 
@@ -54,8 +54,8 @@ entity Blocks {
54
54
  key hash : String(64);
55
55
 
56
56
  @title : 'Block Time'
57
- @description: 'Block time as ISO 8601 string'
58
- time : String;
57
+ @description: 'Block time'
58
+ time : Timestamp;
59
59
 
60
60
  @title : 'Block Height'
61
61
  @description: 'Block height as integer'
@@ -200,6 +200,30 @@ entity Pools : temporal {
200
200
  @title : 'Reward Account'
201
201
  @description: 'Pool reward account in bech32 format'
202
202
  rewardAccount : String;
203
+
204
+ @title : 'Metadata URL'
205
+ @description: 'URL of the pool metadata file as registered on chain. Null without one'
206
+ metadataUrl : String(128);
207
+
208
+ @title : 'Metadata Hash'
209
+ @description: 'blake2b-256 the registration names for the metadata file, as hex'
210
+ metadataHash : Blake2b256;
211
+
212
+ @title : 'Name'
213
+ @description: 'Pool name from the metadata file. Null while the file is unknown or failed its checks'
214
+ name : String(50);
215
+
216
+ @title : 'Ticker'
217
+ @description: 'Pool ticker from the metadata file, 3 to 5 characters'
218
+ ticker : String(5);
219
+
220
+ @title : 'Homepage'
221
+ @description: 'Pool homepage from the metadata file'
222
+ homepage : String(512);
223
+
224
+ @title : 'Description'
225
+ @description: 'Pool description from the metadata file'
226
+ description : String(255);
203
227
  }
204
228
 
205
229
  @title : 'Pool Epoch Snapshot Entity'
@@ -395,6 +419,47 @@ entity EpochLedgerSnapshots {
395
419
  @title : 'Always-No-Confidence Stake'
396
420
  @description: 'Stake delegated to the predefined always-no-confidence DRep; null when not reported'
397
421
  drepNoConfidenceStake : Lovelace;
422
+
423
+ @title : 'Account Count'
424
+ @description: 'Rows in AccountEpochSnapshots for the epoch; null when no account snapshot was taken'
425
+ accountCount : Integer;
426
+
427
+ @title : 'Account Snapshot Slot'
428
+ @description: 'Absolute slot of the block the account snapshot was read at'
429
+ accountSnapshotSlot : Integer64;
430
+ }
431
+
432
+ @title : 'Account Epoch Snapshot Entity'
433
+ @description: 'Reward accounts as the node reported them once per epoch (crawler.accountSnapshots, off by default). The node lists an account while it is delegated to a stake pool or a DRep, so an account without a row had no delegation at the snapshot block or is unknown to the crawl. The block is EpochLedgerSnapshots.accountSnapshotSlot of the epoch. Non-temporal.'
434
+ entity AccountEpochSnapshots {
435
+
436
+ @title : 'Stake Address (Key)'
437
+ @description: 'Reward account (bech32)'
438
+ key stakeAddress : Bech32;
439
+
440
+ @title : 'Epoch (Key)'
441
+ @description: 'Epoch the observation belongs to'
442
+ key epoch : Integer;
443
+
444
+ @title : 'Withdrawable Amount'
445
+ @description: 'Balance of the reward account at the snapshot block. Null for an account without a pool delegation: Ogmios 7.0 does not report that balance.'
446
+ withdrawableAmount : Lovelace;
447
+
448
+ @title : 'Credited Amount'
449
+ @description: 'What the ledger added to the reward account since the snapshot of the previous epoch: the balance difference plus the withdrawals in between. Staking rewards, and also treasury withdrawals and refunded proposal deposits. Null without a balance in this or the previous epoch, or without crawled withdrawals (crawler.certificates).'
450
+ creditedAmount : Lovelace;
451
+
452
+ @title : 'Deposit'
453
+ @description: 'Key deposit held for the registration'
454
+ deposit : Lovelace;
455
+
456
+ @title : 'Pool Id'
457
+ @description: 'Stake pool the account is delegated to (bech32); null without a pool delegation'
458
+ poolId : Bech32;
459
+
460
+ @title : 'DRep Id'
461
+ @description: 'DRep the account delegates its vote to (CIP-129 bech32); drep_always_abstain / drep_always_no_confidence for the predefined ones; null without a vote delegation'
462
+ drepId : Bech32;
398
463
  }
399
464
 
400
465
  @title : 'Asset Entity'
@@ -411,7 +476,7 @@ entity Assets : temporal {
411
476
 
412
477
  @title : 'Asset Name Hex'
413
478
  @description: 'Asset name as hex string (0-32 bytes / 0-64 hex chars)'
414
- assetNameHex : String(64); // 32-byte ledger cap = 64 hex (was HexBytes=String(5000))
479
+ assetNameHex : String(64); // 32-byte ledger cap = 64 hex
415
480
 
416
481
  @title : 'Asset Name'
417
482
  @description: 'Asset name as UTF-8 string when decodable'
@@ -758,7 +823,7 @@ entity Transactions {
758
823
  fee : Lovelace;
759
824
 
760
825
  @title : 'Transaction Deposit'
761
- @description: 'The deposit change in lovelace'
826
+ @description: 'Deposits locked minus deposits refunded, in lovelace. Null when the source could not tell: a transaction with certificates or proposals crawled over Ogmios whose spent inputs are not all indexed'
762
827
  deposit : Lovelace;
763
828
 
764
829
  @title : 'Transaction Size'
@@ -841,6 +906,10 @@ entity TransactionInputs {
841
906
  @description: 'Output index of the consumed UTxO within spentTxHash (outpoint). Null on rows indexed before the column existed.'
842
907
  spentOutputIndex : Integer;
843
908
 
909
+ @title : 'Spent Transaction Sequence'
910
+ @description: 'txSeq of the transaction that created the consumed UTxO. Set on an input that keeps no copy of its assets: it reads them from that output.'
911
+ spentTxSeq : Integer64;
912
+
844
913
  @title : 'Input Lovelace Amount'
845
914
  @description: 'The lovelace amount of the input utxo'
846
915
  isCollateral : Boolean;
@@ -850,9 +919,9 @@ entity TransactionInputs {
850
919
  isReference : Boolean;
851
920
 
852
921
  @title : 'Input Assets'
853
- @description: 'Composed assets associated with the input utxo'
854
- assets : Composition of many TransactionInputAssets
855
- on assets.input = $self;
922
+ @description: 'Assets of the input utxo'
923
+ assets : Association to many TransactionInputAssets
924
+ on assets.input_txSeq = txSeq and assets.input_inputIndex = inputIndex;
856
925
 
857
926
  @title : 'Input Has Addresses'
858
927
  @description: 'Indicates if input has associated addresses'
@@ -863,10 +932,10 @@ entity TransactionInputs {
863
932
  hasAssets : Boolean;
864
933
  }
865
934
 
866
- @title : 'Transaction Input Assets'
867
- @description: 'Projection for Transaction Input Assets'
935
+ @title : 'Transaction Input Asset Copies'
936
+ @description: 'Stored copy of the assets of an input. An input has either copies or TransactionInputs.spentTxSeq, which points at the output that holds them.'
868
937
  @readonly
869
- entity TransactionInputAssets {
938
+ entity TransactionInputAssetCopies {
870
939
 
871
940
  @title : 'Transaction Input (key)'
872
941
  @description: 'The associated transaction input'
@@ -881,6 +950,30 @@ entity TransactionInputAssets {
881
950
  asset : AssetSlice;
882
951
  }
883
952
 
953
+ // Assets of every input: its stored copy, or the assets of the output it points at.
954
+ // An input has one of the two, never both, so no asset shows twice.
955
+ @title : 'Transaction Input Assets'
956
+ @description: 'Assets of a transaction input'
957
+ @readonly
958
+ entity TransactionInputAssets as
959
+ select from TransactionInputAssetCopies as copy {
960
+ key copy.input.txSeq as input_txSeq,
961
+ key copy.input.inputIndex as input_inputIndex,
962
+ key copy.unit,
963
+ copy.asset
964
+ }
965
+ union all
966
+ select from TransactionInputs as spender
967
+ join TransactionOutputAssets as spent
968
+ on spent.output.txSeq = spender.spentTxSeq
969
+ and spent.output.outputIndex = spender.spentOutputIndex
970
+ {
971
+ spender.txSeq as input_txSeq,
972
+ spender.inputIndex as input_inputIndex,
973
+ spent.unit,
974
+ spent.asset
975
+ };
976
+
884
977
  // -----------------------------------------------------
885
978
  // Crawler-fed ledger state. Separate from the lazy Addresses tables, so their TTL logic stays untouched.
886
979
  // -----------------------------------------------------
@@ -1256,6 +1349,10 @@ entity TransactionMetadata {
1256
1349
  @title : 'Metadata Payload'
1257
1350
  @description: 'The metadata payload as JSON string'
1258
1351
  payload : LargeString;
1352
+
1353
+ @title : 'Chain Position'
1354
+ @description: 'txSeq of the transaction (slot * 65536 + txIndex), ascending along the chain. Null on rows written before the column existed and on rows read by hash alone.'
1355
+ txSeq : Integer64;
1259
1356
  }
1260
1357
 
1261
1358
  //-----------------------------------------------------
@@ -1829,7 +1926,7 @@ entity SigningRequests {
1829
1926
  expiresAt : Timestamp;
1830
1927
 
1831
1928
  @title : 'Signed At'
1832
- @description: 'Timestamp when the transaction was signed'
1929
+ @description: 'Timestamp when the signed transaction was claimed for submission'
1833
1930
  signedAt : Timestamp;
1834
1931
 
1835
1932
  @title : 'Submitted At'
@@ -1845,7 +1942,7 @@ entity SigningRequests {
1845
1942
  cip30TxCbor : LargeString;
1846
1943
 
1847
1944
  @title : 'Signed Transaction CBOR'
1848
- @description: 'The full signed transaction CBOR, persisted at claim time on the deferred-submit path so an interrupted submission can be re-driven after a restart (see SUBMIT_DETACH_DESIGN.md)'
1945
+ @description: 'The full signed transaction CBOR, stored when the request is claimed for submission, so an interrupted or unresolved submit can be resolved later'
1849
1946
  signedTxCbor : LargeString;
1850
1947
 
1851
1948
  @title : 'Signer Type'
@@ -1870,7 +1967,7 @@ entity SigningRequests {
1870
1967
  submission : Association to TransactionSubmissions;
1871
1968
 
1872
1969
  @title : 'Error Message'
1873
- @description: 'Error message if signing or verification failed'
1970
+ @description: 'Error message if signing, verification or the submit failed'
1874
1971
  errorMessage : LargeString;
1875
1972
  }
1876
1973
 
@@ -2083,6 +2180,10 @@ entity CardanoWorkerWallets {
2083
2180
  @description: 'Blake2b-224 hash of the wallet verification key'
2084
2181
  publicKeyHash : Blake2b224;
2085
2182
 
2183
+ @title : 'Required Role'
2184
+ @description: 'Role a caller needs to queue jobs for this wallet, from the wallet config; null = any authenticated user'
2185
+ requiresRole : String(100);
2186
+
2086
2187
  @title : 'Enabled'
2087
2188
  @description: 'Disabled wallets accept no new jobs and are skipped by the dispatch loop'
2088
2189
  enabled : Boolean default true;
@@ -2128,7 +2229,7 @@ entity CardanoWalletJobs {
2128
2229
  walletId : String(50);
2129
2230
 
2130
2231
  @title : 'Job Kind'
2131
- @description: 'Transaction kind (simpleAda | metadata | multiAsset | mint | plutusSpend | submitSigned)'
2232
+ @description: 'Transaction kind (simpleAda | metadata | multiAsset | mint | plutusSpend | payout | submitSigned)'
2132
2233
  kind : WalletJobKind;
2133
2234
 
2134
2235
  @title : 'Status'
@@ -2238,17 +2339,9 @@ entity CardanoAgentGrants {
2238
2339
  tokenHash : String(64) not null;
2239
2340
 
2240
2341
  @title : 'Allowed Actions'
2241
- @description: 'JSON array of allow-listed action names (builds, signing-request lifecycle, submits, wallet jobs)'
2342
+ @description: 'JSON array of allow-listed action names (builds, signing-request lifecycle, submits)'
2242
2343
  allowedActions : LargeString not null;
2243
2344
 
2244
- @title : 'Wallet Id'
2245
- @description: 'Worker wallet this grant is pinned to; required for SubmitWalletJob / CancelJob, injected into those requests'
2246
- walletId : String(50);
2247
-
2248
- @title : 'Allowed Job Kinds'
2249
- @description: 'JSON array of WalletJobKind values the grant may queue; null = every kind'
2250
- allowedJobKinds : LargeString;
2251
-
2252
2345
  @title : 'Max Jobs Per Day'
2253
2346
  @description: 'Daily budget of allow-listed action calls (UTC day); null = unlimited'
2254
2347
  maxJobsPerDay : Integer;
package/db/types.cds CHANGED
@@ -188,6 +188,7 @@ type WalletJobKind : String(12) enum {
188
188
  multiAsset = 'multiAsset'; // BuildMultiAssetTransaction payload
189
189
  mint = 'mint'; // BuildMintTransaction payload
190
190
  plutusSpend = 'plutusSpend'; // BuildPlutusSpendTransaction payload
191
+ payout = 'payout'; // several recipients in one transaction (outputsJson)
191
192
  submitSigned = 'submitSigned'; // externally signed CBOR, managed submit and confirm only
192
193
  }
193
194
 
@@ -215,6 +216,13 @@ type UtxoSetImportSource : String(12) enum {
215
216
  scripts = 'scripts';
216
217
  }
217
218
 
219
+ @title : 'Asset Registry Source'
220
+ @description: 'Enum type for where backfillAssetRegistry reads the token registry from'
221
+ type AssetRegistrySource : String(12) enum {
222
+ koios = 'koios';
223
+ file = 'file';
224
+ }
225
+
218
226
  // -----------------------------------------------------
219
227
  // Transaction confirmations (GetTransactionConfirmations action result)
220
228
  // -----------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "2.0.0-rc.49",
3
+ "version": "2.0.0-rc.50",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -16,27 +16,27 @@
16
16
  "srv/**/*.cds",
17
17
  "db/**/*.cds",
18
18
  "@cds-models/",
19
- "scripts/migrate-txseq.mjs",
19
+ "scripts/migrate-schema.mjs",
20
20
  "scripts/migrate-slot-leader.mjs"
21
21
  ],
22
22
  "engines": {
23
23
  "node": ">=22.5"
24
24
  },
25
25
  "peerDependencies": {
26
- "@sap/cds": ">=10"
26
+ "@sap/cds": "^10"
27
27
  },
28
28
  "dependencies": {
29
29
  "@blockfrost/blockfrost-js": "~6.2.0",
30
30
  "@cap-js/hana": "^3",
31
31
  "@cardano-ogmios/client": "^7.0.0",
32
- "@harmoniclabs/buildooor": "0.2.9",
33
- "@harmoniclabs/cardano-costmodels-ts": "~1.6.1",
34
- "@harmoniclabs/cardano-ledger-ts": "^0.5.6",
35
- "@harmoniclabs/cbor": "^2.0.1",
36
- "@harmoniclabs/crypto": "^0.3.0",
37
- "@harmoniclabs/plutus-data": "^2.0.1",
32
+ "@harmoniclabs/buildooor": "0.3.0",
33
+ "@harmoniclabs/cardano-costmodels-ts": "~1.7.0",
34
+ "@harmoniclabs/cardano-ledger-ts": "^0.6.1",
35
+ "@harmoniclabs/cbor": "^2.1.0",
36
+ "@harmoniclabs/crypto": "^0.3.2",
37
+ "@harmoniclabs/plutus-data": "^2.1.1",
38
38
  "@harmoniclabs/uint8array-utils": "^1.0.4",
39
- "@harmoniclabs/uplc": "^2.0.7",
39
+ "@harmoniclabs/uplc": "^2.0.8",
40
40
  "@odatano/cap-auth": "^0.1.0",
41
41
  "@sap/xssec": "^4",
42
42
  "axios": "^1.18.0",
@@ -145,15 +145,16 @@
145
145
  "lint": "eslint .",
146
146
  "typecheck": "tsc --noEmit",
147
147
  "db:deploy": "cds deploy",
148
- "pretest": "npm run clean && npm run cds:types && npm run db:deploy",
148
+ "db:fresh": "node -e \"for(const f of ['db.sqlite','db.sqlite-wal','db.sqlite-shm'])require('fs').rmSync(f,{force:true})\" && npm run db:deploy",
149
+ "pretest": "npm run clean && npm run cds:types && npm run db:fresh",
149
150
  "test": "vitest run",
150
- "pretest:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
151
+ "pretest:coverage": "npm run clean && npm run cds:types && npm run db:fresh",
151
152
  "test:coverage": "vitest run --coverage",
152
- "pretest:ci": "npm run clean && npm run cds:types && npm run db:deploy",
153
+ "pretest:ci": "npm run clean && npm run cds:types && npm run db:fresh",
153
154
  "test:ci": "vitest run --exclude \"**/core-ogmios.test.ts\"",
154
- "pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
155
+ "pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:fresh",
155
156
  "test:ci:coverage": "vitest run --coverage --exclude \"**/core-ogmios.test.ts\"",
156
- "pretest:integration": "npm run clean && npm run cds:types && npm run db:deploy",
157
+ "pretest:integration": "npm run clean && npm run cds:types && npm run db:fresh",
157
158
  "test:integration": "vitest run --project integration",
158
159
  "test:integration:blockfrost": "vitest run test/integration/core.blockfrost.test.ts",
159
160
  "test:integration:koios": "vitest run test/integration/core.koios.test.ts",
@@ -164,6 +165,7 @@
164
165
  "watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
165
166
  "watch-wallet": "cds watch --open wallet/webapp/index.html",
166
167
  "release:check": "node scripts/release-check.mjs",
168
+ "smoke:consumer": "node scripts/smoke-consumer.mjs",
167
169
  "prepublishOnly": "node scripts/publish-guard.mjs"
168
170
  },
169
171
  "sapux": [