diff --git a/src/core_read.cpp b/src/core_read.cpp index e1f778cab4..6aa270962d 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -17,10 +17,10 @@ #include -CScript ParseScript(const std::string& s) -{ - CScript result; +namespace { +opcodetype ParseOpCode(const std::string& s) +{ static std::map mapOpNames; if (mapOpNames.empty()) @@ -42,6 +42,17 @@ CScript ParseScript(const std::string& s) } } } + auto it = mapOpNames.find(s); + if (it == mapOpNames.end()) throw std::runtime_error("script parse error: unknown opcode"); + return it->second; +} + +} // namespace + +CScript ParseScript(const std::string& s) +{ + CScript result; + std::vector words = SplitString(s, " \t\n"); @@ -79,14 +90,10 @@ CScript ParseScript(const std::string& s) std::vector value(w->begin()+1, w->end()-1); result << value; } - else if (mapOpNames.count(*w)) - { - // opcode, e.g. OP_ADD or ADD: - result << mapOpNames[*w]; - } else { - throw std::runtime_error("script parse error"); + // opcode, e.g. OP_ADD or ADD: + result << ParseOpCode(*w); } } diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json index a84b7c9ea1..db9622d371 100644 --- a/test/util/data/bitcoin-util-test.json +++ b/test/util/data/bitcoin-util-test.json @@ -202,7 +202,7 @@ { "exec": "./dash-tx", "args": ["-create", "outscript=0:123badscript"], "return_code": 1, - "error_txt": "error: script parse error", + "error_txt": "error: script parse error: unknown opcode", "description": "Create a new transaction with an invalid output script" }, { "exec": "./dash-tx",