diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 22ca71c66..51668eda8 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -305,6 +305,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + fprintf(stderr,"asset swaps disabled\n"); + return(0); if ( askamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); @@ -429,6 +431,12 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits); return(0); } + if ( assetid2 != zeroid ) + { + fprintf(stderr,"asset swaps disabled\n"); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index f10027c97..0ab0bf874 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -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 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); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index fff113d30..240e5b7e0 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -275,9 +275,10 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector 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); } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 2088d9b73..8adecb3e4 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -250,9 +250,9 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } fprintf(stderr,"fillbuy validated\n"); break; - - case 's': // selloffer case 'e': // selloffer + break; // disable swaps + case 's': // selloffer //vin.0: normal input //vin.1+: valid CC output for sale //vout.0: vin.1 assetoshis output to CC to unspendable @@ -323,6 +323,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"fill validated\n"); break; case 'E': // fillexchange + break; // disable asset swaps //vin.0: normal input //vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0] //vin.2+: valid CC assetid2 output that satisfies exchange (*tx.vin[2])->nValue diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 68c3e6cc7..02eb99a58 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -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) @@ -909,8 +911,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( scriptPubKey != fundingPubKey ) { - fprintf(stderr,"only dice fund creator can submit winner or loser\n"); - return("0"); + //fprintf(stderr,"only dice fund creator can submit winner or loser\n"); + winlosetimeout = 0; } } if ( AddNormalinputs(mtx,mypk,txfee,1) == 0 ) @@ -923,7 +925,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - winlosetimeout = iswin; + if ( winlosetimeout != 0 ) + winlosetimeout = iswin; if ( iswin == winlosetimeout ) { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -939,7 +942,6 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 funcid = 'T'; if ( DiceVerifyTimeout(betTx,timeoutblocks) == 0 ) // hasnt timed out yet { - fprintf(stderr,"timeout is not supported yet\n"); return("0"); } else diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index c2f6dcd27..a0f07aba1 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -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); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 06fdc433b..41228e71a 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -393,10 +393,10 @@ static const CRPCCommand vRPCCommands[] = { "tokens", "tokencancelbid", &tokencancelbid, true }, { "tokens", "tokenfillbid", &tokenfillbid, true }, { "tokens", "tokenask", &tokenask, true }, - { "tokens", "tokenswapask", &tokenswapask, true }, + //{ "tokens", "tokenswapask", &tokenswapask, true }, { "tokens", "tokencancelask", &tokencancelask, true }, { "tokens", "tokenfillask", &tokenfillask, true }, - { "tokens", "tokenfillswap", &tokenfillswap, true }, + //{ "tokens", "tokenfillswap", &tokenfillswap, true }, /* Address index */ { "addressindex", "getaddressmempool", &getaddressmempool, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 4b5dcdc2c..f88f1e571 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -221,8 +221,8 @@ extern UniValue tokenfillbid(const UniValue& params, bool fHelp); extern UniValue tokenask(const UniValue& params, bool fHelp); extern UniValue tokencancelask(const UniValue& params, bool fHelp); extern UniValue tokenfillask(const UniValue& params, bool fHelp); -extern UniValue tokenswapask(const UniValue& params, bool fHelp); -extern UniValue tokenfillswap(const UniValue& params, bool fHelp); +//extern UniValue tokenswapask(const UniValue& params, bool fHelp); +//extern UniValue tokenfillswap(const UniValue& params, bool fHelp); extern UniValue faucetfund(const UniValue& params, bool fHelp); extern UniValue faucetget(const UniValue& params, bool fHelp); extern UniValue faucetaddress(const UniValue& params, bool fHelp);