Skip to content

Commit

Permalink
[Wallet] Sapling GetSaplingNoteWitnesses back ported.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Oct 22, 2020
1 parent e537feb commit 8931916
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/sapling/saplingscriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,33 @@ bool SaplingScriptPubKeyMan::IsSaplingNullifierFromMe(const uint256& nullifier)
wallet->mapWallet.count(mapSaplingNullifiersToNotes.at(nullifier).hash);
}

void SaplingScriptPubKeyMan::GetSaplingNoteWitnesses(const std::vector<SaplingOutPoint>& notes,
std::vector<Optional<SaplingWitness>>& witnesses,
uint256& final_anchor)
{
LOCK(wallet->cs_wallet);
witnesses.resize(notes.size());
Optional<uint256> rt;
int i = 0;
for (SaplingOutPoint note : notes) {
if (wallet->mapWallet.count(note.hash) &&
wallet->mapWallet[note.hash].mapSaplingNoteData.count(note) &&
wallet->mapWallet[note.hash].mapSaplingNoteData[note].witnesses.size() > 0) {
witnesses[i] = wallet->mapWallet[note.hash].mapSaplingNoteData[note].witnesses.front();
if (!rt) {
rt = witnesses[i]->root();
} else {
assert(*rt == witnesses[i]->root());
}
}
i++;
}
// All returned witnesses have the same anchor
if (rt) {
final_anchor = *rt;
}
}

bool SaplingScriptPubKeyMan::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
{
bool unchangedSaplingFlag = (wtxIn.mapSaplingNoteData.empty() || wtxIn.mapSaplingNoteData == wtx.mapSaplingNoteData);
Expand Down
6 changes: 6 additions & 0 deletions src/sapling/saplingscriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ class SaplingScriptPubKeyMan {
//! Whether the nullifier is from this wallet
bool IsSaplingNullifierFromMe(const uint256& nullifier) const;

//! Return all of the witnesses for the input notes
void GetSaplingNoteWitnesses(
const std::vector<SaplingOutPoint>& notes,
std::vector<Optional<SaplingWitness>>& witnesses,
uint256& final_anchor);

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

Expand Down

0 comments on commit 8931916

Please sign in to comment.