@odatano/core 2.0.0-rc.21 → 2.0.0-rc.24

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 (45) hide show
  1. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  2. package/@cds-models/CardanoBackendService/index.js +40 -0
  3. package/@cds-models/CardanoIndexerService/index.d.ts +18 -0
  4. package/@cds-models/CardanoIndexerService/index.js +3 -0
  5. package/@cds-models/CardanoODataService/index.d.ts +37 -0
  6. package/@cds-models/CardanoODataService/index.js +3 -0
  7. package/@cds-models/odatano/cardano/index.d.ts +37 -0
  8. package/@cds-models/odatano/cardano/index.js +3 -0
  9. package/db/schema.cds +2226 -2133
  10. package/package.json +182 -181
  11. package/srv/blockchain/backends/cardano-backend.d.ts +23 -0
  12. package/srv/blockchain/backends/cardano-backend.js +5 -0
  13. package/srv/blockchain/backends/odatano-backend.d.ts +59 -0
  14. package/srv/blockchain/backends/odatano-backend.js +154 -0
  15. package/srv/blockchain/backends/ogmios-backend.d.ts +92 -9
  16. package/srv/blockchain/backends/ogmios-backend.js +164 -32
  17. package/srv/blockchain/cardano-client.d.ts +19 -5
  18. package/srv/blockchain/cardano-client.js +53 -12
  19. package/srv/blockchain/cardano-indexer.d.ts +100 -4
  20. package/srv/blockchain/cardano-indexer.js +466 -23
  21. package/srv/blockchain/cardano-tx-builder.js +2 -2
  22. package/srv/blockchain/crawler/crawler.d.ts +20 -5
  23. package/srv/blockchain/crawler/crawler.js +78 -15
  24. package/srv/blockchain/crawler/utxo-set-import.js +3 -0
  25. package/srv/blockchain/ledger-state.d.ts +6 -0
  26. package/srv/blockchain/ledger-state.js +29 -0
  27. package/srv/blockchain/stored-chain.d.ts +30 -0
  28. package/srv/blockchain/stored-chain.js +208 -0
  29. package/srv/cardano-backend-service.cds +52 -0
  30. package/srv/cardano-backend-service.d.ts +2 -0
  31. package/srv/cardano-backend-service.js +217 -0
  32. package/srv/cardano-indexer-service.cds +176 -164
  33. package/srv/cardano-indexer-service.js +30 -0
  34. package/srv/cardano-service.cds +6 -1
  35. package/srv/cardano-service.js +5 -2
  36. package/srv/server.js +19 -2
  37. package/srv/utils/agent-grants.js +7 -0
  38. package/srv/utils/const.d.ts +4 -0
  39. package/srv/utils/const.js +4 -3
  40. package/srv/utils/db-indexes.js +1 -0
  41. package/srv/utils/errors.d.ts +8 -0
  42. package/srv/utils/errors.js +14 -1
  43. package/srv/utils/mappers.d.ts +19 -2
  44. package/srv/utils/mappers.js +25 -7
  45. package/srv/utils/types.d.ts +8 -1
