MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetScriptNumber

Function GetScriptNumber

src/script/solver.cpp:66–83  ·  view source on GitHub ↗

Retrieve a minimally-encoded number in range [min,max] from an (opcode, data) pair, * whether it's OP_n or through a push. */

Source from the content-addressed store, hash-verified

64/** Retrieve a minimally-encoded number in range [min,max] from an (opcode, data) pair,
65 * whether it's OP_n or through a push. */
66static std::optional<int> GetScriptNumber(opcodetype opcode, valtype data, int min, int max)
67{
68 int count;
69 if (IsSmallInteger(opcode)) {
70 count = CScript::DecodeOP_N(opcode);
71 } else if (IsPushdataOp(opcode)) {
72 if (!CheckMinimalPush(data, opcode)) return {};
73 try {
74 count = CScriptNum(data, /* fRequireMinimal = */ true).getint();
75 } catch (const scriptnum_error&) {
76 return {};
77 }
78 } else {
79 return {};
80 }
81 if (count < min || count > max) return {};
82 return count;
83}
84
85static bool MatchMultisig(const CScript& script, int& required_sigs, std::vector<valtype>& pubkeys)
86{

Callers 2

MatchMultisigFunction · 0.85
MatchMultiAFunction · 0.85

Calls 5

IsSmallIntegerFunction · 0.85
IsPushdataOpFunction · 0.85
CheckMinimalPushFunction · 0.85
CScriptNumClass · 0.70
getintMethod · 0.45

Tested by

no test coverage detected