diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-09-08 04:55:36 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-09-08 04:55:36 +0000 |
commit | da7b8c1260d91e3306eb18dd65633567cb31332f (patch) | |
tree | 1fad88d0c8f5bb0953887c268e9a5a55910931d8 /src | |
parent | ddb709e9de1490afcfa1af045517d2228d5b864c (diff) |
Bugfix: Initialize CWallet::nOrderPosNext on an empty wallet, and save it in db
Diffstat (limited to 'src')
-rw-r--r-- | src/rpcwallet.cpp | 4 | ||||
-rw-r--r-- | src/test/accounting_tests.cpp | 2 | ||||
-rw-r--r-- | src/wallet.cpp | 9 | ||||
-rw-r--r-- | src/wallet.h | 7 | ||||
-rw-r--r-- | src/walletdb.cpp | 4 | ||||
-rw-r--r-- | src/walletdb.h | 6 |
6 files changed, 28 insertions, 4 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 20df4c0a68..475fe1baf9 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -544,7 +544,7 @@ Value movecmd(const Array& params, bool fHelp) // Debit CAccountingEntry debit; - debit.nOrderPos = pwalletMain->nOrderPosNext++; + debit.nOrderPos = pwalletMain->IncOrderPosNext(); debit.strAccount = strFrom; debit.nCreditDebit = -nAmount; debit.nTime = nNow; @@ -554,7 +554,7 @@ Value movecmd(const Array& params, bool fHelp) // Credit CAccountingEntry credit; - credit.nOrderPos = pwalletMain->nOrderPosNext++; + credit.nOrderPos = pwalletMain->IncOrderPosNext(); credit.strAccount = strTo; credit.nCreditDebit = nAmount; credit.nTime = nNow; diff --git a/src/test/accounting_tests.cpp b/src/test/accounting_tests.cpp index c474fd65c1..8ac657288b 100644 --- a/src/test/accounting_tests.cpp +++ b/src/test/accounting_tests.cpp @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade) ae.nTime = 1333333330; ae.strOtherAccount = "d"; - ae.nOrderPos = pwalletMain->nOrderPosNext++; + ae.nOrderPos = pwalletMain->IncOrderPosNext(); walletdb.WriteAccountingEntry(ae); GetResults(walletdb, results); diff --git a/src/wallet.cpp b/src/wallet.cpp index 3af9fdaeae..74c1112d60 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -291,6 +291,13 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) return true; } +int64 CWallet::IncOrderPosNext() +{ + int64 nRet = nOrderPosNext; + CWalletDB(strWalletFile).WriteOrderPosNext(++nOrderPosNext); + return nRet; +} + CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount) { CWalletDB walletdb(strWalletFile); @@ -362,7 +369,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) if (fInsertedNew) { wtx.nTimeReceived = GetAdjustedTime(); - wtx.nOrderPos = nOrderPosNext++; + wtx.nOrderPos = IncOrderPosNext(); wtx.nTimeSmart = wtx.nTimeReceived; if (wtxIn.hashBlock != 0) diff --git a/src/wallet.h b/src/wallet.h index 65d3448212..d3e9fd4ba4 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -98,6 +98,7 @@ public: fFileBacked = false; nMasterKeyMaxID = 0; pwalletdbEncryption = NULL; + nOrderPosNext = 0; } CWallet(std::string strWalletFileIn) { @@ -107,6 +108,7 @@ public: fFileBacked = true; nMasterKeyMaxID = 0; pwalletdbEncryption = NULL; + nOrderPosNext = 0; } std::map<uint256, CWalletTx> mapWallet; @@ -144,6 +146,11 @@ public: bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool EncryptWallet(const SecureString& strWalletPassphrase); + /** Increment the next transaction order id + @return next transaction order id + */ + int64 IncOrderPosNext(); + typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair; typedef std::multimap<int64, TxPair > TxItems; diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 164b68e11f..0fac0109c8 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -392,6 +392,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) return DB_CORRUPT; } } + else if (strType == "orderposnext") + { + ssValue >> pwallet->nOrderPosNext; + } } pcursor->close(); } diff --git a/src/walletdb.h b/src/walletdb.h index 187be65a97..d339d4c3f1 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -115,6 +115,12 @@ public: return Read(std::string("bestblock"), locator); } + bool WriteOrderPosNext(int64 nOrderPosNext) + { + nWalletDBUpdated++; + return Write(std::string("orderposnext"), nOrderPosNext); + } + bool ReadDefaultKey(std::vector<unsigned char>& vchPubKey) { vchPubKey.clear(); |