From c8caee2b5e8efc1086bdb76e0ec0d1cf22a78e26 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 8 May 2024 09:39:02 +1000 Subject: [PATCH] Document CompactTarget order/equality Add documentation to the `CompactTarget` type explaining the nuance surrounding order/equality. Close: #2110 --- bitcoin/src/pow.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 8ef8a1a13..9c91fb115 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -337,6 +337,13 @@ do_impl!(Target); /// /// OpenSSL's bignum (BN) type has an encoding, which is even called "compact" as in bitcoin, which /// is exactly this format. +/// +/// # Note on order/equality +/// +/// Usage of the ordering and equality traits for this type may be surprising. Converting between +/// `CompactTarget` and `Target` is lossy *in both directions* (there are multiple `CompactTarget` +/// values that map to the same `Target` value). Ordering and equality for this type are defined in +/// terms of the underlying `u32`. #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]