From cc6dfd1f4b7709447c6e2b73ebf44946d0b926c5 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 20 Aug 2012 16:18:17 -0400 Subject: Allow signrawtransaction '...' null null 'hashtype' Allows the user to pass null as the second or third parameter to signrawtransaction, in case you need to (for example) fetch private keys from the wallet but want to specify the hash type. --- src/bitcoinrpc.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 208c830aa..ef0c4a1be 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -66,7 +66,8 @@ Object JSONRPCError(int code, const string& message) } void RPCTypeCheck(const Array& params, - const list& typesExpected) + const list& typesExpected, + bool fAllowNull) { unsigned int i = 0; BOOST_FOREACH(Value_type t, typesExpected) @@ -74,8 +75,8 @@ void RPCTypeCheck(const Array& params, if (params.size() <= i) break; - const Value& v = params[i]; - if (v.type() != t) + const Value& v = params[i]; + if (!((v.type() == t) || (fAllowNull && (v.type() == null_type)))) { string err = strprintf("Expected type %s, got %s", Value_type_name[t], Value_type_name[v.type()]); @@ -86,14 +87,16 @@ void RPCTypeCheck(const Array& params, } void RPCTypeCheck(const Object& o, - const map& typesExpected) + const map& typesExpected, + bool fAllowNull) { BOOST_FOREACH(const PAIRTYPE(string, Value_type)& t, typesExpected) { const Value& v = find_value(o, t.first); - if (v.type() == null_type) + if (!fAllowNull && v.type() == null_type) throw JSONRPCError(-3, strprintf("Missing %s", t.first.c_str())); - if (v.type() != t.second) + + if (!((v.type() == t.second) || (fAllowNull && (v.type() == null_type)))) { string err = strprintf("Expected type %s for %s, got %s", Value_type_name[t.second], t.first.c_str(), Value_type_name[v.type()]); @@ -3040,8 +3043,10 @@ Object CallRPC(const string& strMethod, const Array& params) template -void ConvertTo(Value& value) +void ConvertTo(Value& value, bool fAllowNull=false) { + if (fAllowNull && value.type() == null_type) + return; if (value.type() == str_type) { // reinterpret string as unquoted json value @@ -3049,7 +3054,8 @@ void ConvertTo(Value& value) string strJSON = value.get_str(); if (!read_string(strJSON, value2)) throw runtime_error(string("Error parsing JSON:")+strJSON); - value = value2.get_value(); + ConvertTo(value2, fAllowNull); + value = value2; } else { @@ -3100,8 +3106,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 1) ConvertTo(params[1]); if (strMethod == "createrawtransaction" && n > 0) ConvertTo(params[0]); if (strMethod == "createrawtransaction" && n > 1) ConvertTo(params[1]); - if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1]); - if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2]); + if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); + if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); return params; } -- cgit v1.2.3