Fix for signrawtransaction.

Add sendrawtransaction to list of commands we know the return type
for.
This commit is contained in:
John C. Vernaleo 2013-08-12 16:01:01 -04:00
parent dc9618c9ab
commit 5444d262b8
3 changed files with 38 additions and 21 deletions

View file

@ -649,9 +649,10 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
return finalMessage, err return finalMessage, err
} }
finalMessage, err = jsonWithArgs(message, id, args) finalMessage, err = jsonWithArgs(message, id, args)
// one required string (hex) and sets of 4 optional strings. // one required string (hex) and optional sets of one string, one int,
// and one string along with another optional string.
case "signrawtransaction": case "signrawtransaction":
if len(args) < 1 || (len(args)-1)%4 != 0 { if len(args) < 1 {
err = fmt.Errorf("Wrong number of arguments for %s", message) err = fmt.Errorf("Wrong number of arguments for %s", message)
return finalMessage, err return finalMessage, err
} }
@ -662,26 +663,42 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
} }
type txlist struct { type txlist struct {
Txid string `json:"txid"` Txid string `json:"txid"`
Vout string `json:"vout"` Vout int `json:"vout"`
ScriptPubKey string `json:"scriptPubKey"` ScriptPubKey string `json:"scriptPubKey"`
} }
txList := make([]txlist, (len(args)-1)/4) txList := make([]txlist, 1)
pkeyList := make([]string, (len(args)-1)/4)
for i := 0; i < len(args)/4; i += 1 { if len(args) > 1 {
txid, ok1 := args[(i*4)+0].(string) txid, ok2 := args[1].(string)
vout, ok2 := args[(i*4)+1].(string) vout, ok3 := args[2].(int)
spkey, ok3 := args[(i*4)+2].(string) spkey, ok4 := args[3].(string)
pkey, ok4 := args[(i*4)+3].(string)
if !ok1 || !ok2 || !ok3 || !ok4 { if !ok1 || !ok2 || !ok3 || !ok4 {
err = fmt.Errorf("Incorrect arguement types.") err = fmt.Errorf("Incorrect arguement types.")
return finalMessage, err return finalMessage, err
} }
txList[i].Txid = txid txList[0].Txid = txid
txList[i].Vout = vout txList[0].Vout = vout
txList[i].ScriptPubKey = spkey txList[0].ScriptPubKey = spkey
pkeyList[i] = pkey
} }
finalMessage, err = jsonWithArgs(message, id, []interface{}{args[0].(string), txList, pkeyList}) /*
pkeyList := make([]string, (len(args)-1)/4)
for i := 0; i < len(args)/4; i += 1 {
fmt.Println(args[(i*4)+4])
txid, ok1 := args[(i*4)+1].(string)
vout, ok2 := args[(i*4)+2].(int)
spkey, ok3 := args[(i*4)+3].(string)
pkey, ok4 := args[(i*4)+4].(string)
if !ok1 || !ok2 || !ok3 || !ok4 {
err = fmt.Errorf("Incorrect arguement types.")
return finalMessage, err
}
txList[i].Txid = txid
txList[i].Vout = vout
txList[i].ScriptPubKey = spkey
pkeyList[i] = pkey
}
*/
finalMessage, err = jsonWithArgs(message, id, []interface{}{args[0].(string), txList})
// Any other message // Any other message
default: default:
err = fmt.Errorf("Not a valid command: %s", message) err = fmt.Errorf("Not a valid command: %s", message)
@ -780,7 +797,8 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
case "getblockcount", "getbalance", "getblocknumber", "getgenerate", case "getblockcount", "getbalance", "getblocknumber", "getgenerate",
"getconnetioncount", "getdifficulty", "gethashespersec", "getconnetioncount", "getdifficulty", "gethashespersec",
"setgenerate", "stop", "settxfee", "getaccount", "setgenerate", "stop", "settxfee", "getaccount",
"getnewaddress", "sendtoaddress", "createrawtransaction": "getnewaddress", "sendtoaddress", "createrawtransaction",
"sendrawtransaction":
err = json.Unmarshal(message, &result) err = json.Unmarshal(message, &result)
// For anything else put it in an interface. All the data is still // For anything else put it in an interface. All the data is still
// there, just a little less convenient to deal with. // there, just a little less convenient to deal with.

