1- import inquirer from "inquirer" ;
21import { Signature } from "@chainsafe/blst" ;
32import { ApiClient , getClient } from "@lodestar/api" ;
43import { BeaconConfig , createBeaconConfig } from "@lodestar/config" ;
@@ -11,6 +10,7 @@ import {
1110import { Epoch , ValidatorIndex , phase0 , ssz } from "@lodestar/types" ;
1211import { CliCommand , fromHex , toPubkeyHex } from "@lodestar/utils" ;
1312import { SignableMessageType , Signer , SignerType , externalSignerPostSignature } from "@lodestar/validator" ;
13+ import inquirer from "inquirer" ;
1414import { getBeaconConfigFromArgs } from "../../config/index.js" ;
1515import { GlobalArgs } from "../../options/index.js" ;
1616import { 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
2627export 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-
0 commit comments