mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
Move mapFlagNames and FormatScriptFlags logic to script/interpreter.h
Moves FormatScriptFlags logic into GetScriptFlagNames which returns a vector of strings. For completeness, also has GetScriptFlagNames report on any bits that do not match a known script flag.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <crypto/sha256.h>
|
||||
#include <pubkey.h>
|
||||
#include <script/script.h>
|
||||
#include <tinyformat.h>
|
||||
#include <uint256.h>
|
||||
|
||||
typedef std::vector<unsigned char> valtype;
|
||||
@@ -2161,3 +2162,48 @@ size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FLAG_NAME(flag) {std::string(#flag), SCRIPT_VERIFY_##flag}
|
||||
const std::map<std::string, uint32_t> g_verify_flag_names{
|
||||
FLAG_NAME(P2SH),
|
||||
FLAG_NAME(STRICTENC),
|
||||
FLAG_NAME(DERSIG),
|
||||
FLAG_NAME(LOW_S),
|
||||
FLAG_NAME(SIGPUSHONLY),
|
||||
FLAG_NAME(MINIMALDATA),
|
||||
FLAG_NAME(NULLDUMMY),
|
||||
FLAG_NAME(DISCOURAGE_UPGRADABLE_NOPS),
|
||||
FLAG_NAME(CLEANSTACK),
|
||||
FLAG_NAME(MINIMALIF),
|
||||
FLAG_NAME(NULLFAIL),
|
||||
FLAG_NAME(CHECKLOCKTIMEVERIFY),
|
||||
FLAG_NAME(CHECKSEQUENCEVERIFY),
|
||||
FLAG_NAME(WITNESS),
|
||||
FLAG_NAME(DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM),
|
||||
FLAG_NAME(WITNESS_PUBKEYTYPE),
|
||||
FLAG_NAME(CONST_SCRIPTCODE),
|
||||
FLAG_NAME(TAPROOT),
|
||||
FLAG_NAME(DISCOURAGE_UPGRADABLE_PUBKEYTYPE),
|
||||
FLAG_NAME(DISCOURAGE_OP_SUCCESS),
|
||||
FLAG_NAME(DISCOURAGE_UPGRADABLE_TAPROOT_VERSION),
|
||||
};
|
||||
#undef FLAG_NAME
|
||||
|
||||
std::vector<std::string> GetScriptFlagNames(uint32_t flags)
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
if (flags == SCRIPT_VERIFY_NONE) {
|
||||
return res;
|
||||
}
|
||||
uint32_t leftover = flags;
|
||||
for (const auto& [name, flag] : g_verify_flag_names) {
|
||||
if ((flags & flag) != 0) {
|
||||
res.push_back(name);
|
||||
leftover &= ~flag;
|
||||
}
|
||||
}
|
||||
if (leftover != 0) {
|
||||
res.push_back(strprintf("0x%08x", leftover));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -371,4 +371,8 @@ size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey,
|
||||
|
||||
int FindAndDelete(CScript& script, const CScript& b);
|
||||
|
||||
extern const std::map<std::string, uint32_t> g_verify_flag_names;
|
||||
|
||||
std::vector<std::string> GetScriptFlagNames(uint32_t flags);
|
||||
|
||||
#endif // BITCOIN_SCRIPT_INTERPRETER_H
|
||||
|
||||
Reference in New Issue
Block a user