Skip to content

Commit d22a456

Browse files
presstabFuzzbawls
authored andcommitted
Make zpiv unarchiving work with zpivtracker.
1 parent 6fdc6f4 commit d22a456

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

src/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,7 +4967,7 @@ void CWallet::ReconsiderZerocoins(std::list<CZerocoinMint>& listMintsRestored, s
49674967
mint.SetHeight(nHeight);
49684968
mint.SetUsed(IsSerialInBlockchain(mint.GetValue(), nHeight));
49694969

4970-
if (!zpivTracker->UnArchive(hashPubcoin)) {
4970+
if (!zpivTracker->UnArchive(hashPubcoin, false)) {
49714971
LogPrintf("%s : failed to unarchive mint %s\n", __func__, mint.GetValue().GetHex());
49724972
} else {
49734973
zpivTracker->UpdateZerocoinMint(mint);
@@ -4985,7 +4985,7 @@ void CWallet::ReconsiderZerocoins(std::list<CZerocoinMint>& listMintsRestored, s
49854985
dMint.SetHeight(nHeight);
49864986
dMint.SetUsed(IsSerialInBlockchain(dMint.GetSerialHash(), nHeight));
49874987

4988-
if (!zpivTracker->UnArchive(dMint.GetPubcoinHash())) {
4988+
if (!zpivTracker->UnArchive(dMint.GetPubcoinHash(), true)) {
49894989
LogPrintf("%s : failed to unarchive deterministic mint %s\n", __func__, dMint.GetPubcoinHash().GetHex());
49904990
} else {
49914991
zpivTracker->Add(dMint, true);

src/walletdb.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,9 +1128,8 @@ bool CWalletDB::ArchiveDeterministicOrphan(const CDeterministicMint& dMint)
11281128
return true;
11291129
}
11301130

1131-
bool CWalletDB::UnarchiveDeterministicMint(const uint256& hashPubcoin)
1131+
bool CWalletDB::UnarchiveDeterministicMint(const uint256& hashPubcoin, CDeterministicMint& dMint)
11321132
{
1133-
CDeterministicMint dMint;
11341133
if (!Read(make_pair(string("dzco"), hashPubcoin), dMint))
11351134
return error("%s: failed to retrieve deterministic mint from archive", __func__);
11361135

@@ -1143,9 +1142,8 @@ bool CWalletDB::UnarchiveDeterministicMint(const uint256& hashPubcoin)
11431142
return true;
11441143
}
11451144

1146-
bool CWalletDB::UnarchiveZerocoinMint(const uint256& hashPubcoin)
1145+
bool CWalletDB::UnarchiveZerocoinMint(const uint256& hashPubcoin, CZerocoinMint& mint)
11471146
{
1148-
CZerocoinMint mint;
11491147
if (!Read(make_pair(string("zco"), hashPubcoin), mint))
11501148
return error("%s: failed to retrieve zerocoinmint from archive", __func__);
11511149

src/walletdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class CWalletDB : public CDB
162162
bool ReadZerocoinMint(const uint256& hashPubcoin, CZerocoinMint& mint);
163163
bool ArchiveMintOrphan(const CZerocoinMint& zerocoinMint);
164164
bool ArchiveDeterministicOrphan(const CDeterministicMint& dMint);
165-
bool UnarchiveZerocoinMint(const uint256& hashPubcoin);
166-
bool UnarchiveDeterministicMint(const uint256& hashPubcoin);
165+
bool UnarchiveZerocoinMint(const uint256& hashPubcoin, CZerocoinMint& mint);
166+
bool UnarchiveDeterministicMint(const uint256& hashPubcoin, CDeterministicMint& dMint);
167167
std::list<CZerocoinMint> ListMintedCoins();
168168
std::list<CDeterministicMint> ListDeterministicMints();
169169
std::list<CZerocoinSpend> ListSpentCoins();

src/zpivtracker.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,22 @@ bool CzPIVTracker::Archive(CMintMeta& meta)
4343
return true;
4444
}
4545

46-
bool CzPIVTracker::UnArchive(const uint256& hashPubcoin)
46+
bool CzPIVTracker::UnArchive(const uint256& hashPubcoin, bool isDeterministic)
4747
{
48-
if (!HasPubcoinHash(hashPubcoin))
49-
return error("%s: tracker does not have record of pubcoinhash %s", __func__, hashPubcoin.GetHex());
50-
51-
CMintMeta meta = GetMetaFromPubcoin(hashPubcoin);
5248
CWalletDB walletdb(strWalletFile);
53-
if (meta.isDeterministic) {
54-
if (!walletdb.UnarchiveDeterministicMint(hashPubcoin))
55-
return error("%s: failed to unarchive", __func__);
49+
if (isDeterministic) {
50+
CDeterministicMint dMint;
51+
if (!walletdb.UnarchiveDeterministicMint(hashPubcoin, dMint))
52+
return error("%s: failed to unarchive deterministic mint", __func__);
53+
Add(dMint, false);
5654
} else {
57-
if (!walletdb.UnarchiveZerocoinMint(hashPubcoin))
58-
return error("%s: failed to unarchive", __func__);
55+
CZerocoinMint mint;
56+
if (!walletdb.UnarchiveZerocoinMint(hashPubcoin, mint))
57+
return error("%s: failed to unarchivezerocoin mint", __func__);
58+
Add(mint, false);
5959
}
6060

61-
mapSerialHashes.at(meta.hashSerial).isArchived = false;
62-
LogPrintf("%s: unarchived %s\n", __func__, meta.hashPubcoin.GetHex());
61+
LogPrintf("%s: unarchived %s\n", __func__, hashPubcoin.GetHex());
6362
return true;
6463
}
6564

src/zpivtracker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CzPIVTracker
3535
void RemovePending(const uint256& txid);
3636
void SetPubcoinUsed(const uint256& hashPubcoin, const uint256& txid);
3737
void SetPubcoinNotUsed(const uint256& hashPubcoin);
38-
bool UnArchive(const uint256& hashPubcoin);
38+
bool UnArchive(const uint256& hashPubcoin, bool isDeterministic);
3939
bool UpdateZerocoinMint(const CZerocoinMint& mint);
4040
bool UpdateState(const CMintMeta& meta);
4141
void Clear();

0 commit comments

Comments
 (0)