Skip to content

Commit 01b35b5

Browse files
committed
walletdb: Refactor minversion loading
Move minversion loading to its own function in WalletBatch
1 parent a36134f commit 01b35b5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/wallet/walletdb.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,18 @@ bool WalletBatch::IsKeyType(const std::string& strType)
791791
strType == DBKeys::MASTER_KEY || strType == DBKeys::CRYPTED_KEY);
792792
}
793793

794+
static DBErrors LoadMinVersion(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
795+
{
796+
AssertLockHeld(pwallet->cs_wallet);
797+
int nMinVersion = 0;
798+
if (batch.Read(DBKeys::MINVERSION, nMinVersion)) {
799+
if (nMinVersion > FEATURE_LATEST)
800+
return DBErrors::TOO_NEW;
801+
pwallet->LoadMinVersion(nMinVersion);
802+
}
803+
return DBErrors::LOAD_OK;
804+
}
805+
794806
DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
795807
{
796808
CWalletScanState wss;
@@ -806,12 +818,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
806818
pwallet->WalletLogPrintf("Wallet file version = %d, last client version = %d\n", pwallet->GetVersion(), last_client);
807819

808820
try {
809-
int nMinVersion = 0;
810-
if (m_batch->Read(DBKeys::MINVERSION, nMinVersion)) {
811-
if (nMinVersion > FEATURE_LATEST)
812-
return DBErrors::TOO_NEW;
813-
pwallet->LoadMinVersion(nMinVersion);
814-
}
821+
if ((result = LoadMinVersion(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result;
815822

816823
// Load wallet flags, so they are known when processing other records.
817824
// The FLAGS key is absent during wallet creation.

0 commit comments

Comments
 (0)