18 #include <boost/algorithm/string/classification.hpp> 19 #include <boost/algorithm/string/predicate.hpp> 20 #include <boost/algorithm/string/replace.hpp> 21 #include <boost/algorithm/string/split.hpp> 27 static std::map<std::string, opcodetype> mapOpNames;
29 if (mapOpNames.empty())
31 for (
unsigned int op = 0; op <= MAX_OPCODE; 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 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
97 if (!tx.
vin[i].scriptSig.HasValidOps() || tx.
vin[i].scriptSig.size() > MAX_SCRIPT_SIZE) {
103 for (
unsigned int i = 0; i < tx.
vout.size(); i++) {
104 if (!tx.
vout[i].scriptPubKey.HasValidOps() || tx.
vout[i].scriptPubKey.size() > MAX_SCRIPT_SIZE) {
114 if (!
IsHex(strHexTx)) {
118 std::vector<unsigned char> txData(
ParseHex(strHexTx));
128 catch (
const std::exception&) {
136 if (!ssData.
empty()) {
140 catch (
const std::exception&) {
149 if (!
IsHex(strHexBlk))
152 std::vector<unsigned char> blockData(
ParseHex(strHexBlk));
157 catch (
const std::exception&) {
175 throw std::runtime_error(strName +
" must be hexadecimal string (not '" + strHex +
"')");
188 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.
const std::string & getValStr() const
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)
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)