Skip to content

Commit d2d3270

Browse files
committed
getName requests to kns_indexer instead of net
1 parent ab7ad26 commit d2d3270

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/eth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
184184
/// Set the chain_id to determine which chain to call: requests will fail
185185
/// unless the node this process is running on has access to a provider
186186
/// for that chain.
187+
#[derive(Clone)]
187188
pub struct Provider {
188189
chain_id: u64,
189190
request_timeout: u64,

src/kimap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub fn namehash(name: &str) -> String {
5151
}
5252

5353
/// Helper struct for the Kimap.
54+
#[derive(Clone)]
5455
pub struct Kimap {
5556
pub provider: Provider,
5657
address: Address,

src/net.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum NetAction {
5959
/// get the [`Identity`] struct for a single peer
6060
GetPeer(String),
6161
/// get the [`NodeId`] associated with a given namehash, if any
62-
GetName(String),
62+
NamehashToName(NamehashToNameRequest),
6363
/// get a user-readable diagnostics string containing networking inforamtion
6464
GetDiagnostics,
6565
/// sign the attached blob payload, sign with our node's networking key.
@@ -99,6 +99,16 @@ pub enum NetResponse {
9999
Verified(bool),
100100
}
101101

102+
//
103+
// KNS parts of the networking protocol
104+
//
105+
106+
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
107+
pub struct NamehashToNameRequest {
108+
pub hash: String,
109+
pub block: Option<u64>,
110+
}
111+
102112
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
103113
pub struct KnsUpdate {
104114
pub name: String, // actual username / domain name
@@ -160,9 +170,19 @@ where
160170
}
161171

162172
/// get a kimap name from namehash
163-
pub fn get_name(namehash: &str, timeout: Option<u64>) -> anyhow::Result<String> {
164-
let res = Request::to(("our", "net", "distro", "sys"))
165-
.body(rmp_serde::to_vec(&NetAction::GetName(namehash.to_string())).unwrap())
173+
pub fn get_name(
174+
namehash: &str,
175+
block: Option<u64>,
176+
timeout: Option<u64>,
177+
) -> anyhow::Result<String> {
178+
let res = Request::to(("our", "kns_indexer", "kns_indexer", "sys"))
179+
.body(
180+
serde_json::to_vec(&NetAction::NamehashToName(NamehashToNameRequest {
181+
hash: namehash.to_string(),
182+
block: block,
183+
}))
184+
.unwrap(),
185+
)
166186
.send_and_await_response(timeout.unwrap_or(5))??;
167187

168188
let response = rmp_serde::from_slice::<NetResponse>(res.body())?;

0 commit comments

Comments
 (0)