Implement dice timeout
This commit is contained in:
@@ -79,7 +79,7 @@ bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t n
|
||||
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
|
||||
std::vector<uint8_t> Mypubkey();
|
||||
bool Myprivkey(uint8_t myprivkey[]);
|
||||
int64_t CCduration(uint256 txid);
|
||||
int64_t CCduration(int32_t &numblocks,uint256 txid);
|
||||
|
||||
// CCtx
|
||||
std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret);
|
||||
|
||||
@@ -275,9 +275,10 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> param
|
||||
return(false);
|
||||
}
|
||||
|
||||
int64_t CCduration(uint256 txid)
|
||||
int64_t CCduration(int32_t &numblocks,uint256 txid)
|
||||
{
|
||||
CTransaction tx; uint256 hashBlock; uint32_t txtime=0; char str[65]; CBlockIndex *pindex; int64_t duration = 0;
|
||||
CTransaction tx; uint256 hashBlock; uint32_t txheight,txtime=0; char str[65]; CBlockIndex *pindex; int64_t duration = 0;
|
||||
numblocks = 0;
|
||||
if ( myGetTransaction(txid,tx,hashBlock) == 0 )
|
||||
{
|
||||
fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid));
|
||||
@@ -288,18 +289,19 @@ int64_t CCduration(uint256 txid)
|
||||
fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid));
|
||||
return(0);
|
||||
}
|
||||
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 )
|
||||
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->nHeight) <= 0 )
|
||||
{
|
||||
fprintf(stderr,"CCduration no txtime %u %p for txid %s\n",txtime,pindex,uint256_str(str,txid));
|
||||
fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid));
|
||||
return(0);
|
||||
}
|
||||
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime )
|
||||
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight )
|
||||
{
|
||||
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid));
|
||||
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight);
|
||||
return(0);
|
||||
}
|
||||
numblocks = (pindex->nHeight - txheight);
|
||||
duration = (pindex->nTime - txtime);
|
||||
fprintf(stderr,"duration %d (%u - %u)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime);
|
||||
fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight);
|
||||
return(duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -392,8 +392,10 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction
|
||||
|
||||
bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks)
|
||||
{
|
||||
fprintf(stderr,"DiceVerifyTimeout needs to be implemented\n");
|
||||
return(false);
|
||||
int32_t numblocks;
|
||||
if ( CCduration(numblocks,betTx.GetHash()) <= 0 )
|
||||
return(false);
|
||||
return(numblocks >= timeoutblocks);
|
||||
}
|
||||
|
||||
bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx)
|
||||
|
||||
@@ -68,9 +68,9 @@
|
||||
|
||||
uint64_t RewardsCalc(uint64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit)
|
||||
{
|
||||
uint64_t duration,reward = 0;
|
||||
int32_t numblocks; uint64_t duration,reward = 0;
|
||||
fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds);
|
||||
if ( (duration= CCduration(txid)) < minseconds )
|
||||
if ( (duration= CCduration(numblocks,txid)) < minseconds )
|
||||
{
|
||||
fprintf(stderr,"duration %llu < minseconds %llu\n",(long long)duration,(long long)minseconds);
|
||||
return(0);
|
||||
|
||||
Reference in New Issue
Block a user