Changeset View
Changeset View
Standalone View
Standalone View
src/core_read.cpp
Show All 9 Lines | |||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <version.h> | #include <version.h> | ||||
#include <boost/algorithm/string/classification.hpp> | #include <boost/algorithm/string/classification.hpp> | ||||
#include <boost/algorithm/string/predicate.hpp> | |||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <boost/algorithm/string/split.hpp> | #include <boost/algorithm/string/split.hpp> | ||||
#include <algorithm> | |||||
#include <univalue.h> | #include <univalue.h> | ||||
CScript ParseScript(const std::string &s) { | CScript ParseScript(const std::string &s) { | ||||
CScript result; | CScript result; | ||||
static std::map<std::string, opcodetype> mapOpNames; | static std::map<std::string, opcodetype> mapOpNames; | ||||
if (mapOpNames.empty()) { | if (mapOpNames.empty()) { | ||||
Show All 34 Lines | for (const auto &w : words) { | ||||
// Update script size. | // Update script size. | ||||
script_size = result.size(); | script_size = result.size(); | ||||
// Make sure we keep track of the size of push operations. | // Make sure we keep track of the size of push operations. | ||||
push_size = next_push_size; | push_size = next_push_size; | ||||
next_push_size = 0; | next_push_size = 0; | ||||
// Decimal numbers | // Decimal numbers | ||||
if (all(w, boost::algorithm::is_digit()) || | if (std::all_of(w.begin(), w.end(), ::IsDigit) || | ||||
(boost::algorithm::starts_with(w, "-") && | (w.front() == '-' && w.size() > 1 && | ||||
all(std::string(w.begin() + 1, w.end()), | std::all_of(w.begin() + 1, w.end(), ::IsDigit))) { | ||||
boost::algorithm::is_digit()))) { | |||||
// Number | // Number | ||||
int64_t n = atoi64(w); | int64_t n = atoi64(w); | ||||
result << n; | result << n; | ||||
goto next; | goto next; | ||||
} | } | ||||
// Hex Data | // Hex Data | ||||
if (boost::algorithm::starts_with(w, "0x") && | if (w.substr(0, 2) == "0x" && w.size() > 2) { | ||||
(w.begin() + 2 != w.end())) { | |||||
if (!IsHex(std::string(w.begin() + 2, w.end()))) { | if (!IsHex(std::string(w.begin() + 2, w.end()))) { | ||||
// Should only arrive here for improperly formatted hex values | // Should only arrive here for improperly formatted hex values | ||||
throw std::runtime_error("Hex numbers expected to be formatted " | throw std::runtime_error("Hex numbers expected to be formatted " | ||||
"in full-byte chunks (ex: 0x00 " | "in full-byte chunks (ex: 0x00 " | ||||
"instead of 0x0)"); | "instead of 0x0)"); | ||||
} | } | ||||
// Raw hex data, inserted NOT pushed onto stack: | // Raw hex data, inserted NOT pushed onto stack: | ||||
std::vector<uint8_t> raw = | std::vector<uint8_t> raw = | ||||
ParseHex(std::string(w.begin() + 2, w.end())); | ParseHex(std::string(w.begin() + 2, w.end())); | ||||
result.insert(result.end(), raw.begin(), raw.end()); | result.insert(result.end(), raw.begin(), raw.end()); | ||||
goto next; | goto next; | ||||
} | } | ||||
if (w.size() >= 2 && boost::algorithm::starts_with(w, "'") && | if (w.size() >= 2 && w.front() == '\'' && w.back() == '\'') { | ||||
boost::algorithm::ends_with(w, "'")) { | |||||
// Single-quoted string, pushed as data. NOTE: this is poor-man's | // Single-quoted string, pushed as data. NOTE: this is poor-man's | ||||
// parsing, spaces/tabs/newlines in single-quoted strings won't | // parsing, spaces/tabs/newlines in single-quoted strings won't | ||||
// work. | // work. | ||||
std::vector<uint8_t> value(w.begin() + 1, w.end() - 1); | std::vector<uint8_t> value(w.begin() + 1, w.end() - 1); | ||||
result << value; | result << value; | ||||
goto next; | goto next; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 198 Lines • Show Last 20 Lines |