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