Fixed Uint output.
This commit is contained in:
parent
5c945ebd42
commit
5520497e81
@ -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");
|
||||
}
|
||||
|
18
src/uint.rs
18
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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user