Merge pull request #2904 from gmaxwell/newaddr-no-passphrase

[QT] Don't ask for a passphrase to getnewaddress.
This commit is contained in:
Gregory Maxwell 2013-08-28 11:20:09 -07:00
commit 1ef0067eab
6 changed files with 20 additions and 22 deletions

View File

@ -898,7 +898,7 @@ bool AppInit2(boost::thread_group& threadGroup)
RandAddSeedPerfmon(); RandAddSeedPerfmon();
CPubKey newDefaultKey; CPubKey newDefaultKey;
if (pwalletMain->GetKeyFromPool(newDefaultKey, false)) { if (pwalletMain->GetKeyFromPool(newDefaultKey)) {
pwalletMain->SetDefaultKey(newDefaultKey); pwalletMain->SetDefaultKey(newDefaultKey);
if (!pwalletMain->SetAddressBook(pwalletMain->vchDefaultKey.GetID(), "", "receive")) if (!pwalletMain->SetAddressBook(pwalletMain->vchDefaultKey.GetID(), "", "receive"))
strErrors << _("Cannot write default address") << "\n"; strErrors << _("Cannot write default address") << "\n";

View File

@ -355,18 +355,21 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
else if(type == Receive) else if(type == Receive)
{ {
// Generate a new address to associate with given label // Generate a new address to associate with given label
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet failed or was cancelled
editStatus = WALLET_UNLOCK_FAILURE;
return QString();
}
CPubKey newKey; CPubKey newKey;
if(!wallet->GetKeyFromPool(newKey, true)) if(!wallet->GetKeyFromPool(newKey))
{ {
editStatus = KEY_GENERATION_FAILURE; WalletModel::UnlockContext ctx(walletModel->requestUnlock());
return QString(); if(!ctx.isValid())
{
// Unlock wallet failed or was cancelled
editStatus = WALLET_UNLOCK_FAILURE;
return QString();
}
if(!wallet->GetKeyFromPool(newKey))
{
editStatus = KEY_GENERATION_FAILURE;
return QString();
}
} }
strAddress = CBitcoinAddress(newKey.GetID()).ToString(); strAddress = CBitcoinAddress(newKey.GetID()).ToString();
} }

View File

@ -531,7 +531,7 @@ PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QB
} }
else { else {
CPubKey newKey; CPubKey newKey;
if (wallet->GetKeyFromPool(newKey, false)) { if (wallet->GetKeyFromPool(newKey)) {
CKeyID keyID = newKey.GetID(); CKeyID keyID = newKey.GetID();
wallet->SetAddressBook(keyID, strAccount, "refund"); wallet->SetAddressBook(keyID, strAccount, "refund");

View File

@ -110,7 +110,7 @@ Value getnewaddress(const Array& params, bool fHelp)
// Generate a new key that is added to wallet // Generate a new key that is added to wallet
CPubKey newKey; CPubKey newKey;
if (!pwalletMain->GetKeyFromPool(newKey, false)) if (!pwalletMain->GetKeyFromPool(newKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
CKeyID keyID = newKey.GetID(); CKeyID keyID = newKey.GetID();
@ -148,7 +148,7 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
// Generate a new key // Generate a new key
if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed)
{ {
if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive"); pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");

View File

@ -493,7 +493,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
if (txout.scriptPubKey == scriptDefaultKey) if (txout.scriptPubKey == scriptDefaultKey)
{ {
CPubKey newDefaultKey; CPubKey newDefaultKey;
if (GetKeyFromPool(newDefaultKey, false)) if (GetKeyFromPool(newDefaultKey))
{ {
SetDefaultKey(newDefaultKey); SetDefaultKey(newDefaultKey);
SetAddressBook(vchDefaultKey.GetID(), "", "receive"); SetAddressBook(vchDefaultKey.GetID(), "", "receive");
@ -1647,7 +1647,7 @@ void CWallet::ReturnKey(int64 nIndex)
printf("keypool return %"PRI64d"\n", nIndex); printf("keypool return %"PRI64d"\n", nIndex);
} }
bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse) bool CWallet::GetKeyFromPool(CPubKey& result)
{ {
int64 nIndex = 0; int64 nIndex = 0;
CKeyPool keypool; CKeyPool keypool;
@ -1656,11 +1656,6 @@ bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse)
ReserveKeyFromKeyPool(nIndex, keypool); ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex == -1) if (nIndex == -1)
{ {
if (fAllowReuse && vchDefaultKey.IsValid())
{
result = vchDefaultKey;
return true;
}
if (IsLocked()) return false; if (IsLocked()) return false;
result = GenerateNewKey(); result = GenerateNewKey();
return true; return true;

View File

@ -220,7 +220,7 @@ public:
void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
void KeepKey(int64 nIndex); void KeepKey(int64 nIndex);
void ReturnKey(int64 nIndex); void ReturnKey(int64 nIndex);
bool GetKeyFromPool(CPubKey &key, bool fAllowReuse=true); bool GetKeyFromPool(CPubKey &key);
int64 GetOldestKeyPoolTime(); int64 GetOldestKeyPoolTime();
void GetAllReserveKeys(std::set<CKeyID>& setAddress) const; void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;