Add OutputType::BECH32M

Bech32m addresses need their own OutputType

We are not ready to create DescriptorScriptPubKeyMans which produce
bech32m addresses. So don't allow generating them.
This commit is contained in:
Andrew Chow 2021-06-04 16:38:47 -04:00
parent 177c15d2f7
commit 0262536c34
4 changed files with 21 additions and 0 deletions

View file

@ -18,6 +18,7 @@
static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit";
static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32";
static const std::string OUTPUT_TYPE_STRING_BECH32M = "bech32m";
bool ParseOutputType(const std::string& type, OutputType& output_type)
{
@ -30,6 +31,9 @@ bool ParseOutputType(const std::string& type, OutputType& output_type)
} else if (type == OUTPUT_TYPE_STRING_BECH32) {
output_type = OutputType::BECH32;
return true;
} else if (type == OUTPUT_TYPE_STRING_BECH32M) {
output_type = OutputType::BECH32M;
return true;
}
return false;
}
@ -40,6 +44,7 @@ const std::string& FormatOutputType(OutputType type)
case OutputType::LEGACY: return OUTPUT_TYPE_STRING_LEGACY;
case OutputType::P2SH_SEGWIT: return OUTPUT_TYPE_STRING_P2SH_SEGWIT;
case OutputType::BECH32: return OUTPUT_TYPE_STRING_BECH32;
case OutputType::BECH32M: return OUTPUT_TYPE_STRING_BECH32M;
} // no default case, so the compiler can warn about missing cases
assert(false);
}
@ -59,6 +64,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
return witdest;
}
}
case OutputType::BECH32M: {} // This function should never be used with BECH32M, so let it assert
} // no default case, so the compiler can warn about missing cases
assert(false);
}
@ -98,6 +104,7 @@ CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore,
return ScriptHash(witprog);
}
}
case OutputType::BECH32M: {} // This function should not be used for BECH32M, so let it assert
} // no default case, so the compiler can warn about missing cases
assert(false);
}

View file

@ -18,12 +18,14 @@ enum class OutputType {
LEGACY,
P2SH_SEGWIT,
BECH32,
BECH32M,
};
static constexpr auto OUTPUT_TYPES = std::array{
OutputType::LEGACY,
OutputType::P2SH_SEGWIT,
OutputType::BECH32,
OutputType::BECH32M,
};
[[nodiscard]] bool ParseOutputType(const std::string& str, OutputType& output_type);

View file

@ -1889,6 +1889,12 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type)
{
if (addr_type == OutputType::BECH32M) {
// Don't allow setting up taproot descriptors yet
// TODO: Allow setting up taproot descriptors
return false;
}
LOCK(cs_desc_man);
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
@ -1918,6 +1924,7 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
desc_prefix = "wpkh(" + xpub + "/84'";
break;
}
case OutputType::BECH32M: assert(false); // TODO: Setup taproot descriptor
} // no default case, so the compiler can warn about missing cases
assert(!desc_prefix.empty());

View file

@ -3086,6 +3086,11 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
for (bool internal : {false, true}) {
for (OutputType t : OUTPUT_TYPES) {
if (t == OutputType::BECH32M) {
// Skip taproot (bech32m) for now
// TODO: Setup taproot (bech32m) descriptors by default
continue;
}
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, internal));
if (IsCrypted()) {
if (IsLocked()) {