6 #ifndef BITCOIN_SCRIPT_SCRIPT_H 7 #define BITCOIN_SCRIPT_SCRIPT_H 37 return std::vector<unsigned char>(in.begin(), in.end());
214 explicit CScriptNum(
const std::vector<unsigned char>& vch,
bool fRequireMinimal,
217 if (vch.size() > nMaxNumSize) {
220 if (fRequireMinimal && vch.size() > 0) {
227 if ((vch.back() & 0x7f) == 0) {
233 if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
270 assert(
m_value != std::numeric_limits<int64_t>::min());
282 assert(rhs == 0 || (rhs > 0 &&
m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
283 (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
290 assert(rhs == 0 || (rhs > 0 &&
m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
291 (rhs < 0 &&
m_value <= std::numeric_limits<int64_t>::max() + rhs));
304 if (
m_value > std::numeric_limits<int>::max())
305 return std::numeric_limits<int>::max();
306 else if (
m_value < std::numeric_limits<int>::min())
307 return std::numeric_limits<int>::min();
311 std::vector<unsigned char>
getvch()
const 316 static std::vector<unsigned char>
serialize(
const int64_t& value)
319 return std::vector<unsigned char>();
321 std::vector<unsigned char>
result;
322 const bool neg = value < 0;
323 uint64_t absvalue = neg ? -value : value;
327 result.push_back(absvalue & 0xff);
342 result.push_back(neg ? 0x80 : 0);
350 static int64_t
set_vch(
const std::vector<unsigned char>& vch)
356 for (
size_t i = 0; i != vch.size(); ++i)
357 result |= static_cast<int64_t>(vch[i]) << 8*i;
361 if (vch.back() & 0x80)
362 return -((int64_t)(
result & ~(0x80ULL << (8 * (vch.size() - 1)))));
378 if (
n == -1 || (
n >= 1 &&
n <= 16))
396 CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) :
CScriptBase(pbegin, pend) { }
423 if (opcode < 0 || opcode > 0xff)
424 throw std::runtime_error(
"CScript::operator<<(): invalid opcode");
435 CScript& operator<<(const std::vector<unsigned char>& b)
441 else if (b.size() <= 0xff)
446 else if (b.size() <= 0xffff)
468 assert(!
"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
477 bool fRet =
GetOp2(pc2, opcodeRet, &vchRet);
485 bool fRet =
GetOp2(pc2, opcodeRet, NULL);
492 return GetOp2(pc, opcodeRet, &vchRet);
497 return GetOp2(pc, opcodeRet, NULL);
511 unsigned int opcode = *pc++;
516 unsigned int nSize = 0;
541 if (
end() - pc < 0 || (
unsigned int)(
end() - pc) < nSize)
544 pvchRet->assign(pc, pc + nSize);
557 assert(opcode >=
OP_1 && opcode <=
OP_16);
558 return (
int)opcode - (int)(
OP_1 - 1);
562 assert(
n >= 0 &&
n <= 16);
579 while (static_cast<size_t>(
end() - pc) >= b.
size() && std::equal(b.
begin(), b.
end(), pc))
586 while (
GetOp(pc, opcode));
655 #endif // BITCOIN_SCRIPT_SCRIPT_H
unsigned int GetSigOpCount(bool fAccurate) const
CScriptNum operator-(const CScriptNum &rhs) const
static const int MAX_PUBKEYS_PER_MULTISIG
CScript(const unsigned char *pbegin, const unsigned char *pend)
int Find(opcodetype op) const
bool IsPayToPublicKeyHash() const
iterator insert(iterator pos, const T &value)
static void WriteLE16(unsigned char *ptr, uint16_t x)
bool operator>(const int64_t &rhs) const
static std::vector< unsigned char > serialize(const int64_t &value)
static void WriteLE32(unsigned char *ptr, uint32_t x)
CScriptNum operator+(const int64_t &rhs) const
bool operator!=(const int64_t &rhs) const
bool operator==(const int64_t &rhs) const
CScriptNum(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
CScript & operator<<(const CScriptNum &b)
CScript & operator<<(int64_t b)
bool operator!=(const CScriptNum &rhs) const
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
std::vector< unsigned char > getvch() const
int FindAndDelete(const CScript &b)
static uint16_t ReadLE16(const unsigned char *ptr)
CScript(const_iterator pbegin, const_iterator pend)
bool GetOp(iterator &pc, opcodetype &opcodeRet)
static const int MAX_OPS_PER_SCRIPT
const char * GetOpName(opcodetype opcode)
virtual void KeepScript()
CScriptNum operator &(const int64_t &rhs) const
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
CScriptNum & operator=(const int64_t &rhs)
CScriptNum & operator-=(const CScriptNum &rhs)
bool IsUnspendable() const
bool GetOp2(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet) const
virtual ~CReserveScript()
void push_back(const T &value)
friend CScript operator+(const CScript &a, const CScript &b)
bool operator==(const CScriptNum &rhs) const
bool operator>=(const CScriptNum &rhs) const
CScriptNum & operator &=(const CScriptNum &rhs)
prevector< 28, unsigned char > CScriptBase
bool operator<(const int64_t &rhs) const
bool operator<=(const CScriptNum &rhs) const
bool IsNormalPaymentScript() const
scriptnum_error(const std::string &str)
bool IsPayToScriptHash() const
CScript & operator<<(const CScript &b)
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
static uint32_t ReadLE32(const unsigned char *ptr)
CScript & operator<<(opcodetype opcode)
CScriptNum operator+(const CScriptNum &rhs) const
CScriptNum(const int64_t &n)
CScriptNum operator-(const int64_t &rhs) const
bool operator<=(const int64_t &rhs) const
CScriptNum & operator+=(const CScriptNum &rhs)
CScript & operator+=(const CScript &b)
CScriptNum operator-() const
CScript(const CScriptNum &b)
CScriptNum & operator+=(const int64_t &rhs)
bool operator>=(const int64_t &rhs) const
CScript & push_int64(int64_t n)
static const unsigned int LOCKTIME_THRESHOLD
CScript(std::vector< unsigned char >::const_iterator pbegin, std::vector< unsigned char >::const_iterator pend)
CScript(const CScript &b)
CScript(const std::vector< unsigned char > &b)
static int DecodeOP_N(opcodetype opcode)
CScriptNum & operator-=(const int64_t &rhs)
static opcodetype EncodeOP_N(int n)
static const size_t nDefaultMaxNumSize
static int64_t set_vch(const std::vector< unsigned char > &vch)
std::vector< unsigned char > ToByteVector(const T &in)
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const