From 079be98a2ed5e6e761f237b362662804019f049b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 2 Aug 2018 01:10:04 -1100 Subject: [PATCH] myIsutxo_spentinmempool --- src/cc/CCinclude.h | 3 ++- src/cc/CCtx.cpp | 2 +- src/cc/dice.cpp | 15 ++++----------- src/main.cpp | 4 ++-- src/rpcblockchain.cpp | 20 ++++++++++++++++++++ 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 43e10ab22..312d44a06 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -53,7 +53,8 @@ static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx); -uint64_t myGettxout(uint256 hash,int32_t n); +//uint64_t myGettxout(uint256 hash,int32_t n); +bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index dbb477817..66a5d4388 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -220,7 +220,7 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in break; if ( j != mtx.vin.size() ) continue; - if ( myGettxout(txid,vout) == out.tx->vout[out.i].nValue ) + if ( myIsutxo_spentinmempool(txid,vout) == 0 ) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = out.tx->vout[out.i].nValue; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bf0bb24b7..220916535 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -119,13 +119,6 @@ void *dicefinish(void *_ptr) if ( duplicate == 0 ) { CTransaction tx,bettx; uint256 txid,hashBlock; char str[65]; int32_t result; - for (i=0; i<10; i++) - { - if ( myGettxout(ptr->bettxid,0) != 0 ) // need to wait for mempool to be updated - break; - fprintf(stderr,"."); - sleep(3); - } res = DiceWinLoseTimeout(&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result != 0 && res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { @@ -582,7 +575,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK break; if ( j != mtx.vin.size() ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myGettxout(txid,vout) != 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { @@ -616,7 +609,7 @@ uint64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbi { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myGettxout(txid,vout) > 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { //char str[65],str2[65]; if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) @@ -871,7 +864,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid)) >= 2*bet*odds+txfee && entropyval != 0 ) { - if ( myGettxout(entropytxid,0) == 0 ) + if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { fprintf(stderr,"entropy txid is spent\n"); return(0); @@ -923,7 +916,7 @@ std::string DiceWinLoseTimeout(int32_t *resultp,uint64_t txfee,char *planstr,uin { if ( iswin == winlosetimeout ) { - if ( myGettxout(bettxid,0) == 0 || myGettxout(bettxid,1) == 0 ) + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"bettxid already spent\n"); return(0); diff --git a/src/main.cpp b/src/main.cpp index 274d86c07..b42f85ce7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1603,7 +1603,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, return true; } -uint64_t myGettxout(uint256 hash,int32_t n) +/*uint64_t myGettxout(uint256 hash,int32_t n) { CCoins coins; LOCK2(cs_main,mempool.cs); @@ -1613,7 +1613,7 @@ uint64_t myGettxout(uint256 hash,int32_t n) if ( n < 0 || (unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull() ) return(0); else return(coins.vout[n].nValue); -} +}*/ bool myAddtomempool(CTransaction &tx) { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 2e5ed0be8..bedb84383 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -346,6 +346,26 @@ UniValue getdifficulty(const UniValue& params, bool fHelp) return GetNetworkDifficulty(); } +bool myIsutxo_spentinmempool(uint256 txid,int32_t vout) +{ + char *uint256_str(char *str,uint256); + char str[65]; + LOCK(mempool.cs); + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); + BOOST_FOREACH(const CTxIn &txin,tx.vin) + { + fprintf(stderr,"%s/v%d ",uint256_str(str,txin.prevout.hash),txin.prevout.n); + if ( txin.prevout.n == vout && txin.prevout.hash == txid ) + return(true); + } + fprintf(stderr,"are vins for %s\n",uint256_str(str,hash)); + } + return(false); +} + UniValue mempoolToJSON(bool fVerbose = false) { if (fVerbose)