Skip to content

Commit a05e72f

Browse files
committed
integrated saveToFile flag from commit SHA 7aba5b1 of pr 8015
1 parent c6e4829 commit a05e72f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

packages/cli/src/cmds/validator/voluntaryExit.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inquirer from "inquirer";
21
import {Signature} from "@chainsafe/blst";
32
import {ApiClient, getClient} from "@lodestar/api";
43
import {BeaconConfig, createBeaconConfig} from "@lodestar/config";
@@ -11,6 +10,7 @@ import {
1110
import {Epoch, ValidatorIndex, phase0, ssz} from "@lodestar/types";
1211
import {CliCommand, fromHex, toPubkeyHex} from "@lodestar/utils";
1312
import {SignableMessageType, Signer, SignerType, externalSignerPostSignature} from "@lodestar/validator";
13+
import inquirer from "inquirer";
1414
import {getBeaconConfigFromArgs} from "../../config/index.js";
1515
import {GlobalArgs} from "../../options/index.js";
1616
import {YargsError, ensure0xPrefix, wrapError} from "../../util/index.js";
@@ -21,6 +21,7 @@ type VoluntaryExitArgs = {
2121
exitEpoch?: number;
2222
pubkeys?: string[];
2323
yes?: boolean;
24+
saveToFile?: string;
2425
};
2526

2627
export const voluntaryExit: CliCommand<VoluntaryExitArgs, IValidatorCliArgs & GlobalArgs> = {
@@ -65,9 +66,14 @@ If no `pubkeys` are provided, it will exit all validators that have been importe
6566
description: "Skip confirmation prompt",
6667
type: "boolean",
6768
},
69+
70+
saveToFile: {
71+
description: "Path to file where signed voluntary exit(s) will be saved as JSON instead of being published to the network.",
72+
type: "string",
73+
},
6874
},
6975

70-
handler: async (args) => {
76+
handler: async (args: VoluntaryExitArgs & IValidatorCliArgs & GlobalArgs) => {
7177
// Fetch genesisValidatorsRoot always from beacon node
7278
// Do not use known networks cache, it defaults to mainnet for devnets
7379
const {config: chainForkConfig, network} = getBeaconConfigFromArgs(args);
@@ -111,6 +117,7 @@ ${validatorsToExit.map((v) => `${v.pubkey} ${v.index} ${v.status}`).join("\n")}`
111117
}
112118

113119
const alreadySubmitted = [];
120+
const signedExits = [];
114121
for (const [i, validatorToExit] of validatorsToExit.entries()) {
115122
const v: {index: ValidatorIndex; signer: Signer; pubkey: string} = validatorToExit;
116123
let signedVoluntaryExit: phase0.SignedVoluntaryExit;
@@ -139,6 +146,13 @@ ${validatorsToExit.map((v) => `${v.pubkey} ${v.index} ${v.status}`).join("\n")}`
139146
}
140147
}
141148

149+
if (args.saveToFile && signedExits.length > 0) {
150+
// Write all signed voluntary exits to the specified file as a JSON array
151+
const {writeFile} = await import("../../util/file.js");
152+
writeFile(args.saveToFile, signedExits);
153+
console.log(`Saved ${signedExits.length} signed voluntary exit(s) to file: ${args.saveToFile}`);
154+
}
155+
142156
if (alreadySubmitted.length > 0) {
143157
console.log(`Voluntary exit already submitted for ${alreadySubmitted.length}/${signersToExit.length}`);
144158
for (const validatorToExit of alreadySubmitted) {
@@ -240,7 +254,3 @@ function getSignerPubkeyHex(signer: Signer): string {
240254
return signer.pubkey;
241255
}
242256
}
243-
244-
245-
246-

packages/cli/test/e2e/voluntaryExit.saveToFile-noNetwork.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("voluntaryExit saveToFile-noNetwork cmd", () => {
4747
// check on environment/network calls
4848
const mockEnv = vi.spyOn(process, "env", "get").mockReturnValue({
4949
...process.env,
50-
ETH_RPC_URL: "", // ensure no RPC URL defined
50+
ETH_RPC_URL: "",
5151
});
5252

5353
let publishedToNetwork = false;
@@ -70,7 +70,7 @@ describe("voluntaryExit saveToFile-noNetwork cmd", () => {
7070
});
7171

7272
try {
73-
await mockExec(); // simulate execCliCommand
73+
await mockExec();
7474
} catch {}
7575

7676
// Assert: no network calls were made

0 commit comments

Comments
 (0)