aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonero-project <sempre.amaro@gmail.com>2014-05-15 18:47:12 -0400
committermonero-project <sempre.amaro@gmail.com>2014-05-15 18:47:12 -0400
commitdda8b3432bc853463fcdd80c36f436be1a9f5d4f (patch)
treeddf6c47c1ef7c647fe68789c79fa4b773bfd1c38
parentMerge pull request #10 from NoodleDoodleNoodleDoodleNoodleDoodleNoo/patch-8 (diff)
parentAdded 'save_bc' command in daemon for saving blockchain remotely (diff)
downloadmonero-dda8b3432bc853463fcdd80c36f436be1a9f5d4f.tar.xz
Merge pull request #11 from Neozaru/master
'save_bc' command for requesting blockchain saving remotely
-rw-r--r--src/rpc/core_rpc_server.cpp12
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h20
-rw-r--r--src/simplewallet/simplewallet.cpp17
-rw-r--r--src/simplewallet/simplewallet.h1
5 files changed, 52 insertions, 0 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 631fb5cf8..2c4e82085 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -275,6 +275,18 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, connection_context& cntx)
+ {
+ CHECK_CORE_READY();
+ if( !m_core.get_blockchain_storage().store_blockchain() )
+ {
+ res.status = "Error while storing blockhain";
+ return true;
+ }
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 7b14e741a..ad0016c94 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -40,6 +40,7 @@ namespace cryptonote
MAP_URI_AUTO_JON2("/sendrawtransaction", on_send_raw_tx, COMMAND_RPC_SEND_RAW_TX)
MAP_URI_AUTO_JON2("/start_mining", on_start_mining, COMMAND_RPC_START_MINING)
MAP_URI_AUTO_JON2("/stop_mining", on_stop_mining, COMMAND_RPC_STOP_MINING)
+ MAP_URI_AUTO_JON2("/save_bc", on_save_bc, COMMAND_RPC_SAVE_BC)
MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO)
BEGIN_JSON_RPC_MAP("/json_rpc")
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
@@ -61,6 +62,7 @@ namespace cryptonote
bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res, connection_context& cntx);
bool on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res, connection_context& cntx);
bool on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, connection_context& cntx);
+ bool on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, connection_context& cntx);
//json_rpc
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index d67ebfdd7..1e8ebe8ff 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -260,7 +260,27 @@ namespace cryptonote
};
};
+ //-----------------------------------------------
+ struct COMMAND_RPC_SAVE_BC
+ {
+ struct request
+ {
+
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string status;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
//
struct COMMAND_RPC_GETBLOCKCOUNT
{
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 919782ab6..0f84b81de 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -181,6 +181,7 @@ simple_wallet::simple_wallet()
{
m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining [<number_of_threads>] - Start mining in daemon");
m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), "Stop mining in daemon");
+ m_cmd_binder.set_handler("save_bc", boost::bind(&simple_wallet::save_bc, this, _1), "Save current blockchain data");
m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, _1), "Resynchronize transactions and balance");
m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance");
m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, _1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability");
@@ -491,6 +492,22 @@ bool simple_wallet::stop_mining(const std::vector<std::string>& args)
return true;
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::save_bc(const std::vector<std::string>& args)
+{
+ if (!try_connect_to_daemon())
+ return true;
+
+ COMMAND_RPC_SAVE_BC::request req;
+ COMMAND_RPC_SAVE_BC::response res;
+ bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/save_bc", req, res, m_http_client);
+ std::string err = interpret_rpc_response(r, res.status);
+ if (err.empty())
+ success_msg_writer() << "Blockchain saved";
+ else
+ fail_msg_writer() << "Blockchain can't be saved: " << err;
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
void simple_wallet::on_new_block(uint64_t height, const cryptonote::block& block)
{
m_refresh_progress_reporter.update(height, false);
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index a6c771804..3aa0789ae 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -46,6 +46,7 @@ namespace cryptonote
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool start_mining(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
+ bool save_bc(const std::vector<std::string>& args);
bool refresh(const std::vector<std::string> &args);
bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
bool show_incoming_transfers(const std::vector<std::string> &args);