Skip to content

Commit

Permalink
[zPIV] prevent v1 zerocoins from being selected for PublicSpends
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra authored and furszy committed May 23, 2019
1 parent 4439869 commit e0decb1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4903,7 +4903,6 @@ bool CWallet::MintsToInputVectorPublicSpend(std::map<CBigNum, CZerocoinMint>& ma

bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew, CReserveKey& reserveKey, CZerocoinSpendReceipt& receipt, vector<CZerocoinMint>& vSelectedMints, vector<CDeterministicMint>& vNewMints, bool fMintChange, bool fMinimizeChange, CBitcoinAddress* address)
{

// Check available funds
int nStatus = ZPIV_TRX_FUNDS_PROBLEMS;
if (nValue > GetZerocoinBalance(true)) {
Expand All @@ -4929,7 +4928,7 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew,
vector<CMintMeta> vMintsToFetch;
if (vSelectedMints.empty()) {
// All of the zPIV used in the public coin spend are mature by default (everything is public now.. no need to wait for any accumulation)
setMints = zpivTracker->ListMints(true, false, true); // need to find mints to spend
setMints = zpivTracker->ListMints(true, false, true, true); // need to find mints to spend
if(setMints.empty()) {
receipt.SetStatus(_("Failed to find Zerocoins in wallet.dat"), nStatus);
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/zpiv/zpivtracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ bool CzPIVTracker::UpdateStatusInternal(const std::set<uint256>& setMempool, CMi
return false;
}

std::set<CMintMeta> CzPIVTracker::ListMints(bool fUnusedOnly, bool fMatureOnly, bool fUpdateStatus, bool fWrongSeed)
std::set<CMintMeta> CzPIVTracker::ListMints(bool fUnusedOnly, bool fMatureOnly, bool fUpdateStatus, bool fWrongSeed, bool fExcludeV1)
{
CWalletDB walletdb(strWalletFile);
if (fUpdateStatus) {
Expand All @@ -473,6 +473,8 @@ std::set<CMintMeta> CzPIVTracker::ListMints(bool fUnusedOnly, bool fMatureOnly,

CzPIVWallet* zPIVWallet = new CzPIVWallet(strWalletFile);
for (auto& dMint : listDeterministicDB) {
if (fExcludeV1 && dMint.GetVersion() < 2)
continue;
Add(dMint, false, false, zPIVWallet);
}
delete zPIVWallet;
Expand Down
2 changes: 1 addition & 1 deletion src/zpiv/zpivtracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CzPIVTracker
bool ClearSpendCache() EXCLUSIVE_LOCKS_REQUIRED(cs_spendcache);
std::vector<CMintMeta> GetMints(bool fConfirmedOnly) const;
CAmount GetUnconfirmedBalance() const;
std::set<CMintMeta> ListMints(bool fUnusedOnly, bool fMatureOnly, bool fUpdateStatus, bool fWrongSeed = false);
std::set<CMintMeta> ListMints(bool fUnusedOnly, bool fMatureOnly, bool fUpdateStatus, bool fWrongSeed = false, bool fExcludeV1 = false);
void RemovePending(const uint256& txid);
void SetPubcoinUsed(const uint256& hashPubcoin, const uint256& txid);
void SetPubcoinNotUsed(const uint256& hashPubcoin);
Expand Down

0 comments on commit e0decb1

Please sign in to comment.