diff options
author | Andrew Chow <github@achow101.com> | 2023-02-20 17:45:32 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-04-11 15:55:31 -0400 |
commit | e83babe3b85b22e2360a99f9827b2b0d107ad0fa (patch) | |
tree | 67baf57399f7b1c386c64317164a0360976d1451 /src/wallet/walletdb.cpp | |
parent | 2f8000513675467e62bee9d0f836d2fefcc479af (diff) | |
download | bitcoin-e83babe3b85b22e2360a99f9827b2b0d107ad0fa.tar.xz |
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>
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r-- | src/wallet/walletdb.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 3c0ed21b66..c8e8ce4614 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -347,7 +347,13 @@ ReadKeyValue(CWallet* pwallet, DataStream& ssKey, CDataStream& ssValue, } else if (strType == DBKeys::PURPOSE) { std::string strAddress; ssKey >> strAddress; - ssValue >> pwallet->m_address_book[DecodeDestination(strAddress)].purpose; + std::string purpose_str; + ssValue >> purpose_str; + std::optional<AddressPurpose> purpose{PurposeFromString(purpose_str)}; + if (!purpose) { + pwallet->WalletLogPrintf("Warning: nonstandard purpose string '%s' for address '%s'\n", purpose_str, strAddress); + } + pwallet->m_address_book[DecodeDestination(strAddress)].purpose = purpose; } else if (strType == DBKeys::TX) { uint256 hash; ssKey >> hash; |