Deserialize Bitcoin-encoded IP addresses.

This commit is contained in:
Henry de Valence 2019-09-14 09:31:45 -07:00
parent 661c4bd7a6
commit b1431c1cac
1 changed files with 11 additions and 2 deletions

View File

@ -186,11 +186,20 @@ impl ZcashSerialization for std::net::IpAddr {
/// Try to read `self` from the given `reader`.
fn try_read<R: io::Read>(
_reader: R,
mut reader: R,
_magic: Magic,
_version: Version,
) -> Result<Self, SerializationError> {
unimplemented!()
use std::net::{IpAddr::*, Ipv6Addr};
let mut octets = [0u8; 16];
reader.read_exact(&mut octets)?;
let v6_addr = std::net::Ipv6Addr::from(octets);
match v6_addr.to_ipv4() {
Some(v4_addr) => Ok(V4(v4_addr)),
None => Ok(V6(v6_addr)),
}
}
}