diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 44a41e24d..cff13485b 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -502,9 +502,9 @@ namespace cryptonote return m_mempool.print_pool(short_format); } //----------------------------------------------------------------------------------------------- - void core::each_transaction(std::function callback) + std::vector core::transaction_pool_info() { - m_mempool.each_transaction(callback); + return m_mempool.pool_info(); } //----------------------------------------------------------------------------------------------- bool core::update_miner_block_template() diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 5c45aa717..d8edbf3e5 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -17,6 +17,7 @@ #include "cryptonote_core/cryptonote_stat_info.h" #include "warnings.h" #include "crypto/hash.h" +#include "rpc/tx_info.h" PUSH_WARNINGS DISABLE_VS_WARNINGS(4355) @@ -88,7 +89,7 @@ namespace cryptonote void print_blockchain(uint64_t start_index, uint64_t end_index); void print_blockchain_index(); std::string print_pool(bool short_format); - void each_transaction(std::function callback); + std::vector transaction_pool_info(); void print_blockchain_outs(const std::string& file); void on_synchronized(); diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 31bd02aa8..f11e26ac5 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -17,6 +17,7 @@ #include "misc_language.h" #include "warnings.h" #include "crypto/hash.h" +#include "string_tools.h" DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated @@ -374,15 +375,29 @@ namespace cryptonote return ss.str(); } //--------------------------------------------------------------------------------- - void tx_memory_pool::each_transaction(std::function callback) + std::vector tx_memory_pool::pool_info() { CRITICAL_REGION_LOCAL(m_transactions_lock); + + std::vector result; BOOST_FOREACH(transactions_container::value_type& txe, m_transactions) { auto & id = txe.first; auto & details = txe.second; - callback(id, details); + result.emplace_back( + epee::string_tools::pod_to_hex(id) + , obj_to_json_str(details.tx) + , details.blob_size + , details.fee + , epee::string_tools::pod_to_hex(details.max_used_block_id) + , details.max_used_block_height + , details.kept_by_block + , details.last_failed_height + , epee::string_tools::pod_to_hex(details.last_failed_id) + , details.receive_time + ); } + return result; } //--------------------------------------------------------------------------------- bool tx_memory_pool::fill_block_template(block &bl, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee) diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index 2c7c56ffa..c048376b8 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -18,6 +18,7 @@ #include "cryptonote_basic_impl.h" #include "verification_context.h" #include "crypto/hash.h" +#include "rpc/tx_info.h" namespace cryptonote @@ -73,7 +74,7 @@ namespace cryptonote bool have_key_images(const std::unordered_set& kic, const transaction& tx); bool append_key_images(std::unordered_set& kic, const transaction& tx); std::string print_pool(bool short_format); - void each_transaction(std::function callback); + std::vector pool_info(); /*bool flush_pool(const std::strig& folder); bool inflate_pool(const std::strig& folder);*/ diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 6ea14638d..3f1498ad0 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -365,20 +365,7 @@ namespace cryptonote bool core_rpc_server::on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res, connection_context& cntx) { CHECK_CORE_BUSY(); - m_core.each_transaction([&res](crypto::hash const & id, tx_memory_pool::tx_details const & details) { - res.transactions.emplace_back( - string_tools::pod_to_hex(id) - , obj_to_json_str(const_cast(details.tx)) // The serialization macros do not handle const correctness - , details.blob_size - , details.fee - , string_tools::pod_to_hex(details.max_used_block_id) - , details.max_used_block_height - , details.kept_by_block - , details.last_failed_height - , string_tools::pod_to_hex(details.last_failed_id) - , details.receive_time - ); - }); + res.transactions = m_core.transaction_pool_info(); res.status = CORE_RPC_STATUS_OK; return true; }