This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
/
init.go
66 lines (61 loc) · 2.23 KB
/
init.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
package cmd
import (
"bufio"
"errors"
"fmt"
"github.com/OpenBazaar/openbazaar-go/repo"
"github.com/op/go-logging"
"os"
"strings"
"time"
)
var log = logging.MustGetLogger("cmd")
type Init struct {
Password string `short:"p" long:"password" description:"the encryption password if the database is to be encrypted"`
DataDir string `short:"d" long:"datadir" description:"specify the data directory to be used"`
Mnemonic string `short:"m" long:"mnemonic" description:"specify a mnemonic seed to use to derive the keychain"`
Testnet bool `short:"t" long:"testnet" description:"use the test network"`
Force bool `short:"f" long:"force" description:"force overwrite existing repo (dangerous!)"`
WalletCreationDate string `short:"w" long:"walletcreationdate" description:"specify the date the seed was created. if omitted the wallet will sync from the oldest checkpoint."`
}
func (x *Init) Execute(args []string) error {
// Set repo path
repoPath, err := repo.GetRepoPath(x.Testnet)
if err != nil {
return err
}
if x.DataDir != "" {
repoPath = x.DataDir
}
if x.Password != "" {
x.Password = strings.Replace(x.Password, "'", "''", -1)
}
creationDate := time.Now()
if x.WalletCreationDate != "" {
creationDate, err = time.Parse(time.RFC3339, x.WalletCreationDate)
if err != nil {
return errors.New("Wallet creation date timestamp must be in RFC3339 format")
}
}
_, err = InitializeRepo(repoPath, x.Password, x.Mnemonic, x.Testnet, creationDate)
if err == repo.ErrRepoExists && x.Force {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Force overwriting the db will destroy your existing keys and history. Are you really, really sure you want to continue? (y/n): ")
resp, _ := reader.ReadString('\n')
if strings.ToLower(resp) == "y\n" || strings.ToLower(resp) == "yes\n" || strings.ToLower(resp)[:1] == "y" {
os.RemoveAll(repoPath)
_, err = InitializeRepo(repoPath, x.Password, x.Mnemonic, x.Testnet, creationDate)
if err != nil {
return err
}
fmt.Printf("OpenBazaar repo initialized at %s\n", repoPath)
return nil
} else {
return nil
}
} else if err != nil {
return err
}
fmt.Printf("OpenBazaar repo initialized at %s\n", repoPath)
return nil
}