Skip to content

Commit

Permalink
[Wallet] Sapling UpdatedNoteData() implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Oct 14, 2020
1 parent 7045acf commit 2c4bab7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sapling/saplingscriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ void SaplingScriptPubKeyMan::DecrementNoteWitnesses(const CBlockIndex* pindex)
// of the wallet.dat is maintained).
}

bool SaplingScriptPubKeyMan::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
{
bool unchangedSaplingFlag = (wtxIn.mapSaplingNoteData.empty() || wtxIn.mapSaplingNoteData == wtx.mapSaplingNoteData);
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 !unchangedSaplingFlag;
}

void SaplingScriptPubKeyMan::ClearNoteWitnessCache()
{
LOCK(wallet->cs_wallet);
Expand Down
3 changes: 3 additions & 0 deletions src/sapling/saplingscriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class SaplingScriptPubKeyMan {
//! Return the spending key for the payment address (nullopt if the wallet has no spending key for such address)
Optional<libzcash::SaplingExtendedSpendingKey> GetSpendingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &addr) const;

//! Update note data if is needed
bool UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx);

//! Clear every the notesData from every wallet tx and reset the witness cache size
void ClearNoteWitnessCache();

Expand Down
3 changes: 3 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
wtx.nIndex = wtxIn.nIndex;
fUpdated = true;
}
if (HasSaplingSPKM() && m_sspk_man->UpdatedNoteData(wtxIn, wtx)) {
fUpdated = true;
}
if (wtxIn.fFromMe && wtxIn.fFromMe != wtx.fFromMe) {
wtx.fFromMe = wtxIn.fFromMe;
fUpdated = true;
Expand Down

0 comments on commit 2c4bab7

Please sign in to comment.