From fcb162e50b9e2da4f3b312b9ed3d7d08c25ac48d Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 10 Feb 2020 12:57:02 -0500 Subject: [PATCH] remove standalone payment id from add/edit_address_book_entry --- src/wallet/monero_wallet_core.cpp | 41 ++++--------------------------- src/wallet/monero_wallet_core.h | 4 +-- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 002702e..d99ea69 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -2794,10 +2794,9 @@ namespace monero { return entries; } - uint64_t monero_wallet_core::add_address_book_entry(const string& address, const string& description, const string& payment_id) { + uint64_t monero_wallet_core::add_address_book_entry(const string& address, const string& description) { MTRACE("add_address_book_entry()"); cryptonote::address_parse_info info; - crypto::hash payment_id_hash = crypto::null_hash; epee::json_rpc::error er; if(!get_account_address_from_str_or_url(info, m_w2->nettype(), address, [&er](const std::string &url, const std::vector &addresses, bool dnssec_valid)->std::string { @@ -2808,23 +2807,11 @@ namespace monero { { throw runtime_error(std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + address); } - if (info.has_payment_id) { - memcpy(payment_id_hash.data, info.payment_id.data, 8); - memset(payment_id_hash.data + 8, 0, 24); - } - if (!payment_id.empty()) { - if (info.has_payment_id) throw runtime_error("Separate payment ID given with integrated address"); - crypto::hash long_payment_id; - if (!wallet2::parse_long_payment_id(payment_id, payment_id_hash)) { - if (!wallet2::parse_short_payment_id(payment_id, info.payment_id)) throw runtime_error("Payment id has invalid format: \"" + payment_id + "\", expected 64 character string"); - else throw runtime_error("Payment id has invalid format: standalone short payment IDs are forbidden, they must be part of an integrated address"); - } - } - if (!m_w2->add_address_book_row(info.address, payment_id_hash, description, info.is_subaddress)) throw runtime_error("Failed to add address book entry"); + if (!m_w2->add_address_book_row(info.address, info.has_payment_id ? &info.payment_id : NULL, description, info.is_subaddress)) throw runtime_error("Failed to add address book entry"); return m_w2->get_address_book().size() - 1; } - void monero_wallet_core::edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description, bool set_payment_id, const string& payment_id) { + void monero_wallet_core::edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description) { MTRACE("edit_address_book_entry()"); const auto ab = m_w2->get_address_book(); @@ -2833,7 +2820,6 @@ namespace monero { tools::wallet2::address_book_row entry = ab[index]; cryptonote::address_parse_info info; - crypto::hash payment_id_hash = crypto::null_hash; epee::json_rpc::error er; if (set_address) { er.message = ""; @@ -2848,29 +2834,12 @@ namespace monero { } entry.m_address = info.address; entry.m_is_subaddress = info.is_subaddress; - if (info.has_payment_id) { - memcpy(entry.m_payment_id.data, info.payment_id.data, 8); - memset(entry.m_payment_id.data + 8, 0, 24); - } - } - - if (set_payment_id) { - if (payment_id.empty()) { - payment_id_hash = crypto::null_hash; - } else { - if (set_address && info.has_payment_id) throw runtime_error("Separate payment ID given with integrated address"); - if (!wallet2::parse_long_payment_id(payment_id, payment_id_hash)) { - crypto::hash8 spid; - if (!wallet2::parse_short_payment_id(payment_id, spid)) throw runtime_error("Payment id has invalid format: \"" + payment_id + "\", expected 64 character string"); - else throw runtime_error("Payment id has invalid format: standalone short payment IDs are forbidden, they must be part of an integrated address"); - } - } - entry.m_payment_id = payment_id_hash; + if (info.has_payment_id) entry.m_payment_id = info.payment_id; } if (set_description) entry.m_description = description; - if (!m_w2->set_address_book_row(index, entry.m_address, entry.m_payment_id, entry.m_description, entry.m_is_subaddress)) { + if (!m_w2->set_address_book_row(index, entry.m_address, set_address && entry.m_has_payment_id ? &entry.m_payment_id : NULL, entry.m_description, entry.m_is_subaddress)) { throw runtime_error("Failed to edit address book entry"); } } diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index 4762996..968968f 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -263,8 +263,8 @@ namespace monero { void set_tx_note(const string& tx_hash, const string& note); void set_tx_notes(const vector& tx_hashes, const vector& notes); vector get_address_book_entries(const vector& indices) const; - uint64_t add_address_book_entry(const string& address, const string& description, const string& payment_id = ""); - void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description, bool set_payment_id = false, const string& payment_id = ""); + uint64_t add_address_book_entry(const string& address, const string& description); + void edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description); void delete_address_book_entry(uint64_t index); string create_payment_uri(const monero_send_request& request) const; shared_ptr parse_payment_uri(const string& uri) const;