Update CWallet::UpdatedNoteData() for Sapling.

This commit is contained in:
Simon 2018-07-28 10:04:54 -07:00
parent dae1c4204a
commit 3a83e7c9a4
1 changed files with 31 additions and 13 deletions

View File

@ -1310,21 +1310,39 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx) bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
{ {
if (wtxIn.mapSproutNoteData.empty() || wtxIn.mapSproutNoteData == wtx.mapSproutNoteData) { bool unchangedSproutFlag = (wtxIn.mapSproutNoteData.empty() || wtxIn.mapSproutNoteData == wtx.mapSproutNoteData);
return false; if (!unchangedSproutFlag) {
} auto tmp = wtxIn.mapSproutNoteData;
auto tmp = wtxIn.mapSproutNoteData; // Ensure we keep any cached witnesses we may already have
// Ensure we keep any cached witnesses we may already have for (const std::pair <JSOutPoint, SproutNoteData> nd : wtx.mapSproutNoteData) {
for (const std::pair<JSOutPoint, SproutNoteData> nd : wtx.mapSproutNoteData) { if (tmp.count(nd.first) && nd.second.witnesses.size() > 0) {
if (tmp.count(nd.first) && nd.second.witnesses.size() > 0) { tmp.at(nd.first).witnesses.assign(
tmp.at(nd.first).witnesses.assign( nd.second.witnesses.cbegin(), nd.second.witnesses.cend());
nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); }
tmp.at(nd.first).witnessHeight = nd.second.witnessHeight;
} }
tmp.at(nd.first).witnessHeight = nd.second.witnessHeight; // Now copy over the updated note data
wtx.mapSproutNoteData = tmp;
} }
// Now copy over the updated note data
wtx.mapSproutNoteData = tmp; bool unchangedSaplingFlag = (wtxIn.mapSaplingNoteData.empty() || wtxIn.mapSaplingNoteData == wtx.mapSaplingNoteData);
return true; if (!unchangedSaplingFlag) {
auto tmp = wtxIn.mapSaplingNoteData;
// Ensure we keep any cached witnesses we may already have
for (const std::pair <SaplingOutPoint, SaplingNoteData> nd : wtx.mapSaplingNoteData) {
if (tmp.count(nd.first) && nd.second.witnesses.size() > 0) {
tmp.at(nd.first).witnesses.assign(
nd.second.witnesses.cbegin(), nd.second.witnesses.cend());
}
tmp.at(nd.first).witnessHeight = nd.second.witnessHeight;
}
// Now copy over the updated note data
wtx.mapSaplingNoteData = tmp;
}
return !unchangedSproutFlag || !unchangedSaplingFlag;
} }
/** /**