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
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
8 changed files with 78 additions and 223 deletions

View File

@ -196,7 +196,7 @@ namespace
" account tag_description <tag_name> <description>"); " account tag_description <tag_name> <description>");
const char* USAGE_ADDRESS("address [ new <label text with white spaces allowed> | all | <index_min> [<index_max>] | label <index> <label text with white spaces allowed> | device [<index>]]"); const char* USAGE_ADDRESS("address [ new <label text with white spaces allowed> | all | <index_min> [<index_max>] | label <index> <label text with white spaces allowed> | device [<index>]]");
const char* USAGE_INTEGRATED_ADDRESS("integrated_address [device] [<payment_id> | <address>]"); const char* USAGE_INTEGRATED_ADDRESS("integrated_address [device] [<payment_id> | <address>]");
const char* USAGE_ADDRESS_BOOK("address_book [(add ((<address> [pid <id>])|<integrated address>) [<description possibly with whitespaces>])|(delete <index>)]"); const char* USAGE_ADDRESS_BOOK("address_book [(add (<address>|<integrated address>) [<description possibly with whitespaces>])|(delete <index>)]");
const char* USAGE_SET_VARIABLE("set <option> [<value>]"); const char* USAGE_SET_VARIABLE("set <option> [<value>]");
const char* USAGE_GET_TX_KEY("get_tx_key <txid>"); const char* USAGE_GET_TX_KEY("get_tx_key <txid>");
const char* USAGE_SET_TX_KEY("set_tx_key <txid> <tx_key>"); const char* USAGE_SET_TX_KEY("set_tx_key <txid> <tx_key>");
@ -9385,29 +9385,7 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
fail_msg_writer() << tr("failed to parse address"); fail_msg_writer() << tr("failed to parse address");
return true; return true;
} }
crypto::hash payment_id = crypto::null_hash;
size_t description_start = 2; size_t description_start = 2;
if (info.has_payment_id)
{
memcpy(payment_id.data, info.payment_id.data, 8);
}
else if (!info.has_payment_id && args.size() >= 4 && args[2] == "pid")
{
if (tools::wallet2::parse_long_payment_id(args[3], payment_id))
{
LONG_PAYMENT_ID_SUPPORT_CHECK();
}
else if (tools::wallet2::parse_short_payment_id(args[3], info.payment_id))
{
fail_msg_writer() << tr("Short payment IDs are to be used within an integrated address only");
return true;
}
else
{
fail_msg_writer() << tr("failed to parse payment ID");
return true;
}
}
std::string description; std::string description;
for (size_t i = description_start; i < args.size(); ++i) for (size_t i = description_start; i < args.size(); ++i)
{ {
@ -9415,7 +9393,7 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
description += " "; description += " ";
description += args[i]; description += args[i];
} }
m_wallet->add_address_book_row(info.address, payment_id, description, info.is_subaddress); m_wallet->add_address_book_row(info.address, info.has_payment_id ? &info.payment_id : NULL, description, info.is_subaddress);
} }
else else
{ {
@ -9437,8 +9415,12 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
for (size_t i = 0; i < address_book.size(); ++i) { for (size_t i = 0; i < address_book.size(); ++i) {
auto& row = address_book[i]; auto& row = address_book[i];
success_msg_writer() << tr("Index: ") << i; success_msg_writer() << tr("Index: ") << i;
success_msg_writer() << tr("Address: ") << get_account_address_as_str(m_wallet->nettype(), row.m_is_subaddress, row.m_address); std::string address;
success_msg_writer() << tr("Payment ID: ") << row.m_payment_id << " (OBSOLETE)"; if (row.m_has_payment_id)
address = cryptonote::get_account_integrated_address_as_str(m_wallet->nettype(), row.m_address, row.m_payment_id);
else
address = get_account_address_as_str(m_wallet->nettype(), row.m_is_subaddress, row.m_address);
success_msg_writer() << tr("Address: ") << address;
success_msg_writer() << tr("Description: ") << row.m_description << "\n"; success_msg_writer() << tr("Description: ") << row.m_description << "\n";
} }
} }

View File

