|
|
|
@ -14,8 +14,6 @@
|
|
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
typedef std::vector<unsigned char> valtype;
|
|
|
|
|
|
|
|
|
|
TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
|
|
|
|
@ -39,14 +37,14 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
|
|
|
|
|
|
|
|
|
static bool Sign1(const CKeyID& address, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
|
|
|
|
|
{
|
|
|
|
|
vector<unsigned char> vchSig;
|
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
|
if (!creator.CreateSig(vchSig, address, scriptCode, sigversion))
|
|
|
|
|
return false;
|
|
|
|
|
ret.push_back(vchSig);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool SignN(const vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
|
|
|
|
|
static bool SignN(const std::vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
|
|
|
|
|
{
|
|
|
|
|
int nSigned = 0;
|
|
|
|
|
int nRequired = multisigdata.front()[0];
|
|
|
|
@ -73,7 +71,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
|
|
|
|
uint160 h160;
|
|
|
|
|
ret.clear();
|
|
|
|
|
|
|
|
|
|
vector<valtype> vSolutions;
|
|
|
|
|
std::vector<valtype> vSolutions;
|
|
|
|
|
if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
@ -125,7 +123,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CScript PushAll(const vector<valtype>& values)
|
|
|
|
|
static CScript PushAll(const std::vector<valtype>& values)
|
|
|
|
|
{
|
|
|
|
|
CScript result;
|
|
|
|
|
BOOST_FOREACH(const valtype& v, values) {
|
|
|
|
@ -228,12 +226,12 @@ bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CMutab
|
|
|
|
|
return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
|
|
|
|
const vector<valtype>& vSolutions,
|
|
|
|
|
const vector<valtype>& sigs1, const vector<valtype>& sigs2, SigVersion sigversion)
|
|
|
|
|
static std::vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
|
|
|
|
const std::vector<valtype>& vSolutions,
|
|
|
|
|
const std::vector<valtype>& sigs1, const std::vector<valtype>& sigs2, SigVersion sigversion)
|
|
|
|
|
{
|
|
|
|
|
// Combine all the signatures we've got:
|
|
|
|
|
set<valtype> allsigs;
|
|
|
|
|
std::set<valtype> allsigs;
|
|
|
|
|
BOOST_FOREACH(const valtype& v, sigs1)
|
|
|
|
|
{
|
|
|
|
|
if (!v.empty())
|
|
|
|
@ -249,7 +247,7 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
|
|
|
|
|
assert(vSolutions.size() > 1);
|
|
|
|
|
unsigned int nSigsRequired = vSolutions.front()[0];
|
|
|
|
|
unsigned int nPubKeys = vSolutions.size()-2;
|
|
|
|
|
map<valtype, valtype> sigs;
|
|
|
|
|
std::map<valtype, valtype> sigs;
|
|
|
|
|
BOOST_FOREACH(const valtype& sig, allsigs)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 0; i < nPubKeys; i++)
|
|
|
|
@ -306,7 +304,7 @@ struct Stacks
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
|
|
|
|
const txnouttype txType, const vector<valtype>& vSolutions,
|
|
|
|
|
const txnouttype txType, const std::vector<valtype>& vSolutions,
|
|
|
|
|
Stacks sigs1, Stacks sigs2, SigVersion sigversion)
|
|
|
|
|
{
|
|
|
|
|
switch (txType)
|
|
|
|
@ -340,7 +338,7 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
|
|
|
|
CScript pubKey2(spk.begin(), spk.end());
|
|
|
|
|
|
|
|
|
|
txnouttype txType2;
|
|
|
|
|
vector<vector<unsigned char> > vSolutions2;
|
|
|
|
|
std::vector<std::vector<unsigned char> > vSolutions2;
|
|
|
|
|
Solver(pubKey2, txType2, vSolutions2);
|
|
|
|
|
sigs1.script.pop_back();
|
|
|
|
|
sigs2.script.pop_back();
|
|
|
|
@ -360,7 +358,7 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
|
|
|
|
// Recur to combine:
|
|
|
|
|
CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
|
|
|
|
|
txnouttype txType2;
|
|
|
|
|
vector<valtype> vSolutions2;
|
|
|
|
|
std::vector<valtype> vSolutions2;
|
|
|
|
|
Solver(pubKey2, txType2, vSolutions2);
|
|
|
|
|
sigs1.witness.pop_back();
|
|
|
|
|
sigs1.script = sigs1.witness;
|
|
|
|
@ -383,7 +381,7 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
|
|
|
|
const SignatureData& scriptSig1, const SignatureData& scriptSig2)
|
|
|
|
|
{
|
|
|
|
|
txnouttype txType;
|
|
|
|
|
vector<vector<unsigned char> > vSolutions;
|
|
|
|
|
std::vector<std::vector<unsigned char> > vSolutions;
|
|
|
|
|
Solver(scriptPubKey, txType, vSolutions);
|
|
|
|
|
|
|
|
|
|
return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SIGVERSION_BASE).Output();
|
|
|
|
|