Skip to content

Commit cfa6768

Browse files
committed
Merge rust-bitcoin#2221: Implement LowerHex and UpperHex for CompactTarget
58710df Implement LowerHex and UpperHex for CompactTarget (Vojtěch Toman) Pull request description: closes rust-bitcoin#2219 ACKs for top commit: Kixunil: ACK 58710df apoelstra: ACK 58710df Tree-SHA512: 38d8bd6573f0f033f5f0948062174f7a49db02d788a5176375a869633984451651bc738cd0588d5c6e4515f521257899bdf9f61fd4be350d80a26a96f16b19b1
2 parents 65050db + 58710df commit cfa6768

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

bitcoin/src/pow.rs

+16
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ impl Decodable for CompactTarget {
306306
}
307307
}
308308

309+
impl LowerHex for CompactTarget {
310+
#[inline]
311+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { LowerHex::fmt(&self.0, f) }
312+
}
313+
314+
impl UpperHex for CompactTarget {
315+
#[inline]
316+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { UpperHex::fmt(&self.0, f) }
317+
}
318+
309319
/// Big-endian 256 bit integer type.
310320
// (high, low): u.0 contains the high bits, u.1 contains the low bits.
311321
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
@@ -1536,6 +1546,12 @@ mod tests {
15361546
assert!(result.is_err());
15371547
}
15381548

1549+
#[test]
1550+
fn compact_target_lower_hex_and_upper_hex() {
1551+
assert_eq!(format!("{:08x}", CompactTarget(0x01D0F456)), "01d0f456");
1552+
assert_eq!(format!("{:08X}", CompactTarget(0x01d0f456)), "01D0F456");
1553+
}
1554+
15391555
#[test]
15401556
fn target_from_compact() {
15411557
// (nBits, target)

0 commit comments

Comments
 (0)