mirror of https://github.com/oxen-io/oxen-core.git
Merge pull request #1328 from jagerman/wallet-rpc-lns-caching
Add wallet rpc endpoint to record a known name
This commit is contained in:
commit
c6a4f3e1c8
|
@ -12981,12 +12981,12 @@ uint64_t wallet2::get_approximate_blockchain_height() const
|
|||
return approx_blockchain_height;
|
||||
}
|
||||
|
||||
void wallet2::set_lns_cache_record(const wallet2::lns_detail& detail)
|
||||
void wallet2::set_lns_cache_record(wallet2::lns_detail detail)
|
||||
{
|
||||
lns_records_cache[detail.hashed_name] = detail;
|
||||
lns_records_cache[detail.hashed_name] = std::move(detail);
|
||||
}
|
||||
|
||||
void wallet2::delete_lns_cache_record(std::string hashed_name)
|
||||
void wallet2::delete_lns_cache_record(const std::string& hashed_name)
|
||||
{
|
||||
lns_records_cache.erase(hashed_name);
|
||||
}
|
||||
|
|
|
@ -805,9 +805,9 @@ private:
|
|||
};
|
||||
std::unordered_map<std::string, lns_detail> lns_records_cache;
|
||||
|
||||
void set_lns_cache_record(const wallet2::lns_detail& detail);
|
||||
void set_lns_cache_record(wallet2::lns_detail detail);
|
||||
|
||||
void delete_lns_cache_record(std::string name);
|
||||
void delete_lns_cache_record(const std::string& name);
|
||||
|
||||
std::unordered_map<std::string, lns_detail> get_lns_cache();
|
||||
|
||||
|
|
|
@ -3326,6 +3326,30 @@ namespace {
|
|||
return res;
|
||||
}
|
||||
|
||||
LNS_ADD_KNOWN_NAMES::response wallet_rpc_server::invoke(LNS_ADD_KNOWN_NAMES::request&& req)
|
||||
{
|
||||
require_open();
|
||||
|
||||
std::optional<uint8_t> hf_version = m_wallet->get_hard_fork_version();
|
||||
if (!hf_version) throw wallet_rpc_error{error_code::HF_QUERY_FAILED, tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED};
|
||||
|
||||
std::string reason;
|
||||
for (auto& rec : req.names)
|
||||
{
|
||||
lns::mapping_type type;
|
||||
if (!lns::validate_mapping_type(rec.type, *hf_version, lns::lns_tx_type::lookup, &type, &reason))
|
||||
throw wallet_rpc_error{error_code::WRONG_LNS_TYPE, "Invalid LNS type: " + reason};
|
||||
|
||||
auto name = tools::lowercase_ascii_string(rec.name);
|
||||
if (!lns::validate_lns_name(type, name, &reason))
|
||||
throw wallet_rpc_error{error_code::LNS_BAD_NAME, "Invalid LNS name '" + name + "': " + reason};
|
||||
|
||||
m_wallet->set_lns_cache_record({type, name, lns::name_to_base64_hash(name)});
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
LNS_DECRYPT_VALUE::response wallet_rpc_server::invoke(LNS_DECRYPT_VALUE::request&& req)
|
||||
{
|
||||
require_open();
|
||||
|
|
|
@ -162,6 +162,7 @@ namespace tools
|
|||
wallet_rpc::LNS_MAKE_UPDATE_SIGNATURE::response invoke(wallet_rpc::LNS_MAKE_UPDATE_SIGNATURE::request&& req);
|
||||
wallet_rpc::LNS_HASH_NAME::response invoke(wallet_rpc::LNS_HASH_NAME::request&& req);
|
||||
wallet_rpc::LNS_KNOWN_NAMES::response invoke(wallet_rpc::LNS_KNOWN_NAMES::request&& req);
|
||||
wallet_rpc::LNS_ADD_KNOWN_NAMES::response invoke(wallet_rpc::LNS_ADD_KNOWN_NAMES::request&& req);
|
||||
wallet_rpc::LNS_DECRYPT_VALUE::response invoke(wallet_rpc::LNS_DECRYPT_VALUE::request&& req);
|
||||
wallet_rpc::LNS_ENCRYPT_VALUE::response invoke(wallet_rpc::LNS_ENCRYPT_VALUE::request&& req);
|
||||
wallet_rpc::QUERY_KEY::response invoke(wallet_rpc::QUERY_KEY::request&& req);
|
||||
|
|
|
@ -1235,6 +1235,17 @@ KV_SERIALIZE_MAP_CODE_BEGIN(LNS_KNOWN_NAMES::response)
|
|||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(LNS_ADD_KNOWN_NAMES::request)
|
||||
KV_SERIALIZE(names)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(LNS_ADD_KNOWN_NAMES::record)
|
||||
KV_SERIALIZE(type)
|
||||
KV_SERIALIZE(name)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(LNS_DECRYPT_VALUE::request)
|
||||
KV_SERIALIZE(name);
|
||||
KV_SERIALIZE(type);
|
||||
|
|
|
@ -2399,6 +2399,31 @@ This command is only required if the open wallet is one of the owners of a LNS r
|
|||
};
|
||||
};
|
||||
|
||||
LOKI_RPC_DOC_INTROSPECT
|
||||
// Adds one or more names to the persistent LNS wallet cache of known names (i.e. for names that
|
||||
// are owned by this wallet that aren't currently in the cache).
|
||||
struct LNS_ADD_KNOWN_NAMES : RPC_COMMAND
|
||||
{
|
||||
static constexpr auto names() { return NAMES("lns_add_known_names"); }
|
||||
|
||||
struct record
|
||||
{
|
||||
std::string type; // The LNS type (mandatory); currently support values are: "session", "lokinet"
|
||||
std::string name; // The (unhashed) name of the record
|
||||
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
struct request
|
||||
{
|
||||
std::vector<record> names; // List of names to add to the cache
|
||||
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
using response = EMPTY;
|
||||
};
|
||||
|
||||
LOKI_RPC_DOC_INTROSPECT
|
||||
// Takes a LNS encrypted value and encrypts the mapping value using the LNS name.
|
||||
struct LNS_ENCRYPT_VALUE : RPC_COMMAND
|
||||
|
@ -2545,6 +2570,7 @@ This command is only required if the open wallet is one of the owners of a LNS r
|
|||
LNS_MAKE_UPDATE_SIGNATURE,
|
||||
LNS_HASH_NAME,
|
||||
LNS_KNOWN_NAMES,
|
||||
LNS_ADD_KNOWN_NAMES,
|
||||
LNS_DECRYPT_VALUE,
|
||||
LNS_ENCRYPT_VALUE
|
||||
>;
|
||||
|
|
Loading…
Reference in New Issue