17 #include <boost/foreach.hpp>
18 #include <boost/tuple/tuple.hpp>
19 #include <boost/tuple/tuple_comparison.hpp>
22 using namespace boost;
25 static const valtype vchFalse(0);
26 static const valtype vchZero(0);
27 static const valtype vchTrue(1, 1);
33 bool CheckSig(vector<unsigned char> vchSig,
const vector<unsigned char> &vchPubKey,
const CScript &scriptCode,
const CTransaction& txTo,
unsigned int nIn,
int nHashType,
int flags);
37 for (
unsigned int i = 0; i < vch.size(); i++)
42 if (i == vch.size()-1 && vch[i] == 0x80)
56 #define stacktop(i) (stack.at(stack.size()+(i)))
57 #define altstacktop(i) (altstack.at(altstack.size()+(i)))
58 static inline void popstack(vector<valtype>& stack)
61 throw runtime_error(
"popstack() : stack empty");
86 case OP_0 :
return "0";
92 case OP_1 :
return "1";
93 case OP_2 :
return "2";
94 case OP_3 :
return "3";
95 case OP_4 :
return "4";
96 case OP_5 :
return "5";
97 case OP_6 :
return "6";
98 case OP_7 :
return "7";
99 case OP_8 :
return "8";
100 case OP_9 :
return "9";
101 case OP_10 :
return "10";
102 case OP_11 :
return "11";
103 case OP_12 :
return "12";
104 case OP_13 :
return "13";
105 case OP_14 :
return "14";
106 case OP_15 :
return "15";
107 case OP_16 :
return "16";
110 case OP_NOP :
return "OP_NOP";
111 case OP_VER :
return "OP_VER";
112 case OP_IF :
return "OP_IF";
116 case OP_ELSE :
return "OP_ELSE";
125 case OP_2DUP :
return "OP_2DUP";
126 case OP_3DUP :
return "OP_3DUP";
128 case OP_2ROT :
return "OP_2ROT";
132 case OP_DROP :
return "OP_DROP";
133 case OP_DUP :
return "OP_DUP";
134 case OP_NIP :
return "OP_NIP";
135 case OP_OVER :
return "OP_OVER";
136 case OP_PICK :
return "OP_PICK";
137 case OP_ROLL :
return "OP_ROLL";
138 case OP_ROT :
return "OP_ROT";
139 case OP_SWAP :
return "OP_SWAP";
140 case OP_TUCK :
return "OP_TUCK";
143 case OP_CAT :
return "OP_CAT";
145 case OP_LEFT :
return "OP_LEFT";
147 case OP_SIZE :
return "OP_SIZE";
151 case OP_AND :
return "OP_AND";
152 case OP_OR :
return "OP_OR";
153 case OP_XOR :
return "OP_XOR";
160 case OP_1ADD :
return "OP_1ADD";
161 case OP_1SUB :
return "OP_1SUB";
162 case OP_2MUL :
return "OP_2MUL";
163 case OP_2DIV :
return "OP_2DIV";
165 case OP_ABS :
return "OP_ABS";
166 case OP_NOT :
return "OP_NOT";
168 case OP_ADD :
return "OP_ADD";
169 case OP_SUB :
return "OP_SUB";
170 case OP_MUL :
return "OP_MUL";
171 case OP_DIV :
return "OP_DIV";
172 case OP_MOD :
return "OP_MOD";
184 case OP_MIN :
return "OP_MIN";
185 case OP_MAX :
return "OP_MAX";
190 case OP_SHA1 :
return "OP_SHA1";
201 case OP_NOP1 :
return "OP_NOP1";
202 case OP_NOP2 :
return "OP_NOP2";
203 case OP_NOP3 :
return "OP_NOP3";
204 case OP_NOP4 :
return "OP_NOP4";
205 case OP_NOP5 :
return "OP_NOP5";
206 case OP_NOP6 :
return "OP_NOP6";
207 case OP_NOP7 :
return "OP_NOP7";
208 case OP_NOP8 :
return "OP_NOP8";
209 case OP_NOP9 :
return "OP_NOP9";
229 if (vchPubKey.size() < 33)
230 return error(
"Non-canonical public key: too short");
231 if (vchPubKey[0] == 0x04) {
232 if (vchPubKey.size() != 65)
233 return error(
"Non-canonical public key: invalid length for uncompressed key");
234 }
else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
235 if (vchPubKey.size() != 33)
236 return error(
"Non-canonical public key: invalid length for compressed key");
238 return error(
"Non-canonical public key: compressed nor uncompressed");
252 if (vchSig.size() < 9)
253 return error(
"Non-canonical signature: too short");
254 if (vchSig.size() > 73)
255 return error(
"Non-canonical signature: too long");
258 return error(
"Non-canonical signature: unknown hashtype byte");
259 if (vchSig[0] != 0x30)
260 return error(
"Non-canonical signature: wrong type");
261 if (vchSig[1] != vchSig.size()-3)
262 return error(
"Non-canonical signature: wrong length marker");
263 unsigned int nLenR = vchSig[3];
264 if (5 + nLenR >= vchSig.size())
265 return error(
"Non-canonical signature: S length misplaced");
266 unsigned int nLenS = vchSig[5+nLenR];
267 if ((
unsigned long)(nLenR+nLenS+7) != vchSig.size())
268 return error(
"Non-canonical signature: R+S length mismatch");
270 const unsigned char *R = &vchSig[4];
272 return error(
"Non-canonical signature: R value type mismatch");
274 return error(
"Non-canonical signature: R length is zero");
276 return error(
"Non-canonical signature: R value negative");
277 if (nLenR > 1 && (R[0] == 0x00) && !(R[1] & 0x80))
278 return error(
"Non-canonical signature: R value excessively padded");
280 const unsigned char *S = &vchSig[6+nLenR];
282 return error(
"Non-canonical signature: S value type mismatch");
284 return error(
"Non-canonical signature: S length is zero");
286 return error(
"Non-canonical signature: S value negative");
287 if (nLenS > 1 && (S[0] == 0x00) && !(S[1] & 0x80))
288 return error(
"Non-canonical signature: S value excessively padded");
292 return error(
"Non-canonical signature: S value odd");
298 bool EvalScript(vector<vector<unsigned char> >& stack,
const CScript& script,
const CTransaction& txTo,
unsigned int nIn,
unsigned int flags,
int nHashType)
300 CScript::const_iterator pc = script.begin();
301 CScript::const_iterator pend = script.end();
302 CScript::const_iterator pbegincodehash = script.begin();
306 vector<valtype> altstack;
307 if (script.size() > 10000)
315 bool fExec = !count(vfExec.begin(), vfExec.end(),
false);
320 if (!script.
GetOp(pc, opcode, vchPushValue))
322 if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE)
326 if (opcode >
OP_16 && ++nOpCount > 201)
347 stack.push_back(vchPushValue);
374 stack.push_back(bn.
getvch());
394 if (stack.size() < 1)
402 vfExec.push_back(fValue);
410 vfExec.back() = !vfExec.back();
426 if (stack.size() < 1)
448 if (stack.size() < 1)
457 if (altstack.size() < 1)
467 if (stack.size() < 2)
477 if (stack.size() < 2)
481 stack.push_back(vch1);
482 stack.push_back(vch2);
489 if (stack.size() < 3)
494 stack.push_back(vch1);
495 stack.push_back(vch2);
496 stack.push_back(vch3);
503 if (stack.size() < 4)
507 stack.push_back(vch1);
508 stack.push_back(vch2);
515 if (stack.size() < 6)
519 stack.erase(stack.end()-6, stack.end()-4);
520 stack.push_back(vch1);
521 stack.push_back(vch2);
528 if (stack.size() < 4)
538 if (stack.size() < 1)
542 stack.push_back(vch);
550 stack.push_back(bn.getvch());
557 if (stack.size() < 1)
566 if (stack.size() < 1)
569 stack.push_back(vch);
576 if (stack.size() < 2)
578 stack.erase(stack.end() - 2);
585 if (stack.size() < 2)
588 stack.push_back(vch);
597 if (stack.size() < 2)
601 if (n < 0 || n >= (
int)stack.size())
605 stack.erase(stack.end()-n-1);
606 stack.push_back(vch);
615 if (stack.size() < 3)
625 if (stack.size() < 2)
634 if (stack.size() < 2)
637 stack.insert(stack.end()-2, vch);
645 if (stack.size() < 1)
648 stack.push_back(bn.
getvch());
661 if (stack.size() < 2)
665 bool fEqual = (vch1 == vch2);
673 stack.push_back(fEqual ? vchTrue : vchFalse);
696 if (stack.size() < 1)
701 case OP_1ADD: bn += bnOne;
break;
702 case OP_1SUB: bn -= bnOne;
break;
704 case OP_ABS:
if (bn < bnZero) bn = -bn;
break;
705 case OP_NOT: bn = (bn == bnZero);
break;
707 default: assert(!
"invalid opcode");
break;
710 stack.push_back(bn.
getvch());
729 if (stack.size() < 2)
744 case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero);
break;
745 case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero);
break;
753 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2);
break;
754 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2);
break;
755 default: assert(!
"invalid opcode");
break;
759 stack.push_back(bn.
getvch());
774 if (stack.size() < 3)
779 bool fValue = (bn2 <= bn1 && bn1 < bn3);
783 stack.push_back(fValue ? vchTrue : vchFalse);
798 if (stack.size() < 1)
803 RIPEMD160(&vch[0], vch.size(), &vchHash[0]);
805 SHA1(&vch[0], vch.size(), &vchHash[0]);
807 SHA256(&vch[0], vch.size(), &vchHash[0]);
811 memcpy(&vchHash[0], &hash160,
sizeof(hash160));
816 memcpy(&vchHash[0], &hash,
sizeof(hash));
819 stack.push_back(vchHash);
834 if (stack.size() < 2)
845 CScript scriptCode(pbegincodehash, pend);
851 CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
855 stack.push_back(fSuccess ? vchTrue : vchFalse);
872 if ((
int)stack.size() < i)
876 if (nKeysCount < 0 || nKeysCount > 20)
878 nOpCount += nKeysCount;
883 if ((
int)stack.size() < i)
887 if (nSigsCount < 0 || nSigsCount > nKeysCount)
891 if ((
int)stack.size() < i)
895 CScript scriptCode(pbegincodehash, pend);
898 for (
int k = 0; k < nSigsCount; k++)
904 bool fSuccess =
true;
905 while (fSuccess && nSigsCount > 0)
912 CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
923 if (nSigsCount > nKeysCount)
929 stack.push_back(fSuccess ? vchTrue : vchFalse);
946 if (stack.size() + altstack.size() > 1000)
972 class CTransactionSignatureSerializer {
976 const unsigned int nIn;
977 const bool fAnyoneCanPay;
978 const bool fHashSingle;
979 const bool fHashNone;
982 CTransactionSignatureSerializer(
const CTransaction &txToIn,
const CScript &scriptCodeIn,
unsigned int nInIn,
int nHashTypeIn) :
983 txTo(txToIn), scriptCode(scriptCodeIn), nIn(nInIn),
990 void SerializeScriptCode(S &s,
int nType,
int nVersion)
const {
991 CScript::const_iterator it = scriptCode.begin();
992 CScript::const_iterator itBegin = it;
994 unsigned int nCodeSeparators = 0;
995 while (scriptCode.
GetOp(it, opcode)) {
1001 while (scriptCode.
GetOp(it, opcode)) {
1003 s.write((
char*)&itBegin[0], it-itBegin-1);
1007 s.write((
char*)&itBegin[0], it-itBegin);
1011 template<
typename S>
1012 void SerializeInput(S &s,
unsigned int nInput,
int nType,
int nVersion)
const {
1023 SerializeScriptCode(s, nType, nVersion);
1025 if (nInput != nIn && (fHashSingle || fHashNone))
1033 template<
typename S>
1034 void SerializeOutput(S &s,
unsigned int nOutput,
int nType,
int nVersion)
const {
1035 if (fHashSingle && nOutput != nIn)
1043 template<
typename S>
1044 void Serialize(S &s,
int nType,
int nVersion)
const {
1048 unsigned int nInputs = fAnyoneCanPay ? 1 : txTo.
vin.size();
1050 for (
unsigned int nInput = 0; nInput < nInputs; nInput++)
1051 SerializeInput(s, nInput, nType, nVersion);
1053 unsigned int nOutputs = fHashNone ? 0 : (fHashSingle ? nIn+1 : txTo.
vout.size());
1055 for (
unsigned int nOutput = 0; nOutput < nOutputs; nOutput++)
1056 SerializeOutput(s, nOutput, nType, nVersion);
1065 if (nIn >= txTo.
vin.size()) {
1066 LogPrintf(
"ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
1072 if (nIn >= txTo.
vout.size()) {
1073 LogPrintf(
"ERROR: SignatureHash() : nOut=%d out of range\n", nIn);
1079 CTransactionSignatureSerializer txTmp(txTo, scriptCode, nIn, nHashType);
1083 ss << txTmp << nHashType;
1104 boost::shared_lock<boost::shared_mutex> lock(cs_sigcache);
1106 sigdata_type k(hash, vchSig, pubKey);
1107 std::set<sigdata_type>::iterator mi = setValid.find(k);
1108 if (mi != setValid.end())
1119 int64_t nMaxCacheSize =
GetArg(
"-maxsigcachesize", 50000);
1120 if (nMaxCacheSize <= 0)
return;
1122 boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
1124 while (static_cast<int64_t>(setValid.size()) > nMaxCacheSize)
1131 std::vector<unsigned char> unused;
1132 std::set<sigdata_type>::iterator it =
1133 setValid.lower_bound(sigdata_type(randomHash, unused, unused));
1134 if (it == setValid.end())
1135 it = setValid.begin();
1136 setValid.erase(*it);
1139 sigdata_type k(hash, vchSig, pubKey);
1144 bool CheckSig(vector<unsigned char> vchSig,
const vector<unsigned char> &vchPubKey,
const CScript &scriptCode,
1145 const CTransaction& txTo,
unsigned int nIn,
int nHashType,
int flags)
1157 nHashType = vchSig.back();
1158 else if (nHashType != vchSig.back())
1164 if (signatureCache.
Get(sighash, vchSig, pubkey))
1167 if (!pubkey.
Verify(sighash, vchSig))
1171 signatureCache.
Set(sighash, vchSig, pubkey);
1190 static multimap<txnouttype, CScript> mTemplates;
1191 if (mTemplates.empty())
1213 vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
1214 vSolutionsRet.push_back(hashBytes);
1219 const CScript& script1 = scriptPubKey;
1222 const CScript& script2 = tplate.second;
1223 vSolutionsRet.clear();
1226 vector<unsigned char> vch1, vch2;
1229 CScript::const_iterator pc1 = script1.begin();
1230 CScript::const_iterator pc2 = script2.begin();
1233 if (pc1 == script1.end() && pc2 == script2.end())
1236 typeRet = tplate.first;
1240 unsigned char m = vSolutionsRet.front()[0];
1241 unsigned char n = vSolutionsRet.back()[0];
1242 if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
1247 if (!script1.
GetOp(pc1, opcode1, vch1))
1249 if (!script2.
GetOp(pc2, opcode2, vch2))
1255 while (vch1.size() >= 33 && vch1.size() <= 65)
1257 vSolutionsRet.push_back(vch1);
1258 if (!script1.
GetOp(pc1, opcode1, vch1))
1261 if (!script2.
GetOp(pc2, opcode2, vch2))
1269 if (vch1.size() < 33 || vch1.size() > 65)
1271 vSolutionsRet.push_back(vch1);
1275 if (vch1.size() !=
sizeof(
uint160))
1277 vSolutionsRet.push_back(vch1);
1281 if (opcode1 ==
OP_0 ||
1285 vSolutionsRet.push_back(
valtype(1, n));
1293 if (vch1.size() > MAX_OP_RETURN_RELAY)
1296 else if (opcode1 != opcode2 || vch1 != vch2)
1304 vSolutionsRet.clear();
1313 if (!keystore.
GetKey(address, key))
1316 vector<unsigned char> vchSig;
1317 if (!key.
Sign(hash, vchSig))
1319 vchSig.push_back((
unsigned char)nHashType);
1320 scriptSigRet << vchSig;
1328 int nRequired = multisigdata.front()[0];
1329 for (
unsigned int i = 1; i < multisigdata.size()-1 && nSigned < nRequired; i++)
1331 const valtype& pubkey = multisigdata[i];
1333 if (
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
1336 return nSigned==nRequired;
1348 scriptSigRet.clear();
1350 vector<valtype> vSolutions;
1351 if (!
Solver(scriptPubKey, whichTypeRet, vSolutions))
1355 switch (whichTypeRet)
1362 return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
1365 if (!
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
1371 scriptSigRet << vch;
1378 scriptSigRet <<
OP_0;
1379 return (
SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
1396 if (vSolutions.size() < 1 || vSolutions[0].size() < 1)
1398 return vSolutions[0][0] + 1;
1407 vector<valtype> vSolutions;
1408 if (!
Solver(scriptPubKey, whichType, vSolutions))
1413 unsigned char m = vSolutions.front()[0];
1414 unsigned char n = vSolutions.back()[0];
1428 unsigned int nResult = 0;
1429 BOOST_FOREACH(
const valtype& pubkey, pubkeys)
1454 return IsMine(keystore, script);
1459 vector<valtype> vSolutions;
1461 if (!
Solver(scriptPubKey, whichType, vSolutions)) {
1487 if (keystore.
GetCScript(scriptID, subscript)) {
1501 vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
1502 if (
HaveKeys(keys, keystore) == keys.size())
1515 vector<valtype> vSolutions;
1517 if (!
Solver(scriptPubKey, whichType, vSolutions))
1543 vector<valtype> vSolutions;
1544 if (!
Solver(scriptPubKey, typeRet, vSolutions))
1553 nRequiredRet = vSolutions.front()[0];
1554 for (
unsigned int i = 1; i < vSolutions.size()-1; i++)
1557 addressRet.push_back(address);
1566 addressRet.push_back(address);
1582 std::vector<CTxDestination> vDest;
1586 boost::apply_visitor(*
this, dest);
1592 vKeys.push_back(keyId);
1609 unsigned int flags,
int nHashType)
1611 vector<vector<unsigned char> > stack, stackCopy;
1612 if (!
EvalScript(stack, scriptSig, txTo, nIn, flags, nHashType))
1616 if (!
EvalScript(stack, scriptPubKey, txTo, nIn, flags, nHashType))
1633 assert(!stackCopy.empty());
1635 const valtype& pubKeySerialized = stackCopy.back();
1636 CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
1637 popstack(stackCopy);
1639 if (!
EvalScript(stackCopy, pubKey2, txTo, nIn, flags, nHashType))
1641 if (stackCopy.empty())
1652 assert(nIn < txTo.
vin.size());
1660 if (!
Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType))
1668 CScript subscript = txin.scriptSig;
1675 Solver(keystore, subscript, hash2, nHashType, txin.scriptSig, subType) && subType !=
TX_SCRIPTHASH;
1677 txin.scriptSig <<
static_cast<valtype>(subscript);
1678 if (!fSolved)
return false;
1687 assert(nIn < txTo.
vin.size());
1689 assert(txin.prevout.n < txFrom.
vout.size());
1690 const CTxOut& txout = txFrom.
vout[txin.prevout.n];
1692 return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, nHashType);
1695 static CScript PushAll(
const vector<valtype>& values)
1698 BOOST_FOREACH(
const valtype& v, values)
1704 const vector<
valtype>& vSolutions,
1708 set<valtype> allsigs;
1709 BOOST_FOREACH(
const valtype& v, sigs1)
1714 BOOST_FOREACH(
const valtype& v, sigs2)
1721 assert(vSolutions.size() > 1);
1722 unsigned int nSigsRequired = vSolutions.front()[0];
1723 unsigned int nPubKeys = vSolutions.size()-2;
1724 map<valtype, valtype> sigs;
1725 BOOST_FOREACH(
const valtype& sig, allsigs)
1727 for (
unsigned int i = 0; i < nPubKeys; i++)
1729 const valtype& pubkey = vSolutions[i+1];
1730 if (sigs.count(pubkey))
1733 if (
CheckSig(sig, pubkey, scriptPubKey, txTo, nIn, 0, 0))
1741 unsigned int nSigsHave = 0;
1743 for (
unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++)
1745 if (sigs.count(vSolutions[i+1]))
1747 result << sigs[vSolutions[i+1]];
1752 for (
unsigned int i = nSigsHave; i < nSigsRequired; i++)
1759 const txnouttype txType,
const vector<valtype>& vSolutions,
1760 vector<valtype>& sigs1, vector<valtype>& sigs2)
1767 if (sigs1.size() >= sigs2.size())
1768 return PushAll(sigs1);
1769 return PushAll(sigs2);
1773 if (sigs1.empty() || sigs1[0].empty())
1774 return PushAll(sigs2);
1775 return PushAll(sigs1);
1777 if (sigs1.empty() || sigs1.back().empty())
1778 return PushAll(sigs2);
1779 else if (sigs2.empty() || sigs2.back().empty())
1780 return PushAll(sigs1);
1785 CScript pubKey2(spk.begin(), spk.end());
1788 vector<vector<unsigned char> > vSolutions2;
1789 Solver(pubKey2, txType2, vSolutions2);
1797 return CombineMultisig(scriptPubKey, txTo, nIn, vSolutions, sigs1, sigs2);
1807 vector<vector<unsigned char> > vSolutions;
1808 Solver(scriptPubKey, txType, vSolutions);
1810 vector<valtype> stack1;
1812 vector<valtype> stack2;
1815 return CombineSignatures(scriptPubKey, txTo, nIn, txType, vSolutions, stack1, stack2);
1821 const_iterator pc = begin();
1826 if (!GetOp(pc, opcode))
1832 if (fAccurate && lastOpcode >=
OP_1 && lastOpcode <=
OP_16)
1833 n += DecodeOP_N(lastOpcode);
1837 lastOpcode = opcode;
1844 if (!IsPayToScriptHash())
1845 return GetSigOpCount(
true);
1850 const_iterator pc = scriptSig.begin();
1851 vector<unsigned char> data;
1852 while (pc < scriptSig.end())
1855 if (!scriptSig.
GetOp(pc, opcode, data))
1862 CScript subscript(data.begin(), data.end());
1869 return (this->size() == 23 &&
1871 this->at(1) == 0x14 &&
1877 const_iterator pc = begin();
1881 if (!GetOp(pc, opcode))
1895 const_iterator pc = begin();
1899 std::vector<unsigned char> data;
1900 if (!GetOp(pc, opcode, data))
1904 if (opcode < OP_PUSHDATA1 && opcode > OP_0 && (data.size() == 1 && data[0] <= 16))
1954 *
this << EncodeOP_N(nRequired);
1955 BOOST_FOREACH(
const CPubKey& key, keys)
1965 memcpy(&hash, &script[3], 20);
1973 if (script.size() == 23 && script[0] ==
OP_HASH160 && script[1] == 20
1975 memcpy(&hash, &script[2], 20);
1983 if (script.size() == 35 && script[0] == 33 && script[34] ==
OP_CHECKSIG
1984 && (script[1] == 0x02 || script[1] == 0x03)) {
1985 pubkey.
Set(&script[1], &script[34]);
1988 if (script.size() == 67 && script[0] == 65 && script[66] ==
OP_CHECKSIG
1989 && script[1] == 0x04) {
1990 pubkey.
Set(&script[1], &script[66]);
1999 if (IsToKeyID(keyID)) {
2002 memcpy(&out[1], &keyID, 20);
2006 if (IsToScriptID(scriptID)) {
2009 memcpy(&out[1], &scriptID, 20);
2013 if (IsToPubKey(pubkey)) {
2015 memcpy(&out[1], &pubkey[1], 32);
2016 if (pubkey[0] == 0x02 || pubkey[0] == 0x03) {
2019 }
else if (pubkey[0] == 0x04) {
2020 out[0] = 0x04 | (pubkey[64] & 0x01);
2029 if (nSize == 0 || nSize == 1)
2031 if (nSize == 2 || nSize == 3 || nSize == 4 || nSize == 5)
2044 memcpy(&script[3], &in[0], 20);
2052 memcpy(&script[2], &in[0], 20);
2060 memcpy(&script[2], &in[0], 32);
2065 unsigned char vch[33] = {};
2067 memcpy(&vch[1], &in[0], 32);
2068 CPubKey pubkey(&vch[0], &vch[33]);
2071 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)
CScript CombineSignatures(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const CScript &scriptSig1, const CScript &scriptSig2)
CScriptVisitor(CScript *scriptin)
const CKeyStore * keystore
bool Compress(std::vector< unsigned char > &out) const
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
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)
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)
isminetype
IsMine() return codes.
CKeyStoreIsMineVisitor(const CKeyStore *keystoreIn)
opcodetype
Script opcodes.
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
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.
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
uint256 Hash(const T1 pbegin, const T1 pend)
An output of a transaction.
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)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
virtual bool HaveWatchOnly(const CScript &dest) const =0
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)
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)
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.
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. ...
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
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