aboutsummaryrefslogtreecommitdiff
path: root/src/rpcwallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r--src/rpcwallet.cpp73
1 files changed, 53 insertions, 20 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 9e914f336d..5ebab755b7 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -329,12 +329,12 @@ Value signmessage(const Array& params, bool fHelp)
if (!pwalletMain->GetKey(keyID, key))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available");
- CDataStream ss(SER_GETHASH, 0);
+ CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;
vector<unsigned char> vchSig;
- if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig))
+ if (!key.SignCompact(ss.GetHash(), vchSig))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
return EncodeBase64(&vchSig[0], vchSig.size());
@@ -365,12 +365,12 @@ Value verifymessage(const Array& params, bool fHelp)
if (fInvalid)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
- CDataStream ss(SER_GETHASH, 0);
+ CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;
CKey key;
- if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
+ if (!key.SetCompactSignature(ss.GetHash(), vchSig))
return false;
return (key.GetPubKey().GetID() == keyID);
@@ -702,22 +702,13 @@ Value sendmany(const Array& params, bool fHelp)
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();
const Array& keys = params[1].get_array();
- string strAccount;
- if (params.size() > 2)
- strAccount = AccountFromValue(params[2]);
// Gather public keys
if (nRequired < 1)
@@ -760,10 +751,28 @@ Value addmultisigaddress(const Array& params, bool fHelp)
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:
- CScript inner;
- inner.SetMultisig(nRequired, pubkeys);
+ CScript inner = _createmultisig(params);
CScriptID innerID = inner.GetID();
pwalletMain->AddCScript(inner);
@@ -771,6 +780,30 @@ Value addmultisigaddress(const Array& params, bool fHelp)
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
{
@@ -1396,7 +1429,7 @@ Value encryptwallet(const Array& params, bool fHelp)
// slack space in .dat files; that is bad if the old data is
// unencrypted private keys. So:
StartShutdown();
- return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
+ return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
}
class DescribeAddressVisitor : public boost::static_visitor<Object>