GET_STAKING_REQUIREMENT

This commit is contained in:
Sean Darcy 2021-11-08 15:42:56 +11:00
parent eedb23c545
commit a16a2d3949
7 changed files with 29 additions and 41 deletions

View file

@ -1868,11 +1868,12 @@ bool rpc_command_executor::print_sn_status(std::vector<std::string> args)
bool rpc_command_executor::print_sr(uint64_t height)
{
GET_STAKING_REQUIREMENT::response res{};
if (!invoke<GET_STAKING_REQUIREMENT>({height}, res, "Failed to retrieve staking requirements"))
auto maybe_staking_requirement = try_running([this, height] { return invoke<GET_STAKING_REQUIREMENT>(json{{"height", height}}); }, "Failed to retrieve staking requirements");
if (!maybe_staking_requirement)
return false;
auto& staking_requirement = *maybe_staking_requirement;
tools::success_msg_writer() << "Staking Requirement: " << cryptonote::print_money(res.staking_requirement);
tools::success_msg_writer() << "Staking Requirement: " << cryptonote::print_money(staking_requirement["staking_requirement"]);
return true;
}
@ -1883,7 +1884,7 @@ bool rpc_command_executor::pop_blocks(uint64_t num_blocks)
return false;
auto& pop_blocks = *maybe_pop_blocks;
tools::success_msg_writer() << "new height: " << pop_blocks["height"].get<std::string_view>();
tools::success_msg_writer() << "new height: " << pop_blocks["height"];
return true;
}

View file

@ -3054,16 +3054,14 @@ namespace cryptonote::rpc {
[this](bool significant) { if (significant) m_core.reset_proof_interval(); });
}
//------------------------------------------------------------------------------------------------------------------------------
GET_STAKING_REQUIREMENT::response core_rpc_server::invoke(GET_STAKING_REQUIREMENT::request&& req, rpc_context context)
void core_rpc_server::invoke(GET_STAKING_REQUIREMENT& get_staking_requirement, rpc_context context)
{
GET_STAKING_REQUIREMENT::response res{};
PERF_TIMER(on_get_staking_requirement);
res.height = req.height > 0 ? req.height : m_core.get_current_blockchain_height();
get_staking_requirement.response["height"] = get_staking_requirement.request.height > 0 ? get_staking_requirement.request.height : m_core.get_current_blockchain_height();
res.staking_requirement = service_nodes::get_staking_requirement(nettype(), res.height);
res.status = STATUS_OK;
return res;
get_staking_requirement.response["staking_requirement"] = service_nodes::get_staking_requirement(nettype(), get_staking_requirement.request.height);
get_staking_requirement.response["status"] = STATUS_OK;
return;
}
//------------------------------------------------------------------------------------------------------------------------------
static void check_quantity_limit(size_t count, size_t max, char const *container_name = nullptr)

View file

