Add support for debuglevel RPC command.
Also include the supported subsystems in the error message if an invalid subsystem is specified. Closes #15.
This commit is contained in:
parent
e930dc55f0
commit
daa5310e2f
3 changed files with 44 additions and 12 deletions
26
config.go
26
config.go
|
@ -121,15 +121,10 @@ func supportedSubsystems() []string {
|
|||
return subsystems
|
||||
}
|
||||
|
||||
// parseDebugLevel attempt to parse the specified debug level and set the levels
|
||||
// accordingly. An appropriate error is returned if anything is invalid.
|
||||
func parseDebugLevel(debugLevel string) error {
|
||||
// Special show command to list supported subsystems.
|
||||
if debugLevel == "show" {
|
||||
fmt.Println("Supported subsystems", supportedSubsystems())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// parseAndSetDebugLevels attempts to parse the specified debug level and set
|
||||
// the levels accordingly. An appropriate error is returned if anything is
|
||||
// invalid.
|
||||
func parseAndSetDebugLevels(debugLevel string) error {
|
||||
// When the specified string doesn't have any delimters, treat it as
|
||||
// the log level for all subsystems.
|
||||
if !strings.Contains(debugLevel, ",") && !strings.Contains(debugLevel, "=") {
|
||||
|
@ -162,8 +157,9 @@ func parseDebugLevel(debugLevel string) error {
|
|||
|
||||
// Validate subsystem.
|
||||
if _, exists := subsystemLoggers[subsysID]; !exists {
|
||||
str := "The specified subsystem [%v] is invalid"
|
||||
return fmt.Errorf(str, subsysID)
|
||||
str := "The specified subsystem [%v] is invalid -- " +
|
||||
"supported subsytems %v"
|
||||
return fmt.Errorf(str, subsysID, supportedSubsystems())
|
||||
}
|
||||
|
||||
// Validate log level.
|
||||
|
@ -326,8 +322,14 @@ func loadConfig() (*config, []string, error) {
|
|||
activeNetParams = netParams(btcwire.TestNet)
|
||||
}
|
||||
|
||||
// Special show command to list supported subsystems and exit.
|
||||
if cfg.DebugLevel == "show" {
|
||||
fmt.Println("Supported subsystems", supportedSubsystems())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Parse, validate, and set debug log level(s).
|
||||
if err := parseDebugLevel(cfg.DebugLevel); err != nil {
|
||||
if err := parseAndSetDebugLevels(cfg.DebugLevel); err != nil {
|
||||
err := fmt.Errorf("%s: %v", "loadConfig", err.Error())
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
parser.WriteHelp(os.Stderr)
|
||||
|
|
24
rpcserver.go
24
rpcserver.go
|
@ -547,6 +547,7 @@ var handlers = map[string]commandHandler{
|
|||
"backupwallet": handleAskWallet,
|
||||
"createmultisig": handleAskWallet,
|
||||
"createrawtransaction": handleUnimplemented,
|
||||
"debuglevel": handleDebugLevel,
|
||||
"decoderawtransaction": handleDecodeRawTransaction,
|
||||
"decodescript": handleUnimplemented,
|
||||
"dumpprivkey": handleAskWallet,
|
||||
|
@ -662,6 +663,29 @@ func handleAddNode(s *rpcServer, cmd btcjson.Cmd,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// handleDebugLevel handles debuglevel commands.
|
||||
func handleDebugLevel(s *rpcServer, cmd btcjson.Cmd,
|
||||
walletNotification chan []byte) (interface{}, error) {
|
||||
c := cmd.(*btcjson.DebugLevelCmd)
|
||||
|
||||
// Special show command to list supported subsystems.
|
||||
if c.LevelSpec == "show" {
|
||||
return fmt.Sprintf("Supported subsystems %v",
|
||||
supportedSubsystems()), nil
|
||||
}
|
||||
|
||||
err := parseAndSetDebugLevels(c.LevelSpec)
|
||||
if err != nil {
|
||||
jsonErr := btcjson.Error{
|
||||
Code: btcjson.ErrInvalidParams.Code,
|
||||
Message: err.Error(),
|
||||
}
|
||||
return nil, jsonErr
|
||||
}
|
||||
|
||||
return "Done.", nil
|
||||
}
|
||||
|
||||
// handleDecodeRawTransaction handles decoderawtransaction commands.
|
||||
func handleDecodeRawTransaction(s *rpcServer, cmd btcjson.Cmd,
|
||||
walletNotification chan []byte) (interface{}, error) {
|
||||
|
|
|
@ -44,6 +44,7 @@ var (
|
|||
// to validate correctness and perform the command.
|
||||
var commandHandlers = map[string]*handlerData{
|
||||
"addnode": &handlerData{2, 0, displaySpewDump, nil, makeAddNode, "<ip> <add/remove/onetry>"},
|
||||
"debuglevel": &handlerData{1, 0, displayGeneric, nil, makeDebugLevel, "<levelspec>"},
|
||||
"decoderawtransaction": &handlerData{1, 0, displaySpewDump, nil, makeDecodeRawTransaction, "<txhash>"},
|
||||
"dumpprivkey": &handlerData{1, 0, displayGeneric, nil, makeDumpPrivKey, "<bitcoinaddress>"},
|
||||
"getbestblockhash": &handlerData{0, 0, displayGeneric, nil, makeGetBestBlockHash, ""},
|
||||
|
@ -127,6 +128,11 @@ func makeAddNode(args []interface{}) (btcjson.Cmd, error) {
|
|||
args[1].(string))
|
||||
}
|
||||
|
||||
// makeDebugLevel generates the cmd structure for debuglevel commands.
|
||||
func makeDebugLevel(args []interface{}) (btcjson.Cmd, error) {
|
||||
return btcjson.NewDebugLevelCmd("btcctl", args[0].(string))
|
||||
}
|
||||
|
||||
// makeDecodeRawTransaction generates the cmd structure for
|
||||
// decoderawtransaction comands.
|
||||
func makeDecodeRawTransaction(args []interface{}) (btcjson.Cmd, error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue