aboutsummaryrefslogtreecommitdiff
path: root/src/rpcwallet.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2012-05-27 23:06:09 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2012-08-23 18:18:20 +0000
commit9c7722b7c5ce49130bd978b932f73b629ce5cebe (patch)
treed1020863fbc36871042171d73433f0f055f27f3f /src/rpcwallet.cpp
parentcf78183fadac6e9fccb51c7355cfa34641fc06d5 (diff)
downloadbitcoin-9c7722b7c5ce49130bd978b932f73b629ce5cebe.tar.xz
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.
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r--src/rpcwallet.cpp12
1 files changed, 7 insertions, 5 deletions
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<CWalletTx*, CAccountingEntry*> TxPair;
typedef multimap<int64, TxPair > 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<uint256, CWalletTx>::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<CAccountingEntry> 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)