RPC block_count_type, unchecked, unchecked_clear
This commit is contained in:
parent
b374f45f82
commit
cadc182fbd
2 changed files with 92 additions and 3 deletions
|
@ -25,9 +25,9 @@ chain_request_limit (16384)
|
|||
|
||||
void rai::rpc_config::serialize_json (boost::property_tree::ptree & tree_a) const
|
||||
{
|
||||
tree_a.put ("address", address.to_string ());
|
||||
tree_a.put ("port", std::to_string (port));
|
||||
tree_a.put ("enable_control", enable_control);
|
||||
tree_a.put ("address", address.to_string ());
|
||||
tree_a.put ("port", std::to_string (port));
|
||||
tree_a.put ("enable_control", enable_control);
|
||||
tree_a.put ("frontier_request_limit", frontier_request_limit);
|
||||
tree_a.put ("chain_request_limit", chain_request_limit);
|
||||
}
|
||||
|
@ -733,6 +733,18 @@ void rai::rpc_handler::block_count ()
|
|||
response (response_l);
|
||||
}
|
||||
|
||||
void rai::rpc_handler::block_count_type ()
|
||||
{
|
||||
rai::transaction transaction (node.store.environment, nullptr, false);
|
||||
rai::block_counts count (node.store.block_count (transaction));
|
||||
boost::property_tree::ptree response_l;
|
||||
response_l.put ("send", std::to_string (count.send));
|
||||
response_l.put ("receive", std::to_string (count.receive));
|
||||
response_l.put ("open", std::to_string (count.open));
|
||||
response_l.put ("change", std::to_string (count.change));
|
||||
response (response_l);
|
||||
}
|
||||
|
||||
void rai::rpc_handler::successors ()
|
||||
{
|
||||
std::string block_text (request.get <std::string> ("block"));
|
||||
|
@ -1852,6 +1864,68 @@ void rai::rpc_handler::stop ()
|
|||
}
|
||||
}
|
||||
|
||||
void rai::rpc_handler::unchecked ()
|
||||
{
|
||||
uint64_t count (std::numeric_limits <uint64_t>::max ());
|
||||
try
|
||||
{
|
||||
std::string count_text (request.get <std::string> ("count"));
|
||||
auto error (decode_unsigned (count_text, count));
|
||||
if (error)
|
||||
{
|
||||
error_response (response, "Invalid count");
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &)
|
||||
{
|
||||
// If there is no "count" in request
|
||||
}
|
||||
rai::uint256_union hash (0);
|
||||
try
|
||||
{
|
||||
std::string hash_text (request.get <std::string> ("hash"));
|
||||
auto error_hash (hash.decode_hex (hash_text));
|
||||
if (error_hash)
|
||||
{
|
||||
error_response (response, "Bad hash number");
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &)
|
||||
{
|
||||
// If there is no "hash" in request
|
||||
}
|
||||
boost::property_tree::ptree response_l;
|
||||
boost::property_tree::ptree unchecked;
|
||||
rai::transaction transaction (node.store.environment, nullptr, false);
|
||||
for (auto i (node.store.unchecked_begin (transaction, hash)), n (node.store.unchecked_end ()); i != n && unchecked.size () < count; ++i)
|
||||
{
|
||||
rai::block_hash hash (i->first);
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (i->second.mv_data), i->second.mv_size);
|
||||
auto block (rai::deserialize_block (stream));
|
||||
std::string contents;
|
||||
block->serialize_json (contents);
|
||||
unchecked.put(hash.to_string (), contents);
|
||||
}
|
||||
response_l.add_child ("blocks", unchecked);
|
||||
response (response_l);
|
||||
}
|
||||
|
||||
void rai::rpc_handler::unchecked_clear ()
|
||||
{
|
||||
if (rpc.config.enable_control)
|
||||
{
|
||||
rai::transaction transaction (node.store.environment, nullptr, true);
|
||||
node.store.unchecked_clear (transaction);
|
||||
boost::property_tree::ptree response_l;
|
||||
response_l.put ("success", "");
|
||||
response (response_l);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_response (response, "RPC control is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
void rai::rpc_handler::version ()
|
||||
{
|
||||
boost::property_tree::ptree response_l;
|
||||
|
@ -2542,6 +2616,10 @@ void rai::rpc_handler::process_request ()
|
|||
{
|
||||
block_count ();
|
||||
}
|
||||
else if (action == "block_count_type")
|
||||
{
|
||||
block_count_type ();
|
||||
}
|
||||
else if (action == "successors")
|
||||
{
|
||||
successors ();
|
||||
|
@ -2674,6 +2752,14 @@ void rai::rpc_handler::process_request ()
|
|||
{
|
||||
stop ();
|
||||
}
|
||||
else if (action == "unchecked")
|
||||
{
|
||||
unchecked ();
|
||||
}
|
||||
else if (action == "unchecked_clear")
|
||||
{
|
||||
unchecked_clear ();
|
||||
}
|
||||
else if (action == "validate_account_number")
|
||||
{
|
||||
validate_account_number ();
|
||||
|
|
|
@ -109,6 +109,7 @@ public:
|
|||
void blocks ();
|
||||
void block_account ();
|
||||
void block_count ();
|
||||
void block_count_type ();
|
||||
void bootstrap ();
|
||||
void bootstrap_any ();
|
||||
void chain ();
|
||||
|
@ -142,6 +143,8 @@ public:
|
|||
void send ();
|
||||
void stop ();
|
||||
void successors ();
|
||||
void unchecked ();
|
||||
void unchecked_clear ();
|
||||
void validate_account_number ();
|
||||
void version ();
|
||||
void wallet_add ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue