Skip to content

Commit a1f8d3e

Browse files
committed
Merge #8696: [Wallet] Remove last external reference to CWalletDB
2ca6b9d Remove last reference to CWalletDB from accounting_tests.cpp (Patrick Strateman) 02e2a81 Remove pwalletdb parameter from CWallet::AddAccountingEntry (Patrick Strateman) d2e678d Add CWallet::ReorderTransactions and use in accounting_tests.cpp (Patrick Strateman) 59adc86 Add CWallet::ListAccountCreditDebit (Patrick Strateman)
2 parents 02ac669 + 2ca6b9d commit a1f8d3e

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

src/wallet/test/accounting_tests.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "wallet/wallet.h"
6-
#include "wallet/walletdb.h"
76

87
#include "wallet/test/wallet_test_fixture.h"
98

@@ -17,13 +16,13 @@ extern CWallet* pwalletMain;
1716
BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)
1817

1918
static void
20-
GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
19+
GetResults(std::map<CAmount, CAccountingEntry>& results)
2120
{
2221
std::list<CAccountingEntry> aes;
2322

2423
results.clear();
25-
BOOST_CHECK(walletdb.ReorderTransactions(pwalletMain) == DB_LOAD_OK);
26-
walletdb.ListAccountCreditDebit("", aes);
24+
BOOST_CHECK(pwalletMain->ReorderTransactions() == DB_LOAD_OK);
25+
pwalletMain->ListAccountCreditDebit("", aes);
2726
BOOST_FOREACH(CAccountingEntry& ae, aes)
2827
{
2928
results[ae.nOrderPos] = ae;
@@ -32,7 +31,6 @@ GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
3231

3332
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
3433
{
35-
CWalletDB walletdb(pwalletMain->strWalletFile);
3634
std::vector<CWalletTx*> vpwtx;
3735
CWalletTx wtx;
3836
CAccountingEntry ae;
@@ -45,7 +43,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
4543
ae.nTime = 1333333333;
4644
ae.strOtherAccount = "b";
4745
ae.strComment = "";
48-
pwalletMain->AddAccountingEntry(ae, walletdb);
46+
pwalletMain->AddAccountingEntry(ae);
4947

5048
wtx.mapValue["comment"] = "z";
5149
pwalletMain->AddToWallet(wtx);
@@ -55,9 +53,9 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
5553

5654
ae.nTime = 1333333336;
5755
ae.strOtherAccount = "c";
58-
pwalletMain->AddAccountingEntry(ae, walletdb);
56+
pwalletMain->AddAccountingEntry(ae);
5957

60-
GetResults(walletdb, results);
58+
GetResults(results);
6159

6260
BOOST_CHECK(pwalletMain->nOrderPosNext == 3);
6361
BOOST_CHECK(2 == results.size());
@@ -71,9 +69,9 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
7169
ae.nTime = 1333333330;
7270
ae.strOtherAccount = "d";
7371
ae.nOrderPos = pwalletMain->IncOrderPosNext();
74-
pwalletMain->AddAccountingEntry(ae, walletdb);
72+
pwalletMain->AddAccountingEntry(ae);
7573

76-
GetResults(walletdb, results);
74+
GetResults(results);
7775

7876
BOOST_CHECK(results.size() == 3);
7977
BOOST_CHECK(pwalletMain->nOrderPosNext == 4);
@@ -105,7 +103,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
105103
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
106104
vpwtx[2]->nOrderPos = -1;
107105

108-
GetResults(walletdb, results);
106+
GetResults(results);
109107

110108
BOOST_CHECK(results.size() == 3);
111109
BOOST_CHECK(pwalletMain->nOrderPosNext == 6);
@@ -121,9 +119,9 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
121119
ae.nTime = 1333333334;
122120
ae.strOtherAccount = "e";
123121
ae.nOrderPos = -1;
124-
pwalletMain->AddAccountingEntry(ae, walletdb);
122+
pwalletMain->AddAccountingEntry(ae);
125123

126-
GetResults(walletdb, results);
124+
GetResults(results);
127125

128126
BOOST_CHECK(results.size() == 4);
129127
BOOST_CHECK(pwalletMain->nOrderPosNext == 7);

src/wallet/wallet.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,12 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
649649
return true;
650650
}
651651

652+
DBErrors CWallet::ReorderTransactions()
653+
{
654+
CWalletDB walletdb(strWalletFile);
655+
return walletdb.ReorderTransactions(this);
656+
}
657+
652658
int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
653659
{
654660
AssertLockHeld(cs_wallet); // nOrderPosNext
@@ -677,7 +683,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
677683
debit.nTime = nNow;
678684
debit.strOtherAccount = strTo;
679685
debit.strComment = strComment;
680-
AddAccountingEntry(debit, walletdb);
686+
AddAccountingEntry(debit, &walletdb);
681687

682688
// Credit
683689
CAccountingEntry credit;
@@ -687,7 +693,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
687693
credit.nTime = nNow;
688694
credit.strOtherAccount = strFrom;
689695
credit.strComment = strComment;
690-
AddAccountingEntry(credit, walletdb);
696+
AddAccountingEntry(credit, &walletdb);
691697

692698
if (!walletdb.TxnCommit())
693699
return false;
@@ -2501,9 +2507,21 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon
25012507
return true;
25022508
}
25032509

2504-
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB & pwalletdb)
2510+
void CWallet::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries) {
2511+
CWalletDB walletdb(strWalletFile);
2512+
return walletdb.ListAccountCreditDebit(strAccount, entries);
2513+
}
2514+
2515+
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry)
2516+
{
2517+
CWalletDB walletdb(strWalletFile);
2518+
2519+
return AddAccountingEntry(acentry, &walletdb);
2520+
}
2521+
2522+
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwalletdb)
25052523
{
2506-
if (!pwalletdb.WriteAccountingEntry_Backend(acentry))
2524+
if (!pwalletdb->WriteAccountingEntry_Backend(acentry))
25072525
return false;
25082526

25092527
laccentries.push_back(acentry);

src/wallet/wallet.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
741741
* @return next transaction order id
742742
*/
743743
int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
744+
DBErrors ReorderTransactions();
744745
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
745746
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
746747

@@ -775,7 +776,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
775776
std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true);
776777
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman);
777778

778-
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
779+
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
780+
bool AddAccountingEntry(const CAccountingEntry&);
781+
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
779782

780783
static CFeeRate minTxFee;
781784
static CFeeRate fallbackFee;

0 commit comments

Comments
 (0)