Merge rust-bitcoin/rust-bitcoin#2221: Implement LowerHex and UpperHex for CompactTarget
58710dfb91
Implement LowerHex and UpperHex for CompactTarget (Vojtěch Toman) Pull request description: closes #2219 ACKs for top commit: Kixunil: ACK58710dfb91
apoelstra: ACK58710dfb91
Tree-SHA512: 38d8bd6573f0f033f5f0948062174f7a49db02d788a5176375a869633984451651bc738cd0588d5c6e4515f521257899bdf9f61fd4be350d80a26a96f16b19b1
This commit is contained in:
commit
cfa6768e79
|
@ -306,6 +306,16 @@ impl Decodable for CompactTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LowerHex for CompactTarget {
|
||||||
|
#[inline]
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { LowerHex::fmt(&self.0, f) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UpperHex for CompactTarget {
|
||||||
|
#[inline]
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { UpperHex::fmt(&self.0, f) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Big-endian 256 bit integer type.
|
/// Big-endian 256 bit integer type.
|
||||||
// (high, low): u.0 contains the high bits, u.1 contains the low bits.
|
// (high, low): u.0 contains the high bits, u.1 contains the low bits.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
|
@ -1536,6 +1546,12 @@ mod tests {
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compact_target_lower_hex_and_upper_hex() {
|
||||||
|
assert_eq!(format!("{:08x}", CompactTarget(0x01D0F456)), "01d0f456");
|
||||||
|
assert_eq!(format!("{:08X}", CompactTarget(0x01d0f456)), "01D0F456");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn target_from_compact() {
|
fn target_from_compact() {
|
||||||
// (nBits, target)
|
// (nBits, target)
|
||||||
|
|
Loading…
Reference in New Issue