@jpool/bond-cli 1.1.0 → 1.2.0-next.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/dist/cli.js +46 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -81,7 +81,7 @@ function resolveKeypair(path) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// package.json
|
|
84
|
-
var version = "1.0
|
|
84
|
+
var version = "1.1.0";
|
|
85
85
|
|
|
86
86
|
// src/cli.ts
|
|
87
87
|
import_commander.program.name("jbond").description("CLI to interact with the JPool Bond program").version(process.env.VERSION ?? version).allowExcessArguments(false).option("-c, --cluster <CLUSTER>", "Solana cluster or RPC URL").option("-k, --keypair <KEYPAIR>", "Filepath to Solana keypair").hook("preAction", async (command) => {
|
|
@@ -103,13 +103,28 @@ import_commander.program.command("info").description("Get global state informati
|
|
|
103
103
|
console.log(import_chalk.default.yellow("Global state not initialized"));
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
console.log(import_chalk.default.cyan("Global State
|
|
106
|
+
console.log(import_chalk.default.cyan("====== Global State: ======\n"));
|
|
107
107
|
console.log(import_chalk.default.white(` Authority: ${state.authority}`));
|
|
108
108
|
console.log(import_chalk.default.white(` Reserve: ${state.reserve}`));
|
|
109
109
|
console.log(import_chalk.default.white(` Total Validators: ${state.totalValidators}`));
|
|
110
110
|
console.log(import_chalk.default.white(` Total Compensation Amount: ${state.totalCompensationAmount.toString()}`));
|
|
111
111
|
const epochInfo = await provider.connection.getEpochInfo();
|
|
112
112
|
console.log(import_chalk.default.white(` Current Epoch: ${epochInfo.epoch}`));
|
|
113
|
+
console.log(import_chalk.default.cyan("\n====== Validators: ======\n"));
|
|
114
|
+
const bonds = await client.program.account.validatorBond.all();
|
|
115
|
+
const publicKeys = bonds.map((b) => b.publicKey);
|
|
116
|
+
const bondAccounts = await provider.connection.getMultipleAccountsInfo(publicKeys);
|
|
117
|
+
const bondBalances = bondAccounts.map((acc) => acc?.lamports ?? 0);
|
|
118
|
+
if (bonds.length === 0) {
|
|
119
|
+
console.log(import_chalk.default.dim("No validators found"));
|
|
120
|
+
} else {
|
|
121
|
+
bonds.forEach((b, i) => {
|
|
122
|
+
console.log(import_chalk.default.magenta(prettyJson({
|
|
123
|
+
balance: `${bondBalances[i] / import_web32.LAMPORTS_PER_SOL} SOL`,
|
|
124
|
+
...b
|
|
125
|
+
})));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
113
128
|
} catch (error) {
|
|
114
129
|
console.error(import_chalk.default.red(`Failed to get global state info: ${error}`));
|
|
115
130
|
process.exit(1);
|
|
@@ -314,3 +329,32 @@ import_commander.program.parseAsync().catch((e) => {
|
|
|
314
329
|
}
|
|
315
330
|
process.exit();
|
|
316
331
|
});
|
|
332
|
+
function prettyJson(obj, omitKeys = ["bump"]) {
|
|
333
|
+
const convertValue = (value) => {
|
|
334
|
+
if (value === null || value === void 0) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
if (value && typeof value === "object") {
|
|
341
|
+
if (typeof value.toString === "function" && value.constructor.name !== "Object") {
|
|
342
|
+
return value.toString();
|
|
343
|
+
}
|
|
344
|
+
if (Array.isArray(value)) {
|
|
345
|
+
return value.map((item) => convertValue(item));
|
|
346
|
+
}
|
|
347
|
+
const converted2 = {};
|
|
348
|
+
for (const [k, v] of Object.entries(value)) {
|
|
349
|
+
if (omitKeys.includes(k)) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
converted2[k] = convertValue(v);
|
|
353
|
+
}
|
|
354
|
+
return converted2;
|
|
355
|
+
}
|
|
356
|
+
return String(value);
|
|
357
|
+
};
|
|
358
|
+
const converted = convertValue(obj);
|
|
359
|
+
return JSON.stringify(converted, null, 2);
|
|
360
|
+
}
|