File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,26 @@ where
157
157
} )
158
158
}
159
159
160
+ /// get a kimap name from namehash
161
+ pub fn get_name ( namehash : & str , timeout : Option < u64 > ) -> anyhow:: Result < String > {
162
+ let res = Request :: to ( ( "our" , "net" , "distro" , "sys" ) )
163
+ . body ( rmp_serde:: to_vec ( & NetAction :: GetName ( namehash. to_string ( ) ) ) . unwrap ( ) )
164
+ . send_and_await_response ( timeout. unwrap_or ( 5 ) ) ??;
165
+
166
+ let response = rmp_serde:: from_slice :: < NetResponse > ( res. body ( ) ) ?;
167
+ if let NetResponse :: Name ( name) = response {
168
+ // is returning an option optimal?
169
+ // getting an error for send/malformatted hash/not found seems better
170
+ if let Some ( name) = name {
171
+ return Ok ( name) ;
172
+ } else {
173
+ return Err ( anyhow:: anyhow!( "name not found" ) ) ;
174
+ }
175
+ } else {
176
+ Err ( anyhow:: anyhow!( "unexpected response: {:?}" , response) )
177
+ }
178
+ }
179
+
160
180
/// take a DNSwire-formatted node ID from chain and convert it to a String
161
181
pub fn dnswire_decode ( wire_format_bytes : & [ u8 ] ) -> Result < String , DnsDecodeError > {
162
182
let mut i = 0 ;
You can’t perform that action at this time.
0 commit comments