@odatano/core 2.0.0-rc.2 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +139 -2
- package/@cds-models/CardanoIndexerService/index.js +18 -0
- package/@cds-models/CardanoODataService/index.d.ts +231 -6
- package/@cds-models/CardanoODataService/index.js +27 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
- package/@cds-models/odatano/cardano/index.d.ts +323 -6
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2133 -1633
- package/package.json +181 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +10 -10
- package/src/index.js +24 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +45 -158
- package/srv/blockchain/backends/cardano-backend.d.ts +83 -158
- package/srv/blockchain/backends/cardano-backend.js +14 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +293 -203
- package/srv/blockchain/backends/ogmios-backend.d.ts +69 -94
- package/srv/blockchain/backends/ogmios-backend.js +319 -185
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +57 -204
- package/srv/blockchain/cardano-client.js +94 -226
- package/srv/blockchain/cardano-indexer.d.ts +176 -240
- package/srv/blockchain/cardano-indexer.js +615 -338
- package/srv/blockchain/cardano-tx-builder.d.ts +29 -82
- package/srv/blockchain/cardano-tx-builder.js +88 -128
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +121 -53
- package/srv/blockchain/crawler/crawler.js +403 -89
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +44 -28
- package/srv/blockchain/crawler/sync-state.js +115 -43
- package/srv/blockchain/crawler/utxo-set-import.d.ts +69 -0
- package/srv/blockchain/crawler/utxo-set-import.js +269 -0
- package/srv/blockchain/ledger-state.d.ts +80 -0
- package/srv/blockchain/ledger-state.js +383 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +71 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +185 -260
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +42 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +39 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-indexer-service.cds +164 -73
- package/srv/cardano-indexer-service.js +156 -11
- package/srv/cardano-service.cds +45 -0
- package/srv/cardano-service.js +38 -96
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +136 -196
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +28 -86
- package/srv/server.js +95 -128
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +914 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +93 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +36 -179
- package/srv/utils/errors.js +62 -220
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +89 -214
- package/srv/utils/mappers.js +289 -301
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +57 -0
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +14 -20
- package/srv/utils/tx-request-parsers.js +33 -20
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +114 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
package/package.json
CHANGED
|
@@ -1,173 +1,181 @@
|
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@harmoniclabs/
|
|
33
|
-
"@harmoniclabs/
|
|
34
|
-
"@harmoniclabs/
|
|
35
|
-
"@harmoniclabs/
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"@cap-js/
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"
|
|
68
|
-
"eslint": "^
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"
|
|
137
|
-
"test:
|
|
138
|
-
"
|
|
139
|
-
"test:
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
"
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
"
|
|
156
|
-
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Rewrite Blocks.slotLeader values written before it became the bech32 pool id: an Ogmios
|
|
3
|
+
// issuer key (64 hex chars) becomes bech32('pool', blake2b-224(key)); a Koios VRF key
|
|
4
|
+
// (vrf_vk1…) is matched on blake2b-256 against the pools' registered VRF key hashes, taken
|
|
5
|
+
// from an Ogmios `queryLedgerState/stakePools` response. Prints SQL; the database is not touched.
|
|
6
|
+
//
|
|
7
|
+
// psql -Atc "SELECT DISTINCT slotLeader FROM odatano_cardano_Blocks WHERE slotLeader NOT LIKE 'pool1%'" \
|
|
8
|
+
// | node scripts/migrate-slot-leader.mjs [--stake-pools stake-pools.json] [--extra-map extra.txt] > slot-leader.sql
|
|
9
|
+
//
|
|
10
|
+
// The SQL fills a mapping table and runs one UPDATE (PostgreSQL and SQLite). Values that cannot
|
|
11
|
+
// be mapped (a VRF key of a pool no longer registered, unknown formats) are listed on stderr
|
|
12
|
+
// and left unchanged; `--extra-map` supplies them as "<old value> <pool id>" lines.
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import { pathToFileURL } from 'node:url';
|
|
15
|
+
import { bech32 } from 'bech32';
|
|
16
|
+
import { blake2b_224, blake2b_256 } from '@harmoniclabs/crypto';
|
|
17
|
+
|
|
18
|
+
const toHex = (bytes) => Buffer.from(bytes).toString('hex');
|
|
19
|
+
const lines = (text) => text.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
|
|
20
|
+
|
|
21
|
+
/** VRF key hash (hex) -> pool id, from an Ogmios stakePools response (whole JSON-RPC reply or its result). */
|
|
22
|
+
export function vrfMapFromStakePools(response) {
|
|
23
|
+
const pools = response?.result ?? response ?? {};
|
|
24
|
+
const map = new Map();
|
|
25
|
+
for (const [id, pool] of Object.entries(pools)) {
|
|
26
|
+
const vrf = pool?.vrfVerificationKeyHash;
|
|
27
|
+
if (typeof vrf === 'string') map.set(vrf.toLowerCase(), pool.id ?? id);
|
|
28
|
+
}
|
|
29
|
+
return map;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** "<old value> <pool id>" lines to a Map; lines starting with # are skipped. */
|
|
33
|
+
export function parseExtraMap(text) {
|
|
34
|
+
const map = new Map();
|
|
35
|
+
for (const line of lines(text)) {
|
|
36
|
+
if (line.startsWith('#')) continue;
|
|
37
|
+
const [from, to] = line.split(/\s+/);
|
|
38
|
+
if (!to?.startsWith('pool1')) throw new Error(`extra map: no pool id for ${from}`);
|
|
39
|
+
map.set(from, to);
|
|
40
|
+
}
|
|
41
|
+
return map;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Bech32 pool id for an old slotLeader value, or null when it cannot be derived. */
|
|
45
|
+
export function slotLeaderToPoolId(value, vrfMap = new Map()) {
|
|
46
|
+
if (typeof value !== 'string') return null;
|
|
47
|
+
const v = value.trim();
|
|
48
|
+
if (/^[0-9a-f]{64}$/i.test(v)) {
|
|
49
|
+
return bech32.encode('pool', bech32.toWords(blake2b_224(Uint8Array.from(Buffer.from(v, 'hex')))));
|
|
50
|
+
}
|
|
51
|
+
if (v.startsWith('vrf_vk1')) {
|
|
52
|
+
const { words } = bech32.decode(v, 120);
|
|
53
|
+
const vrfHash = toHex(blake2b_256(Uint8Array.from(bech32.fromWords(words))));
|
|
54
|
+
return vrfMap.get(vrfHash) ?? null;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const sqlString = (s) => `'${s.replace(/'/g, "''")}'`;
|
|
60
|
+
|
|
61
|
+
/** SQL that rewrites every mapped value in one UPDATE; empty string when nothing maps. */
|
|
62
|
+
export function migrationSql(mapping) {
|
|
63
|
+
if (mapping.size === 0) return '';
|
|
64
|
+
const rows = [...mapping].map(([from, to]) => ` (${sqlString(from)}, ${sqlString(to)})`);
|
|
65
|
+
return [
|
|
66
|
+
'BEGIN;',
|
|
67
|
+
'CREATE TEMPORARY TABLE slot_leader_map (old_value VARCHAR(200) PRIMARY KEY, new_value VARCHAR(120) NOT NULL);',
|
|
68
|
+
`INSERT INTO slot_leader_map (old_value, new_value) VALUES\n${rows.join(',\n')};`,
|
|
69
|
+
'UPDATE odatano_cardano_Blocks',
|
|
70
|
+
' SET slotLeader = (SELECT m.new_value FROM slot_leader_map m WHERE m.old_value = odatano_cardano_Blocks.slotLeader)',
|
|
71
|
+
' WHERE slotLeader IN (SELECT old_value FROM slot_leader_map);',
|
|
72
|
+
'DROP TABLE slot_leader_map;',
|
|
73
|
+
'COMMIT;',
|
|
74
|
+
'',
|
|
75
|
+
].join('\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function argValue(name) {
|
|
79
|
+
const i = process.argv.indexOf(name);
|
|
80
|
+
return i >= 0 ? process.argv[i + 1] : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function main() {
|
|
84
|
+
const stakePoolsFile = argValue('--stake-pools');
|
|
85
|
+
const extraMapFile = argValue('--extra-map');
|
|
86
|
+
const vrfMap = stakePoolsFile ? vrfMapFromStakePools(JSON.parse(fs.readFileSync(stakePoolsFile, 'utf8'))) : new Map();
|
|
87
|
+
const extraMap = extraMapFile ? parseExtraMap(fs.readFileSync(extraMapFile, 'utf8')) : new Map();
|
|
88
|
+
|
|
89
|
+
const values = [...new Set(lines(fs.readFileSync(0, 'utf8')))];
|
|
90
|
+
const mapping = new Map();
|
|
91
|
+
const unmapped = [];
|
|
92
|
+
for (const v of values) {
|
|
93
|
+
if (v.startsWith('pool1')) continue;
|
|
94
|
+
const poolId = extraMap.get(v) ?? slotLeaderToPoolId(v, vrfMap);
|
|
95
|
+
if (poolId) mapping.set(v, poolId);
|
|
96
|
+
else unmapped.push(v);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
process.stdout.write(migrationSql(mapping));
|
|
100
|
+
console.error(`slotLeader values: ${values.length} read, ${mapping.size} mapped, ${unmapped.length} left unchanged`);
|
|
101
|
+
for (const v of unmapped) console.error(` unmapped: ${v}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main();
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Move a database written before the txSeq schema onto it: TransactionInputs / TransactionOutputs
|
|
3
|
+
// and their asset tables are keyed by Transactions.txSeq (slot * 65536 + txIndex) instead of the
|
|
4
|
+
// transaction hash. Runs against the configured `db` (PostgreSQL or SQLite) with ODATANO stopped:
|
|
5
|
+
//
|
|
6
|
+
// node scripts/migrate-txseq.mjs # image: docker compose run --rm --no-deps odatano migrate-txseq
|
|
7
|
+
// node scripts/migrate-txseq.mjs --dry-run # report what would change, touch nothing
|
|
8
|
+
//
|
|
9
|
+
// One transaction: fill Transactions.txSeq, rebuild the four tables in the new layout (rows copied
|
|
10
|
+
// in key order, row counts checked), recreate the service views, refresh the planner statistics
|
|
11
|
+
// and store the new model in `cds_model` so the next schema deployment sees no difference. A
|
|
12
|
+
// database already on the new layout is left alone. The table indexes are recreated by the server
|
|
13
|
+
// on its next start.
|
|
14
|
+
import cds from '@sap/cds';
|
|
15
|
+
|
|
16
|
+
const DRY = process.argv.includes('--dry-run');
|
|
17
|
+
const T = (name) => `odatano_cardano_${name}`;
|
|
18
|
+
const TX_SEQ_SLOT_FACTOR = 65536;
|
|
19
|
+
|
|
20
|
+
/** Old key column -> new key column, and the column the copy is ordered by after the key. */
|
|
21
|
+
const TABLES = [
|
|
22
|
+
{ name: 'TransactionInputs', hashKey: 'tx_hash', seqKey: 'txSeq', order: 'inputIndex' },
|
|
23
|
+
{ name: 'TransactionOutputs', hashKey: 'tx_hash', seqKey: 'txSeq', order: 'outputIndex' },
|
|
24
|
+
{ name: 'TransactionInputAssets', hashKey: 'input_tx_hash', seqKey: 'input_txSeq', order: 'input_inputIndex, unit' },
|
|
25
|
+
{ name: 'TransactionOutputAssets', hashKey: 'output_tx_hash', seqKey: 'output_txSeq', order: 'output_outputIndex, unit' },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/** Column names of a table, lower-cased (PostgreSQL folds unquoted identifiers). */
|
|
29
|
+
export async function tableColumns(db, table) {
|
|
30
|
+
const rows = db.kind === 'postgres'
|
|
31
|
+
? await db.run(`SELECT column_name AS name FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = '${table.toLowerCase()}'`)
|
|
32
|
+
: await db.run(`SELECT name FROM pragma_table_info('${table}')`);
|
|
33
|
+
return rows.map(r => String(r.name).toLowerCase());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** CREATE statements of the compiled model for one table (renamed) and for every view. */
|
|
37
|
+
export function modelStatements(model, options) {
|
|
38
|
+
const sql = cds.compile.to.sql(model, options);
|
|
39
|
+
const views = sql.filter(s => /^CREATE VIEW/i.test(s.trim()));
|
|
40
|
+
const tableDdl = (name) => {
|
|
41
|
+
const stmt = sql.find(s => new RegExp(`^CREATE TABLE ${T(name)} \\(`, 'i').test(s.trim()));
|
|
42
|
+
if (!stmt) throw new Error(`model has no table ${T(name)}`);
|
|
43
|
+
return stmt;
|
|
44
|
+
};
|
|
45
|
+
return { views, tableDdl };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const viewName = (stmt) => stmt.trim().match(/^CREATE VIEW\s+("?[\w.]+"?)/i)[1];
|
|
49
|
+
|
|
50
|
+
/** Copy statement: every column of the old table except the hash key, the new key from Transactions. */
|
|
51
|
+
export function copySql(spec, oldColumns) {
|
|
52
|
+
const others = oldColumns.filter(c => c !== spec.hashKey.toLowerCase());
|
|
53
|
+
const target = [spec.seqKey, ...others].join(', ');
|
|
54
|
+
const source = ['t.txSeq', ...others.map(c => `x.${c}`)].join(', ');
|
|
55
|
+
const order = ['t.txSeq', ...spec.order.split(',').map(c => `x.${c.trim()}`)].join(', ');
|
|
56
|
+
return `INSERT INTO ${T(spec.name)}_txseq_new (${target}) SELECT ${source} FROM ${T(spec.name)} x `
|
|
57
|
+
+ `JOIN ${T('Transactions')} t ON t.hash = x.${spec.hashKey} ORDER BY ${order}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function count(tx, table) {
|
|
61
|
+
const [row] = await tx.run(`SELECT count(*) AS n FROM ${table}`);
|
|
62
|
+
return Number(row.n);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function main() {
|
|
66
|
+
const db = await cds.connect.to('db');
|
|
67
|
+
if (db.kind !== 'postgres' && db.kind !== 'sqlite') throw new Error(`unsupported database kind ${db.kind}: re-crawl instead`);
|
|
68
|
+
|
|
69
|
+
const inputColumns = await tableColumns(db, T('TransactionInputs'));
|
|
70
|
+
if (!inputColumns.includes('tx_hash')) {
|
|
71
|
+
console.log('Already on the txSeq layout; nothing to do.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [lease] = await db.run(`SELECT leaseUntil FROM ${T('CardanoSyncState')}`).catch(() => []);
|
|
76
|
+
const leaseUntil = lease?.leaseUntil ?? lease?.leaseuntil;
|
|
77
|
+
if (leaseUntil && Date.parse(leaseUntil) > Date.now()) {
|
|
78
|
+
throw new Error(`the crawler lease is held until ${leaseUntil}: stop ODATANO first`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// the model exactly as `cds deploy` compiles it
|
|
82
|
+
const model = await cds.load('*').then(cds.minify);
|
|
83
|
+
cds.deploy.exclude_external_entities_in(model);
|
|
84
|
+
const options = { ...db.options };
|
|
85
|
+
const { views, tableDdl } = modelStatements(model, options);
|
|
86
|
+
const [hasModelTable] = await db.run(db.kind === 'postgres'
|
|
87
|
+
? `SELECT 1 AS x FROM pg_tables WHERE tablename = 'cds_model' AND schemaname = current_schema()`
|
|
88
|
+
: `SELECT 1 AS x FROM sqlite_schema WHERE name = 'cds_model'`);
|
|
89
|
+
|
|
90
|
+
const txNull = Number((await db.run(`SELECT count(*) AS n FROM ${T('Transactions')} WHERE slot IS NULL OR txIndex IS NULL`))[0].n);
|
|
91
|
+
if (txNull > 0) throw new Error(`${txNull} transactions have no slot or txIndex; their txSeq cannot be derived`);
|
|
92
|
+
|
|
93
|
+
const plan = [];
|
|
94
|
+
for (const spec of TABLES) plan.push({ spec, columns: await tableColumns(db, T(spec.name)), rows: await count(db, T(spec.name)) });
|
|
95
|
+
for (const p of plan) console.log(`${T(p.spec.name)}: ${p.rows} rows, key ${p.spec.hashKey} -> ${p.spec.seqKey}`);
|
|
96
|
+
console.log(`${views.length} views recreated${hasModelTable ? ', cds_model updated' : ''}`);
|
|
97
|
+
if (DRY) { console.log('dry run: nothing changed'); return; }
|
|
98
|
+
|
|
99
|
+
await db.tx(async (tx) => {
|
|
100
|
+
const started = Date.now();
|
|
101
|
+
const step = (msg) => console.log(`[${Math.round((Date.now() - started) / 1000)}s] ${msg}`);
|
|
102
|
+
|
|
103
|
+
for (const stmt of [...views].reverse()) {
|
|
104
|
+
await tx.run(`DROP VIEW IF EXISTS ${viewName(stmt)}${db.kind === 'postgres' ? ' CASCADE' : ''}`);
|
|
105
|
+
}
|
|
106
|
+
step('views dropped');
|
|
107
|
+
|
|
108
|
+
const txColumns = await tableColumns(tx, T('Transactions'));
|
|
109
|
+
if (!txColumns.includes('txseq')) await tx.run(`ALTER TABLE ${T('Transactions')} ADD COLUMN txSeq BIGINT`);
|
|
110
|
+
await tx.run(`UPDATE ${T('Transactions')} SET txSeq = slot * ${TX_SEQ_SLOT_FACTOR} + txIndex`);
|
|
111
|
+
await tx.run(`CREATE INDEX IF NOT EXISTS odatano_cardano_transactions_txseq ON ${T('Transactions')} (txSeq)`);
|
|
112
|
+
step('Transactions.txSeq filled');
|
|
113
|
+
|
|
114
|
+
for (const { spec, columns, rows } of plan) {
|
|
115
|
+
const table = T(spec.name);
|
|
116
|
+
const newTable = `${table}_txseq_new`;
|
|
117
|
+
await tx.run(tableDdl(spec.name).replace(new RegExp(`^(\\s*CREATE TABLE )${table}\\b`, 'i'), `$1${newTable}`));
|
|
118
|
+
await tx.run(copySql(spec, columns));
|
|
119
|
+
const copied = await count(tx, newTable);
|
|
120
|
+
if (copied !== rows) throw new Error(`${table}: ${rows} rows, ${copied} copied (rows without a Transactions row?)`);
|
|
121
|
+
await tx.run(`DROP TABLE ${table}`);
|
|
122
|
+
await tx.run(`ALTER TABLE ${newTable} RENAME TO ${table}`);
|
|
123
|
+
if (db.kind === 'postgres') {
|
|
124
|
+
await tx.run(`ALTER TABLE ${table} RENAME CONSTRAINT ${newTable.toLowerCase()}_pkey TO ${table.toLowerCase()}_pkey`);
|
|
125
|
+
}
|
|
126
|
+
step(`${table}: ${copied} rows`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const stmt of views) await tx.run(stmt);
|
|
130
|
+
step('views recreated');
|
|
131
|
+
|
|
132
|
+
// fresh planner statistics: without them the rebuilt tables are read by sequential scans
|
|
133
|
+
for (const name of ['Transactions', ...TABLES.map(t => t.name)]) await tx.run(`ANALYZE ${T(name)}`);
|
|
134
|
+
step('statistics updated');
|
|
135
|
+
|
|
136
|
+
if (hasModelTable) {
|
|
137
|
+
const { afterImage } = cds.compile.to.sql.delta(model, options);
|
|
138
|
+
await tx.run(db.kind === 'postgres' ? 'UPDATE cds_model SET csn = $1' : 'UPDATE cds_model SET csn = ?', [JSON.stringify(afterImage)]);
|
|
139
|
+
step('cds_model updated');
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
console.log('Migration to the txSeq layout done. Start ODATANO; it recreates the table indexes.');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (process.argv[1] && import.meta.url === (await import('node:url')).pathToFileURL(process.argv[1]).href) {
|
|
146
|
+
main().then(() => process.exit(0), (err) => { console.error(`FAILED: ${err.message}`); process.exit(1); });
|
|
147
|
+
}
|