Add RecipientAddress type.
This commit is contained in:
parent
18282040f5
commit
0abe07c73b
|
@ -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; },
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue