Skip to content

Commit

Permalink
[zPIV] rebase problems fixed. (Needs more testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed May 23, 2019
1 parent e7dada8 commit f930016
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
33 changes: 17 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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__);
}
}
Expand All @@ -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");
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -242,9 +252,6 @@ std::list<COutPoint> 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())
Expand Down
11 changes: 1 addition & 10 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/zpiv/zpivmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ class PublicCoinSpend : public libzerocoin::CoinSpend{
this->coinSerialNumber = serial;
this->randomness = randomness;
this->pubkey = pubkey;
this->spendType = libzerocoin::SpendType::SPEND;
};

template <typename Stream>
PublicCoinSpend(
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<unsigned char> 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;

Expand Down

0 comments on commit f930016

Please sign in to comment.