Browse Source

Merge branch 'refactor_times' of git://github.com/luke-jr/bitcoin

0.8
Gavin Andresen 12 years ago
parent
commit
a0971337d0
  1. 4
      src/rpcwallet.cpp
  2. 2
      src/test/accounting_tests.cpp
  3. 9
      src/wallet.cpp
  4. 7
      src/wallet.h
  5. 4
      src/walletdb.cpp
  6. 6
      src/walletdb.h

4
src/rpcwallet.cpp

@ -573,7 +573,7 @@ Value movecmd(const Array& params, bool fHelp)
// Debit // Debit
CAccountingEntry debit; CAccountingEntry debit;
debit.nOrderPos = pwalletMain->nOrderPosNext++; debit.nOrderPos = pwalletMain->IncOrderPosNext();
debit.strAccount = strFrom; debit.strAccount = strFrom;
debit.nCreditDebit = -nAmount; debit.nCreditDebit = -nAmount;
debit.nTime = nNow; debit.nTime = nNow;
@ -583,7 +583,7 @@ Value movecmd(const Array& params, bool fHelp)
// Credit // Credit
CAccountingEntry credit; CAccountingEntry credit;
credit.nOrderPos = pwalletMain->nOrderPosNext++; credit.nOrderPos = pwalletMain->IncOrderPosNext();
credit.strAccount = strTo; credit.strAccount = strTo;
credit.nCreditDebit = nAmount; credit.nCreditDebit = nAmount;
credit.nTime = nNow; credit.nTime = nNow;

2
src/test/accounting_tests.cpp

@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
ae.nTime = 1333333330; ae.nTime = 1333333330;
ae.strOtherAccount = "d"; ae.strOtherAccount = "d";
ae.nOrderPos = pwalletMain->nOrderPosNext++; ae.nOrderPos = pwalletMain->IncOrderPosNext();
walletdb.WriteAccountingEntry(ae); walletdb.WriteAccountingEntry(ae);
GetResults(walletdb, results); GetResults(walletdb, results);

9
src/wallet.cpp

@ -291,6 +291,13 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
return true; 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) CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount)
{ {
CWalletDB walletdb(strWalletFile); CWalletDB walletdb(strWalletFile);
@ -362,7 +369,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
if (fInsertedNew) if (fInsertedNew)
{ {
wtx.nTimeReceived = GetAdjustedTime(); wtx.nTimeReceived = GetAdjustedTime();
wtx.nOrderPos = nOrderPosNext++; wtx.nOrderPos = IncOrderPosNext();
wtx.nTimeSmart = wtx.nTimeReceived; wtx.nTimeSmart = wtx.nTimeReceived;
if (wtxIn.hashBlock != 0) if (wtxIn.hashBlock != 0)

7
src/wallet.h

@ -98,6 +98,7 @@ public:
fFileBacked = false; fFileBacked = false;
nMasterKeyMaxID = 0; nMasterKeyMaxID = 0;
pwalletdbEncryption = NULL; pwalletdbEncryption = NULL;
nOrderPosNext = 0;
} }
CWallet(std::string strWalletFileIn) CWallet(std::string strWalletFileIn)
{ {
@ -107,6 +108,7 @@ public:
fFileBacked = true; fFileBacked = true;
nMasterKeyMaxID = 0; nMasterKeyMaxID = 0;
pwalletdbEncryption = NULL; pwalletdbEncryption = NULL;
nOrderPosNext = 0;
} }
std::map<uint256, CWalletTx> mapWallet; std::map<uint256, CWalletTx> mapWallet;
@ -144,6 +146,11 @@ public:
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
bool EncryptWallet(const SecureString& strWalletPassphrase); 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::pair<CWalletTx*, CAccountingEntry*> TxPair;
typedef std::multimap<int64, TxPair > TxItems; typedef std::multimap<int64, TxPair > TxItems;

4
src/walletdb.cpp

@ -392,6 +392,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
return DB_CORRUPT; return DB_CORRUPT;
} }
} }
else if (strType == "orderposnext")
{
ssValue >> pwallet->nOrderPosNext;
}
} }
pcursor->close(); pcursor->close();
} }

6
src/walletdb.h

@ -115,6 +115,12 @@ public:
return Read(std::string("bestblock"), locator); return Read(std::string("bestblock"), locator);
} }
bool WriteOrderPosNext(int64 nOrderPosNext)
{
nWalletDBUpdated++;
return Write(std::string("orderposnext"), nOrderPosNext);
}
bool ReadDefaultKey(std::vector<unsigned char>& vchPubKey) bool ReadDefaultKey(std::vector<unsigned char>& vchPubKey)
{ {
vchPubKey.clear(); vchPubKey.clear();

Loading…
Cancel
Save