From 8724f7e90bfb5cd9ac8c9992eaa8410b981fd22a Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 9 Jul 2019 16:16:53 -0400 Subject: [PATCH] sort txs by block height unless overriden by requesting tx ids --- src/wallet/MoneroWallet.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index e3f7bed..b0f30b0 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -382,6 +382,16 @@ namespace monero { } } + /** + * Returns true iff tx1's height is known to be less than tx2's height for sorting. + */ + bool txHeightLessThan(const shared_ptr& tx1, const shared_ptr& tx2) { + if (tx1->block != boost::none && tx2->block != boost::none) return tx1->getHeight() < tx2->getHeight(); + else if (tx1->block == boost::none) return false; + else return true; + } + + /** * ---------------- DUPLICATED WALLET RPC TRANSFER CODE --------------------- * @@ -1367,10 +1377,16 @@ namespace monero { //cout << "8" << endl; + // sort txs by block height + vector> txs ; + for (map>::const_iterator txIter = txMap.begin(); txIter != txMap.end(); txIter++) { + txs.push_back(txIter->second); + } + sort(txs.begin(), txs.end(), txHeightLessThan); + // filter and return transfers vector> transfers; - for (map>::const_iterator txIter = txMap.begin(); txIter != txMap.end(); txIter++) { - shared_ptr tx = txIter->second; + for (const shared_ptr& tx : txs) { // collect outgoing transfer, erase if filtered TODO: java/js do not erase filtered transfers if (tx->outgoingTransfer != boost::none && request.meetsCriteria(tx->outgoingTransfer.get().get())) transfers.push_back(tx->outgoingTransfer.get()); @@ -1394,6 +1410,7 @@ namespace monero { } //cout << "9" << endl; cout << "MoneroWallet.cpp getTransfers() returning " << transfers.size() << " transfers" << endl; + return transfers; }