New createmultisig rpc command
This is to support the signrawtransaction API call; given the public keys involved in a multisig transaction, this gives back the redeemScript needed to sign it.
This commit is contained in:
parent
03346a61b1
commit
34226be7a8
3 changed files with 52 additions and 15 deletions
|
@ -234,6 +234,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||||
{ "sendfrom", &sendfrom, false, false },
|
{ "sendfrom", &sendfrom, false, false },
|
||||||
{ "sendmany", &sendmany, false, false },
|
{ "sendmany", &sendmany, false, false },
|
||||||
{ "addmultisigaddress", &addmultisigaddress, false, false },
|
{ "addmultisigaddress", &addmultisigaddress, false, false },
|
||||||
|
{ "createmultisig", &createmultisig, true, true },
|
||||||
{ "getrawmempool", &getrawmempool, true, false },
|
{ "getrawmempool", &getrawmempool, true, false },
|
||||||
{ "getblock", &getblock, false, false },
|
{ "getblock", &getblock, false, false },
|
||||||
{ "getblockhash", &getblockhash, false, false },
|
{ "getblockhash", &getblockhash, false, false },
|
||||||
|
@ -1160,6 +1161,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
|
||||||
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
|
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
|
||||||
if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||||
if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]);
|
if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]);
|
||||||
|
if (strMethod == "createmultisig" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||||
|
if (strMethod == "createmultisig" && n > 1) ConvertTo<Array>(params[1]);
|
||||||
if (strMethod == "listunspent" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
if (strMethod == "listunspent" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||||
if (strMethod == "listunspent" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "listunspent" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
|
if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
|
||||||
|
|
|
@ -158,6 +158,7 @@ extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp);
|
||||||
|
extern json_spirit::Value createmultisig(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp);
|
||||||
|
|
|
@ -702,22 +702,13 @@ Value sendmany(const Array& params, bool fHelp)
|
||||||
return wtx.GetHash().GetHex();
|
return wtx.GetHash().GetHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value addmultisigaddress(const Array& params, bool fHelp)
|
//
|
||||||
|
// Used by addmultisigaddress / createmultisig:
|
||||||
|
//
|
||||||
|
static CScript _createmultisig(const Array& params)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 2 || params.size() > 3)
|
|
||||||
{
|
|
||||||
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
|
|
||||||
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
|
|
||||||
"each key is a Bitcoin address or hex-encoded public key\n"
|
|
||||||
"If [account] is specified, assign address to [account].";
|
|
||||||
throw runtime_error(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int nRequired = params[0].get_int();
|
int nRequired = params[0].get_int();
|
||||||
const Array& keys = params[1].get_array();
|
const Array& keys = params[1].get_array();
|
||||||
string strAccount;
|
|
||||||
if (params.size() > 2)
|
|
||||||
strAccount = AccountFromValue(params[2]);
|
|
||||||
|
|
||||||
// Gather public keys
|
// Gather public keys
|
||||||
if (nRequired < 1)
|
if (nRequired < 1)
|
||||||
|
@ -760,10 +751,28 @@ Value addmultisigaddress(const Array& params, bool fHelp)
|
||||||
throw runtime_error(" Invalid public key: "+ks);
|
throw runtime_error(" Invalid public key: "+ks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CScript result;
|
||||||
|
result.SetMultisig(nRequired, pubkeys);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value addmultisigaddress(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() < 2 || params.size() > 3)
|
||||||
|
{
|
||||||
|
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
|
||||||
|
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
|
||||||
|
"each key is a Bitcoin address or hex-encoded public key\n"
|
||||||
|
"If [account] is specified, assign address to [account].";
|
||||||
|
throw runtime_error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
string strAccount;
|
||||||
|
if (params.size() > 2)
|
||||||
|
strAccount = AccountFromValue(params[2]);
|
||||||
|
|
||||||
// Construct using pay-to-script-hash:
|
// Construct using pay-to-script-hash:
|
||||||
CScript inner;
|
CScript inner = _createmultisig(params);
|
||||||
inner.SetMultisig(nRequired, pubkeys);
|
|
||||||
CScriptID innerID = inner.GetID();
|
CScriptID innerID = inner.GetID();
|
||||||
pwalletMain->AddCScript(inner);
|
pwalletMain->AddCScript(inner);
|
||||||
|
|
||||||
|
@ -771,6 +780,30 @@ Value addmultisigaddress(const Array& params, bool fHelp)
|
||||||
return CBitcoinAddress(innerID).ToString();
|
return CBitcoinAddress(innerID).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value createmultisig(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() < 2 || params.size() > 2)
|
||||||
|
{
|
||||||
|
string msg = "createmultisig <nrequired> <'[\"key\",\"key\"]'>\n"
|
||||||
|
"Creates a multi-signature address and returns a json object\n"
|
||||||
|
"with keys:\n"
|
||||||
|
"address : bitcoin address\n"
|
||||||
|
"redeemScript : hex-encoded redemption script";
|
||||||
|
throw runtime_error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct using pay-to-script-hash:
|
||||||
|
CScript inner = _createmultisig(params);
|
||||||
|
CScriptID innerID = inner.GetID();
|
||||||
|
CBitcoinAddress address(innerID);
|
||||||
|
|
||||||
|
Object result;
|
||||||
|
result.push_back(Pair("address", address.ToString()));
|
||||||
|
result.push_back(Pair("redeemScript", HexStr(inner.begin(), inner.end())));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct tallyitem
|
struct tallyitem
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue