print_owners_to_names now shows cached names and values

This commit is contained in:
Sean Darcy 2020-05-08 05:53:59 +00:00 committed by Jason Rhinelander
parent b734843d77
commit 12fc6a2592
3 changed files with 33 additions and 25 deletions

View File

@ -6529,15 +6529,6 @@ bool simple_wallet::lns_buy_mapping(std::vector<std::string> args)
info.is_subaddress = m_current_subaddress_account != 0;
dsts.push_back(info);
//TODO:(sean)
tools::wallet2::lns_detail detail = {
lns::mapping_type::session,
"testname",
"testvalue",
"testowner",
"testbackupowner" };
m_wallet->set_lns_cache_record(detail);
std::cout << std::endl << tr("Buying Loki Name System Record") << std::endl << std::endl;
if (type == lns::mapping_type::session)
std::cout << boost::format(tr("Session Name: %s")) % name << std::endl;
@ -6567,13 +6558,16 @@ bool simple_wallet::lns_buy_mapping(std::vector<std::string> args)
//TODO(sean)
std::cout << tr("Setting the LNS Cache") << std::endl;
//m_wallet->set_lns_cache_record(
//lns::mapping_type::session,
//name,
//value,
//owner.size() ? owner : m_wallet->get_subaddress_as_str({m_current_subaddress_account, 0}),
//backup_owner.size() ? backup_owner : "");
//
crypto::hash name_hash = lns::name_to_hash(name);
std::string name_hash_str = epee::string_encoding::base64_encode(reinterpret_cast<unsigned char const *>(name_hash.data), sizeof(name_hash));
tools::wallet2::lns_detail detail = {
lns::mapping_type::session,
name,
name_hash_str,
value,
owner.size() ? owner : m_wallet->get_subaddress_as_str({m_current_subaddress_account, 0}),
backup_owner.size() ? backup_owner : ""};
m_wallet->set_lns_cache_record(detail);
}
catch (const std::exception &e)
{
@ -7000,18 +6994,14 @@ bool simple_wallet::lns_print_owners_to_names(const std::vector<std::string>& ar
std::vector<std::vector<cryptonote::rpc::LNS_OWNERS_TO_NAMES::response_entry>> rpc_results;
std::vector<cryptonote::rpc::LNS_OWNERS_TO_NAMES::request> requests(1);
//TODO(sean)
std::vector<tools::wallet2::lns_detail> cache = m_wallet->get_lns_cache();
if (args.size() == 0)
{
for (uint32_t index = 0; index < m_wallet->get_num_subaddresses(m_current_subaddress_account); ++index)
{
//TODO(sean)
std::cout << tr("Retrieving the Cache") << std::endl;
std::vector<tools::wallet2::lns_detail> cache = m_wallet->get_lns_cache_record("", "", m_wallet->get_subaddress_as_str({m_current_subaddress_account, index}) , "");
std::cout << cache.size() << std::endl;
for(unsigned int i=0; i<cache.size(); ++i)
std::cout << cache[i].name << ' ';
if (requests.back().entries.size() >= cryptonote::rpc::LNS_OWNERS_TO_NAMES::MAX_REQUEST_ENTRIES)
requests.emplace_back();
requests.back().entries.push_back(m_wallet->get_subaddress_as_str({m_current_subaddress_account, index}));
@ -7051,6 +7041,7 @@ bool simple_wallet::lns_print_owners_to_names(const std::vector<std::string>& ar
rpc_results.emplace_back(std::move(result));
}
for (size_t i = 0; i < rpc_results.size(); i++)
{
auto const &rpc = rpc_results[i];
@ -7066,10 +7057,23 @@ bool simple_wallet::lns_print_owners_to_names(const std::vector<std::string>& ar
fail_msg_writer() << "Daemon returned an invalid owner index = " << entry.request_index << " skipping mapping";
continue;
}
//TODO(sean):
std::string name = "";
std::string value = "";
for (size_t j = 0; j < cache.size(); j++)
{
if (cache[j].hashed_name == entry.name_hash) {
name = cache[j].name;
value = cache[j].value;
}
}
auto writer = tools::msg_writer();
writer
<< "Name (hashed): " << entry.name_hash
<< "Name (hashed): " << entry.name_hash;
if (!name.empty()) writer
<< "\n Name: " << name;
writer
<< "\n Type: " << entry.type
<< "\n Owner: " << *owner;
if (entry.backup_owner) writer
@ -7080,6 +7084,8 @@ bool simple_wallet::lns_print_owners_to_names(const std::vector<std::string>& ar
<< "\n Expiration height: " << *entry.expiration_height;
writer
<< "\n Encrypted value: " << entry.encrypted_value;
if (!value.empty()) writer
<< "\n Value: " << value;
}
}
return true;

View File

@ -12998,7 +12998,7 @@ void wallet2::set_lns_cache_record(const wallet2::lns_detail& detail)
lns_records_cache.push_back(detail);
}
std::vector<wallet2::lns_detail> wallet2::get_lns_cache_record(std::string name, std::string value, std::string owner, std::string backup_owner)
std::vector<wallet2::lns_detail> wallet2::get_lns_cache()
{
return lns_records_cache;
}

View File

@ -802,6 +802,7 @@ private:
{
lns::mapping_type type;
std::string name;
std::string hashed_name;
std::string value;
std::string owner;
std::string backup_owner;
@ -810,7 +811,7 @@ private:
void set_lns_cache_record(const wallet2::lns_detail& detail);
std::vector<lns_detail> get_lns_cache_record(std::string name, std::string value, std::string owner, std::string backup_owner);
std::vector<lns_detail> get_lns_cache();
uint64_t get_blockchain_current_height() const { return m_light_wallet_blockchain_height ? m_light_wallet_blockchain_height : m_blockchain.size(); }
void rescan_spent();
@ -1688,6 +1689,7 @@ namespace boost::serialization
{
a & x.type;
a & x.name;
a & x.hashed_name;
a & x.value;
a & x.owner;
a & x.backup_owner;