From f93001663b999259dfbce2035e131caa7348850f Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 14 May 2019 15:50:45 +0200 Subject: [PATCH] [zPIV] rebase problems fixed. (Needs more testing) --- src/main.cpp | 33 +++++++++++++++++---------------- src/primitives/transaction.cpp | 13 ++++++++++--- src/primitives/transaction.h | 11 +---------- src/zpiv/zpivmodule.h | 3 ++- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 578ab462a99f9..6079ea3001437 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2636,17 +2636,17 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex * addresses should still be handled by the typical bitcoin based undo code * */ if (tx.ContainsZerocoins()) { - if (tx.IsZerocoinSpend()) { + if (tx.HasZerocoinSpendInputs()) { //erase all zerocoinspends in this transaction - for (const CTxIn& txin : tx.vin) { + for (const CTxIn &txin : tx.vin) { bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend(); if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) { CBigNum serial; if (isPublicSpend) { - libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false); + libzerocoin::ZerocoinParams *params = Params().Zerocoin_Params(false); PublicCoinSpend publicSpend(params); CValidationState state; - if (!ZPIVModule::ParseZerocoinPublicSpend(txin, tx, state, publicSpend)){ + if (!ZPIVModule::ParseZerocoinPublicSpend(txin, tx, state, publicSpend)) { return error("Failed to parse public spend"); } serial = publicSpend.getCoinSerialNumber(); @@ -2660,8 +2660,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex //if this was our spend, then mark it unspent now if (pwalletMain) { - if (pwalletMain->IsMyZerocoinSpend(spend.getCoinSerialNumber())) { - if (!pwalletMain->SetMintUnspent(spend.getCoinSerialNumber())) + if (pwalletMain->IsMyZerocoinSpend(serial)) { + if (!pwalletMain->SetMintUnspent(serial)) LogPrintf("%s: failed to automatically reset mint", __func__); } } @@ -2670,18 +2670,19 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } } - if (tx.HasZerocoinMintOutputs()) { - //erase all zerocoinmints in this transaction - for (const CTxOut& txout : tx.vout) { - if (txout.scriptPubKey.empty() || !txout.IsZerocoinMint()) - continue; + if (tx.HasZerocoinMintOutputs()) { + //erase all zerocoinmints in this transaction + for (const CTxOut &txout : tx.vout) { + if (txout.scriptPubKey.empty() || !txout.IsZerocoinMint()) + continue; - PublicCoin pubCoin(Params().Zerocoin_Params(false)); - if (!TxOutToPublicCoin(txout, pubCoin, state)) - return error("DisconnectBlock(): TxOutToPublicCoin() failed"); + PublicCoin pubCoin(Params().Zerocoin_Params(false)); + if (!TxOutToPublicCoin(txout, pubCoin, state)) + return error("DisconnectBlock(): TxOutToPublicCoin() failed"); - if(!zerocoinDB->EraseCoinMint(pubCoin.getValue())) - return error("DisconnectBlock(): Failed to erase coin mint"); + if (!zerocoinDB->EraseCoinMint(pubCoin.getValue())) + return error("DisconnectBlock(): Failed to erase coin mint"); + } } } diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 3d477319c2dad..44826e5abebab 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -181,6 +181,16 @@ bool CTransaction::HasZerocoinMintOutputs() const return false; } +bool CTransaction::IsZerocoinPublicSpend() 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()) + return true; + } + return false; +} + bool CTransaction::IsCoinStake() const { if (vin.empty()) @@ -242,9 +252,6 @@ std::list CTransaction::GetOutPoints() const CAmount CTransaction::GetZerocoinSpent() const { - if(!IsZerocoinSpend() && !IsZerocoinPublicSpend()) - return 0; - CAmount nValueOut = 0; for (const CTxIn& txin : vin) { if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend()) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 528fab5e9b9ee..32448a8ba0f59 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -268,16 +268,7 @@ class CTransaction return HasZerocoinSpendInputs() || HasZerocoinMintOutputs(); } - // TODO: Move this to the cpp and add it to the HasZerocoinSpendinputs method - bool IsZerocoinPublicSpend() 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()) - return true; - } - return false; - } + bool IsZerocoinPublicSpend() const; CAmount GetZerocoinMinted() const; CAmount GetZerocoinSpent() const; diff --git a/src/zpiv/zpivmodule.h b/src/zpiv/zpivmodule.h index 3e2a5a6795ae3..b2d82bf8b750c 100644 --- a/src/zpiv/zpivmodule.h +++ b/src/zpiv/zpivmodule.h @@ -29,6 +29,7 @@ class PublicCoinSpend : public libzerocoin::CoinSpend{ this->coinSerialNumber = serial; this->randomness = randomness; this->pubkey = pubkey; + this->spendType = libzerocoin::SpendType::SPEND; }; template @@ -36,13 +37,13 @@ class PublicCoinSpend : public libzerocoin::CoinSpend{ libzerocoin::ZerocoinParams* params, Stream& strm):pubCoin(params){ strm >> *this; + this->spendType = libzerocoin::SpendType::SPEND; } uint8_t getVersion() const { return libzerocoin::PrivateCoin::PUBKEY_VERSION; } const uint256 signatureHash() const override; void setVchSig(std::vector vchSig) { this->vchSig = vchSig; }; - libzerocoin::SpendType getSpendType() const { return libzerocoin::SpendType::SPEND; } bool Verify(const libzerocoin::Accumulator& a, bool verifyParams = true) const override; bool validate() const;