mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
Transaction pool RPC
This commit is contained in:
parent
2556949293
commit
2c28871075
@ -502,6 +502,11 @@ namespace cryptonote
|
|||||||
return m_mempool.print_pool(short_format);
|
return m_mempool.print_pool(short_format);
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
|
void core::each_transaction(std::function<void (tx_memory_pool::tx_details &)> callback)
|
||||||
|
{
|
||||||
|
m_mempool.each_transaction(callback);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------
|
||||||
bool core::update_miner_block_template()
|
bool core::update_miner_block_template()
|
||||||
{
|
{
|
||||||
m_miner.on_block_chain_update();
|
m_miner.on_block_chain_update();
|
||||||
|
@ -88,6 +88,8 @@ namespace cryptonote
|
|||||||
void print_blockchain(uint64_t start_index, uint64_t end_index);
|
void print_blockchain(uint64_t start_index, uint64_t end_index);
|
||||||
void print_blockchain_index();
|
void print_blockchain_index();
|
||||||
std::string print_pool(bool short_format);
|
std::string print_pool(bool short_format);
|
||||||
|
void each_transaction(std::function<void (tx_memory_pool::tx_details &)> callback);
|
||||||
|
|
||||||
void print_blockchain_outs(const std::string& file);
|
void print_blockchain_outs(const std::string& file);
|
||||||
void on_synchronized();
|
void on_synchronized();
|
||||||
|
|
||||||
|
@ -374,6 +374,16 @@ namespace cryptonote
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
void tx_memory_pool::each_transaction(std::function<void (tx_details &)> callback)
|
||||||
|
{
|
||||||
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
|
BOOST_FOREACH(transactions_container::value_type& txe, m_transactions)
|
||||||
|
{
|
||||||
|
tx_details& details = txe.second;
|
||||||
|
callback(details);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
// Warning: This function takes already_generated_
|
// Warning: This function takes already_generated_
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <functional>
|
||||||
#include <boost/serialization/version.hpp>
|
#include <boost/serialization/version.hpp>
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
|
||||||
@ -30,6 +31,21 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
tx_memory_pool(blockchain_storage& bchs);
|
tx_memory_pool(blockchain_storage& bchs);
|
||||||
|
|
||||||
|
struct tx_details
|
||||||
|
{
|
||||||
|
transaction tx;
|
||||||
|
size_t blob_size;
|
||||||
|
uint64_t fee;
|
||||||
|
crypto::hash max_used_block_id;
|
||||||
|
uint64_t max_used_block_height;
|
||||||
|
bool kept_by_block;
|
||||||
|
//
|
||||||
|
uint64_t last_failed_height;
|
||||||
|
crypto::hash last_failed_id;
|
||||||
|
time_t receive_time;
|
||||||
|
};
|
||||||
|
|
||||||
bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block);
|
bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block);
|
||||||
bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block);
|
bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block);
|
||||||
//gets tx and remove it from pool
|
//gets tx and remove it from pool
|
||||||
@ -57,6 +73,7 @@ namespace cryptonote
|
|||||||
bool have_key_images(const std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
bool have_key_images(const std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
||||||
bool append_key_images(std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
bool append_key_images(std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
||||||
std::string print_pool(bool short_format);
|
std::string print_pool(bool short_format);
|
||||||
|
void each_transaction(std::function<void (tx_details &)> callback);
|
||||||
|
|
||||||
/*bool flush_pool(const std::strig& folder);
|
/*bool flush_pool(const std::strig& folder);
|
||||||
bool inflate_pool(const std::strig& folder);*/
|
bool inflate_pool(const std::strig& folder);*/
|
||||||
@ -73,20 +90,6 @@ namespace cryptonote
|
|||||||
a & m_spent_key_images;
|
a & m_spent_key_images;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tx_details
|
|
||||||
{
|
|
||||||
transaction tx;
|
|
||||||
size_t blob_size;
|
|
||||||
uint64_t fee;
|
|
||||||
crypto::hash max_used_block_id;
|
|
||||||
uint64_t max_used_block_height;
|
|
||||||
bool kept_by_block;
|
|
||||||
//
|
|
||||||
uint64_t last_failed_height;
|
|
||||||
crypto::hash last_failed_id;
|
|
||||||
time_t receive_time;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool remove_stuck_transactions();
|
bool remove_stuck_transactions();
|
||||||
bool is_transaction_ready_to_go(tx_details& txd);
|
bool is_transaction_ready_to_go(tx_details& txd);
|
||||||
|
@ -346,6 +346,7 @@ namespace cryptonote
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, connection_context& cntx)
|
bool core_rpc_server::on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, connection_context& cntx)
|
||||||
{
|
{
|
||||||
if (req.level < LOG_LEVEL_MIN || req.level > LOG_LEVEL_MAX)
|
if (req.level < LOG_LEVEL_MIN || req.level > LOG_LEVEL_MAX)
|
||||||
@ -360,6 +361,25 @@ 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](tx_memory_pool::tx_details & details) {
|
||||||
|
res.transactions.emplace_back(
|
||||||
|
obj_to_json_str(details.tx)
|
||||||
|
, details.blob_size
|
||||||
|
, details.fee
|
||||||
|
, details.max_used_block_id
|
||||||
|
, details.max_used_block_height
|
||||||
|
, details.kept_by_block
|
||||||
|
, details.last_failed_height
|
||||||
|
, details.last_failed_id
|
||||||
|
, details.receive_time
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
|
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
|
||||||
{
|
{
|
||||||
CHECK_CORE_BUSY();
|
CHECK_CORE_BUSY();
|
||||||
|
@ -49,6 +49,7 @@ namespace cryptonote
|
|||||||
MAP_URI_AUTO_JON2("/get_peer_list", on_get_peer_list, COMMAND_RPC_GET_PEER_LIST)
|
MAP_URI_AUTO_JON2("/get_peer_list", on_get_peer_list, COMMAND_RPC_GET_PEER_LIST)
|
||||||
MAP_URI_AUTO_JON2("/set_log_hash_rate", on_set_log_hash_rate, COMMAND_RPC_SET_LOG_HASH_RATE)
|
MAP_URI_AUTO_JON2("/set_log_hash_rate", on_set_log_hash_rate, COMMAND_RPC_SET_LOG_HASH_RATE)
|
||||||
MAP_URI_AUTO_JON2("/set_log_level", on_set_log_level, COMMAND_RPC_SET_LOG_LEVEL)
|
MAP_URI_AUTO_JON2("/set_log_level", on_set_log_level, COMMAND_RPC_SET_LOG_LEVEL)
|
||||||
|
MAP_URI_AUTO_JON2("/get_transaction_pool", on_get_transaction_pool, COMMAND_RPC_GET_TRANSACTION_POOL)
|
||||||
BEGIN_JSON_RPC_MAP("/json_rpc")
|
BEGIN_JSON_RPC_MAP("/json_rpc")
|
||||||
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
|
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
|
||||||
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
|
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
|
||||||
@ -74,6 +75,7 @@ namespace cryptonote
|
|||||||
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res, connection_context& cntx);
|
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res, connection_context& cntx);
|
||||||
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request& req, COMMAND_RPC_SET_LOG_HASH_RATE::response& res, connection_context& cntx);
|
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request& req, COMMAND_RPC_SET_LOG_HASH_RATE::response& res, connection_context& cntx);
|
||||||
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, connection_context& cntx);
|
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, connection_context& cntx);
|
||||||
|
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res, connection_context& cntx);
|
||||||
|
|
||||||
//json_rpc
|
//json_rpc
|
||||||
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
|
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
|
||||||
|
@ -559,5 +559,66 @@ namespace cryptonote
|
|||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct tx_info
|
||||||
|
{
|
||||||
|
std::string tx_json;
|
||||||
|
size_t blob_size;
|
||||||
|
uint64_t fee;
|
||||||
|
crypto::hash max_used_block_id;
|
||||||
|
uint64_t max_used_block_height;
|
||||||
|
bool kept_by_block;
|
||||||
|
uint64_t last_failed_height;
|
||||||
|
crypto::hash last_failed_id;
|
||||||
|
time_t receive_time;
|
||||||
|
|
||||||
|
tx_info() = default;
|
||||||
|
|
||||||
|
tx_info(std::string tx_json, size_t blob_size, uint64_t fee
|
||||||
|
, crypto::hash max_used_block_id, uint64_t max_used_block_height
|
||||||
|
, bool kept_by_block, uint64_t last_failed_height
|
||||||
|
, crypto::hash last_failed_id, time_t receive_time
|
||||||
|
)
|
||||||
|
: tx_json(std::move(tx_json))
|
||||||
|
, blob_size(blob_size)
|
||||||
|
, fee(fee)
|
||||||
|
, max_used_block_id(std::move(max_used_block_id))
|
||||||
|
, kept_by_block(kept_by_block)
|
||||||
|
, last_failed_height(last_failed_height)
|
||||||
|
, last_failed_id(std::move(last_failed_id))
|
||||||
|
, receive_time(receive_time)
|
||||||
|
{}
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(tx_json)
|
||||||
|
KV_SERIALIZE(blob_size)
|
||||||
|
KV_SERIALIZE(fee)
|
||||||
|
KV_SERIALIZE_VAL_POD_AS_BLOB(max_used_block_id)
|
||||||
|
KV_SERIALIZE(max_used_block_height)
|
||||||
|
KV_SERIALIZE(kept_by_block)
|
||||||
|
KV_SERIALIZE(last_failed_height)
|
||||||
|
KV_SERIALIZE_VAL_POD_AS_BLOB(last_failed_id)
|
||||||
|
KV_SERIALIZE(receive_time)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct COMMAND_RPC_GET_TRANSACTION_POOL
|
||||||
|
{
|
||||||
|
struct request
|
||||||
|
{
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct response
|
||||||
|
{
|
||||||
|
std::string status;
|
||||||
|
std::vector<tx_info> transactions;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(transactions)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user