package/package.json CHANGED
@@ -1,181 +1,182 @@
1
- {
2
- "name": "@odatano/core",
3
- "version": "2.0.0-rc.21",
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
- "scripts/migrate-txseq.mjs",
20
- "scripts/migrate-slot-leader.mjs"
21
- ],
22
- "engines": {
23
- "node": ">=22.5"
24
- },
25
- "peerDependencies": {
26
- "@sap/cds": ">=10"
27
- },
28
- "dependencies": {
29
- "@blockfrost/blockfrost-js": "~6.0.0",
30
- "@cap-js/hana": "^3",
31
- "@cardano-ogmios/client": "^6.14.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/uint8array-utils": "^1.0.4",
38
- "@odatano/cap-auth": "^0.1.0",
39
- "@sap/xssec": "^4",
40
- "axios": "^1.18.0",
41
- "bech32": "^2.0.0",
42
- "blake2b": "^2.1.4"
43
- },
44
- "optionalDependencies": {
45
- "pkcs11js": "^2.1.6"
46
- },
47
- "overrides": {
48
- "axios": "^1.18.0",
49
- "esbuild": "0.28.1",
50
- "form-data": "^4.0.6",
51
- "fast-uri": "^3.1.7",
52
- "ws": "7.5.11",
53
- "@sap/approuter": {
54
- "body-parser": "^2.2.3"
55
- }
56
- },
57
- "devDependencies": {
58
- "@cap-js/cds-test": "^0.4.1",
59
- "@cap-js/cds-typer": "^0.40.0",
60
- "@cap-js/cds-types": "^0.18.0",
61
- "@cap-js/postgres": "^3.1.1",
62
- "@cap-js/sqlite": "^3",
63
- "@sap/cds": "^10",
64
- "@sap/cds-dk": "^10",
65
- "@sap/eslint-plugin-cds": "^4.2.4",
66
- "@types/blake2b": "^2.1.3",
67
- "@types/node": "^22.19.7",
68
- "@typescript-eslint/eslint-plugin": "^8.50.1",
69
- "@typescript-eslint/parser": "^8.50.1",
70
- "@vitest/coverage-v8": "^4.1.10",
71
- "dotenv": "^16.3.1",
72
- "eslint": "^9.39.2",
73
- "nock": "^13.5.6",
74
- "ts-node": "^10.9.2",
75
- "tsx": "^4.21.0",
76
- "typescript": "^5.9.3",
77
- "vitest": "^4.1.10"
78
- },
79
- "cds": {
80
- "typer": {
81
- "ieee754compatible": true
82
- },
83
- "build": {
84
- "tasks": [
85
- {
86
- "for": "node-cf",
87
- "src": "srv",
88
- "dest": "../gen/srv"
89
- },
90
- {
91
- "for": "hana",
92
- "src": "db",
93
- "dest": "../gen/db"
94
- }
95
- ]
96
- },
97
- "requires": {
98
- "db": {
99
- "kind": "sqlite",
100
- "credentials": {
101
- "url": "db.sqlite"
102
- },
103
- "client": {
104
- "timeout": 5000
105
- }
106
- },
107
- "[production]": {
108
- "db": {
109
- "kind": "hana",
110
- "pool": {
111
- "acquireTimeoutMillis": 30000,
112
- "min": 0,
113
- "max": 10
114
- }
115
- },
116
- "auth": "xsuaa"
117
- }
118
- }
119
- },
120
- "scripts": {
121
- "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')\"",
122
- "clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
123
- "build": "npm run cds:types && tsc",
124
- "build:plugin": "npm run cds:types && tsc -p tsconfig.build.json",
125
- "build:package": "npm run clean && npm run clean:models && npm run build:plugin",
126
- "prepare": "npm run build:package",
127
- "start": "cds-serve",
128
- "cds:watch": "cds watch",
129
- "cds:serve": "cds serve --with-mocks",
130
- "cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
131
- "lint": "eslint .",
132
- "typecheck": "tsc --noEmit",
133
- "db:deploy": "cds deploy",
134
- "pretest": "npm run clean && npm run cds:types && npm run db:deploy",
135
- "test": "vitest run",
136
- "pretest:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
137
- "test:coverage": "vitest run --coverage",
138
- "pretest:ci": "npm run clean && npm run cds:types && npm run db:deploy",
139
- "test:ci": "vitest run --exclude \"**/core-ogmios.test.ts\"",
140
- "pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
141
- "test:ci:coverage": "vitest run --coverage --exclude \"**/core-ogmios.test.ts\"",
142
- "pretest:integration": "npm run clean && npm run cds:types && npm run db:deploy",
143
- "test:integration": "vitest run --project integration",
144
- "test:integration:blockfrost": "vitest run test/integration/core.blockfrost.test.ts",
145
- "test:integration:koios": "vitest run test/integration/core.koios.test.ts",
146
- "test:integration:ogmios": "vitest run test/integration/core-ogmios.test.ts",
147
- "test:integration:both": "npm run test:integration:blockfrost && npm run test:integration:koios",
148
- "pretest:unit": "npm run cds:types",
149
- "test:unit": "vitest run --project unit",
150
- "watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
151
- "watch-wallet": "cds watch --open wallet/webapp/index.html",
152
- "release:check": "node scripts/release-check.mjs"
153
- },
154
- "sapux": [
155
- "app/odatano"
156
- ],
157
- "directories": {
158
- "doc": "docs",
159
- "test": "test"
160
- },
161
- "repository": {
162
- "type": "git",
163
- "url": "git+https://github.com/ODATANO/ODATANO.git"
164
- },
165
- "keywords": [
166
- "CAP",
167
- "CDS",
168
- "plugin",
169
- "Cardano",
170
- "blockchain",
171
- "OData",
172
- "SAP"
173
- ],
174
- "author": "Maximilian Weber",
175
- "license": "Apache-2.0",
176
- "type": "commonjs",
177
- "bugs": {
178
- "url": "https://github.com/ODATANO/ODATANO/issues"
179
- },
180
- "homepage": "https://github.com/ODATANO/ODATANO#readme"
181
- }
1
+ {
2
+ "name": "@odatano/core",
3
+ "version": "2.0.0-rc.24",
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
+ "scripts/migrate-txseq.mjs",
20
+ "scripts/migrate-slot-leader.mjs"
21
+ ],
22
+ "engines": {
23
+ "node": ">=22.5"
24
+ },
25
+ "peerDependencies": {
26
+ "@sap/cds": ">=10"
27
+ },
28
+ "dependencies": {
29
+ "@blockfrost/blockfrost-js": "~6.0.0",
30
+ "@cap-js/hana": "^3",
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/uint8array-utils": "^1.0.4",
38
+ "@odatano/cap-auth": "^0.1.0",
39
+ "@sap/xssec": "^4",
40
+ "axios": "^1.18.0",
41
+ "bech32": "^2.0.0",
42
+ "blake2b": "^2.1.4"
43
+ },
44
+ "optionalDependencies": {
45
+ "pkcs11js": "^2.1.6"
46
+ },
47
+ "overrides": {
48
+ "axios": "^1.18.0",
49
+ "esbuild": "0.28.1",
50
+ "form-data": "^4.0.6",
51
+ "fast-uri": "^3.1.7",
52
+ "ws": "7.5.11",
53
+ "@sap/approuter": {
54
+ "body-parser": "^2.2.3"
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@cap-js/cds-test": "^0.4.1",
59
+ "@cap-js/cds-typer": "^0.40.0",
60
+ "@cap-js/cds-types": "^0.18.0",
61
+ "@cap-js/postgres": "^3.1.1",
62
+ "@cap-js/sqlite": "^3",
63
+ "@sap/cds": "^10",
64
+ "@sap/cds-dk": "^10",
65
+ "@sap/eslint-plugin-cds": "^4.2.4",
66
+ "@types/blake2b": "^2.1.3",
67
+ "@types/node": "^22.19.7",
68
+ "@typescript-eslint/eslint-plugin": "^8.50.1",
69
+ "@typescript-eslint/parser": "^8.50.1",
70
+ "@vitest/coverage-v8": "^4.1.10",
71
+ "dotenv": "^16.3.1",
72
+ "eslint": "^9.39.2",
73
+ "nock": "^13.5.6",
74
+ "ts-node": "^10.9.2",
75
+ "tsx": "^4.21.0",
76
+ "typescript": "^5.9.3",
77
+ "vitest": "^4.1.10"
78
+ },
79
+ "cds": {
80
+ "typer": {
81
+ "ieee754compatible": true
82
+ },
83
+ "build": {
84
+ "tasks": [
85
+ {
86
+ "for": "node-cf",
87
+ "src": "srv",
88
+ "dest": "../gen/srv"
89
+ },
90
+ {
91
+ "for": "hana",
92
+ "src": "db",
93
+ "dest": "../gen/db"
94
+ }
95
+ ]
96
+ },
97
+ "requires": {
98
+ "db": {
99
+ "kind": "sqlite",
100
+ "credentials": {
101
+ "url": "db.sqlite"
102
+ },
103
+ "client": {
104
+ "timeout": 5000
105
+ }
106
+ },
107
+ "[production]": {
108
+ "db": {
109
+ "kind": "hana",
110
+ "pool": {
111
+ "acquireTimeoutMillis": 30000,
112
+ "min": 0,
113
+ "max": 10
114
+ }
115
+ },
116
+ "auth": "xsuaa"
117
+ }
118
+ }
119
+ },
120
+ "scripts": {
121
+ "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')\"",
122
+ "clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
123
+ "build": "npm run cds:types && tsc",
124
+ "build:plugin": "npm run cds:types && tsc -p tsconfig.build.json",
125
+ "build:package": "npm run clean && npm run clean:models && npm run build:plugin",
126
+ "prepare": "npm run build:package",
127
+ "start": "cds-serve",
128
+ "cds:watch": "cds watch",
129
+ "cds:serve": "cds serve --with-mocks",
130
+ "cds:types": "cds-typer \"*\" --outputDirectory @cds-models",
131
+ "lint": "eslint .",
132
+ "typecheck": "tsc --noEmit",
133
+ "db:deploy": "cds deploy",
134
+ "pretest": "npm run clean && npm run cds:types && npm run db:deploy",
135
+ "test": "vitest run",
136
+ "pretest:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
137
+ "test:coverage": "vitest run --coverage",
138
+ "pretest:ci": "npm run clean && npm run cds:types && npm run db:deploy",
139
+ "test:ci": "vitest run --exclude \"**/core-ogmios.test.ts\"",
140
+ "pretest:ci:coverage": "npm run clean && npm run cds:types && npm run db:deploy",
141
+ "test:ci:coverage": "vitest run --coverage --exclude \"**/core-ogmios.test.ts\"",
142
+ "pretest:integration": "npm run clean && npm run cds:types && npm run db:deploy",
143
+ "test:integration": "vitest run --project integration",
144
+ "test:integration:blockfrost": "vitest run test/integration/core.blockfrost.test.ts",
145
+ "test:integration:koios": "vitest run test/integration/core.koios.test.ts",
146
+ "test:integration:ogmios": "vitest run test/integration/core-ogmios.test.ts",
147
+ "test:integration:both": "npm run test:integration:blockfrost && npm run test:integration:koios",
148
+ "pretest:unit": "npm run cds:types",
149
+ "test:unit": "vitest run --project unit",
150
+ "watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
151
+ "watch-wallet": "cds watch --open wallet/webapp/index.html",
152
+ "release:check": "node scripts/release-check.mjs",
153
+ "prepublishOnly": "node scripts/publish-guard.mjs"
154
+ },
155
+ "sapux": [
156
+ "app/odatano"
157
+ ],
158
+ "directories": {
159
+ "doc": "docs",
160
+ "test": "test"
161
+ },
162
+ "repository": {
163
+ "type": "git",
164
+ "url": "git+https://github.com/ODATANO/ODATANO.git"
165
+ },
166
+ "keywords": [
167
+ "CAP",
168
+ "CDS",
169
+ "plugin",
170
+ "Cardano",
171
+ "blockchain",
172
+ "OData",
173
+ "SAP"
174
+ ],
175
+ "author": "Maximilian Weber",
176
+ "license": "Apache-2.0",
177
+ "type": "commonjs",
178
+ "bugs": {
179
+ "url": "https://github.com/ODATANO/ODATANO/issues"
180
+ },
181
+ "homepage": "https://github.com/ODATANO/ODATANO#readme"
182
+ }
@@ -130,6 +130,8 @@ export interface LedgerStateBackend extends CardanoBackend {
130
130
  txHash: string;
131
131
  outputIndex: number;
132
132
  }>): Promise<UTxO[]>;
