diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index 18035453..98a4e672 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -89,12 +89,13 @@ namespace cryptonote { const command_line::arg_descriptor arg_extra_messages = {"extra-messages-file", "Specify file for extra messages to include into coinbase transactions", "", true}; const command_line::arg_descriptor arg_start_mining = {"start-mining", "Specify wallet address to mining for", "", true}; - const command_line::arg_descriptor arg_mining_threads = {"mining-threads", "Specify mining threads count", 0, true}; + const command_line::arg_descriptor arg_donate_mining = {"donate-level", "Specify a percentage of blocks to mine to the development wallet", miner::MINING_DEFAULT_DONATION_LEVEL, true}; + const command_line::arg_descriptor arg_mining_threads = {"mining-threads", "Specify mining threads count", 0, true}; const command_line::arg_descriptor arg_bg_mining_enable = {"bg-mining-enable", "enable/disable background mining", true, true}; const command_line::arg_descriptor arg_bg_mining_ignore_battery = {"bg-mining-ignore-battery", "if true, assumes plugged in when unable to query system power status", false, true}; const command_line::arg_descriptor arg_bg_mining_min_idle_interval_seconds = {"bg-mining-min-idle-interval", "Specify min lookback interval in seconds for determining idle state", miner::BACKGROUND_MINING_DEFAULT_MIN_IDLE_INTERVAL_IN_SECONDS, true}; - const command_line::arg_descriptor arg_bg_mining_idle_threshold_percentage = {"bg-mining-idle-threshold", "Specify minimum avg idle percentage over lookback interval", miner::BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE, true}; - const command_line::arg_descriptor arg_bg_mining_miner_target_percentage = {"bg-mining-miner-target", "Specify maximum percentage cpu use by miner(s)", miner::BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE, true}; + const command_line::arg_descriptor arg_bg_mining_idle_threshold_percentage = {"bg-mining-idle-threshold", "Specify minimum avg idle percentage over lookback interval", miner::BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE, true}; + const command_line::arg_descriptor arg_bg_mining_miner_target_percentage = {"bg-mining-miner-target", "Specify maximum percentage cpu use by miner(s)", miner::BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE, true}; } @@ -108,6 +109,9 @@ namespace cryptonote m_height(0), m_pausers_count(0), m_threads_total(0), + m_donate_blocks(MINING_DEFAULT_DONATION_LEVEL), + m_block_counter(0), + m_dev_mine_time(false), m_starter_nonce(0), m_last_hr_merge_time(0), m_hashes(0), @@ -131,6 +135,8 @@ namespace cryptonote catch (...) { /* ignore */ } } //----------------------------------------------------------------------------------------------------- + bool m_last_dev_mine_time = false; + uint64_t last_height = 0; bool miner::set_block_template(const block& bl, const difficulty_type& di, uint64_t height, uint64_t block_reward) { CRITICAL_REGION_LOCAL(m_template_lock); @@ -140,6 +146,38 @@ namespace cryptonote m_block_reward = block_reward; ++m_template_no; m_starter_nonce = crypto::rand(); + + if (height != last_height) + { + m_block_counter++; + + //reset counter + if (m_block_counter > 100) + m_block_counter = 0; + + //if counter is within dev mining window + m_dev_mine_time = (m_block_counter >= (100 - m_donate_blocks)); + +#if defined(ONE_TIME_NOTIFY) + if (m_dev_mine_time != m_last_dev_mine_time) + { + uint32_t remaining = 100 - m_block_counter; + if (m_dev_mine_time) + MGUSER_YELLOW("Mining to the dev fund for the next " << remaining << " blocks"); + else + MGUSER_YELLOW("Resumed mining to your regular mining address"); + + m_last_dev_mine_time = m_dev_mine_time; + } +#else + uint32_t remaining = 100 - m_block_counter; + if (m_dev_mine_time) + MGUSER_YELLOW("Mining to the dev fund for the next " << remaining << " blocks"); +#endif + + last_height = height; + } + return true; } //----------------------------------------------------------------------------------------------------- @@ -164,7 +202,9 @@ namespace cryptonote extra_nonce = m_extra_messages[m_config.current_extra_message_index]; } - if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce)) + account_public_address adr = m_dev_mine_time ? m_donate_mine_address : m_mine_address; + + if(!m_phandler->get_block_template(bl, adr, di, height, expected_reward, extra_nonce)) { LOG_ERROR("Failed to get_block_template(), stopping mining"); return false; @@ -278,6 +318,7 @@ namespace cryptonote { command_line::add_arg(desc, arg_extra_messages); command_line::add_arg(desc, arg_start_mining); + command_line::add_arg(desc, arg_donate_mining); command_line::add_arg(desc, arg_mining_threads); command_line::add_arg(desc, arg_bg_mining_enable); command_line::add_arg(desc, arg_bg_mining_ignore_battery); @@ -321,6 +362,12 @@ namespace cryptonote return false; } m_mine_address = info.address; + + if(!cryptonote::get_account_address_from_str(info, nettype, DONATION_ADDR)) + { + return false; + } + m_donate_mine_address = info.address; m_threads_total = 0; m_do_mining = true; if(command_line::has_arg(vm, arg_mining_threads)) @@ -329,6 +376,11 @@ namespace cryptonote } } + if(command_line::has_arg(vm, arg_donate_mining)) + { + m_donate_blocks = command_line::get_arg(vm, arg_donate_mining); + } + // Background mining parameters // Let init set all parameters even if background mining is not enabled, they can start later with params set if(command_line::has_arg(vm, arg_bg_mining_enable)) @@ -413,6 +465,8 @@ namespace cryptonote MINFO("Ignoring battery"); } + set_donate_blocks(m_donate_blocks); + return true; } //----------------------------------------------------------------------------------------------------- @@ -431,6 +485,20 @@ namespace cryptonote boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1); } //----------------------------------------------------------------------------------------------------- + void miner::set_donate_blocks(uint32_t b) + { + if (b > 100) + b = 100; + + m_donate_blocks = b; + + MGUSER_YELLOW("Mining set to donate " << m_donate_blocks << "% to the dev fund"); + if (m_donate_blocks > 0) + MGUSER_YELLOW("Thankyou for your support."); + + m_block_counter = 0; + } + //----------------------------------------------------------------------------------------------------- bool miner::stop() { MTRACE("Miner has received stop signal"); diff --git a/src/cryptonote_basic/miner.h b/src/cryptonote_basic/miner.h index d85c26ce..c76d700d 100644 --- a/src/cryptonote_basic/miner.h +++ b/src/cryptonote_basic/miner.h @@ -87,6 +87,8 @@ namespace cryptonote uint8_t get_mining_target() const; bool set_mining_target(uint8_t mining_target); uint64_t get_block_reward() const { return m_block_reward; } + void set_donate_blocks(uint32_t b); + uint32_t get_donate_blocks() const { return m_donate_blocks; } static constexpr uint8_t BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE = 90; static constexpr uint8_t BACKGROUND_MINING_MIN_IDLE_THRESHOLD_PERCENTAGE = 50; @@ -101,6 +103,8 @@ namespace cryptonote static constexpr uint64_t BACKGROUND_MINING_DEFAULT_MINER_EXTRA_SLEEP_MILLIS = 400; // ramp up static constexpr uint64_t BACKGROUND_MINING_MIN_MINER_EXTRA_SLEEP_MILLIS = 5; + static constexpr uint32_t MINING_DEFAULT_DONATION_LEVEL = 0; + private: bool worker_thread(); bool request_block_template(); @@ -126,6 +130,9 @@ namespace cryptonote uint64_t m_height; volatile uint32_t m_thread_index; volatile uint32_t m_threads_total; + uint32_t m_donate_blocks; + uint32_t m_block_counter; + bool m_dev_mine_time; std::atomic m_pausers_count; epee::critical_section m_miners_count_lock; @@ -133,6 +140,7 @@ namespace cryptonote epee::critical_section m_threads_lock; i_miner_handler* m_phandler; account_public_address m_mine_address; + account_public_address m_donate_mine_address; epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval; epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; epee::math_helper::once_a_time_seconds<1> m_autodetect_interval; diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index bcd25591..0f29141b 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -126,6 +126,8 @@ #define HASH_OF_HASHES_STEP 256 #define DEFAULT_TXPOOL_MAX_SIZE 648000000ull // 3 days at 300000, in bytes +#define DONATION_ADDR "amitGvbEpdH6vcmWR3qXd9XXyud78DQfM84D2P9NMpJEV9iZFTTrmP5f6kUwWVmfNBXyMs4AufNUoUrGsqwfUn1L695cS6EkwC" + struct hard_fork { uint8_t version; diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 1cd6bb4f..81bf7a58 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -403,6 +403,24 @@ bool t_command_parser_executor::start_mining(const std::vector& arg return true; } +bool t_command_parser_executor::donate_mining(const std::vector& args) +{ + if (args.empty()) + { + std::cout << "expected: donate_level " << std::endl; + return true; + } + + uint32_t blocks_count = 0; + bool ok = epee::string_tools::get_xtype_from_string(blocks_count, args[0]); + blocks_count = ok ? blocks_count : 0; + + if (blocks_count > 100) + blocks_count = 100; + + return m_executor.donate_mining(blocks_count); +} + bool t_command_parser_executor::stop_mining(const std::vector& args) { if (!args.empty()) return false; diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index bc089c99..8415a6bc 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -87,6 +87,8 @@ class t_command_parser_executor final bool start_mining(const std::vector& args); + bool donate_mining(const std::vector& args); + bool stop_mining(const std::vector& args); bool mining_status(const std::vector& args); diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index 8e65124c..201848ce 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -112,6 +112,12 @@ t_command_server::t_command_server( , "start_mining [|auto] [do_background_mining] [ignore_battery]" , "Start mining for specified address. Defaults to 1 thread and no background mining. Use \"auto\" to autodetect optimal number of threads." ); + m_command_lookup.set_handler( + "donate_level" + , std::bind(&t_command_parser_executor::donate_mining, &m_parser, p::_1) + , "donate_level " + , "Amount of time to spend mining to the donation fund." + ); m_command_lookup.set_handler( "stop_mining" , std::bind(&t_command_parser_executor::stop_mining, &m_parser, p::_1) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index dd4baeb8..7c723a1f 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -1205,6 +1205,33 @@ bool t_rpc_command_executor::start_mining(cryptonote::account_public_address add return true; } +bool t_rpc_command_executor::donate_mining(uint32_t blocks_count) +{ + cryptonote::COMMAND_RPC_DONATE_MINING::request req; + cryptonote::COMMAND_RPC_DONATE_MINING::response res; + req.blocks = blocks_count; + + std::string fail_message = "Donation level unchanged"; + + if (m_is_rpc) + { + if (m_rpc_client->rpc_request(req, res, "/set_donate_level", fail_message.c_str())) + { + tools::success_msg_writer() << "Mining started"; + } + } + else + { + if (!m_rpc_server->on_set_donation_level(req, res) || res.status != CORE_RPC_STATUS_OK) + { + tools::fail_msg_writer() << make_error(fail_message, res.status); + return true; + } + } + + return true; +} + bool t_rpc_command_executor::stop_mining() { cryptonote::COMMAND_RPC_STOP_MINING::request req; cryptonote::COMMAND_RPC_STOP_MINING::response res; @@ -2032,7 +2059,7 @@ bool t_rpc_command_executor::update() return true; } - tools::msg_writer() << "Update available: v" << res.version << ENDL << res.uri << ENDL << "SHA256: " << res.hash; + tools::msg_writer() << "Update available- v" << res.version << ":" << res.codename << ENDL << res.uri << ENDL << "Release note: " << res.release_note; return true; } diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index cb9d8779..7b74acfe 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -108,6 +108,8 @@ class t_rpc_command_executor final { bool start_mining(cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining = false, bool ignore_battery = false); + bool donate_mining(uint32_t blocks_count); + bool stop_mining(); bool mining_status(); diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c62cbe99..d63ea7ad 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1076,6 +1076,15 @@ namespace cryptonote return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_set_donation_level(const COMMAND_RPC_DONATE_MINING::request& req, COMMAND_RPC_DONATE_MINING::response& res, const connection_context *ctx) + { + PERF_TIMER(on_set_donation_level); + cryptonote::miner &miner= m_core.get_miner(); + miner.set_donate_blocks(req.blocks); + res.status = CORE_RPC_STATUS_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res, const connection_context *ctx) { PERF_TIMER(on_stop_mining); diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index f745da3d..bb66f6be 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -104,6 +104,7 @@ namespace cryptonote MAP_URI_AUTO_JON2("/send_raw_transaction", on_send_raw_tx, COMMAND_RPC_SEND_RAW_TX) MAP_URI_AUTO_JON2("/sendrawtransaction", on_send_raw_tx, COMMAND_RPC_SEND_RAW_TX) MAP_URI_AUTO_JON2_IF("/start_mining", on_start_mining, COMMAND_RPC_START_MINING, !m_restricted) + MAP_URI_AUTO_JON2_IF("/set_donate_level", on_set_donation_level, COMMAND_RPC_DONATE_MINING, !m_restricted) MAP_URI_AUTO_JON2_IF("/stop_mining", on_stop_mining, COMMAND_RPC_STOP_MINING, !m_restricted) MAP_URI_AUTO_JON2_IF("/mining_status", on_mining_status, COMMAND_RPC_MINING_STATUS, !m_restricted) MAP_URI_AUTO_JON2_IF("/save_bc", on_save_bc, COMMAND_RPC_SAVE_BC, !m_restricted) @@ -181,6 +182,7 @@ namespace cryptonote bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request& req, COMMAND_RPC_SEND_RAW_TX::response& res, const connection_context *ctx = NULL); bool on_start_mining(const COMMAND_RPC_START_MINING::request& req, COMMAND_RPC_START_MINING::response& res, const connection_context *ctx = NULL); bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res, const connection_context *ctx = NULL); + bool on_set_donation_level(const COMMAND_RPC_DONATE_MINING::request& req, COMMAND_RPC_DONATE_MINING::response& res, const connection_context *ctx = NULL); bool on_mining_status(const COMMAND_RPC_MINING_STATUS::request& req, COMMAND_RPC_MINING_STATUS::response& res, const connection_context *ctx = NULL); bool on_get_outs_bin(const COMMAND_RPC_GET_OUTPUTS_BIN::request& req, COMMAND_RPC_GET_OUTPUTS_BIN::response& res, const connection_context *ctx = NULL); bool on_get_outs(const COMMAND_RPC_GET_OUTPUTS::request& req, COMMAND_RPC_GET_OUTPUTS::response& res, const connection_context *ctx = NULL); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 794bc0f7..50053571 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -679,6 +679,29 @@ namespace cryptonote typedef epee::misc_utils::struct_init response; }; //----------------------------------------------- + struct COMMAND_RPC_DONATE_MINING + { + struct request_t + { + uint32_t blocks; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(blocks) + END_KV_SERIALIZE_MAP() + }; + typedef epee::misc_utils::struct_init request; + + struct response_t + { + std::string status; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(status) + END_KV_SERIALIZE_MAP() + }; + typedef epee::misc_utils::struct_init response; + }; + //----------------------------------------------- struct COMMAND_RPC_GET_INFO { struct request_t @@ -2030,16 +2053,16 @@ namespace cryptonote bool update; std::string version; std::string codename; - std::string release_note; std::string uri; - std::string hash; + std::string release_note; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(status) KV_SERIALIZE(update) KV_SERIALIZE(version) + KV_SERIALIZE(codename) KV_SERIALIZE(uri) - KV_SERIALIZE(hash) + KV_SERIALIZE(release_note) END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init response; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 5624ab2d..c329e6a6 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -67,6 +67,7 @@ #include "version.h" #include #include "wallet/message_store.h" +#include "cryptonote_config.h" #ifdef WIN32 #include @@ -136,6 +137,7 @@ namespace const command_line::arg_descriptor< std::vector > arg_command = {"command", ""}; const char* USAGE_START_MINING("start_mining [] [bg_mining] [ignore_battery]"); + const char* USAGE_SET_DONATE_LEVEL("donate_level []"); const char* USAGE_SET_DAEMON("set_daemon [:] [trusted|untrusted]"); const char* USAGE_SHOW_BALANCE("balance [detail]"); const char* USAGE_INCOMING_TRANSFERS("incoming_transfers [available|unavailable] [verbose] [uses] [index=[,[,...]]]"); @@ -2588,6 +2590,10 @@ simple_wallet::simple_wallet() boost::bind(&simple_wallet::start_mining, this, _1), tr(USAGE_START_MINING), tr("Start mining in the daemon (bg_mining and ignore_battery are optional booleans).")); + m_cmd_binder.set_handler("donate_level", + boost::bind(&simple_wallet::set_donate_level, this, _1), + tr(USAGE_SET_DONATE_LEVEL), + tr("Set the amount of time to mine to the dev wallet.")); m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), tr("Stop mining in the daemon.")); @@ -4559,6 +4565,51 @@ bool simple_wallet::start_mining(const std::vector& args) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::set_donate_level(const std::vector& args) +{ + if (!m_wallet->is_trusted_daemon()) + { + fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon"); + return true; + } + + if (!try_connect_to_daemon()) + return true; + + if (!m_wallet) + { + fail_msg_writer() << tr("wallet is null"); + return true; + } + + if (args.size() != 1) + { + fail_msg_writer() << tr("expected only one argument"); + return true; + } + + COMMAND_RPC_DONATE_MINING::request req = AUTO_VAL_INIT(req); + + uint32_t num = 0; + bool ok = string_tools::get_xtype_from_string(num, args[0]); + req.blocks = num; + + if (!ok) + { + PRINT_USAGE(USAGE_SET_DONATE_LEVEL); + return true; + } + + COMMAND_RPC_DONATE_MINING::response res; + bool r = m_wallet->invoke_http_json("/set_donate_level", req, res); + std::string err = interpret_rpc_response(r, res.status); + if (err.empty()) + success_msg_writer() << tr("Donation level set"); + else + fail_msg_writer() << tr("Donation level not set: ") << err; + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::stop_mining(const std::vector& args) { if (!try_connect_to_daemon()) @@ -6335,23 +6386,23 @@ bool simple_wallet::donate(const std::vector &args_) { // if not mainnet, convert donation address string to the relevant network type address_parse_info info; - if (!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, XNV_DONATION_ADDR)) + if (!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, DONATION_ADDR)) { - fail_msg_writer() << tr("Failed to parse donation address: ") << XNV_DONATION_ADDR; + fail_msg_writer() << tr("Failed to parse donation address: ") << DONATION_ADDR; return true; } address_str = cryptonote::get_account_address_as_str(m_wallet->nettype(), info.is_subaddress, info.address); } else { - address_str = XNV_DONATION_ADDR; + address_str = DONATION_ADDR; } local_args.push_back(address_str); local_args.push_back(amount_str); if (!payment_id_str.empty()) local_args.push_back(payment_id_str); if (m_wallet->nettype() == cryptonote::MAINNET) - message_writer() << (boost::format(tr("Donating %s %s to The Amity Project (getamitycoin.org or %s).")) % amount_str % cryptonote::get_unit(cryptonote::get_default_decimal_point()) % XNV_DONATION_ADDR).str(); + message_writer() << (boost::format(tr("Donating %s %s to The Amity Project (getamitycoin.org or %s).")) % amount_str % cryptonote::get_unit(cryptonote::get_default_decimal_point()) % DONATION_ADDR).str(); else message_writer() << (boost::format(tr("Donating %s %s to %s.")) % amount_str % cryptonote::get_unit(cryptonote::get_default_decimal_point()) % address_str).str(); transfer(local_args); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 7eb8bc14..27912d65 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -53,8 +53,6 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "wallet.simplewallet" -constexpr const char XNV_DONATION_ADDR[] = "NV1r8P6THPASAQX77re6hXTMJ1ykXXvtYXFXgMv4vFAQNYo3YatUvZ8LFNRu4dPQBjTwqJbMvqoeiipywmREPHpD2AgWnmG7Q"; - /*! * \namespace cryptonote * \brief Holds cryptonote related classes and helpers. @@ -144,6 +142,7 @@ namespace cryptonote bool set_device_name(const std::vector &args = std::vector()); bool help(const std::vector &args = std::vector()); bool start_mining(const std::vector &args); + bool set_donate_level(const std::vector &args); bool stop_mining(const std::vector &args); bool set_daemon(const std::vector &args); bool save_bc(const std::vector &args); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 96a15d11..1303b0d6 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -2881,6 +2881,30 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_set_donate_level(const wallet_rpc::COMMAND_RPC_DONATE_MINING::request& req, wallet_rpc::COMMAND_RPC_DONATE_MINING::response& res, epee::json_rpc::error& er, const connection_context *ctx) + { + if (!m_wallet) return not_open(er); + if (!m_wallet->is_trusted_daemon()) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "This command requires a trusted daemon."; + return false; + } + + cryptonote::COMMAND_RPC_DONATE_MINING::request daemon_req = AUTO_VAL_INIT(daemon_req); + daemon_req.blocks = req.blocks; + + cryptonote::COMMAND_RPC_DONATE_MINING::response daemon_res; + bool r = m_wallet->invoke_http_json("/set_donate_level", daemon_req, daemon_res); + if (!r || daemon_res.status != CORE_RPC_STATUS_OK) + { + er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; + er.message = "Couldn't set donation level due to unknown error."; + return false; + } + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_stop_mining(const wallet_rpc::COMMAND_RPC_STOP_MINING::request& req, wallet_rpc::COMMAND_RPC_STOP_MINING::response& res, epee::json_rpc::error& er, const connection_context *ctx) { if (!m_wallet) return not_open(er); diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 63795be9..5f0fd582 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -133,6 +133,7 @@ namespace tools MAP_JON_RPC_WE("auto_refresh", on_auto_refresh, wallet_rpc::COMMAND_RPC_AUTO_REFRESH) MAP_JON_RPC_WE("rescan_spent", on_rescan_spent, wallet_rpc::COMMAND_RPC_RESCAN_SPENT) MAP_JON_RPC_WE("start_mining", on_start_mining, wallet_rpc::COMMAND_RPC_START_MINING) + MAP_JON_RPC_WE("set_donate_level", on_set_donate_level, wallet_rpc::COMMAND_RPC_DONATE_MINING) MAP_JON_RPC_WE("stop_mining", on_stop_mining, wallet_rpc::COMMAND_RPC_STOP_MINING) MAP_JON_RPC_WE("get_languages", on_get_languages, wallet_rpc::COMMAND_RPC_GET_LANGUAGES) MAP_JON_RPC_WE("create_wallet", on_create_wallet, wallet_rpc::COMMAND_RPC_CREATE_WALLET) @@ -219,6 +220,7 @@ namespace tools bool on_auto_refresh(const wallet_rpc::COMMAND_RPC_AUTO_REFRESH::request& req, wallet_rpc::COMMAND_RPC_AUTO_REFRESH::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); bool on_rescan_spent(const wallet_rpc::COMMAND_RPC_RESCAN_SPENT::request& req, wallet_rpc::COMMAND_RPC_RESCAN_SPENT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); bool on_start_mining(const wallet_rpc::COMMAND_RPC_START_MINING::request& req, wallet_rpc::COMMAND_RPC_START_MINING::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); + bool on_set_donate_level(const wallet_rpc::COMMAND_RPC_DONATE_MINING::request& req, wallet_rpc::COMMAND_RPC_DONATE_MINING::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); bool on_stop_mining(const wallet_rpc::COMMAND_RPC_STOP_MINING::request& req, wallet_rpc::COMMAND_RPC_STOP_MINING::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); bool on_get_languages(const wallet_rpc::COMMAND_RPC_GET_LANGUAGES::request& req, wallet_rpc::COMMAND_RPC_GET_LANGUAGES::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); bool on_create_wallet(const wallet_rpc::COMMAND_RPC_CREATE_WALLET::request& req, wallet_rpc::COMMAND_RPC_CREATE_WALLET::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index 97ba764c..d0dfab36 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -1979,6 +1979,26 @@ namespace wallet_rpc typedef epee::misc_utils::struct_init response; }; + struct COMMAND_RPC_DONATE_MINING + { + struct request_t + { + uint32_t blocks; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(blocks) + END_KV_SERIALIZE_MAP() + }; + typedef epee::misc_utils::struct_init request; + + struct response_t + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + typedef epee::misc_utils::struct_init response; + }; + struct COMMAND_RPC_STOP_MINING { struct request_t