Creates a Cache in the CLI Wallet for LNS Records

The lns records are stored on the blockchain in a hashed state so the
name and value are not immediately accessable. This creates a store in
the wallet so the unhashed details are saved and can be viewed at a
later date.
This commit is contained in:
Sean Darcy 2020-05-10 02:44:45 +00:00 committed by Jason Rhinelander
parent 12fc6a2592
commit 87ecffa61b
3 changed files with 45 additions and 8 deletions

View File

@ -6556,8 +6556,6 @@ bool simple_wallet::lns_buy_mapping(std::vector<std::string> args)
if (!confirm_and_send_tx(dsts, ptx_vector, priority == tools::tx_priority_blink))
return false;
//TODO(sean)
std::cout << tr("Setting the LNS Cache") << std::endl;
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 = {
@ -6764,6 +6762,18 @@ bool simple_wallet::lns_update_mapping(std::vector<std::string> args)
if (!confirm_and_send_tx(dsts, ptx_vector, false /*blink*/))
return false;
m_wallet->delete_lns_cache_record(name);
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)
{
@ -6922,7 +6932,6 @@ bool simple_wallet::lns_print_name_to_owners(std::vector<std::string> args)
return true;
}
rpc::LNS_NAMES_TO_OWNERS::request request = {};
for (auto& name : args)
{
@ -6980,6 +6989,16 @@ bool simple_wallet::lns_print_name_to_owners(std::vector<std::string> args)
<< "\n Encrypted value: " << enc_hex;
writer
<< "\n";
tools::wallet2::lns_detail detail =
{
static_cast<lns::mapping_type>(mapping.type),
name,
request.entries[0].name_hash,
value.to_readable_value(m_wallet->nettype(), static_cast<lns::mapping_type>(mapping.type)),
mapping.owner,
(mapping.backup_owner.empty() ? NULL_STR : mapping.backup_owner) };
m_wallet->set_lns_cache_record(detail);
}
for (size_t i = last_index + 1; i < args.size(); i++)
fail_msg_writer() << args[i] << " not found\n";
@ -6994,7 +7013,6 @@ 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)
@ -7057,7 +7075,7 @@ 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++)

View File

@ -12992,10 +12992,28 @@ uint64_t wallet2::get_approximate_blockchain_height() const
return approx_blockchain_height;
}
//TODO(sean)
void wallet2::set_lns_cache_record(const wallet2::lns_detail& detail)
{
lns_records_cache.push_back(detail);
bool exists = false;
for (size_t j = 0; j < lns_records_cache.size(); j++)
{
if (lns_records_cache[j].hashed_name == detail.hashed_name) {
exists = true;
}
}
if (!exists) {
lns_records_cache.push_back(detail);
}
}
void wallet2::delete_lns_cache_record(std::string name)
{
for (size_t j = 0; j < lns_records_cache.size(); j++)
{
if (lns_records_cache[j].name == name) {
lns_records_cache.erase (lns_records_cache.begin()+j);
}
}
}
std::vector<wallet2::lns_detail> wallet2::get_lns_cache()

View File

@ -797,7 +797,6 @@ private:
auto lns_owners_to_names(cryptonote::rpc::LNS_OWNERS_TO_NAMES::request const &request) const { return m_node_rpc_proxy.lns_owners_to_names(request); }
auto lns_names_to_owners(cryptonote::rpc::LNS_NAMES_TO_OWNERS::request const &request) const { return m_node_rpc_proxy.lns_names_to_owners(request); }
//TODO(sean)
struct lns_detail
{
lns::mapping_type type;
@ -811,6 +810,8 @@ private:
void set_lns_cache_record(const wallet2::lns_detail& detail);
void delete_lns_cache_record(std::string name);
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(); }