This commit is contained in:
jl777
2018-07-31 05:36:16 -11:00
parent 260c79c3cc
commit cfdc377065
3 changed files with 13 additions and 11 deletions

View File

@@ -24,7 +24,7 @@
bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); 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 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 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); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount);
UniValue DiceInfo(uint256 diceid); UniValue DiceInfo(uint256 diceid);

View File

@@ -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)); 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 ) if ( duplicate == 0 )
{ {
res = DiceWinLoseTimeout(0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); CTransaction tx; uint256 txid; char str[65]; int32_t result;
if ( res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) 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); LOCK(cs_main);
if ( DecodeHexTx(tx,res) != 0 ) if ( DecodeHexTx(tx,res) != 0 )
{ {
@@ -771,9 +771,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
return(0); 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; 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 ) if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
return(0); return(0);
if ( winlosetimeout != 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)); mtx.vout.push_back(CTxOut(txfee,entropyTx.vout[1].scriptPubKey));
} }
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash);
*resultp = 1;
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); 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 fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout);
} else return(0); } else return(0);

View File

@@ -5199,7 +5199,7 @@ UniValue dicebet(const UniValue& params, bool fHelp)
UniValue dicewinner(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 ) if ( fHelp || params.size() != 3 )
throw runtime_error("dicewinner name fundingtxid bettxid\n"); throw runtime_error("dicewinner name fundingtxid bettxid\n");
if ( ensure_CCrequirements() < 0 ) if ( ensure_CCrequirements() < 0 )
@@ -5209,7 +5209,7 @@ UniValue dicewinner(const UniValue& params, bool fHelp)
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].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 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); 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 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 ) if ( fHelp || params.size() != 3 )
throw runtime_error("diceloser name fundingtxid bettxid\n"); throw runtime_error("diceloser name fundingtxid bettxid\n");
if ( ensure_CCrequirements() < 0 ) if ( ensure_CCrequirements() < 0 )
@@ -5230,7 +5230,7 @@ UniValue diceloser(const UniValue& params, bool fHelp)
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].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 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); 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 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 ) if ( fHelp || params.size() != 3 )
throw runtime_error("dicetimeout name fundingtxid bettxid\n"); throw runtime_error("dicetimeout name fundingtxid bettxid\n");
if ( ensure_CCrequirements() < 0 ) if ( ensure_CCrequirements() < 0 )
@@ -5251,7 +5251,7 @@ UniValue dicetimeout(const UniValue& params, bool fHelp)
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].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 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));