This commit is contained in:
blackjok3r
2018-10-28 13:30:02 +08:00
parent 877360794b
commit b30cf0e25e
2 changed files with 10 additions and 7 deletions

View File

@@ -945,7 +945,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6
return(""); return("");
} }
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, char *error)
{ {
CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C;
if ( bet < 0 ) if ( bet < 0 )
@@ -974,6 +974,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
if ( entropytxs < 2 ) { if ( entropytxs < 2 ) {
CCerror = "Your dealer is broke, find a new casino."; CCerror = "Your dealer is broke, find a new casino.";
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
error = CCerror.c_str();
return(""); return("");
} }
if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) if ( myIsutxo_spentinmempool(entropytxid,0) != 0 )
@@ -990,7 +991,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk));
mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid)));
} else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN); } else CCerror = "cant find enough normal inputs for %.8f, plan funding %.8f\n";
} }
if ( entropyval == 0 && funding != 0 ) if ( entropyval == 0 && funding != 0 )
CCerror = "cant find dice entropy inputs"; CCerror = "cant find dice entropy inputs";

View File

@@ -6135,7 +6135,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp)
UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicebet(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name; UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name, *error;
if ( fHelp || params.size() != 4 ) if ( fHelp || params.size() != 4 )
throw runtime_error("dicebet name fundingtxid amount odds\n"); throw runtime_error("dicebet name fundingtxid amount odds\n");
if ( ensure_CCrequirements() < 0 ) if ( ensure_CCrequirements() < 0 )
@@ -6157,7 +6157,9 @@ UniValue dicebet(const UniValue& params, bool fHelp)
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex)); result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt create dice bet transaction. make sure your address has funds"); } else if ( error[0] != 0 ) {
ERR_RESULT(error);
}
} else { } else {
ERR_RESULT("amount and odds must be positive"); ERR_RESULT("amount and odds must be positive");
} }