diff options
Diffstat (limited to 'src/wallet/interfaces.cpp')
-rw-r--r-- | src/wallet/interfaces.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index eeac147d8b..086f6d9de8 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -179,7 +179,7 @@ public: } return false; }; - bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override + bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::optional<AddressPurpose>& purpose) override { return m_wallet->SetAddressBook(dest, name, purpose); } @@ -190,7 +190,7 @@ public: bool getAddress(const CTxDestination& dest, std::string* name, isminetype* is_mine, - std::string* purpose) override + AddressPurpose* purpose) override { LOCK(m_wallet->cs_wallet); const auto& entry = m_wallet->FindAddressBookEntry(dest, /*allow_change=*/false); @@ -198,11 +198,16 @@ public: if (name) { *name = entry->GetLabel(); } + std::optional<isminetype> dest_is_mine; + if (is_mine || purpose) { + dest_is_mine = m_wallet->IsMine(dest); + } if (is_mine) { - *is_mine = m_wallet->IsMine(dest); + *is_mine = *dest_is_mine; } if (purpose) { - *purpose = entry->purpose; + // In very old wallets, address purpose may not be recorded so we derive it from IsMine + *purpose = entry->purpose.value_or(*dest_is_mine ? AddressPurpose::RECEIVE : AddressPurpose::SEND); } return true; } @@ -210,9 +215,11 @@ public: { LOCK(m_wallet->cs_wallet); std::vector<WalletAddress> result; - m_wallet->ForEachAddrBookEntry([&](const CTxDestination& dest, const std::string& label, const std::string& purpose, bool is_change) EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet) { + m_wallet->ForEachAddrBookEntry([&](const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose>& purpose) EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet) { if (is_change) return; - result.emplace_back(dest, m_wallet->IsMine(dest), label, purpose); + isminetype is_mine = m_wallet->IsMine(dest); + // In very old wallets, address purpose may not be recorded so we derive it from IsMine + result.emplace_back(dest, is_mine, purpose.value_or(is_mine ? AddressPurpose::RECEIVE : AddressPurpose::SEND), label); }); return result; } @@ -519,7 +526,7 @@ public: { return MakeSignalHandler(m_wallet->NotifyAddressBookChanged.connect( [fn](const CTxDestination& address, const std::string& label, bool is_mine, - const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); })); + AddressPurpose purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); })); } std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override { |