Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

script.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_SCRIPT_SCRIPT_H
7 #define BITCOIN_SCRIPT_SCRIPT_H
8 
9 #include <crypto/common.h>
10 #include <prevector.h>
11 #include <serialize.h>
12 
13 #include <assert.h>
14 #include <climits>
15 #include <limits>
16 #include <stdexcept>
17 #include <stdint.h>
18 #include <string.h>
19 #include <string>
20 #include <vector>
21 
22 // Maximum number of bytes pushable to the stack
23 static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520;
24 
25 // Maximum number of non-push operations per script
26 static const int MAX_OPS_PER_SCRIPT = 201;
27 
28 // Maximum number of public keys per multisig
29 static const int MAX_PUBKEYS_PER_MULTISIG = 20;
30 
31 // Maximum script length in bytes
32 static const int MAX_SCRIPT_SIZE = 10000;
33 
34 // Maximum number of values on script interpreter stack
35 static const int MAX_STACK_SIZE = 1000;
36 
37 // Threshold for nLockTime: below this value it is interpreted as block number,
38 // otherwise as UNIX timestamp.
39 static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
40 
41 template <typename T>
42 std::vector<unsigned char> ToByteVector(const T& in)
43 {
44  return std::vector<unsigned char>(in.begin(), in.end());
45 }
46 
49 {
50  // push value
51  OP_0 = 0x00,
53  OP_PUSHDATA1 = 0x4c,
54  OP_PUSHDATA2 = 0x4d,
55  OP_PUSHDATA4 = 0x4e,
56  OP_1NEGATE = 0x4f,
57  OP_RESERVED = 0x50,
58  OP_1 = 0x51,
60  OP_2 = 0x52,
61  OP_3 = 0x53,
62  OP_4 = 0x54,
63  OP_5 = 0x55,
64  OP_6 = 0x56,
65  OP_7 = 0x57,
66  OP_8 = 0x58,
67  OP_9 = 0x59,
68  OP_10 = 0x5a,
69  OP_11 = 0x5b,
70  OP_12 = 0x5c,
71  OP_13 = 0x5d,
72  OP_14 = 0x5e,
73  OP_15 = 0x5f,
74  OP_16 = 0x60,
75 
76  // control
77  OP_NOP = 0x61,
78  OP_VER = 0x62,
79  OP_IF = 0x63,
80  OP_NOTIF = 0x64,
81  OP_VERIF = 0x65,
82  OP_VERNOTIF = 0x66,
83  OP_ELSE = 0x67,
84  OP_ENDIF = 0x68,
85  OP_VERIFY = 0x69,
86  OP_RETURN = 0x6a,
87 
88  // stack ops
89  OP_TOALTSTACK = 0x6b,
91  OP_2DROP = 0x6d,
92  OP_2DUP = 0x6e,
93  OP_3DUP = 0x6f,
94  OP_2OVER = 0x70,
95  OP_2ROT = 0x71,
96  OP_2SWAP = 0x72,
97  OP_IFDUP = 0x73,
98  OP_DEPTH = 0x74,
99  OP_DROP = 0x75,
100  OP_DUP = 0x76,
101  OP_NIP = 0x77,
102  OP_OVER = 0x78,
103  OP_PICK = 0x79,
104  OP_ROLL = 0x7a,
105  OP_ROT = 0x7b,
106  OP_SWAP = 0x7c,
107  OP_TUCK = 0x7d,
108 
109  // splice ops
110  OP_CAT = 0x7e,
111  OP_SUBSTR = 0x7f,
112  OP_LEFT = 0x80,
113  OP_RIGHT = 0x81,
114  OP_SIZE = 0x82,
115 
116  // bit logic
117  OP_INVERT = 0x83,
118  OP_AND = 0x84,
119  OP_OR = 0x85,
120  OP_XOR = 0x86,
121  OP_EQUAL = 0x87,
123  OP_RESERVED1 = 0x89,
124  OP_RESERVED2 = 0x8a,
125 
126  // numeric
127  OP_1ADD = 0x8b,
128  OP_1SUB = 0x8c,
129  OP_2MUL = 0x8d,
130  OP_2DIV = 0x8e,
131  OP_NEGATE = 0x8f,
132  OP_ABS = 0x90,
133  OP_NOT = 0x91,
134  OP_0NOTEQUAL = 0x92,
135 
136  OP_ADD = 0x93,
137  OP_SUB = 0x94,
138  OP_MUL = 0x95,
139  OP_DIV = 0x96,
140  OP_MOD = 0x97,
141  OP_LSHIFT = 0x98,
142  OP_RSHIFT = 0x99,
143 
144  OP_BOOLAND = 0x9a,
145  OP_BOOLOR = 0x9b,
146  OP_NUMEQUAL = 0x9c,
149  OP_LESSTHAN = 0x9f,
153  OP_MIN = 0xa3,
154  OP_MAX = 0xa4,
155 
156  OP_WITHIN = 0xa5,
157 
158  // crypto
159  OP_RIPEMD160 = 0xa6,
160  OP_SHA1 = 0xa7,
161  OP_SHA256 = 0xa8,
162  OP_HASH160 = 0xa9,
163  OP_HASH256 = 0xaa,
165  OP_CHECKSIG = 0xac,
169 
170  // expansion
171  OP_NOP1 = 0xb0,
176  OP_NOP4 = 0xb3,
177  OP_NOP5 = 0xb4,
178  OP_NOP6 = 0xb5,
179  OP_NOP7 = 0xb6,
180  OP_NOP8 = 0xb7,
181  OP_NOP9 = 0xb8,
182  OP_NOP10 = 0xb9,
183 
184 
185  // template matching params
187  OP_PUBKEYS = 0xfb,
189  OP_PUBKEY = 0xfe,
190 
192 };
193 
194 // Maximum value that an opcode can be
195 static const unsigned int MAX_OPCODE = OP_NOP10;
196 
197 const char* GetOpName(opcodetype opcode);
198 
199 class scriptnum_error : public std::runtime_error
200 {
201 public:
202  explicit scriptnum_error(const std::string& str) : std::runtime_error(str) {}
203 };
204 
206 {
215 public:
216 
217  explicit CScriptNum(const int64_t& n)
218  {
219  m_value = n;
220  }
221 
222  static const size_t nDefaultMaxNumSize = 4;
223 
224  explicit CScriptNum(const std::vector<unsigned char>& vch, bool fRequireMinimal,
225  const size_t nMaxNumSize = nDefaultMaxNumSize)
226  {
227  if (vch.size() > nMaxNumSize) {
228  throw scriptnum_error("script number overflow");
229  }
230  if (fRequireMinimal && vch.size() > 0) {
231  // Check that the number is encoded with the minimum possible
232  // number of bytes.
233  //
234  // If the most-significant-byte - excluding the sign bit - is zero
235  // then we're not minimal. Note how this test also rejects the
236  // negative-zero encoding, 0x80.
237  if ((vch.back() & 0x7f) == 0) {
238  // One exception: if there's more than one byte and the most
239  // significant bit of the second-most-significant-byte is set
240  // it would conflict with the sign bit. An example of this case
241  // is +-255, which encode to 0xff00 and 0xff80 respectively.
242  // (big-endian).
243  if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
244  throw scriptnum_error("non-minimally encoded script number");
245  }
246  }
247  }
248  m_value = set_vch(vch);
249  }
250 
251  inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
252  inline bool operator!=(const int64_t& rhs) const { return m_value != rhs; }
253  inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
254  inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
255  inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
256  inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
257 
258  inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
259  inline bool operator!=(const CScriptNum& rhs) const { return operator!=(rhs.m_value); }
260  inline bool operator<=(const CScriptNum& rhs) const { return operator<=(rhs.m_value); }
261  inline bool operator< (const CScriptNum& rhs) const { return operator< (rhs.m_value); }
262  inline bool operator>=(const CScriptNum& rhs) const { return operator>=(rhs.m_value); }
263  inline bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }
264 
265  inline CScriptNum operator+( const int64_t& rhs) const { return CScriptNum(m_value + rhs);}
266  inline CScriptNum operator-( const int64_t& rhs) const { return CScriptNum(m_value - rhs);}
267  inline CScriptNum operator+( const CScriptNum& rhs) const { return operator+(rhs.m_value); }
268  inline CScriptNum operator-( const CScriptNum& rhs) const { return operator-(rhs.m_value); }
269 
270  inline CScriptNum& operator+=( const CScriptNum& rhs) { return operator+=(rhs.m_value); }
271  inline CScriptNum& operator-=( const CScriptNum& rhs) { return operator-=(rhs.m_value); }
272 
273  inline CScriptNum operator&( const int64_t& rhs) const { return CScriptNum(m_value & rhs);}
274  inline CScriptNum operator&( const CScriptNum& rhs) const { return operator&(rhs.m_value); }
275 
276  inline CScriptNum& operator&=( const CScriptNum& rhs) { return operator&=(rhs.m_value); }
277 
278  inline CScriptNum operator-() const
279  {
280  assert(m_value != std::numeric_limits<int64_t>::min());
281  return CScriptNum(-m_value);
282  }
283 
284  inline CScriptNum& operator=( const int64_t& rhs)
285  {
286  m_value = rhs;
287  return *this;
288  }
289 
290  inline CScriptNum& operator+=( const int64_t& rhs)
291  {
292  assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
293  (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
294  m_value += rhs;
295  return *this;
296  }
297 
298  inline CScriptNum& operator-=( const int64_t& rhs)
299  {
300  assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
301  (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
302  m_value -= rhs;
303  return *this;
304  }
305 
306  inline CScriptNum& operator&=( const int64_t& rhs)
307  {
308  m_value &= rhs;
309  return *this;
310  }
311 
312  int getint() const
313  {
314  if (m_value > std::numeric_limits<int>::max())
315  return std::numeric_limits<int>::max();
316  else if (m_value < std::numeric_limits<int>::min())
317  return std::numeric_limits<int>::min();
318  return m_value;
319  }
320 
321  std::vector<unsigned char> getvch() const
322  {
323  return serialize(m_value);
324  }
325 
326  static std::vector<unsigned char> serialize(const int64_t& value)
327  {
328  if(value == 0)
329  return std::vector<unsigned char>();
330 
331  std::vector<unsigned char> result;
332  const bool neg = value < 0;
333  uint64_t absvalue = neg ? -value : value;
334 
335  while(absvalue)
336  {
337  result.push_back(absvalue & 0xff);
338  absvalue >>= 8;
339  }
340 
341 // - If the most significant byte is >= 0x80 and the value is positive, push a
342 // new zero-byte to make the significant byte < 0x80 again.
343 
344 // - If the most significant byte is >= 0x80 and the value is negative, push a
345 // new 0x80 byte that will be popped off when converting to an integral.
346 
347 // - If the most significant byte is < 0x80 and the value is negative, add
348 // 0x80 to it, since it will be subtracted and interpreted as a negative when
349 // converting to an integral.
350 
351  if (result.back() & 0x80)
352  result.push_back(neg ? 0x80 : 0);
353  else if (neg)
354  result.back() |= 0x80;
355 
356  return result;
357  }
358 
359 private:
360  static int64_t set_vch(const std::vector<unsigned char>& vch)
361  {
362  if (vch.empty())
363  return 0;
364 
365  int64_t result = 0;
366  for (size_t i = 0; i != vch.size(); ++i)
367  result |= static_cast<int64_t>(vch[i]) << 8*i;
368 
369  // If the input vector's most significant byte is 0x80, remove it from
370  // the result's msb and return a negative.
371  if (vch.back() & 0x80)
372  return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
373 
374  return result;
375  }
376 
377  int64_t m_value;
378 };
379 
387 
389 class CScript : public CScriptBase
390 {
391 protected:
392  CScript& push_int64(int64_t n)
393  {
394  if (n == -1 || (n >= 1 && n <= 16))
395  {
396  push_back(n + (OP_1 - 1));
397  }
398  else if (n == 0)
399  {
400  push_back(OP_0);
401  }
402  else
403  {
404  *this << CScriptNum::serialize(n);
405  }
406  return *this;
407  }
408 public:
409  CScript() { }
410  CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { }
411  CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
412  CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }
413 
415 
416  template <typename Stream, typename Operation>
417  inline void SerializationOp(Stream& s, Operation ser_action) {
418  READWRITE(static_cast<CScriptBase&>(*this));
419  }
420 
422  {
423  reserve(size() + b.size());
424  insert(end(), b.begin(), b.end());
425  return *this;
426  }
427 
428  friend CScript operator+(const CScript& a, const CScript& b)
429  {
430  CScript ret = a;
431  ret += b;
432  return ret;
433  }
434 
435  CScript(int64_t b) { operator<<(b); }
436 
437  explicit CScript(opcodetype b) { operator<<(b); }
438  explicit CScript(const CScriptNum& b) { operator<<(b); }
439  explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
440 
441 
442  CScript& operator<<(int64_t b) { return push_int64(b); }
443 
445  {
446  if (opcode < 0 || opcode > 0xff)
447  throw std::runtime_error("CScript::operator<<(): invalid opcode");
448  insert(end(), (unsigned char)opcode);
449  return *this;
450  }
451 
453  {
454  *this << b.getvch();
455  return *this;
456  }
457 
458  CScript& operator<<(const std::vector<unsigned char>& b)
459  {
460  if (b.size() < OP_PUSHDATA1)
461  {
462  insert(end(), (unsigned char)b.size());
463  }
464  else if (b.size() <= 0xff)
465  {
466  insert(end(), OP_PUSHDATA1);
467  insert(end(), (unsigned char)b.size());
468  }
469  else if (b.size() <= 0xffff)
470  {
471  insert(end(), OP_PUSHDATA2);
472  uint8_t _data[2];
473  WriteLE16(_data, b.size());
474  insert(end(), _data, _data + sizeof(_data));
475  }
476  else
477  {
478  insert(end(), OP_PUSHDATA4);
479  uint8_t _data[4];
480  WriteLE32(_data, b.size());
481  insert(end(), _data, _data + sizeof(_data));
482  }
483  insert(end(), b.begin(), b.end());
484  return *this;
485  }
486 
488  {
489  // I'm not sure if this should push the script or concatenate scripts.
490  // If there's ever a use for pushing a script onto a script, delete this member fn
491  assert(!"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
492  return *this;
493  }
494 
495 
496  bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
497  {
498  // Wrapper so it can be called with either iterator or const_iterator
499  const_iterator pc2 = pc;
500  bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
501  pc = begin() + (pc2 - begin());
502  return fRet;
503  }
504 
505  bool GetOp(iterator& pc, opcodetype& opcodeRet)
506  {
507  const_iterator pc2 = pc;
508  bool fRet = GetOp2(pc2, opcodeRet, nullptr);
509  pc = begin() + (pc2 - begin());
510  return fRet;
511  }
512 
513  bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
514  {
515  return GetOp2(pc, opcodeRet, &vchRet);
516  }
517 
518  bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
519  {
520  return GetOp2(pc, opcodeRet, nullptr);
521  }
522 
523  bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) const
524  {
525  opcodeRet = OP_INVALIDOPCODE;
526  if (pvchRet)
527  pvchRet->clear();
528  if (pc >= end())
529  return false;
530 
531  // Read instruction
532  if (end() - pc < 1)
533  return false;
534  unsigned int opcode = *pc++;
535 
536  // Immediate operand
537  if (opcode <= OP_PUSHDATA4)
538  {
539  unsigned int nSize = 0;
540  if (opcode < OP_PUSHDATA1)
541  {
542  nSize = opcode;
543  }
544  else if (opcode == OP_PUSHDATA1)
545  {
546  if (end() - pc < 1)
547  return false;
548  nSize = *pc++;
549  }
550  else if (opcode == OP_PUSHDATA2)
551  {
552  if (end() - pc < 2)
553  return false;
554  nSize = ReadLE16(&pc[0]);
555  pc += 2;
556  }
557  else if (opcode == OP_PUSHDATA4)
558  {
559  if (end() - pc < 4)
560  return false;
561  nSize = ReadLE32(&pc[0]);
562  pc += 4;
563  }
564  if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize)
565  return false;
566  if (pvchRet)
567  assign_to(pc, pc + nSize, *pvchRet);
568  pc += nSize;
569  }
570 
571  opcodeRet = (opcodetype)opcode;
572  return true;
573  }
574 
576  static int DecodeOP_N(opcodetype opcode)
577  {
578  if (opcode == OP_0)
579  return 0;
580  assert(opcode >= OP_1 && opcode <= OP_16);
581  return (int)opcode - (int)(OP_1 - 1);
582  }
583  static opcodetype EncodeOP_N(int n)
584  {
585  assert(n >= 0 && n <= 16);
586  if (n == 0)
587  return OP_0;
588  return (opcodetype)(OP_1+n-1);
589  }
590 
591  int FindAndDelete(const CScript& b)
592  {
593  int nFound = 0;
594  if (b.empty())
595  return nFound;
596  CScript result;
597  iterator pc = begin(), pc2 = begin();
598  opcodetype opcode;
599  do
600  {
601  result.insert(result.end(), pc2, pc);
602  while (static_cast<size_t>(end() - pc) >= b.size() && std::equal(b.begin(), b.end(), pc))
603  {
604  pc = pc + b.size();
605  ++nFound;
606  }
607  pc2 = pc;
608  }
609  while (GetOp(pc, opcode));
610 
611  if (nFound > 0) {
612  result.insert(result.end(), pc2, end());
613  *this = result;
614  }
615 
616  return nFound;
617  }
618  int Find(opcodetype op) const
619  {
620  int nFound = 0;
621  opcodetype opcode;
622  for (const_iterator pc = begin(); pc != end() && GetOp(pc, opcode);)
623  if (opcode == op)
624  ++nFound;
625  return nFound;
626  }
627 
635  unsigned int GetSigOpCount(bool fAccurate) const;
636 
641  unsigned int GetSigOpCount(const CScript& scriptSig) const;
642 
643  bool IsPayToPublicKeyHash() const;
644 
645  bool IsPayToScriptHash() const;
646 
648  bool IsPayToPublicKey() const;
649 
651  bool IsPushOnly(const_iterator pc) const;
652  bool IsPushOnly() const;
653 
659  bool IsUnspendable() const
660  {
661  return (size() > 0 && *begin() == OP_RETURN) || (size() > MAX_SCRIPT_SIZE);
662  }
663 
664  void clear()
665  {
666  // The default prevector::clear() does not release memory
668  shrink_to_fit();
669  }
670 };
671 
673 {
674 public:
676  virtual void KeepScript() {}
678  virtual ~CReserveScript() {}
679 };
680 
681 #endif // BITCOIN_SCRIPT_SCRIPT_H
Definition: script.h:133
Definition: script.h:62
Definition: script.h:118
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
Definition: script.cpp:153
static const int MAX_PUBKEYS_PER_MULTISIG
Definition: script.h:29
static int64_t set_vch(const std::vector< unsigned char > &vch)
Definition: script.h:360
ADD_SERIALIZE_METHODS
Definition: script.h:414
Definition: script.h:101
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
Definition: script.h:576
int getint() const
Definition: script.h:312
Definition: script.h:154
void shrink_to_fit()
Definition: prevector.h:367
Definition: script.h:93
#define READWRITE(obj)
Definition: serialize.h:165
iterator insert(iterator pos, const T &value)
Definition: prevector.h:375
static const unsigned int MAX_OPCODE
Definition: script.h:195
void clear()
Definition: prevector.h:371
static void WriteLE16(unsigned char *ptr, uint16_t x)
Definition: common.h:38
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
Definition: script.h:513
bool operator<(const int64_t &rhs) const
Definition: script.h:254
virtual ~CReserveScript()
Definition: script.h:678
CScriptNum(const int64_t &n)
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
Definition: script.h:217
bool IsPayToScriptHash() const
Definition: script.cpp:212
Definition: script.h:79
Definition: script.h:72
Definition: script.h:68
Definition: script.h:95
CScriptNum & operator-=(const int64_t &rhs)
Definition: script.h:298
Definition: script.h:132
Definition: script.h:60
Definition: script.h:139
Definition: script.h:66
static void WriteLE32(unsigned char *ptr, uint32_t x)
Definition: common.h:44
CScriptNum operator &(const int64_t &rhs) const
Definition: script.h:273
Definition: script.h:61
bool IsPushOnly() const
Definition: script.cpp:253
CScript & push_int64(int64_t n)
Definition: script.h:392
Definition: box.hpp:161
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
Definition: script.h:23
Definition: script.h:153
friend CScript operator+(const CScript &a, const CScript &b)
Definition: script.h:428
bool operator<=(const int64_t &rhs) const
Definition: script.h:253
CScriptNum & operator=(const int64_t &rhs)
Definition: script.h:284
static uint16_t ReadLE16(const unsigned char *ptr)
Definition: common.h:17
CScript(const std::vector< unsigned char > &b)
Definition: script.h:439
Definition: script.h:74
static std::vector< unsigned char > serialize(const int64_t &value)
Definition: script.h:326
Definition: script.h:70
static const int MAX_OPS_PER_SCRIPT
Definition: script.h:26
const char * GetOpName(opcodetype opcode)
Definition: script.cpp:10
CScript(opcodetype b)
Definition: script.h:437
Definition: script.h:119
CScriptNum & operator+=(const CScriptNum &rhs)
Definition: script.h:270
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack...
Definition: script.h:659
CScript & operator<<(const CScriptNum &b)
Definition: script.h:452
Definition: script.h:63
iterator end()
Definition: prevector.h:320
CScript & operator<<(opcodetype opcode)
Definition: script.h:444
CScript reserveScript
Definition: script.h:675
bool IsPayToPublicKey() const
Used for obsolete pay-to-pubkey addresses indexing.
Definition: script.cpp:221
Definition: script.h:140
void push_back(const T &value)
Definition: prevector.h:455
opcodetype
Script opcodes.
Definition: script.h:48
CScript(const CScriptNum &b)
Definition: script.h:438
bool operator==(const CScriptNum &rhs) const
Definition: script.h:258
CScript & operator<<(const CScript &b)
Definition: script.h:487
Definition: script.h:110
CScriptNum operator+(const int64_t &rhs) const
Definition: script.h:265
static const size_t nDefaultMaxNumSize
Definition: script.h:222
bool operator!=(const int64_t &rhs) const
Definition: script.h:252
CScriptNum operator-() const
Definition: script.h:278
prevector< 28, unsigned char > CScriptBase
We use a prevector for the script to reduce the considerable memory overhead of vectors in cases wher...
Definition: script.h:386
CScript(int64_t b)
Definition: script.h:435
bool operator>=(const CScriptNum &rhs) const
Definition: script.h:262
CScriptNum operator+(const CScriptNum &rhs) const
Definition: script.h:267
Definition: script.h:65
CScript(const unsigned char *pbegin, const unsigned char *pend)
Definition: script.h:412
Definition: script.h:58
Definition: script.h:77
std::vector< unsigned char > getvch() const
Definition: script.h:321
int64_t m_value
Definition: script.h:377
scriptnum_error(const std::string &str)
Definition: script.h:202
CScriptNum(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
Definition: script.h:224
CScript()
Definition: script.h:409
Definition: script.h:137
bool GetOp(iterator &pc, opcodetype &opcodeRet)
Definition: script.h:505
bool operator>(const int64_t &rhs) const
Definition: script.h:256
static const int MAX_SCRIPT_SIZE
Definition: script.h:32
Definition: script.h:105
static const int MAX_STACK_SIZE
Definition: script.h:35
CScriptNum & operator &=(const CScriptNum &rhs)
Definition: script.h:276
Definition: script.h:138
Definition: script.h:83
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:39
static uint32_t ReadLE32(const unsigned char *ptr)
Definition: common.h:24
void reserve(size_type new_capacity)
Definition: prevector.h:361
CScriptNum & operator-=(const CScriptNum &rhs)
Definition: script.h:271
Definition: script.h:67
CScriptNum operator-(const CScriptNum &rhs) const
Definition: script.h:268
Definition: script.h:99
Definition: script.h:92
CScriptNum operator-(const int64_t &rhs) const
Definition: script.h:266
CScript(const_iterator pbegin, const_iterator pend)
Definition: script.h:410
static opcodetype EncodeOP_N(int n)
Definition: script.h:583
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
CScript & operator+=(const CScript &b)
Definition: script.h:421
bool empty() const
Definition: prevector.h:314
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
Definition: script.h:518
int FindAndDelete(const CScript &b)
Definition: script.h:591
Definition: script.h:64
CScript & operator<<(int64_t b)
Definition: script.h:442
virtual void KeepScript()
Definition: script.h:676
iterator begin()
Definition: prevector.h:318
CScriptNum & operator+=(const int64_t &rhs)
Definition: script.h:290
size_type size() const
Definition: prevector.h:310
static void assign_to(const_iterator b, const_iterator e, V &v)
Definition: prevector.h:560
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
Definition: script.h:496
Definition: script.h:71
static const unsigned int LOCKTIME_THRESHOLD
Definition: script.h:39
Definition: script.h:120
Definition: script.h:69
void SerializationOp(Stream &s, Operation ser_action)
Definition: script.h:417
Definition: script.h:78
int Find(opcodetype op) const
Definition: script.h:618
Definition: script.h:59
Definition: script.h:51
void clear()
Definition: script.h:664
bool IsPayToPublicKeyHash() const
Definition: script.cpp:201
CScript(std::vector< unsigned char >::const_iterator pbegin, std::vector< unsigned char >::const_iterator pend)
Definition: script.h:411
CReserveScript()
Definition: script.h:677
Definition: script.h:136
bool operator==(const int64_t &rhs) const
Definition: script.h:251
bool operator>=(const int64_t &rhs) const
Definition: script.h:255
Definition: script.h:73
Definition: script.h:100
bool operator!=(const CScriptNum &rhs) const
Definition: script.h:259
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:42
bool GetOp2(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet) const
Definition: script.h:523
bool operator<=(const CScriptNum &rhs) const
Definition: script.h:260
Released under the MIT license