Change SetType to SetInternal and remove m_address_type

m_address_type was used for two things:
1. Determine the type of descriptor to generate during
   SetupDescriptorGeneration
2. Sanity check during GetNewDestination.

There is no need to have this variable to accomplish those things.
1. Add a argument to SetupDescriptorGeneration indicating the address
   type to use
2. Use Descriptor::GetOutputType for the sanity check.
This commit is contained in:
Andrew Chow
2020-04-27 15:27:43 -04:00
parent 89b1ce1140
commit ca2a09640f
3 changed files with 16 additions and 16 deletions

View File

@@ -1497,7 +1497,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
return set_address;
}
void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {}
void LegacyScriptPubKeyMan::SetInternal(bool internal) {}
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
{
@@ -1509,7 +1509,9 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
{
LOCK(cs_desc_man);
assert(m_wallet_descriptor.descriptor->IsSingleType()); // This is a combo descriptor which should not be an active descriptor
if (type != m_address_type) {
Optional<OutputType> desc_addr_type = m_wallet_descriptor.descriptor->GetOutputType();
assert(desc_addr_type);
if (type != *desc_addr_type) {
throw std::runtime_error(std::string(__func__) + ": Types are inconsistent");
}
@@ -1777,7 +1779,7 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
}
}
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key)
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type)
{
LOCK(cs_desc_man);
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
@@ -1794,7 +1796,7 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
// Build descriptor string
std::string desc_prefix;
std::string desc_suffix = "/*)";
switch (m_address_type) {
switch (addr_type) {
case OutputType::LEGACY: {
desc_prefix = "pkh(" + xpub + "/44'";
break;
@@ -2076,9 +2078,8 @@ uint256 DescriptorScriptPubKeyMan::GetID() const
return id;
}
void DescriptorScriptPubKeyMan::SetType(OutputType type, bool internal)
void DescriptorScriptPubKeyMan::SetInternal(bool internal)
{
this->m_address_type = type;
this->m_internal = internal;
}