diff --git a/src/main.cpp b/src/main.cpp index 3a2f933a72193..acfac7b0566e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1085,7 +1085,7 @@ bool CheckZerocoinSpend(const CTransaction& tx, bool fVerifySignature, CValidati for (const CTxIn& txin : tx.vin) { //only check txin that is a zcspend - bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txin.IsZerocoinPublicSpend(); if (!txin.IsZerocoinSpend() && !isPublicSpend) continue; @@ -1221,7 +1221,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject //require that a zerocoinspend only has inputs that are zerocoins if (tx.HasZerocoinSpendInputs()) { for (const CTxIn& in : tx.vin) { - if (!in.IsZerocoinSpend() && !in.scriptSig.IsZerocoinPublicSpend()) + if (!in.IsZerocoinSpend() && !in.IsZerocoinPublicSpend()) return state.DoS(100, error("CheckTransaction() : zerocoinspend contains inputs that are not zerocoins")); } @@ -1394,7 +1394,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa //Check for double spending of serial #'s for (const CTxIn& txIn : tx.vin) { // Only allow for zc spends inputs - bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txIn.IsZerocoinPublicSpend(); if (!txIn.IsZerocoinSpend() && !isPublicSpend) { return state.Invalid(error("%s: ContextualCheckZerocoinSpend failed for tx %s, every input must be a zcspend or zcpublicspend", __func__, tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv"); @@ -2447,7 +2447,7 @@ void AddInvalidSpendsToMap(const CBlock& block) //Check all zerocoinspends for bad serials for (const CTxIn& in : tx.vin) { - bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = in.IsZerocoinPublicSpend(); if (in.IsZerocoinSpend() || isPublicSpend) { CoinSpend* spend; @@ -2654,7 +2654,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex if (tx.HasZerocoinSpendInputs()) { //erase all zerocoinspends in this transaction for (const CTxIn &txin : tx.vin) { - bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txin.IsZerocoinPublicSpend(); if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) { CBigNum serial; if (isPublicSpend) { @@ -3223,7 +3223,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //Check for double spending of serial #'s set setSerials; for (const CTxIn& txIn : tx.vin) { - bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txIn.IsZerocoinPublicSpend(); bool isPrivZerocoinSpend = txIn.IsZerocoinSpend(); if (!isPrivZerocoinSpend && !isPublicSpend) continue; @@ -4427,7 +4427,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo // double check that there are no double spent zPIV spends in this block if (tx.HasZerocoinSpendInputs()) { for (const CTxIn& txIn : tx.vin) { - bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txIn.IsZerocoinPublicSpend(); if (txIn.IsZerocoinSpend() || isPublicSpend) { libzerocoin::CoinSpend spend; if (isPublicSpend) { @@ -4785,7 +4785,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, for (const CTransaction& tx : block.vtx) { for (const CTxIn& in: tx.vin) { if(nHeight >= Params().Zerocoin_StartHeight()) { - bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = in.IsZerocoinPublicSpend(); bool isPrivZerocoinSpend = in.IsZerocoinSpend(); if (isPrivZerocoinSpend || isPublicSpend) { diff --git a/src/miner.cpp b/src/miner.cpp index f24e40b13e44c..bbd86a9f31ac3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -371,7 +371,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, bool fDoubleSerial = false; for (const CTxIn& txIn : tx.vin) { - bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txIn.IsZerocoinPublicSpend(); if (txIn.IsZerocoinSpend() || isPublicSpend) { libzerocoin::CoinSpend* spend; if (isPublicSpend) { diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 44826e5abebab..710e1b6a8a18b 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -64,6 +64,11 @@ bool CTxIn::IsZerocoinSpend() const return prevout.hash == 0 && scriptSig.IsZerocoinSpend(); } +bool CTxIn::IsZerocoinPublicSpend() const +{ + return scriptSig.IsZerocoinPublicSpend(); +} + std::string CTxIn::ToString() const { std::string str; @@ -166,7 +171,7 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) { bool CTransaction::HasZerocoinSpendInputs() const { for (const CTxIn& txin: vin) { - if (txin.IsZerocoinSpend() || txin.scriptSig.IsZerocoinPublicSpend()) + if (txin.IsZerocoinSpend() || txin.IsZerocoinPublicSpend()) return true; } return false; @@ -181,11 +186,11 @@ bool CTransaction::HasZerocoinMintOutputs() const return false; } -bool CTransaction::IsZerocoinPublicSpend() const +bool CTransaction::HasZerocoinPublicSpendInputs() const { // The wallet only allows publicSpend inputs in the same tx and not a combination between piv and zpiv for(const CTxIn& txin : vin) { - if (txin.scriptSig.IsZerocoinPublicSpend()) + if (txin.IsZerocoinPublicSpend()) return true; } return false; @@ -254,7 +259,7 @@ CAmount CTransaction::GetZerocoinSpent() const { CAmount nValueOut = 0; for (const CTxIn& txin : vin) { - if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend()) + if(!txin.IsZerocoinSpend()) continue; nValueOut += txin.nSequence * COIN; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 32448a8ba0f59..12a13f18e459c 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -96,6 +96,7 @@ class CTxIn } bool IsZerocoinSpend() const; + bool IsZerocoinPublicSpend() const; friend bool operator==(const CTxIn& a, const CTxIn& b) { @@ -260,16 +261,15 @@ class CTransaction unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const; bool HasZerocoinSpendInputs() const; + bool HasZerocoinPublicSpendInputs() const; bool HasZerocoinMintOutputs() const; bool ContainsZerocoins() const { - return HasZerocoinSpendInputs() || HasZerocoinMintOutputs(); + return HasZerocoinSpendInputs() || HasZerocoinPublicSpendInputs() || HasZerocoinMintOutputs(); } - bool IsZerocoinPublicSpend() const; - CAmount GetZerocoinMinted() const; CAmount GetZerocoinSpent() const; int GetZerocoinMintCount() const; diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 6c61874f358e7..71d66a421e86a 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -46,7 +46,7 @@ QList TransactionRecord::decomposeTransaction(const CWallet* if (wtx.HasZerocoinSpendInputs()) { // a zerocoin spend that was created by this wallet - if (wtx.IsZerocoinPublicSpend()) { + if (wtx.HasZerocoinPublicSpendInputs()) { libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false); PublicCoinSpend publicSpend(params); CValidationState state; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 83d9f6ba3f2df..e6290f2a291af 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1051,7 +1051,7 @@ UniValue getfeeinfo(const UniValue& params, bool fHelp) continue; for (unsigned int j = 0; j < tx.vin.size(); j++) { - if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].scriptSig.IsZerocoinPublicSpend()) { + if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].IsZerocoinPublicSpend()) { nValueIn += tx.vin[j].nSequence * COIN; continue; } diff --git a/src/script/script.cpp b/src/script/script.cpp index f32dfd95ffffd..d314b43917908 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -266,10 +266,7 @@ bool CScript::IsZerocoinSpend() const bool CScript::IsZerocoinPublicSpend() const { - if (this->empty()) - return false; - - return (this->at(0) == OP_ZEROCOINPUBLICSPEND); + return StartsWithOpcode(OP_ZEROCOINPUBLICSPEND); } bool CScript::IsPushOnly(const_iterator pc) const diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a8c6f630a811e..76b4335764a19 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -565,11 +565,11 @@ void CTxMemPool::check(const CCoinsViewCache* pcoins) const fDependsWait = true; } else { const CCoins* coins = pcoins->AccessCoins(txin.prevout.hash); - if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend()) + if(!txin.IsZerocoinSpend() && !txin.IsZerocoinPublicSpend()) assert(coins && coins->IsAvailable(txin.prevout.n)); } // Check whether its inputs are marked in mapNextTx. - if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend()) { + if(!txin.IsZerocoinSpend() && !txin.IsZerocoinPublicSpend()) { std::map::const_iterator it3 = mapNextTx.find(txin.prevout); assert(it3 != mapNextTx.end()); assert(it3->second.ptx == &tx); diff --git a/src/zpiv/zpivmodule.cpp b/src/zpiv/zpivmodule.cpp index c1883237dd996..8134497e45293 100644 --- a/src/zpiv/zpivmodule.cpp +++ b/src/zpiv/zpivmodule.cpp @@ -75,7 +75,7 @@ namespace ZPIVModule { } bool parseCoinSpend(const CTxIn &in, const CTransaction &tx, const CTxOut &prevOut, PublicCoinSpend &publicCoinSpend) { - if (!in.scriptSig.IsZerocoinPublicSpend() || !prevOut.scriptPubKey.IsZerocoinMint()) + if (!in.IsZerocoinPublicSpend() || !prevOut.IsZerocoinMint()) return error("%s: invalid argument/s\n", __func__); std::vector > data; @@ -123,4 +123,4 @@ namespace ZPIVModule { } return true; } -} \ No newline at end of file +} diff --git a/src/zpivchain.cpp b/src/zpivchain.cpp index 18a6ff3116943..a1b38dbc342a4 100644 --- a/src/zpivchain.cpp +++ b/src/zpivchain.cpp @@ -286,7 +286,7 @@ std::string ReindexZerocoinDB() //Record Serials if (tx.HasZerocoinSpendInputs()) { for (auto& in : tx.vin) { - bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = in.IsZerocoinPublicSpend(); if (!in.IsZerocoinSpend() && !isPublicSpend) continue; if (isPublicSpend) { @@ -387,7 +387,7 @@ std::list ZerocoinSpendListFromBlock(const CBlock continue; for (const CTxIn& txin : tx.vin) { - bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend(); + bool isPublicSpend = txin.IsZerocoinPublicSpend(); if (!txin.IsZerocoinSpend() && !isPublicSpend) continue;