Merge pull request #5629 from nuttycom/feature/wallet_orchard-minconf_filter

Respect minDepth argument for Orchard notes in GetFilteredNotes
This commit is contained in:
str4d 2022-03-04 03:18:52 +00:00 committed by GitHub
commit 414e74f70a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -176,6 +176,10 @@ class WalletAccountsTest(BitcoinTestFramework):
self.check_balance(0, 0, ua0, {'sapling': 9})
self.check_balance(0, 0, ua0, {'sapling': 9, 'orchard': 10}, 0)
# The total balance with the default minconf should be just the Sapling balance
assert_equal('9.00', self.nodes[0].z_gettotalbalance()['private'])
assert_equal('19.00', self.nodes[0].z_gettotalbalance(0)['private'])
self.nodes[2].generate(1)
self.sync_all()

View File

@ -3410,6 +3410,9 @@ CAmount getBalanceZaddr(std::optional<libzcash::PaymentAddress> address, int min
for (auto & entry : saplingEntries) {
balance += CAmount(entry.note.value());
}
for (auto & entry : orchardEntries) {
balance += entry.GetNoteValue();
}
return balance;
}
@ -4407,7 +4410,7 @@ size_t EstimateTxSize(
[&](const libzcash::OrchardRawAddress& addr) {
if (fromSprout) {
throw JSONRPCError(
RPC_INVALID_PARAMETER,
RPC_INVALID_PARAMETER,
"Sending funds from a Sprout address to a Unified Address is not supported by z_sendmany");
}
orchardRecipientCount += 1;
@ -4419,7 +4422,7 @@ size_t EstimateTxSize(
if (fromSprout || !nu5Active) {
mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID;
mtx.nVersion = SAPLING_TX_VERSION;
mtx.nVersion = SAPLING_TX_VERSION;
} else {
mtx.nVersionGroupId = ZIP225_VERSION_GROUP_ID;
mtx.nVersion = ZIP225_TX_VERSION;

View File

@ -6331,12 +6331,13 @@ void CWallet::GetFilteredNotes(
}
}
std::vector<OrchardNoteMetadata> orchardNotes;
if (noteFilter.has_value()) {
for (const OrchardRawAddress& addr: noteFilter.value().GetOrchardAddresses()) {
auto ivk = orchardWallet.GetIncomingViewingKeyForAddress(addr);
if (ivk.has_value()) {
orchardWallet.GetFilteredNotes(
orchardNotesRet,
orchardNotes,
ivk.value(),
ignoreSpent,
ignoreLocked,
@ -6346,17 +6347,20 @@ void CWallet::GetFilteredNotes(
} else {
// return all Orchard notes
orchardWallet.GetFilteredNotes(
orchardNotesRet,
orchardNotes,
std::nullopt,
ignoreSpent,
ignoreLocked,
requireSpendingKey);
}
for (auto &orchardNoteMeta : orchardNotesRet) {
auto wtx = GetWalletTx(orchardNoteMeta.GetOutPoint().hash);
for (auto& noteMeta : orchardNotes) {
auto wtx = GetWalletTx(noteMeta.GetOutPoint().hash);
if (wtx) {
orchardNoteMeta.SetConfirmations(wtx->GetDepthInMainChain());
if (wtx->GetDepthInMainChain() >= minDepth) {
noteMeta.SetConfirmations(wtx->GetDepthInMainChain());
orchardNotesRet.push_back(noteMeta);
}
} else {
throw std::runtime_error("Wallet inconsistency: We have an Orchard WalletTx without a corresponding CWalletTx");
}