Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ void GenerateGcoins(bool fGenerate, CWallet* pwallet, int nThreads)
minerThreads = NULL;
}

SoftSetBoolArg("-gen", fGenerate);

if (nThreads == 0 || !fGenerate)
return;

Expand Down
21 changes: 12 additions & 9 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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.
Expand Down
15 changes: 9 additions & 6 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,7 @@ void CWallet::ViewKeyPool(std::vector<CPubKey>& 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);
Expand All @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class CWallet : public CHDKeyStore, public CValidationInterface
bool AddKeyPool(CPubKey& key);
bool EraseKeyPool();
void ViewKeyPool(std::vector<CPubKey>& 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);
Expand Down