Skip to content

Commit

Permalink
fix some cmd bug
Browse files Browse the repository at this point in the history
  • Loading branch information
erickyan86 committed May 13, 2019
1 parent c78d2a3 commit 40c6e6b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 39 deletions.
2 changes: 0 additions & 2 deletions build/eg_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ log:
node:
# the node datadir
datadir: "./build/testdatadir"
# Reduce key-derivation RAM & CPU usage at some expense of KDF strength
lightkdf: false
# RPC:ipc file name
ipcpath: "ft.ipc"
# RPC:http host address
Expand Down
27 changes: 13 additions & 14 deletions cmd/ft/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,19 @@ func defaultFtConfig() *ftConfig {

func defaultNodeConfig() *node.Config {
return &node.Config{
Name: params.ClientIdentifier,
DataDir: defaultDataDir(),
UseLightweightKDF: false,
IPCPath: params.ClientIdentifier + ".ipc",
HTTPHost: "localhost",
HTTPPort: 8545,
HTTPModules: []string{"ft", "dpos", "fee", "account"},
HTTPVirtualHosts: []string{"localhost"},
HTTPCors: []string{"*"},
WSHost: "localhost",
WSPort: 8546,
WSModules: []string{"ft"},
Logger: log.New(),
P2PConfig: defaultP2pConfig(),
Name: params.ClientIdentifier,
DataDir: defaultDataDir(),
IPCPath: params.ClientIdentifier + ".ipc",
HTTPHost: "localhost",
HTTPPort: 8545,
HTTPModules: []string{"ft", "dpos", "fee", "account"},
HTTPVirtualHosts: []string{"localhost"},
HTTPCors: []string{"*"},
WSHost: "localhost",
WSPort: 8546,
WSModules: []string{"ft"},
Logger: log.New(),
P2PConfig: defaultP2pConfig(),
}
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/ft/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var cpuProfileCmd = &cobra.Command{
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
clientCall(ipcEndpoint, nil, "debug_gcStats", args[0], parseUint64(args[1]))
printJSON(true)
},
}

Expand All @@ -73,6 +74,7 @@ var goTraceCmd = &cobra.Command{
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
clientCall(ipcEndpoint, nil, "debug_goTrace", args[0], parseUint64(args[1]))
printJSON(true)
},
}

Expand All @@ -83,6 +85,7 @@ var blockProfileCmd = &cobra.Command{
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
clientCall(ipcEndpoint, nil, "debug_blockProfile", args[0], parseUint64(args[1]))
printJSON(true)
},
}

Expand All @@ -93,6 +96,7 @@ var mutexProfileCmd = &cobra.Command{
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
clientCall(ipcEndpoint, nil, "debug_mutexProfile", args[0], parseUint64(args[1]))
printJSON(true)
},
}

Expand All @@ -103,6 +107,7 @@ var writeMemProfileCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
clientCall(ipcEndpoint, nil, "debug_writeMemProfile", args[0])
printJSON(true)
},
}

Expand All @@ -125,6 +130,7 @@ var freeOSMemoryCmd = &cobra.Command{
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
clientCall(ipcEndpoint, nil, "debug_freeOSMemory")
printJSON(true)
},
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/ft/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ func addFlags(flags *flag.FlagSet) {
viper.BindPFlag("node.datadir", flags.Lookup("datadir"))

// node
flags.BoolVar(
&ftCfgInstance.NodeCfg.UseLightweightKDF,
"lightkdf",
ftCfgInstance.NodeCfg.UseLightweightKDF,
"Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
)
viper.BindPFlag("node.lightkdf", flags.Lookup("lightkdf"))

flags.StringVar(
&ftCfgInstance.NodeCfg.IPCPath,
"ipcpath",
Expand Down
13 changes: 5 additions & 8 deletions cmd/ft/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var forceCmd = &cobra.Command{
Use: "force ",
Short: "force start mint new block.",
Long: `force start mint new block.`,
Args: cobra.RangeArgs(0, 1),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
var result bool
clientCall(ipcEndpoint, &result, "miner_force")
Expand Down Expand Up @@ -89,7 +89,6 @@ var setCoinbaseCmd = &cobra.Command{
Long: `Set the coinbase of the miner.`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var result bool
name := common.Name(args[0])
if !name.IsValid(regexp.MustCompile("^([a-z][a-z0-9]{6,15})(?:\\.([a-z0-9]{1,8})){0,1}$")) {
jww.ERROR.Println("valid name: " + name)
Expand Down Expand Up @@ -123,9 +122,8 @@ var setCoinbaseCmd = &cobra.Command{
jww.ERROR.Println("keys is empty ", "path", path)
return
}

clientCall(ipcEndpoint, &result, "miner_mining", name, keys)
printJSON(result)
clientCall(ipcEndpoint, nil, "miner_setCoinbase", name, keys)
printJSON(true)
},
}

Expand All @@ -135,9 +133,8 @@ var setExtraCmd = &cobra.Command{
Long: `Set the extra of the miner.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var result bool
clientCall(ipcEndpoint, &result, "miner_setExtra", args[0])
printJSON(result)
clientCall(ipcEndpoint, nil, "miner_setExtra", args[0])
printJSON(true)
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/ft/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var badlistCmd = &cobra.Command{
Use: "badlist",
Short: "return bad nodes list.",
Long: `return bad nodes list.`,
Args: cobra.ExactArgs(1),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
var result []string
clientCall(ipcEndpoint, &result, "p2p_badNodes")
Expand All @@ -152,7 +152,7 @@ var selfnodeCmd = &cobra.Command{
Use: "selfnode",
Short: "return bad nodes list.",
Long: `return bad nodes list.`,
Args: cobra.ExactArgs(1),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
var result string
clientCall(ipcEndpoint, &result, "p2p_selfNode")
Expand Down
3 changes: 2 additions & 1 deletion cmd/ft/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ func clientCall(endpoint string, result interface{}, method string, args ...inte
client, err := dialRPC(ipcEndpoint)
if err != nil {
jww.ERROR.Println(err)
return
os.Exit(-1)
}
if err := client.Call(result, method, args...); err != nil {
jww.ERROR.Println(err)
os.Exit(-1)
}
}

Expand Down
7 changes: 3 additions & 4 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ const (
// Config represents a small collection of configuration values to fine tune the
// P2P network layer of a protocol stack.
type Config struct {
Name string
DataDir string `mapstructure:"datadir"`
UseLightweightKDF bool `mapstructure:"lightkdf"`
IPCPath string `mapstructure:"ipcpath"`
Name string
DataDir string `mapstructure:"datadir"`
IPCPath string `mapstructure:"ipcpath"`

HTTPHost string `mapstructure:"httphost"`
HTTPPort int `mapstructure:"httpport"`
Expand Down

0 comments on commit 40c6e6b

Please sign in to comment.