diff --git a/src/rlp/rlpin.rs b/src/rlp/rlpin.rs index 2179643d1..821511405 100644 --- a/src/rlp/rlpin.rs +++ b/src/rlp/rlpin.rs @@ -133,3 +133,12 @@ impl<'a, 'view> Iterator for RlpIterator<'a, 'view> { result } } + +#[test] +fn break_it() { + use common::*; + let h: Bytes = FromHex::from_hex("f84d0589010efbef67941f79b2a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap(); + let r: Rlp = Rlp::new(&h); + let u: U256 = r.val_at(1); + assert_eq!(format!("{}", u), "0x10efbef67941f79b2"); +} diff --git a/src/uint.rs b/src/uint.rs index 038c85458..2a18a2fb0 100644 --- a/src/uint.rs +++ b/src/uint.rs @@ -597,8 +597,15 @@ macro_rules! construct_uint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let &$name(ref data) = self; try!(write!(f, "0x")); + let mut latch = false; for ch in data.iter().rev() { - try!(write!(f, "{:02x}", ch)); + for x in 0..16 { + let ch = ch & (15u64 << ((15 - x) * 4) as u64) >> ((15 - x) * 4) as u64; + if !latch { latch = ch != 0 } + if latch { + try!(write!(f, "{:01x}", ch)); + } + } } Ok(()) } @@ -608,8 +615,15 @@ macro_rules! construct_uint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let &$name(ref data) = self; try!(write!(f, "0x")); + let mut latch = false; for ch in data.iter().rev() { - try!(write!(f, "{:02x}", ch)); + for x in 0..16 { + let nibble = (ch & (15u64 << ((15 - x) * 4) as u64)) >> (((15 - x) * 4) as u64); + if !latch { latch = nibble != 0 } + if latch { + try!(write!(f, "{:x}", nibble)); + } + } } Ok(()) }