Skip to content

Commit

Permalink
Fix multisig
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Spread committed Jan 23, 2015
1 parent 3e1cd9c commit 651a520
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
12 changes: 3 additions & 9 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ static CScript _createmultisig(const Array& params)
throw runtime_error(
strprintf("not enough keys supplied "
"(got %"PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired));
std::vector<CPubKey> pubkeys;
std::vector<CKeyID> pubkeys;
pubkeys.resize(keys.size());
for (unsigned int i = 0; i < keys.size(); i++)
{
Expand All @@ -763,13 +763,7 @@ static CScript _createmultisig(const Array& params)
if (!address.GetKeyID(keyID))
throw runtime_error(
strprintf("%s does not refer to a key",ks.c_str()));
CPubKey vchPubKey;
if (!pwalletMain->GetPubKey(keyID, vchPubKey))
throw runtime_error(
strprintf("no full public key for address %s",ks.c_str()));
if (!vchPubKey.IsFullyValid())
throw runtime_error(" Invalid public key: "+ks);
pubkeys[i] = vchPubKey;
pubkeys[i] = keyID;
}

// Case 2: hex public key
Expand All @@ -778,7 +772,7 @@ static CScript _createmultisig(const Array& params)
CPubKey vchPubKey(ParseHex(ks));
if (!vchPubKey.IsFullyValid())
throw runtime_error(" Invalid public key: "+ks);
pubkeys[i] = vchPubKey;
pubkeys[i] = vchPubKey.GetID();
}
else
{
Expand Down
11 changes: 5 additions & 6 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
// Template matching opcodes:
if (opcode2 == OP_PUBKEYS)
{
while (vch1.size() >= 33 && vch1.size() <= 120)
while (vch1.size() == sizeof(uint160))
{
vSolutionsRet.push_back(vch1);
if (!script1.GetOp2(pc1, opcode1, &vch1))
Expand Down Expand Up @@ -1225,8 +1225,7 @@ bool SignN(const vector<valtype>& multisigdata, const CKeyStore& keystore, uint2
int nRequired = multisigdata.front()[0];
for (unsigned int i = 1; i < multisigdata.size()-1 && nSigned < nRequired; i++)
{
const valtype& pubkey = multisigdata[i];
CKeyID keyID = CPubKey(pubkey).GetID();
CKeyID keyID = CKeyID(uint160(multisigdata[i]));
if (Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
++nSigned;
}
Expand Down Expand Up @@ -1311,7 +1310,7 @@ unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore)
unsigned int nResult = 0;
BOOST_FOREACH(const valtype& pubkey, pubkeys)
{
CKeyID keyID = CPubKey(pubkey).GetID();
CKeyID keyID = CKeyID(uint160(pubkey));
if (keystore.HaveKey(keyID))
++nResult;
}
Expand Down Expand Up @@ -1770,12 +1769,12 @@ void CScript::SetDestination(const CTxDestination& dest)
boost::apply_visitor(CScriptVisitor(this), dest);
}

void CScript::SetMultisig(int nRequired, const std::vector<CPubKey>& keys)
void CScript::SetMultisig(int nRequired, const std::vector<CKeyID>& keys)
{
this->clear();

*this << EncodeOP_N(nRequired);
BOOST_FOREACH(const CPubKey& key, keys)
BOOST_FOREACH(const CKeyID& key, keys)
*this << key;
*this << EncodeOP_N(keys.size()) << OP_CHECKMULTISIG;
}
2 changes: 1 addition & 1 deletion src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class CScript : public std::vector<unsigned char>


void SetDestination(const CTxDestination& address);
void SetMultisig(int nRequired, const std::vector<CPubKey>& keys);
void SetMultisig(int nRequired, const std::vector<CKeyID> &keys);


void PrintHex() const
Expand Down

0 comments on commit 651a520

Please sign in to comment.