From 9c7722b7c5ce49130bd978b932f73b629ce5cebe Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 27 May 2012 23:06:09 +0000 Subject: Store a fixed order of transactions (and accounting) in the wallet For backward compatibility, new accounting data is stored after a \0 in the comment string. This way, old versions and third-party software should load and store them, but all actual use (listtransactions, for example) ignores it. --- src/rpcwallet.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/rpcwallet.cpp') diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 3b68105dd7..005a7766f1 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -542,6 +542,7 @@ Value movecmd(const Array& params, bool fHelp) // Debit CAccountingEntry debit; + debit.nOrderPos = pwalletMain->nOrderPosNext++; debit.strAccount = strFrom; debit.nCreditDebit = -nAmount; debit.nTime = nNow; @@ -551,6 +552,7 @@ Value movecmd(const Array& params, bool fHelp) // Credit CAccountingEntry credit; + credit.nOrderPos = pwalletMain->nOrderPosNext++; credit.strAccount = strTo; credit.nCreditDebit = nAmount; credit.nTime = nNow; @@ -984,27 +986,27 @@ Value listtransactions(const Array& params, bool fHelp) Array ret; CWalletDB walletdb(pwalletMain->strWalletFile); - // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap. + // First: get all CWalletTx and CAccountingEntry into a sorted-by-order multimap. typedef pair TxPair; typedef multimap TxItems; - TxItems txByTime; + TxItems txOrdered; // Note: maintaining indices in the database of (account,time) --> txid and (account, time) --> acentry // would make this much faster for applications that do this a lot. for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { CWalletTx* wtx = &((*it).second); - txByTime.insert(make_pair(wtx->GetTxTime(), TxPair(wtx, (CAccountingEntry*)0))); + txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0))); } list acentries; walletdb.ListAccountCreditDebit(strAccount, acentries); BOOST_FOREACH(CAccountingEntry& entry, acentries) { - txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry))); + txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry))); } // iterate backwards until we have nCount items to return: - for (TxItems::reverse_iterator it = txByTime.rbegin(); it != txByTime.rend(); ++it) + for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { CWalletTx *const pwtx = (*it).second.first; if (pwtx != 0) -- cgit v1.2.3