From 513763cac31479a6ae839be9abf9bf441d948aaf Mon Sep 17 00:00:00 2001 From: magonjr Date: Wed, 21 Aug 2024 11:26:56 -0300 Subject: [PATCH] red-223 --- src/config/default-node-config.ts | 9 +++++++- src/node-commands.ts | 37 +++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/config/default-node-config.ts b/src/config/default-node-config.ts index 94c5d83..e691af5 100644 --- a/src/config/default-node-config.ts +++ b/src/config/default-node-config.ts @@ -1,14 +1,21 @@ export const defaultNodeConfig = { autoRestart: true, + lastStopped: undefined }; -export type nodeConfigType = typeof defaultNodeConfig; +export type nodeConfigType = { + autoRestart: boolean, + lastStopped?: number +} export const nodeConfigSchema = { type: "object", properties: { autoRestart: { type: "boolean" + }, + lastStopped: { + type: "number" } }, required: ["autoRestart"] diff --git a/src/node-commands.ts b/src/node-commands.ts index 9ff7fca..0b46f72 100644 --- a/src/node-commands.ts +++ b/src/node-commands.ts @@ -437,12 +437,12 @@ export function registerNodeCommands(program: Command) { const nominee = eoaData?.operatorAccountInfo?.nominee ?? '' // Convert stake value to ether, handling potential hexadecimal input - const stakeOutput = stakeValue + const stakeOutput = stakeValue ? ethers.utils.formatEther( ethers.BigNumber.from(stakeValue.startsWith('0x') ? stakeValue : '0x' + stakeValue).toString() ) : '' - + console.log(yaml.dump({ stake: stakeOutput, nominee: nominee @@ -513,7 +513,14 @@ export function registerNodeCommands(program: Command) { .action(options => { function stopNode() { pm2.stop('validator', err => { - if (err) console.error(err); + if (err) { + console.error(err); + } else { + nodeConfig.lastStopped = new Date().getTime(); + console.log('Node process stopped', nodeConfig); + writeNodeConfig(); + } + return pm2.disconnect(); }); } @@ -879,6 +886,7 @@ export function registerNodeCommands(program: Command) { console.log( yaml.dump({ autoRestart: settings.autoRestart, + lastStopped: settings.lastStopped, }) ); }); @@ -980,17 +988,22 @@ export function registerNodeCommands(program: Command) { return; } nodeConfig.autoRestart = input === 'true'; - // eslint-disable-next-line security/detect-non-literal-fs-filename - fs.writeFile( - path.join(__dirname, `../${File.NODE_CONFIG}`), - JSON.stringify(nodeConfig, undefined, 2), - {encoding: 'utf8', mode: 0o600}, - err => { - if (err) console.error(err); - } - ); + writeNodeConfig(); }); + function writeNodeConfig() { + // eslint-disable-next-line security/detect-non-literal-fs-filename + fs.writeFile( + path.join(__dirname, `../${File.NODE_CONFIG}`), + JSON.stringify(nodeConfig, undefined, 2), + {encoding: 'utf8', mode: 0o600}, + err => { + if (err) console.error(err); + } + ); + } + + // setCommand // .command('archiver') // .arguments('')