@ -249,6 +249,7 @@ namespace cryptonote::rpc {
void invoke(GETBANS& get_bans, rpc_context context);
void invoke(SETBANS& set_bans, rpc_context context);
void invoke(GET_CHECKPOINTS& get_checkpoints, rpc_context context);
void invoke(GET_STAKING_REQUIREMENT& get_staking_requirement, rpc_context context);
// Deprecated Monero NIH binary endpoints:
GET_ALT_BLOCKS_HASHES_BIN::response invoke(GET_ALT_BLOCKS_HASHES_BIN::request&& req, rpc_context context);
@ -276,7 +277,6 @@ namespace cryptonote::rpc {
GET_SERVICE_NODE_BLACKLISTED_KEY_IMAGES::response invoke(GET_SERVICE_NODE_BLACKLISTED_KEY_IMAGES::request&& req, rpc_context context);
GET_SERVICE_KEYS::response invoke(GET_SERVICE_KEYS::request&& req, rpc_context context);
GET_SERVICE_PRIVKEYS::response invoke(GET_SERVICE_PRIVKEYS::request&& req, rpc_context context);
GET_STAKING_REQUIREMENT::response invoke(GET_STAKING_REQUIREMENT::request&& req, rpc_context context);
ONS_NAMES_TO_OWNERS::response invoke(ONS_NAMES_TO_OWNERS::request&& req, rpc_context context);
ONS_OWNERS_TO_NAMES::response invoke(ONS_OWNERS_TO_NAMES::request&& req, rpc_context context);

View file

@ -485,4 +485,8 @@ namespace cryptonote::rpc {
get_values(in, "seconds", set_bans.request.seconds);
get_values(in, "ban", set_bans.request.ban);
}
void parse_request(GET_STAKING_REQUIREMENT& get_staking_requirement, rpc_input in) {
get_values(in, "height", get_staking_requirement.request.height);
}
}

View file

@ -40,4 +40,5 @@ namespace cryptonote::rpc {
void parse_request(GET_LAST_BLOCK_HEADER& get_last_block_header, rpc_input in);
void parse_request(GET_BLOCK_HEADER_BY_HASH& get_block_header_by_hash, rpc_input in);
void parse_request(SETBANS& set_bans, rpc_input in);
void parse_request(GET_STAKING_REQUIREMENT& get_staking_requirement, rpc_input in);
}

View file

@ -347,18 +347,6 @@ KV_SERIALIZE_MAP_CODE_BEGIN(GET_SERVICE_PRIVKEYS::response)
KV_SERIALIZE_MAP_CODE_END()
KV_SERIALIZE_MAP_CODE_BEGIN(GET_STAKING_REQUIREMENT::request)
KV_SERIALIZE(height)
KV_SERIALIZE_MAP_CODE_END()
KV_SERIALIZE_MAP_CODE_BEGIN(GET_STAKING_REQUIREMENT::response)
KV_SERIALIZE(staking_requirement)
KV_SERIALIZE(height)
KV_SERIALIZE(status)
KV_SERIALIZE_MAP_CODE_END()
KV_SERIALIZE_MAP_CODE_BEGIN(GET_SERVICE_NODE_BLACKLISTED_KEY_IMAGES::entry)
KV_SERIALIZE(key_image)
KV_SERIALIZE(unlock_height)

View file

@ -2051,29 +2051,27 @@ namespace cryptonote::rpc {
} request;
};
OXEN_RPC_DOC_INTROSPECT
// Get the required amount of Loki to become a Service Node at the queried height.
// Get the required amount of Oxen to become a Service Node at the queried height.
// For devnet and testnet values, ensure the daemon is started with the
// `--devnet` or `--testnet` flags respectively.
///
/// Inputs:
///
/// - \p height The height to query the staking requirement for. 0 (or omitting) means current height.
///
/// Output values available from a public RPC endpoint:
///
/// - \p status generic RPC error code; "OK" means the request was successful.
/// - \p staking_requirement The staking requirement in Oxen, in atomic units.
/// - \p height The height requested (or current height if 0 was requested)
struct GET_STAKING_REQUIREMENT : PUBLIC
{
static constexpr auto names() { return NAMES("get_staking_requirement"); }
struct request
struct request_parameters
{
uint64_t height; // The height to query the staking requirement for. 0 (or omitting) means current height.
KV_MAP_SERIALIZABLE
};
struct response
{
uint64_t staking_requirement; // The staking requirement in Loki, in atomic units.
uint64_t height; // The height requested (or current height if 0 was requested)
std::string status; // Generic RPC error code. "OK" is the success value.
KV_MAP_SERIALIZABLE
};
} request;
};
OXEN_RPC_DOC_INTROSPECT
@ -2127,8 +2125,6 @@ namespace cryptonote::rpc {
uint64_t end_height; // Optional: Get the first count checkpoints before end height. Specify both start and end to get the checkpoints inbetween.
uint32_t count; // Optional: Number of checkpoints to query.
} request;
};
/// Query hardcoded/service node checkpoints stored for the blockchain. Omit all arguments to