diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-07-09 21:48:37 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2024-02-07 18:15:38 -0300 |
commit | bba4f8dcb55de3ca4963711dc17882b43cb0bc4a (patch) | |
tree | bbcfe55e0dac23faf4e2d0bc9e81bd1b27c3fcfc /src/wallet/wallet.cpp | |
parent | 97b075392305becfbad4d497614478cff2d9237f (diff) | |
download | bitcoin-bba4f8dcb55de3ca4963711dc17882b43cb0bc4a.tar.xz |
refactor: SetAddrBookWithDB, signal only if write succeeded
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 28c696d0dd..55f8f1b9b5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2368,13 +2368,22 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add purpose = m_address_book[address].purpose; } } + + const std::string& encoded_dest = EncodeDestination(address); + if (new_purpose && !batch.WritePurpose(encoded_dest, PurposeToString(*new_purpose))) { + WalletLogPrintf("Error: fail to write address book 'purpose' entry\n"); + return false; + } + if (!batch.WriteName(encoded_dest, strName)) { + WalletLogPrintf("Error: fail to write address book 'name' entry\n"); + return false; + } + // In very old wallets, address purpose may not be recorded so we derive it from IsMine NotifyAddressBookChanged(address, strName, is_mine, purpose.value_or(is_mine ? AddressPurpose::RECEIVE : AddressPurpose::SEND), (fUpdated ? CT_UPDATED : CT_NEW)); - if (new_purpose && !batch.WritePurpose(EncodeDestination(address), PurposeToString(*new_purpose))) - return false; - return batch.WriteName(EncodeDestination(address), strName); + return true; } bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& purpose) |