133
+ /** Unspent outputs of several addresses at the tip. */
134
+ getUtxosByAddresses?(addresses: string[]): Promise<UTxO[]>;
133
135
  }
134
136
  export declare function isLedgerStateBackend(backend: CardanoBackend): backend is LedgerStateBackend;
135
137
  /**
@@ -171,6 +173,27 @@ export interface EnumeratingBackend extends CardanoBackend {
171
173
  /** Resolve a batch of DRep ids. Ids the backend does not know are omitted. */
172
174
  getDreps(drepIds: string[]): Promise<DrepData[]>;
173
175
  }
176
+ /** Network-wide ledger state read at one block for an epoch snapshot; unreported figures are null. */
177
+ export interface EpochLedgerState {
178
+ /** Epoch the ledger was in at the acquired block. */
179
+ epoch: number;
180
+ pools: PoolData[];
181
+ /** Registered DReps only; the two predefined DReps are summed into the stake fields below. */
182
+ dreps: DrepData[];
183
+ treasury: string | null;
184
+ reserves: string | null;
185
+ drepAbstainStake: string | null;
186
+ drepNoConfidenceStake: string | null;
187
+ }
188
+ /**
189
+ * Backend that reads the whole pool/DRep set from the node's ledger at a given block (Ogmios).
190
+ * The block must still be inside the node's volatile window (k blocks), else acquisition fails.
191
+ */
192
+ export interface EpochStateBackend extends CardanoBackend {
193
+ epochStateAt(point: ChainPoint): Promise<EpochLedgerState>;
194
+ }
195
+ /** Type guard: can this backend read epoch state at a block? */
196
+ export declare function isEpochStateBackend(backend: CardanoBackend): backend is EpochStateBackend;
174
197
  /** Type guard: can this backend enumerate pools and DReps? */
