diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 33f187391..8ecd7addd 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); -std::string DiceWinLoseTimeout(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceWinLoseTimeout(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 68ef87362..8e4b2ba73 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -127,10 +127,10 @@ void *dicefinish(void *_ptr) fprintf(stderr,"duplicate.%d dicefinish.%d %s funding.%s bid.%s\n",duplicate,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); if ( duplicate == 0 ) { - res = DiceWinLoseTimeout(0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) + CTransaction tx; uint256 txid; char str[65]; int32_t result; + res = DiceWinLoseTimeout(&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result != 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { - CTransaction tx; uint256 txid; char str[65]; LOCK(cs_main); if ( DecodeHexTx(tx,res) != 0 ) { @@ -771,9 +771,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(0); } -std::string DiceWinLoseTimeout(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceWinLoseTimeout(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk; struct CCcontract_info *cp,C; int64_t inputs,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid; int32_t iswin; uint64_t entropyval,sbits; + *resultp = 0; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(0); if ( winlosetimeout != 0 ) @@ -832,6 +833,7 @@ std::string DiceWinLoseTimeout(uint64_t txfee,char *planstr,uint256 fundingtxid, mtx.vout.push_back(CTxOut(txfee,entropyTx.vout[1].scriptPubKey)); } hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + *resultp = 1; return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); } else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout); } else return(0); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa16727b7..9b7b31ff2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5199,7 +5199,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicewinner(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; int32_t result; if ( fHelp || params.size() != 3 ) throw runtime_error("dicewinner name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -5209,7 +5209,7 @@ UniValue dicewinner(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceWinLoseTimeout(0,name,fundingtxid,bettxid,1); + hex = DiceWinLoseTimeout(&result,0,name,fundingtxid,bettxid,1); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5220,7 +5220,7 @@ UniValue dicewinner(const UniValue& params, bool fHelp) UniValue diceloser(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; int32_t result; if ( fHelp || params.size() != 3 ) throw runtime_error("diceloser name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -5230,7 +5230,7 @@ UniValue diceloser(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceWinLoseTimeout(0,name,fundingtxid,bettxid,-1); + hex = DiceWinLoseTimeout(&result,0,name,fundingtxid,bettxid,-1); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5241,7 +5241,7 @@ UniValue diceloser(const UniValue& params, bool fHelp) UniValue dicetimeout(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; int32_t result; if ( fHelp || params.size() != 3 ) throw runtime_error("dicetimeout name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -5251,7 +5251,7 @@ UniValue dicetimeout(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceWinLoseTimeout(0,name,fundingtxid,bettxid,0); + hex = DiceWinLoseTimeout(&result,0,name,fundingtxid,bettxid,0); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success"));