Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
script.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef H_BITCOIN_SCRIPT
6 #define H_BITCOIN_SCRIPT
7 
8 #include <string>
9 #include <vector>
10 
11 #include <boost/foreach.hpp>
12 #include <boost/variant.hpp>
13 
14 #include "keystore.h"
15 #include "bignum.h"
16 
17 class CCoins;
18 class CTransaction;
19 
20 static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
21 
23 enum
24 {
29 };
30 
32 enum
33 {
35  SCRIPT_VERIFY_P2SH = (1U << 0),
37  SCRIPT_VERIFY_NOCACHE = (1U << 2),
38 };
39 
41 {
43  // 'standard' transaction types:
48 };
49 
51 public:
52  friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
53  friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
54 };
55 
62 typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
63 
64 const char* GetTxnOutputType(txnouttype t);
65 
68 {
69  // push value
70  OP_0 = 0x00,
72  OP_PUSHDATA1 = 0x4c,
73  OP_PUSHDATA2 = 0x4d,
74  OP_PUSHDATA4 = 0x4e,
75  OP_1NEGATE = 0x4f,
76  OP_RESERVED = 0x50,
77  OP_1 = 0x51,
79  OP_2 = 0x52,
80  OP_3 = 0x53,
81  OP_4 = 0x54,
82  OP_5 = 0x55,
83  OP_6 = 0x56,
84  OP_7 = 0x57,
85  OP_8 = 0x58,
86  OP_9 = 0x59,
87  OP_10 = 0x5a,
88  OP_11 = 0x5b,
89  OP_12 = 0x5c,
90  OP_13 = 0x5d,
91  OP_14 = 0x5e,
92  OP_15 = 0x5f,
93  OP_16 = 0x60,
94 
95  // control
96  OP_NOP = 0x61,
97  OP_VER = 0x62,
98  OP_IF = 0x63,
99  OP_NOTIF = 0x64,
100  OP_VERIF = 0x65,
101  OP_VERNOTIF = 0x66,
102  OP_ELSE = 0x67,
103  OP_ENDIF = 0x68,
104  OP_VERIFY = 0x69,
105  OP_RETURN = 0x6a,
106 
107  // stack ops
110  OP_2DROP = 0x6d,
111  OP_2DUP = 0x6e,
112  OP_3DUP = 0x6f,
113  OP_2OVER = 0x70,
114  OP_2ROT = 0x71,
115  OP_2SWAP = 0x72,
116  OP_IFDUP = 0x73,
117  OP_DEPTH = 0x74,
118  OP_DROP = 0x75,
119  OP_DUP = 0x76,
120  OP_NIP = 0x77,
121  OP_OVER = 0x78,
122  OP_PICK = 0x79,
123  OP_ROLL = 0x7a,
124  OP_ROT = 0x7b,
125  OP_SWAP = 0x7c,
126  OP_TUCK = 0x7d,
127 
128  // splice ops
129  OP_CAT = 0x7e,
130  OP_SUBSTR = 0x7f,
131  OP_LEFT = 0x80,
132  OP_RIGHT = 0x81,
133  OP_SIZE = 0x82,
134 
135  // bit logic
136  OP_INVERT = 0x83,
137  OP_AND = 0x84,
138  OP_OR = 0x85,
139  OP_XOR = 0x86,
140  OP_EQUAL = 0x87,
142  OP_RESERVED1 = 0x89,
143  OP_RESERVED2 = 0x8a,
144 
145  // numeric
146  OP_1ADD = 0x8b,
147  OP_1SUB = 0x8c,
148  OP_2MUL = 0x8d,
149  OP_2DIV = 0x8e,
150  OP_NEGATE = 0x8f,
151  OP_ABS = 0x90,
152  OP_NOT = 0x91,
153  OP_0NOTEQUAL = 0x92,
154 
155  OP_ADD = 0x93,
156  OP_SUB = 0x94,
157  OP_MUL = 0x95,
158  OP_DIV = 0x96,
159  OP_MOD = 0x97,
160  OP_LSHIFT = 0x98,
161  OP_RSHIFT = 0x99,
162 
163  OP_BOOLAND = 0x9a,
164  OP_BOOLOR = 0x9b,
165  OP_NUMEQUAL = 0x9c,
168  OP_LESSTHAN = 0x9f,
172  OP_MIN = 0xa3,
173  OP_MAX = 0xa4,
174 
175  OP_WITHIN = 0xa5,
176 
177  // crypto
178  OP_RIPEMD160 = 0xa6,
179  OP_SHA1 = 0xa7,
180  OP_SHA256 = 0xa8,
181  OP_HASH160 = 0xa9,
182  OP_HASH256 = 0xaa,
184  OP_CHECKSIG = 0xac,
188 
189  // expansion
190  OP_NOP1 = 0xb0,
191  OP_NOP2 = 0xb1,
192  OP_NOP3 = 0xb2,
193  OP_NOP4 = 0xb3,
194  OP_NOP5 = 0xb4,
195  OP_NOP6 = 0xb5,
196  OP_NOP7 = 0xb6,
197  OP_NOP8 = 0xb7,
198  OP_NOP9 = 0xb8,
199  OP_NOP10 = 0xb9,
200 
201 
202 
203  // template matching params
205  OP_PUBKEYS = 0xfb,
207  OP_PUBKEY = 0xfe,
208 
210 };
211 
212 const char* GetOpName(opcodetype opcode);
213 
214 
215 
216 inline std::string ValueString(const std::vector<unsigned char>& vch)
217 {
218  if (vch.size() <= 4)
219  return strprintf("%d", CBigNum(vch).getint());
220  else
221  return HexStr(vch);
222 }
223 
224 inline std::string StackString(const std::vector<std::vector<unsigned char> >& vStack)
225 {
226  std::string str;
227  BOOST_FOREACH(const std::vector<unsigned char>& vch, vStack)
228  {
229  if (!str.empty())
230  str += " ";
231  str += ValueString(vch);
232  }
233  return str;
234 }
235 
236 
237 
238 
239 
240 
241 
242 
244 class CScript : public std::vector<unsigned char>
245 {
246 protected:
248  {
249  if (n == -1 || (n >= 1 && n <= 16))
250  {
251  push_back(n + (OP_1 - 1));
252  }
253  else
254  {
255  CBigNum bn(n);
256  *this << bn.getvch();
257  }
258  return *this;
259  }
260 
262  {
263  if (n >= 1 && n <= 16)
264  {
265  push_back(n + (OP_1 - 1));
266  }
267  else
268  {
269  CBigNum bn(n);
270  *this << bn.getvch();
271  }
272  return *this;
273  }
274 
275 public:
276  CScript() { }
277  CScript(const CScript& b) : std::vector<unsigned char>(b.begin(), b.end()) { }
278  CScript(const_iterator pbegin, const_iterator pend) : std::vector<unsigned char>(pbegin, pend) { }
279 #ifndef _MSC_VER
280  CScript(const unsigned char* pbegin, const unsigned char* pend) : std::vector<unsigned char>(pbegin, pend) { }
281 #endif
282 
284  {
285  insert(end(), b.begin(), b.end());
286  return *this;
287  }
288 
289  friend CScript operator+(const CScript& a, const CScript& b)
290  {
291  CScript ret = a;
292  ret += b;
293  return ret;
294  }
295 
296 
297  //explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'.
298  explicit CScript(signed char b) { operator<<(b); }
299  explicit CScript(short b) { operator<<(b); }
300  explicit CScript(int b) { operator<<(b); }
301  explicit CScript(long b) { operator<<(b); }
302  explicit CScript(int64 b) { operator<<(b); }
303  explicit CScript(unsigned char b) { operator<<(b); }
304  explicit CScript(unsigned int b) { operator<<(b); }
305  explicit CScript(unsigned short b) { operator<<(b); }
306  explicit CScript(unsigned long b) { operator<<(b); }
307  explicit CScript(uint64 b) { operator<<(b); }
308 
309  explicit CScript(opcodetype b) { operator<<(b); }
310  explicit CScript(const uint256& b) { operator<<(b); }
311  explicit CScript(const CBigNum& b) { operator<<(b); }
312  explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
313 
314 
315  //CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'.
316  CScript& operator<<(signed char b) { return push_int64(b); }
317  CScript& operator<<(short b) { return push_int64(b); }
318  CScript& operator<<(int b) { return push_int64(b); }
319  CScript& operator<<(long b) { return push_int64(b); }
320  CScript& operator<<(int64 b) { return push_int64(b); }
321  CScript& operator<<(unsigned char b) { return push_uint64(b); }
322  CScript& operator<<(unsigned int b) { return push_uint64(b); }
323  CScript& operator<<(unsigned short b) { return push_uint64(b); }
324  CScript& operator<<(unsigned long b) { return push_uint64(b); }
326 
328  {
329  if (opcode < 0 || opcode > 0xff)
330  throw std::runtime_error("CScript::operator<<() : invalid opcode");
331  insert(end(), (unsigned char)opcode);
332  return *this;
333  }
334 
336  {
337  insert(end(), sizeof(b));
338  insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
339  return *this;
340  }
341 
343  {
344  insert(end(), sizeof(b));
345  insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
346  return *this;
347  }
348 
350  {
351  assert(key.size() < OP_PUSHDATA1);
352  insert(end(), (unsigned char)key.size());
353  insert(end(), key.begin(), key.end());
354  return *this;
355  }
356 
358  {
359  *this << b.getvch();
360  return *this;
361  }
362 
363  CScript& operator<<(const std::vector<unsigned char>& b)
364  {
365  if (b.size() < OP_PUSHDATA1)
366  {
367  insert(end(), (unsigned char)b.size());
368  }
369  else if (b.size() <= 0xff)
370  {
371  insert(end(), OP_PUSHDATA1);
372  insert(end(), (unsigned char)b.size());
373  }
374  else if (b.size() <= 0xffff)
375  {
376  insert(end(), OP_PUSHDATA2);
377  unsigned short nSize = b.size();
378  insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
379  }
380  else
381  {
382  insert(end(), OP_PUSHDATA4);
383  unsigned int nSize = b.size();
384  insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
385  }
386  insert(end(), b.begin(), b.end());
387  return *this;
388  }
389 
391  {
392  // I'm not sure if this should push the script or concatenate scripts.
393  // If there's ever a use for pushing a script onto a script, delete this member fn
394  assert(!"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
395  return *this;
396  }
397 
398 
399  bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
400  {
401  // Wrapper so it can be called with either iterator or const_iterator
402  const_iterator pc2 = pc;
403  bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
404  pc = begin() + (pc2 - begin());
405  return fRet;
406  }
407 
408  bool GetOp(iterator& pc, opcodetype& opcodeRet)
409  {
410  const_iterator pc2 = pc;
411  bool fRet = GetOp2(pc2, opcodeRet, NULL);
412  pc = begin() + (pc2 - begin());
413  return fRet;
414  }
415 
416  bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
417  {
418  return GetOp2(pc, opcodeRet, &vchRet);
419  }
420 
421  bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
422  {
423  return GetOp2(pc, opcodeRet, NULL);
424  }
425 
426  bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) const
427  {
428  opcodeRet = OP_INVALIDOPCODE;
429  if (pvchRet)
430  pvchRet->clear();
431  if (pc >= end())
432  return false;
433 
434  // Read instruction
435  if (end() - pc < 1)
436  return false;
437  unsigned int opcode = *pc++;
438 
439  // Immediate operand
440  if (opcode <= OP_PUSHDATA4)
441  {
442  unsigned int nSize = 0;
443  if (opcode < OP_PUSHDATA1)
444  {
445  nSize = opcode;
446  }
447  else if (opcode == OP_PUSHDATA1)
448  {
449  if (end() - pc < 1)
450  return false;
451  nSize = *pc++;
452  }
453  else if (opcode == OP_PUSHDATA2)
454  {
455  if (end() - pc < 2)
456  return false;
457  nSize = 0;
458  memcpy(&nSize, &pc[0], 2);
459  pc += 2;
460  }
461  else if (opcode == OP_PUSHDATA4)
462  {
463  if (end() - pc < 4)
464  return false;
465  memcpy(&nSize, &pc[0], 4);
466  pc += 4;
467  }
468  if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize)
469  return false;
470  if (pvchRet)
471  pvchRet->assign(pc, pc + nSize);
472  pc += nSize;
473  }
474 
475  opcodeRet = (opcodetype)opcode;
476  return true;
477  }
478 
479  // Encode/decode small integers:
480  static int DecodeOP_N(opcodetype opcode)
481  {
482  if (opcode == OP_0)
483  return 0;
484  assert(opcode >= OP_1 && opcode <= OP_16);
485  return (int)opcode - (int)(OP_1 - 1);
486  }
487  static opcodetype EncodeOP_N(int n)
488  {
489  assert(n >= 0 && n <= 16);
490  if (n == 0)
491  return OP_0;
492  return (opcodetype)(OP_1+n-1);
493  }
494 
495  int FindAndDelete(const CScript& b)
496  {
497  int nFound = 0;
498  if (b.empty())
499  return nFound;
500  iterator pc = begin();
501  opcodetype opcode;
502  do
503  {
504  while (end() - pc >= (long)b.size() && memcmp(&pc[0], &b[0], b.size()) == 0)
505  {
506  erase(pc, pc + b.size());
507  ++nFound;
508  }
509  }
510  while (GetOp(pc, opcode));
511  return nFound;
512  }
513  int Find(opcodetype op) const
514  {
515  int nFound = 0;
516  opcodetype opcode;
517  for (const_iterator pc = begin(); pc != end() && GetOp(pc, opcode);)
518  if (opcode == op)
519  ++nFound;
520  return nFound;
521  }
522 
523  // Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs
524  // as 20 sigops. With pay-to-script-hash, that changed:
525  // CHECKMULTISIGs serialized in scriptSigs are
526  // counted more accurately, assuming they are of the form
527  // ... OP_N CHECKMULTISIG ...
528  unsigned int GetSigOpCount(bool fAccurate) const;
529 
530  // Accurately count sigOps, including sigOps in
531  // pay-to-script-hash transactions:
532  unsigned int GetSigOpCount(const CScript& scriptSig) const;
533 
534  bool IsPayToScriptHash() const;
535 
536  // Called by CTransaction::IsStandard
537  bool IsPushOnly() const
538  {
539  const_iterator pc = begin();
540  while (pc < end())
541  {
542  opcodetype opcode;
543  if (!GetOp(pc, opcode))
544  return false;
545  if (opcode > OP_16)
546  return false;
547  }
548  return true;
549  }
550 
551 
552  void SetDestination(const CTxDestination& address);
553  void SetMultisig(int nRequired, const std::vector<CPubKey>& keys);
554 
555 
556  void PrintHex() const
557  {
558  printf("CScript(%s)\n", HexStr(begin(), end(), true).c_str());
559  }
560 
561  std::string ToString() const
562  {
563  std::string str;
564  opcodetype opcode;
565  std::vector<unsigned char> vch;
566  const_iterator pc = begin();
567  while (pc < end())
568  {
569  if (!str.empty())
570  str += " ";
571  if (!GetOp(pc, opcode, vch))
572  {
573  str += "[error]";
574  return str;
575  }
576  if (0 <= opcode && opcode <= OP_PUSHDATA4)
577  str += ValueString(vch);
578  else
579  str += GetOpName(opcode);
580  }
581  return str;
582  }
583 
584  void print() const
585  {
586  printf("%s\n", ToString().c_str());
587  }
588 
589  CScriptID GetID() const
590  {
591  return CScriptID(Hash160(*this));
592  }
593 };
594 
607 {
608 private:
609  // make this static for now (there are only 6 special scripts defined)
610  // this can potentially be extended together with a new nVersion for
611  // transactions, in which case this value becomes dependent on nVersion
612  // and nHeight of the enclosing transaction.
613  static const unsigned int nSpecialScripts = 6;
614 
616 protected:
617  // These check for scripts for which a special case with a shorter encoding is defined.
618  // They are implemented separately from the CScript test, as these test for exact byte
619  // sequence correspondences, and are more strict. For example, IsToPubKey also verifies
620  // whether the public key is valid (as invalid ones cannot be represented in compressed
621  // form).
622  bool IsToKeyID(CKeyID &hash) const;
623  bool IsToScriptID(CScriptID &hash) const;
624  bool IsToPubKey(CPubKey &pubkey) const;
625 
626  bool Compress(std::vector<unsigned char> &out) const;
627  unsigned int GetSpecialSize(unsigned int nSize) const;
628  bool Decompress(unsigned int nSize, const std::vector<unsigned char> &out);
629 public:
630  CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }
631 
632  unsigned int GetSerializeSize(int nType, int nVersion) const {
633  std::vector<unsigned char> compr;
634  if (Compress(compr))
635  return compr.size();
636  unsigned int nSize = script.size() + nSpecialScripts;
637  return script.size() + VARINT(nSize).GetSerializeSize(nType, nVersion);
638  }
639 
640  template<typename Stream>
641  void Serialize(Stream &s, int nType, int nVersion) const {
642  std::vector<unsigned char> compr;
643  if (Compress(compr)) {
644  s << CFlatData(&compr[0], &compr[compr.size()]);
645  return;
646  }
647  unsigned int nSize = script.size() + nSpecialScripts;
648  s << VARINT(nSize);
649  s << CFlatData(&script[0], &script[script.size()]);
650  }
651 
652  template<typename Stream>
653  void Unserialize(Stream &s, int nType, int nVersion) {
654  unsigned int nSize = 0;
655  s >> VARINT(nSize);
656  if (nSize < nSpecialScripts) {
657  std::vector<unsigned char> vch(GetSpecialSize(nSize), 0x00);
658  s >> REF(CFlatData(&vch[0], &vch[vch.size()]));
659  Decompress(nSize, vch);
660  return;
661  }
662  nSize -= nSpecialScripts;
663  script.resize(nSize);
664  s >> REF(CFlatData(&script[0], &script[script.size()]));
665  }
666 };
667 
668 bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey);
669 bool IsCanonicalSignature(const std::vector<unsigned char> &vchSig);
670 
671 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
672 bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
673 int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
674 bool IsStandard(const CScript& scriptPubKey);
675 bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
676 bool IsMine(const CKeyStore& keystore, const CTxDestination &dest);
677 bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
678 bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
679 bool SignSignature(const CKeyStore& keystore, const CScript& fromPubKey, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL);
680 bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL);
681 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
682 
683 // Given two sets of signatures for scriptPubKey, possibly with OP_0 placeholders,
684 // combine them intelligently and return the result.
685 CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, unsigned int nIn, const CScript& scriptSig1, const CScript& scriptSig2);
686 
687 #endif
Definition: script.h:152
Definition: script.h:81
Definition: script.h:137
bool IsToKeyID(CKeyID &hash) const
Definition: script.cpp:1783
#define VARINT(obj)
Definition: serialize.h:305
#define strprintf(format,...)
Definition: util.h:169
void print() const
Definition: script.h:584
Definition: script.h:120
static int DecodeOP_N(opcodetype opcode)
Definition: script.h:480
bool GetOp2(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet) const
Definition: script.h:426
CScript & operator<<(int64 b)
Definition: script.h:320
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
Definition: script.cpp:1477
CScript & operator<<(unsigned short b)
Definition: script.h:323
Definition: script.h:173
CScript & operator<<(const uint160 &b)
Definition: script.h:335
CScript(const CScript &b)
Definition: script.h:277
Definition: script.h:98
Definition: script.h:91
Definition: script.h:87
bool Compress(std::vector< unsigned char > &out) const
Definition: script.cpp:1819
CScript(signed char b)
Definition: script.h:298
bool IsPayToScriptHash() const
Definition: script.cpp:1734
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
Definition: script.cpp:292
const char * GetTxnOutputType(txnouttype t)
Definition: script.cpp:73
CScript(long b)
Definition: script.h:301
Definition: script.h:151
unsigned int GetSpecialSize(unsigned int nSize) const
Definition: script.cpp:1850
Definition: script.h:79
Definition: script.h:158
CScript & push_int64(int64 n)
Definition: script.h:247
Definition: script.h:85
unsigned int size() const
Definition: key.h:88
bool IsToPubKey(CPubKey &pubkey) const
Definition: script.cpp:1804
Definition: script.h:80
Compact serializer for scripts.
Definition: script.h:606
friend bool operator==(const CNoDestination &a, const CNoDestination &b)
Definition: script.h:52
void PrintHex() const
Definition: script.h:556
unsigned long long uint64
Definition: serialize.h:26
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
Definition: main.h:896
uint160 Hash160(const T1 pbegin, const T1 pend)
Definition: hash.h:109
bool IsStandard(const CScript &scriptPubKey)
Definition: script.cpp:1332
Definition: script.h:172
friend CScript operator+(const CScript &a, const CScript &b)
Definition: script.h:289
int ScriptSigArgsExpected(txnouttype t, const std::vector< std::vector< unsigned char > > &vSolutions)
Definition: script.cpp:1312
CScript(const std::vector< unsigned char > &b)
Definition: script.h:312
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
Definition: script.h:421
CScript & operator<<(unsigned long b)
Definition: script.h:324
Definition: script.h:93
bool IsMine(const CKeyStore &keystore, const CScript &scriptPubKey)
Definition: script.cpp:1383
std::string ToString() const
Definition: script.h:561
Definition: script.h:89
const char * GetOpName(opcodetype opcode)
Definition: script.cpp:87
CScript(opcodetype b)
Definition: script.h:309
Definition: script.h:138
void SetDestination(const CTxDestination &address)
Definition: script.cpp:1768
std::string ValueString(const std::vector< unsigned char > &vch)
Definition: script.h:216
void Serialize(Stream &s, int nType, int nVersion) const
Definition: script.h:641
Definition: script.h:82
CScript & operator<<(opcodetype opcode)
Definition: script.h:327
CScript(unsigned char b)
Definition: script.h:303
friend bool operator<(const CNoDestination &a, const CNoDestination &b)
Definition: script.h:53
Definition: script.h:159
opcodetype
Script opcodes.
Definition: script.h:67
CScript(int64 b)
Definition: script.h:302
CScript & operator<<(const CScript &b)
Definition: script.h:390
CScript & operator<<(unsigned char b)
Definition: script.h:321
unsigned int GetSerializeSize(int nType, int nVersion) const
Definition: script.h:632
Definition: script.h:129
CScriptCompressor(CScript &scriptIn)
Definition: script.h:630
#define printf
Definition: rpcdump.cpp:12
unsigned int GetSigOpCount(bool fAccurate) const
Definition: script.cpp:1686
bool IsToScriptID(CScriptID &hash) const
Definition: script.cpp:1794
txnouttype
Definition: script.h:40
An encapsulated public key.
Definition: key.h:40
Definition: script.h:84
CScript & operator<<(signed char b)
Definition: script.h:316
CScript(const unsigned char *pbegin, const unsigned char *pend)
Definition: script.h:280
Definition: script.h:77
bool IsPushOnly() const
Definition: script.h:537
Definition: script.h:96
C++ wrapper for BIGNUM (OpenSSL bignum)
Definition: bignum.h:51
std::vector< unsigned char > getvch() const
Definition: bignum.h:255
CScript()
Definition: script.h:276
CScript & script
Definition: script.h:615
Definition: script.h:156
bool GetOp(iterator &pc, opcodetype &opcodeRet)
Definition: script.h:408
CScript & operator<<(unsigned int b)
Definition: script.h:322
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Definition: script.cpp:1127
CScript(unsigned long b)
Definition: script.h:306
Definition: script.h:124
CScript & operator<<(const CBigNum &b)
Definition: script.h:357
CScript & operator<<(short b)
Definition: script.h:317
Definition: script.h:157
const unsigned char * begin() const
Definition: key.h:89
int getint() const
Definition: bignum.h:116
bool IsCanonicalSignature(const std::vector< unsigned char > &vchSig)
Definition: script.cpp:245
CScript & operator<<(int b)
Definition: script.h:318
CScript(int b)
Definition: script.h:300
Definition: script.h:86
256-bit unsigned integer
Definition: uint256.h:537
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType=SIGHASH_ALL)
Definition: script.cpp:1519
std::string StackString(const std::vector< std::vector< unsigned char > > &vStack)
Definition: script.h:224
CScript & operator<<(long b)
Definition: script.h:319
static const unsigned int nSpecialScripts
Definition: script.h:613
CScript(const uint256 &b)
Definition: script.h:310
CScript(const_iterator pbegin, const_iterator pend)
Definition: script.h:278
static opcodetype EncodeOP_N(int n)
Definition: script.h:487
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:244
bool Decompress(unsigned int nSize, const std::vector< unsigned char > &out)
Definition: script.cpp:1859
CScript & operator+=(const CScript &b)
Definition: script.h:283
CScript & push_uint64(uint64 n)
Definition: script.h:261
A virtual base class for key stores.
Definition: keystore.h:15
void SetMultisig(int nRequired, const std::vector< CPubKey > &keys)
Definition: script.cpp:1773
A reference to a CKey: the Hash160 of its serialized public key.
Definition: key.h:24
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: script.cpp:1422
CScriptID GetID() const
Definition: script.h:589
int FindAndDelete(const CScript &b)
Definition: script.h:495
Definition: script.h:83
160-bit unsigned integer
Definition: uint256.h:422
CScript CombineSignatures(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const CScript &scriptSig1, const CScript &scriptSig2)
Definition: script.cpp:1671
CScript(const CBigNum &b)
Definition: script.h:311
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Definition: script.cpp:1448
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: key.h:32
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
Definition: script.h:416
CScript & operator<<(const uint256 &b)
Definition: script.h:342
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: script.h:62
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
Definition: script.h:399
Definition: script.h:90
CScript(unsigned int b)
Definition: script.h:304
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: main.h:477
CScript(unsigned short b)
Definition: script.h:305
Definition: script.h:139
bool IsCanonicalPubKey(const std::vector< unsigned char > &vchPubKey)
Definition: script.cpp:230
Definition: script.h:88
Definition: script.h:97
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:292
Definition: script.h:78
Definition: script.h:70
T & REF(const T &val)
Definition: serialize.h:36
CScript & operator<<(uint64 b)
Definition: script.h:325
CScript(short b)
Definition: script.h:299
CScript(uint64 b)
Definition: script.h:307
uint32_t hash
Definition: cache.cc:34
CScript & operator<<(const CPubKey &key)
Definition: script.h:349
Definition: script.h:155
const unsigned char * end() const
Definition: key.h:90
Definition: script.h:92
Wrapper for serializing arrays and POD.
Definition: serialize.h:309
int Find(opcodetype op) const
Definition: script.h:513
Definition: script.h:119
void Unserialize(Stream &s, int nType, int nVersion)
Definition: script.h:653
long long int64
Definition: serialize.h:25