5 #include <boost/foreach.hpp>
6 #include <boost/tuple/tuple.hpp>
19 bool CheckSig(vector<unsigned char> vchSig,
const vector<unsigned char> &vchPubKey,
const CScript &scriptCode,
const CTransaction& txTo,
unsigned int nIn,
int nHashType,
int flags);
24 static const valtype vchFalse(0);
25 static const valtype vchZero(0);
26 static const valtype vchTrue(1, 1);
29 static const CBigNum bnFalse(0);
31 static const size_t nMaxNumSize = 4;
36 if (vch.size() > nMaxNumSize)
37 throw runtime_error(
"CastToBigNum() : overflow");
44 for (
unsigned int i = 0; i < vch.size(); i++)
49 if (i == vch.size()-1 && vch[i] == 0x80)
63 #define stacktop(i) (stack.at(stack.size()+(i)))
64 #define altstacktop(i) (altstack.at(altstack.size()+(i)))
65 static inline void popstack(vector<valtype>& stack)
68 throw runtime_error(
"popstack() : stack empty");
92 case OP_0 :
return "0";
98 case OP_1 :
return "1";
99 case OP_2 :
return "2";
100 case OP_3 :
return "3";
101 case OP_4 :
return "4";
102 case OP_5 :
return "5";
103 case OP_6 :
return "6";
104 case OP_7 :
return "7";
105 case OP_8 :
return "8";
106 case OP_9 :
return "9";
107 case OP_10 :
return "10";
108 case OP_11 :
return "11";
109 case OP_12 :
return "12";
110 case OP_13 :
return "13";
111 case OP_14 :
return "14";
112 case OP_15 :
return "15";
113 case OP_16 :
return "16";
116 case OP_NOP :
return "OP_NOP";
117 case OP_VER :
return "OP_VER";
118 case OP_IF :
return "OP_IF";
122 case OP_ELSE :
return "OP_ELSE";
131 case OP_2DUP :
return "OP_2DUP";
132 case OP_3DUP :
return "OP_3DUP";
134 case OP_2ROT :
return "OP_2ROT";
138 case OP_DROP :
return "OP_DROP";
139 case OP_DUP :
return "OP_DUP";
140 case OP_NIP :
return "OP_NIP";
141 case OP_OVER :
return "OP_OVER";
142 case OP_PICK :
return "OP_PICK";
143 case OP_ROLL :
return "OP_ROLL";
144 case OP_ROT :
return "OP_ROT";
145 case OP_SWAP :
return "OP_SWAP";
146 case OP_TUCK :
return "OP_TUCK";
149 case OP_CAT :
return "OP_CAT";
151 case OP_LEFT :
return "OP_LEFT";
153 case OP_SIZE :
return "OP_SIZE";
157 case OP_AND :
return "OP_AND";
158 case OP_OR :
return "OP_OR";
159 case OP_XOR :
return "OP_XOR";
166 case OP_1ADD :
return "OP_1ADD";
167 case OP_1SUB :
return "OP_1SUB";
168 case OP_2MUL :
return "OP_2MUL";
169 case OP_2DIV :
return "OP_2DIV";
171 case OP_ABS :
return "OP_ABS";
172 case OP_NOT :
return "OP_NOT";
174 case OP_ADD :
return "OP_ADD";
175 case OP_SUB :
return "OP_SUB";
176 case OP_MUL :
return "OP_MUL";
177 case OP_DIV :
return "OP_DIV";
178 case OP_MOD :
return "OP_MOD";
190 case OP_MIN :
return "OP_MIN";
191 case OP_MAX :
return "OP_MAX";
196 case OP_SHA1 :
return "OP_SHA1";
207 case OP_NOP1 :
return "OP_NOP1";
208 case OP_NOP2 :
return "OP_NOP2";
209 case OP_NOP3 :
return "OP_NOP3";
210 case OP_NOP4 :
return "OP_NOP4";
211 case OP_NOP5 :
return "OP_NOP5";
212 case OP_NOP6 :
return "OP_NOP6";
213 case OP_NOP7 :
return "OP_NOP7";
214 case OP_NOP8 :
return "OP_NOP8";
215 case OP_NOP9 :
return "OP_NOP9";
231 if (vchPubKey.size() < 33)
232 return error(
"Non-canonical public key: too short");
233 if (vchPubKey[0] == 0x04) {
234 if (vchPubKey.size() != 65)
235 return error(
"Non-canonical public key: invalid length for uncompressed key");
236 }
else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
237 if (vchPubKey.size() != 33)
238 return error(
"Non-canonical public key: invalid length for compressed key");
240 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");
292 bool EvalScript(vector<vector<unsigned char> >& stack,
const CScript& script,
const CTransaction& txTo,
unsigned int nIn,
unsigned int flags,
int nHashType)
295 CScript::const_iterator pc = script.begin();
296 CScript::const_iterator pend = script.end();
297 CScript::const_iterator pbegincodehash = script.begin();
301 vector<valtype> altstack;
302 if (script.size() > 10000)
311 bool fExec = !count(vfExec.begin(), vfExec.end(),
false);
316 if (!script.
GetOp(pc, opcode, vchPushValue))
318 if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE)
320 if (opcode >
OP_16 && ++nOpCount > 201)
341 stack.push_back(vchPushValue);
368 stack.push_back(bn.
getvch());
388 if (stack.size() < 1)
396 vfExec.push_back(fValue);
404 vfExec.back() = !vfExec.back();
420 if (stack.size() < 1)
442 if (stack.size() < 1)
451 if (altstack.size() < 1)
461 if (stack.size() < 2)
471 if (stack.size() < 2)
475 stack.push_back(vch1);
476 stack.push_back(vch2);
483 if (stack.size() < 3)
488 stack.push_back(vch1);
489 stack.push_back(vch2);
490 stack.push_back(vch3);
497 if (stack.size() < 4)
501 stack.push_back(vch1);
502 stack.push_back(vch2);
509 if (stack.size() < 6)
513 stack.erase(stack.end()-6, stack.end()-4);
514 stack.push_back(vch1);
515 stack.push_back(vch2);
522 if (stack.size() < 4)
532 if (stack.size() < 1)
536 stack.push_back(vch);
544 stack.push_back(bn.getvch());
551 if (stack.size() < 1)
560 if (stack.size() < 1)
563 stack.push_back(vch);
570 if (stack.size() < 2)
572 stack.erase(stack.end() - 2);
579 if (stack.size() < 2)
582 stack.push_back(vch);
591 if (stack.size() < 2)
595 if (n < 0 || n >= (
int)stack.size())
599 stack.erase(stack.end()-n-1);
600 stack.push_back(vch);
609 if (stack.size() < 3)
619 if (stack.size() < 2)
628 if (stack.size() < 2)
631 stack.insert(stack.end()-2, vch);
639 if (stack.size() < 1)
642 stack.push_back(bn.
getvch());
655 if (stack.size() < 2)
659 bool fEqual = (vch1 == vch2);
667 stack.push_back(fEqual ? vchTrue : vchFalse);
690 if (stack.size() < 1)
695 case OP_1ADD: bn += bnOne;
break;
696 case OP_1SUB: bn -= bnOne;
break;
698 case OP_ABS:
if (bn < bnZero) bn = -bn;
break;
699 case OP_NOT: bn = (bn == bnZero);
break;
701 default: assert(!
"invalid opcode");
break;
704 stack.push_back(bn.
getvch());
723 if (stack.size() < 2)
738 case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero);
break;
739 case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero);
break;
747 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2);
break;
748 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2);
break;
749 default: assert(!
"invalid opcode");
break;
753 stack.push_back(bn.
getvch());
768 if (stack.size() < 3)
773 bool fValue = (bn2 <= bn1 && bn1 < bn3);
777 stack.push_back(fValue ? vchTrue : vchFalse);
792 if (stack.size() < 1)
797 RIPEMD160(&vch[0], vch.size(), &vchHash[0]);
799 SHA1(&vch[0], vch.size(), &vchHash[0]);
801 SHA256(&vch[0], vch.size(), &vchHash[0]);
805 memcpy(&vchHash[0], &hash160,
sizeof(hash160));
810 memcpy(&vchHash[0], &hash,
sizeof(hash));
813 stack.push_back(vchHash);
828 if (stack.size() < 2)
839 CScript scriptCode(pbegincodehash, pend);
846 fSuccess =
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
850 stack.push_back(fSuccess ? vchTrue : vchFalse);
867 if ((
int)stack.size() < i)
871 if (nKeysCount < 0 || nKeysCount > 20)
873 nOpCount += nKeysCount;
878 if ((
int)stack.size() < i)
882 if (nSigsCount < 0 || nSigsCount > nKeysCount)
886 if ((
int)stack.size() < i)
890 CScript scriptCode(pbegincodehash, pend);
893 for (
int k = 0; k < nSigsCount; k++)
899 bool fSuccess =
true;
900 while (fSuccess && nSigsCount > 0)
908 fOk =
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);
919 if (nSigsCount > nKeysCount)
925 stack.push_back(fSuccess ? vchTrue : vchFalse);
942 if (stack.size() + altstack.size() > 1000)
968 if (nIn >= txTo.
vin.size())
970 printf(
"ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
980 for (
unsigned int i = 0; i < txTmp.
vin.size(); i++)
982 txTmp.
vin[nIn].scriptSig = scriptCode;
991 for (
unsigned int i = 0; i < txTmp.
vin.size(); i++)
993 txTmp.
vin[i].nSequence = 0;
998 unsigned int nOut = nIn;
999 if (nOut >= txTmp.
vout.size())
1001 printf(
"ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
1004 txTmp.
vout.resize(nOut+1);
1005 for (
unsigned int i = 0; i < nOut; i++)
1006 txTmp.
vout[i].SetNull();
1009 for (
unsigned int i = 0; i < txTmp.
vin.size(); i++)
1011 txTmp.
vin[i].nSequence = 0;
1017 txTmp.
vin[0] = txTmp.
vin[nIn];
1018 txTmp.
vin.resize(1);
1023 ss << txTmp << nHashType;
1044 boost::shared_lock<boost::shared_mutex> lock(cs_sigcache);
1046 sigdata_type k(hash, vchSig, pubKey);
1047 std::set<sigdata_type>::iterator mi = setValid.find(k);
1048 if (mi != setValid.end())
1059 int64 nMaxCacheSize =
GetArg(
"-maxsigcachesize", 50000);
1060 if (nMaxCacheSize <= 0)
return;
1062 boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
1064 while (static_cast<int64>(setValid.size()) > nMaxCacheSize)
1071 std::vector<unsigned char> unused;
1072 std::set<sigdata_type>::iterator it =
1073 setValid.lower_bound(sigdata_type(randomHash, unused, unused));
1074 if (it == setValid.end())
1075 it = setValid.begin();
1076 setValid.erase(*it);
1079 sigdata_type k(hash, vchSig, pubKey);
1084 bool CheckSig(vector<unsigned char> vchSig,
const vector<unsigned char> &vchPubKey,
const CScript &scriptCode,
1085 const CTransaction& txTo,
unsigned int nIn,
int nHashType,
int flags)
1097 nHashType = vchSig.back();
1098 else if (nHashType != vchSig.back())
1104 if (signatureCache.
Get(sighash, vchSig, pubkey))
1107 if (!pubkey.
Verify(sighash, vchSig))
1111 signatureCache.
Set(sighash, vchSig, pubkey);
1130 static map<txnouttype, CScript> mTemplates;
1131 if (mTemplates.empty())
1148 vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
1149 vSolutionsRet.push_back(hashBytes);
1154 const CScript& script1 = scriptPubKey;
1157 const CScript& script2 = tplate.second;
1158 vSolutionsRet.clear();
1161 vector<unsigned char> vch1, vch2;
1164 CScript::const_iterator pc1 = script1.begin();
1165 CScript::const_iterator pc2 = script2.begin();
1168 if (pc1 == script1.end() && pc2 == script2.end())
1171 typeRet = tplate.first;
1175 unsigned char m = vSolutionsRet.front()[0];
1176 unsigned char n = vSolutionsRet.back()[0];
1177 if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
1182 if (!script1.
GetOp(pc1, opcode1, vch1))
1184 if (!script2.
GetOp(pc2, opcode2, vch2))
1190 while (vch1.size() >= 33 && vch1.size() <= 120)
1192 vSolutionsRet.push_back(vch1);
1193 if (!script1.
GetOp(pc1, opcode1, vch1))
1196 if (!script2.
GetOp(pc2, opcode2, vch2))
1204 if (vch1.size() < 33 || vch1.size() > 120)
1206 vSolutionsRet.push_back(vch1);
1210 if (vch1.size() !=
sizeof(
uint160))
1212 vSolutionsRet.push_back(vch1);
1216 if (opcode1 ==
OP_0 ||
1220 vSolutionsRet.push_back(
valtype(1, n));
1225 else if (opcode1 != opcode2 || vch1 != vch2)
1233 vSolutionsRet.clear();
1242 if (!keystore.
GetKey(address, key))
1245 vector<unsigned char> vchSig;
1246 if (!key.
Sign(hash, vchSig))
1248 vchSig.push_back((
unsigned char)nHashType);
1249 scriptSigRet << vchSig;
1257 int nRequired = multisigdata.front()[0];
1258 for (
unsigned int i = 1; i < multisigdata.size()-1 && nSigned < nRequired; i++)
1260 const valtype& pubkey = multisigdata[i];
1262 if (
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
1265 return nSigned==nRequired;
1277 scriptSigRet.clear();
1279 vector<valtype> vSolutions;
1280 if (!
Solver(scriptPubKey, whichTypeRet, vSolutions))
1284 switch (whichTypeRet)
1290 return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
1293 if (!
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
1299 scriptSigRet << vch;
1306 scriptSigRet <<
OP_0;
1307 return (
SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
1323 if (vSolutions.size() < 1 || vSolutions[0].size() < 1)
1325 return vSolutions[0][0] + 1;
1334 vector<valtype> vSolutions;
1336 if (!
Solver(scriptPubKey, whichType, vSolutions))
1341 unsigned char m = vSolutions.front()[0];
1342 unsigned char n = vSolutions.back()[0];
1356 unsigned int nResult = 0;
1357 BOOST_FOREACH(
const valtype& pubkey, pubkeys)
1385 vector<valtype> vSolutions;
1387 if (!
Solver(scriptPubKey, whichType, vSolutions))
1397 return keystore.
HaveKey(keyID);
1400 return keystore.
HaveKey(keyID);
1406 return IsMine(keystore, subscript);
1415 vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
1416 return HaveKeys(keys, keystore) == keys.size();
1424 vector<valtype> vSolutions;
1426 if (!
Solver(scriptPubKey, whichType, vSolutions))
1452 vector<valtype> vSolutions;
1453 if (!
Solver(scriptPubKey, typeRet, vSolutions))
1458 nRequiredRet = vSolutions.front()[0];
1459 for (
unsigned int i = 1; i < vSolutions.size()-1; i++)
1462 addressRet.push_back(address);
1471 addressRet.push_back(address);
1478 unsigned int flags,
int nHashType)
1480 vector<vector<unsigned char> > stack, stackCopy;
1481 if (!
EvalScript(stack, scriptSig, txTo, nIn, flags, nHashType))
1485 if (!
EvalScript(stack, scriptPubKey, txTo, nIn, flags, nHashType))
1502 assert(!stackCopy.empty());
1504 const valtype& pubKeySerialized = stackCopy.back();
1505 CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
1506 popstack(stackCopy);
1508 if (!
EvalScript(stackCopy, pubKey2, txTo, nIn, flags, nHashType))
1510 if (stackCopy.empty())
1521 assert(nIn < txTo.
vin.size());
1529 if (!
Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType))
1537 CScript subscript = txin.scriptSig;
1544 Solver(keystore, subscript, hash2, nHashType, txin.scriptSig, subType) && subType !=
TX_SCRIPTHASH;
1546 txin.scriptSig <<
static_cast<valtype>(subscript);
1547 if (!fSolved)
return false;
1556 assert(nIn < txTo.
vin.size());
1558 assert(txin.prevout.n < txFrom.
vout.size());
1559 const CTxOut& txout = txFrom.
vout[txin.prevout.n];
1561 return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, nHashType);
1564 static CScript PushAll(
const vector<valtype>& values)
1567 BOOST_FOREACH(
const valtype& v, values)
1573 const vector<
valtype>& vSolutions,
1577 set<valtype> allsigs;
1578 BOOST_FOREACH(
const valtype& v, sigs1)
1583 BOOST_FOREACH(
const valtype& v, sigs2)
1590 assert(vSolutions.size() > 1);
1591 unsigned int nSigsRequired = vSolutions.front()[0];
1592 unsigned int nPubKeys = vSolutions.size()-2;
1593 map<valtype, valtype> sigs;
1594 BOOST_FOREACH(
const valtype& sig, allsigs)
1596 for (
unsigned int i = 0; i < nPubKeys; i++)
1598 const valtype& pubkey = vSolutions[i+1];
1599 if (sigs.count(pubkey))
1602 if (
CheckSig(sig, pubkey, scriptPubKey, txTo, nIn, 0, 0))
1610 unsigned int nSigsHave = 0;
1612 for (
unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++)
1614 if (sigs.count(vSolutions[i+1]))
1616 result << sigs[vSolutions[i+1]];
1621 for (
unsigned int i = nSigsHave; i < nSigsRequired; i++)
1628 const txnouttype txType,
const vector<valtype>& vSolutions,
1629 vector<valtype>& sigs1, vector<valtype>& sigs2)
1635 if (sigs1.size() >= sigs2.size())
1636 return PushAll(sigs1);
1637 return PushAll(sigs2);
1641 if (sigs1.empty() || sigs1[0].empty())
1642 return PushAll(sigs2);
1643 return PushAll(sigs1);
1645 if (sigs1.empty() || sigs1.back().empty())
1646 return PushAll(sigs2);
1647 else if (sigs2.empty() || sigs2.back().empty())
1648 return PushAll(sigs1);
1653 CScript pubKey2(spk.begin(), spk.end());
1656 vector<vector<unsigned char> > vSolutions2;
1657 Solver(pubKey2, txType2, vSolutions2);
1665 return CombineMultisig(scriptPubKey, txTo, nIn, vSolutions, sigs1, sigs2);
1675 vector<vector<unsigned char> > vSolutions;
1676 Solver(scriptPubKey, txType, vSolutions);
1678 vector<valtype> stack1;
1680 vector<valtype> stack2;
1683 return CombineSignatures(scriptPubKey, txTo, nIn, txType, vSolutions, stack1, stack2);
1689 const_iterator pc = begin();
1694 if (!GetOp(pc, opcode))
1700 if (fAccurate && lastOpcode >=
OP_1 && lastOpcode <=
OP_16)
1701 n += DecodeOP_N(lastOpcode);
1705 lastOpcode = opcode;
1712 if (!IsPayToScriptHash())
1713 return GetSigOpCount(
true);
1718 const_iterator pc = scriptSig.begin();
1719 vector<unsigned char> data;
1720 while (pc < scriptSig.end())
1723 if (!scriptSig.
GetOp(pc, opcode, data))
1730 CScript subscript(data.begin(), data.end());
1737 return (this->size() == 23 &&
1739 this->at(1) == 0x14 &&
1777 *
this << EncodeOP_N(nRequired);
1778 BOOST_FOREACH(
const CPubKey& key, keys)
1788 memcpy(&hash, &script[3], 20);
1796 if (script.size() == 23 && script[0] ==
OP_HASH160 && script[1] == 20
1798 memcpy(&hash, &script[2], 20);
1806 if (script.size() == 35 && script[0] == 33 && script[34] ==
OP_CHECKSIG
1807 && (script[1] == 0x02 || script[1] == 0x03)) {
1808 pubkey.
Set(&script[1], &script[34]);
1811 if (script.size() == 67 && script[0] == 65 && script[66] ==
OP_CHECKSIG
1812 && script[1] == 0x04) {
1813 pubkey.
Set(&script[1], &script[66]);
1822 if (IsToKeyID(keyID)) {
1825 memcpy(&out[1], &keyID, 20);
1829 if (IsToScriptID(scriptID)) {
1832 memcpy(&out[1], &scriptID, 20);
1836 if (IsToPubKey(pubkey)) {
1838 memcpy(&out[1], &pubkey[1], 32);
1839 if (pubkey[0] == 0x02 || pubkey[0] == 0x03) {
1842 }
else if (pubkey[0] == 0x04) {
1843 out[0] = 0x04 | (pubkey[64] & 0x01);
1852 if (nSize == 0 || nSize == 1)
1854 if (nSize == 2 || nSize == 3 || nSize == 4 || nSize == 5)
1867 memcpy(&script[3], &in[0], 20);
1875 memcpy(&script[2], &in[0], 20);
1883 memcpy(&script[2], &in[0], 32);
1888 unsigned char vch[33] = {};
1890 memcpy(&vch[1], &in[0], 32);
1891 CPubKey pubkey(&vch[0], &vch[33]);
1894 assert(pubkey.
size() == 65);
1897 memcpy(&script[1], pubkey.
begin(), 65);
bool error(const char *format,...)
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)
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
bool IsPayToScriptHash() const
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)
uint256 SignatureHash(CScript scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
RAII encapsulated BN_CTX (OpenSSL bignum context)
uint160 Hash160(const T1 pbegin, const T1 pend)
bool operator()(const CNoDestination &dest) const
virtual bool HaveCScript(const CScriptID &hash) const =0
int ScriptSigArgsExpected(txnouttype t, const std::vector< std::vector< unsigned char > > &vSolutions)
unsigned int HaveKeys(const vector< valtype > &pubkeys, const CKeyStore &keystore)
void SetDestination(const CTxDestination &address)
CKeyStoreIsMineVisitor(const CKeyStore *keystoreIn)
opcodetype
Script opcodes.
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
An input of a transaction.
unsigned int GetSigOpCount(bool fAccurate) const
bool IsToScriptID(CScriptID &hash) const
std::vector< CTxOut > vout
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.
C++ wrapper for BIGNUM (OpenSSL bignum)
std::vector< unsigned char > getvch() const
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)
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)
A virtual base class for key stores.
void SetMultisig(int nRequired, const std::vector< CPubKey > &keys)
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)
bool IsFullyValid() const
bool Sign1(const CKeyID &address, const CKeyStore &keystore, uint256 hash, int nHashType, CScript &scriptSigRet)
int FindAndDelete(const CScript &b)
bool IsStandard(const CScript &scriptPubKey)
bool operator()(const CKeyID &keyID) const
A reference to a CScript: the Hash160 of its serialization (see script.h)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
bool IsCanonicalPubKey(const valtype &vchPubKey)
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)
CBigNum CastToBigNum(const valtype &vch)
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
vector< unsigned char > valtype
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
bool IsCanonicalSignature(const valtype &vchSig)
bool operator()(const CScriptID &scriptID) const