-
Notifications
You must be signed in to change notification settings - Fork 886
/
node_types.go
73 lines (62 loc) · 1.76 KB
/
node_types.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
package main
import (
"errors"
"fmt"
"strings"
sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
nodecmd "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/nodebuilder/p2p"
)
var (
nodeDirKey = "node.type"
networkKey = "p2p.network"
)
func DirectoryFlags() *flag.FlagSet {
flags := &flag.FlagSet{}
defaultNetwork := string(p2p.DefaultNetwork)
flags.String(
nodeDirKey,
"",
"Sets key utility to use the node type's directory (e.g. "+
"~/.celestia-light-"+strings.ToLower(defaultNetwork)+" if --node.type light is passed).")
flags.String(
networkKey,
defaultNetwork,
"Sets key utility to use the node network's directory (e.g. "+
"~/.celestia-light-mynetwork if --p2p.network MyNetwork is passed).")
return flags
}
func ParseDirectoryFlags(cmd *cobra.Command) error {
// if keyring-dir is explicitly set, use it
if cmd.Flags().Changed(sdkflags.FlagKeyringDir) {
return nil
}
nodeType := cmd.Flag(nodeDirKey).Value.String()
if nodeType == "" {
return errors.New("no node type provided")
}
network := cmd.Flag(networkKey).Value.String()
if net, err := p2p.Network(network).Validate(); err == nil {
network = string(net)
} else {
fmt.Println("WARNING: unknown network specified: ", network)
}
switch nodeType {
case "bridge", "full", "light":
path, err := nodecmd.DefaultNodeStorePath(nodeType, network)
if err != nil {
return err
}
keyPath := fmt.Sprintf("%s/keys", path)
fmt.Println("using directory: ", keyPath)
if err := cmd.Flags().Set(sdkflags.FlagKeyringDir, keyPath); err != nil {
return err
}
default:
return fmt.Errorf("node type %s is not valid. Provided node types: (bridge || full || light)",
nodeType)
}
return nil
}