-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add command to clear transaction pool (#3250)
- Loading branch information
1 parent
0663b0f
commit 56f482d
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} | ||
} |