Add Orchard to change address generation

This commit is contained in:
Jack Grigg 2022-03-14 16:58:57 +00:00
parent d4eee99060
commit d49c8a2865
5 changed files with 20 additions and 2 deletions

View File

@ -1901,6 +1901,9 @@ std::optional<RecipientAddress> CWallet::GenerateChangeAddressForAccount(
for (OutputPool t : changeOptions) {
std::optional<RecipientAddress> changeAddr;
switch (t) {
case OutputPool::Orchard:
changeAddr = ufvk.value().GetChangeAddress(OrchardChangeRequest());
break;
case OutputPool::Sapling:
changeAddr = ufvk.value().GetChangeAddress(SaplingChangeRequest());
break;

View File

@ -43,6 +43,10 @@ uint256 OrchardFullViewingKey::ToInternalOutgoingViewingKey() const {
return ovk;
}
OrchardRawAddress OrchardFullViewingKey::GetChangeAddress() const {
return ToInternalIncomingViewingKey().Address(0);
}
OrchardSpendingKey OrchardSpendingKey::ForAccount(
const HDSeed& seed,
uint32_t bip44CoinType,

View File

@ -206,6 +206,8 @@ public:
uint256 ToInternalOutgoingViewingKey() const;
libzcash::OrchardRawAddress GetChangeAddress() const;
OrchardFullViewingKey& operator=(OrchardFullViewingKey&& key)
{
if (this != &key) {

View File

@ -175,16 +175,23 @@ std::optional<RecipientAddress> ZcashdUnifiedFullViewingKey::GetChangeAddress(co
}
},
[&](const SaplingChangeRequest& req) {
// currently true by construction, as a UFVK must have a supported shielded component
if (saplingKey.has_value()) {
addr = saplingKey.value().GetChangeAddress();
}
},
[&](const OrchardChangeRequest& req) {
if (orchardKey.has_value()) {
addr = orchardKey.value().GetChangeAddress();
}
}
}, req);
return addr;
}
std::optional<RecipientAddress> ZcashdUnifiedFullViewingKey::GetChangeAddress() const {
if (orchardKey.has_value()) {
return orchardKey.value().GetChangeAddress();
}
if (saplingKey.has_value()) {
return saplingKey.value().GetChangeAddress();
}

View File

@ -58,10 +58,12 @@ public:
};
class SaplingChangeRequest {};
class OrchardChangeRequest {};
typedef std::variant<
TransparentChangeRequest,
SaplingChangeRequest> ChangeRequest;
SaplingChangeRequest,
OrchardChangeRequest> ChangeRequest;
/**
* Test whether the specified list of receiver types contains a