Add getnewpubkey RPC call
authoralex <alex@alex-VirtualBox.(none)>
Sun, 17 Feb 2013 22:00:13 +0000 (02:00 +0400)
committeralex <alex@alex-VirtualBox.(none)>
Sun, 17 Feb 2013 22:00:13 +0000 (02:00 +0400)
src/bitcoinrpc.cpp
src/wallet.cpp
src/wallet.h

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 },
index e955965..e4a4ec3 100644 (file)
@@ -18,9 +18,9 @@ using namespace std;
 // mapWallet
 //
 
-std::vector<unsigned char> CWallet::GenerateNewKey()
+std::vector<unsigned char> CWallet::GenerateNewKey(bool bCompressed = true)
 {
-    bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
+    bool fCompressed = bCompressed ? CanSupportFeature(FEATURE_COMPRPUBKEY) : false; // default to compressed public keys if we want 0.6.0 wallets
 
     RandAddSeedPerfmon();
     CKey key;
index 88e8648..a531944 100644 (file)
@@ -119,7 +119,7 @@ public:
 
     // keystore implementation
     // Generate a new key
-    std::vector<unsigned char> GenerateNewKey();
+    std::vector<unsigned char> GenerateNewKey(bool bCompressed);
     // Adds a key to the store, and saves it to disk.
     bool AddKey(const CKey& key);
     // Adds a key to the store, without saving it to disk (used by LoadWallet)