add sendmany to btcctl

This commit is contained in:
David Hill 2014-01-27 15:57:44 -05:00
parent b354015426
commit c0d6180685

View file

@ -76,6 +76,7 @@ var commandHandlers = map[string]*handlerData{
"ping": &handlerData{0, 0, displayGeneric, nil, makePing, ""},
"sendfrom": &handlerData{3, 3, displayGeneric, []conversionHandler{nil, nil, toSatoshi, toInt, nil, nil},
makeSendFrom, "<account> <address> <amount> [minconf=1] [comment] [comment-to]"},
"sendmany": &handlerData{2, 2, displayGeneric, []conversionHandler{nil, nil, toInt, nil}, makeSendMany, "<account> <{\"address\":amount,...}> [minconf=1] [comment]"},
"sendrawtransaction": &handlerData{1, 0, displayGeneric, nil, makeSendRawTransaction, "<hextx>"},
"stop": &handlerData{0, 0, displayGeneric, nil, makeStop, ""},
"submitblock": &handlerData{1, 1, displayGeneric, nil, makeSubmitBlock, "<hexdata> [jsonparametersobject]"},
@ -463,6 +464,30 @@ func makeSendFrom(args []interface{}) (btcjson.Cmd, error) {
args[2].(int64), minconf, comment, commentTo)
}
// makeSendMany generates the cmd structure for sendmany commands.
func makeSendMany(args []interface{}) (btcjson.Cmd, error) {
minconf := 1
comment := ""
origPairs := make(map[string]float64)
err := json.Unmarshal([]byte(args[1].(string)), &origPairs)
if err != nil {
return nil, err
}
pairs := make(map[string]int64)
for addr, value := range origPairs {
pairs[addr] = int64(float64(btcutil.SatoshiPerBitcoin) * value)
}
if len(args) > 2 {
minconf = args[2].(int)
}
if len(args) > 3 {
comment = args[3].(string)
}
return btcjson.NewSendManyCmd("btcctl", args[0].(string), pairs, minconf, comment)
}
// makeSendRawTransaction generates the cmd structure for sendrawtransaction
// commands.
func makeSendRawTransaction(args []interface{}) (btcjson.Cmd, error) {