175
198
  export declare function isEnumeratingBackend(backend: CardanoBackend): backend is EnumeratingBackend;
176
199
  //# sourceMappingURL=cardano-backend.d.ts.map
@@ -4,6 +4,7 @@ exports.isEvaluatingBackend = isEvaluatingBackend;
4
4
  exports.isChainSyncBackend = isChainSyncBackend;
5
5
  exports.isLedgerStateBackend = isLedgerStateBackend;
6
6
  exports.isPaginatingBackend = isPaginatingBackend;
7
+ exports.isEpochStateBackend = isEpochStateBackend;
7
8
  exports.isEnumeratingBackend = isEnumeratingBackend;
8
9
  /** Type guard: does this backend support transaction evaluation? */
9
10
  function isEvaluatingBackend(backend) {
@@ -23,6 +24,10 @@ function isPaginatingBackend(backend) {
23
24
  && typeof b.getNextBlocks === 'function'
24
25
  && typeof b.getBlockTransactions === 'function';
25
26
  }
27
+ /** Type guard: can this backend read epoch state at a block? */
28
+ function isEpochStateBackend(backend) {
29
+ return typeof backend.epochStateAt === 'function';
30
+ }
26
31
  /** Type guard: can this backend enumerate pools and DReps? */
27
32
  function isEnumeratingBackend(backend) {
28
33
  const b = backend;
@@ -0,0 +1,59 @@
1
+ import { CardanoBackend, EvaluatingBackend, PaginatingBackend, EnumeratingBackend } from './cardano-backend';
2
+ import type { Transaction, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, BlockData, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../../utils/types';
3
+ import { Network } from '../cardano-client';
4
+ /** Public ODATANO API per network (ACCESS gateway); mainnet has no default and needs `odatanoUrl`. */
5
+ export declare const ODATANO_API_URLS: Partial<Record<Network, string>>;
6
+ /**
7
+ * Backend over another ODATANO instance (typically the hosted API behind the ACCESS gateway),
8
+ * speaking its `CardanoBackendService`. Answers arrive in the provider shape, so everything above
9
+ * this class treats it like Koios. The key goes as `Authorization: Bearer`.
10
+ */
11
+ export declare class OdatanoBackend implements CardanoBackend, EvaluatingBackend, PaginatingBackend, EnumeratingBackend {
12
+ readonly name = "odatano";
13
+ private readonly api;
14
+ /** Units left on the key, from the gateway's `x-access-units-left` header; null when not reported. */
15
+ unitsLeft: number | null;
16
+ constructor(network: Network, timeoutMs: number, url: string | undefined, apiKey: string | undefined);
17
+ /** Probe the remote instance with its cheapest call. */
18
+ init(): Promise<boolean>;
19
+ getTransaction(txHash: string): Promise<Transaction>;
20
+ getAddress(address: string): Promise<Address>;
21
+ getAddressUtxos(address: string): Promise<UTxO[]>;
22
+ getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
23
+ getAddressTransactionHashes(address: string, limit: number): Promise<string[]>;
24
+ getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
25
+ getCredentialUtxos(credHash: string): Promise<UTxO[]>;
26
+ getNetworkInformation(): Promise<NetworkInformation>;
27
+ getTransactionMetadata(txHash: string): Promise<MetadataLabelTx[]>;
28
+ getBlock(blockHash: string): Promise<BlockData>;
29
+ getEpoch(epochNumber: number): Promise<EpochData>;
30
+ getLatestEpoch(): Promise<EpochData>;
31
+ getLatestBlock(): Promise<BlockData>;
32
+ getCurrentSlot(): Promise<number>;
33
+ isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
34
+ getPool(poolId: string): Promise<PoolData>;
35
+ getDrep(drepId: string): Promise<DrepData>;
36
+ getAccount(stakeAddress: string): Promise<AccountData>;
37
+ getAssetInfo(unit: string): Promise<AssetInfo>;
38
+ getAssetHistory(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
39
+ getProtocolParameters(): Promise<LedgerProtocolParameters>;
40
+ submitTransaction(signedTxCbor: string): Promise<string>;
41
+ evaluateTransaction(unsignedTxCbor: string): Promise<ScriptEvaluationResult[]>;
42
+ getBlockByHeight(height: number): Promise<BlockData>;
43
+ getNextBlocks(afterHash: string, count: number, afterHeight?: number): Promise<BlockData[]>;
44
+ getBlockTransactions(blockHash: string): Promise<Transaction[]>;
45
+ getPoolIds(): Promise<string[]>;
46
+ getPools(poolIds: string[]): Promise<PoolData[]>;
47
+ getDrepIds(): Promise<string[]>;
48
+ getDreps(drepIds: string[]): Promise<DrepData[]>;
49
+ shutdown(): Promise<void>;
50
+ private batched;
51
+ /**
52
+ * POST one operation, parse the JSON string it answers (safeJSON keeps big integers) and map
53
+ * HTTP failures to the backend error classes. The remote message is kept verbatim, so markers
54
+ * such as `CHAIN_POINT_MISMATCH:` reach the crawler unchanged.
55
+ */
56
+ private call;
57
+ private mapError;
58
+ }
59
+ //# sourceMappingURL=odatano-backend.d.ts.map
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OdatanoBackend = exports.ODATANO_API_URLS = void 0;
7
+ const cds_1 = __importDefault(require("@sap/cds"));
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const client_1 = require("@cardano-ogmios/client");
10
+ const errors_1 = require("../../utils/errors");
11
+ const logger = cds_1.default.log('OdatanoBackend');
12
+ /** Public ODATANO API per network (ACCESS gateway); mainnet has no default and needs `odatanoUrl`. */
13
+ exports.ODATANO_API_URLS = {
14
+ preview: 'https://api.preview.odatano.dev',
15
+ preprod: 'https://api.preprod.odatano.dev',
16
+ };
17
+ const SERVICE_PATH = '/odata/v4/cardano-backend';
18
+ /** Ids per GetPools / GetDreps call, below the service's list cap. */
19
+ const ENUMERATION_BATCH = 200;
20
+ /**
21
+ * Backend over another ODATANO instance (typically the hosted API behind the ACCESS gateway),
22
+ * speaking its `CardanoBackendService`. Answers arrive in the provider shape, so everything above
23
+ * this class treats it like Koios. The key goes as `Authorization: Bearer`.
24
+ */
25
+ class OdatanoBackend {
26
+ name = 'odatano';
27
+ api;
28
+ /** Units left on the key, from the gateway's `x-access-units-left` header; null when not reported. */
29
+ unitsLeft = null;
30
+ constructor(network, timeoutMs, url, apiKey) {
31
+ const baseURL = (url || exports.ODATANO_API_URLS[network] || '').replace(/\/+$/, '');
32
+ if (!baseURL) {
33
+ throw new errors_1.BackendInitError('odatano', new Error(`odatanoUrl is required on ${network}`));
34
+ }
35
+ if (!/^https?:\/\//i.test(baseURL)) {
36
+ throw new errors_1.BackendInitError('odatano', new Error(`odatanoUrl must be an http(s) URL, got "${baseURL}"`));
37
+ }
38
+ this.api = axios_1.default.create({
39
+ baseURL: baseURL + SERVICE_PATH,
40
+ timeout: timeoutMs,
41
+ headers: {
42
+ 'Content-Type': 'application/json',
43
+ ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
44
+ },
45
+ });
46
+ }
47
+ /** Probe the remote instance with its cheapest call. */
48
+ async init() {
49
+ await this.call('GetCurrentSlot');
50
+ return true;
51
+ }
52
+ // --- CardanoBackend ------------------------------------------------------------------------
53
+ getTransaction(txHash) { return this.call('GetTransaction', { hash: txHash }); }
54
+ getAddress(address) { return this.call('GetAddress', { address }); }
55
+ getAddressUtxos(address) { return this.call('GetAddressUtxos', { address }); }
56
+ getAddressTransactions(address, limit) {
57
+ return this.call('GetAddressTransactions', { address, limit });
58
+ }
59
+ getAddressTransactionHashes(address, limit) {
60
+ return this.call('GetAddressTransactionHashes', { address, limit });
61
+ }
62
+ async getTransactionsBatch(txHashes) {
63
+ const out = new Map();
64
+ for (let i = 0; i < txHashes.length; i += ENUMERATION_BATCH) {
65
+ const found = await this.call('GetTransactionsBatch', {
66
+ hashes: JSON.stringify(txHashes.slice(i, i + ENUMERATION_BATCH)),
67
+ });
68
+ for (const [hash, tx] of Object.entries(found ?? {}))
69
+ out.set(hash, tx);
70
+ }
71
+ return out;
72
+ }
73
+ getCredentialUtxos(credHash) { return this.call('GetCredentialUtxos', { credential: credHash }); }
74
+ getNetworkInformation() { return this.call('GetNetworkInformation'); }
75
+ getTransactionMetadata(txHash) { return this.call('GetTransactionMetadata', { hash: txHash }); }
76
+ getBlock(blockHash) { return this.call('GetBlock', { hash: blockHash }); }
77
+ getEpoch(epochNumber) { return this.call('GetEpoch', { epoch: epochNumber }); }
78
+ getLatestEpoch() { return this.call('GetLatestEpoch'); }
79
+ getLatestBlock() { return this.call('GetLatestBlock'); }
80
+ getCurrentSlot() { return this.call('GetCurrentSlot'); }
81
+ isUtxoUnspent(txHash, outputIndex) {
82
+ return this.call('IsUtxoUnspent', { txHash, outputIndex });
83
+ }
84
+ getPool(poolId) { return this.call('GetPool', { poolId }); }
85
+ getDrep(drepId) { return this.call('GetDrep', { drepId }); }
86
+ getAccount(stakeAddress) { return this.call('GetAccount', { stakeAddress }); }
87
+ getAssetInfo(unit) { return this.call('GetAssetInfo', { unit }); }
88
+ getAssetHistory(unit, limit = 100) { return this.call('GetAssetHistory', { unit, limit }); }
89
+ getProtocolParameters() { return this.call('GetProtocolParameters'); }
90
+ submitTransaction(signedTxCbor) { return this.call('SubmitTransaction', { cbor: signedTxCbor }); }
91
+ // --- EvaluatingBackend -----------------------------------------------------------------------
92
+ evaluateTransaction(unsignedTxCbor) {
93
+ return this.call('EvaluateTransaction', { cbor: unsignedTxCbor });
94
+ }
95
+ // --- PaginatingBackend (crawler source) ------------------------------------------------------
96
+ getBlockByHeight(height) { return this.call('GetBlockByHeight', { height }); }
97
+ getNextBlocks(afterHash, count, afterHeight) {
98
+ return this.call('GetNextBlocks', { afterHash, count, afterHeight: afterHeight ?? null });
99
+ }
100
+ getBlockTransactions(blockHash) { return this.call('GetBlockTransactions', { blockHash }); }
101
+ // --- EnumeratingBackend (epoch snapshots) -----------------------------------------------------
102
+ getPoolIds() { return this.call('GetPoolIds'); }
103
+ getPools(poolIds) { return this.batched('GetPools', poolIds); }
104
+ getDrepIds() { return this.call('GetDrepIds'); }
105
+ getDreps(drepIds) { return this.batched('GetDreps', drepIds); }
106
+ async shutdown() { }
107
+ async batched(operation, ids) {
108
+ const out = [];
109
+ for (let i = 0; i < ids.length; i += ENUMERATION_BATCH) {
110
+ out.push(...await this.call(operation, { ids: JSON.stringify(ids.slice(i, i + ENUMERATION_BATCH)) }));
111
+ }
112
+ return out;
113
+ }
114
+ /**
115
+ * POST one operation, parse the JSON string it answers (safeJSON keeps big integers) and map
116
+ * HTTP failures to the backend error classes. The remote message is kept verbatim, so markers
117
+ * such as `CHAIN_POINT_MISMATCH:` reach the crawler unchanged.
118
+ */
119
+ async call(operation, body = {}) {
120
+ try {
121
+ const res = await this.api.post(`/${operation}`, body);
122
+ const left = Number(res.headers?.['x-access-units-left']);
123
+ if (Number.isFinite(left))
124
+ this.unitsLeft = left;
125
+ const value = res.data?.value;
126
+ return (typeof value === 'string' ? client_1.safeJSON.parse(value) : value);
127
+ }
128
+ catch (err) {
129
+ throw this.mapError(operation, err);
130
+ }
131
+ }
132
+ mapError(operation, err) {
133
+ const ax = err;
134
+ if (!ax?.isAxiosError)
135
+ return err instanceof Error ? err : new Error(String(err));
136
+ const status = ax.response?.status;
137
+ const message = ax.response?.data?.error?.message ?? ax.message;
138
+ // NotFoundError appends " not found" itself; the remote message already ends with it
139
+ if (status === 404)
140
+ return new errors_1.NotFoundError(message.replace(/ not found$/, ''), this.name);
141
+ if (status === 429) {
142
+ const retryAfter = Number(ax.response?.headers?.['retry-after']);
143
+ return new errors_1.RateLimitError(message, this.name, Number.isFinite(retryAfter) ? retryAfter : undefined);
144
+ }
145
+ if (status === 400)
146
+ return new errors_1.TransactionValidationError(message);
147
+ if (status === 401 || status === 402 || status === 403) {
148
+ logger.error(`${operation}: the remote ODATANO refused the key (${status}): ${message}`);
149
+ }
150
+ return new errors_1.ProviderUnavailableError(message, this.name);
151
+ }
152
+ }
153
+ exports.OdatanoBackend = OdatanoBackend;
154
+ //# sourceMappingURL=odatano-backend.js.map