From 3ccbaca8239c292d50715e700efa8c5be84f33c8 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 Dec 2019 00:50:30 +0300 Subject: [PATCH] simplewallet: --pos-mining-reward-address command-line option implemented --- src/simplewallet/simplewallet.cpp | 15 ++++++++++++++- src/wallet/wallet2.cpp | 7 ++++++- src/wallet/wallet2.h | 1 + src/wallet/wallet_rpc_server.cpp | 6 +++--- src/wallet/wallet_rpc_server.h | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 1cc11544..ce224660 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -49,6 +49,7 @@ namespace const command_line::arg_descriptor arg_daemon_port = {"daemon-port", "Use daemon instance at port instead of default", 0}; const command_line::arg_descriptor arg_log_level = {"set-log", "", 0, true}; const command_line::arg_descriptor arg_do_pos_mining = { "do-pos-mining", "Do PoS mining", false, false }; + const command_line::arg_descriptor arg_pos_mining_reward_address = { "pos-mining-reward-address", "Block reward will be sent to the giving address if specified", "" }; const command_line::arg_descriptor arg_restore_wallet = { "restore-wallet", "Restore wallet from the seed phrase and save it to ", "" }; const command_line::arg_descriptor arg_offline_mode = { "offline-mode", "Don't connect to daemon, work offline (for cold-signing process)", false, true }; @@ -1578,6 +1579,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_dont_set_date); command_line::add_arg(desc_params, arg_print_brain_wallet); command_line::add_arg(desc_params, arg_do_pos_mining); + command_line::add_arg(desc_params, arg_pos_mining_reward_address); command_line::add_arg(desc_params, arg_restore_wallet); command_line::add_arg(desc_params, arg_offline_mode); command_line::add_arg(desc_params, command_line::arg_log_file); @@ -1728,6 +1730,17 @@ int main(int argc, char* argv[]) break; } + currency::account_public_address miner_address = wal.get_account().get_public_address(); + if (command_line::has_arg(vm, arg_pos_mining_reward_address)) + { + std::string arg_pos_mining_reward_address_str = command_line::get_arg(vm, arg_pos_mining_reward_address); + if (!arg_pos_mining_reward_address_str.empty()) + { + r = get_account_address_from_str(miner_address, arg_pos_mining_reward_address_str); + CHECK_AND_ASSERT_MES(r, EXIT_FAILURE, "Failed to parse miner address from string: " << arg_pos_mining_reward_address_str); + LOG_PRINT_YELLOW("PoS reward will be sent to another address: " << arg_pos_mining_reward_address_str, LOG_LEVEL_0); + } + } tools::wallet_rpc_server wrpc(wal); bool r = wrpc.init(vm); @@ -1737,7 +1750,7 @@ int main(int argc, char* argv[]) wrpc.send_stop_signal(); }); LOG_PRINT_L0("Starting wallet rpc server"); - wrpc.run(command_line::get_arg(vm, arg_do_pos_mining), offline_mode); + wrpc.run(command_line::get_arg(vm, arg_do_pos_mining), offline_mode, miner_address); LOG_PRINT_L0("Stopped wallet rpc server"); try { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 68779858..2f54565b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2750,6 +2750,11 @@ bool wallet2::fill_mining_context(mining_context& ctx) } //------------------------------------------------------------------ bool wallet2::try_mint_pos() +{ + return try_mint_pos(m_account.get_public_address()); +} +//------------------------------------------------------------------ +bool wallet2::try_mint_pos(const currency::account_public_address& miner_address) { mining_context ctx = AUTO_VAL_INIT(ctx); WLT_LOG_L1("Starting PoS mining iteration"); @@ -2778,7 +2783,7 @@ bool wallet2::try_mint_pos() if (ctx.rsp.status == CORE_RPC_STATUS_OK) { - build_minted_block(ctx.sp, ctx.rsp); + build_minted_block(ctx.sp, ctx.rsp, miner_address); } WLT_LOG_L0("PoS mining iteration finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index e214f5a7..2bff7279 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -681,6 +681,7 @@ namespace tools //PoS //synchronous version of function bool try_mint_pos(); + bool try_mint_pos(const currency::account_public_address& miner_address); // block reward will be sent to miner_address, stake will be returned back to the wallet //for unit tests friend class ::test_generator; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 508ff005..1d3f58ef 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -51,7 +51,7 @@ namespace tools wallet_rpc_server::wallet_rpc_server(wallet2& w):m_wallet(w), m_do_mint(false), m_deaf(false) {} //------------------------------------------------------------------------------------------------------------------------------ - bool wallet_rpc_server::run(bool do_mint, bool offline_mode) + bool wallet_rpc_server::run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address) { static const uint64_t wallet_rpt_idle_work_period_ms = 2000; @@ -59,7 +59,7 @@ namespace tools if (!offline_mode) { - m_net_server.add_idle_handler([this]() -> bool + m_net_server.add_idle_handler([this, &miner_address]() -> bool { try { @@ -80,7 +80,7 @@ namespace tools LOG_PRINT_L2("wallet RPC idle: scanning tx pool..."); m_wallet.scan_tx_pool(has_related_alias_in_unconfirmed); LOG_PRINT_L2("wallet RPC idle: trying to do PoS iteration..."); - m_wallet.try_mint_pos(); + m_wallet.try_mint_pos(miner_address); } } catch (error::no_connection_to_daemon&) diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 065efb85..dca8bd53 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -32,7 +32,7 @@ namespace tools static void init_options(boost::program_options::options_description& desc); bool init(const boost::program_options::variables_map& vm); - bool run(bool do_mint, bool offline_mode); + bool run(bool do_mint, bool offline_mode, const currency::account_public_address& miner_address); bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context);