From 2356884c5fbe12dc8f23af43a1345101b1f780ae Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 22 Oct 2017 23:27:44 -0700 Subject: [PATCH] function to create a cryptocondition from a Univalue --- configure.ac | 2 +- src/rpccryptoconditions.cpp | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index c471bab89..9f8f1900f 100644 --- a/configure.ac +++ b/configure.ac @@ -996,7 +996,7 @@ unset PKG_CONFIG_LIBDIR PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP" ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no" -AC_CONFIG_SUBDIRS([src/secp256k1 src/univalue]) +AC_CONFIG_SUBDIRS([src/secp256k1 src/univalue src/cryptoconditions]) AC_OUTPUT diff --git a/src/rpccryptoconditions.cpp b/src/rpccryptoconditions.cpp index 946667aae..e297ed4e4 100644 --- a/src/rpccryptoconditions.cpp +++ b/src/rpccryptoconditions.cpp @@ -375,6 +375,14 @@ UniValue verifytxoutproofcc(const UniValue& params, bool fHelp) return res; } +CC *ConditionFromValue(const UniValue& condition) { + std::string encoded = condition.write(); + char *err = new char[1000]; + CC *cond = cc_conditionFromJSONString(encoded.c_str(), err); + if (NULL == cond) + throw JSONRPCError(RPC_INVALID_PARAMETER, err); +} + UniValue createrawtransactioncc(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 2) @@ -409,7 +417,7 @@ UniValue createrawtransactioncc(const UniValue& params, bool fHelp) ); LOCK(cs_main); - RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VARR)); + //RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VARR)); UniValue inputs = params[0].get_array(); UniValue outputs = params[1].get_array(); @@ -429,6 +437,9 @@ UniValue createrawtransactioncc(const UniValue& params, bool fHelp) if (nOutput < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); + CC *cond = ConditionFromValue(find_value(output, "condition")); + char *ffillBin = new char[1024*1024]; + CTxIn in(COutPoint(txid, nOutput)); rawTx.vin.push_back(in); } @@ -436,13 +447,7 @@ UniValue createrawtransactioncc(const UniValue& params, bool fHelp) for (size_t idx = 0; idx < outputs.size(); idx++) { const UniValue& output = outputs[idx].get_obj(); - const UniValue& condition = find_value(output, "condition"); - std::string encoded = condition.write(); - fprintf(stderr, "%s\n", encoded.c_str()); - char *err = new char[1000]; - CC *cond = cc_conditionFromJSONString(encoded.c_str(), err); - if (NULL == cond) - throw JSONRPCError(RPC_INVALID_PARAMETER, err); + CC *cond = ConditionFromValue(find_value(output, "condition")); char *condBin = new char[1000]; size_t binLength = cc_conditionBinary(cond, condBin); std::vector condVec(condBin, condBin + binLength);