From af311078b4d3ca809ab7f7c1b5122ae3506d3999 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 7 Nov 2013 17:07:26 -0600 Subject: [PATCH] Correct btcctl getblockhash. Also run gofmt while here. --- util/btcctl/btcctl.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/util/btcctl/btcctl.go b/util/btcctl/btcctl.go index 2ef48bd3..04ad8cdc 100644 --- a/util/btcctl/btcctl.go +++ b/util/btcctl/btcctl.go @@ -51,17 +51,16 @@ var commandHandlers = map[string]*handlerData{ "addnode": &handlerData{2, 0, displaySpewDump, nil, makeAddNode, " "}, "decoderawtransaction": &handlerData{1, 0, displaySpewDump, nil, makeDecodeRawTransaction, ""}, "getbestblockhash": &handlerData{0, 0, displayGeneric, nil, makeGetBestBlockHash, ""}, - "getblock": &handlerData{1, 0, displaySpewDump, nil, makeGetBlock, - ""}, - "getblockcount": &handlerData{0, 0, displayFloat64, nil, makeGetBlockCount, ""}, - "getblockhash": &handlerData{1, 0, displayGeneric, []conversionHandler{toInt}, makeGetBlockHash, ""}, - "getconnectioncount": &handlerData{0, 0, displayFloat64, nil, makeGetConnectionCount, ""}, - "getdifficulty": &handlerData{0, 0, displayFloat64, nil, makeGetDifficulty, ""}, - "getgenerate": &handlerData{0, 0, displayGeneric, nil, makeGetGenerate, ""}, - "getpeerinfo": &handlerData{0, 0, displaySpewDump, nil, makeGetPeerInfo, ""}, - "getrawmempool": &handlerData{0, 0, displaySpewDump, nil, makeGetRawMempool, ""}, - "getrawtransaction": &handlerData{1, 1, displaySpewDump, []conversionHandler{nil, toInt}, makeGetRawTransaction, " [verbose=0]"}, - "stop": &handlerData{0, 0, displayGeneric, nil, makeStop, ""}, + "getblock": &handlerData{1, 0, displaySpewDump, nil, makeGetBlock, ""}, + "getblockcount": &handlerData{0, 0, displayFloat64, nil, makeGetBlockCount, ""}, + "getblockhash": &handlerData{1, 0, displayGeneric, []conversionHandler{toInt64}, makeGetBlockHash, ""}, + "getconnectioncount": &handlerData{0, 0, displayFloat64, nil, makeGetConnectionCount, ""}, + "getdifficulty": &handlerData{0, 0, displayFloat64, nil, makeGetDifficulty, ""}, + "getgenerate": &handlerData{0, 0, displayGeneric, nil, makeGetGenerate, ""}, + "getpeerinfo": &handlerData{0, 0, displaySpewDump, nil, makeGetPeerInfo, ""}, + "getrawmempool": &handlerData{0, 0, displaySpewDump, nil, makeGetRawMempool, ""}, + "getrawtransaction": &handlerData{1, 1, displaySpewDump, []conversionHandler{nil, toInt}, makeGetRawTransaction, " [verbose=0]"}, + "stop": &handlerData{0, 0, displayGeneric, nil, makeStop, ""}, } // toInt attempts to convert the passed string to an integer. It returns the @@ -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 {