Skip to content

Commit 675c738

Browse files
author
laodouya
authored
Merge branch 'develop' into bugfix/provide_service
2 parents 75dbfd5 + 127d925 commit 675c738

24 files changed

Lines changed: 341 additions & 167 deletions

File tree

bin/completion/_cql

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# -------
1111
#
1212
# * Robinhuett <https://github.com/Robinhuett>
13-
# * Auxten <auxtenwpc#gmail.com>
13+
# * Auxten <auxten@covenantsql.io>
1414
#
1515
# ------------------------------------------------------------------------------
1616

@@ -21,135 +21,156 @@ _cql_dsn() {
2121
_cql_args() {
2222
case $words[1] in
2323
(help)
24-
_arguments '*:help:(generate console create drop wallet transfer grant mirror explorer adapter idminer rpc
25-
)'
24+
_arguments '*:help:(generate console create drop wallet transfer grant mirror explorer adapter idminer rpc)'
2625
;;
2726
(generate)
28-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
29-
'-bypass-signature[Disable signature sign and verify, for testing]' \
27+
_arguments '-bypass-signature[Disable signature sign and verify, for testing]' \
3028
'-help[Show help message]' \
31-
'-no-password[Use empty password for master key]' \
32-
'-password=-[Master key]:name: ' \
29+
'-with-password[Enter the passphrase for private.key]' \
30+
'-password=-[Passphrase for encrypting private.key]:name: ' \
3331
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
32+
'-private=-[Generate config using an existing private key]:name: ' \
33+
'-source=-[Generate config using the specified config template]:name: ' \
34+
'-miner=-[Generate miner config with specified miner address]:name: ' \
3435
'*:arguments:(config public)'
3536
;;
3637
(console)
37-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
38+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
3839
'-bypass-signature[Disable signature sign and verify, for testing]' \
3940
'-help[Show help message]' \
40-
'-no-password[Use empty password for master key]' \
41-
'-password=-[Master key]:name: ' \
41+
'-with-password[Enter the passphrase for private.key]' \
42+
'-password=-[Passphrase for encrypting private.key]:name: ' \
4243
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
4344
'-adapter=-[Address to serve a database chain adapter]:adapter_addr: ' \
4445
'-command=-[Run only single command and exit]:cmd: ' \
45-
'-dsn=-[Database url]:dsn:_cql_dsn' \
4646
'-explorer=-[Address serve a database chain explorer]:explorer_addr: ' \
4747
'-file=-[Execute commands from file and exit]:_files' \
4848
'-no-rc[Do not read start up file]' \
4949
'-out=-[Record stdout to file]:out_file:_files' \
5050
'-single-transaction[Execute as a single transaction (if non-interactive)]' \
51-
'-variable=-[Set variable]:var: '
51+
'-variable=-[Set variable]:var: ' \
52+
'1:Database ID:_cql_dsn '
5253
;;
5354
(create)
54-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
55+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
5556
'-bypass-signature[Disable signature sign and verify, for testing]' \
5657
'-help[Show help message]' \
57-
'-no-password[Use empty password for master key]' \
58-
'-password=-[Master key]:name: ' \
58+
'-with-password[Enter the passphrase for private.key]' \
59+
'-password=-[Passphrase for encrypting private.key]:name: ' \
5960
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
60-
'-wait-tx-confirm[Wait for transaction confirmation]'
61+
'-wait-tx-confirm[Wait for transaction confirmation]' \
62+
'-db-advance-payment=-[Customized advance payment]:var: ' \
63+
'-db-consistency-level=-[Consistency level, node*consistency_level is the node count to perform strong consistency]:var: ' \
64+
'-db-encrypt-key=-[Encryption key for persistence data]:var: ' \
65+
'-db-eventual-consistency=-[Use eventual consistency to sync among miner nodes]:var: ' \
66+
'-db-gas-price=-[Customized gas price]:var: ' \
67+
'-db-isolation-level=-[Isolation level in a single node]:var: ' \
68+
'-db-load-avg-per-cpu=-[Minimum idle CPU requirement, 0 for none]:var: ' \
69+
'-db-memory=-[Minimum memory requirement, 0 for none]:var: ' \
70+
'-db-node=-[Target node count]:var: ' \
71+
'-db-space=-[Minimum disk space requirement, 0 for none]:var: ' \
72+
'-db-target-miners=-[List of target miner addresses(separated by ',')]:var: '
6173
;;
6274
(drop)
63-
_arguments -C '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
75+
_arguments -C '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
6476
'-bypass-signature[Disable signature sign and verify, for testing]' \
6577
'-help[Show help message]' \
66-
'-no-password[Use empty password for master key]' \
67-
'-password=-[Master key]:name: ' \
78+
'-with-password[Enter the passphrase for private.key]' \
79+
'-password=-[Passphrase for encrypting private.key]:name: ' \
6880
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
6981
'-wait-tx-confirm[Wait for transaction confirmation]' \
7082
'1:Database ID:_cql_dsn '
7183
;;
7284
(wallet)
73-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
85+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
7486
'-bypass-signature[Disable signature sign and verify, for testing]' \
7587
'-help[Show help message]' \
76-
'-no-password[Use empty password for master key]' \
77-
'-password=-[Master key]:name: ' \
88+
'-with-password[Enter the passphrase for private.key]' \
89+
'-password=-[Passphrase for encrypting private.key]:name: ' \
7890
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
79-
'-balance=-[Get specific token balance of current account]:token_type:(Particle Wave All)'
91+
'-dsn=-[Database url]:dsn:_cql_dsn' \
92+
'-token=-[Get specific token balance of current account, e.g. Particle, Wave, All]:token_type:(Particle Wave All)'
8093
;;
8194
(transfer)
82-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
95+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
8396
'-bypass-signature[Disable signature sign and verify, for testing]' \
8497
'-help[Show help message]' \
85-
'-no-password[Use empty password for master key]' \
86-
'-password=-[Master key]:name: ' \
98+
'-with-password[Enter the passphrase for private.key]' \
99+
'-password=-[Passphrase for encrypting private.key]:name: ' \
87100
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
88-
'-wait-tx-confirm[Wait for transaction confirmation]'
101+
'-wait-tx-confirm[Wait for transaction confirmation]' \
102+
'-amount=-[Token account to transfer]:var: ' \
103+
'-to-dsn=-[Target database dsn to transfer token]:dsn:_cql_dsn' \
104+
'-to-user=-[Target address of an user account to transfer token]:var: ' \
105+
'-token=-[Token type to transfer, e.g. Particle, Wave]:token_type:(Particle Wave)'
89106
;;
90107
(grant)
91-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
108+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
92109
'-bypass-signature[Disable signature sign and verify, for testing]' \
93110
'-help[Show help message]' \
94-
'-no-password[Use empty password for master key]' \
95-
'-password=-[Master key]:name: ' \
111+
'-with-password[Enter the passphrase for private.key]' \
112+
'-password=-[Passphrase for encrypting private.key]:name: ' \
96113
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
97-
'-wait-tx-confirm[Wait for transaction confirmation]'
114+
'-to-dsn=-[Target database dsn to transfer token]:dsn:_cql_dsn' \
115+
'-to-user=-[Target address of an user account to transfer token]:var: ' \
116+
'-wait-tx-confirm[Wait for transaction confirmation]' \
117+
'-perm=-[Permission type struct for grant]:name: '
98118
;;
99119
(mirror)
100-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
120+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
101121
'-bypass-signature[Disable signature sign and verify, for testing]' \
102122
'-help[Show help message]' \
103-
'-no-password[Use empty password for master key]' \
104-
'-password=-[Master key]:name: ' \
123+
'-with-password[Enter the passphrase for private.key]' \
124+
'-password=-[Passphrase for encrypting private.key]:name: ' \
105125
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
106126
'-bg-log-level=-[Background log level]:bg_log_level:(trace debug info warning error fatal panic)' \
107127
'-tmp-path=-[Background service temp file path, use os.TempDir for default]:tmp_path:_files' \
108128
'1:Database ID:_cql_dsn ' \
109129
'2:Listen Addr:'
110130
;;
111131
(explorer)
112-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
132+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
113133
'-bypass-signature[Disable signature sign and verify, for testing]' \
114134
'-help[Show help message]' \
115-
'-no-password[Use empty password for master key]' \
116-
'-password=-[Master key]:name: ' \
135+
'-with-password[Enter the passphrase for private.key]' \
136+
'-password=-[Passphrase for encrypting private.key]:name: ' \
117137
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
118138
'-bg-log-level=-[Background log level]:bg_log_level:(trace debug info warning error fatal panic)' \
119139
'-tmp-path=-[Background service temp file path, use os.TempDir for default]:tmp_path:_files' \
120140
'1:Listen Addr:'
121141
;;
122142
(adapter)
123-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
143+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
124144
'-bypass-signature[Disable signature sign and verify, for testing]' \
125145
'-help[Show help message]' \
126-
'-no-password[Use empty password for master key]' \
127-
'-password=-[Master key]:name: ' \
146+
'-with-password[Enter the passphrase for private.key]' \
147+
'-password=-[Passphrase for encrypting private.key]:name: ' \
128148
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
129149
'-bg-log-level=-[Background log level]:bg_log_level:(trace debug info warning error fatal panic)' \
130150
'-tmp-path=-[Background service temp file path, use os.TempDir for default]:tmp_path:_files' \
131151
'-mirror=-[Mirror server for adapter to query]:' \
132152
'1:Listen Addr:'
133153
;;
134154
(idminer)
135-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
155+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
136156
'-bypass-signature[Disable signature sign and verify, for testing]' \
137157
'-help[Show help message]' \
138-
'-no-password[Use empty password for master key]' \
139-
'-password=-[Master key]:name: ' \
158+
'-with-password[Enter the passphrase for private.key]' \
159+
'-password=-[Passphrase for encrypting private.key]:name: ' \
140160
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
141161
'-difficulty=-[Difficulty for miner to mine nodes and generating nonce (default 24)]:difficulty: ' \
142162
'-loop[Keep mining until interrupted]'
143163
;;
144164
(rpc)
145-
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml]:CONF file:_files' \
165+
_arguments '-config=-[Config file for CovenantSQL, default "~/.cql/config.yaml"]:CONF file:_files' \
146166
'-bypass-signature[Disable signature sign and verify, for testing]' \
147167
'-help[Show help message]' \
148-
'-no-password[Use empty password for master key]' \
149-
'-password=-[Master key]:name: ' \
168+
'-with-password[Enter the passphrase for private.key]' \
169+
'-password=-[Passphrase for encrypting private.key]:name: ' \
150170
'-log-level=-[Console log level]:log_level:(trace debug info warning error fatal panic)' \
151-
'-wait-tx-confirm[Wait for transaction confirmation]' \
171+
'-bp[Call block producer node]' \
152172
'-endpoint=-[RPC endpoint Node ID to do test call]:' \
173+
'-wait-tx-confirm[Wait for transaction confirmation]' \
153174
'-name=-[RPC name to do test call]:' \
154175
'-req=-[RPC request to do test call, in json format]:'
155176
;;

