16 typedef std::vector<unsigned char>
valtype;
23 std::vector<unsigned char> vchSig;
26 vchSig.push_back((
unsigned char) nHashType);
27 scriptSigRet << vchSig;
34 int nRequired = multisigdata.front()[0];
35 for (
unsigned int i = 1; i < multisigdata.size() - 1 && nSigned < nRequired; i++) {
36 const valtype &pubkey = multisigdata[i];
38 if (
Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
41 return nSigned == nRequired;
54 std::vector<valtype> vSolutions;
55 if (!
Solver(scriptPubKey, whichTypeRet, vSolutions)) {
61 switch (whichTypeRet) {
69 if (!
Sign1(keyID, keystore, hash, nHashType, scriptSigRet)) {
76 if (!
Sign1(keyID, keystore, hash, nHashType, scriptSigRet)) {
77 LogPrintf(
"*** solver failed to sign \n");
90 return (
SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
98 assert(nIn < txTo.
vin.size());
106 if (!
Solver(keystore, fromPubKey, hash, nHashType, txin.
scriptSig, whichType))
123 if (!fSolved)
return false;
137 assert(nIn < txTo.
vin.size());
146 static CScript PushAll(
const std::vector<valtype>& values) {
148 for (
const valtype &v : values)
154 const std::vector<valtype>& vSolutions,
155 const std::vector<valtype>& sigs1,
const std::vector<valtype>& sigs2) {
157 std::set<valtype> allsigs;
170 assert(vSolutions.size() > 1);
171 unsigned int nSigsRequired = vSolutions.front()[0];
172 unsigned int nPubKeys = vSolutions.size() - 2;
173 std::map<valtype, valtype> sigs;
174 for (
const valtype &sig : allsigs)
176 for (
unsigned int i = 0; i < nPubKeys; i++) {
177 const valtype &pubkey = vSolutions[i + 1];
178 if (sigs.count(pubkey))
188 unsigned int nSigsHave = 0;
191 for (
unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++) {
192 if (sigs.count(vSolutions[i + 1])) {
193 result << sigs[vSolutions[i + 1]];
198 for (
unsigned int i = nSigsHave; i < nSigsRequired; i++)
205 const txnouttype txType,
const std::vector<valtype>& vSolutions,
206 std::vector<valtype>& sigs1, std::vector<valtype>& sigs2) {
214 if (sigs1.size() >= sigs2.size())
215 return PushAll(sigs1);
216 return PushAll(sigs2);
220 if (sigs1.empty() || sigs1[0].empty())
221 return PushAll(sigs2);
222 return PushAll(sigs1);
224 if (sigs1.empty() || sigs1.back().empty())
225 return PushAll(sigs2);
226 else if (sigs2.empty() || sigs2.back().empty())
227 return PushAll(sigs1);
231 CScript pubKey2(spk.begin(), spk.end());
234 std::vector<std::vector<unsigned char> > vSolutions2;
235 Solver(pubKey2, txType2, vSolutions2);
243 return CombineMultisig(scriptPubKey, txTo, nIn, vSolutions, sigs1, sigs2);
252 std::vector<std::vector<unsigned char> > vSolutions;
253 Solver(scriptPubKey, txType, vSolutions);
255 std::vector<valtype> stack1;
257 std::vector<valtype> stack2;
260 return CombineSignatures(scriptPubKey, txTo, nIn, txType, vSolutions, stack1, stack2);