File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
packages/core/src/commands/pool Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments