script/verify_flags: make script_verify_flags type safe

`using script_verify_flags = uint32_t` allows implicit conversion to
and from int, so replace it with a class to have the compiler ensure we
use the correct type. Provide from_int and as_int to allow for explicit
conversions when desired.

Introduces the type `script_verify_flag_name` for the individual flag
name enumeration.
This commit is contained in:
Anthony Towns
2025-07-26 18:51:24 +10:00
parent a5ead122fe
commit bddcadee82
12 changed files with 100 additions and 25 deletions

View File

@@ -2164,7 +2164,7 @@ size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey,
}
#define FLAG_NAME(flag) {std::string(#flag), SCRIPT_VERIFY_##flag}
const std::map<std::string, uint32_t> g_verify_flag_names{
const std::map<std::string, script_verify_flag_name> g_verify_flag_names{
FLAG_NAME(P2SH),
FLAG_NAME(STRICTENC),
FLAG_NAME(DERSIG),
@@ -2203,7 +2203,7 @@ std::vector<std::string> GetScriptFlagNames(script_verify_flags flags)
}
}
if (leftover != 0) {
res.push_back(strprintf("0x%08x", leftover));
res.push_back(strprintf("0x%08x", leftover.as_int()));
}
return res;
}