Remove unspent note entry structs

This commit is contained in:
Eirik Ogilvie-Wigley 2018-10-09 09:48:32 -06:00
parent c2bb0ec67f
commit 9396b85db8
3 changed files with 18 additions and 33 deletions

View File

@ -2566,17 +2566,17 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
UniValue results(UniValue::VARR); UniValue results(UniValue::VARR);
if (zaddrs.size() > 0) { if (zaddrs.size() > 0) {
std::vector<CUnspentSproutNotePlaintextEntry> sproutEntries; std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<UnspentSaplingNoteEntry> saplingEntries; std::vector<SaplingNoteEntry> saplingEntries;
pwalletMain->GetUnspentFilteredNotes(sproutEntries, saplingEntries, zaddrs, nMinDepth, nMaxDepth, !fIncludeWatchonly); pwalletMain->GetUnspentFilteredNotes(sproutEntries, saplingEntries, zaddrs, nMinDepth, nMaxDepth, !fIncludeWatchonly);
std::set<std::pair<PaymentAddress, uint256>> nullifierSet = pwalletMain->GetNullifiersForAddresses(zaddrs); std::set<std::pair<PaymentAddress, uint256>> nullifierSet = pwalletMain->GetNullifiersForAddresses(zaddrs);
for (CUnspentSproutNotePlaintextEntry & entry : sproutEntries) { for (auto & entry : sproutEntries) {
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("txid", entry.jsop.hash.ToString()));
obj.push_back(Pair("jsindex", (int)entry.jsop.js )); obj.push_back(Pair("jsindex", (int)entry.jsop.js ));
obj.push_back(Pair("jsoutindex", (int)entry.jsop.n)); obj.push_back(Pair("jsoutindex", (int)entry.jsop.n));
obj.push_back(Pair("confirmations", entry.nHeight)); obj.push_back(Pair("confirmations", entry.confirmations));
bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get<libzcash::SproutPaymentAddress>(entry.address)); bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get<libzcash::SproutPaymentAddress>(entry.address));
obj.push_back(Pair("spendable", hasSproutSpendingKey)); obj.push_back(Pair("spendable", hasSproutSpendingKey));
obj.push_back(Pair("address", EncodePaymentAddress(entry.address))); obj.push_back(Pair("address", EncodePaymentAddress(entry.address)));
@ -2589,11 +2589,11 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
results.push_back(obj); results.push_back(obj);
} }
for (UnspentSaplingNoteEntry & entry : saplingEntries) { for (auto & entry : saplingEntries) {
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("txid", entry.op.hash.ToString()));
obj.push_back(Pair("outindex", (int)entry.op.n)); obj.push_back(Pair("outindex", (int)entry.op.n));
obj.push_back(Pair("confirmations", entry.nHeight)); obj.push_back(Pair("confirmations", entry.confirmations));
libzcash::SaplingIncomingViewingKey ivk; libzcash::SaplingIncomingViewingKey ivk;
libzcash::SaplingFullViewingKey fvk; libzcash::SaplingFullViewingKey fvk;
pwalletMain->GetSaplingIncomingViewingKey(boost::get<libzcash::SaplingPaymentAddress>(entry.address), ivk); pwalletMain->GetSaplingIncomingViewingKey(boost::get<libzcash::SaplingPaymentAddress>(entry.address), ivk);

View File

@ -4440,7 +4440,7 @@ void CWallet::GetFilteredNotes(
hSig, hSig,
(unsigned char) j); (unsigned char) j);
sproutEntries.push_back(CSproutNotePlaintextEntry{jsop, pa, plaintext}); sproutEntries.push_back(CSproutNotePlaintextEntry{jsop, pa, plaintext, wtx.GetDepthInMainChain()});
} catch (const note_decryption_failed &err) { } catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key // Couldn't decrypt with this spending key
@ -4495,7 +4495,7 @@ void CWallet::GetFilteredNotes(
auto note = notePt.note(nd.ivk).get(); auto note = notePt.note(nd.ivk).get();
saplingEntries.push_back(SaplingNoteEntry { saplingEntries.push_back(SaplingNoteEntry {
op, pa, note, notePt.memo() }); op, pa, note, notePt.memo(), wtx.GetDepthInMainChain() });
} }
} }
} }
@ -4503,8 +4503,8 @@ void CWallet::GetFilteredNotes(
/* Find unspent notes filtered by payment address, min depth and max depth */ /* Find unspent notes filtered by payment address, min depth and max depth */
void CWallet::GetUnspentFilteredNotes( void CWallet::GetUnspentFilteredNotes(
std::vector<CUnspentSproutNotePlaintextEntry>& sproutEntries, std::vector<CSproutNotePlaintextEntry>& sproutEntries,
std::vector<UnspentSaplingNoteEntry>& saplingEntries, std::vector<SaplingNoteEntry>& saplingEntries,
std::set<PaymentAddress>& filterAddresses, std::set<PaymentAddress>& filterAddresses,
int minDepth, int minDepth,
int maxDepth, int maxDepth,
@ -4560,7 +4560,7 @@ void CWallet::GetUnspentFilteredNotes(
hSig, hSig,
(unsigned char) j); (unsigned char) j);
sproutEntries.push_back(CUnspentSproutNotePlaintextEntry{jsop, pa, plaintext, wtx.GetDepthInMainChain()}); sproutEntries.push_back(CSproutNotePlaintextEntry{jsop, pa, plaintext, wtx.GetDepthInMainChain()});
} catch (const note_decryption_failed &err) { } catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key // Couldn't decrypt with this spending key
@ -4609,7 +4609,7 @@ void CWallet::GetUnspentFilteredNotes(
} }
auto note = notePt.note(nd.ivk).get(); auto note = notePt.note(nd.ivk).get();
saplingEntries.push_back(UnspentSaplingNoteEntry { saplingEntries.push_back(SaplingNoteEntry {
op, pa, note, notePt.memo(), wtx.GetDepthInMainChain() }); op, pa, note, notePt.memo(), wtx.GetDepthInMainChain() });
} }
} }

