Skip to content

Commit fa650ca

Browse files
author
MarcoFalke
committed
Use -Wswitch for TxoutType where possible
1 parent fa59e0b commit fa650ca

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

src/script/sign.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
106106
std::vector<valtype> vSolutions;
107107
whichTypeRet = Solver(scriptPubKey, vSolutions);
108108

109-
switch (whichTypeRet)
110-
{
109+
switch (whichTypeRet) {
111110
case TxoutType::NONSTANDARD:
112111
case TxoutType::NULL_DATA:
113112
case TxoutType::WITNESS_UNKNOWN:
@@ -173,10 +172,8 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
173172
// Could not find witnessScript, add to missing
174173
sigdata.missing_witness_script = uint256(vSolutions[0]);
175174
return false;
176-
177-
default:
178-
return false;
179-
}
175+
} // no default case, so the compiler can warn about missing cases
176+
assert(false);
180177
}
181178

182179
static CScript PushAll(const std::vector<valtype>& values)

src/script/standard.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
4545

4646
std::string GetTxnOutputType(TxoutType t)
4747
{
48-
switch (t)
49-
{
48+
switch (t) {
5049
case TxoutType::NONSTANDARD: return "nonstandard";
5150
case TxoutType::PUBKEY: return "pubkey";
5251
case TxoutType::PUBKEYHASH: return "pubkeyhash";
@@ -182,43 +181,51 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
182181
std::vector<valtype> vSolutions;
183182
TxoutType whichType = Solver(scriptPubKey, vSolutions);
184183

185-
if (whichType == TxoutType::PUBKEY) {
184+
switch (whichType) {
185+
case TxoutType::PUBKEY: {
186186
CPubKey pubKey(vSolutions[0]);
187187
if (!pubKey.IsValid())
188188
return false;
189189

190190
addressRet = PKHash(pubKey);
191191
return true;
192192
}
193-
else if (whichType == TxoutType::PUBKEYHASH)
194-
{
193+
case TxoutType::PUBKEYHASH: {
195194
addressRet = PKHash(uint160(vSolutions[0]));
196195
return true;
197196
}
198-
else if (whichType == TxoutType::SCRIPTHASH)
199-
{
197+
case TxoutType::SCRIPTHASH: {
200198
addressRet = ScriptHash(uint160(vSolutions[0]));
201199
return true;
202-
} else if (whichType == TxoutType::WITNESS_V0_KEYHASH) {
200+
}
201+
case TxoutType::WITNESS_V0_KEYHASH: {
203202
WitnessV0KeyHash hash;
204203
std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
205204
addressRet = hash;
206205
return true;
207-
} else if (whichType == TxoutType::WITNESS_V0_SCRIPTHASH) {
206+
}
207+
case TxoutType::WITNESS_V0_SCRIPTHASH: {
208208
WitnessV0ScriptHash hash;
209209
std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
210210
addressRet = hash;
211211
return true;
212-
} else if (whichType == TxoutType::WITNESS_UNKNOWN || whichType == TxoutType::WITNESS_V1_TAPROOT) {
212+
}
213+
case TxoutType::WITNESS_UNKNOWN:
214+
case TxoutType::WITNESS_V1_TAPROOT: {
213215
WitnessUnknown unk;
214216
unk.version = vSolutions[0][0];
215217
std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);
216218
unk.length = vSolutions[1].size();
217219
addressRet = unk;
218220
return true;
219221
}
220-
// Multisig txns have more than one address...
221-
return false;
222+
case TxoutType::MULTISIG:
223+
// Multisig txns have more than one address...
224+
case TxoutType::NULL_DATA:
225+
case TxoutType::NONSTANDARD:
226+
return false;
227+
} // no default case, so the compiler can warn about missing cases
228+
assert(false);
222229
}
223230

224231
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)

src/wallet/rpcdump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,9 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
934934
case TxoutType::NONSTANDARD:
935935
case TxoutType::WITNESS_UNKNOWN:
936936
case TxoutType::WITNESS_V1_TAPROOT:
937-
default:
938937
return "unrecognized script";
939-
}
938+
} // no default case, so the compiler can warn about missing cases
939+
CHECK_NONFATAL(false);
940940
}
941941

942942
static UniValue ProcessImportLegacy(ImportData& import_data, std::map<CKeyID, CPubKey>& pubkey_map, std::map<CKeyID, CKey>& privkey_map, std::set<CScript>& script_pub_keys, bool& have_solving_data, const UniValue& data, std::vector<CKeyID>& ordered_pubkeys)

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
9191
TxoutType whichType = Solver(scriptPubKey, vSolutions);
9292

9393
CKeyID keyID;
94-
switch (whichType)
95-
{
94+
switch (whichType) {
9695
case TxoutType::NONSTANDARD:
9796
case TxoutType::NULL_DATA:
9897
case TxoutType::WITNESS_UNKNOWN:
@@ -191,7 +190,7 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
191190
}
192191
break;
193192
}
194-
}
193+
} // no default case, so the compiler can warn about missing cases
195194

196195
if (ret == IsMineResult::NO && keystore.HaveWatchOnly(scriptPubKey)) {
197196
ret = std::max(ret, IsMineResult::WATCH_ONLY);

0 commit comments

Comments
 (0)