From: alex Date: Sun, 17 Feb 2013 22:00:13 +0000 (+0400) Subject: Add getnewpubkey RPC call X-Git-Tag: v0.4.0-unstable~51 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=440991a0f8dbdd6147e56ec55e3423429cee6e90 Add getnewpubkey RPC call --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 147e6b1..e2f7d27 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -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 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 }, diff --git a/src/wallet.cpp b/src/wallet.cpp index e955965..e4a4ec3 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -18,9 +18,9 @@ using namespace std; // mapWallet // -std::vector CWallet::GenerateNewKey() +std::vector 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; diff --git a/src/wallet.h b/src/wallet.h index 88e8648..a531944 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -119,7 +119,7 @@ public: // keystore implementation // Generate a new key - std::vector GenerateNewKey(); + std::vector 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)