Skip to content

Commit

Permalink
Refactor keymetadata writing to a separate method
Browse files Browse the repository at this point in the history
Summary:
Partial backport of Core [[bitcoin/bitcoin#14021 | PR14021]]
bitcoin/bitcoin@c45415f

Test Plan:
  ninja
  ninja check
  ninja check-functional

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6004
  • Loading branch information
achow101 authored and Nico Guiton committed May 22, 2020
1 parent 2429c34 commit eb725bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ bool WalletBatch::EraseTx(uint256 hash) {
return EraseIC(std::make_pair(std::string("tx"), hash));
}

bool WalletBatch::WriteKeyMetadata(const CKeyMetadata &meta,
const CPubKey &pubkey,
const bool overwrite) {
return WriteIC(std::make_pair(std::string("keymeta"), pubkey), meta,
overwrite);
}

bool WalletBatch::WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey,
const CKeyMetadata &keyMeta) {
if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta,
false)) {
if (!WriteKeyMetadata(keyMeta, vchPubKey, false)) {
return false;
}

Expand All @@ -93,7 +99,7 @@ bool WalletBatch::WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey,
bool WalletBatch::WriteCryptedKey(const CPubKey &vchPubKey,
const std::vector<uint8_t> &vchCryptedSecret,
const CKeyMetadata &keyMeta) {
if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta)) {
if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/wallet/walletdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class WalletBatch {
bool WriteTx(const CWalletTx &wtx);
bool EraseTx(uint256 hash);

bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey,
const bool overwrite);
bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey,
const CKeyMetadata &keyMeta);
bool WriteCryptedKey(const CPubKey &vchPubKey,
Expand Down

0 comments on commit eb725bf

Please sign in to comment.