Add getnewpubkey RPC call
[novacoin.git] / src / bitcoinrpc.cpp
index 147e6b1..e2f7d27 100644 (file)
@@ -1996,6 +1996,34 @@ Value getmemorypool(const Array& params, bool fHelp)
     }
 }
 
+Value getnewpubkey(const Array& params, bool fHelp)
+{
+    if (fHelp || params.size() > 1)
+        throw runtime_error(
+            "getnewpubkey [account]\n"
+            "Returns new public key for coinbase generation.");
+
+    // Parse the account first so we don't generate a key if there's an error
+    string strAccount;
+    if (params.size() > 0)
+        strAccount = AccountFromValue(params[0]);
+
+    if (!pwalletMain->IsLocked())
+        pwalletMain->TopUpKeyPool();
+
+    // Generate a new key that is added to wallet
+    std::vector<unsigned char> newKey = pwalletMain->GenerateNewKey(false);
+
+    if(!newKey.size())
+        throw JSONRPCError(-12, "Error: Unable to create key");
+
+    CBitcoinAddress address(newKey);
+    pwalletMain->SetAddressBookName(address, strAccount);
+
+    return HexStr(newKey.begin(), newKey.end());
+}
+
+
 Value getblockhash(const Array& params, bool fHelp)
 {
     if (fHelp || params.size() != 1)
@@ -2264,6 +2292,7 @@ static const CRPCCommand vRPCCommands[] =
     { "getinfo",                &getinfo,                true },
     { "getmininginfo",          &getmininginfo,          true },
     { "getnewaddress",          &getnewaddress,          true },
+    { "getnewpubkey",           &getnewpubkey,           true },
     { "getaccountaddress",      &getaccountaddress,      true },
     { "setaccount",             &setaccount,             true },
     { "getaccount",             &getaccount,             false },