From 9c098ae1fbd07b35ef519464ea8018356ebd0c3a Mon Sep 17 00:00:00 2001 From: Neil Coggins Date: Thu, 6 Jun 2024 14:13:14 +0100 Subject: [PATCH] added support for auto-frozen incoming payments --- src/simplewallet/simplewallet.cpp | 25 ++++++++++++++++++++++++- src/simplewallet/simplewallet.h | 1 + src/wallet/wallet2.cpp | 9 ++++++++- src/wallet/wallet2.h | 3 +++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 291fbb86b..a8e278800 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3178,6 +3178,25 @@ bool simple_wallet::set_enable_multisig(const std::vector &args/* = return true; } +bool simple_wallet::set_freeze_incoming_payments(const std::vector &args/* = std::vector()*/) +{ + if (args.size() < 2) + { + fail_msg_writer() << tr("Value not specified"); + return true; + } + + const auto pwd_container = get_and_verify_password(); + if (pwd_container) + { + parse_bool_and_use(args[1], [&](bool r) { + m_wallet->freeze_incoming_payments(r); + m_wallet->rewrite(m_wallet_file, pwd_container->password()); + }); + } + return true; +} + bool simple_wallet::help(const std::vector &args/* = std::vector()*/) { if(args.empty()) @@ -3533,7 +3552,9 @@ simple_wallet::simple_wallet() "enable-multisig-experimental <1|0>\n " " Set this to allow multisig commands. Multisig may currently be exploitable if parties do not trust each other.\n " "inactivity-lock-timeout \n " - " How many seconds to wait before locking the wallet (0 to disable).")); + " How many seconds to wait before locking the wallet (0 to disable).\n" + "freeze-incoming-payments <1|0>\n " + " Whether to have incoming payments automatically frozen, so they cannot be spent erroneously.")); m_cmd_binder.set_handler("encrypted_seed", boost::bind(&simple_wallet::on_command, this, &simple_wallet::encrypted_seed, _1), tr("Display the encrypted Electrum-style mnemonic seed.")); @@ -3948,6 +3969,7 @@ bool simple_wallet::set_variable(const std::vector &args) success_msg_writer() << "credits-target = " << m_wallet->credits_target(); success_msg_writer() << "load-deprecated-formats = " << m_wallet->load_deprecated_formats(); success_msg_writer() << "enable-multisig-experimental = " << m_wallet->is_multisig_enabled(); + success_msg_writer() << "freeze-incoming-payments = " << m_wallet->is_freeze_incoming_payments_enabled(); return true; } else @@ -4015,6 +4037,7 @@ bool simple_wallet::set_variable(const std::vector &args) CHECK_SIMPLE_VARIABLE("auto-mine-for-rpc-payment-threshold", set_auto_mine_for_rpc_payment_threshold, tr("floating point >= 0")); CHECK_SIMPLE_VARIABLE("credits-target", set_credits_target, tr("unsigned integer")); CHECK_SIMPLE_VARIABLE("enable-multisig-experimental", set_enable_multisig, tr("0 or 1")); + CHECK_SIMPLE_VARIABLE("freeze-incoming-payments", set_freeze_incoming_payments, tr("0 or 1")); } fail_msg_writer() << tr("set: unrecognized argument(s)"); return true; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 51e07dbf6..b67329f6e 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -154,6 +154,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_freeze_incoming_payments(const std::vector &args = std::vector()); bool set_persistent_rpc_client_id(const std::vector &args = std::vector()); bool set_auto_mine_for_rpc_payment_threshold(const std::vector &args = std::vector()); bool set_credits_target(const std::vector &args = std::vector()); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7506ea5cb..a5d50700c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1240,6 +1240,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std m_load_deprecated_formats(false), m_credits_target(0), m_enable_multisig(false), + m_freeze_incoming_payments(false), m_pool_info_query_time(0), m_has_ever_refreshed_from_node(false), m_allow_mismatched_daemon_version(false) @@ -2642,7 +2643,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote td.m_mask = rct::identity(); td.m_rct = false; } - td.m_frozen = false; + td.m_frozen = m_freeze_incoming_payments; set_unspent(m_transfers.size()-1); if (td.m_key_image_known) m_key_images[td.m_key_image] = m_transfers.size()-1; @@ -4856,6 +4857,9 @@ boost::optional wallet2::get_keys_file_data(const epee: value2.SetInt(m_enable_multisig ? 1 : 0); json.AddMember("enable_multisig", value2, json.GetAllocator()); + value2.SetInt(m_freeze_incoming_payments ? 1 : 0); + json.AddMember("freeze_incoming_payments", value2, json.GetAllocator()); + // Serialize the JSON object rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); @@ -5002,6 +5006,7 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st m_auto_mine_for_rpc_payment_threshold = -1.0f; m_credits_target = 0; m_enable_multisig = false; + m_freeze_incoming_payments = false; m_allow_mismatched_daemon_version = false; } else if(json.IsObject()) @@ -5239,6 +5244,8 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st m_credits_target = field_credits_target; GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, enable_multisig, int, Int, false, false); m_enable_multisig = field_enable_multisig; + GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, freeze_incoming_payments, int, Int, false, false); + m_freeze_incoming_payments = field_freeze_incoming_payments; } else { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 3a0593ecd..c071fb439 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1450,6 +1450,8 @@ private: void credits_target(uint64_t threshold) { m_credits_target = threshold; } bool is_multisig_enabled() const { return m_enable_multisig; } void enable_multisig(bool enable) { m_enable_multisig = enable; } + bool is_freeze_incoming_payments_enabled() const { return m_freeze_incoming_payments; } + void freeze_incoming_payments(bool enable) { m_freeze_incoming_payments = enable; } bool is_mismatched_daemon_version_allowed() const { return m_allow_mismatched_daemon_version; } void allow_mismatched_daemon_version(bool allow_mismatch) { m_allow_mismatched_daemon_version = allow_mismatch; } @@ -1991,6 +1993,7 @@ private: rpc_payment_state_t m_rpc_payment_state; uint64_t m_credits_target; bool m_enable_multisig; + bool m_freeze_incoming_payments; bool m_allow_mismatched_daemon_version; // Aux transaction data from device