forked from lthn/blockchain
simplewallet: --pos-mining-reward-address command-line option implemented
This commit is contained in:
parent
98c782565f
commit
3ccbaca823
5 changed files with 25 additions and 6 deletions
|
|
@ -49,6 +49,7 @@ namespace
|
|||
const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", "Use daemon instance at port <arg> instead of default", 0};
|
||||
const command_line::arg_descriptor<uint32_t> arg_log_level = {"set-log", "", 0, true};
|
||||
const command_line::arg_descriptor<bool> arg_do_pos_mining = { "do-pos-mining", "Do PoS mining", false, false };
|
||||
const command_line::arg_descriptor<std::string> 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<std::string> arg_restore_wallet = { "restore-wallet", "Restore wallet from the seed phrase and save it to <arg>", "" };
|
||||
const command_line::arg_descriptor<bool> 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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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&)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue