Skip to content

Commit f2fc6d4

Browse files
authored
Merge pull request #177 from pegnet/develop
Version 2.0.3
2 parents 97d2b91 + c8c3522 commit f2fc6d4

File tree

6 files changed

+505
-23
lines changed

6 files changed

+505
-23
lines changed

cmd/api.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"os"
9+
"runtime"
910
"sort"
1011
"strconv"
1112
"strings"
@@ -53,7 +54,7 @@ func init() {
5354
//tx.Flags()
5455
rootCmd.AddCommand(tx)
5556
rootCmd.AddCommand(conv)
56-
57+
rootCmd.AddCommand(resetDB)
5758
}
5859

5960
var minerDistro = &cobra.Command{
@@ -575,6 +576,28 @@ var status = &cobra.Command{
575576
},
576577
}
577578

579+
var resetDB = &cobra.Command{
580+
Use: "resetDB",
581+
Short: "reset sql database for the pegnetd node",
582+
PersistentPreRun: always,
583+
PreRun: SoftReadConfig,
584+
Run: func(cmd *cobra.Command, args []string) {
585+
rawpath := viper.GetString(config.SqliteDBPath)
586+
fmt.Println("Resetting database...", rawpath)
587+
if runtime.GOOS == "windows" {
588+
rawpath = strings.Replace(rawpath, "$HOME", "$USERPROFILE", -1)
589+
}
590+
path := os.ExpandEnv(rawpath)
591+
592+
err := os.Remove(path)
593+
if err != nil {
594+
fmt.Println("Resetting database is failed. Manual removing is required.", err)
595+
} else {
596+
fmt.Println("Database has been reset successfully.")
597+
}
598+
},
599+
}
600+
578601
func getProperties() srv.PegnetdProperties {
579602
cl := srv.NewClient()
580603
cl.PegnetdServer = viper.GetString(config.Pegnetd)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/AdamSLevy/jsonrpc2/v13 v13.0.1
77
github.com/Factom-Asset-Tokens/factom v0.0.0-20191114224337-71de98ff5b3e
88
github.com/mattn/go-sqlite3 v1.11.0
9-
github.com/pegnet/pegnet v0.5.1-0.20201201194922-e59c2d3b3061
9+
github.com/pegnet/pegnet v0.5.1-0.20210225213341-a476b4b2cc0f
1010
github.com/rs/cors v1.7.0
1111
github.com/sirupsen/logrus v1.4.2
1212
github.com/spf13/cobra v0.0.5

0 commit comments

Comments
 (0)