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> 26 static std::map<std::string, opcodetype> mapOpNames;
28 if (mapOpNames.empty())
30 for (
unsigned int op = 0; op <= MAX_OPCODE; op++)
37 if (strcmp(name,
"OP_UNKNOWN") == 0)
39 std::string strName(name);
42 boost::algorithm::replace_first(strName,
"OP_",
"");
47 std::vector<std::string> words;
48 boost::algorithm::split(words, s, boost::algorithm::is_any_of(
" \t\n"), boost::algorithm::token_compress_on);
50 for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
56 else if (all(*w, boost::algorithm::is_digit()) ||
57 (boost::algorithm::starts_with(*w,
"-") && all(std::string(w->begin()+1, w->end()), boost::algorithm::is_digit())))
63 else if (boost::algorithm::starts_with(*w,
"0x") && (w->begin()+2 != w->end()) &&
IsHex(std::string(w->begin()+2, w->end())))
66 std::vector<unsigned char> raw =
ParseHex(std::string(w->begin()+2, w->end()));
67 result.
insert(result.
end(), raw.begin(), raw.end());
69 else if (w->size() >= 2 && boost::algorithm::starts_with(*w,
"'") && boost::algorithm::ends_with(*w,
"'"))
73 std::vector<unsigned char> value(w->begin()+1, w->end()-1);
76 else if (mapOpNames.count(*w))
79 result << mapOpNames[*w];
83 throw std::runtime_error(
"script parse error");
95 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
96 if (!tx.
vin[i].scriptSig.HasValidOps() || tx.
vin[i].scriptSig.size() > MAX_SCRIPT_SIZE) {
102 for (
unsigned int i = 0; i < tx.
vout.size(); i++) {
103 if (!tx.
vout[i].scriptPubKey.HasValidOps() || tx.
vout[i].scriptPubKey.size() > MAX_SCRIPT_SIZE) {
113 if (!
IsHex(strHexTx)) {
117 std::vector<unsigned char> txData(
ParseHex(strHexTx));
127 catch (
const std::exception&) {
135 if (!ssData.
empty()) {
139 catch (
const std::exception&) {
148 if (!
IsHex(strHexBlk))
151 std::vector<unsigned char> blockData(
ParseHex(strHexBlk));
156 catch (
const std::exception&) {
174 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
187 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
std::vector< unsigned char > ParseHexUV(const UniValue &v, const std::string &strName)
iterator insert(iterator pos, const T &value)
Double ended buffer combining vector and stream-like interfaces.
opcodetype
Script opcodes.
bool IsHex(const std::string &str)
uint256 ParseHashStr(const std::string &strHex, const std::string &strName)
bool CheckTxScriptsSanity(const CMutableTransaction &tx)
std::vector< CTxOut > vout
const char * GetOpName(opcodetype opcode)
CScript ParseScript(const std::string &s)
const std::string & getValStr() const
Serialized script, used inside transaction inputs and outputs.
int64_t atoi64(const char *psz)
A mutable version of CTransaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
void SetHex(const char *psz)
uint256 ParseHashUV(const UniValue &v, const std::string &strName)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx, bool fTryNoWitness)
bool DecodeHexBlk(CBlock &block, const std::string &strHexBlk)
std::vector< unsigned char > ParseHex(const char *psz)