From 5d8db23ffa73417937230238d807310eb6052579 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 8 Dec 2024 23:09:02 +0100 Subject: [PATCH] seal: custom implementation for Ord on TxoSeal automatic derive requires dbc::Proof to be Ord, which is not always the case --- seals/src/txout.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/seals/src/txout.rs b/seals/src/txout.rs index abc3ef37..d87ee942 100644 --- a/seals/src/txout.rs +++ b/seals/src/txout.rs @@ -24,6 +24,7 @@ use core::fmt::Debug; use core::marker::PhantomData; +use std::cmp::Ordering; use amplify::confinement::TinyOrdMap; use amplify::{ByteArray, Bytes, Bytes32}; @@ -155,7 +156,7 @@ impl StrictDumb for TxoSealExt { fn strict_dumb() -> Self { TxoSealExt::Noise(Noise::from(Bytes::from_byte_array([0u8; 68]))) } } -#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Display)] #[display("{primary}/{secondary}")] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = dbc::LIB_NAME_BPCORE)] @@ -170,6 +171,15 @@ pub struct TxoSeal { _phantom: PhantomData, } +impl PartialOrd for TxoSeal { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } +} +impl Ord for TxoSeal { + fn cmp(&self, other: &Self) -> Ordering { + self.primary.cmp(&other.primary).then(self.secondary.cmp(&other.secondary)) + } +} + impl SingleUseSeal for TxoSeal { type Message = Bytes32; type PubWitness = Tx;