aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-12-17 11:25:15 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-12-17 11:28:49 +0000
commit55fa0479a0db599d81500e57e355124f1fb9c05e (patch)
treed394bf9b6ad9f8d8320cc3a34e860c7af5bc671c /src/daemon
parentMerge pull request #1459 (diff)
downloadmonero-55fa0479a0db599d81500e57e355124f1fb9c05e.tar.xz
rpc: new function and RPC to get alternative chain info
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/command_parser_executor.cpp11
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp5
-rw-r--r--src/daemon/rpc_command_executor.cpp33
-rw-r--r--src/daemon/rpc_command_executor.h2
5 files changed, 53 insertions, 0 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 88b77f76d..f07ef1616 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -482,4 +482,15 @@ bool t_command_parser_executor::print_coinbase_tx_sum(const std::vector<std::str
return m_executor.print_coinbase_tx_sum(height, count);
}
+bool t_command_parser_executor::alt_chain_info(const std::vector<std::string>& args)
+{
+ if(args.size())
+ {
+ std::cout << "No parameters allowed" << std::endl;
+ return false;
+ }
+
+ return m_executor.alt_chain_info();
+}
+
} // namespace daemonize
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index 93b1fab56..cc929db00 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -119,6 +119,8 @@ public:
bool output_histogram(const std::vector<std::string>& args);
bool print_coinbase_tx_sum(const std::vector<std::string>& args);
+
+ bool alt_chain_info(const std::vector<std::string>& args);
};
} // namespace daemonize
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 729b19cbf..88c49d111 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -225,6 +225,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::print_coinbase_tx_sum, &m_parser, p::_1)
, "Print sum of coinbase transactions (start height, block count)"
);
+ m_command_lookup.set_handler(
+ "alt_chain_info"
+ , std::bind(&t_command_parser_executor::alt_chain_info, &m_parser, p::_1)
+ , "Print information about alternative chains"
+ );
}
bool t_command_server::process_command_str(const std::string& cmd)
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 65b42cc47..41b1fad24 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1367,5 +1367,38 @@ bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t height, uint64_t cou
return true;
}
+bool t_rpc_command_executor::alt_chain_info()
+{
+ cryptonote::COMMAND_RPC_GET_ALTERNATE_CHAINS::request req;
+ cryptonote::COMMAND_RPC_GET_ALTERNATE_CHAINS::response res;
+ epee::json_rpc::error error_resp;
+
+ std::string fail_message = "Unsuccessful";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "get_alternate_chains", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_alternate_chains(req, res, error_resp))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ tools::msg_writer() << boost::lexical_cast<std::string>(res.chains.size()) << " alternate chains found:";
+ for (const auto chain: res.chains)
+ {
+ tools::msg_writer() << chain.length << " blocks long, branching at height " << (chain.height - chain.length + 1)
+ << ", difficulty " << chain.difficulty << ": " << chain.block_hash;
+ }
+ return true;
+}
+
}// namespace daemonize
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index c1c99155b..a6c712c04 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -137,6 +137,8 @@ public:
bool output_histogram(uint64_t min_count, uint64_t max_count);
bool print_coinbase_tx_sum(uint64_t height, uint64_t count);
+
+ bool alt_chain_info();
};
} // namespace daemonize