diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index b760545..4d936c6 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -408,6 +408,20 @@ namespace monero { else return false; } + /** + * Returns true iff wallet vout1 is ordered before vout2 by ascending account and subaddress indices then index. + */ + bool voutBefore(const shared_ptr& o1, const shared_ptr& o2) { + shared_ptr ow1 = static_pointer_cast(o1); + shared_ptr ow2 = static_pointer_cast(o2); + if (ow1->accountIndex.get() < ow2->accountIndex.get()) return true; + else if (ow1->accountIndex.get() == ow2->accountIndex.get()) { + if (ow1->subaddressIndex.get() < ow2->subaddressIndex.get()) return true; + if (ow1->subaddressIndex.get() == ow2->subaddressIndex.get() && ow1->index.get() < ow2->index.get()) return true; + } + return false; + } + /** * ---------------- DUPLICATED WALLET RPC TRANSFER CODE --------------------- * @@ -1556,6 +1570,11 @@ namespace monero { vector> vouts; for (map>::const_iterator txIter = txMap.begin(); txIter != txMap.end(); txIter++) { shared_ptr tx = txIter->second; + + // sort outputs + sort(tx->vouts.begin(), tx->vouts.end(), voutBefore); + + // collect requested outputs, remove unrequested outputs vector>::iterator voutIter = tx->vouts.begin(); while (voutIter != tx->vouts.end()) { shared_ptr voutWallet = static_pointer_cast(*voutIter);