Skip to content

Commit

Permalink
refactor: unify WalletBatch's WriteHDChain and WriteCryptedHDChain
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Mar 5, 2024
1 parent 9c8e458 commit a180d73
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ bool LegacyScriptPubKeyMan::SetCryptedHDChain(WalletBatch &batch, const CHDChain

if (!memonly) {
if (encrypted_batch) {
if (!encrypted_batch->WriteCryptedHDChain(chain))
throw std::runtime_error(std::string(__func__) + ": WriteCryptedHDChain failed");
if (!encrypted_batch->WriteHDChain(chain))
throw std::runtime_error(std::string(__func__) + ": WriteHDChain failed");
} else {
if (!batch.WriteCryptedHDChain(chain))
throw std::runtime_error(std::string(__func__) + ": WriteCryptedHDChain failed");
if (!batch.WriteHDChain(chain))
throw std::runtime_error(std::string(__func__) + ": WriteHDChain failed");
}
m_storage.UnsetBlankWalletFlag(batch);
}
Expand Down
16 changes: 7 additions & 9 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,17 +800,15 @@ bool WalletBatch::EraseDestData(const std::string &address, const std::string &k

bool WalletBatch::WriteHDChain(const CHDChain& chain)
{
return WriteIC(DBKeys::HDCHAIN, chain);
}

bool WalletBatch::WriteCryptedHDChain(const CHDChain& chain)
{
if (!WriteIC(DBKeys::CRYPTED_HDCHAIN, chain))
return false;
if (chain.IsCrypted()) {
if (!WriteIC(DBKeys::CRYPTED_HDCHAIN, chain))
return false;

EraseIC(DBKeys::HDCHAIN);
EraseIC(DBKeys::HDCHAIN);

return true;
return true;
}
return WriteIC(DBKeys::HDCHAIN, chain);
}

bool WalletBatch::WriteHDPubKey(const CHDPubKey& hdPubKey, const CKeyMetadata& keyMeta)
Expand Down
1 change: 0 additions & 1 deletion src/wallet/walletdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class WalletBatch

//! write the hdchain model (external chain child index counter)
bool WriteHDChain(const CHDChain& chain);
bool WriteCryptedHDChain(const CHDChain& chain);
bool WriteHDPubKey(const CHDPubKey& hdPubKey, const CKeyMetadata& keyMeta);

bool WriteWalletFlags(const uint64_t flags);
Expand Down

0 comments on commit a180d73

Please sign in to comment.