Skip to content

Commit

Permalink
Merge #11247: qt: Use IsMine to validate custom change address
Browse files Browse the repository at this point in the history
a1ea1cf qt: Use IsMine to validate custom change address (Chris Moore)

Pull request description:

  Fixes #11137
  Closes #11184 (which was accidentally opened against 0.15 branch)

Tree-SHA512: a20a59b4f36c1471a9c84bcc7c69048576d1f413104c299a7ed9ba221f28eddf93d727fca2926420ea5d0dd9aba582924f26a5acd44d995039b7202c73eb53bc
  • Loading branch information
MarcoFalke committed Sep 5, 2017
2 parents 777519b + a1ea1cf commit a31e9ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,18 +789,16 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
}
else // Valid address
{
CKeyID keyid;
addr.GetKeyID(keyid);
if (!model->havePrivKey(keyid)) // Unknown change address
{
const CTxDestination dest = addr.Get();
if (!model->IsSpendable(dest)) {
ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));

// confirmation dialog
QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm custom change address"), tr("The address you selected for change is not part of this wallet. Any or all funds in your wallet may be sent to this address. Are you sure?"),
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);

if(btnRetVal == QMessageBox::Yes)
CoinControlDialog::coinControl->destChange = addr.Get();
CoinControlDialog::coinControl->destChange = dest;
else
{
ui->lineEditCoinControlChange->setText("");
Expand All @@ -819,7 +817,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
else
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));

CoinControlDialog::coinControl->destChange = addr.Get();
CoinControlDialog::coinControl->destChange = dest;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
return wallet->GetPubKey(address, vchPubKeyOut);
}

bool WalletModel::havePrivKey(const CKeyID &address) const
bool WalletModel::IsSpendable(const CTxDestination& dest) const
{
return wallet->HaveKey(address);
return IsMine(*wallet, dest) & ISMINE_SPENDABLE;
}

bool WalletModel::getPrivKey(const CKeyID &address, CKey& vchPrivKeyOut) const
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class WalletModel : public QObject
UnlockContext requestUnlock();

bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
bool havePrivKey(const CKeyID &address) const;
bool IsSpendable(const CTxDestination& dest) const;
bool getPrivKey(const CKeyID &address, CKey& vchPrivKeyOut) const;
void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
bool isSpent(const COutPoint& outpoint) const;
Expand Down

0 comments on commit a31e9ad

Please sign in to comment.