From d2d518a8e42dc921c362942ea130644d2ebe64cc Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 23 Jun 2014 16:54:00 -0500 Subject: [PATCH] btcctl: Add lockunspent support. ok @davecgh --- util/btcctl/btcctl.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/util/btcctl/btcctl.go b/util/btcctl/btcctl.go index 6fade54f..13223cfe 100644 --- a/util/btcctl/btcctl.go +++ b/util/btcctl/btcctl.go @@ -42,13 +42,15 @@ var ( ErrUsage = errors.New("btcctl usage") // Real usage is shown. ) +const outpointArrayStr = `"[{"txid":"id","vout":n},...]"` + // commandHandlers is a map of commands and associated handler data that is used // to validate correctness and perform the command. var commandHandlers = map[string]*handlerData{ "addmultisigaddress": {2, 1, displayGeneric, []conversionHandler{toInt, nil, nil}, makeAddMultiSigAddress, " <[\"pubkey\",...]> [account]"}, "addnode": {2, 0, displayJSONDump, nil, makeAddNode, " "}, "createencryptedwallet": {1, 0, displayGeneric, nil, makeCreateEncryptedWallet, ""}, - "createrawtransaction": {2, 0, displayGeneric, nil, makeCreateRawTransaction, "\"[{\"txid\":\"id\",\"vout\":n},...]\" \"{\"address\":amount,...}\""}, + "createrawtransaction": {2, 0, displayGeneric, nil, makeCreateRawTransaction, outpointArrayStr + " " + "\"{\"address\":amount,...}\""}, "debuglevel": {1, 0, displayGeneric, nil, makeDebugLevel, ""}, "decoderawtransaction": {1, 0, displayJSONDump, nil, makeDecodeRawTransaction, ""}, "decodescript": {1, 0, displayJSONDump, nil, makeDecodeScript, ""}, @@ -96,6 +98,7 @@ var commandHandlers = map[string]*handlerData{ "listsinceblock": {0, 2, displayJSONDump, []conversionHandler{nil, toInt}, makeListSinceBlock, "[blockhash] [minconf=10]"}, "listtransactions": {0, 3, displayJSONDump, []conversionHandler{nil, toInt, toInt}, makeListTransactions, "[account] [count=10] [from=0]"}, "listunspent": {0, 3, displayJSONDump, []conversionHandler{toInt, toInt, nil}, makeListUnspent, "[minconf=1] [maxconf=9999999] [jsonaddressarray]"}, + "lockunspent": {1, 2, displayJSONDump, []conversionHandler{toBool, nil}, makeLockUnspent, " " + outpointArrayStr}, "ping": {0, 0, displayGeneric, nil, makePing, ""}, "sendfrom": {3, 3, displayGeneric, []conversionHandler{nil, nil, toSatoshi, toInt, nil, nil}, makeSendFrom, "
[minconf=1] [comment] [comment-to]"}, @@ -661,6 +664,21 @@ func makeListUnspent(args []interface{}) (btcjson.Cmd, error) { return btcjson.NewListUnspentCmd("btcctl", optargs...) } +// makeLockUnspent generates the cmd structure for lockunspent commands. +func makeLockUnspent(args []interface{}) (btcjson.Cmd, error) { + var optargs = make([][]btcjson.TransactionInput, 0, 1) + if len(args) > 1 { + var inputs []btcjson.TransactionInput + err := json.Unmarshal([]byte(args[1].(string)), &inputs) + if err != nil { + return nil, err + } + optargs = append(optargs, inputs) + } + + return btcjson.NewLockUnspentCmd("btcctl", args[0].(bool), optargs...) +} + // makePing generates the cmd structure for ping commands. func makePing(args []interface{}) (btcjson.Cmd, error) { return btcjson.NewPingCmd("btcctl")