View file

@ -156,12 +156,11 @@ var cmdtests = []struct {
{"lockunspent", []interface{}{true, "something"}, true}, {"lockunspent", []interface{}{true, "something"}, true},
{"lockunspent", []interface{}{true}, false}, {"lockunspent", []interface{}{true}, false},
{"lockunspent", []interface{}{1.0, "something"}, false}, {"lockunspent", []interface{}{1.0, "something"}, false},
{"signrawtransaction", []interface{}{"hexstring"}, true}, {"signrawtransaction", []interface{}{"hexstring", "test", 1, "test"}, true},
{"signrawtransaction", []interface{}{"hexstring", "test", "test2", "test3", "test4"}, true}, {"signrawtransaction", []interface{}{"hexstring", "test", "test2", "test3", "test4"}, false},
{"signrawtransaction", []interface{}{"hexstring", "test", "test2", "test3"}, false}, {"signrawtransaction", []interface{}{"hexstring", "test", "test2", "test3"}, false},
{"signrawtransaction", []interface{}{1.2, "test", "test2", "test3", "test4"}, false}, {"signrawtransaction", []interface{}{1.2, "test", "test2", "test3", "test4"}, false},
{"signrawtransaction", []interface{}{"hexstring", 1, "test2", "test3", "test4"}, false}, {"signrawtransaction", []interface{}{"hexstring", 1, "test2", "test3", "test4"}, false},
{"signrawtransaction", []interface{}{"hexstring", "test", 2, "test3", "test4"}, false},
{"signrawtransaction", []interface{}{"hexstring", "test", "test2", 3, "test4"}, false}, {"signrawtransaction", []interface{}{"hexstring", "test", "test2", 3, "test4"}, false},
{"listsinceblock", []interface{}{"test", "test"}, true}, {"listsinceblock", []interface{}{"test", "test"}, true},
{"listsinceblock", []interface{}{"test", "test", "test"}, false}, {"listsinceblock", []interface{}{"test", "test", "test"}, false},

View file

@ -1,5 +1,4 @@
github.com/conformal/btcjson/jsonapi.go CreateMessageWithId 100.00% (332/332)
github.com/conformal/btcjson/jsonapi.go ReadResultCmd 100.00% (64/64) github.com/conformal/btcjson/jsonapi.go ReadResultCmd 100.00% (64/64)
github.com/conformal/btcjson/jsonapi.go JSONToAmount 100.00% (15/15) github.com/conformal/btcjson/jsonapi.go JSONToAmount 100.00% (15/15)
github.com/conformal/btcjson/jsonapi.go JSONGetMethod 100.00% (14/14) github.com/conformal/btcjson/jsonapi.go JSONGetMethod 100.00% (14/14)
@ -9,7 +8,8 @@ github.com/conformal/btcjson/jsonfxns.go GetRaw 100.00% (6/6)
github.com/conformal/btcjson/jsonapi.go jsonWithArgs 100.00% (5/5) github.com/conformal/btcjson/jsonapi.go jsonWithArgs 100.00% (5/5)
github.com/conformal/btcjson/jsonapi.go IsValidIdType 100.00% (3/3) github.com/conformal/btcjson/jsonapi.go IsValidIdType 100.00% (3/3)
github.com/conformal/btcjson/jsonapi.go CreateMessage 100.00% (2/2) github.com/conformal/btcjson/jsonapi.go CreateMessage 100.00% (2/2)
github.com/conformal/btcjson/jsonapi.go CreateMessageWithId 99.39% (327/329)
github.com/conformal/btcjson/jsonapi.go RpcCommand 61.54% (8/13) github.com/conformal/btcjson/jsonapi.go RpcCommand 61.54% (8/13)
github.com/conformal/btcjson/jsonapi.go RpcRawCommand 53.33% (8/15) github.com/conformal/btcjson/jsonapi.go RpcRawCommand 53.33% (8/15)
github.com/conformal/btcjson ------------------- 97.52% (471/483) github.com/conformal/btcjson ------------------- 97.08% (466/480)