Skip to content

Commit 9db4652

Browse files
committed
Add purpose arg to Wallet::getAddress
Also make all arguments to getAddress required and document args at call sites.
1 parent 8d651ae commit 9db4652

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/interfaces/wallet.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ class WalletImpl : public Wallet
148148
{
149149
return m_wallet.DelAddressBook(dest);
150150
}
151-
bool getAddress(const CTxDestination& dest, std::string* name, isminetype* is_mine) override
151+
bool getAddress(const CTxDestination& dest,
152+
std::string* name,
153+
isminetype* is_mine,
154+
std::string* purpose) override
152155
{
153156
LOCK(m_wallet.cs_wallet);
154157
auto it = m_wallet.mapAddressBook.find(dest);
@@ -161,6 +164,9 @@ class WalletImpl : public Wallet
161164
if (is_mine) {
162165
*is_mine = IsMine(m_wallet, dest);
163166
}
167+
if (purpose) {
168+
*purpose = it->second.purpose;
169+
}
164170
return true;
165171
}
166172
std::vector<WalletAddress> getAddresses() override

src/interfaces/wallet.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ class Wallet
9494

9595
//! Look up address in wallet, return whether exists.
9696
virtual bool getAddress(const CTxDestination& dest,
97-
std::string* name = nullptr,
98-
isminetype* is_mine = nullptr) = 0;
97+
std::string* name,
98+
isminetype* is_mine,
99+
std::string* purpose) = 0;
99100

100101
//! Get wallet address list.
101102
virtual std::vector<WalletAddress> getAddresses() = 0;

src/qt/addresstablemodel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
266266
}
267267
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
268268
// to paste an existing address over another address (with a different label)
269-
if (walletModel->wallet().getAddress(newAddress))
269+
if (walletModel->wallet().getAddress(
270+
newAddress, /* name= */ nullptr, /* is_mine= */ nullptr, /* purpose= */ nullptr))
270271
{
271272
editStatus = DUPLICATE_ADDRESS;
272273
return false;
@@ -351,7 +352,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
351352
}
352353
// Check for duplicate addresses
353354
{
354-
if(walletModel->wallet().getAddress(DecodeDestination(strAddress)))
355+
if (walletModel->wallet().getAddress(
356+
DecodeDestination(strAddress), /* name= */ nullptr, /* is_mine= */ nullptr, /* purpose= */ nullptr))
355357
{
356358
editStatus = DUPLICATE_ADDRESS;
357359
return QString();

src/qt/transactiondesc.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
102102
if (IsValidDestination(address)) {
103103
std::string name;
104104
isminetype ismine;
105-
if (wallet.getAddress(address, &name, &ismine))
105+
if (wallet.getAddress(address, &name, &ismine, /* purpose= */ nullptr))
106106
{
107107
strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>";
108108
strHTML += "<b>" + tr("To") + ":</b> ";
@@ -128,7 +128,8 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
128128
strHTML += "<b>" + tr("To") + ":</b> ";
129129
CTxDestination dest = DecodeDestination(strAddress);
130130
std::string name;
131-
if (wallet.getAddress(dest, &name) && !name.empty())
131+
if (wallet.getAddress(
132+
dest, &name, /* is_mine= */ nullptr, /* purpose= */ nullptr) && !name.empty())
132133
strHTML += GUIUtil::HtmlEscape(name) + " ";
133134
strHTML += GUIUtil::HtmlEscape(strAddress) + "<br>";
134135
}
@@ -196,7 +197,8 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
196197
{
197198
strHTML += "<b>" + tr("To") + ":</b> ";
198199
std::string name;
199-
if (wallet.getAddress(address, &name) && !name.empty())
200+
if (wallet.getAddress(
201+
address, &name, /* is_mine= */ nullptr, /* purpose= */ nullptr) && !name.empty())
200202
strHTML += GUIUtil::HtmlEscape(name) + " ";
201203
strHTML += GUIUtil::HtmlEscape(EncodeDestination(address));
202204
if(toSelf == ISMINE_SPENDABLE)
@@ -319,7 +321,7 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
319321
if (ExtractDestination(vout.scriptPubKey, address))
320322
{
321323
std::string name;
322-
if (wallet.getAddress(address, &name) && !name.empty())
324+
if (wallet.getAddress(address, &name, /* is_mine= */ nullptr, /* purpose= */ nullptr) && !name.empty())
323325
strHTML += GUIUtil::HtmlEscape(name) + " ";
324326
strHTML += QString::fromStdString(EncodeDestination(address));
325327
}

src/qt/walletmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
274274
{
275275
// Check if we have a new address or an updated label
276276
std::string name;
277-
if (!m_wallet->getAddress(dest, &name))
277+
if (!m_wallet->getAddress(
278+
dest, &name, /* is_mine= */ nullptr, /* purpose= */ nullptr))
278279
{
279280
m_wallet->setAddressBook(dest, strLabel, "send");
280281
}

0 commit comments

Comments
 (0)