Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

red-223 #21

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/config/default-node-config.ts
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
37 changes: 25 additions & 12 deletions src/node-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
}
Expand Down Expand Up @@ -879,6 +886,7 @@ export function registerNodeCommands(program: Command) {
console.log(
yaml.dump({
autoRestart: settings.autoRestart,
lastStopped: settings.lastStopped,
})
);
});
Expand Down Expand Up @@ -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('<URL>')
Expand Down