Skip to content

Commit 36796f2

Browse files
committed
[Cleanup] Fix formatting in wallet and walletdb
1 parent b6dbbf3 commit 36796f2

File tree

3 files changed

+72
-53
lines changed

3 files changed

+72
-53
lines changed

src/wallet/wallet.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,8 +2121,9 @@ bool CWallet::Verify()
21212121
}
21222122

21232123
std::string strError;
2124-
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
2124+
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError)) {
21252125
return UIError(strError);
2126+
}
21262127

21272128
if (gArgs.GetBoolArg("-salvagewallet", false)) {
21282129
// Recover readable keypairs:
@@ -2133,14 +2134,16 @@ bool CWallet::Verify()
21332134
// tx status. If lock can't be taken, tx confirmation status may be not
21342135
// reliable.
21352136
LOCK(cs_main);
2136-
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter, backup_filename))
2137+
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter, backup_filename)) {
21372138
return false;
2139+
}
21382140
}
21392141

21402142
std::string strWarning;
21412143
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
2142-
if (!strWarning.empty())
2144+
if (!strWarning.empty()) {
21432145
UIWarning(strWarning);
2146+
}
21442147
if (!dbV) {
21452148
return UIError(strError);
21462149
}
@@ -2153,16 +2156,19 @@ void CWallet::ResendWalletTransactions(CConnman* connman)
21532156
{
21542157
// Do this infrequently and randomly to avoid giving away
21552158
// that these are our transactions.
2156-
if (GetTime() < nNextResend)
2159+
if (GetTime() < nNextResend) {
21572160
return;
2161+
}
21582162
bool fFirst = (nNextResend == 0);
21592163
nNextResend = GetTime() + GetRand(30 * 60);
2160-
if (fFirst)
2164+
if (fFirst) {
21612165
return;
2166+
}
21622167

21632168
// Only do it if there's been a new block since last time
2164-
if (nTimeBestReceived < nLastResend)
2169+
if (nTimeBestReceived < nLastResend) {
21652170
return;
2171+
}
21662172
nLastResend = GetTime();
21672173

21682174
// Rebroadcast any of our txes that aren't in a block yet
@@ -2175,8 +2181,9 @@ void CWallet::ResendWalletTransactions(CConnman* connman)
21752181
CWalletTx& wtx = item.second;
21762182
// Don't rebroadcast until it's had plenty of time that
21772183
// it should have gotten in already by now.
2178-
if (nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60)
2184+
if (nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60) {
21792185
mapSorted.emplace(wtx.nTimeReceived, &wtx);
2186+
}
21802187
}
21812188
for (std::pair<const unsigned int, CWalletTx*> & item : mapSorted) {
21822189
CWalletTx& wtx = *item.second;
@@ -4256,8 +4263,9 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
42564263
LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
42574264
nMaxVersion = FEATURE_LATEST;
42584265
walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
4259-
} else
4266+
} else {
42604267
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
4268+
}
42614269
if (nMaxVersion < walletInstance->GetVersion()) {
42624270
UIError("Cannot downgrade wallet\n");
42634271
return nullptr;

src/wallet/walletdb.cpp

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2014 The Bitcoin developers
2+
// Copyright (c) 2009-2021 The Bitcoin developers
33
// Copyright (c) 2014-2015 The Dash developers
4-
// Copyright (c) 2015-2020 The PIVX developers
4+
// Copyright (c) 2015-2021 The PIVX developers
55
// Distributed under the MIT/X11 software license, see the accompanying
66
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
77

@@ -100,8 +100,9 @@ bool CWalletDB::EraseTx(uint256 hash)
100100

101101
bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta)
102102
{
103-
if (!WriteIC(std::make_pair(std::string(DBKeys::KEYMETA), vchPubKey), keyMeta, false))
103+
if (!WriteIC(std::make_pair(std::string(DBKeys::KEYMETA), vchPubKey), keyMeta, false)) {
104104
return false;
105+
}
105106

106107
// hash pubkey/privkey to accelerate wallet load
107108
std::vector<unsigned char> vchKey;
@@ -113,16 +114,18 @@ bool CWalletDB::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, c
113114
}
114115

