function to create a cryptocondition from a Univalue
This commit is contained in:
@@ -996,7 +996,7 @@ unset PKG_CONFIG_LIBDIR
|
|||||||
PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
|
PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
|
||||||
|
|
||||||
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no"
|
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
|
AC_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -375,6 +375,14 @@ UniValue verifytxoutproofcc(const UniValue& params, bool fHelp)
|
|||||||
return res;
|
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)
|
UniValue createrawtransactioncc(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 2)
|
if (fHelp || params.size() != 2)
|
||||||
@@ -409,7 +417,7 @@ UniValue createrawtransactioncc(const UniValue& params, bool fHelp)
|
|||||||
);
|
);
|
||||||
|
|
||||||
LOCK(cs_main);
|
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 inputs = params[0].get_array();
|
||||||
UniValue outputs = params[1].get_array();
|
UniValue outputs = params[1].get_array();
|
||||||
@@ -429,6 +437,9 @@ UniValue createrawtransactioncc(const UniValue& params, bool fHelp)
|
|||||||
if (nOutput < 0)
|
if (nOutput < 0)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
|
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));
|
CTxIn in(COutPoint(txid, nOutput));
|
||||||
rawTx.vin.push_back(in);
|
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++) {
|
for (size_t idx = 0; idx < outputs.size(); idx++) {
|
||||||
const UniValue& output = outputs[idx].get_obj();
|
const UniValue& output = outputs[idx].get_obj();
|
||||||
|
|
||||||
const UniValue& condition = find_value(output, "condition");
|
CC *cond = ConditionFromValue(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);
|
|
||||||
char *condBin = new char[1000];
|
char *condBin = new char[1000];
|
||||||
size_t binLength = cc_conditionBinary(cond, condBin);
|
size_t binLength = cc_conditionBinary(cond, condBin);
|
||||||
std::vector<char> condVec(condBin, condBin + binLength);
|
std::vector<char> condVec(condBin, condBin + binLength);
|
||||||
|
|||||||
Reference in New Issue
Block a user