@@ -588,31 +588,6 @@ int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
588588 return nRet;
589589}
590590
591- CWallet::TxItems CWallet::OrderedTxItems (std::list<CAccountingEntry>& acentries, std::string strAccount)
592- {
593- AssertLockHeld (cs_wallet); // mapWallet
594- CWalletDB walletdb (strWalletFile);
595-
596- // First: get all CWalletTx and CAccountingEntry into a sorted-by-order multimap.
597- TxItems txOrdered;
598-
599- // Note: maintaining indices in the database of (account,time) --> txid and (account, time) --> acentry
600- // would make this much faster for applications that do this a lot.
601- for (map<uint256, CWalletTx>::iterator it = mapWallet.begin (); it != mapWallet.end (); ++it)
602- {
603- CWalletTx* wtx = &((*it).second );
604- txOrdered.insert (make_pair (wtx->nOrderPos , TxPair (wtx, (CAccountingEntry*)0 )));
605- }
606- acentries.clear ();
607- walletdb.ListAccountCreditDebit (strAccount, acentries);
608- BOOST_FOREACH (CAccountingEntry& entry, acentries)
609- {
610- txOrdered.insert (make_pair (entry.nOrderPos , TxPair ((CWalletTx*)0 , &entry)));
611- }
612-
613- return txOrdered;
614- }
615-
616591void CWallet::MarkDirty ()
617592{
618593 {
@@ -629,7 +604,9 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
629604 if (fFromLoadWallet )
630605 {
631606 mapWallet[hash] = wtxIn;
632- mapWallet[hash].BindWallet (this );
607+ CWalletTx& wtx = mapWallet[hash];
608+ wtx.BindWallet (this );
609+ wtxOrdered.insert (make_pair (wtx.nOrderPos , TxPair (&wtx, (CAccountingEntry*)0 )));
633610 AddToSpends (hash);
634611 }
635612 else
@@ -644,6 +621,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
644621 {
645622 wtx.nTimeReceived = GetAdjustedTime ();
646623 wtx.nOrderPos = IncOrderPosNext (pwalletdb);
624+ wtxOrdered.insert (make_pair (wtx.nOrderPos , TxPair (&wtx, (CAccountingEntry*)0 )));
647625
648626 wtx.nTimeSmart = wtx.nTimeReceived ;
649627 if (!wtxIn.hashBlock .IsNull ())
@@ -655,9 +633,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
655633 {
656634 // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future
657635 int64_t latestTolerated = latestNow + 300 ;
658- std::list<CAccountingEntry> acentries;
659- TxItems txOrdered = OrderedTxItems (acentries);
660- for (TxItems::reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
636+ const TxItems & txOrdered = wtxOrdered;
637+ for (TxItems::const_reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it)
661638 {
662639 CWalletTx *const pwtx = (*it).second .first ;
663640 if (pwtx == &wtx)
@@ -2118,6 +2095,18 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
21182095 return true ;
21192096}
21202097
2098+ bool CWallet::AddAccountingEntry (const CAccountingEntry& acentry, CWalletDB & pwalletdb)
2099+ {
2100+ if (!pwalletdb.WriteAccountingEntry_Backend (acentry))
2101+ return false ;
2102+
2103+ laccentries.push_back (acentry);
2104+ CAccountingEntry & entry = laccentries.back ();
2105+ wtxOrdered.insert (make_pair (entry.nOrderPos , TxPair ((CWalletTx*)0 , &entry)));
2106+
2107+ return true ;
2108+ }
2109+
21212110CAmount CWallet::GetRequiredFee (unsigned int nTxBytes)
21222111{
21232112 return std::max (minTxFee.GetFee (nTxBytes), ::minRelayTxFee.GetFee (nTxBytes));
0 commit comments