@hsuite/smart-engines-cli 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -9
- package/dist/commands/deploy.d.ts +13 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +132 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/governance.d.ts +42 -0
- package/dist/commands/governance.d.ts.map +1 -0
- package/dist/commands/governance.js +144 -0
- package/dist/commands/governance.js.map +1 -0
- package/dist/commands/hist-balance.d.ts +52 -0
- package/dist/commands/hist-balance.d.ts.map +1 -0
- package/dist/commands/hist-balance.js +134 -0
- package/dist/commands/hist-balance.js.map +1 -0
- package/dist/commands/personhood.d.ts +42 -0
- package/dist/commands/personhood.d.ts.map +1 -0
- package/dist/commands/personhood.js +150 -0
- package/dist/commands/personhood.js.map +1 -0
- package/dist/commands/subscribe.d.ts.map +1 -1
- package/dist/commands/subscribe.js +19 -4
- package/dist/commands/subscribe.js.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ Flow:
|
|
|
84
84
|
1. Reads `XRPL_*` + `APP_NAME` from `.env.local`
|
|
85
85
|
2. Builds a signer using `ripple-keypairs.sign`
|
|
86
86
|
3. Authenticates via `BaasClient.authenticate({chain: 'xrpl', ...})` against the cluster
|
|
87
|
-
4. Calls `BaasClient.
|
|
87
|
+
4. Calls `BaasClient.deployment.init({name, port, services})` — the new four-step deploy flow's step 1 (legacy `register()` removed in PR-A); the cluster runs the per-entity DKG ceremony and returns the DKG entityId as `appId`
|
|
88
88
|
5. Appends `SUBSCRIPTION_APP_ID=<appId>` and `APP_ID=<appId>` to your `.env.local`, flips `SKIP_SUBSCRIPTION_CHECK=false`
|
|
89
89
|
|
|
90
90
|
After this, your smart-app boots in cluster-mode automatically.
|
|
@@ -93,27 +93,43 @@ After this, your smart-app boots in cluster-mode automatically.
|
|
|
93
93
|
|
|
94
94
|
## `hsuite deploy`
|
|
95
95
|
|
|
96
|
-
Deploy a smart-app from a JSON manifest via the SDK's
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
Deploy a smart-app image from a JSON manifest via the SDK's four-step
|
|
97
|
+
runtime-orchestration flow (`init` → `docker push` → optional
|
|
98
|
+
`uploadFrontend` → `deploy`). Use this for CI pipelines that ship a
|
|
99
|
+
container image to the cluster.
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
102
|
hsuite deploy --manifest ./my-app.json --env .env.local
|
|
103
|
+
hsuite deploy --manifest ./my-app.json --env .env.local --non-interactive # for CI
|
|
103
104
|
```
|
|
104
105
|
|
|
105
106
|
`my-app.json`:
|
|
106
107
|
|
|
107
108
|
```json
|
|
108
109
|
{
|
|
109
|
-
"name": "
|
|
110
|
+
"name": "my-smart-app",
|
|
111
|
+
"port": 3000,
|
|
112
|
+
"tag": "v1",
|
|
113
|
+
"replicas": 1,
|
|
110
114
|
"services": ["database", "storage", "messaging", "functions"],
|
|
111
|
-
"
|
|
112
|
-
|
|
113
|
-
}
|
|
115
|
+
"env": { "NODE_ENV": "production" },
|
|
116
|
+
"frontend": { "bundlePath": "./dist/bundle.tar.gz" }
|
|
114
117
|
}
|
|
115
118
|
```
|
|
116
119
|
|
|
120
|
+
What the command does, in order:
|
|
121
|
+
|
|
122
|
+
1. **`deployment.init`** — cluster allocates the `appId` (per-entity DKG
|
|
123
|
+
entityId) and returns ephemeral DOCR push credentials.
|
|
124
|
+
2. **(out-of-band)** the CLI prints the `docker login` + `docker push`
|
|
125
|
+
commands and waits for Enter (skipped with `--non-interactive`,
|
|
126
|
+
`CI=true`, or no TTY — the caller is assumed to have completed the
|
|
127
|
+
push).
|
|
128
|
+
3. **`deployment.uploadFrontend`** — if `frontend.bundlePath` is set, the
|
|
129
|
+
tarball is uploaded.
|
|
130
|
+
4. **`deployment.deploy`** — the cluster reconciles the requested `tag`
|
|
131
|
+
+ `replicas` + `env` to k8s.
|
|
132
|
+
|
|
117
133
|
The returned `appId` is appended to `.env.local` as `DEPLOYED_APP_ID`.
|
|
118
134
|
|
|
119
135
|
---
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `hsuite deploy` — Deploy a smart-app from a JSON manifest.
|
|
3
|
+
*
|
|
4
|
+
* Implements the four-step runtime-deploy flow defined in
|
|
5
|
+
* `docs/superpowers/specs/2026-05-14-smart-app-runtime-orchestration-design.md` §6.1:
|
|
6
|
+
*
|
|
7
|
+
* 1. `init` → server allocates appId + ephemeral DOCR creds
|
|
8
|
+
* 2. (out-of-band, manual) → customer `docker push <repo>:<tag>`
|
|
9
|
+
* 3. `uploadFrontend` (opt.) → tarball with the SPA bundle
|
|
10
|
+
* 4. `deploy` → server reconciles to k8s
|
|
11
|
+
*
|
|
12
|
+
* The manifest schema widens to include `image`, `port`, `tag`, `replicas`,
|
|
13
|
+
* `env`, and an optional `frontend.bundlePath`. Between init and deploy the
|
|
14
|
+
* CLI prints the docker push command and waits for Enter (skipped in CI /
|
|
15
|
+
* with `--non-interactive`).
|
|
3
16
|
*/
|
|
4
17
|
import { Command } from 'commander';
|
|
5
18
|
export declare const deployCommand: Command;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+DpC,eAAO,MAAM,aAAa,SA6HtB,CAAC"}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -6,19 +39,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
39
|
exports.deployCommand = void 0;
|
|
7
40
|
/**
|
|
8
41
|
* `hsuite deploy` — Deploy a smart-app from a JSON manifest.
|
|
42
|
+
*
|
|
43
|
+
* Implements the four-step runtime-deploy flow defined in
|
|
44
|
+
* `docs/superpowers/specs/2026-05-14-smart-app-runtime-orchestration-design.md` §6.1:
|
|
45
|
+
*
|
|
46
|
+
* 1. `init` → server allocates appId + ephemeral DOCR creds
|
|
47
|
+
* 2. (out-of-band, manual) → customer `docker push <repo>:<tag>`
|
|
48
|
+
* 3. `uploadFrontend` (opt.) → tarball with the SPA bundle
|
|
49
|
+
* 4. `deploy` → server reconciles to k8s
|
|
50
|
+
*
|
|
51
|
+
* The manifest schema widens to include `image`, `port`, `tag`, `replicas`,
|
|
52
|
+
* `env`, and an optional `frontend.bundlePath`. Between init and deploy the
|
|
53
|
+
* CLI prints the docker push command and waits for Enter (skipped in CI /
|
|
54
|
+
* with `--non-interactive`).
|
|
9
55
|
*/
|
|
10
56
|
const commander_1 = require("commander");
|
|
11
57
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
58
|
const ora_1 = __importDefault(require("ora"));
|
|
13
59
|
const fs_1 = require("fs");
|
|
14
60
|
const path_1 = require("path");
|
|
61
|
+
const readline = __importStar(require("readline"));
|
|
15
62
|
const smart_engines_sdk_1 = require("@hsuite/smart-engines-sdk");
|
|
16
63
|
const env_1 = require("../_lib/env");
|
|
64
|
+
/**
|
|
65
|
+
* Block until the user presses Enter on stdin. Skipped in non-interactive
|
|
66
|
+
* mode (env `CI=true`, no TTY, or `--non-interactive` flag) — caller is
|
|
67
|
+
* assumed to have completed the docker push before invoking the CLI.
|
|
68
|
+
*/
|
|
69
|
+
async function waitForEnter() {
|
|
70
|
+
return new Promise((res) => {
|
|
71
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
72
|
+
rl.question('', () => {
|
|
73
|
+
rl.close();
|
|
74
|
+
res();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function isNonInteractive(flag) {
|
|
79
|
+
if (flag)
|
|
80
|
+
return true;
|
|
81
|
+
if (process.env.CI === 'true')
|
|
82
|
+
return true;
|
|
83
|
+
if (!process.stdin.isTTY)
|
|
84
|
+
return true;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
17
87
|
exports.deployCommand = new commander_1.Command('deploy')
|
|
18
|
-
.description('Deploy a smart-app from a JSON manifest')
|
|
88
|
+
.description('Deploy a smart-app from a JSON manifest (init → push → deploy)')
|
|
19
89
|
.requiredOption('--manifest <file>', 'JSON manifest path')
|
|
20
90
|
.option('--env <file>', 'Env file with auth creds', '.env.local')
|
|
21
91
|
.option('--gateway <url>', 'Smart-engines gateway URL', 'https://v3-testnet-gateway.hsuite.network')
|
|
92
|
+
.option('--non-interactive', 'Skip the wait-for-Enter between init and deploy', false)
|
|
22
93
|
.action(async (opts) => {
|
|
23
94
|
console.log(chalk_1.default.bold.cyan('\n hsuite deploy\n'));
|
|
24
95
|
const manifestPath = (0, path_1.resolve)(opts.manifest);
|
|
@@ -27,13 +98,18 @@ exports.deployCommand = new commander_1.Command('deploy')
|
|
|
27
98
|
process.exit(1);
|
|
28
99
|
}
|
|
29
100
|
const manifest = JSON.parse((0, fs_1.readFileSync)(manifestPath, 'utf8'));
|
|
30
|
-
if (!manifest.name ||
|
|
31
|
-
|
|
101
|
+
if (!manifest.name ||
|
|
102
|
+
typeof manifest.port !== 'number' ||
|
|
103
|
+
!Array.isArray(manifest.services) ||
|
|
104
|
+
!manifest.tag) {
|
|
105
|
+
console.error(chalk_1.default.red(` manifest must have at minimum {name, port, services[], tag}\n`));
|
|
32
106
|
process.exit(1);
|
|
33
107
|
}
|
|
34
108
|
console.log(chalk_1.default.gray(` manifest: ${manifestPath}`));
|
|
35
109
|
console.log(chalk_1.default.gray(` name: ${manifest.name}`));
|
|
36
|
-
console.log(chalk_1.default.gray(`
|
|
110
|
+
console.log(chalk_1.default.gray(` port: ${manifest.port}`));
|
|
111
|
+
console.log(chalk_1.default.gray(` services: ${manifest.services.join(', ') || '(none)'}`));
|
|
112
|
+
console.log(chalk_1.default.gray(` tag: ${manifest.tag}`));
|
|
37
113
|
console.log(chalk_1.default.gray(` gateway: ${opts.gateway}\n`));
|
|
38
114
|
const env = (0, env_1.readEnv)(opts.env);
|
|
39
115
|
const signer = (0, env_1.buildSignerFromEnv)(env);
|
|
@@ -57,21 +133,67 @@ exports.deployCommand = new commander_1.Command('deploy')
|
|
|
57
133
|
process.exit(1);
|
|
58
134
|
}
|
|
59
135
|
spinner.succeed('authenticated');
|
|
60
|
-
|
|
61
|
-
|
|
136
|
+
// ── Step 1: init ──────────────────────────────────────────────────
|
|
137
|
+
spinner = (0, ora_1.default)('init...').start();
|
|
138
|
+
let init;
|
|
62
139
|
try {
|
|
63
|
-
|
|
140
|
+
init = await client.deployment.init({
|
|
64
141
|
name: manifest.name,
|
|
142
|
+
port: manifest.port,
|
|
65
143
|
services: manifest.services,
|
|
66
|
-
|
|
144
|
+
limits: manifest.limits,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
spinner.fail(`init failed: ${err.message}`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
spinner.succeed(`init: appId=${init.appId} registry=${init.registry.repository}`);
|
|
152
|
+
// ── Step 2 (out-of-band): docker push ─────────────────────────────
|
|
153
|
+
console.log(chalk_1.default.bold.yellow('\n → push your image now:'));
|
|
154
|
+
console.log(` echo ${JSON.stringify(init.registry.password)} | docker login ${init.registry.server} -u ${init.registry.username} --password-stdin`);
|
|
155
|
+
console.log(` docker push ${init.registry.server}/${init.registry.repository}:${manifest.tag}`);
|
|
156
|
+
if (!isNonInteractive(opts.nonInteractive)) {
|
|
157
|
+
console.log(chalk_1.default.bold.yellow('\n → press Enter when push is complete'));
|
|
158
|
+
await waitForEnter();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.log(chalk_1.default.gray(' (non-interactive: assuming push already complete)'));
|
|
162
|
+
}
|
|
163
|
+
// ── Step 3 (optional): upload frontend ────────────────────────────
|
|
164
|
+
if (manifest.frontend?.bundlePath) {
|
|
165
|
+
const bundlePath = (0, path_1.resolve)(manifest.frontend.bundlePath);
|
|
166
|
+
if (!(0, fs_1.existsSync)(bundlePath)) {
|
|
167
|
+
console.error(chalk_1.default.red(` frontend bundle not found: ${bundlePath}\n`));
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
spinner = (0, ora_1.default)('uploading frontend bundle...').start();
|
|
171
|
+
try {
|
|
172
|
+
const bundle = await fs_1.promises.readFile(bundlePath);
|
|
173
|
+
const upload = await client.deployment.uploadFrontend(init.appId, bundle);
|
|
174
|
+
spinner.succeed(`frontend uploaded: sha256=${upload.bundleSha256.slice(0, 12)}…`);
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
spinner.fail(`frontend upload failed: ${err.message}`);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// ── Step 4: deploy ────────────────────────────────────────────────
|
|
182
|
+
spinner = (0, ora_1.default)('deploying...').start();
|
|
183
|
+
let deployRes;
|
|
184
|
+
try {
|
|
185
|
+
deployRes = await client.deployment.deploy(init.appId, {
|
|
186
|
+
tag: manifest.tag,
|
|
187
|
+
replicas: manifest.replicas ?? 1,
|
|
188
|
+
env: manifest.env,
|
|
67
189
|
});
|
|
68
190
|
}
|
|
69
191
|
catch (err) {
|
|
70
192
|
spinner.fail(`deploy failed: ${err.message}`);
|
|
71
193
|
process.exit(1);
|
|
72
194
|
}
|
|
73
|
-
spinner.succeed(`deployed:
|
|
74
|
-
(0, env_1.upsertEnv)(opts.env, { DEPLOYED_APP_ID:
|
|
195
|
+
spinner.succeed(`deployed: ${deployRes.url}`);
|
|
196
|
+
(0, env_1.upsertEnv)(opts.env, { DEPLOYED_APP_ID: init.appId });
|
|
75
197
|
console.log(chalk_1.default.bold.green('\n ✓ done\n'));
|
|
76
198
|
});
|
|
77
199
|
//# sourceMappingURL=deploy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,2BAA8D;AAC9D,+BAA+B;AAC/B,mDAAqC;AACrC,iEAAuD;AAIvD,qCAAqE;AA+BrE;;;;GAIG;AACH,KAAK,UAAU,YAAY;IACzB,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE;YACnB,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,GAAG,EAAE,CAAC;QACR,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAyB;IACjD,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IACtB,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACtC,OAAO,KAAK,CAAC;AACf,CAAC;AAEY,QAAA,aAAa,GAAG,IAAI,mBAAO,CAAC,QAAQ,CAAC;KAC/C,WAAW,CAAC,gEAAgE,CAAC;KAC7E,cAAc,CAAC,mBAAmB,EAAE,oBAAoB,CAAC;KACzD,MAAM,CAAC,cAAc,EAAE,0BAA0B,EAAE,YAAY,CAAC;KAChE,M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AAG,EAAC,cAAc,CAAC,CAAC,KAAK,EAAE,CAAC;IACtC,IAAI,SAAS,CAAC;IACd,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE;YACrD,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,IAAI,CAAC;YAChC,GAAG,EAAE,QAAQ,CAAC,GAAG;SAClB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,kBAAmB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,OAAO,CAAC,aAAa,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;IAE9C,IAAA,eAAS,EAAC,IAAI,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hsuite governance simulate` — dry-run a `GovernanceMolecule.validate(...)`
|
|
3
|
+
* against fixture data without depending on the rules-engine package.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* hsuite governance simulate --proposal <file> [--server <url>] [--format json|plain]
|
|
7
|
+
*
|
|
8
|
+
* The `<file>` is a JSON document of shape `{ config, context }` matching the
|
|
9
|
+
* SDK's `GovernanceSimulateRequest` type.
|
|
10
|
+
*
|
|
11
|
+
* Exit codes:
|
|
12
|
+
* 0 — `result.isValid === true`
|
|
13
|
+
* 1 — `result.isValid === false` (proposal/vote/etc. rejected by the molecule)
|
|
14
|
+
* 2 — input or transport error (missing file, malformed JSON, HTTP failure)
|
|
15
|
+
*/
|
|
16
|
+
import { Command } from 'commander';
|
|
17
|
+
import { SmartEngineClient } from '@hsuite/smart-engines-sdk';
|
|
18
|
+
/**
|
|
19
|
+
* Internal SDK builder — exposed for tests to inject a stub.
|
|
20
|
+
*
|
|
21
|
+
* Each call returns a `SmartEngineClient` configured for the given server.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildSdkClient(server: string): SmartEngineClient;
|
|
24
|
+
/**
|
|
25
|
+
* Pure logic separated from `commander` for testability.
|
|
26
|
+
*
|
|
27
|
+
* Returns the exit code rather than calling `process.exit`. The action
|
|
28
|
+
* handler wraps this and exits.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runGovernanceSimulate(opts: {
|
|
31
|
+
proposal: string;
|
|
32
|
+
server?: string;
|
|
33
|
+
format?: 'json' | 'plain';
|
|
34
|
+
/** Test seam — override the SDK constructor. */
|
|
35
|
+
clientFactory?: (server: string) => Pick<SmartEngineClient, 'governance'>;
|
|
36
|
+
/** Test seam — capture stdout instead of writing to process. */
|
|
37
|
+
out?: (line: string) => void;
|
|
38
|
+
/** Test seam — capture stderr instead of writing to process. */
|
|
39
|
+
err?: (line: string) => void;
|
|
40
|
+
}): Promise<number>;
|
|
41
|
+
export declare const governanceCommand: Command;
|
|
42
|
+
//# sourceMappingURL=governance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governance.d.ts","sourceRoot":"","sources":["../../src/commands/governance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAiD9D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAKhE;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,gDAAgD;IAChD,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;IAC1E,gEAAgE;IAChE,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,gEAAgE;IAChE,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CA+ClB;AAED,eAAO,MAAM,iBAAiB,SAiB3B,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
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.governanceCommand = void 0;
|
|
7
|
+
exports.buildSdkClient = buildSdkClient;
|
|
8
|
+
exports.runGovernanceSimulate = runGovernanceSimulate;
|
|
9
|
+
/**
|
|
10
|
+
* `hsuite governance simulate` — dry-run a `GovernanceMolecule.validate(...)`
|
|
11
|
+
* against fixture data without depending on the rules-engine package.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* hsuite governance simulate --proposal <file> [--server <url>] [--format json|plain]
|
|
15
|
+
*
|
|
16
|
+
* The `<file>` is a JSON document of shape `{ config, context }` matching the
|
|
17
|
+
* SDK's `GovernanceSimulateRequest` type.
|
|
18
|
+
*
|
|
19
|
+
* Exit codes:
|
|
20
|
+
* 0 — `result.isValid === true`
|
|
21
|
+
* 1 — `result.isValid === false` (proposal/vote/etc. rejected by the molecule)
|
|
22
|
+
* 2 — input or transport error (missing file, malformed JSON, HTTP failure)
|
|
23
|
+
*/
|
|
24
|
+
const commander_1 = require("commander");
|
|
25
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
26
|
+
const fs_1 = require("fs");
|
|
27
|
+
const path_1 = require("path");
|
|
28
|
+
const smart_engines_sdk_1 = require("@hsuite/smart-engines-sdk");
|
|
29
|
+
const DEFAULT_SERVER = 'https://v3-testnet-gateway.hsuite.network';
|
|
30
|
+
/** Exit-code-bearing error so the action handler can branch precisely. */
|
|
31
|
+
class CliExit extends Error {
|
|
32
|
+
code;
|
|
33
|
+
constructor(code, message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.code = code;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function readProposal(file) {
|
|
39
|
+
const path = (0, path_1.resolve)(file);
|
|
40
|
+
if (!(0, fs_1.existsSync)(path)) {
|
|
41
|
+
throw new CliExit(2, `proposal file not found: ${path}`);
|
|
42
|
+
}
|
|
43
|
+
let raw;
|
|
44
|
+
try {
|
|
45
|
+
raw = (0, fs_1.readFileSync)(path, 'utf8');
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
throw new CliExit(2, `unable to read proposal file: ${err.message}`);
|
|
49
|
+
}
|
|
50
|
+
let parsed;
|
|
51
|
+
try {
|
|
52
|
+
parsed = JSON.parse(raw);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
throw new CliExit(2, `malformed JSON in proposal file: ${err.message}`);
|
|
56
|
+
}
|
|
57
|
+
if (!parsed ||
|
|
58
|
+
typeof parsed !== 'object' ||
|
|
59
|
+
!('config' in parsed) ||
|
|
60
|
+
!('context' in parsed)) {
|
|
61
|
+
throw new CliExit(2, 'proposal file must be JSON with shape { "config": {...}, "context": {...} }');
|
|
62
|
+
}
|
|
63
|
+
return parsed;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Internal SDK builder — exposed for tests to inject a stub.
|
|
67
|
+
*
|
|
68
|
+
* Each call returns a `SmartEngineClient` configured for the given server.
|
|
69
|
+
*/
|
|
70
|
+
function buildSdkClient(server) {
|
|
71
|
+
return new smart_engines_sdk_1.SmartEngineClient({
|
|
72
|
+
baseUrl: server,
|
|
73
|
+
allowInsecure: server.startsWith('http://'),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Pure logic separated from `commander` for testability.
|
|
78
|
+
*
|
|
79
|
+
* Returns the exit code rather than calling `process.exit`. The action
|
|
80
|
+
* handler wraps this and exits.
|
|
81
|
+
*/
|
|
82
|
+
async function runGovernanceSimulate(opts) {
|
|
83
|
+
const write = opts.out ?? ((line) => console.log(line));
|
|
84
|
+
const writeErr = opts.err ?? ((line) => console.error(line));
|
|
85
|
+
const server = opts.server ?? DEFAULT_SERVER;
|
|
86
|
+
const format = opts.format ?? 'plain';
|
|
87
|
+
let request;
|
|
88
|
+
try {
|
|
89
|
+
request = readProposal(opts.proposal);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
if (err instanceof CliExit) {
|
|
93
|
+
writeErr(chalk_1.default.red(` ${err.message}`));
|
|
94
|
+
return err.code;
|
|
95
|
+
}
|
|
96
|
+
writeErr(chalk_1.default.red(` unexpected error: ${err.message}`));
|
|
97
|
+
return 2;
|
|
98
|
+
}
|
|
99
|
+
const client = (opts.clientFactory ?? buildSdkClient)(server);
|
|
100
|
+
let result;
|
|
101
|
+
try {
|
|
102
|
+
result = await client.governance.simulate(request);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
writeErr(chalk_1.default.red(` simulate failed: ${err.message}`));
|
|
106
|
+
return 2;
|
|
107
|
+
}
|
|
108
|
+
if (format === 'json') {
|
|
109
|
+
write(JSON.stringify(result, null, 2));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const status = result.isValid
|
|
113
|
+
? chalk_1.default.bold.green('VALID')
|
|
114
|
+
: chalk_1.default.bold.red('INVALID');
|
|
115
|
+
write(` ${status}`);
|
|
116
|
+
if (result.reason) {
|
|
117
|
+
write(chalk_1.default.gray(` reason: ${result.reason}`));
|
|
118
|
+
}
|
|
119
|
+
if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
120
|
+
write(chalk_1.default.gray(` metadata: ${JSON.stringify(result.metadata)}`));
|
|
121
|
+
}
|
|
122
|
+
if (result.validatedAt) {
|
|
123
|
+
write(chalk_1.default.gray(` validated: ${result.validatedAt}`));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result.isValid ? 0 : 1;
|
|
127
|
+
}
|
|
128
|
+
exports.governanceCommand = new commander_1.Command('governance')
|
|
129
|
+
.description('Governance proposal dry-run')
|
|
130
|
+
.addCommand(new commander_1.Command('simulate')
|
|
131
|
+
.description('Dry-run a GovernanceMolecule.validate(...) against a fixture file')
|
|
132
|
+
.requiredOption('--proposal <file>', 'JSON file with shape { config, context }')
|
|
133
|
+
.option('--server <url>', 'Validator base URL', DEFAULT_SERVER)
|
|
134
|
+
.option('--format <format>', 'Output format: json | plain', 'plain')
|
|
135
|
+
.action(async (opts) => {
|
|
136
|
+
const format = opts.format === 'json' ? 'json' : 'plain';
|
|
137
|
+
const code = await runGovernanceSimulate({
|
|
138
|
+
proposal: opts.proposal,
|
|
139
|
+
server: opts.server,
|
|
140
|
+
format,
|
|
141
|
+
});
|
|
142
|
+
process.exit(code);
|
|
143
|
+
}));
|
|
144
|
+
//# sourceMappingURL=governance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governance.js","sourceRoot":"","sources":["../../src/commands/governance.ts"],"names":[],"mappings":";;;;;;AAyEA,wCAKC;AAQD,sDAyDC;AA/ID;;;;;;;;;;;;;;GAcG;AACH,yCAAoC;AACpC,kDAA0B;AAC1B,2BAA8C;AAC9C,+BAA+B;AAC/B,iEAA8D;AAM9D,MAAM,cAAc,GAAG,2CAA2C,CAAC;AAEnE,0EAA0E;AAC1E,MAAM,OAAQ,SAAQ,KAAK;IAEP;IADlB,YACkB,IAAY,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,CACT,IAAI,mBAAO,CAAC,UAAU,CAAC;KACpB,WAAW,CAAC,mEAAmE,CAAC;KAChF,cAAc,CAAC,mBAAmB,EAAE,0CAA0C,CAAC;KAC/E,MAAM,CAAC,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,CAAC;KAC9D,MAAM,CAAC,mBAAmB,EAAE,6BAA6B,EAAE,OAAO,CAAC;KACnE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACrB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACzD,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC;QACvC,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM;KACP,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC,CACL,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hsuite hist-balance query` — ad-hoc historical-balance query.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the SDK's `HistoricalBalanceClient` so operators / smart-app devs
|
|
5
|
+
* can sanity-check archive reads from a terminal without writing a script:
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* hsuite hist-balance query \
|
|
9
|
+
* --chain hedera \
|
|
10
|
+
* --entity 0.0.5555 \
|
|
11
|
+
* --account 0.0.1234 \
|
|
12
|
+
* --at 1700000000 \
|
|
13
|
+
* --server https://validator.example.com
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Exit codes:
|
|
17
|
+
* 0 success
|
|
18
|
+
* 1 input error (missing/invalid flag, unsupported chain, etc.)
|
|
19
|
+
* 2 transport or server error (network, 4xx, 5xx)
|
|
20
|
+
*
|
|
21
|
+
* Zero internal `@hsuite/*` deps beyond `@hsuite/smart-engines-sdk`, which
|
|
22
|
+
* itself is decoupled from server-side libs by design (PR-CLEANUP #576).
|
|
23
|
+
*/
|
|
24
|
+
import { Command } from 'commander';
|
|
25
|
+
import { HistoricalBalanceClient } from '@hsuite/smart-engines-sdk';
|
|
26
|
+
type RunArgs = {
|
|
27
|
+
chain?: string;
|
|
28
|
+
entity?: string;
|
|
29
|
+
account?: string;
|
|
30
|
+
at?: string;
|
|
31
|
+
server?: string;
|
|
32
|
+
format?: string;
|
|
33
|
+
authToken?: string;
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Pure-function core (no `process.exit`, no `console.log`) so tests can
|
|
38
|
+
* exercise the full code path and assert on the returned exit code +
|
|
39
|
+
* captured streams.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runHistBalanceQuery(args: RunArgs, io: {
|
|
42
|
+
out: (msg: string) => void;
|
|
43
|
+
err: (msg: string) => void;
|
|
44
|
+
sdk?: (config: {
|
|
45
|
+
baseUrl: string;
|
|
46
|
+
authToken?: string;
|
|
47
|
+
apiKey?: string;
|
|
48
|
+
}) => Pick<HistoricalBalanceClient, 'getBalance'>;
|
|
49
|
+
}): Promise<number>;
|
|
50
|
+
export declare const histBalanceCommand: Command;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=hist-balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hist-balance.d.ts","sourceRoot":"","sources":["../../src/commands/hist-balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,uBAAuB,EAGxB,MAAM,2BAA2B,CAAC;AAEnC,KAAK,OAAO,GAAG;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,OAAO,EACb,EAAE,EAAE;IACF,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3B,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3B,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,KAAK,IAAI,CAAC,uBAAuB,EAAE,YAAY,CAAC,CAAC;CACnD,GACA,OAAO,CAAC,MAAM,CAAC,CA6FjB;AAED,eAAO,MAAM,kBAAkB,SAE9B,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `hsuite hist-balance query` — ad-hoc historical-balance query.
|
|
4
|
+
*
|
|
5
|
+
* Wraps the SDK's `HistoricalBalanceClient` so operators / smart-app devs
|
|
6
|
+
* can sanity-check archive reads from a terminal without writing a script:
|
|
7
|
+
*
|
|
8
|
+
* ```
|
|
9
|
+
* hsuite hist-balance query \
|
|
10
|
+
* --chain hedera \
|
|
11
|
+
* --entity 0.0.5555 \
|
|
12
|
+
* --account 0.0.1234 \
|
|
13
|
+
* --at 1700000000 \
|
|
14
|
+
* --server https://validator.example.com
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Exit codes:
|
|
18
|
+
* 0 success
|
|
19
|
+
* 1 input error (missing/invalid flag, unsupported chain, etc.)
|
|
20
|
+
* 2 transport or server error (network, 4xx, 5xx)
|
|
21
|
+
*
|
|
22
|
+
* Zero internal `@hsuite/*` deps beyond `@hsuite/smart-engines-sdk`, which
|
|
23
|
+
* itself is decoupled from server-side libs by design (PR-CLEANUP #576).
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.histBalanceCommand = void 0;
|
|
27
|
+
exports.runHistBalanceQuery = runHistBalanceQuery;
|
|
28
|
+
const commander_1 = require("commander");
|
|
29
|
+
const smart_engines_sdk_1 = require("@hsuite/smart-engines-sdk");
|
|
30
|
+
/**
|
|
31
|
+
* Pure-function core (no `process.exit`, no `console.log`) so tests can
|
|
32
|
+
* exercise the full code path and assert on the returned exit code +
|
|
33
|
+
* captured streams.
|
|
34
|
+
*/
|
|
35
|
+
async function runHistBalanceQuery(args, io) {
|
|
36
|
+
// ── Input validation ──────────────────────────────────────────────────
|
|
37
|
+
const chain = args.chain;
|
|
38
|
+
if (chain !== 'hedera' && chain !== 'xrpl' && chain !== 'polkadot') {
|
|
39
|
+
io.err(`error: --chain must be one of hedera | xrpl | polkadot (received: ${chain ?? '<missing>'})`);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
const entity = args.entity;
|
|
43
|
+
if (!entity || typeof entity !== 'string') {
|
|
44
|
+
io.err('error: --entity is required');
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
const account = args.account;
|
|
48
|
+
if (!account || typeof account !== 'string') {
|
|
49
|
+
io.err('error: --account is required');
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
if (args.at === undefined || args.at === '') {
|
|
53
|
+
io.err('error: --at is required (unix seconds, positive integer)');
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
const atNum = Number(args.at);
|
|
57
|
+
if (!Number.isInteger(atNum) || atNum <= 0) {
|
|
58
|
+
io.err(`error: --at must be a positive integer (received: ${args.at})`);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
const server = args.server ?? process.env.VALIDATOR_URL ?? process.env.SMART_HOST_URL;
|
|
62
|
+
if (!server) {
|
|
63
|
+
io.err('error: --server is required (or set VALIDATOR_URL / SMART_HOST_URL env)');
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
const format = args.format ?? 'plain';
|
|
67
|
+
if (format !== 'plain' && format !== 'json') {
|
|
68
|
+
io.err(`error: --format must be plain | json (received: ${format})`);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const authToken = args.authToken ?? process.env.VALIDATOR_AUTH_TOKEN;
|
|
72
|
+
const apiKey = args.apiKey ?? process.env.VALIDATOR_API_KEY;
|
|
73
|
+
// ── Build SDK client ──────────────────────────────────────────────────
|
|
74
|
+
const factory = io.sdk ??
|
|
75
|
+
((cfg) => new smart_engines_sdk_1.HistoricalBalanceClient({
|
|
76
|
+
baseUrl: cfg.baseUrl,
|
|
77
|
+
authToken: cfg.authToken,
|
|
78
|
+
apiKey: cfg.apiKey,
|
|
79
|
+
}));
|
|
80
|
+
const client = factory({ baseUrl: server, authToken, apiKey });
|
|
81
|
+
// ── Call ──────────────────────────────────────────────────────────────
|
|
82
|
+
try {
|
|
83
|
+
const result = await client.getBalance({
|
|
84
|
+
chain: chain,
|
|
85
|
+
entityId: entity,
|
|
86
|
+
account,
|
|
87
|
+
atTimestamp: atNum,
|
|
88
|
+
});
|
|
89
|
+
if (format === 'json') {
|
|
90
|
+
io.out(JSON.stringify(result, null, 2));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
io.out(`chain: ${result.chain}`);
|
|
94
|
+
io.out(`entity: ${result.entityId}`);
|
|
95
|
+
io.out(`account: ${result.account}`);
|
|
96
|
+
io.out(`atTimestamp: ${result.atTimestamp}`);
|
|
97
|
+
io.out(`balance: ${result.balance}`);
|
|
98
|
+
io.out(`source: ${result.source}`);
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err instanceof smart_engines_sdk_1.HistoricalBalanceClientError) {
|
|
104
|
+
// Client-side validation is also surfaced as HistoricalBalanceClientError
|
|
105
|
+
// with statusCode=400; treat 4xx as input errors, 5xx / 0 as transport.
|
|
106
|
+
const isInputError = err.statusCode >= 400 && err.statusCode < 500;
|
|
107
|
+
io.err(`error: ${err.message} (status=${err.statusCode})`);
|
|
108
|
+
return isInputError ? 1 : 2;
|
|
109
|
+
}
|
|
110
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
111
|
+
io.err(`error: ${message}`);
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.histBalanceCommand = new commander_1.Command('hist-balance').description('Query historical balances against the validator archive endpoint');
|
|
116
|
+
exports.histBalanceCommand
|
|
117
|
+
.command('query')
|
|
118
|
+
.description('Look up a point-in-time balance for an account / entity / chain')
|
|
119
|
+
.requiredOption('--chain <chain>', 'Chain: hedera | xrpl | polkadot')
|
|
120
|
+
.requiredOption('--entity <id>', 'Chain-native token / IOU / asset id')
|
|
121
|
+
.requiredOption('--account <addr>', 'Chain-native holder address')
|
|
122
|
+
.requiredOption('--at <unixSeconds>', 'Unix timestamp in seconds (positive integer)')
|
|
123
|
+
.option('--server <url>', 'Validator base URL (default: $VALIDATOR_URL or $SMART_HOST_URL)')
|
|
124
|
+
.option('--format <format>', 'Output format: plain | json', 'plain')
|
|
125
|
+
.option('--auth-token <token>', 'Bearer token (default: $VALIDATOR_AUTH_TOKEN)')
|
|
126
|
+
.option('--api-key <key>', 'API key (default: $VALIDATOR_API_KEY)')
|
|
127
|
+
.action(async (opts) => {
|
|
128
|
+
const code = await runHistBalanceQuery(opts, {
|
|
129
|
+
out: (m) => console.log(m),
|
|
130
|
+
err: (m) => console.error(m),
|
|
131
|
+
});
|
|
132
|
+
process.exit(code);
|
|
133
|
+
});
|
|
134
|
+
//# sourceMappingURL=hist-balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hist-balance.js","sourceRoot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,CAAC,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAEY,QAAA,kBAAkB,GAAG,IAAI,mBAAO,CAAC,cAAc,CAAC,CAAC,WAAW,CACvE,kEAAkE,CACnE,CAAC;AAEF,0BAAkB;KACf,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,iEAAiE,CAAC;KAC9E,cAAc,CAAC,iBAAiB,EAAE,iCAAiC,CAAC;KACpE,cAAc,CAAC,eAAe,EAAE,qCAAqC,CAAC;KACtE,cAAc,CAAC,kBAAkB,EAAE,6BAA6B,CAAC;KACjE,cAAc,CAAC,oBAAoB,EAAE,8CAA8C,CAAC;KACpF,MAAM,CACL,gBAAgB,EAChB,iEAAiE,CAClE;KACA,MAAM,CAAC,mBAAmB,EAAE,6BAA6B,EAAE,OAAO,CAAC;KACnE,MAAM,CAAC,sBAAsB,EAAE,+CAA+C,CAAC;KAC/E,MAAM,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;KAClE,MAAM,CAAC,KAAK,EAAE,IAAa,EAAE,EAAE;IAC9B,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE;QAC3C,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1B,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;KAC7B,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hsuite personhood verify` — verify a personhood proof against the cluster.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around the SDK's `PersonhoodClient`. Reads a JSON proof from
|
|
5
|
+
* disk, POSTs to the validator, and prints the resulting cert (or `null`)
|
|
6
|
+
* to stdout or `--out`.
|
|
7
|
+
*
|
|
8
|
+
* Exit codes:
|
|
9
|
+
* 0 cert issued (printed to stdout / --out)
|
|
10
|
+
* 0 null cert (info message printed to stderr, body printed to stdout)
|
|
11
|
+
* 1 input error: missing file, malformed JSON, missing --candidate
|
|
12
|
+
* 2 transport error: 5xx, network, timeout
|
|
13
|
+
*
|
|
14
|
+
* The 503 `personhood_verifier_not_configured` envelope is treated as a
|
|
15
|
+
* transport-level error (exit 2) because the hub operator must wire a
|
|
16
|
+
* verifier before this command can succeed.
|
|
17
|
+
*/
|
|
18
|
+
import { Command } from 'commander';
|
|
19
|
+
import { PersonhoodClient } from '@hsuite/smart-engines-sdk';
|
|
20
|
+
/**
|
|
21
|
+
* Internal factory hook — overridable in tests to mock the SDK client.
|
|
22
|
+
* Production callers never set this; the CLI builds a real
|
|
23
|
+
* `SmartEngineClient` against `--server`.
|
|
24
|
+
*/
|
|
25
|
+
export type PersonhoodClientFactory = (server: string) => PersonhoodClient;
|
|
26
|
+
/** @internal — for tests only. */
|
|
27
|
+
export declare function __setPersonhoodClientFactory(factory: PersonhoodClientFactory): void;
|
|
28
|
+
/** @internal — for tests only. */
|
|
29
|
+
export declare function __resetPersonhoodClientFactory(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Build a fresh `personhood` Command tree. Commander Command instances
|
|
32
|
+
* accumulate state across `parseAsync` calls (parsed option values stick
|
|
33
|
+
* around on the same node), so tests use this factory to get an
|
|
34
|
+
* isolated subtree per test. The bin entrypoint calls it once at startup.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildPersonhoodCommand(): Command;
|
|
37
|
+
/**
|
|
38
|
+
* Default command instance used by the bin entrypoint. Tests build their
|
|
39
|
+
* own via {@link buildPersonhoodCommand}.
|
|
40
|
+
*/
|
|
41
|
+
export declare const personhoodCommand: Command;
|
|
42
|
+
//# sourceMappingURL=personhood.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personhood.d.ts","sourceRoot":"","sources":["../../src/commands/personhood.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EACL,gBAAgB,EAMjB,MAAM,2BAA2B,CAAC;AAEnC;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,gBAAgB,CAAC;AAQ3E,kCAAkC;AAClC,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAEnF;AAED,kCAAkC;AAClC,wBAAgB,8BAA8B,IAAI,IAAI,CAMrD;AA0BD;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CA4EhD;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,SAA2B,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
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.personhoodCommand = void 0;
|
|
7
|
+
exports.__setPersonhoodClientFactory = __setPersonhoodClientFactory;
|
|
8
|
+
exports.__resetPersonhoodClientFactory = __resetPersonhoodClientFactory;
|
|
9
|
+
exports.buildPersonhoodCommand = buildPersonhoodCommand;
|
|
10
|
+
/**
|
|
11
|
+
* `hsuite personhood verify` — verify a personhood proof against the cluster.
|
|
12
|
+
*
|
|
13
|
+
* Thin wrapper around the SDK's `PersonhoodClient`. Reads a JSON proof from
|
|
14
|
+
* disk, POSTs to the validator, and prints the resulting cert (or `null`)
|
|
15
|
+
* to stdout or `--out`.
|
|
16
|
+
*
|
|
17
|
+
* Exit codes:
|
|
18
|
+
* 0 cert issued (printed to stdout / --out)
|
|
19
|
+
* 0 null cert (info message printed to stderr, body printed to stdout)
|
|
20
|
+
* 1 input error: missing file, malformed JSON, missing --candidate
|
|
21
|
+
* 2 transport error: 5xx, network, timeout
|
|
22
|
+
*
|
|
23
|
+
* The 503 `personhood_verifier_not_configured` envelope is treated as a
|
|
24
|
+
* transport-level error (exit 2) because the hub operator must wire a
|
|
25
|
+
* verifier before this command can succeed.
|
|
26
|
+
*/
|
|
27
|
+
const commander_1 = require("commander");
|
|
28
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
29
|
+
const ora_1 = __importDefault(require("ora"));
|
|
30
|
+
const fs_1 = require("fs");
|
|
31
|
+
const path_1 = require("path");
|
|
32
|
+
const smart_engines_sdk_1 = require("@hsuite/smart-engines-sdk");
|
|
33
|
+
let clientFactory = (server) => {
|
|
34
|
+
const allowInsecure = server.startsWith('http://');
|
|
35
|
+
const sdk = new smart_engines_sdk_1.SmartEngineClient({ baseUrl: server, allowInsecure });
|
|
36
|
+
return sdk.personhood;
|
|
37
|
+
};
|
|
38
|
+
/** @internal — for tests only. */
|
|
39
|
+
function __setPersonhoodClientFactory(factory) {
|
|
40
|
+
clientFactory = factory;
|
|
41
|
+
}
|
|
42
|
+
/** @internal — for tests only. */
|
|
43
|
+
function __resetPersonhoodClientFactory() {
|
|
44
|
+
clientFactory = (server) => {
|
|
45
|
+
const allowInsecure = server.startsWith('http://');
|
|
46
|
+
const sdk = new smart_engines_sdk_1.SmartEngineClient({ baseUrl: server, allowInsecure });
|
|
47
|
+
return sdk.personhood;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function loadProof(path) {
|
|
51
|
+
const absPath = (0, path_1.resolve)(path);
|
|
52
|
+
if (!(0, fs_1.existsSync)(absPath)) {
|
|
53
|
+
throw new Error(`proof file not found: ${absPath}`);
|
|
54
|
+
}
|
|
55
|
+
const raw = (0, fs_1.readFileSync)(absPath, 'utf8');
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new Error(`proof file is not valid JSON: ${err.message}`);
|
|
62
|
+
}
|
|
63
|
+
if (!parsed ||
|
|
64
|
+
typeof parsed !== 'object' ||
|
|
65
|
+
typeof parsed.attestationMethod !== 'string') {
|
|
66
|
+
throw new Error('proof file must be a JSON object with an `attestationMethod` string field');
|
|
67
|
+
}
|
|
68
|
+
return parsed;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a fresh `personhood` Command tree. Commander Command instances
|
|
72
|
+
* accumulate state across `parseAsync` calls (parsed option values stick
|
|
73
|
+
* around on the same node), so tests use this factory to get an
|
|
74
|
+
* isolated subtree per test. The bin entrypoint calls it once at startup.
|
|
75
|
+
*/
|
|
76
|
+
function buildPersonhoodCommand() {
|
|
77
|
+
const cmd = new commander_1.Command('personhood').description('Personhood verification (HPP one-human-one-member)');
|
|
78
|
+
cmd
|
|
79
|
+
.command('verify')
|
|
80
|
+
.description('Verify a personhood proof against the cluster')
|
|
81
|
+
.requiredOption('--candidate <addr>', 'address of the human being verified')
|
|
82
|
+
.requiredOption('--proof <file>', 'JSON file containing the PersonhoodProof envelope')
|
|
83
|
+
.option('--out <file>', 'Write cert JSON to this file (default: stdout)')
|
|
84
|
+
.option('--server <url>', 'Validator base URL (default: $VALIDATOR_URL env)')
|
|
85
|
+
.action(async (opts) => {
|
|
86
|
+
const server = opts.server ?? process.env.VALIDATOR_URL;
|
|
87
|
+
if (!server) {
|
|
88
|
+
console.error(chalk_1.default.red(' --server is required (or set VALIDATOR_URL in the environment)\n'));
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
let proof;
|
|
92
|
+
try {
|
|
93
|
+
proof = loadProof(opts.proof);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
console.error(chalk_1.default.red(` ${err.message}\n`));
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const spinner = (0, ora_1.default)(`POST ${server}/api/v3/personhood/verify`).start();
|
|
100
|
+
let cert;
|
|
101
|
+
try {
|
|
102
|
+
const client = clientFactory(server);
|
|
103
|
+
cert = await client.verify({ candidate: opts.candidate, proof });
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
// 503 personhood_verifier_not_configured → operator must wire a
|
|
107
|
+
// verifier; surface as a transport-level failure.
|
|
108
|
+
if ((0, smart_engines_sdk_1.isPersonhoodVerifierNotConfigured)(err)) {
|
|
109
|
+
spinner.fail('personhood verifier is not configured on the cluster');
|
|
110
|
+
process.exit(2);
|
|
111
|
+
}
|
|
112
|
+
if (err instanceof smart_engines_sdk_1.SdkHttpError) {
|
|
113
|
+
spinner.fail(`HTTP ${err.statusCode}: ${err.message}`);
|
|
114
|
+
process.exit(2);
|
|
115
|
+
}
|
|
116
|
+
spinner.fail(`transport error: ${err.message}`);
|
|
117
|
+
process.exit(2);
|
|
118
|
+
}
|
|
119
|
+
if (cert === null) {
|
|
120
|
+
spinner.warn('verification did not produce a cert');
|
|
121
|
+
// The body is still emitted so scripts can pipe / diff a stable JSON
|
|
122
|
+
// shape regardless of the issued/rejected outcome.
|
|
123
|
+
const body = JSON.stringify(null);
|
|
124
|
+
if (opts.out) {
|
|
125
|
+
(0, fs_1.writeFileSync)((0, path_1.resolve)(opts.out), body);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
process.stdout.write(body + '\n');
|
|
129
|
+
}
|
|
130
|
+
// Exit 0: rejection is a valid outcome the caller can branch on.
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
spinner.succeed(`cert issued by ${cert.issuerId}`);
|
|
134
|
+
const body = JSON.stringify(cert, null, 2);
|
|
135
|
+
if (opts.out) {
|
|
136
|
+
(0, fs_1.writeFileSync)((0, path_1.resolve)(opts.out), body);
|
|
137
|
+
console.log(chalk_1.default.gray(` wrote cert → ${opts.out}`));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
process.stdout.write(body + '\n');
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return cmd;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Default command instance used by the bin entrypoint. Tests build their
|
|
147
|
+
* own via {@link buildPersonhoodCommand}.
|
|
148
|
+
*/
|
|
149
|
+
exports.personhoodCommand = buildPersonhoodCommand();
|
|
150
|
+
//# sourceMappingURL=personhood.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personhood.js","sourceRoot":"","sources":["../../src/commands/personhood.ts"],"names":[],"mappings":";;;;;;AA6CA,oEAEC;AAGD,wEAMC;AAgCD,wDA4EC;AApKD;;;;;;;;;;;;;;;;GAgBG;AACH,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,2BAA6D;AAC7D,+BAA+B;AAC/B,iEAOmC;AASnC,IAAI,aAAa,GAA4B,CAAC,MAAc,EAAE,EAAE;IAC9D,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,IAAI,qCAAiB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;IACtE,OAAO,GAAG,CAAC,UAAU,CAAC;AACxB,CAAC,CAAC;AAEF,kCAAkC;AAClC,SAAgB,4BAA4B,CAAC,OAAgC;IAC3E,aAAa,GAAG,OAAO,CAAC;AAC1B,CAAC;AAED,kCAAkC;AAClC,SAAgB,8BAA8B;IAC5C,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE;QACjC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,IAAI,qCAAiB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACtE,OAAO,GAAG,CAAC,UAAU,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,OAAO,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CA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ands/subscribe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../src/commands/subscribe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,eAAO,MAAM,gBAAgB,SAqGzB,CAAC"}
|
|
@@ -35,7 +35,15 @@ exports.subscribeCommand = new commander_1.Command('subscribe')
|
|
|
35
35
|
console.error(chalk_1.default.gray(' hint: run `hsuite init` first\n'));
|
|
36
36
|
process.exit(1);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
// The init endpoint requires a DNS-safe name (lowercase alphanumeric +
|
|
39
|
+
// hyphens, max 63 chars). Normalise the display-name accordingly so a
|
|
40
|
+
// CLI invocation with a free-text APP_NAME doesn't 400 at the boundary.
|
|
41
|
+
const rawAppName = opts.name ?? env.get('APP_NAME') ?? 'smart-app-showcase';
|
|
42
|
+
const appName = rawAppName
|
|
43
|
+
.toLowerCase()
|
|
44
|
+
.replace(/[^a-z0-9-]+/g, '-')
|
|
45
|
+
.replace(/^-+|-+$/g, '')
|
|
46
|
+
.slice(0, 63) || 'smart-app-showcase';
|
|
39
47
|
const services = opts.services
|
|
40
48
|
.split(',')
|
|
41
49
|
.map((s) => s.trim())
|
|
@@ -73,15 +81,22 @@ exports.subscribeCommand = new commander_1.Command('subscribe')
|
|
|
73
81
|
spinner = (0, ora_1.default)('register free_testnet smart-app...').start();
|
|
74
82
|
let result;
|
|
75
83
|
try {
|
|
76
|
-
|
|
84
|
+
// PR-A runtime-orchestration: `deployment.init` is the first step of
|
|
85
|
+
// the four-step deploy flow and the new entry-point for allocating an
|
|
86
|
+
// appId on the cluster. The legacy `BaasClient.register()` +
|
|
87
|
+
// `POST /api/deployment/apps` surface was removed (no backward compat
|
|
88
|
+
// per spec §4 hard rules). `subscribe` does not deploy an image, so
|
|
89
|
+
// we synthesise a reasonable default port — the runtime sub-doc is
|
|
90
|
+
// populated at `deploy` time (PR-D), not at init.
|
|
91
|
+
result = await client.deployment.init({ name: appName, port: 3000, services });
|
|
77
92
|
}
|
|
78
93
|
catch (err) {
|
|
79
94
|
spinner.fail(`register failed: ${err.message}`);
|
|
80
95
|
process.exit(1);
|
|
81
96
|
}
|
|
82
97
|
spinner.succeed(`appId: ${result.appId}`);
|
|
83
|
-
console.log(chalk_1.default.gray(`
|
|
84
|
-
console.log(chalk_1.default.gray(` services: ${
|
|
98
|
+
console.log(chalk_1.default.gray(` registry: ${result.registry.server}/${result.registry.repository}`));
|
|
99
|
+
console.log(chalk_1.default.gray(` services: ${services.join(', ')}`));
|
|
85
100
|
(0, env_1.upsertEnv)(opts.env, {
|
|
86
101
|
SUBSCRIPTION_APP_ID: result.appId,
|
|
87
102
|
APP_ID: result.appId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../../src/commands/subscribe.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;GAMG;AACH,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,iEAAuD;AAGvD,qCAAqE;AAExD,QAAA,gBAAgB,GAAG,IAAI,mBAAO,CAAC,WAAW,CAAC;KACrD,WAAW,CAAC,kDAAkD,CAAC;KAC/D,MAAM,CAAC,cAAc,EAAE,iCAAiC,EAAE,YAAY,CAAC;KACvE,MAAM,CACL,iBAAiB,EACjB,2BAA2B,EAC3B,2CAA2C,CAC5C;KACA,MAAM,CAAC,eAAe,EAAE,wBAAwB,CAAC;KACjD,MAAM,CACL,mBAAmB,EACnB,oCAAoC,EACpC,sCAAsC,CACvC;KACA,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACrB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,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
@@ -54,6 +54,9 @@ const path = __importStar(require("path"));
|
|
|
54
54
|
const init_1 = require("./commands/init");
|
|
55
55
|
const subscribe_1 = require("./commands/subscribe");
|
|
56
56
|
const deploy_1 = require("./commands/deploy");
|
|
57
|
+
const governance_1 = require("./commands/governance");
|
|
58
|
+
const hist_balance_1 = require("./commands/hist-balance");
|
|
59
|
+
const personhood_1 = require("./commands/personhood");
|
|
57
60
|
dotenv.config();
|
|
58
61
|
function getVersion() {
|
|
59
62
|
try {
|
|
@@ -73,6 +76,9 @@ program
|
|
|
73
76
|
program.addCommand(init_1.initCommand);
|
|
74
77
|
program.addCommand(subscribe_1.subscribeCommand);
|
|
75
78
|
program.addCommand(deploy_1.deployCommand);
|
|
79
|
+
program.addCommand(governance_1.governanceCommand);
|
|
80
|
+
program.addCommand(hist_balance_1.histBalanceCommand);
|
|
81
|
+
program.addCommand(personhood_1.personhoodCommand);
|
|
76
82
|
program.parse(process.argv);
|
|
77
83
|
if (!process.argv.slice(2).length) {
|
|
78
84
|
program.outputHelp();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAoC;AACpC,+CAAiC;AACjC,uCAAyB;AACzB,2CAA6B;AAC7B,0CAA8C;AAC9C,oDAAwD;AACxD,8CAAkD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAoC;AACpC,+CAAiC;AACjC,uCAAyB;AACzB,2CAA6B;AAC7B,0CAA8C;AAC9C,oDAAwD;AACxD,8CAAkD;AAClD,sDAA0D;AAC1D,0DAA6D;AAC7D,sDAA0D;AAE1D,MAAM,CAAC,MA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