diff --git a/src/rpc/index_util.cpp b/src/rpc/index_util.cpp index d5ba2b1669..4e362af88c 100644 --- a/src/rpc/index_util.cpp +++ b/src/rpc/index_util.cpp @@ -25,7 +25,7 @@ bool GetAddressIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, co } bool GetAddressUnspentIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, const AddressType type, - std::vector& unspentOutputs) + std::vector& unspentOutputs, const bool height_sort) { AssertLockHeld(::cs_main); @@ -35,12 +35,20 @@ bool GetAddressUnspentIndex(CBlockTreeDB& block_tree_db, const uint160& addressH if (!block_tree_db.ReadAddressUnspentIndex(addressHash, type, unspentOutputs)) return error("Unable to get txids for address"); + if (height_sort) { + std::sort(unspentOutputs.begin(), unspentOutputs.end(), + [](const CAddressUnspentIndexEntry &a, const CAddressUnspentIndexEntry &b) { + return a.second.m_block_height < b.second.m_block_height; + }); + } + return true; } bool GetMempoolAddressDeltaIndex(const CTxMemPool& mempool, const std::vector& addressDeltaIndex, - std::vector& addressDeltaEntries) + std::vector& addressDeltaEntries, + const bool timestamp_sort) { if (!fAddressIndex) return error("Address index not enabled"); @@ -48,6 +56,13 @@ bool GetMempoolAddressDeltaIndex(const CTxMemPool& mempool, if (!mempool.getAddressIndex(addressDeltaIndex, addressDeltaEntries)) return error("Unable to get address delta information"); + if (timestamp_sort) { + std::sort(addressDeltaEntries.begin(), addressDeltaEntries.end(), + [](const CMempoolAddressDeltaEntry &a, const CMempoolAddressDeltaEntry &b) { + return a.second.m_time < b.second.m_time; + }); + } + return true; } diff --git a/src/rpc/index_util.h b/src/rpc/index_util.h index d296721be9..3155bf2263 100644 --- a/src/rpc/index_util.h +++ b/src/rpc/index_util.h @@ -29,11 +29,12 @@ bool GetAddressIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, co const int32_t start = 0, const int32_t end = 0) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); bool GetAddressUnspentIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, const AddressType type, - std::vector& unspentOutputs) + std::vector& unspentOutputs, const bool height_sort = false) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); bool GetMempoolAddressDeltaIndex(const CTxMemPool& mempool, const std::vector& addressDeltaIndex, - std::vector& addressDeltaEntries); + std::vector& addressDeltaEntries, + const bool timestamp_sort = false); bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const CSpentIndexKey& key, CSpentIndexValue& value) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index eec4baec66..377acc2679 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -701,14 +701,6 @@ static bool getAddressesFromParams(const UniValue& params, std::vector