Skip to content

Commit

Permalink
Merge #2221: Implement LowerHex and UpperHex for CompactTarget
Browse files Browse the repository at this point in the history
58710df Implement LowerHex and UpperHex for CompactTarget (Vojtěch Toman)

Pull request description:

  closes #2219

ACKs for top commit:
  Kixunil:
    ACK 58710df
  apoelstra:
    ACK 58710df

Tree-SHA512: 38d8bd6573f0f033f5f0948062174f7a49db02d788a5176375a869633984451651bc738cd0588d5c6e4515f521257899bdf9f61fd4be350d80a26a96f16b19b1
  • Loading branch information
apoelstra committed Nov 26, 2023
2 parents 65050db + 58710df commit cfa6768
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bitcoin/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// (high, low): u.0 contains the high bits, u.1 contains the low bits.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
Expand Down Expand Up @@ -1536,6 +1546,12 @@ mod tests {
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]
fn target_from_compact() {
// (nBits, target)
Expand Down

0 comments on commit cfa6768

Please sign in to comment.