View File

@ -309,38 +309,23 @@ public:
typedef std::map<JSOutPoint, SproutNoteData> mapSproutNoteData_t; typedef std::map<JSOutPoint, SproutNoteData> mapSproutNoteData_t;
typedef std::map<SaplingOutPoint, SaplingNoteData> mapSaplingNoteData_t; typedef std::map<SaplingOutPoint, SaplingNoteData> mapSaplingNoteData_t;
/** Decrypted note and its location in a transaction. */ /** Decrypted note, its location in a transaction, and number of confirmations. */
struct CSproutNotePlaintextEntry struct CSproutNotePlaintextEntry
{ {
JSOutPoint jsop; JSOutPoint jsop;
libzcash::SproutPaymentAddress address; libzcash::SproutPaymentAddress address;
libzcash::SproutNotePlaintext plaintext; libzcash::SproutNotePlaintext plaintext;
int confirmations;
}; };
/** Decrypted note, location in a transaction, and confirmation height. */ /** Sapling note, its location in a transaction, and number of confirmations. */
struct CUnspentSproutNotePlaintextEntry {
JSOutPoint jsop;
libzcash::SproutPaymentAddress address;
libzcash::SproutNotePlaintext plaintext;
int nHeight;
};
/** Sapling note and its location in a transaction. */
struct SaplingNoteEntry struct SaplingNoteEntry
{ {
SaplingOutPoint op; SaplingOutPoint op;
libzcash::SaplingPaymentAddress address; libzcash::SaplingPaymentAddress address;
libzcash::SaplingNote note; libzcash::SaplingNote note;
std::array<unsigned char, ZC_MEMO_SIZE> memo; std::array<unsigned char, ZC_MEMO_SIZE> memo;
}; int confirmations;
/** Sapling note, location in a transaction, and confirmation height. */
struct UnspentSaplingNoteEntry {
SaplingOutPoint op;
libzcash::SaplingPaymentAddress address;
libzcash::SaplingNote note;
std::array<unsigned char, ZC_MEMO_SIZE> memo;
int nHeight;
}; };
/** A transaction with a merkle branch linking it to the block chain. */ /** A transaction with a merkle branch linking it to the block chain. */
@ -1305,8 +1290,8 @@ public:
bool ignoreUnspendable=true); bool ignoreUnspendable=true);
/* Find unspent notes filtered by payment address, min depth and max depth */ /* Find unspent notes filtered by payment address, min depth and max depth */
void GetUnspentFilteredNotes(std::vector<CUnspentSproutNotePlaintextEntry>& sproutEntries, void GetUnspentFilteredNotes(std::vector<CSproutNotePlaintextEntry>& sproutEntries,
std::vector<UnspentSaplingNoteEntry>& saplingEntries, std::vector<SaplingNoteEntry>& saplingEntries,
std::set<libzcash::PaymentAddress>& filterAddresses, std::set<libzcash::PaymentAddress>& filterAddresses,
int minDepth=1, int minDepth=1,
int maxDepth=INT_MAX, int maxDepth=INT_MAX,