implementation of yield_info function

This commit is contained in:
Some Random Crypto Guy
2024-05-14 14:23:31 +01:00
parent b0ce6d2969
commit ae28c7a900
12 changed files with 179 additions and 25 deletions
+29
View File
@@ -2939,6 +2939,35 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_yield_info(const COMMAND_RPC_GET_YIELD_INFO::request& req, COMMAND_RPC_GET_YIELD_INFO::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx)
{
PERF_TIMER(on_get_yield_info);
uint64_t height = m_core.get_current_blockchain_height();
std::map<uint64_t, yield_block_info> ybi_cache;
if (!m_core.get_blockchain_storage().get_ybi_cache(ybi_cache)) {
res.status = "failed to get YBI data from blockchain";
return true;
}
// Iterate over the cache, supplying the data in a more accessible format
res.yield_data.clear();
for (const auto& entry: ybi_cache) {
// Skip this entry if out-of=range
if (req.from_height > 0 and entry.first < req.from_height) continue;
if (req.to_height > 0 and entry.first > req.to_height) continue;
// Clone the data into the response
COMMAND_RPC_GET_YIELD_INFO::yield_data_t yd;
yd.block_height = entry.second.block_height;
yd.slippage_total_this_block = entry.second.slippage_total_this_block;
yd.locked_coins_this_block = entry.second.locked_coins_this_block;
yd.locked_coins_tally = entry.second.locked_coins_tally;
yd.network_health_percentage = entry.second.network_health_percentage;
res.yield_data.push_back(yd);
}
res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_base_fee_estimate(const COMMAND_RPC_GET_BASE_FEE_ESTIMATE::request& req, COMMAND_RPC_GET_BASE_FEE_ESTIMATE::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx)
{
RPC_TRACKER(get_base_fee_estimate);
+2
View File
@@ -175,6 +175,7 @@ namespace cryptonote
MAP_JON_RPC_WE("get_version", on_get_version, COMMAND_RPC_GET_VERSION)
MAP_JON_RPC_WE_IF("get_coinbase_tx_sum", on_get_coinbase_tx_sum, COMMAND_RPC_GET_COINBASE_TX_SUM, !m_restricted)
MAP_JON_RPC_WE("get_circulating_supply", on_get_circulating_supply, COMMAND_RPC_GET_CIRCULATING_SUPPLY)
MAP_JON_RPC_WE("get_yield_info", on_get_yield_info, COMMAND_RPC_GET_YIELD_INFO)
MAP_JON_RPC_WE("get_fee_estimate", on_get_base_fee_estimate, COMMAND_RPC_GET_BASE_FEE_ESTIMATE)
MAP_JON_RPC_WE_IF("get_alternate_chains",on_get_alternate_chains, COMMAND_RPC_GET_ALTERNATE_CHAINS, !m_restricted)
MAP_JON_RPC_WE_IF("relay_tx", on_relay_tx, COMMAND_RPC_RELAY_TX, !m_restricted)
@@ -253,6 +254,7 @@ namespace cryptonote
bool on_get_version(const COMMAND_RPC_GET_VERSION::request& req, COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_get_coinbase_tx_sum(const COMMAND_RPC_GET_COINBASE_TX_SUM::request& req, COMMAND_RPC_GET_COINBASE_TX_SUM::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_get_circulating_supply(const COMMAND_RPC_GET_CIRCULATING_SUPPLY::request& req, COMMAND_RPC_GET_CIRCULATING_SUPPLY::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_get_yield_info(const COMMAND_RPC_GET_YIELD_INFO::request& req, COMMAND_RPC_GET_YIELD_INFO::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_get_base_fee_estimate(const COMMAND_RPC_GET_BASE_FEE_ESTIMATE::request& req, COMMAND_RPC_GET_BASE_FEE_ESTIMATE::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_get_alternate_chains(const COMMAND_RPC_GET_ALTERNATE_CHAINS::request& req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_relay_tx(const COMMAND_RPC_RELAY_TX::request& req, COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
+26 -3
View File
@@ -1225,9 +1225,31 @@ namespace cryptonote
struct COMMAND_RPC_GET_YIELD_INFO
{
struct yield_data_t
{
uint64_t block_height;
uint64_t slippage_total_this_block;
uint64_t locked_coins_this_block;
uint64_t locked_coins_tally;
uint8_t network_health_percentage;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block_height)
KV_SERIALIZE(slippage_total_this_block)
KV_SERIALIZE(locked_coins_this_block)
KV_SERIALIZE(locked_coins_tally)
KV_SERIALIZE(network_health_percentage)
END_KV_SERIALIZE_MAP()
};
struct request_t
{
uint64_t from_height;
uint64_t to_height;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_OPT(from_height, (uint64_t)0)
KV_SERIALIZE_OPT(to_height, (uint64_t)0)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;
@@ -1235,10 +1257,11 @@ namespace cryptonote
struct response_t
{
cryptonote::yield_block_info& latest_ybi;
std::string status;
std::vector<COMMAND_RPC_GET_YIELD_INFO::yield_data_t> yield_data;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(latest_ybi)
KV_SERIALIZE(status)
KV_SERIALIZE(yield_data)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;