Skip to content

Commit f5649db

Browse files
committed
refactor: add UNKNOWN OutputType
add to enum, array and handle UNKNOWN in various case statements
1 parent ac59112 commit f5649db

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/outputtype.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
2020
static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit";
2121
static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32";
2222
static const std::string OUTPUT_TYPE_STRING_BECH32M = "bech32m";
23+
static const std::string OUTPUT_TYPE_STRING_UNKNOWN = "unknown";
2324

2425
std::optional<OutputType> ParseOutputType(const std::string& type)
2526
{
@@ -31,6 +32,8 @@ std::optional<OutputType> ParseOutputType(const std::string& type)
3132
return OutputType::BECH32;
3233
} else if (type == OUTPUT_TYPE_STRING_BECH32M) {
3334
return OutputType::BECH32M;
35+
} else if (type == OUTPUT_TYPE_STRING_UNKNOWN) {
36+
return OutputType::UNKNOWN;
3437
}
3538
return std::nullopt;
3639
}
@@ -42,6 +45,7 @@ const std::string& FormatOutputType(OutputType type)
4245
case OutputType::P2SH_SEGWIT: return OUTPUT_TYPE_STRING_P2SH_SEGWIT;
4346
case OutputType::BECH32: return OUTPUT_TYPE_STRING_BECH32;
4447
case OutputType::BECH32M: return OUTPUT_TYPE_STRING_BECH32M;
48+
case OutputType::UNKNOWN: return OUTPUT_TYPE_STRING_UNKNOWN;
4549
} // no default case, so the compiler can warn about missing cases
4650
assert(false);
4751
}
@@ -61,7 +65,8 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
6165
return witdest;
6266
}
6367
}
64-
case OutputType::BECH32M: {} // This function should never be used with BECH32M, so let it assert
68+
case OutputType::BECH32M:
69+
case OutputType::UNKNOWN: {} // This function should never be used with BECH32M or UNKNOWN, so let it assert
6570
} // no default case, so the compiler can warn about missing cases
6671
assert(false);
6772
}
@@ -101,7 +106,8 @@ CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore,
101106
return ScriptHash(witprog);
102107
}
103108
}
104-
case OutputType::BECH32M: {} // This function should not be used for BECH32M, so let it assert
109+
case OutputType::BECH32M:
110+
case OutputType::UNKNOWN: {} // This function should not be used for BECH32M or UNKNOWN, so let it assert
105111
} // no default case, so the compiler can warn about missing cases
106112
assert(false);
107113
}

src/outputtype.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ enum class OutputType {
1919
P2SH_SEGWIT,
2020
BECH32,
2121
BECH32M,
22+
UNKNOWN,
2223
};
2324

2425
static constexpr auto OUTPUT_TYPES = std::array{
2526
OutputType::LEGACY,
2627
OutputType::P2SH_SEGWIT,
2728
OutputType::BECH32,
2829
OutputType::BECH32M,
30+
OutputType::UNKNOWN,
2931
};
3032

3133
std::optional<OutputType> ParseOutputType(const std::string& str);

src/wallet/scriptpubkeyman.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,11 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
19661966
desc_prefix = "tr(" + xpub + "/86'";
19671967
break;
19681968
}
1969+
case OutputType::UNKNOWN: {
1970+
// We should never have a DescriptorScriptPubKeyMan for an UNKNOWN OutputType,
1971+
// so if we get to this point something is wrong
1972+
assert(false);
1973+
}
19691974
} // no default case, so the compiler can warn about missing cases
19701975
assert(!desc_prefix.empty());
19711976

src/wallet/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,6 +3421,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
34213421

34223422
for (bool internal : {false, true}) {
34233423
for (OutputType t : OUTPUT_TYPES) {
3424+
if (t == OutputType::UNKNOWN) continue;
34243425
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this));
34253426
if (IsCrypted()) {
34263427
if (IsLocked()) {

0 commit comments

Comments
 (0)