Skip to content

Commit

Permalink
Display onion v2 in bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Oct 18, 2023
1 parent da5cb29 commit e7cf3a5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,9 @@ pub fn parse_onion_address(host: &str, port: u16) -> Result<SocketAddress, Socke
}
}

/// [`SocketAddress::OnionV2`] to onion address string
/// [`SocketAddress::OnionV2`] to debug represent
pub fn to_onion_v2_string(bytes: &[u8; 12]) -> String {
let onion = base32::Alphabet::RFC4648 { padding: false }.encode(&bytes[..10]);
let port = u16::from_be_bytes([bytes[10], bytes[11]]);
format!("{}.onion:{}", onion, port)
format!("OnionV2({:?})", bytes)
}

/// [`SocketAddress::OnionV3`] to onion address string
Expand Down Expand Up @@ -4123,7 +4121,7 @@ mod tests {
assert_eq!(hostname, SocketAddress::from_str(&hostname.to_string()).unwrap());

let onion_v2 = SocketAddress::OnionV2 ([40, 4, 64, 185, 202, 19, 162, 75, 90, 200, 38, 7],);
assert_eq!("FACEBOOKCOREWWWI.onion:9735", &onion_v2.to_string());
assert_eq!("OnionV2([40, 4, 64, 185, 202, 19, 162, 75, 90, 200, 38, 7])", &onion_v2.to_string());
assert_eq!(Err(SocketAddressParseError::InvalidOnionV3), SocketAddress::from_str("FACEBOOKCOREWWWI.onion:9735"));

let onion_v3 = SocketAddress::OnionV3 {
Expand Down

0 comments on commit e7cf3a5

Please sign in to comment.