Simplify retrieval of unified account by address.

Co-authored-by: ying tong <yingtong@z.cash>
This commit is contained in:
Kris Nuttycombe 2022-03-16 23:23:01 -06:00 committed by Kris Nuttycombe
parent 9582a2c1f1
commit a783de43e3
1 changed files with 3 additions and 18 deletions

View File

@ -1773,25 +1773,10 @@ std::optional<libzcash::AccountId> CWallet::FindAccountForSelector(const ZTXOSel
} }
}, },
[&](const libzcash::UnifiedAddress& addr) { [&](const libzcash::UnifiedAddress& addr) {
std::optional<libzcash::AccountId> singleAccount; auto meta = GetUFVKMetadataForAddress(addr);
for (const auto& receiver : addr) {
auto meta = GetUFVKMetadataForReceiver(receiver);
if (meta.has_value()) { if (meta.has_value()) {
auto tmp = self->GetUnifiedAccountId(meta.value().first); result = self->GetUnifiedAccountId(meta.value().first);
if (singleAccount.has_value()) {
// If a UA corresponds to more than one account, we cannot return
// a sensible result, so we report it as corresponding to no
// account.
if (tmp.has_value() && singleAccount.value() != tmp.value()) {
singleAccount = std::nullopt;
break;
} }
} else {
singleAccount = tmp;
}
}
}
result = singleAccount;
}, },
[&](const libzcash::UnifiedFullViewingKey& vk) { [&](const libzcash::UnifiedFullViewingKey& vk) {
result = self->GetUnifiedAccountId(vk.GetKeyID(Params())); result = self->GetUnifiedAccountId(vk.GetKeyID(Params()));