-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
56 lines (43 loc) · 1.04 KB
/
create.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
package wallet
import (
"fmt"
"github.com/GGP1/btcs/wallet"
"github.com/tyler-smith/go-bip39"
"github.com/spf13/cobra"
)
var mnemonic, passphrase string
func newCreate() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Creates a new wallet",
RunE: runCreate(),
}
f := cmd.Flags()
f.StringVarP(&passphrase, "passphrase", "p", "", "Seed passphrase")
f.StringVarP(&mnemonic, "mnemonic", "m", "", "Seed mnemonic, should be enclosed by doublequotes. If it's not specified a new one will be provided")
return cmd
}
func runCreate() runEFunc {
return func(cmd *cobra.Command, args []string) error {
if mnemonic == "" {
entropy, err := bip39.NewEntropy(256)
if err != nil {
return err
}
mnemonic, err = bip39.NewMnemonic(entropy)
if err != nil {
return err
}
fmt.Println("Mnemonic:", mnemonic)
}
wallet, err := wallet.NewWallet(mnemonic, passphrase)
if err != nil {
return err
}
if err := wallet.Save(); err != nil {
return err
}
fmt.Println("Wallet created")
return nil
}
}