bin/docker-entry.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ blockproducer)
1212
exec /app/cqld -config "${COVENANT_CONF}" -metric-web "${METRIC_WEB_ADDR}" "${@}"
1313
;;
1414
observer)
15-
exec /app/cql explorer -config "${COVENANT_CONF}" -no-password "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
15+
exec /app/cql explorer -config "${COVENANT_CONF}" "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
1616
;;
1717
adapter)
18-
exec /app/cql adapter -config "${COVENANT_CONF}" -no-password "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
18+
exec /app/cql adapter -config "${COVENANT_CONF}" "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
1919
;;
2020
mysql-adapter)
2121
exec /app/cql-mysql-adapter -config "${COVENANT_CONF}" "${@}"
2222
;;
2323
cli)
24-
exec /app/cql console -config ${COVENANT_CONF} -no-password "${@}"
24+
exec /app/cql console -config ${COVENANT_CONF} "${@}"
2525
;;
2626
faucet)
2727
exec /app/cql-faucet -config ${COVENANT_CONF} "${@}"

client/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func registerNode() (err error) {
531531
}
532532

533533
if nodeInfo.Role != proto.Leader && nodeInfo.Role != proto.Follower {
534-
log.Infof("Register self to blockproducer: %v", conf.GConf.BP.NodeID)
534+
log.Infof("Self register to blockproducer: %v", conf.GConf.BP.NodeID)
535535
err = rpc.PingBP(nodeInfo, conf.GConf.BP.NodeID)
536536
}
537537

