From 31871d6253ea2b515e4d0300c556cbbab0288840 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 6 Apr 2020 23:17:11 +0300 Subject: [PATCH] simplewallet: transfer command changed to accept only hex-encoded payment id --- src/simplewallet/simplewallet.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a0025fb6..36d23a7f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -198,7 +198,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("payments", boost::bind(&simple_wallet::show_payments, this, _1), "payments [ ... ] - Show payments , ... "); m_cmd_binder.set_handler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this, _1), "Show blockchain height"); m_cmd_binder.set_handler("wallet_bc_height", boost::bind(&simple_wallet::show_wallet_bcheight, this, _1), "Show blockchain height"); - m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this, _1), "transfer [ ... ] [payment_id] - Transfer ,... to ,... , respectively. is the number of transactions yours is indistinguishable from (from 0 to maximum available)"); + m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this, _1), "transfer [ ... ] [payment_id] - Transfer ,... to ,... , respectively. is the number of transactions yours is indistinguishable from (from 0 to maximum available), is an optional HEX-encoded string"); m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), "set_log - Change current log detalisation level, is a number 0-4"); m_cmd_binder.set_handler("enable_console_logger", boost::bind(&simple_wallet::enable_console_logger, this, _1), "Enables console logging"); m_cmd_binder.set_handler("resync", boost::bind(&simple_wallet::resync_wallet, this, _1), "Causes wallet to reset all transfers and re-synchronize wallet"); @@ -1142,26 +1142,31 @@ bool simple_wallet::transfer(const std::vector &args_) local_args.erase(local_args.begin()); - std::string payment_id; + currency::payment_id_t payment_id; if (1 == local_args.size() % 2) { - payment_id = local_args.back(); + std::string payment_id_hex = local_args.back(); local_args.pop_back(); + if (!payment_id_hex.empty() && !currency::parse_payment_id_from_hex_str(payment_id_hex, payment_id)) + { + fail_msg_writer() << "unable to parse payment id: " << payment_id_hex << ", HEX-encoded string is expected"; + return true; + } } - + if (!currency::is_payment_id_size_ok(payment_id)) { - fail_msg_writer() << "payment id is too long: " << payment_id.size() << " bytes, max allowed: " << BC_PAYMENT_ID_SERVICE_SIZE_MAX; + fail_msg_writer() << "decoded payment id is too long: " << payment_id.size() << " bytes, max allowed: " << BC_PAYMENT_ID_SERVICE_SIZE_MAX; return true; } vector dsts; for (size_t i = 0; i < local_args.size(); i += 2) { - std::string embedded_payment_id; + std::string integrated_payment_id; currency::tx_destination_entry de; de.addr.resize(1); - if(!(de.addr.size() == 1 && m_wallet->get_transfer_address(local_args[i], de.addr.front(), embedded_payment_id))) + if(!(de.addr.size() == 1 && m_wallet->get_transfer_address(local_args[i], de.addr.front(), integrated_payment_id))) { fail_msg_writer() << "wrong address: " << local_args[i]; return true; @@ -1181,14 +1186,14 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } - if (embedded_payment_id.size() != 0) + if (integrated_payment_id.size() != 0) { if (payment_id.size() != 0) { - fail_msg_writer() << "address " + local_args[i] + " has embedded payment id \"" + embedded_payment_id + "\" which conflicts with previously set payment id: \"" << payment_id << "\""; + fail_msg_writer() << "address " + local_args[i] + " has integrated payment id " + epee::string_tools::buff_to_hex_nodelimer(integrated_payment_id) + " which conflicts with previously set payment id: " << epee::string_tools::buff_to_hex_nodelimer(payment_id) << ""; return true; } - payment_id = embedded_payment_id; + payment_id = integrated_payment_id; } dsts.push_back(de);