6#ifndef BITCOIN_SCRIPT_SCRIPT_H
7#define BITCOIN_SCRIPT_SCRIPT_H
43 return std::vector<uint8_t>(
in.begin(),
in.end());
213 :
std::runtime_error(str) {}
243 const std::vector<uint8_t> &vch,
332 (
rhs > 0 &&
m_value <= std::numeric_limits<int64_t>::max() -
rhs) ||
341 (
rhs > 0 &&
m_value >= std::numeric_limits<int64_t>::min() +
rhs) ||
342 (
rhs < 0 &&
m_value <= std::numeric_limits<int64_t>::max() +
rhs));
353 if (
m_value > std::numeric_limits<int>::max()) {
354 return std::numeric_limits<int>::max();
355 }
else if (
m_value < std::numeric_limits<int>::min()) {
356 return std::numeric_limits<int>::min();
368 std::vector<uint8_t> result;
369 const bool neg = value < 0;
386 if (result.back() & 0x80) {
387 result.push_back(
neg ? 0x80 : 0);
389 result.back() |= 0x80;
402 for (
size_t i = 0; i != vch.size(); ++i) {
403 result |=
int64_t(vch[i]) << 8 * i;
408 if (vch.back() & 0x80) {
409 return -
int64_t(result & ~(0x80ULL << (8 * (vch.size() - 1))));
428 std::vector<uint8_t> *
pvchRet);
434 if (n == -1 || (n >= 1 && n <= 16)) {
449 std::vector<uint8_t>::const_iterator pend)
461 explicit CScript(
const std::vector<uint8_t> &
b) =
delete;
470 throw std::runtime_error(
"CScript::operator<<(): invalid opcode");
484 }
else if (
b.size() <= 0xff) {
487 }
else if (
b.size() <= 0xffff) {
503 std::vector<uint8_t> &
vchRet)
const {
513 if (opcode ==
OP_0) {
521 assert(n >= 0 && n <= 16);
Serialized script, used inside transaction inputs and outputs.
CScript(const_iterator pbegin, const_iterator pend)
bool IsPayToScriptHash() const
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
CScript & operator<<(const CScript &b)=delete
Delete non-existent operator to defend against future introduction.
CScript(const CScriptNum &b)
CScript(const uint8_t *pbegin, const uint8_t *pend)
CScript & push_int64(int64_t n)
SERIALIZE_METHODS(CScript, obj)
CScript(std::vector< uint8_t >::const_iterator pbegin, std::vector< uint8_t >::const_iterator pend)
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
bool IsWitnessProgram() const
CScript & operator<<(const std::vector< uint8_t > &b) LIFETIMEBOUND
bool HasValidOps() const
Check if the script contains valid OP_CODES.
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
CScript & operator<<(opcodetype opcode) LIFETIMEBOUND
CScript & operator<<(const CScriptNum &b) LIFETIMEBOUND
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< uint8_t > &vchRet) const
CScript(const std::vector< uint8_t > &b)=delete
CScript & operator<<(int64_t b) LIFETIMEBOUND
static opcodetype EncodeOP_N(int n)
CScriptNum & operator-=(const CScriptNum &rhs)
CScriptNum & operator-=(const int64_t &rhs)
CScriptNum operator-(const int64_t &rhs) const
bool operator<(const CScriptNum &rhs) const
CScriptNum operator+(const int64_t &rhs) const
CScriptNum & operator+=(const CScriptNum &rhs)
CScriptNum operator-(const CScriptNum &rhs) const
bool operator>(const CScriptNum &rhs) const
bool operator==(const CScriptNum &rhs) const
static std::vector< uint8_t > serialize(const int64_t &value)
CScriptNum & operator&=(const CScriptNum &rhs)
std::vector< uint8_t > getvch() const
bool operator<=(const CScriptNum &rhs) const
bool operator==(const int64_t &rhs) const
bool operator<(const int64_t &rhs) const
CScriptNum(const std::vector< uint8_t > &vch, bool fRequireMinimal, const size_t nMaxNumSize=MAXIMUM_ELEMENT_SIZE)
CScriptNum operator%(const int64_t &rhs) const
CScriptNum operator&(const int64_t &rhs) const
CScriptNum operator&(const CScriptNum &rhs) const
CScriptNum & operator+=(const int64_t &rhs)
bool operator>=(const int64_t &rhs) const
bool operator<=(const int64_t &rhs) const
CScriptNum operator%(const CScriptNum &rhs) const
CScriptNum(const int64_t &n)
static bool MinimallyEncode(std::vector< uint8_t > &data)
bool operator!=(const int64_t &rhs) const
bool operator>=(const CScriptNum &rhs) const
bool operator>(const int64_t &rhs) const
CScriptNum & operator&=(const int64_t &rhs)
static int64_t set_vch(const std::vector< uint8_t > &vch)
static const size_t MAXIMUM_ELEMENT_SIZE
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
CScriptNum operator/(const CScriptNum &rhs) const
CScriptNum operator/(const int64_t &rhs) const
CScriptNum operator-() const
bool operator!=(const CScriptNum &rhs) const
CScriptNum & operator=(const int64_t &rhs)
static bool IsMinimallyEncoded(const std::vector< uint8_t > &vch, const size_t nMaxNumSize=CScriptNum::MAXIMUM_ELEMENT_SIZE)
CScriptNum operator+(const CScriptNum &rhs) const
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
iterator insert(iterator pos, const T &value)
void push_back(const T &value)
scriptnum_error(const std::string &str)
static void WriteLE16(uint8_t *ptr, uint16_t x)
static void WriteLE32(uint8_t *ptr, uint32_t x)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
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...
static const unsigned int LOCKTIME_THRESHOLD
static const unsigned int MAX_OPCODE
std::string GetOpName(opcodetype opcode)
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
static const int MAX_SCRIPT_SIZE
opcodetype
Script opcodes.
@ FIRST_UNDEFINED_OP_VALUE
prevector< 28, uint8_t > CScriptBase
We use a prevector for the script to reduce the considerable memory overhead of vectors in cases wher...
static const int MAX_STACK_SIZE
static const int MAX_OPS_PER_SCRIPT
bool CheckMinimalPush(const std::vector< uint8_t > &data, opcodetype opcode)
Check whether the given stack element data would be minimally pushed using the given opcode.
static const int MAX_PUBKEYS_PER_MULTISIG
std::vector< uint8_t > ToByteVector(const T &in)
bool GetScriptOp(CScriptBase::const_iterator &pc, CScriptBase::const_iterator end, opcodetype &opcodeRet, std::vector< uint8_t > *pvchRet)
#define READWRITEAS(type, obj)