cmd/cql/internal/adapter.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package internal
1818

1919
import (
2020
"context"
21+
"flag"
2122
"time"
2223

2324
"github.com/CovenantSQL/CovenantSQL/sqlchain/adapter"
@@ -38,6 +39,9 @@ Adapter serves a SQLChain adapter.
3839
e.g.
3940
cql adapter 127.0.0.1:7784
4041
`,
42+
Flag: flag.NewFlagSet("Adapter params", flag.ExitOnError),
43+
CommonFlag: flag.NewFlagSet("Common params", flag.ExitOnError),
44+
DebugFlag: flag.NewFlagSet("Debug params", flag.ExitOnError),
4145
}
4246

4347
func init() {
@@ -74,13 +78,15 @@ func startAdapterServer(adapterAddr string, adapterUseMirrorAddr string) func()
7478
}
7579

7680
func runAdapter(cmd *Command, args []string) {
81+
commonFlagsInit(cmd)
82+
7783
if len(args) != 1 {
7884
ConsoleLog.Error("adapter command need listen address as param")
7985
SetExitStatus(1)
80-
help = true
86+
printCommandHelp(cmd)
87+
Exit()
8188
}
8289

83-
commonFlagsInit(cmd)
8490
configInit()
8591
bgServerInit()
8692

cmd/cql/internal/base.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ type Command struct {
6262
// Long is the long message shown in the 'cql help <this-command>' output.
6363
Long string
6464

65+
// DebugFlag is a set of debug flags specific to this command.
66+
DebugFlag *flag.FlagSet
67+
68+
// CommonFlag is a set of common flags specific to this command.
69+
CommonFlag *flag.FlagSet
70+
6571
// Flag is a set of flags specific to this command.
66-
Flag flag.FlagSet
72+
Flag *flag.FlagSet
6773
}
6874

6975
// LongName returns the command's long name: all the words in the usage line between "cql" and a flag or argument,

cmd/cql/internal/cfg.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
var (
4545
configFile string
4646
password string
47-
noPassword bool
47+
withPassword bool
4848
consoleLogLevel string // foreground console log level
4949

5050
waitTxConfirmation bool // wait for transaction confirmation before exiting
@@ -55,26 +55,22 @@ var (
5555
)
5656

5757
func addCommonFlags(cmd *Command) {
58-
cmd.Flag.BoolVar(&help, "help", false, "Show help message")
59-
cmd.Flag.BoolVar(&noPassword, "no-password", true,
60-
"Use empty password for master key")
58+
cmd.CommonFlag.BoolVar(&help, "help", false, "Show help message")
59+
cmd.CommonFlag.BoolVar(&withPassword, "with-password", false,
60+
"Enter the passphrase for private.key")
6161

6262
// debugging flags.
63-
cmd.Flag.StringVar(&password, "password", "",
64-
"Master key password for covenantsql (NOT SAFE, for debug or script only)")
65-
cmd.Flag.StringVar(&consoleLogLevel, "log-level", "info",
63+
cmd.DebugFlag.StringVar(&password, "password", "",
64+
"Passphrase for encrypting private.key (NOT SAFE, for debug or script only)")
65+
cmd.DebugFlag.StringVar(&consoleLogLevel, "log-level", "info",
6666
"Console log level: trace debug info warning error fatal panic")
67-
cmd.Flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
67+
cmd.DebugFlag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
6868
"Disable signature sign and verify, for testing")
6969
}
7070

7171
func commonFlagsInit(cmd *Command) {
7272
if help {
73-
_, _ = fmt.Fprintf(os.Stdout, "usage: %s\n", cmd.UsageLine)
74-
_, _ = fmt.Fprintf(os.Stdout, cmd.Long)
75-
_, _ = fmt.Fprintf(os.Stdout, "\nParams:\n")
76-
cmd.Flag.SetOutput(os.Stdout)
77-
cmd.Flag.PrintDefaults()
73+
printCommandHelp(cmd)
7874
Exit()
7975
}
8076

@@ -86,15 +82,15 @@ func commonFlagsInit(cmd *Command) {
8682
}
8783

8884
func addConfigFlag(cmd *Command) {
89-
cmd.Flag.StringVar(&configFile, "config", "~/.cql/config.yaml",
90-
"Config file for covenantsql (Usually no need to set, default is enough.)")
85+
cmd.CommonFlag.StringVar(&configFile, "config", "~/.cql/config.yaml",
86+
"Config file for CovanantSQL (Usually no need to set, default is enough.)")
9187
}
9288

9389
func configInit() {
9490
configFile = utils.HomeDirExpand(configFile)
9591

9692
if password == "" {
97-
password = readMasterKey(noPassword)
93+
password = readMasterKey(!withPassword)
9894
}
9995

10096
// init covenantsql driver
@@ -133,7 +129,7 @@ func wait(txHash hash.Hash) (err error) {
133129

134130
func addBgServerFlag(cmd *Command) {
135131
cmd.Flag.StringVar(&tmpPath, "tmp-path", "",
136-
"Background service temp file path, use \"dirname `mktemp -u`\" to check it out")
132+
"Background service temp file path, use \"dirname $(mktemp -u)\" to check it out")
137133
cmd.Flag.StringVar(&bgLogLevel, "bg-log-level", "info",
138134
"Background service log level: trace debug info warning error fatal panic")
139135
}

cmd/cql/internal/console.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ If those params are set, it will run SQL script and exit without staying console
6060
e.g.
6161
cql console -command "create table test1(test2 int);" covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c
6262
`,
63+
Flag: flag.NewFlagSet("Console params", flag.ExitOnError),
64+
CommonFlag: flag.NewFlagSet("Common params", flag.ExitOnError),
65+
DebugFlag: flag.NewFlagSet("Debug params", flag.ExitOnError),
6366
}
6467

6568
var (
@@ -326,6 +329,8 @@ func run(u *user.User) (err error) {
326329
func runConsole(cmd *Command, args []string) {
327330
configFile = utils.HomeDirExpand(configFile)
328331

332+
commonFlagsInit(cmd)
333+
329334
var err error
330335
// load config
331336
if conf.GConf, err = conf.LoadConfig(configFile); err != nil {
@@ -375,11 +380,11 @@ func runConsole(cmd *Command, args []string) {
375380
} else {
376381
ConsoleLog.Error("neither local dsn storage exists nor a dsn string present")
377382
SetExitStatus(1)
378-
help = true
383+
printCommandHelp(cmd)
384+
Exit()
379385
}
380386
}
381387

382-
commonFlagsInit(cmd)
383388
configInit()
384389

385390
usqlRegister()

0 commit comments

Comments
 (0)