diff options
author | Gregory Maxwell <greg@xiph.org> | 2012-08-23 12:38:50 -0700 |
---|---|---|
committer | Gregory Maxwell <greg@xiph.org> | 2012-08-23 12:38:50 -0700 |
commit | 47753fa369f15274718779ffea1e2f151aa8307d (patch) | |
tree | 0caa89a1b21692c7e9a1dc03404280455186773f /src/rpcwallet.cpp | |
parent | cf78183fadac6e9fccb51c7355cfa34641fc06d5 (diff) | |
parent | c3f95ef13f48d21db53992984976eac93e7a08fc (diff) |
Merge pull request #1393 from luke-jr/refactor_times
Refactor transaction/accounting time
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r-- | src/rpcwallet.cpp | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 3b68105dd7..eacb5b3b1a 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -38,9 +38,11 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); entry.push_back(Pair("blockindex", wtx.nIndex)); + entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); + entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) entry.push_back(Pair(item.first, item.second)); } @@ -542,6 +544,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 +554,7 @@ Value movecmd(const Array& params, bool fHelp) // Credit CAccountingEntry credit; + credit.nOrderPos = pwalletMain->nOrderPosNext++; credit.strAccount = strTo; credit.nCreditDebit = nAmount; credit.nTime = nNow; @@ -982,29 +986,11 @@ Value listtransactions(const Array& params, bool fHelp) throw JSONRPCError(-8, "Negative from"); Array ret; - CWalletDB walletdb(pwalletMain->strWalletFile); - - // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap. - typedef pair<CWalletTx*, CAccountingEntry*> TxPair; - typedef multimap<int64, TxPair > TxItems; - TxItems txByTime; - // 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))); - } - list<CAccountingEntry> acentries; - walletdb.ListAccountCreditDebit(strAccount, acentries); - BOOST_FOREACH(CAccountingEntry& entry, acentries) - { - txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry))); - } + CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(strAccount); // iterate backwards until we have nCount items to return: - for (TxItems::reverse_iterator it = txByTime.rbegin(); it != txByTime.rend(); ++it) + for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { CWalletTx *const pwtx = (*it).second.first; if (pwtx != 0) |