17 #include <boost/algorithm/string/classification.hpp>
18 #include <boost/algorithm/string/predicate.hpp>
19 #include <boost/algorithm/string/replace.hpp>
20 #include <boost/algorithm/string/split.hpp>
21 #include <boost/assign/list_of.hpp>
27 static std::map<std::string, opcodetype> mapOpNames;
29 if (mapOpNames.empty())
31 for (
int op = 0; op <=
OP_NOP10; op++)
38 if (strcmp(name,
"OP_UNKNOWN") == 0)
40 std::string strName(name);
43 boost::algorithm::replace_first(strName,
"OP_",
"");
48 std::vector<std::string> words;
49 boost::algorithm::split(words, s, boost::algorithm::is_any_of(
" \t\n"), boost::algorithm::token_compress_on);
51 for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
57 else if (all(*w, boost::algorithm::is_digit()) ||
58 (boost::algorithm::starts_with(*w,
"-") && all(std::string(w->begin()+1, w->end()), boost::algorithm::is_digit())))
64 else if (boost::algorithm::starts_with(*w,
"0x") && (w->begin()+2 != w->end()) &&
IsHex(std::string(w->begin()+2, w->end())))
67 std::vector<unsigned char> raw =
ParseHex(std::string(w->begin()+2, w->end()));
68 result.
insert(result.
end(), raw.begin(), raw.end());
70 else if (w->size() >= 2 && boost::algorithm::starts_with(*w,
"'") && boost::algorithm::ends_with(*w,
"'"))
74 std::vector<unsigned char> value(w->begin()+1, w->end()-1);
77 else if (mapOpNames.count(*w))
80 result << mapOpNames[*w];
84 throw std::runtime_error(
"script parse error");
96 std::vector<unsigned char> txData(
ParseHex(strHexTx));
106 catch (
const std::exception&) {
117 catch (
const std::exception&) {
126 if (!
IsHex(strHexBlk))
129 std::vector<unsigned char> blockData(
ParseHex(strHexBlk));
134 catch (
const std::exception&) {
152 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
165 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
Double ended buffer combining vector and stream-like interfaces.
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(const std::string &s)
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)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx, bool fTryNoWitness)
const char * GetOpName(opcodetype opcode)
opcodetype
Script opcodes.
A mutable version of CTransaction.
int64_t atoi64(const char *psz)
bool IsHex(const string &str)
vector< unsigned char > ParseHex(const char *psz)