diff --git a/bitcoin/src/blockdata/locktime/absolute.rs b/bitcoin/src/blockdata/locktime/absolute.rs index 40eac8f2..81cc8501 100644 --- a/bitcoin/src/blockdata/locktime/absolute.rs +++ b/bitcoin/src/blockdata/locktime/absolute.rs @@ -62,7 +62,6 @@ pub const LOCK_TIME_THRESHOLD: u32 = 500_000_000; /// ``` #[allow(clippy::derive_ord_xor_partial_ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -#[derive(Ord)] // will be removed in next commit pub enum LockTime { /// A block height lock time value. /// diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 3ef54483..71936945 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -16,7 +16,7 @@ use crate::prelude::*; use crate::io; use crate::string::FromHexStr; -use core::{fmt, str, default::Default}; +use core::{cmp, fmt, str, default::Default}; use core::convert::TryFrom; use bitcoin_internals::write_err; @@ -580,7 +580,7 @@ impl EncodeSigningDataResult { /// /// We therefore deviate from the spec by always using the Segwit witness encoding /// for 0-input transactions, which results in unambiguously parseable transactions. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Transaction { @@ -599,6 +599,20 @@ pub struct Transaction { pub output: Vec, } +impl cmp::PartialOrd for Transaction { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(&other)) + } +} +impl cmp::Ord for Transaction { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.version.cmp(&other.version) + .then(self.lock_time.to_consensus_u32().cmp(&other.lock_time.to_consensus_u32())) + .then(self.input.cmp(&other.input)) + .then(self.output.cmp(&other.output)) + } +} + impl Transaction { /// Computes a "normalized TXID" which does not include any signatures. ///