Skip to content

Commit

Permalink
Fix signrawtransaction and sendrawtransaction RPC calls to support mu…
Browse files Browse the repository at this point in the history
…ltisig redeem scripts.

(cherry picked from commit f1c4b8a)
  • Loading branch information
glv2 authored and sunnyking committed Mar 23, 2015
1 parent 80c1287 commit 4ce4f25
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2974,6 +2974,28 @@ Value signrawtransaction(const Array& params, bool fHelp)
}
}

bool fGivenKeys = false;
CBasicKeyStore tempKeystore;
if (params.size() > 2 && params[2].type() != null_type)
{
fGivenKeys = true;
Array keys = params[2].get_array();
BOOST_FOREACH(Value k, keys)
{
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(k.get_str());
if (!fGood)
throw JSONRPCError(-5,"Invalid private key");
CKey key;
bool fCompressed;
CSecret secret = vchSecret.GetSecret(fCompressed);
key.SetSecret(secret, fCompressed);
tempKeystore.AddKey(key);
}
}
else if(pwalletMain->IsCrypted())
throw runtime_error("The wallet must be unlocked with walletpassphrase first");

// Add previous txouts given in the RPC call:
if (params.size() > 1 && params[1].type() != null_type)
{
Expand Down Expand Up @@ -3015,30 +3037,21 @@ Value signrawtransaction(const Array& params, bool fHelp)
}
else
mapPrevOut[outpoint] = scriptPubKey;
}
}

bool fGivenKeys = false;
CBasicKeyStore tempKeystore;
if (params.size() > 2 && params[2].type() != null_type)
{
fGivenKeys = true;
Array keys = params[2].get_array();
BOOST_FOREACH(Value k, keys)
{
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(k.get_str());
if (!fGood)
throw JSONRPCError(-5,"Invalid private key");
CKey key;
bool fCompressed;
CSecret secret = vchSecret.GetSecret(fCompressed);
key.SetSecret(secret, fCompressed);
tempKeystore.AddKey(key);
// if redeemScript given and not using the local wallet (private keys
// given), add redeemScript to the tempKeystore so it can be signed:
if (fGivenKeys && scriptPubKey.IsPayToScriptHash())
{
Value v = find_value(prevOut, "redeemScript");
if (!(v == Value::null))
{
vector<unsigned char> rsData(ParseHex(v.get_str()));
CScript redeemScript(rsData.begin(), rsData.end());
tempKeystore.AddCScript(redeemScript);
}
}
}
}
else if(pwalletMain->IsCrypted())
throw runtime_error("The wallet must be unlocked with walletpassphrase first");

const CKeyStore& keystore = (fGivenKeys ? tempKeystore : *pwalletMain);

Expand Down Expand Up @@ -3133,7 +3146,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
{
// push to local node
CTxDB txdb("r");
if (!tx.AcceptToMemoryPool(txdb))
if (!tx.AcceptToMemoryPool(txdb, false))
throw JSONRPCError(-22, "TX rejected");

SyncWithWallets(tx, NULL, true);
Expand Down

0 comments on commit 4ce4f25

Please sign in to comment.