Skip to content

Commit 4278930

Browse files
authored
Merge pull request #741 from gzliudan/cli-v2
cmd: migrate to urfave/cli/v2
2 parents 017dcdd + ae56946 commit 4278930

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2460
-2000
lines changed

cicd/devnet/start-local-devnet.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ echo "Running a node with wallet: ${wallet} at local"
5353
../../build/bin/XDC --ethstats ${netstats} --gcmode=archive \
5454
--bootnodes ${bootnodes} --syncmode full \
5555
--datadir ./tmp/xdcchain --networkid 551 \
56-
-port 30303 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 \
57-
--rpcport 8545 \
58-
--rpcapi db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS \
59-
--rpcvhosts "*" --unlock "${wallet}" --password ./tmp/.pwd --mine \
60-
--gasprice "1" --targetgaslimit "420000000" --verbosity ${log_level} \
61-
--ws --wsaddr=0.0.0.0 --wsport 8555 \
62-
--wsorigins "*" 2>&1 >>./tmp/xdc.log
56+
--port 30303 --http --http-corsdomain "*" --http-addr 0.0.0.0 \
57+
--http-port 8545 \
58+
--http-api db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS \
59+
--http-vhosts "*" --unlock "${wallet}" --password ./tmp/.pwd --mine \
60+
--miner-gasprice "1" --miner-gaslimit "420000000" --verbosity ${log_level} \
61+
--ws --ws-addr=0.0.0.0 --ws-port 8555 \
62+
--ws-origins "*" 2>&1 >>./tmp/xdc.log

cicd/devnet/start.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ XDC --ethstats ${netstats} --gcmode archive \
7575
--nat extip:${INSTANCE_IP} \
7676
--bootnodes ${bootnodes} --syncmode full \
7777
--datadir /work/xdcchain --networkid 551 \
78-
-port $port --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 \
79-
--rpcport $rpc_port \
80-
--rpcapi db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
81-
--rpcvhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
82-
--gasprice "1" --targetgaslimit "420000000" --verbosity ${log_level} \
78+
--port $port --http --http-corsdomain "*" --http-addr 0.0.0.0 \
79+
--http-port $rpc_port \
80+
--http-api db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
81+
--http-vhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
82+
--miner-gasprice "1" --miner-gaslimit "420000000" --verbosity ${log_level} \
8383
--debugdatadir /work/xdcchain \
84-
--ws --wsaddr=0.0.0.0 --wsport $ws_port \
85-
--wsorigins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log
84+
--ws --ws-addr=0.0.0.0 --ws-port $ws_port \
85+
--ws-origins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log

cicd/mainnet/start.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ XDC --ethstats ${netstats} --gcmode archive \
7474
--nat extip:${INSTANCE_IP} \
7575
--bootnodes ${bootnodes} --syncmode full \
7676
--datadir /work/xdcchain --networkid 50 \
77-
-port $port --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 \
78-
--rpcport $rpc_port \
79-
--rpcapi db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
80-
--rpcvhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
81-
--gasprice "1" --targetgaslimit "420000000" --verbosity ${log_level} \
77+
--port $port --http --http-corsdomain "*" --http-addr 0.0.0.0 \
78+
--http-port $rpc_port \
79+
--http-api db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
80+
--http-vhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
81+
--miner-gasprice "1" --miner-gaslimit "420000000" --verbosity ${log_level} \
8282
--debugdatadir /work/xdcchain \
83-
--ws --wsaddr=0.0.0.0 --wsport $ws_port \
84-
--wsorigins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log
83+
--ws --ws-addr=0.0.0.0 --ws-port $ws_port \
84+
--ws-origins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log

