 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
6 #ifndef BITCOIN_SCRIPT_SCRIPT_H
7 #define BITCOIN_SCRIPT_SCRIPT_H
22 typedef std::vector<unsigned char>
valtype;
24 static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520;
25 static const int MAX_SCRIPT_SIZE = 10000;
29 static const unsigned int LOCKTIME_THRESHOLD = 500000000;
34 return std::vector<unsigned char>(in.begin(), in.end());
209 explicit CScriptNum(
const std::vector<unsigned char>& vch,
bool fRequireMinimal,
212 if (vch.size() > nMaxNumSize) {
215 if (fRequireMinimal && vch.size() > 0) {
222 if ((vch.back() & 0x7f) == 0) {
228 if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
260 assert(
m_value != std::numeric_limits<int64_t>::min());
272 assert(rhs == 0 || (rhs > 0 &&
m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
273 (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
280 assert(rhs == 0 || (rhs > 0 &&
m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
281 (rhs < 0 &&
m_value <= std::numeric_limits<int64_t>::max() + rhs));
288 if (
m_value > std::numeric_limits<int>::max())
289 return std::numeric_limits<int>::max();
290 else if (
m_value < std::numeric_limits<int>::min())
291 return std::numeric_limits<int>::min();
295 std::vector<unsigned char>
getvch()
const
300 static std::vector<unsigned char>
serialize(
const int64_t& value)
303 return std::vector<unsigned char>();
305 std::vector<unsigned char> result;
306 const bool neg = value < 0;
307 uint64_t absvalue = neg ? -value : value;
311 result.push_back(absvalue & 0xff);
325 if (result.back() & 0x80)
326 result.push_back(neg ? 0x80 : 0);
328 result.back() |= 0x80;
334 static int64_t
set_vch(
const std::vector<unsigned char>& vch)
340 for (
size_t i = 0; i != vch.size(); ++i)
341 result |=
static_cast<int64_t
>(vch[i]) << 8*i;
345 if (vch.back() & 0x80)
346 return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
368 if (n == -1 || (n >= 1 && n <= 16))
385 CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) :
CScriptBase(pbegin, pend) { }
412 if (opcode < 0 || opcode > 0xff)
413 throw std::runtime_error(
"CScript::operator<<() : invalid opcode");
430 else if (
b.size() <= 0xff)
435 else if (
b.size() <= 0xffff)
439 WriteLE16(
data,
b.size());
446 WriteLE32(
data,
b.size());
457 assert(!
"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
463 std::vector<unsigned char> vchKey =
key.Raw();
464 return (*
this) << vchKey;
472 bool fRet =
GetOp2(pc2, opcodeRet, &vchRet);
480 bool fRet =
GetOp2(pc2, opcodeRet, NULL);
487 return GetOp2(pc, opcodeRet, &vchRet);
492 return GetOp2(pc, opcodeRet, NULL);
506 unsigned int opcode = *pc++;
511 unsigned int nSize = 0;
526 nSize = ReadLE16(&pc[0]);
533 nSize = ReadLE32(&pc[0]);
536 if (
end() - pc < 0 || (
unsigned int)(
end() - pc) < nSize)
539 pvchRet->assign(pc, pc + nSize);
552 assert(opcode >=
OP_1 && opcode <=
OP_16);
553 return (
int)opcode - (int)(
OP_1 - 1);
557 assert(n >= 0 && n <= 16);
575 while (
static_cast<size_t>(
end() - pc) >=
b.size() && std::equal(
b.begin(),
b.end(), pc))
582 while (
GetOp(pc, opcode));
642 #endif // BITCOIN_SCRIPT_SCRIPT_H
CScriptNum operator-() const
scriptnum_error(const std::string &str)
CScript & operator<<(const CPubKey &key)
CScript(const_iterator pbegin, const_iterator pend)
bool operator<=(const int64_t &rhs) const
iterator insert(iterator pos, const T &value)
bool IsNormalPaymentScript() const
bool operator!=(const CScriptNum &rhs) const
std::vector< unsigned char > valtype
CScript & operator<<(const std::vector< unsigned char > &b)
bool GetOp2(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet) const
static const size_t nDefaultMaxNumSize
CScriptNum(const int64_t &n)
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
std::vector< unsigned char > ToByteVector(const T &in)
CScript(const unsigned char *pbegin, const unsigned char *pend)
static opcodetype EncodeOP_N(int n)
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
friend CScript operator+(const CScript &a, const CScript &b)
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)
bool IsPayToScriptHash() const
CScriptNum & operator-=(const int64_t &rhs)
static int64_t set_vch(const std::vector< unsigned char > &vch)
bool operator==(const CScriptNum &rhs) const
CScriptNum operator+(const int64_t &rhs) const
void push_back(const T &value)
CScript(const std::vector< unsigned char > &b)
int Find(opcodetype op) const
bool operator!=(const int64_t &rhs) const
CScriptNum & operator=(const int64_t &rhs)
CScriptNum operator+(const CScriptNum &rhs) const
bool operator>=(const CScriptNum &rhs) const
bool operator>=(const int64_t &rhs) const
bool GetOp(iterator &pc, opcodetype &opcodeRet)
CScriptNum & operator+=(const CScriptNum &rhs)
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
prevector< 28, unsigned char > CScriptBase
We use a prevector for the script to reduce the considerable memory overhead of vectors in cases wher...
CScriptNum & operator+=(const int64_t &rhs)
CScript & operator<<(opcodetype opcode)
Serialized script, used inside transaction inputs and outputs.
CScriptNum & operator-=(const CScriptNum &rhs)
std::vector< unsigned char > getvch() const
static std::vector< unsigned char > serialize(const int64_t &value)
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
CScript & operator+=(const CScript &b)
An encapsulated public key.
CScript & operator<<(const CScript &b)
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
CScript & operator<<(int64_t b)
int FindAndDelete(const CScript &b)
std::string ToString() const
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
CScript & operator<<(const CScriptNum &b)
CScriptNum operator-(const CScriptNum &rhs) const
CScript(std::vector< unsigned char >::const_iterator pbegin, std::vector< unsigned char >::const_iterator pend)
CScriptNum operator-(const int64_t &rhs) const
bool operator>(const int64_t &rhs) const
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
const char * GetOpName(opcodetype opcode)
CScript & push_int64(int64_t n)
bool operator<=(const CScriptNum &rhs) const
CScript(const CScriptNum &b)
opcodetype
Script opcodes.
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const