Add RecipientAddress type.

This commit is contained in:
Kris Nuttycombe 2022-01-13 14:55:54 -07:00
parent 18282040f5
commit 0abe07c73b
2 changed files with 27 additions and 0 deletions

View File

@ -73,6 +73,25 @@ std::optional<SaplingPaymentAddress> UnifiedAddress::GetSaplingReceiver() const
return std::nullopt;
}
std::optional<RecipientAddress> UnifiedAddress::GetPreferredRecipientAddress() const {
// Return the first receiver type we recognize; receivers are sorted in
// order from most-preferred to least.
std::optional<RecipientAddress> result;
for (const auto& receiver : *this) {
std::visit(match {
[&](const SaplingPaymentAddress& addr) { result = addr; },
[&](const CScriptID& addr) { result = addr; },
[&](const CKeyID& addr) { result = addr; },
[&](const UnknownReceiver& addr) { }
}, receiver);
if (result.has_value()) {
return result;
}
}
return std::nullopt;
}
bool HasKnownReceiverType(const Receiver& receiver) {
return std::visit(match {
[](const SaplingPaymentAddress& addr) { return true; },

View File

@ -90,6 +90,12 @@ private:
size_t cur;
};
/** A recipient address to which a unified address can be resolved */
typedef std::variant<
CKeyID,
CScriptID,
libzcash::SaplingPaymentAddress> RecipientAddress;
class UnifiedAddress {
std::vector<Receiver> receivers;
@ -148,6 +154,8 @@ public:
std::optional<SaplingPaymentAddress> GetSaplingReceiver() const;
std::optional<RecipientAddress> GetPreferredRecipientAddress() const;
friend inline bool operator==(const UnifiedAddress& a, const UnifiedAddress& b) {
return a.receivers == b.receivers;
}