diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index e00b5a0a0..477487390 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -281,6 +281,7 @@ int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode) sprintf(&cp->CChexstr[i*2],"%02x",pub33[i]); cp->CChexstr[i*2] = 0; GetCCaddress(cp,cp->unspendableCCaddr,pk); + return(0); } } return(-1); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2d4ba25d7..c6370d762 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5347,25 +5347,39 @@ UniValue cclibaddress(const UniValue& params, bool fHelp) UniValue cclibinfo(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_FIRSTUSER); + struct CCcontract_info *cp,C; uint8_t evalcode = EVAL_FIRSTUSER; if ( fHelp || params.size() > 0 ) throw runtime_error("cclibinfo\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + if ( params.size() >= 1 ) + { + evalcode = atoi(params[0].get_str().c_str()); + if ( evalcode < EVAL_FIRSTUSER || evalcode > EVAL_LASTUSER ) + throw runtime_error("evalcode not between EVAL_FIRSTUSER and EVAL_LASTUSER\n"); + } + cp = CCinit(&C,evalcode); return(CClib_info(cp)); } UniValue cclib(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; char *method; cJSON *jsonparams; + struct CCcontract_info *cp,C; char *method; cJSON *jsonparams=0; uint8_t evalcode; cp = CCinit(&C,EVAL_FIRSTUSER); - if ( fHelp || params.size() > 2 ) - throw runtime_error("cclib method [JSON params]\n"); + if ( fHelp || params.size() > 3 ) + throw runtime_error("cclib method [evalcode] [JSON params]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); method = (char *)params[0].get_str().c_str(); - jsonparams = cJSON_Parse(params[1].get_str().c_str()); + if ( params.size() >= 1 ) + { + evalcode = atoi(params[1].get_str().c_str()); + if ( evalcode < EVAL_FIRSTUSER || evalcode > EVAL_LASTUSER ) + throw runtime_error("evalcode not between EVAL_FIRSTUSER and EVAL_LASTUSER\n"); + if ( params.size() == 2 ) + jsonparams = cJSON_Parse(params[2].get_str().c_str()); + } + cp = CCinit(&C,evalcode); return(CClib(cp,method,jsonparams)); }