forked from OpenBazaar/openbazaar-go
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathopenbazaard.go
94 lines (86 loc) · 3.04 KB
/
openbazaard.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
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"os"
"os/signal"
"path/filepath"
"github.com/ipfs/go-ipfs/repo/fsrepo"
"github.com/jessevdk/go-flags"
"github.com/op/go-logging"
"github.com/phoreproject/openbazaar-go/cmd"
"github.com/phoreproject/openbazaar-go/core"
)
var log = logging.MustGetLogger("main")
type Opts struct {
Version bool `short:"v" long:"version" description:"Print the version number and exit"`
}
var opts Opts
var parser = flags.NewParser(&opts, flags.Default)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
log.Noticef("Received %s\n", sig)
log.Info("Phore Marketplace shutting down...")
if core.Node != nil {
if core.Node.MessageRetriever != nil {
core.Node.RecordAgingNotifier.Stop()
close(core.Node.MessageRetriever.DoneChan)
core.Node.MessageRetriever.Wait()
}
core.OfflineMessageWaitGroup.Wait()
core.PublishLock.Lock()
core.Node.Datastore.Close()
repoLockFile := filepath.Join(core.Node.RepoPath, fsrepo.LockFile)
os.Remove(repoLockFile)
core.Node.Multiwallet.Close()
core.Node.IpfsNode.Close()
}
os.Exit(1)
}
}()
parser.AddCommand("gencerts",
"Generate certificates",
"Generate self-singned certificates",
&cmd.GenerateCertificates{})
parser.AddCommand("init",
"initialize a new repo and exit",
"Initializes a new repo without starting the server",
&cmd.Init{})
parser.AddCommand("status",
"get the repo status",
"Returns the status of the repo ― Uninitialized, Encrypted, Decrypted. Also returns whether Tor is available.",
&cmd.Status{})
parser.AddCommand("setapicreds",
"set API credentials",
"The API password field in the config file takes a SHA256 hash of the password. This command will generate the hash for you and save it to the config file.",
&cmd.SetAPICreds{})
parser.AddCommand("start",
"start the OpenBazaar-Server",
"The start command starts the OpenBazaar-Server",
&cmd.Start{})
parser.AddCommand("encryptdatabase",
"encrypt your database",
"This command encrypts the database containing your bitcoin private keys, identity key, and contracts",
&cmd.EncryptDatabase{})
parser.AddCommand("decryptdatabase",
"decrypt your database",
"This command decrypts the database containing your bitcoin private keys, identity key, and contracts.\n [Warning] doing so may put your bitcoins at risk.",
&cmd.DecryptDatabase{})
parser.AddCommand("restore",
"restore user data",
"This command will attempt to restore user data (profile, listings, ratings, etc) by downloading them from the network. This will only work if the IPNS mapping is still available in the DHT. Optionally it will take a mnemonic seed to restore from.",
&cmd.Restore{})
parser.AddCommand("convert",
"convert this node to a different coin type",
"This command will convert the node to use a different cryptocurrency",
&cmd.Convert{})
if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-v") {
fmt.Println(core.VERSION)
return
}
if _, err := parser.Parse(); err != nil {
os.Exit(1)
}
}