cicd/testnet/start.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ XDC --ethstats ${netstats} --gcmode archive \
7676
--nat extip:${INSTANCE_IP} \
7777
--bootnodes ${bootnodes} --syncmode full \
7878
--datadir /work/xdcchain --networkid 51 \
79-
-port $port --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 \
80-
--rpcport $rpc_port \
81-
--rpcapi db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
82-
--rpcvhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
83-
--gasprice "1" --targetgaslimit "420000000" --verbosity ${log_level} \
79+
--port $port --http --http-corsdomain "*" --http-addr 0.0.0.0 \
80+
--http-port $rpc_port \
81+
--http-api db,eth,debug,net,shh,txpool,personal,web3,XDPoS \
82+
--http-vhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
83+
--miner-gasprice "1" --miner-gaslimit "420000000" --verbosity ${log_level} \
8484
--debugdatadir /work/xdcchain \
85-
--ws --wsaddr=0.0.0.0 --wsport $ws_port \
86-
--wsorigins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log
85+
--ws --ws-addr=0.0.0.0 --ws-port $ws_port \
86+
--ws-origins "*" 2>&1 >>/work/xdcchain/xdc.log | tee -a /work/xdcchain/xdc.log

cmd/XDC/accountcmd.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@ import (
2626
"github.com/XinFinOrg/XDPoSChain/console"
2727
"github.com/XinFinOrg/XDPoSChain/crypto"
2828
"github.com/XinFinOrg/XDPoSChain/log"
29-
"gopkg.in/urfave/cli.v1"
29+
"github.com/urfave/cli/v2"
3030
)
3131

