20#include <boost/algorithm/string/classification.hpp>
21#include <boost/algorithm/string/split.hpp>
29 static std::map<std::string, opcodetype>
mapOpNames;
45 if (
strName.compare(0, 3,
"OP_") == 0) {
53 throw std::runtime_error(
"script parse error: unknown opcode " + s);
63 std::vector<std::string>
words;
64 boost::algorithm::split(
words, s, boost::algorithm::is_any_of(
" \t\n"),
65 boost::algorithm::token_compress_on);
72 for (
const auto &w :
words) {
87 if (std::all_of(w.begin(), w.end(),
::IsDigit) ||
88 (w.front() ==
'-' && w.size() > 1 &&
89 std::all_of(w.begin() + 1, w.end(),
::IsDigit))) {
97 throw std::runtime_error(
"script parse error: decimal numeric "
98 "value only allowed in the "
99 "range -0xFFFFFFFF...0xFFFFFFFF");
107 if (w.substr(0, 2) ==
"0x" && w.size() > 2) {
108 if (!
IsHex(std::string(w.begin() + 2, w.end()))) {
110 throw std::runtime_error(
"Hex numbers expected to be formatted "
111 "in full-byte chunks (ex: 0x00 "
116 std::vector<uint8_t> raw =
117 ParseHex(std::string(w.begin() + 2, w.end()));
119 result.
insert(result.
end(), raw.begin(), raw.end());
123 if (w.size() >= 2 && w.front() ==
'\'' && w.back() ==
'\'') {
127 std::vector<uint8_t> value(w.begin() + 1, w.end() - 1);
140 throw std::runtime_error(
141 "Wrong number of bytes being pushed. Expected:" +
210 }
catch (
const std::exception &
e) {
226 }
catch (
const std::exception &) {
241 }
catch (
const std::exception &) {
264 throw std::runtime_error(
265 strName +
" must be hexadecimal string (not '" +
strHex +
"')");
278 {
"ALL|FORKID|ANYONECANPAY",
283 {
"NONE|FORKID|ANYONECANPAY",
288 {
"SINGLE|FORKID|ANYONECANPAY",
297 " is not a valid sighash parameter.");
Double ended buffer combining vector and stream-like interfaces.
A mutable version of CTransaction.
Serialized script, used inside transaction inputs and outputs.
Signature hash type wrapper class.
SigHashType withForkId(bool forkId=true) const
const std::string & getValStr() const
void SetHex(const char *psz)
iterator insert(iterator pos, const T &value)
reverse_iterator rbegin()
CScript ParseScript(const std::string &s)
bool DecodeHexBlockHeader(CBlockHeader &header, const std::string &hex_header)
bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx)
std::vector< uint8_t > ParseHexUV(const UniValue &v, const std::string &strName)
bool ParseHashStr(const std::string &strHex, uint256 &result)
Parse a hex string into 256 bits.
SigHashType ParseSighashString(const UniValue &sighash)
bool DecodeHexBlk(CBlock &block, const std::string &strHexBlk)
static uint16_t ReadLE16(const uint8_t *ptr)
static uint32_t ReadLE32(const uint8_t *ptr)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::string GetOpName(opcodetype opcode)
opcodetype
Script opcodes.
@ FIRST_UNDEFINED_OP_VALUE
static std::string ToString(const CService &ip)
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
template std::vector< std::byte > ParseHex(std::string_view)
bool IsHex(std::string_view str)
Returns true if each character in str is a hex character, and has an even number of hex digits.
int64_t atoi64(const std::string &str)
static const int PROTOCOL_VERSION
network protocol versioning