Skip to content

Commit

Permalink
seal: custom implementation for Ord on TxoSeal
Browse files Browse the repository at this point in the history
automatic derive requires dbc::Proof to be Ord, which is not always the case
  • Loading branch information
dr-orlovsky committed Dec 8, 2024
1 parent 14892a2 commit 5d8db23
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion seals/src/txout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)]

Check warning on line 161 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L161

Added line #L161 was not covered by tests
#[strict_type(lib = dbc::LIB_NAME_BPCORE)]
Expand All @@ -170,6 +171,15 @@ pub struct TxoSeal<D: dbc::Proof> {
_phantom: PhantomData<D>,
}

impl<D: dbc::Proof> PartialOrd for TxoSeal<D> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }

Check warning on line 175 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L175

Added line #L175 was not covered by tests
}
impl<D: dbc::Proof> Ord for TxoSeal<D> {
fn cmp(&self, other: &Self) -> Ordering {
self.primary.cmp(&other.primary).then(self.secondary.cmp(&other.secondary))
}

Check warning on line 180 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L178-L180

Added lines #L178 - L180 were not covered by tests
}

impl<D: dbc::Proof> SingleUseSeal for TxoSeal<D> {
type Message = Bytes32;
type PubWitness = Tx;
Expand Down

0 comments on commit 5d8db23

Please sign in to comment.