From 59adc86680911a83dcccf5b23db299a370fc92f2 Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Fri, 9 Sep 2016 18:53:23 -0700 Subject: [PATCH 1/4] Add CWallet::ListAccountCreditDebit Simple pass through for CWalletDB::ListAccountCreditDebit --- src/wallet/test/accounting_tests.cpp | 2 +- src/wallet/wallet.cpp | 5 +++++ src/wallet/wallet.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp index a6cada46a..1863652fd 100644 --- a/src/wallet/test/accounting_tests.cpp +++ b/src/wallet/test/accounting_tests.cpp @@ -23,7 +23,7 @@ GetResults(CWalletDB& walletdb, std::map& results) results.clear(); BOOST_CHECK(walletdb.ReorderTransactions(pwalletMain) == DB_LOAD_OK); - walletdb.ListAccountCreditDebit("", aes); + pwalletMain->ListAccountCreditDebit("", aes); BOOST_FOREACH(CAccountingEntry& ae, aes) { results[ae.nOrderPos] = ae; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4c10ea0ed..7b5511167 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2501,6 +2501,11 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon return true; } +void CWallet::ListAccountCreditDebit(const std::string& strAccount, std::list& entries) { + CWalletDB walletdb(strWalletFile); + return walletdb.ListAccountCreditDebit(strAccount, entries); +} + bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB & pwalletdb) { if (!pwalletdb.WriteAccountingEntry_Backend(acentry)) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 61aff6e45..160e097a8 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -775,6 +775,7 @@ public: std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman); + void ListAccountCreditDebit(const std::string& strAccount, std::list& entries); bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb); static CFeeRate minTxFee; From d2e678d7d220e2f430c2cb4bde559acee00c8c7c Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Fri, 9 Sep 2016 19:21:44 -0700 Subject: [PATCH 2/4] Add CWallet::ReorderTransactions and use in accounting_tests.cpp --- src/wallet/test/accounting_tests.cpp | 2 +- src/wallet/wallet.cpp | 6 ++++++ src/wallet/wallet.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp index 1863652fd..ad2f081b4 100644 --- a/src/wallet/test/accounting_tests.cpp +++ b/src/wallet/test/accounting_tests.cpp @@ -22,7 +22,7 @@ GetResults(CWalletDB& walletdb, std::map& results) std::list aes; results.clear(); - BOOST_CHECK(walletdb.ReorderTransactions(pwalletMain) == DB_LOAD_OK); + BOOST_CHECK(pwalletMain->ReorderTransactions() == DB_LOAD_OK); pwalletMain->ListAccountCreditDebit("", aes); BOOST_FOREACH(CAccountingEntry& ae, aes) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7b5511167..fe9671926 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -649,6 +649,12 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) return true; } +DBErrors CWallet::ReorderTransactions() +{ + CWalletDB walletdb(strWalletFile); + return walletdb.ReorderTransactions(this); +} + int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb) { AssertLockHeld(cs_wallet); // nOrderPosNext diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 160e097a8..2b978ba1e 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -741,6 +741,7 @@ public: * @return next transaction order id */ int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL); + DBErrors ReorderTransactions(); bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = ""); bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false); From 02e2a815367945ea556a1ae9c3596917553ddfdb Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Fri, 9 Sep 2016 19:22:59 -0700 Subject: [PATCH 3/4] Remove pwalletdb parameter from CWallet::AddAccountingEntry --- src/wallet/test/accounting_tests.cpp | 8 ++++---- src/wallet/wallet.cpp | 15 +++++++++++---- src/wallet/wallet.h | 3 ++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp index ad2f081b4..6fc3a32ae 100644 --- a/src/wallet/test/accounting_tests.cpp +++ b/src/wallet/test/accounting_tests.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nTime = 1333333333; ae.strOtherAccount = "b"; ae.strComment = ""; - pwalletMain->AddAccountingEntry(ae, walletdb); + pwalletMain->AddAccountingEntry(ae); wtx.mapValue["comment"] = "z"; pwalletMain->AddToWallet(wtx); @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nTime = 1333333336; ae.strOtherAccount = "c"; - pwalletMain->AddAccountingEntry(ae, walletdb); + pwalletMain->AddAccountingEntry(ae); GetResults(walletdb, results); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nTime = 1333333330; ae.strOtherAccount = "d"; ae.nOrderPos = pwalletMain->IncOrderPosNext(); - pwalletMain->AddAccountingEntry(ae, walletdb); + pwalletMain->AddAccountingEntry(ae); GetResults(walletdb, results); @@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nTime = 1333333334; ae.strOtherAccount = "e"; ae.nOrderPos = -1; - pwalletMain->AddAccountingEntry(ae, walletdb); + pwalletMain->AddAccountingEntry(ae); GetResults(walletdb, results); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fe9671926..1d7ddd99a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -683,7 +683,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun debit.nTime = nNow; debit.strOtherAccount = strTo; debit.strComment = strComment; - AddAccountingEntry(debit, walletdb); + AddAccountingEntry(debit, &walletdb); // Credit CAccountingEntry credit; @@ -693,7 +693,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun credit.nTime = nNow; credit.strOtherAccount = strFrom; credit.strComment = strComment; - AddAccountingEntry(credit, walletdb); + AddAccountingEntry(credit, &walletdb); if (!walletdb.TxnCommit()) return false; @@ -2512,9 +2512,16 @@ void CWallet::ListAccountCreditDebit(const std::string& strAccount, std::listWriteAccountingEntry_Backend(acentry)) return false; laccentries.push_back(acentry); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2b978ba1e..584f01320 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -777,7 +777,8 @@ public: bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman); void ListAccountCreditDebit(const std::string& strAccount, std::list& entries); - bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb); + bool AddAccountingEntry(const CAccountingEntry&); + bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb); static CFeeRate minTxFee; static CFeeRate fallbackFee; From 2ca6b9df1dfe50c294b01b5f06c5c5c7489f46c3 Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Fri, 9 Sep 2016 19:23:36 -0700 Subject: [PATCH 4/4] Remove last reference to CWalletDB from accounting_tests.cpp --- src/wallet/test/accounting_tests.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp index 6fc3a32ae..a833be13d 100644 --- a/src/wallet/test/accounting_tests.cpp +++ b/src/wallet/test/accounting_tests.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "wallet/wallet.h" -#include "wallet/walletdb.h" #include "wallet/test/wallet_test_fixture.h" @@ -17,7 +16,7 @@ extern CWallet* pwalletMain; BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup) static void -GetResults(CWalletDB& walletdb, std::map& results) +GetResults(std::map& results) { std::list aes; @@ -32,7 +31,6 @@ GetResults(CWalletDB& walletdb, std::map& results) BOOST_AUTO_TEST_CASE(acc_orderupgrade) { - CWalletDB walletdb(pwalletMain->strWalletFile); std::vector vpwtx; CWalletTx wtx; CAccountingEntry ae; @@ -57,7 +55,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.strOtherAccount = "c"; pwalletMain->AddAccountingEntry(ae); - GetResults(walletdb, results); + GetResults(results); BOOST_CHECK(pwalletMain->nOrderPosNext == 3); BOOST_CHECK(2 == results.size()); @@ -73,7 +71,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nOrderPos = pwalletMain->IncOrderPosNext(); pwalletMain->AddAccountingEntry(ae); - GetResults(walletdb, results); + GetResults(results); BOOST_CHECK(results.size() == 3); BOOST_CHECK(pwalletMain->nOrderPosNext == 4); @@ -105,7 +103,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) vpwtx[2]->nTimeReceived = (unsigned int)1333333329; vpwtx[2]->nOrderPos = -1; - GetResults(walletdb, results); + GetResults(results); BOOST_CHECK(results.size() == 3); BOOST_CHECK(pwalletMain->nOrderPosNext == 6); @@ -123,7 +121,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nOrderPos = -1; pwalletMain->AddAccountingEntry(ae); - GetResults(walletdb, results); + GetResults(results); BOOST_CHECK(results.size() == 4); BOOST_CHECK(pwalletMain->nOrderPosNext == 7);