btcctl: Add lockunspent support.

ok @davecgh
This commit is contained in:
Josh Rickmar 2014-06-23 16:54:00 -05:00
parent 5f444ce000
commit d2d518a8e4

View file

@ -42,13 +42,15 @@ var (
ErrUsage = errors.New("btcctl usage") // Real usage is shown. 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 // commandHandlers is a map of commands and associated handler data that is used
// to validate correctness and perform the command. // to validate correctness and perform the command.
var commandHandlers = map[string]*handlerData{ var commandHandlers = map[string]*handlerData{
"addmultisigaddress": {2, 1, displayGeneric, []conversionHandler{toInt, nil, nil}, makeAddMultiSigAddress, "<numrequired> <[\"pubkey\",...]> [account]"}, "addmultisigaddress": {2, 1, displayGeneric, []conversionHandler{toInt, nil, nil}, makeAddMultiSigAddress, "<numrequired> <[\"pubkey\",...]> [account]"},
"addnode": {2, 0, displayJSONDump, nil, makeAddNode, "<ip> <add/remove/onetry>"}, "addnode": {2, 0, displayJSONDump, nil, makeAddNode, "<ip> <add/remove/onetry>"},
"createencryptedwallet": {1, 0, displayGeneric, nil, makeCreateEncryptedWallet, "<passphrase>"}, "createencryptedwallet": {1, 0, displayGeneric, nil, makeCreateEncryptedWallet, "<passphrase>"},
"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, "<levelspec>"}, "debuglevel": {1, 0, displayGeneric, nil, makeDebugLevel, "<levelspec>"},
"decoderawtransaction": {1, 0, displayJSONDump, nil, makeDecodeRawTransaction, "<txhash>"}, "decoderawtransaction": {1, 0, displayJSONDump, nil, makeDecodeRawTransaction, "<txhash>"},
"decodescript": {1, 0, displayJSONDump, nil, makeDecodeScript, "<hex>"}, "decodescript": {1, 0, displayJSONDump, nil, makeDecodeScript, "<hex>"},
@ -96,6 +98,7 @@ var commandHandlers = map[string]*handlerData{
"listsinceblock": {0, 2, displayJSONDump, []conversionHandler{nil, toInt}, makeListSinceBlock, "[blockhash] [minconf=10]"}, "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]"}, "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]"}, "listunspent": {0, 3, displayJSONDump, []conversionHandler{toInt, toInt, nil}, makeListUnspent, "[minconf=1] [maxconf=9999999] [jsonaddressarray]"},
"lockunspent": {1, 2, displayJSONDump, []conversionHandler{toBool, nil}, makeLockUnspent, "<unlock> " + outpointArrayStr},
"ping": {0, 0, displayGeneric, nil, makePing, ""}, "ping": {0, 0, displayGeneric, nil, makePing, ""},
"sendfrom": {3, 3, displayGeneric, []conversionHandler{nil, nil, toSatoshi, toInt, nil, nil}, "sendfrom": {3, 3, displayGeneric, []conversionHandler{nil, nil, toSatoshi, toInt, nil, nil},
makeSendFrom, "<account> <address> <amount> [minconf=1] [comment] [comment-to]"}, makeSendFrom, "<account> <address> <amount> [minconf=1] [comment] [comment-to]"},
@ -661,6 +664,21 @@ func makeListUnspent(args []interface{}) (btcjson.Cmd, error) {
return btcjson.NewListUnspentCmd("btcctl", optargs...) 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. // makePing generates the cmd structure for ping commands.
func makePing(args []interface{}) (btcjson.Cmd, error) { func makePing(args []interface{}) (btcjson.Cmd, error) {
return btcjson.NewPingCmd("btcctl") return btcjson.NewPingCmd("btcctl")