Skip to content

Commit

Permalink
[Refactoring] Mimic ListCoins for sapling notes
Browse files Browse the repository at this point in the history
Create CWallet::ListNotes and use it in WalletModel::listAvailableNotes
  • Loading branch information
random-zebra committed Jun 2, 2021
1 parent 54fa122 commit e7cafab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/qt/walletmodel.cpp
Expand Up @@ -1044,19 +1044,16 @@ void WalletModel::listCoins(std::map<ListCoinsKey, std::vector<ListCoinsValue>>&

void WalletModel::listAvailableNotes(std::map<ListCoinsKey, std::vector<ListCoinsValue>>& mapCoins) const
{
std::vector<SaplingNoteEntry> notes;
Optional<libzcash::SaplingPaymentAddress> dummy = nullopt;
wallet->GetSaplingScriptPubKeyMan()->GetFilteredNotes(notes, dummy);
for (const auto& note : notes) {
ListCoinsKey key{QString::fromStdString(KeyIO::EncodePaymentAddress(note.address)), false, nullopt};
ListCoinsValue value{
note.op.hash,
(int)note.op.n,
(CAmount)note.note.value(),
0,
note.confirmations
};
mapCoins[key].emplace_back(value);
for (const auto& it: wallet->ListNotes()) {
const ListCoinsKey key{QString::fromStdString(KeyIO::EncodePaymentAddress(it.first)), false, nullopt};

for (const SaplingNoteEntry& note : it.second) {
mapCoins[key].emplace_back(note.op.hash,
(int)note.op.n,
(CAmount)note.note.value(),
0,
note.confirmations);
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/sapling/saplingscriptpubkeyman.cpp
Expand Up @@ -511,6 +511,20 @@ void SaplingScriptPubKeyMan::GetFilteredNotes(
}
}

/* Return list of available notes grouped by sapling address. */
std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> SaplingScriptPubKeyMan::ListNotes() const
{
std::vector<SaplingNoteEntry> notes;
Optional<libzcash::SaplingPaymentAddress> dummy = nullopt;
GetFilteredNotes(notes, dummy);

std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> result;
for (const auto& note : notes) {
result[note.address].emplace_back(std::move(note));
}
return result;
}

Optional<libzcash::SaplingPaymentAddress>
SaplingScriptPubKeyMan::GetAddressFromInputIfPossible(const uint256& txHash, int index) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/sapling/saplingscriptpubkeyman.h
Expand Up @@ -297,6 +297,8 @@ class SaplingScriptPubKeyMan {
bool requireSpendingKey=true,
bool ignoreLocked=true) const;

/* Return list of available notes grouped by sapling address. */
std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> ListNotes() const;

//! Return the address from where the shielded spend is taking the funds from (if possible)
Optional<libzcash::SaplingPaymentAddress> GetAddressFromInputIfPossible(const CWalletTx* wtx, int index) const;
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/wallet.cpp
Expand Up @@ -2999,6 +2999,11 @@ std::map<std::pair<CTxDestination, Optional<CTxDestination>>, std::vector<COutpu
return result;
}

std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> CWallet::ListNotes() const
{
return m_sspk_man->ListNotes();
}

bool CWallet::CreateBudgetFeeTX(CTransactionRef& tx, const uint256& hash, CReserveKey& keyChange, bool fFinalization)
{
CScript scriptChange;
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/wallet.h
Expand Up @@ -98,6 +98,7 @@ class CScheduler;
class ScriptPubKeyMan;
class SaplingScriptPubKeyMan;
class SaplingNoteData;
struct SaplingNoteEntry;
class CDeterministicMNList;

/** (client) version numbers for particular wallet features */
Expand Down Expand Up @@ -816,6 +817,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
* is reserved for the staker address in case of P2CS.
*/
std::map<std::pair<CTxDestination, Optional<CTxDestination>>, std::vector<COutput>> ListCoins() const;
/**
* Return list of available shield notes grouped by sapling address.
*/
std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> ListNotes() const;

/// Get 10000 PIV output and keys which can be used for the Masternode
bool GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet,
Expand Down

0 comments on commit e7cafab

Please sign in to comment.