wallet: do not split integrated addresses in address book api

This commit is contained in:
moneromooo-monero
2019-11-19 16:30:19 +00:00
parent 59e7d5686b
commit dd8c6b1703
8 changed files with 78 additions and 223 deletions
+12 -42
View File
@@ -55,37 +55,14 @@ bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &pa
return false;
}
crypto::hash payment_id = crypto::null_hash;
bool has_long_pid = (payment_id_str.empty())? false : tools::wallet2::parse_long_payment_id(payment_id_str, payment_id);
// Short payment id provided
if(payment_id_str.length() == 16) {
m_errorString = tr("Invalid payment ID. Short payment ID should only be used in an integrated address");
m_errorCode = Invalid_Payment_Id;
return false;
}
// long payment id provided but not valid
if(!payment_id_str.empty() && !has_long_pid) {
m_errorString = tr("Invalid payment ID");
m_errorCode = Invalid_Payment_Id;
return false;
}
// integrated + long payment id provided
if(has_long_pid && info.has_payment_id) {
m_errorString = tr("Integrated address and long payment ID can't be used at the same time");
m_errorCode = Invalid_Payment_Id;
return false;
}
// Pad short pid with zeros
if (info.has_payment_id)
if (!payment_id_str.empty())
{
memcpy(payment_id.data, info.payment_id.data, 8);
m_errorString = tr("Payment ID supplied: this is obsolete");
m_errorCode = Invalid_Payment_Id;
return false;
}
bool r = m_wallet->m_wallet->add_address_book_row(info.address,payment_id,description,info.is_subaddress);
bool r = m_wallet->m_wallet->add_address_book_row(info.address, info.has_payment_id ? &info.payment_id : NULL,description,info.is_subaddress);
if (r)
refresh();
else
@@ -104,19 +81,12 @@ void AddressBookImpl::refresh()
for (size_t i = 0; i < rows.size(); ++i) {
tools::wallet2::address_book_row * row = &rows.at(i);
std::string payment_id = (row->m_payment_id == crypto::null_hash)? "" : epee::string_tools::pod_to_hex(row->m_payment_id);
std::string address = cryptonote::get_account_address_as_str(m_wallet->m_wallet->nettype(), row->m_is_subaddress, row->m_address);
// convert the zero padded short payment id to integrated address
if (!row->m_is_subaddress && payment_id.length() > 16 && payment_id.substr(16).find_first_not_of('0') == std::string::npos) {
payment_id = payment_id.substr(0,16);
crypto::hash8 payment_id_short;
if(tools::wallet2::parse_short_payment_id(payment_id, payment_id_short)) {
address = cryptonote::get_account_integrated_address_as_str(m_wallet->m_wallet->nettype(), row->m_address, payment_id_short);
// Don't show payment id when integrated address is used
payment_id = "";
}
}
AddressBookRow * abr = new AddressBookRow(i, address, payment_id, row->m_description);
std::string address;
if (row->m_has_payment_id)
address = cryptonote::get_account_integrated_address_as_str(m_wallet->m_wallet->nettype(), row->m_address, row->m_payment_id);
else
address = get_account_address_as_str(m_wallet->m_wallet->nettype(), row->m_is_subaddress, row->m_address);
AddressBookRow * abr = new AddressBookRow(i, address, "", row->m_description);
m_rows.push_back(abr);
}