17 #include <boost/algorithm/string/classification.hpp>
18 #include <boost/algorithm/string/replace.hpp>
19 #include <boost/algorithm/string/split.hpp>
27 static std::map<std::string, opcodetype> mapOpNames;
29 if (mapOpNames.empty()) {
36 if (strcmp(
name,
"OP_UNKNOWN") == 0)
38 std::string strName(
name);
39 mapOpNames[strName] =
static_cast<opcodetype>(op);
41 boost::algorithm::replace_first(strName,
"OP_",
"");
42 mapOpNames[strName] =
static_cast<opcodetype>(op);
46 std::vector<std::string> words;
47 boost::algorithm::split(words, s, boost::algorithm::is_any_of(
" \t\n"), boost::algorithm::token_compress_on);
49 for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w) {
52 }
else if (std::all_of(w->begin(), w->end(), ::
IsDigit) ||
53 (w->front() ==
'-' && w->size() > 1 && std::all_of(w->begin()+1, w->end(), ::
IsDigit))) {
57 }
else if (w->substr(0,2) ==
"0x" && w->size() > 2 &&
IsHex(std::string(w->begin()+2, w->end()))) {
59 std::vector<unsigned char> raw =
ParseHex(std::string(w->begin() + 2, w->end()));
60 result.
insert(result.
end(), raw.begin(), raw.end());
61 }
else if (w->size() >= 2 && w->front() ==
'\'' && w->back() ==
'\'') {
64 std::vector<unsigned char> value(w->begin() + 1, w->end() - 1);
66 }
else if (mapOpNames.count(*w)) {
68 result << mapOpNames[*w];
70 throw std::runtime_error(
"script parse error");
82 std::vector<unsigned char> txData(
ParseHex(strHexTx));
86 }
catch (
const std::exception&) {
95 if (!
IsHex(strHexBlk))
98 std::vector<unsigned char> blockData(
ParseHex(strHexBlk));
102 }
catch (
const std::exception&) {
120 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
129 if (!
IsHex(strReq) || (strReq.size() != 64))
142 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
Serialized script, used inside transaction inputs and outputs.
const std::string & getValStr() const
void SetHex(const char *psz)
iterator insert(iterator pos, const T &value)
CScript ParseScript(std::string s)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
std::vector< unsigned char > ParseHexUV(const UniValue &v, const std::string &strName)
uint256 ParseHashStr(const std::string &strHex, const std::string &strName)
uint256 ParseHashUV(const UniValue &v, const std::string &strName)
bool DecodeHexBlk(CBlock &block, const std::string &strHexBlk)
const char * GetOpName(opcodetype opcode)
opcodetype
Script opcodes.
A mutable version of CTransaction.
int64_t atoi64(const char *psz)
std::vector< unsigned char > ParseHex(const char *psz)
bool IsHex(const std::string &str)
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.