Skip to content

Commit

Permalink
[zPIV] zPIV Maturity --> Minimum amount of coins accumulated no neede…
Browse files Browse the repository at this point in the history
…d anymore.
  • Loading branch information
furszy committed May 23, 2019
1 parent 0e8d0f9 commit c8d519e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,20 +1660,25 @@ CAmount CWallet::GetBalance() const
return nTotal;
}

std::map<libzerocoin::CoinDenomination, int> mapMintMaturity;
int nLastMaturityCheck = 0;
//std::map<libzerocoin::CoinDenomination, int> mapMintMaturity;
//int nLastMaturityCheck = 0;

CAmount CWallet::GetZerocoinBalance(bool fMatureOnly) const
{
if (fMatureOnly) {
if (chainActive.Height() > nLastMaturityCheck)
mapMintMaturity = GetMintMaturityHeight();
nLastMaturityCheck = chainActive.Height();
// This code is not removed just for when we back to use zPIV in the future, for now it's useless,
// every public coin spend is now spendable without need to have new mints on top.

//if (chainActive.Height() > nLastMaturityCheck)
// mapMintMaturity = GetMintMaturityHeight();
//nLastMaturityCheck = chainActive.Height();

CAmount nBalance = 0;
vector<CMintMeta> vMints = zpivTracker->GetMints(true);
for (auto meta : vMints) {
if (meta.nHeight >= mapMintMaturity.at(meta.denom) || meta.nHeight >= chainActive.Height() || meta.nHeight == 0)
continue;
// Every public coin spend is now spendable, no need to mint new coins on top.
//if (meta.nHeight >= mapMintMaturity.at(meta.denom) || meta.nHeight >= chainActive.Height() || meta.nHeight == 0)
// continue;
nBalance += libzerocoin::ZerocoinDenominationToAmount(meta.denom);
}
return nBalance;
Expand Down Expand Up @@ -4922,7 +4927,8 @@ bool CWallet::CreateZerocoinSpendTransaction(CAmount nValue, CWalletTx& wtxNew,
const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction
vector<CMintMeta> vMintsToFetch;
if (vSelectedMints.empty()) {
setMints = zpivTracker->ListMints(true, true, true); // need to find mints to spend
// 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
if(setMints.empty()) {
receipt.SetStatus(_("Failed to find Zerocoins in wallet.dat"), nStatus);
return false;
Expand Down

0 comments on commit c8d519e

Please sign in to comment.