Skip to content

Commit 56f482d

Browse files
datedfaustbrian
authored andcommitted
feat(core): add command to clear transaction pool (#3250)
1 parent 0663b0f commit 56f482d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { readdirSync } from "fs";
2+
import { removeSync } from "fs-extra";
3+
import { confirm } from "../../helpers/prompts";
4+
import { CommandFlags } from "../../types";
5+
import { BaseCommand } from "../command";
6+
7+
export class ClearCommand extends BaseCommand {
8+
public static description: string = "Clear the transaction pool";
9+
10+
public static flags: CommandFlags = {
11+
...BaseCommand.flagsNetwork,
12+
};
13+
14+
public async run(): Promise<void> {
15+
const { flags, paths } = await this.parseWithNetwork(ClearCommand);
16+
17+
this.abortRunningProcess(`${flags.token}-core`);
18+
this.abortRunningProcess(`${flags.token}-forger`);
19+
this.abortRunningProcess(`${flags.token}-relay`);
20+
21+
if (flags.force) {
22+
return this.removeFiles(paths.data);
23+
}
24+
25+
try {
26+
await confirm("Are you sure you want to clear the transaction pool?", async () => {
27+
this.removeFiles(paths.data);
28+
});
29+
} catch (err) {
30+
this.error(err.message);
31+
}
32+
}
33+
34+
private removeFiles(dataPath: string) {
35+
const files: string[] = readdirSync(dataPath).filter((file: string) => file.includes("transaction-pool"));
36+
37+
for (const file of files) {
38+
removeSync(`${dataPath}/${file}`);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)