Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service nodes print_sr command for staking requirement #198

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/daemon/command_parser_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ bool t_command_parser_executor::print_sn_key(const std::vector<std::string>& arg
return result;
}

bool t_command_parser_executor::print_sr(const std::vector<std::string>& args)
{
if (args.size() != 1)
{
std::cout << "expected 1 argument, <height>, received: " << args.size() << std::endl;
return false;
}

uint64_t height = 0;
if(!epee::string_tools::get_xtype_from_string(height, args[0]))
{
std::cout << "wrong block height parameter" << std::endl;
return false;
}

bool result = m_executor.print_sr(height);
return result;
}

bool t_command_parser_executor::prepare_registration()
{
bool result = m_executor.prepare_registration();
Expand Down
2 changes: 2 additions & 0 deletions src/daemon/command_parser_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class t_command_parser_executor final

bool print_sn_key(const std::vector<std::string>& args);

bool print_sr(const std::vector<std::string>& args);

bool prepare_registration();

bool print_sn(const std::vector<std::string>& args);
Expand Down
6 changes: 6 additions & 0 deletions src/daemon/command_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ t_command_server::t_command_server(
, "print_sn_key"
, "Print this daemon's service node key, if it is one and launched in service node mode."
);
m_command_lookup.set_handler(
"print_sr"
, std::bind(&t_command_parser_executor::print_sr, &m_parser, p::_1)
, "print_sr <height>"
, "Print the staking requirement for the height."
);
m_command_lookup.set_handler(
"prepare_registration"
, std::bind(&t_command_parser_executor::prepare_registration, &m_parser)
Expand Down
30 changes: 30 additions & 0 deletions src/daemon/rpc_command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,36 @@ bool t_rpc_command_executor::print_sn_status()
return result;
}

bool t_rpc_command_executor::print_sr(uint64_t height)
{
cryptonote::COMMAND_RPC_GET_STAKING_REQUIREMENT::request req = {};
cryptonote::COMMAND_RPC_GET_STAKING_REQUIREMENT::response res = {};
std::string fail_message = "Unsuccessful";
epee::json_rpc::error error_resp;
req.height = height;

if (m_is_rpc)
{
if (!m_rpc_client->json_rpc_request(req, res, "get_staking_requirement", fail_message.c_str()))
{
tools::fail_msg_writer() << make_error(fail_message, res.status);
return true;
}
}
else
{
epee::json_rpc::error error_resp;
if (!m_rpc_server->on_get_staking_requirement(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
{
tools::fail_msg_writer() << make_error(fail_message, error_resp.message);
return true;
}
}

tools::success_msg_writer() << "Staking Requirement: " << cryptonote::print_money(res.staking_requirement);
return true;
}

bool t_rpc_command_executor::print_sn_key()
{
cryptonote::COMMAND_RPC_GET_SERVICE_NODE_KEY::request req = {};
Expand Down
2 changes: 2 additions & 0 deletions src/daemon/rpc_command_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class t_rpc_command_executor final {

bool print_sn_status();

bool print_sr(uint64_t height);

bool prepare_registration();

bool print_sn(const std::vector<std::string> &args);
Expand Down
8 changes: 7 additions & 1 deletion src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,13 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------

bool core_rpc_server::on_get_staking_requirement(const COMMAND_RPC_GET_STAKING_REQUIREMENT::request& req, COMMAND_RPC_GET_STAKING_REQUIREMENT::response& res, epee::json_rpc::error& error_resp)
{
PERF_TIMER(on_get_staking_requirement);
res.staking_requirement = service_nodes::get_staking_requirement(nettype(), req.height);
res.status = CORE_RPC_STATUS_OK;
return true;
}

const command_line::arg_descriptor<std::string, false, true, 2> core_rpc_server::arg_rpc_bind_port = {
"rpc-bind-port"
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/core_rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ namespace cryptonote
MAP_JON_RPC_WE("get_service_node_registration_cmd", on_get_service_node_registration_cmd, COMMAND_RPC_GET_SERVICE_NODE_REGISTRATION_CMD)
MAP_JON_RPC_WE("get_service_node_key", on_get_service_node_key, COMMAND_RPC_GET_SERVICE_NODE_KEY)
MAP_JON_RPC_WE("get_service_nodes", on_get_service_nodes, COMMAND_RPC_GET_SERVICE_NODES)
MAP_JON_RPC_WE("get_staking_requirement", on_get_staking_requirement, COMMAND_RPC_GET_STAKING_REQUIREMENT)
END_JSON_RPC_MAP()
END_URI_MAP2()

Expand Down Expand Up @@ -226,6 +227,7 @@ namespace cryptonote
bool on_get_service_node_registration_cmd(const COMMAND_RPC_GET_SERVICE_NODE_REGISTRATION_CMD::request& req, COMMAND_RPC_GET_SERVICE_NODE_REGISTRATION_CMD::response& res, epee::json_rpc::error& error_resp);
bool on_get_service_node_key(const COMMAND_RPC_GET_SERVICE_NODE_KEY::request& req, COMMAND_RPC_GET_SERVICE_NODE_KEY::response& res, epee::json_rpc::error &error_resp);
bool on_get_service_nodes(const COMMAND_RPC_GET_SERVICE_NODES::request& req, COMMAND_RPC_GET_SERVICE_NODES::response& res, epee::json_rpc::error& error_resp);
bool on_get_staking_requirement(const COMMAND_RPC_GET_STAKING_REQUIREMENT::request& req, COMMAND_RPC_GET_STAKING_REQUIREMENT::response& res, epee::json_rpc::error& error_resp);
//-----------------------

private:
Expand Down
22 changes: 22 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "cryptonote_basic/verification_context.h"
#include "cryptonote_basic/difficulty.h"
#include "crypto/hash.h"
#include "cryptonote_config.h"
#include "cryptonote_core/service_node_deregister.h"

namespace cryptonote
Expand Down Expand Up @@ -2411,4 +2412,25 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
};

struct COMMAND_RPC_GET_STAKING_REQUIREMENT
{
struct request
{
uint64_t height;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(height)
END_KV_SERIALIZE_MAP()
};

struct response
{
uint64_t staking_requirement;
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(staking_requirement)
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
};
}