return json to dicestatus
This commit is contained in:
@@ -25,7 +25,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 &error);
|
||||
std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout);
|
||||
double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid);
|
||||
double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error);
|
||||
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);
|
||||
|
||||
@@ -950,37 +950,31 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
|
||||
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 )
|
||||
{
|
||||
CCerror = "bet must be positive";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = "bet must be positive";
|
||||
return("");
|
||||
}
|
||||
if ( odds < 1 || odds > 9999 )
|
||||
{
|
||||
CCerror = "odds must be between 1 and 9999";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = "odds must be between 1 and 9999";
|
||||
return("");
|
||||
}
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
return("");
|
||||
if ( bet < minbet || bet > maxbet || odds > maxodds )
|
||||
{
|
||||
CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds);
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds);
|
||||
return("");
|
||||
}
|
||||
int32_t entropytxs;
|
||||
if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 )
|
||||
{
|
||||
if ( entropytxs < 2 ) {
|
||||
CCerror = "Your dealer is broke, find a new casino.";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = CCerror;
|
||||
error = "Your dealer is broke, find a new casino.";
|
||||
return("");
|
||||
}
|
||||
if ( myIsutxo_spentinmempool(entropytxid,0) != 0 )
|
||||
{
|
||||
CCerror = "entropy txid is spent";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = "entropy txid is spent";
|
||||
return("");
|
||||
}
|
||||
mtx.vin.push_back(CTxIn(entropytxid,0,CScript()));
|
||||
@@ -991,13 +985,12 @@ 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(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid)));
|
||||
} else CCerror = "cant find enough normal inputs for %.8f, plan funding %.8f\n";
|
||||
} else error = "cant find enough normal inputs for %.8f, plan funding %.8f\n";
|
||||
}
|
||||
if ( entropyval == 0 && funding != 0 )
|
||||
CCerror = "cant find dice entropy inputs";
|
||||
error = "cant find dice entropy inputs";
|
||||
else
|
||||
CCerror = "cant find dice input";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = "cant find dice input";
|
||||
return("");
|
||||
}
|
||||
|
||||
@@ -1116,13 +1109,12 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256
|
||||
return("");
|
||||
}
|
||||
|
||||
double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid)
|
||||
double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error)
|
||||
{
|
||||
CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res;
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
{
|
||||
CCerror = "Diceinit error in status";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
error = "Diceinit error in status";
|
||||
return(0.);
|
||||
}
|
||||
fundingpk = DiceFundingPk(fundingPubKey);
|
||||
@@ -1173,8 +1165,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
|
||||
return(0.);
|
||||
else return((double)spenttx.vout[2].nValue/COIN);
|
||||
}
|
||||
CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid);
|
||||
fprintf(stderr,"%s\n", CCerror.c_str());
|
||||
error = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid);
|
||||
return(-1.);
|
||||
}
|
||||
else if ( scriptPubKey == fundingPubKey )
|
||||
@@ -1194,8 +1185,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
|
||||
else return((double)spenttx.vout[2].nValue/COIN);
|
||||
} else return(0.);
|
||||
}
|
||||
CCerror = "didnt find dicefinish tx";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str());
|
||||
error = "didnt find dicefinish tx";
|
||||
}
|
||||
return(-1.);
|
||||
}
|
||||
|
||||
@@ -6196,7 +6196,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue dicestatus(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status; double winnings;
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status,error; double winnings;
|
||||
if ( fHelp || (params.size() != 2 && params.size() != 3) )
|
||||
throw runtime_error("dicestatus name fundingtxid bettxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -6212,10 +6212,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp)
|
||||
memset(&bettxid,0,sizeof(bettxid));
|
||||
if ( params.size() == 3 )
|
||||
bettxid = Parseuint256((char *)params[2].get_str().c_str());
|
||||
winnings = DiceStatus(0,name,fundingtxid,bettxid);
|
||||
if (CCerror != "") {
|
||||
ERR_RESULT(CCerror);
|
||||
return result;
|
||||
winnings = DiceStatus(0,name,fundingtxid,bettxid,error);
|
||||
if ( error[0] != 0 ) {
|
||||
ERR_RESULT(error);
|
||||
return(result);
|
||||
}
|
||||
result.push_back(Pair("result", "success"));
|
||||
if ( winnings >= 0. )
|
||||
|
||||
Reference in New Issue
Block a user