mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Use -Wswitch for TxoutType where possible
This commit is contained in:
parent
fa59e0b5bd
commit
fa650ca7f1
4 changed files with 26 additions and 23 deletions
|
@ -106,8 +106,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
|
||||||
std::vector<valtype> vSolutions;
|
std::vector<valtype> vSolutions;
|
||||||
whichTypeRet = Solver(scriptPubKey, vSolutions);
|
whichTypeRet = Solver(scriptPubKey, vSolutions);
|
||||||
|
|
||||||
switch (whichTypeRet)
|
switch (whichTypeRet) {
|
||||||
{
|
|
||||||
case TxoutType::NONSTANDARD:
|
case TxoutType::NONSTANDARD:
|
||||||
case TxoutType::NULL_DATA:
|
case TxoutType::NULL_DATA:
|
||||||
case TxoutType::WITNESS_UNKNOWN:
|
case TxoutType::WITNESS_UNKNOWN:
|
||||||
|
@ -173,10 +172,8 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
|
||||||
// Could not find witnessScript, add to missing
|
// Could not find witnessScript, add to missing
|
||||||
sigdata.missing_witness_script = uint256(vSolutions[0]);
|
sigdata.missing_witness_script = uint256(vSolutions[0]);
|
||||||
return false;
|
return false;
|
||||||
|
} // no default case, so the compiler can warn about missing cases
|
||||||
default:
|
assert(false);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static CScript PushAll(const std::vector<valtype>& values)
|
static CScript PushAll(const std::vector<valtype>& values)
|
||||||
|
|
|
@ -45,8 +45,7 @@ WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
|
||||||
|
|
||||||
std::string GetTxnOutputType(TxoutType t)
|
std::string GetTxnOutputType(TxoutType t)
|
||||||
{
|
{
|
||||||
switch (t)
|
switch (t) {
|
||||||
{
|
|
||||||
case TxoutType::NONSTANDARD: return "nonstandard";
|
case TxoutType::NONSTANDARD: return "nonstandard";
|
||||||
case TxoutType::PUBKEY: return "pubkey";
|
case TxoutType::PUBKEY: return "pubkey";
|
||||||
case TxoutType::PUBKEYHASH: return "pubkeyhash";
|
case TxoutType::PUBKEYHASH: return "pubkeyhash";
|
||||||
|
@ -182,7 +181,8 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
||||||
std::vector<valtype> vSolutions;
|
std::vector<valtype> vSolutions;
|
||||||
TxoutType whichType = Solver(scriptPubKey, vSolutions);
|
TxoutType whichType = Solver(scriptPubKey, vSolutions);
|
||||||
|
|
||||||
if (whichType == TxoutType::PUBKEY) {
|
switch (whichType) {
|
||||||
|
case TxoutType::PUBKEY: {
|
||||||
CPubKey pubKey(vSolutions[0]);
|
CPubKey pubKey(vSolutions[0]);
|
||||||
if (!pubKey.IsValid())
|
if (!pubKey.IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
@ -190,26 +190,28 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
||||||
addressRet = PKHash(pubKey);
|
addressRet = PKHash(pubKey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (whichType == TxoutType::PUBKEYHASH)
|
case TxoutType::PUBKEYHASH: {
|
||||||
{
|
|
||||||
addressRet = PKHash(uint160(vSolutions[0]));
|
addressRet = PKHash(uint160(vSolutions[0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (whichType == TxoutType::SCRIPTHASH)
|
case TxoutType::SCRIPTHASH: {
|
||||||
{
|
|
||||||
addressRet = ScriptHash(uint160(vSolutions[0]));
|
addressRet = ScriptHash(uint160(vSolutions[0]));
|
||||||
return true;
|
return true;
|
||||||
} else if (whichType == TxoutType::WITNESS_V0_KEYHASH) {
|
}
|
||||||
|
case TxoutType::WITNESS_V0_KEYHASH: {
|
||||||
WitnessV0KeyHash hash;
|
WitnessV0KeyHash hash;
|
||||||
std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
|
std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
|
||||||
addressRet = hash;
|
addressRet = hash;
|
||||||
return true;
|
return true;
|
||||||
} else if (whichType == TxoutType::WITNESS_V0_SCRIPTHASH) {
|
}
|
||||||
|
case TxoutType::WITNESS_V0_SCRIPTHASH: {
|
||||||
WitnessV0ScriptHash hash;
|
WitnessV0ScriptHash hash;
|
||||||
std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
|
std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
|
||||||
addressRet = hash;
|
addressRet = hash;
|
||||||
return true;
|
return true;
|
||||||
} else if (whichType == TxoutType::WITNESS_UNKNOWN || whichType == TxoutType::WITNESS_V1_TAPROOT) {
|
}
|
||||||
|
case TxoutType::WITNESS_UNKNOWN:
|
||||||
|
case TxoutType::WITNESS_V1_TAPROOT: {
|
||||||
WitnessUnknown unk;
|
WitnessUnknown unk;
|
||||||
unk.version = vSolutions[0][0];
|
unk.version = vSolutions[0][0];
|
||||||
std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);
|
std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);
|
||||||
|
@ -217,8 +219,13 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
||||||
addressRet = unk;
|
addressRet = unk;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case TxoutType::MULTISIG:
|
||||||
// Multisig txns have more than one address...
|
// Multisig txns have more than one address...
|
||||||
|
case TxoutType::NULL_DATA:
|
||||||
|
case TxoutType::NONSTANDARD:
|
||||||
return false;
|
return false;
|
||||||
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
|
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
|
||||||
|
|
|
@ -934,9 +934,9 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
|
||||||
case TxoutType::NONSTANDARD:
|
case TxoutType::NONSTANDARD:
|
||||||
case TxoutType::WITNESS_UNKNOWN:
|
case TxoutType::WITNESS_UNKNOWN:
|
||||||
case TxoutType::WITNESS_V1_TAPROOT:
|
case TxoutType::WITNESS_V1_TAPROOT:
|
||||||
default:
|
|
||||||
return "unrecognized script";
|
return "unrecognized script";
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
CHECK_NONFATAL(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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)
|
||||||
|
|
|
@ -91,8 +91,7 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
|
||||||
TxoutType whichType = Solver(scriptPubKey, vSolutions);
|
TxoutType whichType = Solver(scriptPubKey, vSolutions);
|
||||||
|
|
||||||
CKeyID keyID;
|
CKeyID keyID;
|
||||||
switch (whichType)
|
switch (whichType) {
|
||||||
{
|
|
||||||
case TxoutType::NONSTANDARD:
|
case TxoutType::NONSTANDARD:
|
||||||
case TxoutType::NULL_DATA:
|
case TxoutType::NULL_DATA:
|
||||||
case TxoutType::WITNESS_UNKNOWN:
|
case TxoutType::WITNESS_UNKNOWN:
|
||||||
|
@ -191,7 +190,7 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
|
||||||
if (ret == IsMineResult::NO && keystore.HaveWatchOnly(scriptPubKey)) {
|
if (ret == IsMineResult::NO && keystore.HaveWatchOnly(scriptPubKey)) {
|
||||||
ret = std::max(ret, IsMineResult::WATCH_ONLY);
|
ret = std::max(ret, IsMineResult::WATCH_ONLY);
|
||||||
|
|
Loading…
Add table
Reference in a new issue