Correct btcctl getblockhash.

Also run gofmt while here.
This commit is contained in:
Dave Collins 2013-11-07 17:07:26 -06:00
parent d81a2c9067
commit af311078b4

View file

@ -51,10 +51,9 @@ var commandHandlers = map[string]*handlerData{
"addnode": &handlerData{2, 0, displaySpewDump, nil, makeAddNode, "<ip> <add/remove/onetry>"},
"decoderawtransaction": &handlerData{1, 0, displaySpewDump, nil, makeDecodeRawTransaction, "<txhash>"},
"getbestblockhash": &handlerData{0, 0, displayGeneric, nil, makeGetBestBlockHash, ""},
"getblock": &handlerData{1, 0, displaySpewDump, nil, makeGetBlock,
"<blockhash>"},
"getblock": &handlerData{1, 0, displaySpewDump, nil, makeGetBlock, "<blockhash>"},
"getblockcount": &handlerData{0, 0, displayFloat64, nil, makeGetBlockCount, ""},
"getblockhash": &handlerData{1, 0, displayGeneric, []conversionHandler{toInt}, makeGetBlockHash, "<blocknumber>"},
"getblockhash": &handlerData{1, 0, displayGeneric, []conversionHandler{toInt64}, makeGetBlockHash, "<blocknumber>"},
"getconnectioncount": &handlerData{0, 0, displayFloat64, nil, makeGetConnectionCount, ""},
"getdifficulty": &handlerData{0, 0, displayFloat64, nil, makeGetDifficulty, ""},
"getgenerate": &handlerData{0, 0, displayGeneric, nil, makeGetGenerate, ""},
@ -77,6 +76,19 @@ func toInt(val string) (interface{}, error) {
return idx, nil
}
// toInt64 attempts to convert the passed string to an int64. It returns the
// integer packed into an interface so it can be used in the calls which expect
// interfaces. An error will be returned if the string can't be converted to an
// integer.
func toInt64(val string) (interface{}, error) {
idx, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, err
}
return idx, nil
}
// displayGeneric is a displayHandler that simply displays the passed interface
// using fmt.Println.
func displayGeneric(reply interface{}) error {