forked from elastos/Elastos.ELA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
154 lines (141 loc) · 3.75 KB
/
flags.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package common
import (
"errors"
"github.com/elastos/Elastos.ELA/account"
"github.com/elastos/Elastos.ELA/utils"
"github.com/urfave/cli"
)
var (
// Account flags
AccountWalletFlag = cli.StringFlag{
Name: "wallet, w",
Usage: "wallet `<file>` path",
Value: account.KeystoreFileName,
}
AccountPasswordFlag = cli.StringFlag{
Name: "password, p",
Usage: "wallet password",
}
AccountMultiMFlag = cli.IntFlag{
Name: "m",
Usage: "min signature `<number>` of multi signature address",
}
AccountMultiPubKeyFlag = cli.StringFlag{
Name: "pubkeys, pks",
Usage: "public key list of multi signature address, separate public keys with comma `,`",
}
// Transaction flags
TransactionFromFlag = cli.StringFlag{
Name: "from",
Usage: "the sender `<address>` of the transaction",
}
TransactionToFlag = cli.StringFlag{
Name: "to",
Usage: "the recipient `<address>` of the transaction",
}
TransactionToManyFlag = cli.StringFlag{
Name: "tomany",
Usage: "the `<file>` path that contains multi-recipients and amount",
}
TransactionAmountFlag = cli.StringFlag{
Name: "amount",
Usage: "the transfer `<amount>` of the transaction",
}
TransactionFeeFlag = cli.StringFlag{
Name: "fee",
Usage: "the transfer `<fee>` of the transaction",
}
TransactionLockFlag = cli.StringFlag{
Name: "lock",
Usage: "the `<lock time>` to specify when the received asset can be spent",
}
TransactionHexFlag = cli.StringFlag{
Name: "hex",
Usage: "the transaction content in hex string format to be sign or send",
}
TransactionFileFlag = cli.StringFlag{
Name: "file, f",
Usage: "the file path to specify a transaction file path with the hex string content to be sign",
}
TransactionNodePublicKeyFlag = cli.StringFlag{
Name: "nodepublickey",
Usage: "the node public key of an arbitrator which have been inactivated",
}
TransactionForFlag = cli.StringFlag{
Name: "for",
Usage: "the `<file>` path that holds the list of candidates",
}
// RPC flags
RPCUserFlag = cli.StringFlag{
Name: "rpcuser",
Usage: "username for JSON-RPC connections",
}
RPCPasswordFlag = cli.StringFlag{
Name: "rpcpassword",
Usage: "password for JSON-RPC connections",
}
RPCPortFlag = cli.StringFlag{
Name: "rpcport",
Usage: "JSON-RPC server listening port `<number>`",
}
// Info flags
InfoStartFlag = cli.IntFlag{
Name: "start",
Usage: "the start index of producers",
Value: 0,
}
InfoLimitFlag = cli.Int64Flag{
Name: "limit",
Usage: "the limit count of producers",
Value: -1,
}
InfoProducerStateFlag = cli.StringFlag{
Name: "state",
Usage: "the producer state you want",
}
// Config flags
ConfigFileFlag = cli.StringFlag{
Name: "conf",
Usage: "config `<file>` path, ",
Value: defaultConfigPath,
}
DataDirFlag = cli.StringFlag{
Name: "datadir",
Usage: "block data and logs storage `<path>`",
Value: defaultDataDir,
}
)
// MoveRPCFlags finds the rpc argument and moves it to the front
// of the argument array.
func MoveRPCFlags(args []string) ([]string, error) {
newArgs := args[:1]
cacheArgs := make([]string, 0)
for i := 1; i < len(args); i++ {
switch args[i] {
case "--rpcport":
fallthrough
case "--rpcuser":
fallthrough
case "--rpcpassword":
newArgs = append(newArgs, args[i])
if i == len(args)-1 {
return nil, errors.New("invalid flag " + args[i])
}
newArgs = append(newArgs, args[i+1])
i++
default:
cacheArgs = append(cacheArgs, args[i])
}
}
newArgs = append(newArgs, cacheArgs...)
return newArgs, nil
}
// GetFlagPassword gets node's wallet password from command line or user input
func GetFlagPassword(c *cli.Context) ([]byte, error) {
flagPassword := c.String("password")
password := []byte(flagPassword)
if flagPassword == "" {
return utils.GetPassword()
}
return password, nil
}