From a8ff7fecb4f5ccaece90f30b9f5b77dd45ceaefb Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 2 Jan 2014 13:48:06 -0600 Subject: [PATCH] Add createrawtransaction support to btcctl. --- util/btcctl/btcctl.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/util/btcctl/btcctl.go b/util/btcctl/btcctl.go index b34940bd..a41a35c5 100644 --- a/util/btcctl/btcctl.go +++ b/util/btcctl/btcctl.go @@ -45,6 +45,7 @@ var ( // to validate correctness and perform the command. var commandHandlers = map[string]*handlerData{ "addnode": &handlerData{2, 0, displayJSONDump, nil, makeAddNode, " "}, + "createrawtransaction": &handlerData{2, 0, displayGeneric, nil, makeCreateRawTransaction, "\"[{\"txid\":\"id\",\"vout\":n},...]\" \"{\"address\":amount,...}\""}, "debuglevel": &handlerData{1, 0, displayGeneric, nil, makeDebugLevel, ""}, "decoderawtransaction": &handlerData{1, 0, displayJSONDump, nil, makeDecodeRawTransaction, ""}, "dumpprivkey": &handlerData{1, 0, displayGeneric, nil, makeDumpPrivKey, ""}, @@ -151,6 +152,30 @@ func makeAddNode(args []interface{}) (btcjson.Cmd, error) { args[1].(string)) } +// makeCreateRawTransaction generates the cmd structure for createrawtransaction +// comands. +func makeCreateRawTransaction(args []interface{}) (btcjson.Cmd, error) { + // First unmarshal the JSON provided by the parameters into interfaces. + var iinputs, iamounts interface{} + err := json.Unmarshal([]byte(args[0].(string)), &iinputs) + if err != nil { + return nil, err + } + err = json.Unmarshal([]byte(args[1].(string)), &iamounts) + if err != nil { + return nil, err + } + + // Validate and convert the interfaces to concrete types. + inputs, amounts, err := btcjson.ConvertCreateRawTxParams(iinputs, + iamounts) + if err != nil { + return nil, err + } + + return btcjson.NewCreateRawTransactionCmd("btcctl", inputs, amounts) +} + // makeDebugLevel generates the cmd structure for debuglevel commands. func makeDebugLevel(args []interface{}) (btcjson.Cmd, error) { return btcjson.NewDebugLevelCmd("btcctl", args[0].(string))