Mercurial > hg > bitcoin
annotate src/script.cpp @ 2687:2cca172f83a9 draft
Encapsulate public keys in CPubKey
author | Pieter Wuille <pieter.wuille@gmail.com> |
---|---|
date | Mon, 14 May 2012 19:07:52 +0200 |
parents | 9c977b16c045 |
children | 2c65e5d626eb |
rev | line source |
---|---|
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1 // Copyright (c) 2009-2010 Satoshi Nakamoto |
1818
20667468f95b
Update all copyrights to 2012
Gavin Andresen <gavinandresen@gmail.com>
parents:
1769
diff
changeset
|
2 // Copyright (c) 2009-2012 The Bitcoin developers |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3 // Distributed under the MIT/X11 software license, see the accompanying |
2607 | 4 // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
2274 | 5 #include <boost/foreach.hpp> |
2663
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
6 #include <boost/tuple/tuple.hpp> |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
7 |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
575
diff
changeset
|
8 using namespace std; |
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
575
diff
changeset
|
9 using namespace boost; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
10 |
2274 | 11 #include "script.h" |
12 #include "keystore.h" | |
13 #include "bignum.h" | |
14 #include "key.h" | |
15 #include "main.h" | |
2663
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
16 #include "sync.h" |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
17 #include "util.h" |
2274 | 18 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
19 bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
20 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
21 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
22 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
23 typedef vector<unsigned char> valtype; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
24 static const valtype vchFalse(0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
25 static const valtype vchZero(0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
26 static const valtype vchTrue(1, 1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
27 static const CBigNum bnZero(0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
28 static const CBigNum bnOne(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
29 static const CBigNum bnFalse(0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
30 static const CBigNum bnTrue(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
31 static const size_t nMaxNumSize = 4; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
32 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
33 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
34 CBigNum CastToBigNum(const valtype& vch) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
35 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
36 if (vch.size() > nMaxNumSize) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
37 throw runtime_error("CastToBigNum() : overflow"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
38 // Get rid of extra leading zeros |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
39 return CBigNum(CBigNum(vch).getvch()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
40 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
41 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
42 bool CastToBool(const valtype& vch) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
43 { |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
44 for (unsigned int i = 0; i < vch.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
45 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
46 if (vch[i] != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
47 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
48 // Can be negative zero |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
49 if (i == vch.size()-1 && vch[i] == 0x80) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
50 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
51 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
52 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
53 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
54 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
55 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
56 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
57 void MakeSameSize(valtype& vch1, valtype& vch2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
58 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
59 // Lengthen the shorter one |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
60 if (vch1.size() < vch2.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
61 vch1.resize(vch2.size(), 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
62 if (vch2.size() < vch1.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
63 vch2.resize(vch1.size(), 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
64 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
65 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
66 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
67 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
68 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
69 // Script is a stack machine (like Forth) that evaluates a predicate |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
70 // returning a bool indicating valid or not. There are no loops. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
71 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
72 #define stacktop(i) (stack.at(stack.size()+(i))) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
73 #define altstacktop(i) (altstack.at(altstack.size()+(i))) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
74 static inline void popstack(vector<valtype>& stack) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
75 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
76 if (stack.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
77 throw runtime_error("popstack() : stack empty"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
78 stack.pop_back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
79 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
80 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
81 |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
82 const char* GetTxnOutputType(txnouttype t) |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
83 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
84 switch (t) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
85 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
86 case TX_NONSTANDARD: return "nonstandard"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
87 case TX_PUBKEY: return "pubkey"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
88 case TX_PUBKEYHASH: return "pubkeyhash"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
89 case TX_SCRIPTHASH: return "scripthash"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
90 case TX_MULTISIG: return "multisig"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
91 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
92 return NULL; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
93 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
94 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
95 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
96 const char* GetOpName(opcodetype opcode) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
97 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
98 switch (opcode) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
99 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
100 // push value |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
101 case OP_0 : return "0"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
102 case OP_PUSHDATA1 : return "OP_PUSHDATA1"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
103 case OP_PUSHDATA2 : return "OP_PUSHDATA2"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
104 case OP_PUSHDATA4 : return "OP_PUSHDATA4"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
105 case OP_1NEGATE : return "-1"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
106 case OP_RESERVED : return "OP_RESERVED"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
107 case OP_1 : return "1"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
108 case OP_2 : return "2"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
109 case OP_3 : return "3"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
110 case OP_4 : return "4"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
111 case OP_5 : return "5"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
112 case OP_6 : return "6"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
113 case OP_7 : return "7"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
114 case OP_8 : return "8"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
115 case OP_9 : return "9"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
116 case OP_10 : return "10"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
117 case OP_11 : return "11"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
118 case OP_12 : return "12"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
119 case OP_13 : return "13"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
120 case OP_14 : return "14"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
121 case OP_15 : return "15"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
122 case OP_16 : return "16"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
123 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
124 // control |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
125 case OP_NOP : return "OP_NOP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
126 case OP_VER : return "OP_VER"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
127 case OP_IF : return "OP_IF"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
128 case OP_NOTIF : return "OP_NOTIF"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
129 case OP_VERIF : return "OP_VERIF"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
130 case OP_VERNOTIF : return "OP_VERNOTIF"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
131 case OP_ELSE : return "OP_ELSE"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
132 case OP_ENDIF : return "OP_ENDIF"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
133 case OP_VERIFY : return "OP_VERIFY"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
134 case OP_RETURN : return "OP_RETURN"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
135 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
136 // stack ops |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
137 case OP_TOALTSTACK : return "OP_TOALTSTACK"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
138 case OP_FROMALTSTACK : return "OP_FROMALTSTACK"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
139 case OP_2DROP : return "OP_2DROP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
140 case OP_2DUP : return "OP_2DUP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
141 case OP_3DUP : return "OP_3DUP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
142 case OP_2OVER : return "OP_2OVER"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
143 case OP_2ROT : return "OP_2ROT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
144 case OP_2SWAP : return "OP_2SWAP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
145 case OP_IFDUP : return "OP_IFDUP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
146 case OP_DEPTH : return "OP_DEPTH"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
147 case OP_DROP : return "OP_DROP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
148 case OP_DUP : return "OP_DUP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
149 case OP_NIP : return "OP_NIP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
150 case OP_OVER : return "OP_OVER"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
151 case OP_PICK : return "OP_PICK"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
152 case OP_ROLL : return "OP_ROLL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
153 case OP_ROT : return "OP_ROT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
154 case OP_SWAP : return "OP_SWAP"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
155 case OP_TUCK : return "OP_TUCK"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
156 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
157 // splice ops |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
158 case OP_CAT : return "OP_CAT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
159 case OP_SUBSTR : return "OP_SUBSTR"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
160 case OP_LEFT : return "OP_LEFT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
161 case OP_RIGHT : return "OP_RIGHT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
162 case OP_SIZE : return "OP_SIZE"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
163 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
164 // bit logic |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
165 case OP_INVERT : return "OP_INVERT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
166 case OP_AND : return "OP_AND"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
167 case OP_OR : return "OP_OR"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
168 case OP_XOR : return "OP_XOR"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
169 case OP_EQUAL : return "OP_EQUAL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
170 case OP_EQUALVERIFY : return "OP_EQUALVERIFY"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
171 case OP_RESERVED1 : return "OP_RESERVED1"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
172 case OP_RESERVED2 : return "OP_RESERVED2"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
173 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
174 // numeric |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
175 case OP_1ADD : return "OP_1ADD"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
176 case OP_1SUB : return "OP_1SUB"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
177 case OP_2MUL : return "OP_2MUL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
178 case OP_2DIV : return "OP_2DIV"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
179 case OP_NEGATE : return "OP_NEGATE"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
180 case OP_ABS : return "OP_ABS"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
181 case OP_NOT : return "OP_NOT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
182 case OP_0NOTEQUAL : return "OP_0NOTEQUAL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
183 case OP_ADD : return "OP_ADD"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
184 case OP_SUB : return "OP_SUB"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
185 case OP_MUL : return "OP_MUL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
186 case OP_DIV : return "OP_DIV"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
187 case OP_MOD : return "OP_MOD"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
188 case OP_LSHIFT : return "OP_LSHIFT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
189 case OP_RSHIFT : return "OP_RSHIFT"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
190 case OP_BOOLAND : return "OP_BOOLAND"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
191 case OP_BOOLOR : return "OP_BOOLOR"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
192 case OP_NUMEQUAL : return "OP_NUMEQUAL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
193 case OP_NUMEQUALVERIFY : return "OP_NUMEQUALVERIFY"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
194 case OP_NUMNOTEQUAL : return "OP_NUMNOTEQUAL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
195 case OP_LESSTHAN : return "OP_LESSTHAN"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
196 case OP_GREATERTHAN : return "OP_GREATERTHAN"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
197 case OP_LESSTHANOREQUAL : return "OP_LESSTHANOREQUAL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
198 case OP_GREATERTHANOREQUAL : return "OP_GREATERTHANOREQUAL"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
199 case OP_MIN : return "OP_MIN"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
200 case OP_MAX : return "OP_MAX"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
201 case OP_WITHIN : return "OP_WITHIN"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
202 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
203 // crypto |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
204 case OP_RIPEMD160 : return "OP_RIPEMD160"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
205 case OP_SHA1 : return "OP_SHA1"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
206 case OP_SHA256 : return "OP_SHA256"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
207 case OP_HASH160 : return "OP_HASH160"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
208 case OP_HASH256 : return "OP_HASH256"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
209 case OP_CODESEPARATOR : return "OP_CODESEPARATOR"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
210 case OP_CHECKSIG : return "OP_CHECKSIG"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
211 case OP_CHECKSIGVERIFY : return "OP_CHECKSIGVERIFY"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
212 case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
213 case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
214 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
215 // expanson |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
216 case OP_NOP1 : return "OP_NOP1"; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
217 case OP_NOP2 : return "OP_NOP2"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
218 case OP_NOP3 : return "OP_NOP3"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
219 case OP_NOP4 : return "OP_NOP4"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
220 case OP_NOP5 : return "OP_NOP5"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
221 case OP_NOP6 : return "OP_NOP6"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
222 case OP_NOP7 : return "OP_NOP7"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
223 case OP_NOP8 : return "OP_NOP8"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
224 case OP_NOP9 : return "OP_NOP9"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
225 case OP_NOP10 : return "OP_NOP10"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
226 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
227 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
228 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
229 // template matching params |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
230 case OP_PUBKEYHASH : return "OP_PUBKEYHASH"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
231 case OP_PUBKEY : return "OP_PUBKEY"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
232 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
233 case OP_INVALIDOPCODE : return "OP_INVALIDOPCODE"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
234 default: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
235 return "OP_UNKNOWN"; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
236 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
237 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
238 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
239 bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
240 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
241 CAutoBN_CTX pctx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
242 CScript::const_iterator pc = script.begin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
243 CScript::const_iterator pend = script.end(); |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
244 CScript::const_iterator pbegincodehash = script.begin(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
245 opcodetype opcode; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
246 valtype vchPushValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
247 vector<bool> vfExec; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
248 vector<valtype> altstack; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
249 if (script.size() > 10000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
250 return false; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
251 int nOpCount = 0; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
252 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
253 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
254 try |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
255 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
256 while (pc < pend) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
257 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
258 bool fExec = !count(vfExec.begin(), vfExec.end(), false); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
259 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
260 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
261 // Read instruction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
262 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
263 if (!script.GetOp(pc, opcode, vchPushValue)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
264 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
265 if (vchPushValue.size() > 520) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
266 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
267 if (opcode > OP_16 && ++nOpCount > 201) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
268 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
269 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
270 if (opcode == OP_CAT || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
271 opcode == OP_SUBSTR || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
272 opcode == OP_LEFT || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
273 opcode == OP_RIGHT || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
274 opcode == OP_INVERT || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
275 opcode == OP_AND || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
276 opcode == OP_OR || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
277 opcode == OP_XOR || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
278 opcode == OP_2MUL || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
279 opcode == OP_2DIV || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
280 opcode == OP_MUL || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
281 opcode == OP_DIV || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
282 opcode == OP_MOD || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
283 opcode == OP_LSHIFT || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
284 opcode == OP_RSHIFT) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
285 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
286 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
287 if (fExec && 0 <= opcode && opcode <= OP_PUSHDATA4) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
288 stack.push_back(vchPushValue); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
289 else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
290 switch (opcode) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
291 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
292 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
293 // Push value |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
294 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
295 case OP_1NEGATE: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
296 case OP_1: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
297 case OP_2: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
298 case OP_3: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
299 case OP_4: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
300 case OP_5: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
301 case OP_6: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
302 case OP_7: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
303 case OP_8: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
304 case OP_9: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
305 case OP_10: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
306 case OP_11: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
307 case OP_12: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
308 case OP_13: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
309 case OP_14: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
310 case OP_15: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
311 case OP_16: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
312 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
313 // ( -- value) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
314 CBigNum bn((int)opcode - (int)(OP_1 - 1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
315 stack.push_back(bn.getvch()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
316 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
317 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
318 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
319 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
320 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
321 // Control |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
322 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
323 case OP_NOP: |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
324 case OP_NOP1: case OP_NOP2: case OP_NOP3: case OP_NOP4: case OP_NOP5: |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
325 case OP_NOP6: case OP_NOP7: case OP_NOP8: case OP_NOP9: case OP_NOP10: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
326 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
327 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
328 case OP_IF: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
329 case OP_NOTIF: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
330 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
331 // <expression> if [statements] [else [statements]] endif |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
332 bool fValue = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
333 if (fExec) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
334 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
335 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
336 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
337 valtype& vch = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
338 fValue = CastToBool(vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
339 if (opcode == OP_NOTIF) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
340 fValue = !fValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
341 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
342 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
343 vfExec.push_back(fValue); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
344 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
345 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
346 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
347 case OP_ELSE: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
348 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
349 if (vfExec.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
350 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
351 vfExec.back() = !vfExec.back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
352 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
353 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
354 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
355 case OP_ENDIF: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
356 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
357 if (vfExec.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
358 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
359 vfExec.pop_back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
360 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
361 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
362 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
363 case OP_VERIFY: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
364 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
365 // (true -- ) or |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
366 // (false -- false) and return |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
367 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
368 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
369 bool fValue = CastToBool(stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
370 if (fValue) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
371 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
372 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
373 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
374 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
375 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
376 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
377 case OP_RETURN: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
378 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
379 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
380 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
381 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
382 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
383 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
384 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
385 // Stack ops |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
386 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
387 case OP_TOALTSTACK: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
388 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
389 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
390 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
391 altstack.push_back(stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
392 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
393 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
394 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
395 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
396 case OP_FROMALTSTACK: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
397 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
398 if (altstack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
399 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
400 stack.push_back(altstacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
401 popstack(altstack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
402 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
403 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
404 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
405 case OP_2DROP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
406 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
407 // (x1 x2 -- ) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
408 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
409 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
410 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
411 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
412 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
413 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
414 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
415 case OP_2DUP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
416 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
417 // (x1 x2 -- x1 x2 x1 x2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
418 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
419 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
420 valtype vch1 = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
421 valtype vch2 = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
422 stack.push_back(vch1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
423 stack.push_back(vch2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
424 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
425 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
426 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
427 case OP_3DUP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
428 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
429 // (x1 x2 x3 -- x1 x2 x3 x1 x2 x3) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
430 if (stack.size() < 3) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
431 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
432 valtype vch1 = stacktop(-3); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
433 valtype vch2 = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
434 valtype vch3 = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
435 stack.push_back(vch1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
436 stack.push_back(vch2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
437 stack.push_back(vch3); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
438 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
439 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
440 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
441 case OP_2OVER: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
442 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
443 // (x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
444 if (stack.size() < 4) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
445 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
446 valtype vch1 = stacktop(-4); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
447 valtype vch2 = stacktop(-3); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
448 stack.push_back(vch1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
449 stack.push_back(vch2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
450 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
451 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
452 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
453 case OP_2ROT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
454 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
455 // (x1 x2 x3 x4 x5 x6 -- x3 x4 x5 x6 x1 x2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
456 if (stack.size() < 6) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
457 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
458 valtype vch1 = stacktop(-6); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
459 valtype vch2 = stacktop(-5); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
460 stack.erase(stack.end()-6, stack.end()-4); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
461 stack.push_back(vch1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
462 stack.push_back(vch2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
463 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
464 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
465 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
466 case OP_2SWAP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
467 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
468 // (x1 x2 x3 x4 -- x3 x4 x1 x2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
469 if (stack.size() < 4) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
470 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
471 swap(stacktop(-4), stacktop(-2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
472 swap(stacktop(-3), stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
473 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
474 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
475 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
476 case OP_IFDUP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
477 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
478 // (x - 0 | x x) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
479 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
480 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
481 valtype vch = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
482 if (CastToBool(vch)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
483 stack.push_back(vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
484 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
485 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
486 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
487 case OP_DEPTH: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
488 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
489 // -- stacksize |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
490 CBigNum bn(stack.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
491 stack.push_back(bn.getvch()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
492 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
493 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
494 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
495 case OP_DROP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
496 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
497 // (x -- ) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
498 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
499 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
500 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
501 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
502 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
503 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
504 case OP_DUP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
505 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
506 // (x -- x x) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
507 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
508 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
509 valtype vch = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
510 stack.push_back(vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
511 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
512 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
513 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
514 case OP_NIP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
515 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
516 // (x1 x2 -- x2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
517 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
518 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
519 stack.erase(stack.end() - 2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
520 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
521 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
522 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
523 case OP_OVER: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
524 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
525 // (x1 x2 -- x1 x2 x1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
526 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
527 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
528 valtype vch = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
529 stack.push_back(vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
530 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
531 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
532 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
533 case OP_PICK: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
534 case OP_ROLL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
535 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
536 // (xn ... x2 x1 x0 n - xn ... x2 x1 x0 xn) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
537 // (xn ... x2 x1 x0 n - ... x2 x1 x0 xn) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
538 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
539 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
540 int n = CastToBigNum(stacktop(-1)).getint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
541 popstack(stack); |
2311
20e40ae0d404
Add casts for unavoidable signed/unsigned comparisons
Jeff Garzik <jgarzik@exmulti.com>
parents:
2309
diff
changeset
|
542 if (n < 0 || n >= (int)stack.size()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
543 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
544 valtype vch = stacktop(-n-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
545 if (opcode == OP_ROLL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
546 stack.erase(stack.end()-n-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
547 stack.push_back(vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
548 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
549 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
550 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
551 case OP_ROT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
552 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
553 // (x1 x2 x3 -- x2 x3 x1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
554 // x2 x1 x3 after first swap |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
555 // x2 x3 x1 after second swap |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
556 if (stack.size() < 3) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
557 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
558 swap(stacktop(-3), stacktop(-2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
559 swap(stacktop(-2), stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
560 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
561 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
562 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
563 case OP_SWAP: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
564 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
565 // (x1 x2 -- x2 x1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
566 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
567 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
568 swap(stacktop(-2), stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
569 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
570 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
571 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
572 case OP_TUCK: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
573 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
574 // (x1 x2 -- x2 x1 x2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
575 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
576 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
577 valtype vch = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
578 stack.insert(stack.end()-2, vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
579 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
580 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
581 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
582 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
583 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
584 // Splice ops |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
585 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
586 case OP_CAT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
587 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
588 // (x1 x2 -- out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
589 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
590 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
591 valtype& vch1 = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
592 valtype& vch2 = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
593 vch1.insert(vch1.end(), vch2.begin(), vch2.end()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
594 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
595 if (stacktop(-1).size() > 520) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
596 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
597 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
598 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
599 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
600 case OP_SUBSTR: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
601 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
602 // (in begin size -- out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
603 if (stack.size() < 3) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
604 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
605 valtype& vch = stacktop(-3); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
606 int nBegin = CastToBigNum(stacktop(-2)).getint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
607 int nEnd = nBegin + CastToBigNum(stacktop(-1)).getint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
608 if (nBegin < 0 || nEnd < nBegin) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
609 return false; |
2311
20e40ae0d404
Add casts for unavoidable signed/unsigned comparisons
Jeff Garzik <jgarzik@exmulti.com>
parents:
2309
diff
changeset
|
610 if (nBegin > (int)vch.size()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
611 nBegin = vch.size(); |
2311
20e40ae0d404
Add casts for unavoidable signed/unsigned comparisons
Jeff Garzik <jgarzik@exmulti.com>
parents:
2309
diff
changeset
|
612 if (nEnd > (int)vch.size()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
613 nEnd = vch.size(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
614 vch.erase(vch.begin() + nEnd, vch.end()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
615 vch.erase(vch.begin(), vch.begin() + nBegin); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
616 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
617 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
618 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
619 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
620 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
621 case OP_LEFT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
622 case OP_RIGHT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
623 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
624 // (in size -- out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
625 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
626 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
627 valtype& vch = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
628 int nSize = CastToBigNum(stacktop(-1)).getint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
629 if (nSize < 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
630 return false; |
2311
20e40ae0d404
Add casts for unavoidable signed/unsigned comparisons
Jeff Garzik <jgarzik@exmulti.com>
parents:
2309
diff
changeset
|
631 if (nSize > (int)vch.size()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
632 nSize = vch.size(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
633 if (opcode == OP_LEFT) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
634 vch.erase(vch.begin() + nSize, vch.end()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
635 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
636 vch.erase(vch.begin(), vch.end() - nSize); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
637 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
638 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
639 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
640 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
641 case OP_SIZE: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
642 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
643 // (in -- in size) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
644 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
645 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
646 CBigNum bn(stacktop(-1).size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
647 stack.push_back(bn.getvch()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
648 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
649 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
650 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
651 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
652 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
653 // Bitwise logic |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
654 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
655 case OP_INVERT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
656 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
657 // (in - out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
658 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
659 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
660 valtype& vch = stacktop(-1); |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
661 for (unsigned int i = 0; i < vch.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
662 vch[i] = ~vch[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
663 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
664 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
665 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
666 case OP_AND: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
667 case OP_OR: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
668 case OP_XOR: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
669 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
670 // (x1 x2 - out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
671 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
672 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
673 valtype& vch1 = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
674 valtype& vch2 = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
675 MakeSameSize(vch1, vch2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
676 if (opcode == OP_AND) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
677 { |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
678 for (unsigned int i = 0; i < vch1.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
679 vch1[i] &= vch2[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
680 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
681 else if (opcode == OP_OR) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
682 { |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
683 for (unsigned int i = 0; i < vch1.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
684 vch1[i] |= vch2[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
685 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
686 else if (opcode == OP_XOR) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
687 { |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
688 for (unsigned int i = 0; i < vch1.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
689 vch1[i] ^= vch2[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
690 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
691 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
692 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
693 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
694 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
695 case OP_EQUAL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
696 case OP_EQUALVERIFY: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
697 //case OP_NOTEQUAL: // use OP_NUMNOTEQUAL |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
698 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
699 // (x1 x2 - bool) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
700 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
701 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
702 valtype& vch1 = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
703 valtype& vch2 = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
704 bool fEqual = (vch1 == vch2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
705 // OP_NOTEQUAL is disabled because it would be too easy to say |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
706 // something like n != 1 and have some wiseguy pass in 1 with extra |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
707 // zero bytes after it (numerically, 0x01 == 0x0001 == 0x000001) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
708 //if (opcode == OP_NOTEQUAL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
709 // fEqual = !fEqual; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
710 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
711 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
712 stack.push_back(fEqual ? vchTrue : vchFalse); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
713 if (opcode == OP_EQUALVERIFY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
714 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
715 if (fEqual) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
716 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
717 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
718 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
719 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
720 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
721 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
722 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
723 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
724 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
725 // Numeric |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
726 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
727 case OP_1ADD: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
728 case OP_1SUB: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
729 case OP_2MUL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
730 case OP_2DIV: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
731 case OP_NEGATE: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
732 case OP_ABS: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
733 case OP_NOT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
734 case OP_0NOTEQUAL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
735 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
736 // (in -- out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
737 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
738 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
739 CBigNum bn = CastToBigNum(stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
740 switch (opcode) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
741 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
742 case OP_1ADD: bn += bnOne; break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
743 case OP_1SUB: bn -= bnOne; break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
744 case OP_2MUL: bn <<= 1; break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
745 case OP_2DIV: bn >>= 1; break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
746 case OP_NEGATE: bn = -bn; break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
747 case OP_ABS: if (bn < bnZero) bn = -bn; break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
748 case OP_NOT: bn = (bn == bnZero); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
749 case OP_0NOTEQUAL: bn = (bn != bnZero); break; |
779
2898aa13cfc0
fix warning: X enumeration values not handled in switch [-Wswitch-enum]
Giel van Schijndel <me@mortis.eu>
parents:
766
diff
changeset
|
750 default: assert(!"invalid opcode"); break; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
751 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
752 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
753 stack.push_back(bn.getvch()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
754 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
755 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
756 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
757 case OP_ADD: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
758 case OP_SUB: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
759 case OP_MUL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
760 case OP_DIV: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
761 case OP_MOD: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
762 case OP_LSHIFT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
763 case OP_RSHIFT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
764 case OP_BOOLAND: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
765 case OP_BOOLOR: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
766 case OP_NUMEQUAL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
767 case OP_NUMEQUALVERIFY: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
768 case OP_NUMNOTEQUAL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
769 case OP_LESSTHAN: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
770 case OP_GREATERTHAN: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
771 case OP_LESSTHANOREQUAL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
772 case OP_GREATERTHANOREQUAL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
773 case OP_MIN: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
774 case OP_MAX: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
775 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
776 // (x1 x2 -- out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
777 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
778 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
779 CBigNum bn1 = CastToBigNum(stacktop(-2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
780 CBigNum bn2 = CastToBigNum(stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
781 CBigNum bn; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
782 switch (opcode) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
783 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
784 case OP_ADD: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
785 bn = bn1 + bn2; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
786 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
787 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
788 case OP_SUB: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
789 bn = bn1 - bn2; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
790 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
791 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
792 case OP_MUL: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
793 if (!BN_mul(&bn, &bn1, &bn2, pctx)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
794 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
795 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
796 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
797 case OP_DIV: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
798 if (!BN_div(&bn, NULL, &bn1, &bn2, pctx)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
799 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
800 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
801 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
802 case OP_MOD: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
803 if (!BN_mod(&bn, &bn1, &bn2, pctx)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
804 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
805 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
806 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
807 case OP_LSHIFT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
808 if (bn2 < bnZero || bn2 > CBigNum(2048)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
809 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
810 bn = bn1 << bn2.getulong(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
811 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
812 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
813 case OP_RSHIFT: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
814 if (bn2 < bnZero || bn2 > CBigNum(2048)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
815 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
816 bn = bn1 >> bn2.getulong(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
817 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
818 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
819 case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
820 case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
821 case OP_NUMEQUAL: bn = (bn1 == bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
822 case OP_NUMEQUALVERIFY: bn = (bn1 == bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
823 case OP_NUMNOTEQUAL: bn = (bn1 != bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
824 case OP_LESSTHAN: bn = (bn1 < bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
825 case OP_GREATERTHAN: bn = (bn1 > bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
826 case OP_LESSTHANOREQUAL: bn = (bn1 <= bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
827 case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
828 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
829 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break; |
779
2898aa13cfc0
fix warning: X enumeration values not handled in switch [-Wswitch-enum]
Giel van Schijndel <me@mortis.eu>
parents:
766
diff
changeset
|
830 default: assert(!"invalid opcode"); break; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
831 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
832 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
833 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
834 stack.push_back(bn.getvch()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
835 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
836 if (opcode == OP_NUMEQUALVERIFY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
837 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
838 if (CastToBool(stacktop(-1))) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
839 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
840 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
841 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
842 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
843 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
844 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
845 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
846 case OP_WITHIN: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
847 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
848 // (x min max -- out) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
849 if (stack.size() < 3) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
850 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
851 CBigNum bn1 = CastToBigNum(stacktop(-3)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
852 CBigNum bn2 = CastToBigNum(stacktop(-2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
853 CBigNum bn3 = CastToBigNum(stacktop(-1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
854 bool fValue = (bn2 <= bn1 && bn1 < bn3); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
855 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
856 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
857 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
858 stack.push_back(fValue ? vchTrue : vchFalse); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
859 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
860 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
861 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
862 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
863 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
864 // Crypto |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
865 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
866 case OP_RIPEMD160: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
867 case OP_SHA1: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
868 case OP_SHA256: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
869 case OP_HASH160: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
870 case OP_HASH256: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
871 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
872 // (in -- hash) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
873 if (stack.size() < 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
874 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
875 valtype& vch = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
876 valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
877 if (opcode == OP_RIPEMD160) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
878 RIPEMD160(&vch[0], vch.size(), &vchHash[0]); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
879 else if (opcode == OP_SHA1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
880 SHA1(&vch[0], vch.size(), &vchHash[0]); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
881 else if (opcode == OP_SHA256) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
882 SHA256(&vch[0], vch.size(), &vchHash[0]); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
883 else if (opcode == OP_HASH160) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
884 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
885 uint160 hash160 = Hash160(vch); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
886 memcpy(&vchHash[0], &hash160, sizeof(hash160)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
887 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
888 else if (opcode == OP_HASH256) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
889 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
890 uint256 hash = Hash(vch.begin(), vch.end()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
891 memcpy(&vchHash[0], &hash, sizeof(hash)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
892 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
893 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
894 stack.push_back(vchHash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
895 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
896 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
897 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
898 case OP_CODESEPARATOR: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
899 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
900 // Hash starts after the code separator |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
901 pbegincodehash = pc; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
902 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
903 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
904 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
905 case OP_CHECKSIG: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
906 case OP_CHECKSIGVERIFY: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
907 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
908 // (sig pubkey -- bool) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
909 if (stack.size() < 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
910 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
911 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
912 valtype& vchSig = stacktop(-2); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
913 valtype& vchPubKey = stacktop(-1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
914 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
915 ////// debug print |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
916 //PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
917 //PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
918 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
919 // Subset of script starting at the most recent codeseparator |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
920 CScript scriptCode(pbegincodehash, pend); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
921 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
922 // Drop the signature, since there's no way for a signature to sign itself |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
923 scriptCode.FindAndDelete(CScript(vchSig)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
924 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
925 bool fSuccess = CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
926 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
927 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
928 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
929 stack.push_back(fSuccess ? vchTrue : vchFalse); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
930 if (opcode == OP_CHECKSIGVERIFY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
931 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
932 if (fSuccess) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
933 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
934 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
935 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
936 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
937 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
938 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
939 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
940 case OP_CHECKMULTISIG: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
941 case OP_CHECKMULTISIGVERIFY: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
942 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
943 // ([sig ...] num_of_signatures [pubkey ...] num_of_pubkeys -- bool) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
944 |
2322
e28cb2309ead
Undo part of c2e8c8ac to fix issue#1148
Gavin Andresen <gavinandresen@gmail.com>
parents:
2311
diff
changeset
|
945 int i = 1; |
2351
e92f87e6691c
EvalScript(): cast to avoid signed/unsigned warning
Jeff Garzik <jgarzik@exmulti.com>
parents:
2322
diff
changeset
|
946 if ((int)stack.size() < i) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
947 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
948 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
949 int nKeysCount = CastToBigNum(stacktop(-i)).getint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
950 if (nKeysCount < 0 || nKeysCount > 20) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
951 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
952 nOpCount += nKeysCount; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
953 if (nOpCount > 201) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
954 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
955 int ikey = ++i; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
956 i += nKeysCount; |
2351
e92f87e6691c
EvalScript(): cast to avoid signed/unsigned warning
Jeff Garzik <jgarzik@exmulti.com>
parents:
2322
diff
changeset
|
957 if ((int)stack.size() < i) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
958 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
959 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
960 int nSigsCount = CastToBigNum(stacktop(-i)).getint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
961 if (nSigsCount < 0 || nSigsCount > nKeysCount) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
962 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
963 int isig = ++i; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
964 i += nSigsCount; |
2351
e92f87e6691c
EvalScript(): cast to avoid signed/unsigned warning
Jeff Garzik <jgarzik@exmulti.com>
parents:
2322
diff
changeset
|
965 if ((int)stack.size() < i) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
966 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
967 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
968 // Subset of script starting at the most recent codeseparator |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
969 CScript scriptCode(pbegincodehash, pend); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
970 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
971 // Drop the signatures, since there's no way for a signature to sign itself |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
972 for (int k = 0; k < nSigsCount; k++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
973 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
974 valtype& vchSig = stacktop(-isig-k); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
975 scriptCode.FindAndDelete(CScript(vchSig)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
976 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
977 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
978 bool fSuccess = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
979 while (fSuccess && nSigsCount > 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
980 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
981 valtype& vchSig = stacktop(-isig); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
982 valtype& vchPubKey = stacktop(-ikey); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
983 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
984 // Check signature |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
985 if (CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
986 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
987 isig++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
988 nSigsCount--; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
989 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
990 ikey++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
991 nKeysCount--; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
992 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
993 // If there are more signatures left than keys left, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
994 // then too many signatures have failed |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
995 if (nSigsCount > nKeysCount) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
996 fSuccess = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
997 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
998 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
999 while (i-- > 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1000 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1001 stack.push_back(fSuccess ? vchTrue : vchFalse); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1002 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1003 if (opcode == OP_CHECKMULTISIGVERIFY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1004 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1005 if (fSuccess) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1006 popstack(stack); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1007 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1008 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1009 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1010 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1011 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1012 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1013 default: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1014 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1015 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1016 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1017 // Size limits |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1018 if (stack.size() + altstack.size() > 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1019 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1020 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1021 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1022 catch (...) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1023 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1024 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1025 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1026 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1027 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1028 if (!vfExec.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1029 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1030 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1031 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1032 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1033 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1034 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1035 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1036 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1037 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1038 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1039 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1040 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1041 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1042 uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1043 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1044 if (nIn >= txTo.vin.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1045 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1046 printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1047 return 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1048 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1049 CTransaction txTmp(txTo); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1050 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1051 // In case concatenating two scripts ends up with two codeseparators, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1052 // or an extra one at the end, this prevents all those possible incompatibilities. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1053 scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1054 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1055 // Blank out other inputs' signatures |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
1056 for (unsigned int i = 0; i < txTmp.vin.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1057 txTmp.vin[i].scriptSig = CScript(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1058 txTmp.vin[nIn].scriptSig = scriptCode; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1059 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1060 // Blank out some of the outputs |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1061 if ((nHashType & 0x1f) == SIGHASH_NONE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1062 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1063 // Wildcard payee |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1064 txTmp.vout.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1065 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1066 // Let the others update at will |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
1067 for (unsigned int i = 0; i < txTmp.vin.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1068 if (i != nIn) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1069 txTmp.vin[i].nSequence = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1070 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1071 else if ((nHashType & 0x1f) == SIGHASH_SINGLE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1072 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1073 // Only lockin the txout payee at same index as txin |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1074 unsigned int nOut = nIn; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1075 if (nOut >= txTmp.vout.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1076 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1077 printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1078 return 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1079 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1080 txTmp.vout.resize(nOut+1); |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
1081 for (unsigned int i = 0; i < nOut; i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1082 txTmp.vout[i].SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1083 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1084 // Let the others update at will |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
1085 for (unsigned int i = 0; i < txTmp.vin.size(); i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1086 if (i != nIn) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1087 txTmp.vin[i].nSequence = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1088 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1089 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1090 // Blank out other inputs completely, not recommended for open transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1091 if (nHashType & SIGHASH_ANYONECANPAY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1092 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1093 txTmp.vin[0] = txTmp.vin[nIn]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1094 txTmp.vin.resize(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1095 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1096 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1097 // Serialize and hash |
2277
0dcf927bc6b2
Further reduce header dependencies
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2274
diff
changeset
|
1098 CDataStream ss(SER_GETHASH, 0); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1099 ss.reserve(10000); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1100 ss << txTmp << nHashType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1101 return Hash(ss.begin(), ss.end()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1102 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1103 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1104 |
2663
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1105 // Valid signature cache, to avoid doing expensive ECDSA signature checking |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1106 // twice for every transaction (once when accepted into memory pool, and |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1107 // again when accepted into the block chain) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1108 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1109 class CSignatureCache |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1110 { |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1111 private: |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1112 // sigdata_type is (signature hash, signature, public key): |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1113 typedef boost::tuple<uint256, std::vector<unsigned char>, std::vector<unsigned char> > sigdata_type; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1114 std::set< sigdata_type> setValid; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1115 CCriticalSection cs_sigcache; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1116 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1117 public: |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1118 bool |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1119 Get(uint256 hash, const std::vector<unsigned char>& vchSig, const std::vector<unsigned char>& pubKey) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1120 { |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1121 LOCK(cs_sigcache); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1122 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1123 sigdata_type k(hash, vchSig, pubKey); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1124 std::set<sigdata_type>::iterator mi = setValid.find(k); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1125 if (mi != setValid.end()) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1126 return true; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1127 return false; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1128 } |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1129 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1130 void |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1131 Set(uint256 hash, const std::vector<unsigned char>& vchSig, const std::vector<unsigned char>& pubKey) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1132 { |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1133 // DoS prevention: limit cache size to less than 10MB |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1134 // (~200 bytes per cache entry times 50,000 entries) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1135 // Since there are a maximum of 20,000 signature operations per block |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1136 // 50,000 is a reasonable default. |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1137 int64 nMaxCacheSize = GetArg("-maxsigcachesize", 50000); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1138 if (nMaxCacheSize <= 0) return; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1139 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1140 LOCK(cs_sigcache); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1141 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1142 while (static_cast<int64>(setValid.size()) > nMaxCacheSize) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1143 { |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1144 // Evict a random entry. Random because that helps |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1145 // foil would-be DoS attackers who might try to pre-generate |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1146 // and re-use a set of valid signatures just-slightly-greater |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1147 // than our cache size. |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1148 uint256 randomHash = GetRandHash(); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1149 std::vector<unsigned char> unused; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1150 std::set<sigdata_type>::iterator it = |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1151 setValid.lower_bound(sigdata_type(randomHash, unused, unused)); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1152 if (it == setValid.end()) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1153 it = setValid.begin(); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1154 setValid.erase(*it); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1155 } |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1156 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1157 sigdata_type k(hash, vchSig, pubKey); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1158 setValid.insert(k); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1159 } |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1160 }; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1161 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1162 bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CScript scriptCode, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1163 const CTransaction& txTo, unsigned int nIn, int nHashType) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1164 { |
2663
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1165 static CSignatureCache signatureCache; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1166 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1167 // Hash type is one byte tacked on to the end of the signature |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1168 if (vchSig.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1169 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1170 if (nHashType == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1171 nHashType = vchSig.back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1172 else if (nHashType != vchSig.back()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1173 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1174 vchSig.pop_back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1175 |
2663
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1176 uint256 sighash = SignatureHash(scriptCode, txTo, nIn, nHashType); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1177 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1178 if (signatureCache.Get(sighash, vchSig, vchPubKey)) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1179 return true; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1180 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1181 CKey key; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1182 if (!key.SetPubKey(vchPubKey)) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1183 return false; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1184 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1185 if (!key.Verify(sighash, vchSig)) |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1186 return false; |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1187 |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1188 signatureCache.Set(sighash, vchSig, vchPubKey); |
9c977b16c045
Move signature cache from CKey::Verify to CheckSig in script.cpp
Gavin Andresen <gavinandresen@gmail.com>
parents:
2607
diff
changeset
|
1189 return true; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1190 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1191 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1192 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1193 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1194 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1195 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1196 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1197 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1198 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1199 |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1200 // |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1201 // Return public keys or hashes from scriptPubKey, for 'standard' transaction types. |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1202 // |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1203 bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1204 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1205 // Templates |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1206 static map<txnouttype, CScript> mTemplates; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1207 if (mTemplates.empty()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1208 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1209 // Standard tx, sender provides pubkey, receiver adds signature |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1210 mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG)); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1211 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1212 // Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1213 mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG)); |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1214 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1215 // Sender provides N pubkeys, receivers provides M signatures |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1216 mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG)); |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1217 } |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1218 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1219 // Shortcut for pay-to-script-hash, which are more constrained than the other types: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1220 // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1221 if (scriptPubKey.IsPayToScriptHash()) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1222 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1223 typeRet = TX_SCRIPTHASH; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1224 vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1225 vSolutionsRet.push_back(hashBytes); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1226 return true; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1227 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1228 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1229 // Scan templates |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1230 const CScript& script1 = scriptPubKey; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1231 BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1232 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1233 const CScript& script2 = tplate.second; |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1234 vSolutionsRet.clear(); |
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1235 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1236 opcodetype opcode1, opcode2; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1237 vector<unsigned char> vch1, vch2; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1238 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1239 // Compare |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1240 CScript::const_iterator pc1 = script1.begin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1241 CScript::const_iterator pc2 = script2.begin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1242 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1243 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1244 if (pc1 == script1.end() && pc2 == script2.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1245 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1246 // Found a match |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1247 typeRet = tplate.first; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1248 if (typeRet == TX_MULTISIG) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1249 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1250 // Additional checks for TX_MULTISIG: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1251 unsigned char m = vSolutionsRet.front()[0]; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1252 unsigned char n = vSolutionsRet.back()[0]; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1253 if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1254 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1255 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1256 return true; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1257 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1258 if (!script1.GetOp(pc1, opcode1, vch1)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1259 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1260 if (!script2.GetOp(pc2, opcode2, vch2)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1261 break; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1262 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1263 // Template matching opcodes: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1264 if (opcode2 == OP_PUBKEYS) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1265 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1266 while (vch1.size() >= 33 && vch1.size() <= 120) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1267 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1268 vSolutionsRet.push_back(vch1); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1269 if (!script1.GetOp(pc1, opcode1, vch1)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1270 break; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1271 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1272 if (!script2.GetOp(pc2, opcode2, vch2)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1273 break; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1274 // Normal situation is to fall through |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1275 // to other if/else statments |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1276 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1277 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1278 if (opcode2 == OP_PUBKEY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1279 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1280 if (vch1.size() < 33 || vch1.size() > 120) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1281 break; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1282 vSolutionsRet.push_back(vch1); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1283 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1284 else if (opcode2 == OP_PUBKEYHASH) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1285 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1286 if (vch1.size() != sizeof(uint160)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1287 break; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1288 vSolutionsRet.push_back(vch1); |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1289 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1290 else if (opcode2 == OP_SMALLINTEGER) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1291 { // Single-byte small integer pushed onto vSolutions |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1292 if (opcode1 == OP_0 || |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1293 (opcode1 >= OP_1 && opcode1 <= OP_16)) |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1294 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1295 char n = (char)CScript::DecodeOP_N(opcode1); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1296 vSolutionsRet.push_back(valtype(1, n)); |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1297 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1298 else |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1299 break; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1300 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1301 else if (opcode1 != opcode2 || vch1 != vch2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1302 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1303 // Others must match exactly |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1304 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1305 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1306 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1307 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1308 |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1309 vSolutionsRet.clear(); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1310 typeRet = TX_NONSTANDARD; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1311 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1312 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1313 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1314 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1315 bool Sign1(const CBitcoinAddress& address, const CKeyStore& keystore, uint256 hash, int nHashType, CScript& scriptSigRet) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1316 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1317 CKey key; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1318 if (!keystore.GetKey(address, key)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1319 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1320 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1321 vector<unsigned char> vchSig; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1322 if (!key.Sign(hash, vchSig)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1323 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1324 vchSig.push_back((unsigned char)nHashType); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1325 scriptSigRet << vchSig; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1326 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1327 return true; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1328 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1329 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1330 bool SignN(const vector<valtype>& multisigdata, const CKeyStore& keystore, uint256 hash, int nHashType, CScript& scriptSigRet) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1331 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1332 int nSigned = 0; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1333 int nRequired = multisigdata.front()[0]; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1334 for (vector<valtype>::const_iterator it = multisigdata.begin()+1; it != multisigdata.begin()+multisigdata.size()-1; it++) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1335 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1336 const valtype& pubkey = *it; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1337 CBitcoinAddress address; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1338 address.SetPubKey(pubkey); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1339 if (Sign1(address, keystore, hash, nHashType, scriptSigRet)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1340 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1341 ++nSigned; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1342 if (nSigned == nRequired) break; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1343 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1344 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1345 return nSigned==nRequired; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1346 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1347 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1348 // |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1349 // Sign scriptPubKey with private keys stored in keystore, given transaction hash and hash type. |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1350 // Signatures are returned in scriptSigRet (or returns false if scriptPubKey can't be signed), |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1351 // unless whichTypeRet is TX_SCRIPTHASH, in which case scriptSigRet is the redemption script. |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1352 // Returns false if scriptPubKey could not be completely satisified. |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1353 // |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1354 bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash, int nHashType, |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1355 CScript& scriptSigRet, txnouttype& whichTypeRet) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1356 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1357 scriptSigRet.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1358 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1359 vector<valtype> vSolutions; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1360 if (!Solver(scriptPubKey, whichTypeRet, vSolutions)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1361 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1362 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1363 CBitcoinAddress address; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1364 switch (whichTypeRet) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1365 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1366 case TX_NONSTANDARD: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1367 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1368 case TX_PUBKEY: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1369 address.SetPubKey(vSolutions[0]); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1370 return Sign1(address, keystore, hash, nHashType, scriptSigRet); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1371 case TX_PUBKEYHASH: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1372 address.SetHash160(uint160(vSolutions[0])); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1373 if (!Sign1(address, keystore, hash, nHashType, scriptSigRet)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1374 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1375 else |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1376 { |
2687
2cca172f83a9
Encapsulate public keys in CPubKey
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2663
diff
changeset
|
1377 CPubKey vch; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1378 keystore.GetPubKey(address, vch); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1379 scriptSigRet << vch; |
892
51e9fb5de117
Fix rpc-hanging deadlocks
Gavin Andresen <gavinandresen@gmail.com>
parents:
846
diff
changeset
|
1380 } |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1381 return true; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1382 case TX_SCRIPTHASH: |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1383 return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1384 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1385 case TX_MULTISIG: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1386 scriptSigRet << OP_0; // workaround CHECKMULTISIG bug |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1387 return (SignN(vSolutions, keystore, hash, nHashType, scriptSigRet)); |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1388 } |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1389 return false; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1390 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1391 |
1769
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1392 int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions) |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1393 { |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1394 switch (t) |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1395 { |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1396 case TX_NONSTANDARD: |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1397 return -1; |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1398 case TX_PUBKEY: |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1399 return 1; |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1400 case TX_PUBKEYHASH: |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1401 return 2; |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1402 case TX_MULTISIG: |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1403 if (vSolutions.size() < 1 || vSolutions[0].size() < 1) |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1404 return -1; |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1405 return vSolutions[0][0] + 1; |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1406 case TX_SCRIPTHASH: |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1407 return 1; // doesn't include args needed by the script |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1408 } |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1409 return -1; |
73e4f1828765
Make transactions with extra data in their scriptSig's non-standard.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1752
diff
changeset
|
1410 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1411 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1412 bool IsStandard(const CScript& scriptPubKey) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1413 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1414 vector<valtype> vSolutions; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1415 txnouttype whichType; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1416 if (!Solver(scriptPubKey, whichType, vSolutions)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1417 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1418 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1419 if (whichType == TX_MULTISIG) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1420 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1421 unsigned char m = vSolutions.front()[0]; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1422 unsigned char n = vSolutions.back()[0]; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1423 // Support up to x-of-3 multisig txns as standard |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1424 if (n < 1 || n > 3) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1425 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1426 if (m < 1 || m > n) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1427 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1428 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1429 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1430 return whichType != TX_NONSTANDARD; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1431 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1432 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1433 |
2309
ce4d0278e085
SigOp and orphan-tx constants and counts are always unsigned.
Jeff Garzik <jeff@garzik.org>
parents:
2308
diff
changeset
|
1434 unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore) |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1435 { |
2309
ce4d0278e085
SigOp and orphan-tx constants and counts are always unsigned.
Jeff Garzik <jeff@garzik.org>
parents:
2308
diff
changeset
|
1436 unsigned int nResult = 0; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1437 BOOST_FOREACH(const valtype& pubkey, pubkeys) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1438 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1439 CBitcoinAddress address; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1440 address.SetPubKey(pubkey); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1441 if (keystore.HaveKey(address)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1442 ++nResult; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1443 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1444 return nResult; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1445 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1446 |
690 | 1447 bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1448 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1449 vector<valtype> vSolutions; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1450 txnouttype whichType; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1451 if (!Solver(scriptPubKey, whichType, vSolutions)) |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1452 return false; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1453 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1454 CBitcoinAddress address; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1455 switch (whichType) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1456 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1457 case TX_NONSTANDARD: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1458 return false; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1459 case TX_PUBKEY: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1460 address.SetPubKey(vSolutions[0]); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1461 return keystore.HaveKey(address); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1462 case TX_PUBKEYHASH: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1463 address.SetHash160(uint160(vSolutions[0])); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1464 return keystore.HaveKey(address); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1465 case TX_SCRIPTHASH: |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1466 { |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1467 CScript subscript; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1468 if (!keystore.GetCScript(uint160(vSolutions[0]), subscript)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1469 return false; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1470 return IsMine(keystore, subscript); |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1471 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1472 case TX_MULTISIG: |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1473 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1474 // Only consider transactions "mine" if we own ALL the |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1475 // keys involved. multi-signature transactions that are |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1476 // partially owned (somebody else has a key that can spend |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1477 // them) enable spend-out-from-under-you attacks, especially |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1478 // in shared-wallet situations. |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1479 vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1); |
1640
768b5a7944f0
make sure IsMine only returns true when we own all keys
coderrr <coderrr.contact@gmail.com>
parents:
1636
diff
changeset
|
1480 return HaveKeys(keys, keystore) == keys.size(); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1481 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1482 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1483 return false; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1484 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1485 |
1618
e16276182f0f
Fix broken ExtractAddress (refactored, made callers check for addresses in keystore if they care)
Gavin Andresen <gavinandresen@gmail.com>
parents:
1606
diff
changeset
|
1486 bool ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1487 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1488 vector<valtype> vSolutions; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1489 txnouttype whichType; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1490 if (!Solver(scriptPubKey, whichType, vSolutions)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1491 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1492 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1493 if (whichType == TX_PUBKEY) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1494 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1495 addressRet.SetPubKey(vSolutions[0]); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1496 return true; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1497 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1498 else if (whichType == TX_PUBKEYHASH) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1499 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1500 addressRet.SetHash160(uint160(vSolutions[0])); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1501 return true; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1502 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1503 else if (whichType == TX_SCRIPTHASH) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1504 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1505 addressRet.SetScriptHash160(uint160(vSolutions[0])); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1506 return true; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1507 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1508 // Multisig txns have more than one address... |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1509 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1510 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1511 |
1618
e16276182f0f
Fix broken ExtractAddress (refactored, made callers check for addresses in keystore if they care)
Gavin Andresen <gavinandresen@gmail.com>
parents:
1606
diff
changeset
|
1512 bool ExtractAddresses(const CScript& scriptPubKey, txnouttype& typeRet, vector<CBitcoinAddress>& addressRet, int& nRequiredRet) |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1513 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1514 addressRet.clear(); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1515 typeRet = TX_NONSTANDARD; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1516 vector<valtype> vSolutions; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1517 if (!Solver(scriptPubKey, typeRet, vSolutions)) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1518 return false; |
827
c418a20d8590
Bugfix: don't overuse limited ExtractAddress
Pieter Wuille <pieter.wuille@gmail.com>
parents:
815
diff
changeset
|
1519 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1520 if (typeRet == TX_MULTISIG) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1521 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1522 nRequiredRet = vSolutions.front()[0]; |
2308
eb0890ee717f
Prefer 'unsigned int' for loop index variables tested against ::size()
Jeff Garzik <jgarzik@exmulti.com>
parents:
2277
diff
changeset
|
1523 for (unsigned int i = 1; i < vSolutions.size()-1; i++) |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1524 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1525 CBitcoinAddress address; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1603
diff
changeset
|
1526 address.SetPubKey(vSolutions[i]); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1527 addressRet.push_back(address); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1528 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1529 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1530 else |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1531 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1532 nRequiredRet = 1; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1533 CBitcoinAddress address; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1534 if (typeRet == TX_PUBKEYHASH) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1535 address.SetHash160(uint160(vSolutions.front())); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1536 else if (typeRet == TX_SCRIPTHASH) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1537 address.SetScriptHash160(uint160(vSolutions.front())); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1538 else if (typeRet == TX_PUBKEY) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1539 address.SetPubKey(vSolutions.front()); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1540 addressRet.push_back(address); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1541 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1542 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1543 return true; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1544 } |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1545 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1546 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1547 bool fValidatePayToScriptHash, int nHashType) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1548 { |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1549 vector<vector<unsigned char> > stack, stackCopy; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1550 if (!EvalScript(stack, scriptSig, txTo, nIn, nHashType)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1551 return false; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1552 if (fValidatePayToScriptHash) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1553 stackCopy = stack; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1554 if (!EvalScript(stack, scriptPubKey, txTo, nIn, nHashType)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1555 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1556 if (stack.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1557 return false; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1558 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1559 if (CastToBool(stack.back()) == false) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1560 return false; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1561 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1562 // Additional validation for spend-to-script-hash transactions: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1563 if (fValidatePayToScriptHash && scriptPubKey.IsPayToScriptHash()) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1564 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1565 if (!scriptSig.IsPushOnly()) // scriptSig must be literals-only |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1566 return false; // or validation fails |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1567 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1568 const valtype& pubKeySerialized = stackCopy.back(); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1569 CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end()); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1570 popstack(stackCopy); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1571 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1572 if (!EvalScript(stackCopy, pubKey2, txTo, nIn, nHashType)) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1573 return false; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1574 if (stackCopy.empty()) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1575 return false; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1576 return CastToBool(stackCopy.back()); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1577 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1578 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1579 return true; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1580 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1581 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1582 |
1751
ec000d0b853b
Remove not-used-anywhere scriptPrereq from SignSignature()
Gavin Andresen <gavinandresen@gmail.com>
parents:
1640
diff
changeset
|
1583 bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1584 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1585 assert(nIn < txTo.vin.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1586 CTxIn& txin = txTo.vin[nIn]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1587 assert(txin.prevout.n < txFrom.vout.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1588 const CTxOut& txout = txFrom.vout[txin.prevout.n]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1589 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1590 // Leave out the signature from the hash, since a signature can't sign itself. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1591 // The checksig op will also drop the signatures from its hash. |
1751
ec000d0b853b
Remove not-used-anywhere scriptPrereq from SignSignature()
Gavin Andresen <gavinandresen@gmail.com>
parents:
1640
diff
changeset
|
1592 uint256 hash = SignatureHash(txout.scriptPubKey, txTo, nIn, nHashType); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1593 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1594 txnouttype whichType; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1595 if (!Solver(keystore, txout.scriptPubKey, hash, nHashType, txin.scriptSig, whichType)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1596 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1597 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1598 if (whichType == TX_SCRIPTHASH) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1599 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1600 // Solver returns the subscript that need to be evaluated; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1601 // the final scriptSig is the signatures from that |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1602 // and then the serialized subscript: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1603 CScript subscript = txin.scriptSig; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1604 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1605 // Recompute txn hash using subscript in place of scriptPubKey: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1606 uint256 hash2 = SignatureHash(subscript, txTo, nIn, nHashType); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1607 txnouttype subType; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1608 if (!Solver(keystore, subscript, hash2, nHashType, txin.scriptSig, subType)) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1609 return false; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1610 if (subType == TX_SCRIPTHASH) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1611 return false; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1612 txin.scriptSig << static_cast<valtype>(subscript); // Append serialized subscript |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1613 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1614 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1615 // Test solution |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1616 if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, true, 0)) |
1751
ec000d0b853b
Remove not-used-anywhere scriptPrereq from SignSignature()
Gavin Andresen <gavinandresen@gmail.com>
parents:
1640
diff
changeset
|
1617 return false; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1618 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1619 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1620 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1621 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1622 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1623 bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, bool fValidatePayToScriptHash, int nHashType) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1624 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1625 assert(nIn < txTo.vin.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1626 const CTxIn& txin = txTo.vin[nIn]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1627 if (txin.prevout.n >= txFrom.vout.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1628 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1629 const CTxOut& txout = txFrom.vout[txin.prevout.n]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1630 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1631 if (txin.prevout.hash != txFrom.GetHash()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1632 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1633 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1634 if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, fValidatePayToScriptHash, nHashType)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1635 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1636 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1637 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1638 } |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1639 |
2309
ce4d0278e085
SigOp and orphan-tx constants and counts are always unsigned.
Jeff Garzik <jeff@garzik.org>
parents:
2308
diff
changeset
|
1640 unsigned int CScript::GetSigOpCount(bool fAccurate) const |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1641 { |
2309
ce4d0278e085
SigOp and orphan-tx constants and counts are always unsigned.
Jeff Garzik <jeff@garzik.org>
parents:
2308
diff
changeset
|
1642 unsigned int n = 0; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1643 const_iterator pc = begin(); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1644 opcodetype lastOpcode = OP_INVALIDOPCODE; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1645 while (pc < end()) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1646 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1647 opcodetype opcode; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1648 if (!GetOp(pc, opcode)) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1649 break; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1650 if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1651 n++; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1652 else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1653 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1654 if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1655 n += DecodeOP_N(lastOpcode); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1656 else |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1657 n += 20; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1658 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1659 lastOpcode = opcode; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1660 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1661 return n; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1662 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1663 |
2309
ce4d0278e085
SigOp and orphan-tx constants and counts are always unsigned.
Jeff Garzik <jeff@garzik.org>
parents:
2308
diff
changeset
|
1664 unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1665 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1666 if (!IsPayToScriptHash()) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1667 return GetSigOpCount(true); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1668 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1669 // This is a pay-to-script-hash scriptPubKey; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1670 // get the last item that the scriptSig |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1671 // pushes onto the stack: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1672 const_iterator pc = scriptSig.begin(); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1673 vector<unsigned char> data; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1674 while (pc < scriptSig.end()) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1675 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1676 opcodetype opcode; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1677 if (!scriptSig.GetOp(pc, opcode, data)) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1678 return 0; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1679 if (opcode > OP_16) |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1680 return 0; |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1681 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1682 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1683 /// ... and return it's opcount: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1684 CScript subscript(data.begin(), data.end()); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1685 return subscript.GetSigOpCount(true); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1686 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1687 |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1688 bool CScript::IsPayToScriptHash() const |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1689 { |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1690 // Extra-fast test for pay-to-script-hash CScripts: |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1691 return (this->size() == 23 && |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1692 this->at(0) == OP_HASH160 && |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1693 this->at(1) == 0x14 && |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1694 this->at(22) == OP_EQUAL); |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1695 } |
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1696 |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1697 void CScript::SetBitcoinAddress(const CBitcoinAddress& address) |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1698 { |
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1699 this->clear(); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1700 if (address.IsScript()) |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1701 *this << OP_HASH160 << address.GetHash160() << OP_EQUAL; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1702 else |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1703 *this << OP_DUP << OP_HASH160 << address.GetHash160() << OP_EQUALVERIFY << OP_CHECKSIG; |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1704 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1705 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1706 void CScript::SetMultisig(int nRequired, const std::vector<CKey>& keys) |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1707 { |
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1708 this->clear(); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1709 |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1710 *this << EncodeOP_N(nRequired); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1711 BOOST_FOREACH(const CKey& key, keys) |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1712 *this << key.GetPubKey(); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1713 *this << EncodeOP_N(keys.size()) << OP_CHECKMULTISIG; |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1714 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1715 |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1716 void CScript::SetPayToScriptHash(const CScript& subscript) |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1717 { |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1718 assert(!subscript.empty()); |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1598
diff
changeset
|
1719 uint160 subscriptHash = Hash160(subscript); |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1720 this->clear(); |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1751
diff
changeset
|
1721 *this << OP_HASH160 << subscriptHash << OP_EQUAL; |
1598
057a59e89d51
Support 3 new multisignature IsStandard transactions
Gavin Andresen <gavinandresen@gmail.com>
parents:
1596
diff
changeset
|
1722 } |