mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
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)
This commit is contained in:
parent
fbbddf8107
commit
630c699f00
@ -3,7 +3,6 @@
|
|||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include "wallet/wallet.h"
|
#include "wallet/wallet.h"
|
||||||
#include "wallet/walletdb.h"
|
|
||||||
|
|
||||||
#include "wallet/test/wallet_test_fixture.h"
|
#include "wallet/test/wallet_test_fixture.h"
|
||||||
|
|
||||||
@ -17,13 +16,13 @@ extern CWallet* pwalletMain;
|
|||||||
BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
|
GetResults(std::map<CAmount, CAccountingEntry>& results)
|
||||||
{
|
{
|
||||||
std::list<CAccountingEntry> aes;
|
std::list<CAccountingEntry> aes;
|
||||||
|
|
||||||
results.clear();
|
results.clear();
|
||||||
BOOST_CHECK(walletdb.ReorderTransactions(pwalletMain) == DB_LOAD_OK);
|
BOOST_CHECK(pwalletMain->ReorderTransactions() == DB_LOAD_OK);
|
||||||
walletdb.ListAccountCreditDebit("", aes);
|
pwalletMain->ListAccountCreditDebit("", aes);
|
||||||
BOOST_FOREACH(CAccountingEntry& ae, aes)
|
BOOST_FOREACH(CAccountingEntry& ae, aes)
|
||||||
{
|
{
|
||||||
results[ae.nOrderPos] = ae;
|
results[ae.nOrderPos] = ae;
|
||||||
@ -32,7 +31,6 @@ GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
||||||
{
|
{
|
||||||
CWalletDB walletdb(pwalletMain->strWalletFile);
|
|
||||||
std::vector<CWalletTx*> vpwtx;
|
std::vector<CWalletTx*> vpwtx;
|
||||||
CWalletTx wtx;
|
CWalletTx wtx;
|
||||||
CAccountingEntry ae;
|
CAccountingEntry ae;
|
||||||
@ -45,7 +43,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|||||||
ae.nTime = 1333333333;
|
ae.nTime = 1333333333;
|
||||||
ae.strOtherAccount = "b";
|
ae.strOtherAccount = "b";
|
||||||
ae.strComment = "";
|
ae.strComment = "";
|
||||||
pwalletMain->AddAccountingEntry(ae, walletdb);
|
pwalletMain->AddAccountingEntry(ae);
|
||||||
|
|
||||||
wtx.mapValue["comment"] = "z";
|
wtx.mapValue["comment"] = "z";
|
||||||
pwalletMain->AddToWallet(wtx);
|
pwalletMain->AddToWallet(wtx);
|
||||||
@ -55,9 +53,9 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|||||||
|
|
||||||
ae.nTime = 1333333336;
|
ae.nTime = 1333333336;
|
||||||
ae.strOtherAccount = "c";
|
ae.strOtherAccount = "c";
|
||||||
pwalletMain->AddAccountingEntry(ae, walletdb);
|
pwalletMain->AddAccountingEntry(ae);
|
||||||
|
|
||||||
GetResults(walletdb, results);
|
GetResults(results);
|
||||||
|
|
||||||
BOOST_CHECK(pwalletMain->nOrderPosNext == 3);
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 3);
|
||||||
BOOST_CHECK(2 == results.size());
|
BOOST_CHECK(2 == results.size());
|
||||||
@ -71,9 +69,9 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|||||||
ae.nTime = 1333333330;
|
ae.nTime = 1333333330;
|
||||||
ae.strOtherAccount = "d";
|
ae.strOtherAccount = "d";
|
||||||
ae.nOrderPos = pwalletMain->IncOrderPosNext();
|
ae.nOrderPos = pwalletMain->IncOrderPosNext();
|
||||||
pwalletMain->AddAccountingEntry(ae, walletdb);
|
pwalletMain->AddAccountingEntry(ae);
|
||||||
|
|
||||||
GetResults(walletdb, results);
|
GetResults(results);
|
||||||
|
|
||||||
BOOST_CHECK(results.size() == 3);
|
BOOST_CHECK(results.size() == 3);
|
||||||
BOOST_CHECK(pwalletMain->nOrderPosNext == 4);
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 4);
|
||||||
@ -105,7 +103,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|||||||
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
|
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
|
||||||
vpwtx[2]->nOrderPos = -1;
|
vpwtx[2]->nOrderPos = -1;
|
||||||
|
|
||||||
GetResults(walletdb, results);
|
GetResults(results);
|
||||||
|
|
||||||
BOOST_CHECK(results.size() == 3);
|
BOOST_CHECK(results.size() == 3);
|
||||||
BOOST_CHECK(pwalletMain->nOrderPosNext == 6);
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 6);
|
||||||
@ -121,9 +119,9 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
|||||||
ae.nTime = 1333333334;
|
ae.nTime = 1333333334;
|
||||||
ae.strOtherAccount = "e";
|
ae.strOtherAccount = "e";
|
||||||
ae.nOrderPos = -1;
|
ae.nOrderPos = -1;
|
||||||
pwalletMain->AddAccountingEntry(ae, walletdb);
|
pwalletMain->AddAccountingEntry(ae);
|
||||||
|
|
||||||
GetResults(walletdb, results);
|
GetResults(results);
|
||||||
|
|
||||||
BOOST_CHECK(results.size() == 4);
|
BOOST_CHECK(results.size() == 4);
|
||||||
BOOST_CHECK(pwalletMain->nOrderPosNext == 7);
|
BOOST_CHECK(pwalletMain->nOrderPosNext == 7);
|
||||||
|
@ -863,6 +863,12 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBErrors CWallet::ReorderTransactions()
|
||||||
|
{
|
||||||
|
CWalletDB walletdb(strWalletFile);
|
||||||
|
return walletdb.ReorderTransactions(this);
|
||||||
|
}
|
||||||
|
|
||||||
int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
|
int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet); // nOrderPosNext
|
AssertLockHeld(cs_wallet); // nOrderPosNext
|
||||||
@ -891,7 +897,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
|
|||||||
debit.nTime = nNow;
|
debit.nTime = nNow;
|
||||||
debit.strOtherAccount = strTo;
|
debit.strOtherAccount = strTo;
|
||||||
debit.strComment = strComment;
|
debit.strComment = strComment;
|
||||||
AddAccountingEntry(debit, walletdb);
|
AddAccountingEntry(debit, &walletdb);
|
||||||
|
|
||||||
// Credit
|
// Credit
|
||||||
CAccountingEntry credit;
|
CAccountingEntry credit;
|
||||||
@ -901,7 +907,7 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
|
|||||||
credit.nTime = nNow;
|
credit.nTime = nNow;
|
||||||
credit.strOtherAccount = strFrom;
|
credit.strOtherAccount = strFrom;
|
||||||
credit.strComment = strComment;
|
credit.strComment = strComment;
|
||||||
AddAccountingEntry(credit, walletdb);
|
AddAccountingEntry(credit, &walletdb);
|
||||||
|
|
||||||
if (!walletdb.TxnCommit())
|
if (!walletdb.TxnCommit())
|
||||||
return false;
|
return false;
|
||||||
@ -3649,9 +3655,21 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB & pwalletdb)
|
void CWallet::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries) {
|
||||||
|
CWalletDB walletdb(strWalletFile);
|
||||||
|
return walletdb.ListAccountCreditDebit(strAccount, entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry)
|
||||||
{
|
{
|
||||||
if (!pwalletdb.WriteAccountingEntry_Backend(acentry))
|
CWalletDB walletdb(strWalletFile);
|
||||||
|
|
||||||
|
return AddAccountingEntry(acentry, &walletdb);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwalletdb)
|
||||||
|
{
|
||||||
|
if (!pwalletdb->WriteAccountingEntry_Backend(acentry))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
laccentries.push_back(acentry);
|
laccentries.push_back(acentry);
|
||||||
|
@ -852,6 +852,7 @@ public:
|
|||||||
* @return next transaction order id
|
* @return next transaction order id
|
||||||
*/
|
*/
|
||||||
int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
|
int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
|
||||||
|
DBErrors ReorderTransactions();
|
||||||
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
|
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
|
||||||
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
|
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
|
||||||
|
|
||||||
@ -899,7 +900,9 @@ public:
|
|||||||
bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason);
|
bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason);
|
||||||
bool ConvertList(std::vector<CTxIn> vecTxIn, std::vector<CAmount>& vecAmounts);
|
bool ConvertList(std::vector<CTxIn> vecTxIn, std::vector<CAmount>& vecAmounts);
|
||||||
|
|
||||||
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
|
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
|
||||||
|
bool AddAccountingEntry(const CAccountingEntry&);
|
||||||
|
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
|
||||||
|
|
||||||
static CFeeRate minTxFee;
|
static CFeeRate minTxFee;
|
||||||
static CFeeRate fallbackFee;
|
static CFeeRate fallbackFee;
|
||||||
|
Loading…
Reference in New Issue
Block a user