Skip to content

Commit c45415f

Browse files
committed
Refactor keymetadata writing to a separate method
1 parent 9b1df4b commit c45415f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/wallet/walletdb.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ bool WalletBatch::EraseTx(uint256 hash)
5757
return EraseIC(std::make_pair(std::string("tx"), hash));
5858
}
5959

60+
bool WalletBatch::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite)
61+
{
62+
return WriteIC(std::make_pair(std::string("keymeta"), pubkey), meta, overwrite);
63+
}
64+
6065
bool WalletBatch::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
6166
{
62-
if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta, false)) {
67+
if (!WriteKeyMetadata(keyMeta, vchPubKey, false)) {
6368
return false;
6469
}
6570

@@ -76,7 +81,7 @@ bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey,
7681
const std::vector<unsigned char>& vchCryptedSecret,
7782
const CKeyMetadata &keyMeta)
7883
{
79-
if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta)) {
84+
if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) {
8085
return false;
8186
}
8287

src/wallet/walletdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class WalletBatch
177177
bool WriteTx(const CWalletTx& wtx);
178178
bool EraseTx(uint256 hash);
179179

180+
bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite);
180181
bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
181182
bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
182183
bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey);

0 commit comments

Comments
 (0)