115116
bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
116-
const std::vector<unsigned char>& vchCryptedSecret,
117-
const CKeyMetadata& keyMeta)
117+
const std::vector<unsigned char>& vchCryptedSecret,
118+
const CKeyMetadata& keyMeta)
118119
{
119120
const bool fEraseUnencryptedKey = true;
120121

121-
if (!WriteIC(std::make_pair(std::string(DBKeys::KEYMETA), vchPubKey), keyMeta))
122+
if (!WriteIC(std::make_pair(std::string(DBKeys::KEYMETA), vchPubKey), keyMeta)) {
122123
return false;
124+
}
123125

124-
if (!WriteIC(std::make_pair(std::string(DBKeys::CRYPTED_KEY), vchPubKey), vchCryptedSecret, false))
126+
if (!WriteIC(std::make_pair(std::string(DBKeys::CRYPTED_KEY), vchPubKey), vchCryptedSecret, false)) {
125127
return false;
128+
}
126129
if (fEraseUnencryptedKey) {
127130
EraseIC(std::make_pair(std::string(DBKeys::KEY), vchPubKey));
128131
}
@@ -134,32 +137,34 @@ bool CWalletDB::WriteSaplingZKey(const libzcash::SaplingIncomingViewingKey &ivk,
134137
const libzcash::SaplingExtendedSpendingKey &key,
135138
const CKeyMetadata &keyMeta)
136139
{
137-
if (!WriteIC(std::make_pair(std::string(DBKeys::SAP_KEYMETA), ivk), keyMeta))
140+
if (!WriteIC(std::make_pair(std::string(DBKeys::SAP_KEYMETA), ivk), keyMeta)) {
138141
return false;
142+
}
139143

140144
return WriteIC(std::make_pair(std::string(DBKeys::SAP_KEY), ivk), key, false);
141145
}
142146

143-
bool CWalletDB::WriteSaplingPaymentAddress(
144-
const libzcash::SaplingPaymentAddress &addr,
145-
const libzcash::SaplingIncomingViewingKey &ivk)
147+
bool CWalletDB::WriteSaplingPaymentAddress(const libzcash::SaplingPaymentAddress &addr,
148+
const libzcash::SaplingIncomingViewingKey &ivk)
146149
{
147150
return WriteIC(std::make_pair(std::string(DBKeys::SAP_ADDR), addr), ivk, false);
148151
}
149152

150-
bool CWalletDB::WriteCryptedSaplingZKey(
151-
const libzcash::SaplingExtendedFullViewingKey &extfvk,
152-
const std::vector<unsigned char>& vchCryptedSecret,
153-
const CKeyMetadata &keyMeta)
153+
bool CWalletDB::WriteCryptedSaplingZKey(const libzcash::SaplingExtendedFullViewingKey &extfvk,
154+
const std::vector<unsigned char>& vchCryptedSecret,
155+
const CKeyMetadata &keyMeta)
154156
{
155157
const bool fEraseUnencryptedKey = true;
156158
auto ivk = extfvk.fvk.in_viewing_key();
157159

158-
if (!WriteIC(std::make_pair(std::string(DBKeys::SAP_KEYMETA), ivk), keyMeta))
160+
if (!WriteIC(std::make_pair(std::string(DBKeys::SAP_KEYMETA), ivk), keyMeta)) {
159161
return false;
162+
}
160163

161-
if (!WriteIC(std::make_pair(std::string(DBKeys::SAP_KEY_CRIPTED), ivk), std::make_pair(extfvk, vchCryptedSecret), false))
164+
if (!WriteIC(std::make_pair(std::string(DBKeys::SAP_KEY_CRIPTED), ivk),
165+
std::make_pair(extfvk, vchCryptedSecret), false)) {
162166
return false;
167+
}
163168

164169
if (fEraseUnencryptedKey) {
165170
EraseIC(std::make_pair(std::string(DBKeys::SAP_KEY), ivk));
@@ -210,7 +215,9 @@ bool CWalletDB::WriteBestBlock(const CBlockLocator& locator)
210215

211216
bool CWalletDB::ReadBestBlock(CBlockLocator& locator)
212217
{
213-
if (batch.Read(std::string(DBKeys::BESTBLOCK), locator) && !locator.vHave.empty()) return true;
218+
if (batch.Read(std::string(DBKeys::BESTBLOCK), locator) && !locator.vHave.empty()) {
219+
return true;
220+
}
214221
return batch.Read(std::string(DBKeys::BESTBLOCK_NOMERKLE), locator);
215222
}
216223

@@ -279,7 +286,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
279286
typedef std::multimap<int64_t, CWalletTx*> TxItems;
280287
TxItems txByTime;
281288

282-
for (std::map<uint256, CWalletTx>::iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) {
289+
for (auto it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) {
283290
CWalletTx* wtx = &((*it).second);
284291
txByTime.insert(std::make_pair(wtx->nTimeReceived, wtx));
285292
}
@@ -295,8 +302,8 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
295302
nOrderPos = nOrderPosNext++;
296303
nOrderPosOffsets.push_back(nOrderPos);
297304

298-
if (!WriteTx(*pwtx))
299-
return DB_LOAD_FAIL;
305+
if (!WriteTx(*pwtx)) return DB_LOAD_FAIL;
306+
300307
} else {
301308
int64_t nOrderPosOff = 0;
302309
for (const int64_t& nOffsetStart : nOrderPosOffsets) {
@@ -306,12 +313,10 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
306313
nOrderPos += nOrderPosOff;
307314
nOrderPosNext = std::max(nOrderPosNext, nOrderPos + 1);
308315

309-
if (!nOrderPosOff)
310-
continue;
316+
if (!nOrderPosOff) continue;
311317

312318
// Since we're changing the order, write it back
313-
if (!WriteTx(*pwtx))
314-
return DB_LOAD_FAIL;
319+
if (!WriteTx(*pwtx)) return DB_LOAD_FAIL;
315320
}
316321
}
317322
WriteOrderPosNext(nOrderPosNext);
@@ -626,8 +631,9 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
626631
try {
627632
int nMinVersion = 0;
628633
if (batch.Read((std::string) DBKeys::MINVERSION, nMinVersion)) {
629-
if (nMinVersion > CLIENT_VERSION)
634+
if (nMinVersion > CLIENT_VERSION) {
630635
return DB_TOO_NEW;
636+
}
631637
pwallet->LoadMinVersion(nMinVersion);
632638
}
633639

@@ -643,9 +649,9 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
643649
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
644650
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
645651
int ret = batch.ReadAtCursor(pcursor, ssKey, ssValue);
646-
if (ret == DB_NOTFOUND)
652+
if (ret == DB_NOTFOUND) {
647653
break;
648-
else if (ret != 0) {
654+
} else if (ret != 0) {
649655
LogPrintf("Error reading next record from wallet database\n");
650656
return DB_CORRUPT;
651657
}
@@ -655,9 +661,9 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
655661
if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) {
656662
// losing keys is considered a catastrophic error, anything else
657663
// we assume the user can live with:
658-
if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY)
664+
if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY) {
659665
result = DB_CORRUPT;
660-
else {
666+
} else {
661667
// Leave other errors alone, if we try to fix them we might make things worse.
662668
fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
663669
if (strType == DBKeys::TX)
@@ -695,18 +701,22 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
695701
if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
696702
pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
697703

698-
for (const uint256& hash : wss.vWalletUpgrade)
704+
for (const uint256& hash : wss.vWalletUpgrade) {
699705
WriteTx(pwallet->mapWallet.at(hash));
706+
}
700707

701708
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
702-
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
709+
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000)) {
703710
return DB_NEED_REWRITE;
711+
}
704712

705-
if (wss.nFileVersion < CLIENT_VERSION) // Update
713+
if (wss.nFileVersion < CLIENT_VERSION) { // Update
706714
WriteVersion(CLIENT_VERSION);
715+
}
707716

708-
if (wss.fAnyUnordered)
717+
if (wss.fAnyUnordered) {
709718
result = ReorderTransactions(pwallet);
719+
}
710720

711721
return result;
712722
}
@@ -720,8 +730,9 @@ DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash
720730
LOCK(pwallet->cs_wallet);
721731
int nMinVersion = 0;
722732
if (batch.Read((std::string) DBKeys::MINVERSION, nMinVersion)) {
723-
if (nMinVersion > CLIENT_VERSION)
733+
if (nMinVersion > CLIENT_VERSION) {
724734
return DB_TOO_NEW;
735+
}
725736
pwallet->LoadMinVersion(nMinVersion);
726737
}
727738

@@ -737,9 +748,9 @@ DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash
737748
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
738749
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
739750
int ret = batch.ReadAtCursor(pcursor, ssKey, ssValue);
740-
if (ret == DB_NOTFOUND)
751+
if (ret == DB_NOTFOUND) {
741752
break;
742-
else if (ret != 0) {
753+
} else if (ret != 0) {
743754
LogPrintf("Error reading next record from wallet database\n");
744755
return DB_CORRUPT;
745756
}
@@ -775,13 +786,13 @@ DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, std::vector<CWalletTx>& vWtx)
775786
// build list of wallet TXs
776787
std::vector<uint256> vTxHash;
777788
DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx);
778-
if (err != DB_LOAD_OK)
789+
if (err != DB_LOAD_OK) {
779790
return err;
791+
}
780792

781793
// erase each wallet TX
782794
for (uint256& hash : vTxHash) {
783-
if (!EraseTx(hash))
784-
return DB_CORRUPT;
795+
if (!EraseTx(hash)) return DB_CORRUPT;
785796
}
786797

787798
return DB_LOAD_OK;

src/wallet/walletdb.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2013 The Bitcoin developers
3-
// Copyright (c) 2016-2020 The PIVX developers
2+
// Copyright (c) 2009-2021 The Bitcoin developers
3+
// Copyright (c) 2016-2021 The PIVX developers
44
// Distributed under the MIT/X11 software license, see the accompanying
55
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

7-
#ifndef BITCOIN_WALLETDB_H
8-
#define BITCOIN_WALLETDB_H
7+
#ifndef PIVX_WALLETDB_H
8+
#define PIVX_WALLETDB_H
99

1010
#include "amount.h"
1111
#include "wallet/db.h"
@@ -247,4 +247,4 @@ bool AutoBackupWallet(const std::string& strWalletFile, std::string& strBackupWa
247247
//! Compacts BDB state so that wallet.dat is self-contained (if there are changes)
248248
void MaybeCompactWalletDB();
249249

250-
#endif // BITCOIN_WALLETDB_H
250+
#endif // PIVX_WALLETDB_H

0 commit comments

Comments
 (0)