diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8954aa331e..d2c2066fe6 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3051,6 +3051,22 @@ bool simple_wallet::set_enable_multisig(const std::vector &args/* = return true; } +bool simple_wallet::set_change_output_index(const std::vector &args/* = std::vector()*/) +{ + const auto pwd_container = get_and_verify_password(); + if (pwd_container) + { + uint32_t index; + if (!epee::string_tools::get_xtype_from_string(index, args[1])) + { + fail_msg_writer() << tr("Invalid index"); + return true; + } + m_wallet->set_change_output_address_index(index); + m_wallet->rewrite(m_wallet_file, pwd_container->password()); + } + return true; +} bool simple_wallet::help(const std::vector &args/* = std::vector()*/) { if(args.empty()) @@ -3351,6 +3367,8 @@ simple_wallet::simple_wallet() " Device name for hardware wallet.\n " "export-format <\"binary\"|\"ascii\">\n " " Save all exported files as binary (cannot be copied and pasted) or ascii (can be).\n " + "change-output-index \n " + " the destination address index for generating the change output if needed.\n " "load-deprecated-formats <1|0>\n " " Whether to enable importing data in deprecated formats.\n " "show-wallet-name-when-locked <1|0>\n " @@ -3751,6 +3769,7 @@ bool simple_wallet::set_variable(const std::vector &args) success_msg_writer() << "setup-background-mining = " << setup_background_mining_string; success_msg_writer() << "device-name = " << m_wallet->device_name(); success_msg_writer() << "export-format = " << (m_wallet->export_format() == tools::wallet2::ExportFormat::Ascii ? "ascii" : "binary"); + success_msg_writer() << "change-output-index = " << m_wallet->change_output_address_index(); success_msg_writer() << "show-wallet-name-when-locked = " << m_wallet->show_wallet_name_when_locked(); success_msg_writer() << "inactivity-lock-timeout = " << m_wallet->inactivity_lock_timeout() #ifdef _WIN32 @@ -3824,6 +3843,7 @@ bool simple_wallet::set_variable(const std::vector &args) CHECK_SIMPLE_VARIABLE("export-format", set_export_format, tr("\"binary\" or \"ascii\"")); CHECK_SIMPLE_VARIABLE("load-deprecated-formats", set_load_deprecated_formats, tr("0 or 1")); CHECK_SIMPLE_VARIABLE("enable-multisig-experimental", set_enable_multisig, tr("0 or 1")); + CHECK_SIMPLE_VARIABLE("change-output-index", set_change_output_index, tr("unsigned integer")); } fail_msg_writer() << tr("set: unrecognized argument(s)"); return true; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 76ece1b389..92ec2c338e 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -155,6 +155,7 @@ namespace cryptonote bool set_export_format(const std::vector &args = std::vector()); bool set_load_deprecated_formats(const std::vector &args = std::vector()); bool set_enable_multisig(const std::vector &args = std::vector()); + bool set_change_output_index(const std::vector &args = std::vector()); bool help(const std::vector &args = std::vector()); bool apropos(const std::vector &args); bool scan_tx(const std::vector &args); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e149a910cc..16063f7a1c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1253,6 +1253,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std m_offline(false), m_rpc_version(0), m_export_format(ExportFormat::Binary), + m_change_output_address_index(0), m_enable_multisig(false), m_pool_info_query_time(0), m_has_ever_refreshed_from_node(false), @@ -4761,6 +4762,9 @@ boost::optional wallet2::get_keys_file_data(const crypt value2.SetInt(false); json.AddMember("load_deprecated_formats", value2, json.GetAllocator()); + value2.SetInt(m_change_output_address_index); + json.AddMember("change_output_address_index", value2, json.GetAllocator()); + value2.SetUint(1); json.AddMember("encrypted_secret_keys", value2, json.GetAllocator()); @@ -5024,6 +5028,7 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st m_subaddress_lookahead_minor = SUBADDRESS_LOOKAHEAD_MINOR; m_original_keys_available = false; m_export_format = ExportFormat::Binary; + m_change_output_address_index = 0; m_device_name = ""; m_device_derivation_path = ""; m_key_device_type = hw::device::device_type::SOFTWARE; @@ -5208,6 +5213,9 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, export_format, ExportFormat, Int, false, Binary); m_export_format = field_export_format; + GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, change_output_address_index, uint32_t, Uint, false, 0); + m_change_output_address_index = field_change_output_address_index; + GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, device_name, std::string, String, false, std::string()); if (m_device_name.empty()) { @@ -9759,8 +9767,8 @@ void wallet2::transfer_selected(const std::vector