3232
var (
33-
walletCommand = cli.Command{
33+
walletCommand = &cli.Command{
3434
Name: "wallet",
3535
Usage: "Manage XDPoSChain presale wallets",
3636
ArgsUsage: "",
37-
Category: "ACCOUNT COMMANDS",
3837
Description: `
3938
XDC wallet import /path/to/my/presale.wallet
4039
4140
will prompt for your password and imports your ether presale account.
4241
It can be used non-interactively with the --password option taking a
4342
passwordfile as argument containing the wallet password in plaintext.`,
44-
Subcommands: []cli.Command{
43+
Subcommands: []*cli.Command{
4544
{
4645

4746
Name: "import",
4847
Usage: "Import XDPoSChain presale wallet",
4948
ArgsUsage: "<keyFile>",
50-
Action: utils.MigrateFlags(importWallet),
49+
Action: importWallet,
5150
Category: "ACCOUNT COMMANDS",
5251
Flags: []cli.Flag{
5352
utils.DataDirFlag,
53+
utils.XDCXDataDirFlag,
5454
utils.KeyStoreDirFlag,
5555
utils.PasswordFileFlag,
5656
utils.LightKDFFlag,
@@ -65,10 +65,9 @@ passwordfile as argument containing the wallet password in plaintext.`,
6565
},
6666
}
6767

68-
accountCommand = cli.Command{
69-
Name: "account",
70-
Usage: "Manage accounts",
71-
Category: "ACCOUNT COMMANDS",
68+
accountCommand = &cli.Command{
69+
Name: "account",
70+
Usage: "Manage accounts",
7271
Description: `
7372
7473
Manage accounts, list all existing accounts, import a private key into a new
@@ -89,13 +88,14 @@ It is safe to transfer the entire directory or the individual keys therein
8988
between ethereum nodes by simply copying.
9089
9190
Make sure you backup your keys regularly.`,
92-
Subcommands: []cli.Command{
91+
Subcommands: []*cli.Command{
9392
{
9493
Name: "list",
9594
Usage: "Print summary of existing accounts",
96-
Action: utils.MigrateFlags(accountList),
95+
Action: accountList,
9796
Flags: []cli.Flag{
9897
utils.DataDirFlag,
98+
utils.XDCXDataDirFlag,
9999
utils.KeyStoreDirFlag,
100100
},
101101
Description: `
@@ -104,9 +104,10 @@ Print a short summary of all accounts`,
104104
{
105105
Name: "new",
106106
Usage: "Create a new account",
107-
Action: utils.MigrateFlags(accountCreate),
107+
Action: accountCreate,
108108
Flags: []cli.Flag{
109109
utils.DataDirFlag,
110+
utils.XDCXDataDirFlag,
110111
utils.KeyStoreDirFlag,
111112
utils.PasswordFileFlag,
112113
utils.LightKDFFlag,
@@ -129,10 +130,11 @@ password to file or expose in any other way.
129130
{
130131
Name: "update",
131132
Usage: "Update an existing account",
132-
Action: utils.MigrateFlags(accountUpdate),
133+
Action: accountUpdate,
133134
ArgsUsage: "<address>",
134135
Flags: []cli.Flag{
135136
utils.DataDirFlag,
137+
utils.XDCXDataDirFlag,
136138
utils.KeyStoreDirFlag,
137139
utils.LightKDFFlag,
138140
},
@@ -158,9 +160,10 @@ changing your password is only possible interactively.
158160
{
159161
Name: "import",
160162
Usage: "Import a private key into a new account",
161-
Action: utils.MigrateFlags(accountImport),
163+
Action: accountImport,
162164
Flags: []cli.Flag{
163165
utils.DataDirFlag,
166+
utils.XDCXDataDirFlag,
164167
utils.KeyStoreDirFlag,
165168
utils.PasswordFileFlag,
166169
utils.LightKDFFlag,
@@ -293,7 +296,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
293296
func accountCreate(ctx *cli.Context) error {
294297
cfg := XDCConfig{Node: defaultNodeConfig()}
295298
// Load config file.
296-
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
299+
if file := ctx.String(configFileFlag.Name); file != "" {
297300
if err := loadConfig(file, &cfg); err != nil {
298301
utils.Fatalf("%v", err)
299302
}
@@ -319,13 +322,13 @@ func accountCreate(ctx *cli.Context) error {
319322
// accountUpdate transitions an account from a previous format to the current
320323
// one, also providing the possibility to change the pass-phrase.
321324
func accountUpdate(ctx *cli.Context) error {
322-
if len(ctx.Args()) == 0 {
325+
if ctx.Args().Len() == 0 {
323326
utils.Fatalf("No accounts specified to update")
324327
}
325328
stack, _ := makeConfigNode(ctx)
326329
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
327330

328-
for _, addr := range ctx.Args() {
331+
for _, addr := range ctx.Args().Slice() {
329332
account, oldPassword := unlockAccount(ctx, ks, addr, 0, nil)
330333
newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
331334
if err := ks.Update(account, oldPassword, newPassword); err != nil {
@@ -336,10 +339,10 @@ func accountUpdate(ctx *cli.Context) error {
336339
}
337340

338341
func importWallet(ctx *cli.Context) error {
339-
keyfile := ctx.Args().First()
340-
if len(keyfile) == 0 {
341-
utils.Fatalf("keyfile must be given as argument")
342+
if ctx.Args().Len() != 1 {
343+
utils.Fatalf("keyfile must be given as the only argument")
342344
}
345+
keyfile := ctx.Args().First()
343346
keyJson, err := os.ReadFile(keyfile)
344347
if err != nil {
345348
utils.Fatalf("Could not read wallet file: %v", err)
@@ -358,10 +361,10 @@ func importWallet(ctx *cli.Context) error {
358361
}
359362

360363
func accountImport(ctx *cli.Context) error {
361-
keyfile := ctx.Args().First()
362-
if len(keyfile) == 0 {
363-
utils.Fatalf("keyfile must be given as argument")
364+
if ctx.Args().Len() != 1 {
365+
utils.Fatalf("keyfile must be given as the only argument")
364366
}
367+
keyfile := ctx.Args().First()
365368
key, err := crypto.LoadECDSA(keyfile)
366369
if err != nil {
367370
utils.Fatalf("Failed to load the private key: %v", err)

0 commit comments

Comments
 (0)