From c6c490af1d8e466fdc26ba7405149b7dfc0533a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Jul 2018 09:33:23 -1100 Subject: [PATCH] Fix duplicate vin --- src/cc/CCassetstx.cpp | 12 +++++++++--- src/cc/CCtx.cpp | 11 +++++++++-- src/cc/CCutils.cpp | 1 - src/cc/auction.cpp | 1 + src/cc/dice.cpp | 1 + src/cc/faucet.cpp | 1 + src/cc/lotto.cpp | 1 + src/cc/ponzi.cpp | 1 + src/cc/rewards.cpp | 1 + 9 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index f70080ec2..b4185bfae 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,19 +17,25 @@ uint64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,uint64_t total,int32_t maxinputs) { - char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + vout = (int32_t)it->first.index; + for (j=0; jfirst.index,assetid)) > 0 ) + if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 ) { if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript())); + mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = it->second.satoshis; totalinputs += nValue; n++; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index b37e6f061..3f871de74 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -165,7 +165,7 @@ void SetCCunspents(std::vector vecOutputs; + int32_t vout,j,n = 0; uint64_t nValue,totalinputs = 0; uint256 txid; std::vector vecOutputs; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); @@ -175,7 +175,14 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in { if ( out.fSpendable != 0 ) { - mtx.vin.push_back(CTxIn(out.tx->GetHash(),out.i,CScript())); + txid = out.tx->GetHash(); + vout = out.i; + for (j=0; jvout[out.i].nValue; totalinputs += nValue; n++; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index f8617e536..d9672c61d 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -257,5 +257,4 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param } -uint64_t AddFaucetInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs); diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index a11f66e85..1be6a50aa 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -126,6 +126,7 @@ uint64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + // prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsAuctionvout(cp,vintx,(int32_t)it->first.index)) > 0 ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f76fc02ab..a551fed1c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -126,6 +126,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + // prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsDicevout(cp,vintx,(int32_t)it->first.index)) > 0 ) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 00b01d76f..b9071e621 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -133,6 +133,7 @@ uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + // prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsFaucetvout(cp,vintx,(int32_t)it->first.index)) > 0 ) diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index af6222b5d..ee8db7c39 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -126,6 +126,7 @@ uint64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + // prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsLottovout(cp,vintx,(int32_t)it->first.index)) > 0 ) diff --git a/src/cc/ponzi.cpp b/src/cc/ponzi.cpp index 81021209e..19e00bc2b 100644 --- a/src/cc/ponzi.cpp +++ b/src/cc/ponzi.cpp @@ -126,6 +126,7 @@ uint64_t AddPonziInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + // prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsPonzivout(cp,vintx,(int32_t)it->first.index)) > 0 ) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 65ad8b6f0..17c838c51 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -176,6 +176,7 @@ uint64_t AddRewardsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; + // prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsRewardsvout(cp,vintx,(int32_t)it->first.index)) > 0 )