mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user