diff --git a/src/miner.cpp b/src/miner.cpp index 0cfb055e..e9a2375a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -676,6 +676,8 @@ void GenerateGcoins(bool fGenerate, CWallet* pwallet, int nThreads) minerThreads = NULL; } + SoftSetBoolArg("-gen", fGenerate); + if (nThreads == 0 || !fGenerate) return; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 31147011..0cabd51e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -152,13 +152,16 @@ Value assignfixedaddress(const Array& params, bool fHelp) "\nArguments:\n" "1. \"address\" (string, required) The address to be assigned as the default address.\n" "\nResult:\n" - "\"address\" (string) The default gcoin address\n" + "{\n" + " \"address\" : true (boolean) If the default gcoin address is mining\n" + "}\n" "\nExamples:\n" + HelpExampleCli("assignfixedaddress", "") + HelpExampleCli("assignfixedaddress", "address") + HelpExampleRpc("assignfixedaddress", "address") ); + Object result; std::string str = params[0].get_str(); CPubKey newDefaultKey; CKeyID keyID; @@ -169,6 +172,9 @@ Value assignfixedaddress(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gcoin address or key"); } + if (keyID == pwalletMain->vchDefaultKey.GetID()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Same default address"); + if (!pwalletMain->GetKeyFromPool(newDefaultKey, address)) { if (!pwalletMain->GetPubKey(keyID, newDefaultKey)) { throw JSONRPCError(RPC_WALLET_ERROR, "Public key for address " + str + " is not known"); @@ -184,15 +190,12 @@ Value assignfixedaddress(const Array& params, bool fHelp) throw JSONRPCError(RPC_WALLET_ERROR, "Cannot write default address"); } - if (mapArgs["-gen"] == "1") { - GenerateGcoins(true, pwalletMain, atoi(mapArgs["-genproclimit"])); - if (mapArgs["-gen"] == "1") - str += " mining continues"; - else - str += " mining stops"; - } + if (GetBoolArg("-gen", false)) + GenerateGcoins(true, pwalletMain, GetArg("-genproclimit", 1)); - return str; + result.push_back(Pair(str, GetBoolArg("-gen", false))); + + return result; } // Get a specific amount of new address. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4d65b988..c82b1f3d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2620,7 +2620,7 @@ void CWallet::ViewKeyPool(std::vector& keys) } } -int64_t CWallet::SearchKeyPool(const CBitcoinAddress& address) const +bool CWallet::SearchKeyPool(int64_t& nIndex, const CBitcoinAddress& address) const { LOCK(cs_wallet); CWalletDB walletdb(strWalletFile); @@ -2629,10 +2629,12 @@ int64_t CWallet::SearchKeyPool(const CBitcoinAddress& address) const CKeyPool keypool; if (!walletdb.ReadPool(*it, keypool)) throw runtime_error(_(__func__) + "() : read failed"); - if (address == CBitcoinAddress(keypool.vchPubKey.GetID())) - return (*it); + if (address == CBitcoinAddress(keypool.vchPubKey.GetID())) { + nIndex = *it; + return true; + } } - return -1; + return false; } void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) @@ -2666,12 +2668,13 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, const CB { LOCK(cs_wallet); - // Get the oldest key + // Return if the key pool is empty if (setKeyPool.empty()) return; CWalletDB walletdb(strWalletFile); - nIndex = SearchKeyPool(address); + if (!SearchKeyPool(nIndex, address)) + return; setKeyPool.erase(nIndex); if (!walletdb.ReadPool(nIndex, keypool)) throw runtime_error(_(__func__) + "() : read failed"); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index e58396bd..d8f707d8 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -682,7 +682,7 @@ class CWallet : public CHDKeyStore, public CValidationInterface bool AddKeyPool(CPubKey& key); bool EraseKeyPool(); void ViewKeyPool(std::vector& keys); - int64_t SearchKeyPool(const CBitcoinAddress& address) const; + bool SearchKeyPool(int64_t& nIndex, const CBitcoinAddress& address) const; void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool); void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, const CBitcoinAddress& address); void KeepKey(int64_t nIndex);