16 #include <boost/foreach.hpp>
17 #include <boost/tuple/tuple.hpp>
18 #include <boost/tuple/tuple_comparison.hpp>
21 using namespace boost;
32 bool CheckSig(vector<unsigned char> vchSig,
const vector<unsigned char> &vchPubKey,
const CScript &scriptCode,
const CTransaction& txTo,
unsigned int nIn,
int nHashType,
int flags);
36 for (
unsigned int i = 0; i < vch.size(); i++)
41 if (i == vch.size()-1 && vch[i] == 0x80)
55 #define stacktop(i) (stack.at(stack.size()+(i)))
56 #define altstacktop(i) (altstack.at(altstack.size()+(i)))
57 static inline void popstack(vector<valtype>& stack)
60 throw runtime_error(
"popstack() : stack empty");
85 case OP_0 :
return "0";
91 case OP_1 :
return "1";
92 case OP_2 :
return "2";
93 case OP_3 :
return "3";
94 case OP_4 :
return "4";
95 case OP_5 :
return "5";
96 case OP_6 :
return "6";
97 case OP_7 :
return "7";
98 case OP_8 :
return "8";
99 case OP_9 :
return "9";
100 case OP_10 :
return "10";
101 case OP_11 :
return "11";
102 case OP_12 :
return "12";
103 case OP_13 :
return "13";
104 case OP_14 :
return "14";
105 case OP_15 :
return "15";
106 case OP_16 :
return "16";
109 case OP_NOP :
return "OP_NOP";
110 case OP_VER :
return "OP_VER";
111 case OP_IF :
return "OP_IF";
115 case OP_ELSE :
return "OP_ELSE";
124 case OP_2DUP :
return "OP_2DUP";
125 case OP_3DUP :
return "OP_3DUP";
127 case OP_2ROT :
return "OP_2ROT";
131 case OP_DROP :
return "OP_DROP";
132 case OP_DUP :
return "OP_DUP";
133 case OP_NIP :
return "OP_NIP";
134 case OP_OVER :
return "OP_OVER";
135 case OP_PICK :
return "OP_PICK";
136 case OP_ROLL :
return "OP_ROLL";
137 case OP_ROT :
return "OP_ROT";
138 case OP_SWAP :
return "OP_SWAP";
139 case OP_TUCK :
return "OP_TUCK";
142 case OP_CAT :
return "OP_CAT";
144 case OP_LEFT :
return "OP_LEFT";
146 case OP_SIZE :
return "OP_SIZE";
150 case OP_AND :
return "OP_AND";
151 case OP_OR :
return "OP_OR";
152 case OP_XOR :
return "OP_XOR";
159 case OP_1ADD :
return "OP_1ADD";
160 case OP_1SUB :
return "OP_1SUB";
161 case OP_2MUL :
return "OP_2MUL";
162 case OP_2DIV :
return "OP_2DIV";
164 case OP_ABS :
return "OP_ABS";
165 case OP_NOT :
return "OP_NOT";
167 case OP_ADD :
return "OP_ADD";
168 case OP_SUB :
return "OP_SUB";
169 case OP_MUL :
return "OP_MUL";
170 case OP_DIV :
return "OP_DIV";
171 case OP_MOD :
return "OP_MOD";
183 case OP_MIN :
return "OP_MIN";
184 case OP_MAX :
return "OP_MAX";
189 case OP_SHA1 :
return "OP_SHA1";
200 case OP_NOP1 :
return "OP_NOP1";
201 case OP_NOP2 :
return "OP_NOP2";
202 case OP_NOP3 :
return "OP_NOP3";
203 case OP_NOP4 :
return "OP_NOP4";
204 case OP_NOP5 :
return "OP_NOP5";
205 case OP_NOP6 :
return "OP_NOP6";
206 case OP_NOP7 :
return "OP_NOP7";
207 case OP_NOP8 :
return "OP_NOP8";
208 case OP_NOP9 :
return "OP_NOP9";
228 if (vchPubKey.size() < 33)
229 return error(
"Non-canonical public key: too short");
230 if (vchPubKey[0] == 0x04) {
231 if (vchPubKey.size() != 65)
232 return error(
"Non-canonical public key: invalid length for uncompressed key");
233 }
else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
234 if (vchPubKey.size() != 33)
235 return error(
"Non-canonical public key: invalid length for compressed key");
237 return error(
"Non-canonical public key: compressed nor uncompressed");
251 if (vchSig.size() < 9)
252 return error(
"Non-canonical signature: too short");
253 if (vchSig.size() > 73)
254 return error(
"Non-canonical signature: too long");
257 return error(
"Non-canonical signature: unknown hashtype byte");
258 if (vchSig[0] != 0x30)
259 return error(
"Non-canonical signature: wrong type");
260 if (vchSig[1] != vchSig.size()-3)
261 return error(
"Non-canonical signature: wrong length marker");
262 unsigned int nLenR = vchSig[3];
263 if (5 + nLenR >= vchSig.size())
264 return error(
"Non-canonical signature: S length misplaced");
265 unsigned int nLenS = vchSig[5+nLenR];
266 if ((
unsigned long)(nLenR+nLenS+7) != vchSig.size())
267 return error(
"Non-canonical signature: R+S length mismatch");
269 const unsigned char *R = &vchSig[4];
271 return error(
"Non-canonical signature: R value type mismatch");
273 return error(
"Non-canonical signature: R length is zero");
275 return error(
"Non-canonical signature: R value negative");
276 if (nLenR > 1 && (R[0] == 0x00) && !(R[1] & 0x80))
277 return error(
"Non-canonical signature: R value excessively padded");
279 const unsigned char *S = &vchSig[6+nLenR];
281 return error(
"Non-canonical signature: S value type mismatch");
283 return error(
"Non-canonical signature: S length is zero");
285 return error(
"Non-canonical signature: S value negative");
286 if (nLenS > 1 && (S[0] == 0x00) && !(S[1] & 0x80))
287 return error(
"Non-canonical signature: S value excessively padded");
291 return error(
"Non-canonical signature: S value odd");
297 bool EvalScript(vector<vector<unsigned char> >& stack,
const CScript& script,
const CTransaction& txTo,
unsigned int nIn,
unsigned int flags,
int nHashType)
299 CScript::const_iterator pc = script.begin();
300 CScript::const_iterator pend = script.end();
301 CScript::const_iterator pbegincodehash = script.begin();
305 vector<valtype> altstack;
306 if (script.size() > 10000)
314 bool fExec = !count(vfExec.begin(), vfExec.end(),
false);
319 if (!script.
GetOp(pc, opcode, vchPushValue))
325 if (opcode >
OP_16 && ++nOpCount > 201)
346 stack.push_back(vchPushValue);
373 stack.push_back(bn.
getvch());
393 if (stack.size() < 1)
401 vfExec.push_back(fValue);
409 vfExec.back() = !vfExec.back();
425 if (stack.size() < 1)
447 if (stack.size() < 1)
456 if (altstack.size() < 1)
466 if (stack.size() < 2)
476 if (stack.size() < 2)
480 stack.push_back(vch1);
481 stack.push_back(vch2);
488 if (stack.size() < 3)
493 stack.push_back(vch1);
494 stack.push_back(vch2);
495 stack.push_back(vch3);
502 if (stack.size() < 4)
506 stack.push_back(vch1);
507 stack.push_back(vch2);
514 if (stack.size() < 6)
518 stack.erase(stack.end()-6, stack.end()-4);
519 stack.push_back(vch1);
520 stack.push_back(vch2);
527 if (stack.size() < 4)
537 if (stack.size() < 1)
541 stack.push_back(vch);
549 stack.push_back(bn.getvch());
556 if (stack.size() < 1)
565 if (stack.size() < 1)
568 stack.push_back(vch);
575 if (stack.size() < 2)
577 stack.erase(stack.end() - 2);
584 if (stack.size() < 2)
587 stack.push_back(vch);
596 if (stack.size() < 2)
600 if (n < 0 || n >= (
int)stack.size())
604 stack.erase(stack.end()-n-1);
605 stack.push_back(vch);
614 if (stack.size() < 3)
624 if (stack.size() < 2)
633 if (stack.size() < 2)
636 stack.insert(stack.end()-2, vch);
644 if (stack.size() < 1)
647 stack.push_back(bn.
getvch());
660 if (stack.size() < 2)
664 bool fEqual = (vch1 == vch2);
695 if (stack.size() < 1)
706 default: assert(!
"invalid opcode");
break;
709 stack.push_back(bn.
getvch());
728 if (stack.size() < 2)
752 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2);
break;
753 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2);
break;
754 default: assert(!
"invalid opcode");
break;
758 stack.push_back(bn.
getvch());
773 if (stack.size() < 3)
778 bool fValue = (bn2 <= bn1 && bn1 < bn3);
797 if (stack.size() < 1)
802 RIPEMD160(&vch[0], vch.size(), &vchHash[0]);
804 SHA1(&vch[0], vch.size(), &vchHash[0]);
806 SHA256(&vch[0], vch.size(), &vchHash[0]);
810 memcpy(&vchHash[0], &hash160,
sizeof(hash160));
815 memcpy(&vchHash[0], &hash,
sizeof(hash));
818 stack.push_back(vchHash);
833 if (stack.size() < 2)
844 CScript scriptCode(pbegincodehash, pend);
850 CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
871 if ((
int)stack.size() < i)
875 if (nKeysCount < 0 || nKeysCount > 20)
877 nOpCount += nKeysCount;
882 if ((
int)stack.size() < i)
886 if (nSigsCount < 0 || nSigsCount > nKeysCount)
890 if ((
int)stack.size() < i)
894 CScript scriptCode(pbegincodehash, pend);
897 for (
int k = 0; k < nSigsCount; k++)
903 bool fSuccess =
true;
904 while (fSuccess && nSigsCount > 0)
911 CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
922 if (nSigsCount > nKeysCount)
945 if (stack.size() + altstack.size() > 1000)
971 class CTransactionSignatureSerializer {
975 const unsigned int nIn;
976 const bool fAnyoneCanPay;
977 const bool fHashSingle;
978 const bool fHashNone;
981 CTransactionSignatureSerializer(
const CTransaction &txToIn,
const CScript &scriptCodeIn,
unsigned int nInIn,
int nHashTypeIn) :
982 txTo(txToIn), scriptCode(scriptCodeIn), nIn(nInIn),
989 void SerializeScriptCode(S &s,
int nType,
int nVersion)
const {
990 CScript::const_iterator it = scriptCode.begin();
991 CScript::const_iterator itBegin = it;
993 unsigned int nCodeSeparators = 0;
994 while (scriptCode.
GetOp(it, opcode)) {
1000 while (scriptCode.
GetOp(it, opcode)) {
1002 s.write((
char*)&itBegin[0], it-itBegin-1);
1006 s.write((
char*)&itBegin[0], it-itBegin);
1010 template<
typename S>
1011 void SerializeInput(S &s,
unsigned int nInput,
int nType,
int nVersion)
const {
1022 SerializeScriptCode(s, nType, nVersion);
1024 if (nInput != nIn && (fHashSingle || fHashNone))
1032 template<
typename S>
1033 void SerializeOutput(S &s,
unsigned int nOutput,
int nType,
int nVersion)
const {
1034 if (fHashSingle && nOutput != nIn)
1042 template<
typename S>
1043 void Serialize(S &s,
int nType,
int nVersion)
const {
1047 unsigned int nInputs = fAnyoneCanPay ? 1 : txTo.
vin.size();
1049 for (
unsigned int nInput = 0; nInput < nInputs; nInput++)
1050 SerializeInput(s, nInput, nType, nVersion);
1052 unsigned int nOutputs = fHashNone ? 0 : (fHashSingle ? nIn+1 : txTo.
vout.size());
1054 for (
unsigned int nOutput = 0; nOutput < nOutputs; nOutput++)
1055 SerializeOutput(s, nOutput, nType, nVersion);
1064 if (nIn >= txTo.
vin.size()) {
1065 LogPrintf(
"ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
1071 if (nIn >= txTo.
vout.size()) {
1072 LogPrintf(
"ERROR: SignatureHash() : nOut=%d out of range\n", nIn);
1078 CTransactionSignatureSerializer txTmp(txTo, scriptCode, nIn, nHashType);
1082 ss << txTmp << nHashType;
1103 boost::shared_lock<boost::shared_mutex> lock(cs_sigcache);
1105 sigdata_type k(hash, vchSig, pubKey);
1106 std::set<sigdata_type>::iterator mi = setValid.find(k);
1107 if (mi != setValid.end())
1118 int64_t nMaxCacheSize =
GetArg(
"-maxsigcachesize", 50000);
1119 if (nMaxCacheSize <= 0)
return;
1121 boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
1123 while (static_cast<int64_t>(setValid.size()) > nMaxCacheSize)
1130 std::vector<unsigned char> unused;
1131 std::set<sigdata_type>::iterator it =
1132 setValid.lower_bound(sigdata_type(randomHash, unused, unused));
1133 if (it == setValid.end())
1134 it = setValid.begin();
1135 setValid.erase(*it);
1138 sigdata_type k(hash, vchSig, pubKey);
1143 bool CheckSig(vector<unsigned char> vchSig,
const vector<unsigned char> &vchPubKey,
const CScript &scriptCode,
1144 const CTransaction& txTo,
unsigned int nIn,
int nHashType,
int flags)
1156 nHashType = vchSig.back();
1157 else if (nHashType != vchSig.back())
1163 if (signatureCache.
Get(sighash, vchSig, pubkey))
1166 if (!pubkey.
Verify(sighash, vchSig))
1170 signatureCache.
Set(sighash, vchSig, pubkey);
1189 static multimap<txnouttype, CScript> mTemplates;
1190 if (mTemplates.empty())
1211 vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
1212 vSolutionsRet.push_back(hashBytes);
1217 const CScript& script1 = scriptPubKey;
1220 const CScript& script2 = tplate.second;
1221 vSolutionsRet.clear();
1224 vector<unsigned char> vch1, vch2;
1227 CScript::const_iterator pc1 = script1.begin();
1228 CScript::const_iterator pc2 = script2.begin();
1231 if (pc1 == script1.end() && pc2 == script2.end())
1234 typeRet = tplate.first;
1238 unsigned char m = vSolutionsRet.front()[0];
1239 unsigned char n = vSolutionsRet.back()[0];
1240 if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
1245 if (!script1.
GetOp(pc1, opcode1, vch1))
1247 if (!script2.
GetOp(pc2, opcode2, vch2))
1253 while (vch1.size() >= 33 && vch1.size() <= 65)
1255 vSolutionsRet.push_back(vch1);
1256 if (!script1.
GetOp(pc1, opcode1, vch1))
1259 if (!script2.
GetOp(pc2, opcode2, vch2))
1267 if (vch1.size() < 33 || vch1.size() > 65)
1269 vSolutionsRet.push_back(vch1);
1273 if (vch1.size() !=
sizeof(
uint160))
1275 vSolutionsRet.push_back(vch1);
1279 if (opcode1 ==
OP_0 ||
1283 vSolutionsRet.push_back(
valtype(1, n));
1294 else if (opcode1 != opcode2 || vch1 != vch2)
1302 vSolutionsRet.clear();
1311 if (!keystore.
GetKey(address, key))
1314 vector<unsigned char> vchSig;
1315 if (!key.
Sign(hash, vchSig))
1317 vchSig.push_back((
unsigned char)nHashType);
1318 scriptSigRet << vchSig;
1326 int nRequired = multisigdata.front()[0];
1327 for (
unsigned int i = 1; i < multisigdata.size()-1 && nSigned < nRequired; i++)
1329 const valtype& pubkey = multisigdata[i];
1331 if (
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
1334 return nSigned==nRequired;
1346 scriptSigRet.clear();
1348 vector<valtype> vSolutions;
1349 if (!
Solver(scriptPubKey, whichTypeRet, vSolutions))
1353 switch (whichTypeRet)
1360 return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
1363 if (!
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
1369 scriptSigRet << vch;
1376 scriptSigRet <<
OP_0;
1377 return (
SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
1394 if (vSolutions.size() < 1 || vSolutions[0].size() < 1)
1396 return vSolutions[0][0] + 1;
1405 vector<valtype> vSolutions;
1406 if (!
Solver(scriptPubKey, whichType, vSolutions))
1411 unsigned char m = vSolutions.front()[0];
1412 unsigned char n = vSolutions.back()[0];
1426 unsigned int nResult = 0;
1427 BOOST_FOREACH(
const valtype& pubkey, pubkeys)
1455 vector<valtype> vSolutions;
1457 if (!
Solver(scriptPubKey, whichType, vSolutions))
1468 return keystore.
HaveKey(keyID);
1471 return keystore.
HaveKey(keyID);
1477 return IsMine(keystore, subscript);
1486 vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
1487 return HaveKeys(keys, keystore) == keys.size();
1495 vector<valtype> vSolutions;
1497 if (!
Solver(scriptPubKey, whichType, vSolutions))
1523 vector<valtype> vSolutions;
1524 if (!
Solver(scriptPubKey, typeRet, vSolutions))
1533 nRequiredRet = vSolutions.front()[0];
1534 for (
unsigned int i = 1; i < vSolutions.size()-1; i++)
1537 addressRet.push_back(address);
1546 addressRet.push_back(address);
1562 std::vector<CTxDestination> vDest;
1566 boost::apply_visitor(*
this, dest);
1572 vKeys.push_back(keyId);
1589 unsigned int flags,
int nHashType)
1591 vector<vector<unsigned char> > stack, stackCopy;
1592 if (!
EvalScript(stack, scriptSig, txTo, nIn, flags, nHashType))
1596 if (!
EvalScript(stack, scriptPubKey, txTo, nIn, flags, nHashType))
1613 assert(!stackCopy.empty());
1615 const valtype& pubKeySerialized = stackCopy.back();
1616 CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
1619 if (!
EvalScript(stackCopy, pubKey2, txTo, nIn, flags, nHashType))
1621 if (stackCopy.empty())
1632 assert(nIn < txTo.
vin.size());
1640 if (!
Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType))
1648 CScript subscript = txin.scriptSig;
1655 Solver(keystore, subscript, hash2, nHashType, txin.scriptSig, subType) && subType !=
TX_SCRIPTHASH;
1657 txin.scriptSig <<
static_cast<valtype>(subscript);
1658 if (!fSolved)
return false;
1667 assert(nIn < txTo.
vin.size());
1669 assert(txin.prevout.n < txFrom.
vout.size());
1670 const CTxOut& txout = txFrom.
vout[txin.prevout.n];
1672 return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, nHashType);
1678 BOOST_FOREACH(
const valtype& v, values)
1684 const vector<valtype>& vSolutions,
1685 vector<valtype>& sigs1, vector<valtype>& sigs2)
1688 set<valtype> allsigs;
1689 BOOST_FOREACH(
const valtype& v, sigs1)
1694 BOOST_FOREACH(
const valtype& v, sigs2)
1701 assert(vSolutions.size() > 1);
1702 unsigned int nSigsRequired = vSolutions.front()[0];
1703 unsigned int nPubKeys = vSolutions.size()-2;
1704 map<valtype, valtype> sigs;
1705 BOOST_FOREACH(
const valtype& sig, allsigs)
1707 for (
unsigned int i = 0; i < nPubKeys; i++)
1709 const valtype& pubkey = vSolutions[i+1];
1710 if (sigs.count(pubkey))
1713 if (
CheckSig(sig, pubkey, scriptPubKey, txTo, nIn, 0, 0))
1721 unsigned int nSigsHave = 0;
1723 for (
unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++)
1725 if (sigs.count(vSolutions[i+1]))
1727 result << sigs[vSolutions[i+1]];
1732 for (
unsigned int i = nSigsHave; i < nSigsRequired; i++)
1739 const txnouttype txType,
const vector<valtype>& vSolutions,
1740 vector<valtype>& sigs1, vector<valtype>& sigs2)
1747 if (sigs1.size() >= sigs2.size())
1753 if (sigs1.empty() || sigs1[0].empty())
1757 if (sigs1.empty() || sigs1.back().empty())
1759 else if (sigs2.empty() || sigs2.back().empty())
1765 CScript pubKey2(spk.begin(), spk.end());
1768 vector<vector<unsigned char> > vSolutions2;
1769 Solver(pubKey2, txType2, vSolutions2);
1777 return CombineMultisig(scriptPubKey, txTo, nIn, vSolutions, sigs1, sigs2);
1787 vector<vector<unsigned char> > vSolutions;
1788 Solver(scriptPubKey, txType, vSolutions);
1790 vector<valtype> stack1;
1792 vector<valtype> stack2;
1795 return CombineSignatures(scriptPubKey, txTo, nIn, txType, vSolutions, stack1, stack2);
1801 const_iterator pc = begin();
1806 if (!GetOp(pc, opcode))
1812 if (fAccurate && lastOpcode >=
OP_1 && lastOpcode <=
OP_16)
1813 n += DecodeOP_N(lastOpcode);
1817 lastOpcode = opcode;
1824 if (!IsPayToScriptHash())
1825 return GetSigOpCount(
true);
1830 const_iterator pc = scriptSig.begin();
1831 vector<unsigned char>
data;
1832 while (pc < scriptSig.end())
1835 if (!scriptSig.
GetOp(pc, opcode, data))
1842 CScript subscript(data.begin(), data.end());
1849 return (this->size() == 23 &&
1851 this->at(1) == 0x14 &&
1857 const_iterator pc = begin();
1861 if (!GetOp(pc, opcode))
1875 const_iterator pc = begin();
1879 std::vector<unsigned char>
data;
1880 if (!GetOp(pc, opcode, data))
1884 if (opcode < OP_PUSHDATA1 && opcode >
OP_0 && (data.size() == 1 && data[0] <= 16))
1934 *
this << EncodeOP_N(nRequired);
1935 BOOST_FOREACH(
const CPubKey& key, keys)
1945 memcpy(&hash, &script[3], 20);
1953 if (script.size() == 23 && script[0] ==
OP_HASH160 && script[1] == 20
1955 memcpy(&hash, &script[2], 20);
1963 if (script.size() == 35 && script[0] == 33 && script[34] ==
OP_CHECKSIG
1964 && (script[1] == 0x02 || script[1] == 0x03)) {
1965 pubkey.
Set(&script[1], &script[34]);
1968 if (script.size() == 67 && script[0] == 65 && script[66] ==
OP_CHECKSIG
1969 && script[1] == 0x04) {
1970 pubkey.
Set(&script[1], &script[66]);
1979 if (IsToKeyID(keyID)) {
1982 memcpy(&out[1], &keyID, 20);
1986 if (IsToScriptID(scriptID)) {
1989 memcpy(&out[1], &scriptID, 20);
1993 if (IsToPubKey(pubkey)) {
1995 memcpy(&out[1], &pubkey[1], 32);
1996 if (pubkey[0] == 0x02 || pubkey[0] == 0x03) {
1999 }
else if (pubkey[0] == 0x04) {
2000 out[0] = 0x04 | (pubkey[64] & 0x01);
2009 if (nSize == 0 || nSize == 1)
2011 if (nSize == 2 || nSize == 3 || nSize == 4 || nSize == 5)
2024 memcpy(&script[3], &in[0], 20);
2032 memcpy(&script[2], &in[0], 20);
2040 memcpy(&script[2], &in[0], 32);
2045 unsigned char vch[33] = {};
2047 memcpy(&vch[1], &in[0], 32);
2048 CPubKey pubkey(&vch[0], &vch[33]);
2051 assert(pubkey.
size() == 65);
bool IsToKeyID(CKeyID &hash) const
bool operator()(const CScriptID &scriptID) const
bool operator()(const CNoDestination &dest) const
static int DecodeOP_N(opcodetype opcode)
bool Get(const uint256 &hash, const std::vector< unsigned char > &vchSig, const CPubKey &pubKey)
void Process(const CScript &script)
static CScript CombineSignatures(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const txnouttype txType, const vector< valtype > &vSolutions, vector< valtype > &sigs1, vector< valtype > &sigs2)
CScriptVisitor(CScript *scriptin)
const CKeyStore * keystore
static CScript PushAll(const vector< valtype > &values)
static const unsigned int MAX_OP_RETURN_RELAY
bool Compress(std::vector< unsigned char > &out) const
bool IsPayToScriptHash() const
void Serialize(Stream &s, char a, int, int=0)
unsigned int GetSpecialSize(unsigned int nSize) const
bool SignN(const vector< valtype > &multisigdata, const CKeyStore &keystore, uint256 hash, int nHashType, CScript &scriptSigRet)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType)
unsigned int size() const
void Set(const T pbegin, const T pend)
bool IsToPubKey(CPubKey &pubkey) const
boost::shared_mutex cs_sigcache
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig) const
const char * GetTxnOutputType(txnouttype t)
uint160 Hash160(const T1 pbegin, const T1 pend)
static CScript CombineMultisig(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const vector< valtype > &vSolutions, vector< valtype > &sigs1, vector< valtype > &sigs2)
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
bool operator()(const CNoDestination &dest) const
bool IsCanonicalPubKey(const valtype &vchPubKey, unsigned int flags)
virtual bool HaveCScript(const CScriptID &hash) const =0
int ScriptSigArgsExpected(txnouttype t, const std::vector< std::vector< unsigned char > > &vSolutions)
void operator()(const CNoDestination &none)
unsigned int HaveKeys(const vector< valtype > &pubkeys, const CKeyStore &keystore)
void SetDestination(const CTxDestination &address)
CKeyStoreIsMineVisitor(const CKeyStore *keystoreIn)
opcodetype
Script opcodes.
static const valtype vchTrue(1, 1)
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
An input of a transaction.
bool IsCanonicalSignature(const valtype &vchSig, unsigned int flags)
unsigned int GetSigOpCount(bool fAccurate) const
bool IsToScriptID(CScriptID &hash) const
std::vector< CTxOut > vout
void operator()(const CScriptID &scriptId)
bool CheckSig(vector< unsigned char > vchSig, const vector< unsigned char > &vchPubKey, const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, int flags)
virtual bool HaveKey(const CKeyID &address) const =0
An encapsulated public key.
static bool error(const char *format)
static const CScriptNum bnZero(0)
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, vector< vector< unsigned char > > &vSolutionsRet)
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const =0
bool operator()(const CKeyID &keyID) const
static const valtype vchFalse(0)
uint256 Hash(const T1 pbegin, const T1 pend)
static const CScriptNum bnOne(1)
An output of a transaction.
static const CScriptNum bnTrue(1)
bool EvalScript(vector< vector< unsigned char > > &stack, const CScript &script, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
bool CastToBool(const valtype &vch)
std::set< sigdata_type > setValid
const unsigned char * begin() const
const char * GetOpName(opcodetype opcode)
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
boost::tuple< uint256, std::vector< unsigned char >, CPubKey > sigdata_type
Serialized script, used inside transaction inputs and outputs.
bool Decompress(unsigned int nSize, const std::vector< unsigned char > &out)
void * memcpy(void *a, const void *b, size_t c)
A virtual base class for key stores.
void SetMultisig(int nRequired, const std::vector< CPubKey > &keys)
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
bool IsMine(const CKeyStore &keystore, const CTxDestination &dest)
A reference to a CKey: the Hash160 of its serialized public key.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
std::vector< unsigned char > getvch() const
bool IsFullyValid() const
bool Sign1(const CKeyID &address, const CKeyStore &keystore, uint256 hash, int nHashType, CScript &scriptSigRet)
int FindAndDelete(const CScript &b)
void operator()(const CKeyID &keyId)
static void popstack(vector< valtype > &stack)
static const valtype vchZero(0)
bool IsStandard(const CScript &scriptPubKey, txnouttype &whichType)
bool operator()(const CKeyID &keyID) const
A reference to a CScript: the Hash160 of its serialization (see script.h)
std::vector< CKeyID > & vKeys
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
void Set(const uint256 &hash, const std::vector< unsigned char > &vchSig, const CPubKey &pubKey)
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
static const CCheckpointData data
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
void WriteCompactSize(Stream &os, uint64_t nSize)
vector< unsigned char > valtype
void ExtractAffectedKeys(const CKeyStore &keystore, const CScript &scriptPubKey, std::vector< CKeyID > &vKeys)
bool HasCanonicalPushes() const
static const CScriptNum bnFalse(0)
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector< CKeyID > &vKeysIn)
const CKeyStore & keystore
bool operator()(const CScriptID &scriptID) const