Skip to content

Commit

Permalink
Don't generate shield addressed that have already been used
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Sep 16, 2023
1 parent 5efedea commit 74f7f94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ QString AddressTableModel::getAddressToShow(bool isShielded) const

for (auto it = wallet->NewAddressBookIterator(); it.IsValid(); it.Next()) {
const auto addrData = it.GetValue();

CWDestination x = *it.GetDestKey();
if (!isShielded) {
if (addrData.purpose == AddressBook::AddressBookPurpose::RECEIVE) {
const auto &address = *it.GetCTxDestKey();
Expand All @@ -622,10 +622,9 @@ QString AddressTableModel::getAddressToShow(bool isShielded) const
}
}
} else {
// todo: add shielded address support to IsUsed
if (addrData.purpose == AddressBook::AddressBookPurpose::SHIELDED_RECEIVE) {
const auto &address = *it.GetShieldedDestKey();
if (IsValidPaymentAddress(address) && IsMine(*wallet, address)) {
if (IsValidPaymentAddress(address) && IsMine(*wallet, address) && !wallet->IsUsed(address)) {
return QString::fromStdString(KeyIO::EncodePaymentAddress(address));
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,23 @@ bool CWallet::IsUsed(const CTxDestination address) const
return false;
}

bool CWallet::IsUsed(const libzcash::SaplingPaymentAddress address) const
{
LOCK(cs_wallet);
if (!::IsMine(*this, address)) {
return false;
}

for (const auto& it : mapWallet) {
const CWalletTx& wtx = it.second;
for (const auto& txout : wtx.mapSaplingNoteData) {
if (txout.second.address && *txout.second.address == address)
return true;
}
}
return false;
}

CAmount CWallet::GetDebit(const CTxIn& txin, const isminefilter& filter) const
{
{
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool CreateBudgetFeeTX(CTransactionRef& tx, const uint256& hash, CReserveKey& keyChange, CAmount fee);

bool IsUsed(const CTxDestination address) const;
bool IsUsed(const libzcash::SaplingPaymentAddress address) const;

isminetype IsMine(const CTxIn& txin) const;
CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
Expand Down

0 comments on commit 74f7f94

Please sign in to comment.