MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / ParseOpCode

Function ParseOpCode

src/core_read.cpp:27–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace {
26
27opcodetype ParseOpCode(const std::string &s) {
28 static std::map<std::string, opcodetype> mapOpNames;
29
30 if (mapOpNames.empty()) {
31 for (int op = 0; op < FIRST_UNDEFINED_OP_VALUE; op++) {
32 if (op < OP_PUSHDATA1) {
33 continue;
34 }
35
36 std::string strName = GetOpName(static_cast<opcodetype>(op));
37 if (strName == "OP_UNKNOWN") {
38 continue;
39 }
40
41 mapOpNames[strName] = static_cast<opcodetype>(op);
42 // Convenience: OP_ADD and just ADD are both recognized:
43 // strName starts with "OP_"
44 if (strName.compare(0, 3, "OP_") == 0) {
45 mapOpNames[strName.substr(3)] = static_cast<opcodetype>(op);
46 }
47 }
48 }
49
50 auto it = mapOpNames.find(s);
51 if (it == mapOpNames.end()) {
52 throw std::runtime_error("script parse error: unknown opcode " + s);
53 }
54 return it->second;
55}
56
57} // namespace
58

Callers 1

ParseScriptFunction · 0.85

Calls 5

GetOpNameFunction · 0.85
emptyMethod · 0.45
compareMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected