return json to dicestatus
This commit is contained in:
@@ -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.);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user