aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp104
1 files changed, 102 insertions, 2 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index fdb1b34a0a..bed90d4f6c 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -673,7 +673,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
if (params.size() > 1)
nMinDepth = params[1].get_int();
- // Get the set of pub keys that have the label
+ // Get the set of pub keys assigned to account
string strAccount = AccountFromValue(params[0]);
set<CBitcoinAddress> setAddress;
GetAccountAddresses(strAccount, setAddress);
@@ -942,6 +942,68 @@ Value sendmany(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
+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, hex or base58 public key\n"
+ "If [account] is specified, assign address to [account].";
+ throw runtime_error(msg);
+ }
+ if (!fTestNet)
+ throw runtime_error("addmultisigaddress available only when running -testnet\n");
+
+ int nRequired = params[0].get_int();
+ const Array& keys = params[1].get_array();
+ string strAccount;
+ if (params.size() > 2)
+ strAccount = AccountFromValue(params[2]);
+
+ // Gather public keys
+ if (keys.size() < nRequired)
+ throw runtime_error(
+ strprintf("addmultisigaddress: wrong number of keys (got %d, need at least %d)", keys.size(), nRequired));
+ std::vector<CKey> pubkeys;
+ pubkeys.resize(keys.size());
+ for (int i = 0; i < keys.size(); i++)
+ {
+ const std::string& ks = keys[i].get_str();
+ if (ks.size() == 130) // hex public key
+ pubkeys[i].SetPubKey(ParseHex(ks));
+ else if (ks.size() > 34) // base58-encoded
+ {
+ std::vector<unsigned char> vchPubKey;
+ if (DecodeBase58(ks, vchPubKey))
+ pubkeys[i].SetPubKey(vchPubKey);
+ else
+ throw runtime_error("Error base58 decoding key: "+ks);
+ }
+ else // bitcoin address for key in this wallet
+ {
+ CBitcoinAddress address(ks);
+ if (!pwalletMain->GetKey(address, pubkeys[i]))
+ throw runtime_error(
+ strprintf("addmultisigaddress: unknown address: %s",ks.c_str()));
+ }
+ }
+
+ // Construct using OP_EVAL
+ CScript inner;
+ inner.SetMultisig(nRequired, pubkeys);
+
+ uint160 scriptHash = Hash160(inner);
+ CScript scriptPubKey;
+ scriptPubKey.SetEval(inner);
+ pwalletMain->AddCScript(scriptHash, inner);
+ CBitcoinAddress address;
+ address.SetScriptHash160(scriptHash);
+
+ pwalletMain->SetAddressBookName(address, strAccount);
+ return address.ToString();
+}
+
struct tallyitem
{
@@ -1602,7 +1664,35 @@ Value validateaddress(const Array& params, bool fHelp)
// version of the address:
string currentAddress = address.ToString();
ret.push_back(Pair("address", currentAddress));
- ret.push_back(Pair("ismine", (pwalletMain->HaveKey(address) > 0)));
+ if (pwalletMain->HaveKey(address))
+ {
+ ret.push_back(Pair("ismine", true));
+ std::vector<unsigned char> vchPubKey;
+ pwalletMain->GetPubKey(address, vchPubKey);
+ ret.push_back(Pair("pubkey", HexStr(vchPubKey)));
+ std::string strPubKey(vchPubKey.begin(), vchPubKey.end());
+ ret.push_back(Pair("pubkey58", EncodeBase58(vchPubKey)));
+ }
+ else if (pwalletMain->HaveCScript(address.GetHash160()))
+ {
+ ret.push_back(Pair("isscript", true));
+ CScript subscript;
+ pwalletMain->GetCScript(address.GetHash160(), subscript);
+ ret.push_back(Pair("ismine", ::IsMine(*pwalletMain, subscript)));
+ std::vector<CBitcoinAddress> addresses;
+ txnouttype whichType;
+ int nRequired;
+ ExtractAddresses(subscript, pwalletMain, whichType, addresses, nRequired);
+ ret.push_back(Pair("script", GetTxnOutputType(whichType)));
+ Array a;
+ BOOST_FOREACH(const CBitcoinAddress& addr, addresses)
+ a.push_back(addr.ToString());
+ ret.push_back(Pair("addresses", a));
+ if (whichType == TX_MULTISIG)
+ ret.push_back(Pair("sigsrequired", nRequired));
+ }
+ else
+ ret.push_back(Pair("ismine", false));
if (pwalletMain->mapAddressBook.count(address))
ret.push_back(Pair("account", pwalletMain->mapAddressBook[address]));
}
@@ -1847,6 +1937,7 @@ pair<string, rpcfn_type> pCallTable[] =
make_pair("move", &movecmd),
make_pair("sendfrom", &sendfrom),
make_pair("sendmany", &sendmany),
+ make_pair("addmultisigaddress", &addmultisigaddress),
make_pair("gettransaction", &gettransaction),
make_pair("listtransactions", &listtransactions),
make_pair("signmessage", &signmessage),
@@ -2490,6 +2581,15 @@ int CommandLineRPC(int argc, char *argv[])
params[1] = v.get_obj();
}
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 > 1)
+ {
+ string s = params[1].get_str();
+ Value v;
+ if (!read_string(s, v) || v.type() != array_type)
+ throw runtime_error("addmultisigaddress: type mismatch "+s);
+ params[1] = v.get_array();
+ }
// Execute
Object reply = CallRPC(strMethod, params);