@ -55,37 +55,14 @@ bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &pa
return false; return false;
} }
crypto::hash payment_id = crypto::null_hash; if (!payment_id_str.empty())
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)
{ {
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) if (r)
refresh(); refresh();
else else
@ -104,19 +81,12 @@ void AddressBookImpl::refresh()
for (size_t i = 0; i < rows.size(); ++i) { for (size_t i = 0; i < rows.size(); ++i) {
tools::wallet2::address_book_row * row = &rows.at(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;
std::string address = cryptonote::get_account_address_as_str(m_wallet->m_wallet->nettype(), row->m_is_subaddress, row->m_address); if (row->m_has_payment_id)
// convert the zero padded short payment id to integrated address address = cryptonote::get_account_integrated_address_as_str(m_wallet->m_wallet->nettype(), row->m_address, row->m_payment_id);
if (!row->m_is_subaddress && payment_id.length() > 16 && payment_id.substr(16).find_first_not_of('0') == std::string::npos) { else
payment_id = payment_id.substr(0,16); address = get_account_address_as_str(m_wallet->m_wallet->nettype(), row->m_is_subaddress, row->m_address);
crypto::hash8 payment_id_short; AddressBookRow * abr = new AddressBookRow(i, address, "", row->m_description);
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);
m_rows.push_back(abr); m_rows.push_back(abr);
} }

View File

@ -3151,11 +3151,12 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height,
} }
bool wallet2::add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description, bool is_subaddress) bool wallet2::add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress)
{ {
wallet2::address_book_row a; wallet2::address_book_row a;
a.m_address = address; a.m_address = address;
a.m_payment_id = payment_id; a.m_has_payment_id = !!payment_id;
a.m_payment_id = payment_id ? *payment_id : crypto::null_hash8;
a.m_description = description; a.m_description = description;
a.m_is_subaddress = is_subaddress; a.m_is_subaddress = is_subaddress;
@ -3166,11 +3167,12 @@ bool wallet2::add_address_book_row(const cryptonote::account_public_address &add
return false; return false;
} }
bool wallet2::set_address_book_row(size_t row_id, const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description, bool is_subaddress) bool wallet2::set_address_book_row(size_t row_id, const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress)
{ {
wallet2::address_book_row a; wallet2::address_book_row a;
a.m_address = address; a.m_address = address;
a.m_payment_id = payment_id; a.m_has_payment_id = !!payment_id;
a.m_payment_id = payment_id ? *payment_id : crypto::null_hash8;
a.m_description = description; a.m_description = description;
a.m_is_subaddress = is_subaddress; a.m_is_subaddress = is_subaddress;

View File

@ -546,9 +546,10 @@ private:
struct address_book_row struct address_book_row
{ {
cryptonote::account_public_address m_address; cryptonote::account_public_address m_address;
crypto::hash m_payment_id; crypto::hash8 m_payment_id;
std::string m_description; std::string m_description;
bool m_is_subaddress; bool m_is_subaddress;
bool m_has_payment_id;
}; };
struct reserve_proof_entry struct reserve_proof_entry
@ -1125,8 +1126,8 @@ private:
* \brief GUI Address book get/store * \brief GUI Address book get/store
*/ */
std::vector<address_book_row> get_address_book() const { return m_address_book; } std::vector<address_book_row> get_address_book() const { return m_address_book; }
bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description, bool is_subaddress); bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress);
bool set_address_book_row(size_t row_id, const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description, bool is_subaddress); bool set_address_book_row(size_t row_id, const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress);
bool delete_address_book_row(std::size_t row_id); bool delete_address_book_row(std::size_t row_id);
uint64_t get_num_rct_outputs(); uint64_t get_num_rct_outputs();
@ -1634,7 +1635,7 @@ BOOST_CLASS_VERSION(tools::wallet2::payment_details, 4)
BOOST_CLASS_VERSION(tools::wallet2::pool_payment_details, 1) BOOST_CLASS_VERSION(tools::wallet2::pool_payment_details, 1)
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 8) BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 8)
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 6) BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 6)
BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 17) BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 18)
BOOST_CLASS_VERSION(tools::wallet2::reserve_proof_entry, 0) BOOST_CLASS_VERSION(tools::wallet2::reserve_proof_entry, 0)
BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0) BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0)
BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1) BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1)
@ -1954,7 +1955,26 @@ namespace boost
inline void serialize(Archive& a, tools::wallet2::address_book_row& x, const boost::serialization::version_type ver) inline void serialize(Archive& a, tools::wallet2::address_book_row& x, const boost::serialization::version_type ver)
{ {
a & x.m_address; a & x.m_address;
a & x.m_payment_id; if (ver < 18)
{
crypto::hash payment_id;
a & payment_id;
x.m_has_payment_id = !(payment_id == crypto::null_hash);
if (x.m_has_payment_id)
{
bool is_long = false;
for (int i = 8; i < 32; ++i)
is_long |= payment_id.data[i];
if (is_long)
{
MWARNING("Long payment ID ignored on address book load");
x.m_payment_id = crypto::null_hash8;
x.m_has_payment_id = false;
}
else
memcpy(x.m_payment_id.data, payment_id.data, 8);
}
}
a & x.m_description; a & x.m_description;
if (ver < 17) if (ver < 17)
{ {
@ -1962,6 +1982,11 @@ namespace boost
return; return;
} }
a & x.m_is_subaddress; a & x.m_is_subaddress;
if (ver < 18)
return;
a & x.m_has_payment_id;
if (x.m_has_payment_id)
a & x.m_payment_id;
} }
template <class Archive> template <class Archive>

