Skip to content

Commit

Permalink
feat(core): add command to clear transaction pool (#3250)
Browse files Browse the repository at this point in the history
  • Loading branch information
dated authored and faustbrian committed Nov 13, 2019
1 parent 0663b0f commit 56f482d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/core/src/commands/pool/clear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { readdirSync } from "fs";
import { removeSync } from "fs-extra";
import { confirm } from "../../helpers/prompts";
import { CommandFlags } from "../../types";
import { BaseCommand } from "../command";

export class ClearCommand extends BaseCommand {
public static description: string = "Clear the transaction pool";

public static flags: CommandFlags = {
...BaseCommand.flagsNetwork,
};

public async run(): Promise<void> {
const { flags, paths } = await this.parseWithNetwork(ClearCommand);

this.abortRunningProcess(`${flags.token}-core`);
this.abortRunningProcess(`${flags.token}-forger`);
this.abortRunningProcess(`${flags.token}-relay`);

if (flags.force) {
return this.removeFiles(paths.data);
}

try {
await confirm("Are you sure you want to clear the transaction pool?", async () => {
this.removeFiles(paths.data);
});
} catch (err) {
this.error(err.message);
}
}

private removeFiles(dataPath: string) {
const files: string[] = readdirSync(dataPath).filter((file: string) => file.includes("transaction-pool"));

for (const file of files) {
removeSync(`${dataPath}/${file}`);
}
}
}

0 comments on commit 56f482d

Please sign in to comment.