mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
wallet: Replace use of purpose strings with an enum
Instead of storing and passing around fixed strings for the purpose of an address, use an enum. This also rationalizes the CAddressBookData struct, documenting all fields and making them public, and simplifying the representation to avoid bugs like https://github.com/bitcoin/bitcoin/pull/26761#discussion_r1134615114 and make it not possible to invalid address data like change addresses with labels. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
@@ -35,6 +35,7 @@ struct bilingual_str;
|
||||
namespace wallet {
|
||||
class CCoinControl;
|
||||
class CWallet;
|
||||
enum class AddressPurpose;
|
||||
enum isminetype : unsigned int;
|
||||
struct CRecipient;
|
||||
struct WalletContext;
|
||||
@@ -103,7 +104,7 @@ public:
|
||||
virtual bool haveWatchOnly() = 0;
|
||||
|
||||
//! Add or update address.
|
||||
virtual bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) = 0;
|
||||
virtual bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::optional<wallet::AddressPurpose>& purpose) = 0;
|
||||
|
||||
// Remove address.
|
||||
virtual bool delAddressBook(const CTxDestination& dest) = 0;
|
||||
@@ -112,7 +113,7 @@ public:
|
||||
virtual bool getAddress(const CTxDestination& dest,
|
||||
std::string* name,
|
||||
wallet::isminetype* is_mine,
|
||||
std::string* purpose) = 0;
|
||||
wallet::AddressPurpose* purpose) = 0;
|
||||
|
||||
//! Get wallet address list.
|
||||
virtual std::vector<WalletAddress> getAddresses() const = 0;
|
||||
@@ -293,7 +294,7 @@ public:
|
||||
using AddressBookChangedFn = std::function<void(const CTxDestination& address,
|
||||
const std::string& label,
|
||||
bool is_mine,
|
||||
const std::string& purpose,
|
||||
wallet::AddressPurpose purpose,
|
||||
ChangeType status)>;
|
||||
virtual std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) = 0;
|
||||
|
||||
@@ -352,11 +353,11 @@ struct WalletAddress
|
||||
{
|
||||
CTxDestination dest;
|
||||
wallet::isminetype is_mine;
|
||||
wallet::AddressPurpose purpose;
|
||||
std::string name;
|
||||
std::string purpose;
|
||||
|
||||
WalletAddress(CTxDestination dest, wallet::isminetype is_mine, std::string name, std::string purpose)
|
||||
: dest(std::move(dest)), is_mine(is_mine), name(std::move(name)), purpose(std::move(purpose))
|
||||
WalletAddress(CTxDestination dest, wallet::isminetype is_mine, wallet::AddressPurpose purpose, std::string name)
|
||||
: dest(std::move(dest)), is_mine(is_mine), purpose(std::move(purpose)), name(std::move(name))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user