View File

@ -2745,7 +2745,14 @@ namespace tools
{ {
uint64_t idx = 0; uint64_t idx = 0;
for (const auto &entry: ab) for (const auto &entry: ab)
res.entries.push_back(wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::entry{idx++, get_account_address_as_str(m_wallet->nettype(), entry.m_is_subaddress, entry.m_address), epee::string_tools::pod_to_hex(entry.m_payment_id), entry.m_description}); {
std::string address;
if (entry.m_has_payment_id)
address = cryptonote::get_account_integrated_address_as_str(m_wallet->nettype(), entry.m_address, entry.m_payment_id);
else
address = get_account_address_as_str(m_wallet->nettype(), entry.m_is_subaddress, entry.m_address);
res.entries.push_back(wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::entry{idx++, address, entry.m_description});
}
} }
else else
{ {
@ -2758,7 +2765,12 @@ namespace tools
return false; return false;
} }
const auto &entry = ab[idx]; const auto &entry = ab[idx];
res.entries.push_back(wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::entry{idx, get_account_address_as_str(m_wallet->nettype(), entry.m_is_subaddress, entry.m_address), epee::string_tools::pod_to_hex(entry.m_payment_id), entry.m_description}); std::string address;
if (entry.m_has_payment_id)
address = cryptonote::get_account_integrated_address_as_str(m_wallet->nettype(), entry.m_address, entry.m_payment_id);
else
address = get_account_address_as_str(m_wallet->nettype(), entry.m_is_subaddress, entry.m_address);
res.entries.push_back(wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::entry{idx, address, entry.m_description});
} }
} }
return true; return true;
@ -2775,7 +2787,6 @@ namespace tools
} }
cryptonote::address_parse_info info; cryptonote::address_parse_info info;
crypto::hash payment_id = crypto::null_hash;
er.message = ""; er.message = "";
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address, if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address,
[&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string { [&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
@ -2797,39 +2808,7 @@ namespace tools
er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + req.address; er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + req.address;
return false; return false;
} }
if (info.has_payment_id) if (!m_wallet->add_address_book_row(info.address, info.has_payment_id ? &info.payment_id : NULL, req.description, info.is_subaddress))
{
memcpy(payment_id.data, info.payment_id.data, 8);
memset(payment_id.data + 8, 0, 24);
}
if (!req.payment_id.empty())
{
if (info.has_payment_id)
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Separate payment ID given with integrated address";
return false;
}
crypto::hash long_payment_id;
if (!wallet2::parse_long_payment_id(req.payment_id, payment_id))
{
if (!wallet2::parse_short_payment_id(req.payment_id, info.payment_id))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Payment id has invalid format: \"" + req.payment_id + "\", expected 64 character string";
return false;
}
else
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Payment id has invalid format: standalone short payment IDs are forbidden, they must be part of an integrated address";
return false;
}
}
}
if (!m_wallet->add_address_book_row(info.address, payment_id, req.description, info.is_subaddress))
{ {
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "Failed to add address book entry"; er.message = "Failed to add address book entry";
@ -2860,7 +2839,6 @@ namespace tools
tools::wallet2::address_book_row entry = ab[req.index]; tools::wallet2::address_book_row entry = ab[req.index];
cryptonote::address_parse_info info; cryptonote::address_parse_info info;
crypto::hash payment_id = crypto::null_hash;
if (req.set_address) if (req.set_address)
{ {
er.message = ""; er.message = "";
@ -2887,52 +2865,13 @@ namespace tools
entry.m_address = info.address; entry.m_address = info.address;
entry.m_is_subaddress = info.is_subaddress; entry.m_is_subaddress = info.is_subaddress;
if (info.has_payment_id) if (info.has_payment_id)
{ entry.m_payment_id = info.payment_id;
memcpy(entry.m_payment_id.data, info.payment_id.data, 8);
memset(entry.m_payment_id.data + 8, 0, 24);
}
}
if (req.set_payment_id)
{
if (req.payment_id.empty())
{
payment_id = crypto::null_hash;
}
else
{
if (req.set_address && info.has_payment_id)
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Separate payment ID given with integrated address";
return false;
}
if (!wallet2::parse_long_payment_id(req.payment_id, payment_id))
{
crypto::hash8 spid;
if (!wallet2::parse_short_payment_id(req.payment_id, spid))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Payment id has invalid format: \"" + req.payment_id + "\", expected 64 character string";
return false;
}
else
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Payment id has invalid format: standalone short payment IDs are forbidden, they must be part of an integrated address";
return false;
}
}
}
entry.m_payment_id = payment_id;
} }
if (req.set_description) if (req.set_description)
entry.m_description = req.description; entry.m_description = req.description;
if (!m_wallet->set_address_book_row(req.index, entry.m_address, entry.m_payment_id, entry.m_description, entry.m_is_subaddress)) if (!m_wallet->set_address_book_row(req.index, entry.m_address, req.set_address && entry.m_has_payment_id ? &entry.m_payment_id : NULL, entry.m_description, entry.m_is_subaddress))
{ {
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "Failed to edit address book entry"; er.message = "Failed to edit address book entry";

View File

@ -1829,12 +1829,10 @@ namespace wallet_rpc
struct request_t struct request_t
{ {
std::string address; std::string address;
std::string payment_id;
std::string description; std::string description;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address) KV_SERIALIZE(address)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(description) KV_SERIALIZE(description)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };
@ -1858,8 +1856,6 @@ namespace wallet_rpc
uint64_t index; uint64_t index;
bool set_address; bool set_address;
std::string address; std::string address;
bool set_payment_id;
std::string payment_id;
bool set_description; bool set_description;
std::string description; std::string description;
@ -1867,8 +1863,6 @@ namespace wallet_rpc
KV_SERIALIZE(index) KV_SERIALIZE(index)
KV_SERIALIZE(set_address) KV_SERIALIZE(set_address)
KV_SERIALIZE(address) KV_SERIALIZE(address)
KV_SERIALIZE(set_payment_id)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(set_description) KV_SERIALIZE(set_description)
KV_SERIALIZE(description) KV_SERIALIZE(description)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
@ -1899,13 +1893,11 @@ namespace wallet_rpc
{ {
uint64_t index; uint64_t index;
std::string address; std::string address;
std::string payment_id;
std::string description; std::string description;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(index) KV_SERIALIZE(index)
KV_SERIALIZE(address) KV_SERIALIZE(address)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(description) KV_SERIALIZE(description)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View File

@ -73,14 +73,13 @@ class AddressBookTest():
# add one # add one
res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', description = 'self') res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', description = 'self')
assert res.index == 0 assert res.index == 0, res
for get_all in [True, False]: for get_all in [True, False]:
res = wallet.get_address_book() if get_all else wallet.get_address_book([0]) res = wallet.get_address_book() if get_all else wallet.get_address_book([0])
assert len(res.entries) == 1 assert len(res.entries) == 1
e = res.entries[0] e = res.entries[0]
assert e.index == 0 assert e.index == 0
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', e
assert e.payment_id == '' or e.payment_id == '0' * 16 or e.payment_id == '0' * 64
assert e.description == 'self' assert e.description == 'self'
# add a duplicate # add a duplicate
@ -91,7 +90,6 @@ class AddressBookTest():
assert res.entries[0].index == 0 assert res.entries[0].index == 0
assert res.entries[1].index == 1 assert res.entries[1].index == 1
assert res.entries[0].address == res.entries[1].address assert res.entries[0].address == res.entries[1].address
assert res.entries[0].payment_id == res.entries[1].payment_id
assert res.entries[0].description == res.entries[1].description assert res.entries[0].description == res.entries[1].description
e = res.entries[1] e = res.entries[1]
res = wallet.get_address_book([1]) res = wallet.get_address_book([1])
@ -118,7 +116,6 @@ class AddressBookTest():
assert len(res.entries) == 1 assert len(res.entries) == 1
assert res.entries[0].index == 0 assert res.entries[0].index == 0
assert res.entries[0].address == e.address assert res.entries[0].address == e.address
assert res.entries[0].payment_id == e.payment_id
assert res.entries[0].description == e.description assert res.entries[0].description == e.description
# delete (new) first # delete (new) first
@ -165,38 +162,13 @@ class AddressBookTest():
assert res.entries[0] == e assert res.entries[0] == e
assert res.entries[1] == e assert res.entries[1] == e
# payment IDs
res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 64)
assert res.index == 2
ok = False
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = 'x' * 64)
except: ok = True
assert ok
ok = False
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 65)
except: ok = True
assert ok
ok = False
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 63)
except: ok = True
assert ok
ok = False
try: res = wallet.add_address_book('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', payment_id = '0' * 16)
except: ok = True
assert ok
# various address types # various address types
res = wallet.make_integrated_address() res = wallet.make_integrated_address()
integrated_address = res.integrated_address integrated_address = res.integrated_address
integrated_address_payment_id = res.payment_id
ok = False
try: res = wallet.add_address_book(integrated_address, payment_id = '0' * 64)
except: ok = True
assert ok
res = wallet.add_address_book(integrated_address) res = wallet.add_address_book(integrated_address)
assert res.index == 3 assert res.index == 2
res = wallet.add_address_book('87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB') res = wallet.add_address_book('87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB')
assert res.index == 4 assert res.index == 3
# get them back # get them back
res = wallet.get_address_book([0]) res = wallet.get_address_book([0])
@ -209,16 +181,9 @@ class AddressBookTest():
assert res.entries[0].description == u'あまやかす' assert res.entries[0].description == u'あまやかす'
res = wallet.get_address_book([2]) res = wallet.get_address_book([2])
assert len(res.entries) == 1 assert len(res.entries) == 1
assert res.entries[0].address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert res.entries[0].address == integrated_address
res = wallet.get_address_book([3]) res = wallet.get_address_book([3])
assert len(res.entries) == 1 assert len(res.entries) == 1
if False: # for now, the address book splits integrated addresses
assert res.entries[0].address == integrated_address
else:
assert res.entries[0].address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert res.entries[0].payment_id == integrated_address_payment_id + '0' * 48
res = wallet.get_address_book([4])
assert len(res.entries) == 1
assert res.entries[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.entries[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB'
# edit # edit
@ -227,15 +192,12 @@ class AddressBookTest():
e = res.entries[0] e = res.entries[0]
assert e.index == 1 assert e.index == 1
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert e.payment_id == '0' * 64
assert e.description == u'あまやかす' assert e.description == u'あまやかす'
res = wallet.edit_address_book(1, payment_id = '1' * 64)
res = wallet.get_address_book([1]) res = wallet.get_address_book([1])
assert len(res.entries) == 1 assert len(res.entries) == 1
e = res.entries[0] e = res.entries[0]
assert e.index == 1 assert e.index == 1
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert e.payment_id == '1' * 64
assert e.description == u'あまやかす' assert e.description == u'あまやかす'
res = wallet.edit_address_book(1, description = '') res = wallet.edit_address_book(1, description = '')
res = wallet.get_address_book([1]) res = wallet.get_address_book([1])
@ -243,7 +205,6 @@ class AddressBookTest():
e = res.entries[0] e = res.entries[0]
assert e.index == 1 assert e.index == 1
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert e.payment_id == '1' * 64
assert e.description == '' assert e.description == ''
res = wallet.edit_address_book(1, description = 'えんしゅう') res = wallet.edit_address_book(1, description = 'えんしゅう')
res = wallet.get_address_book([1]) res = wallet.get_address_book([1])
@ -251,7 +212,6 @@ class AddressBookTest():
e = res.entries[0] e = res.entries[0]
assert e.index == 1 assert e.index == 1
assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert e.payment_id == '1' * 64
assert e.description == u'えんしゅう' assert e.description == u'えんしゅう'
res = wallet.edit_address_book(1, address = '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A') res = wallet.edit_address_book(1, address = '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A')
res = wallet.get_address_book([1]) res = wallet.get_address_book([1])
@ -259,25 +219,12 @@ class AddressBookTest():
e = res.entries[0] e = res.entries[0]
assert e.index == 1 assert e.index == 1
assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A' assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
assert e.payment_id == '1' * 64
assert e.description == u'えんしゅう'
res = wallet.edit_address_book(1, payment_id = '')
res = wallet.get_address_book([1])
assert len(res.entries) == 1
e = res.entries[0]
assert e.index == 1
assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'
assert e.payment_id == '0' * 64
assert e.description == u'えんしゅう' assert e.description == u'えんしゅう'
ok = False ok = False
try: res = wallet.edit_address_book(1, address = '') try: res = wallet.edit_address_book(1, address = '')
except: ok = True except: ok = True
assert ok assert ok
ok = False ok = False
try: res = wallet.edit_address_book(1, payment_id = 'asdnd')
except: ok = True
assert ok
ok = False
try: res = wallet.edit_address_book(1, address = 'address') try: res = wallet.edit_address_book(1, address = 'address')
except: ok = True except: ok = True
assert ok assert ok
@ -287,7 +234,6 @@ class AddressBookTest():
assert e == res.entries[0] assert e == res.entries[0]
# empty # empty
wallet.delete_address_book(4)
wallet.delete_address_book(0) wallet.delete_address_book(0)
res = wallet.get_address_book([0]) # entries above the deleted one collapse one slot up res = wallet.get_address_book([0]) # entries above the deleted one collapse one slot up
assert len(res.entries) == 1 assert len(res.entries) == 1

View File

@ -735,7 +735,6 @@ TEST(Serialization, portability_wallet)
auto address_book_row = w.m_address_book.begin(); auto address_book_row = w.m_address_book.begin();
ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_address.m_spend_public_key) == "9bc53a6ff7b0831c9470f71b6b972dbe5ad1e8606f72682868b1dda64e119fb3"); ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_address.m_spend_public_key) == "9bc53a6ff7b0831c9470f71b6b972dbe5ad1e8606f72682868b1dda64e119fb3");
ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_address.m_view_public_key) == "49fece1ef97dc0c0f7a5e2106e75e96edd910f7e86b56e1e308cd0cf734df191"); ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_address.m_view_public_key) == "49fece1ef97dc0c0f7a5e2106e75e96edd910f7e86b56e1e308cd0cf734df191");
ASSERT_TRUE(epee::string_tools::pod_to_hex(address_book_row->m_payment_id) == "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
ASSERT_TRUE(address_book_row->m_description == "testnet wallet 9y52S6"); ASSERT_TRUE(address_book_row->m_description == "testnet wallet 9y52S6");
} }
} }