forked from OpenBazaar/openbazaar-go
/
status.go
84 lines (79 loc) · 1.81 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cmd
import (
"fmt"
"os"
"github.com/ipfs/go-ipfs/repo/fsrepo"
"github.com/phoreproject/multiwallet/util"
obnet "github.com/phoreproject/pm-go/net"
"github.com/phoreproject/pm-go/repo"
"github.com/phoreproject/pm-go/repo/db"
)
type Status struct {
DataDir string `short:"d" long:"datadir" description:"specify the data directory to be used"`
Testnet bool `short:"t" long:"testnet" description:"use the test network"`
}
func (x *Status) Execute(args []string) error {
// Set repo path
repoPath, err := repo.GetRepoPath(x.Testnet, x.DataDir)
if err != nil {
return err
}
if x.DataDir != "" {
repoPath = x.DataDir
}
torAvailable := false
_, err = obnet.GetTorControlPort()
if err == nil {
torAvailable = true
}
if fsrepo.IsInitialized(repoPath) {
sqliteDB, err := db.Create(repoPath, "", x.Testnet, util.CoinTypePhore)
if err != nil {
os.Exit(1)
}
defer sqliteDB.Close()
if sqliteDB.Config().IsEncrypted() {
if !torAvailable {
fmt.Println("Initialized - Encrypted")
os.Exit(30)
} else {
fmt.Println("Initialized - Encrypted")
fmt.Println("Tor Available")
os.Exit(31)
}
} else {
_, isEncrypted, err := sqliteDB.Config().GetMnemonic()
if err != nil {
os.Exit(1)
}
if !torAvailable {
fmt.Println("Initialized - Not Encrypted")
if isEncrypted {
fmt.Println("Seed Words Encrypted")
os.Exit(25)
} else {
os.Exit(20)
}
} else {
fmt.Println("Initialized - Not Encrypted")
fmt.Println("Tor Available")
if isEncrypted {
fmt.Println("Seed Words Encrypted")
os.Exit(26)
} else {
os.Exit(21)
}
}
}
} else {
if !torAvailable {
fmt.Println("Not initialized")
os.Exit(10)
} else {
fmt.Println("Not initialized")
fmt.Println("Tor Available")
os.Exit(11)
}
}
return nil
}