Skip to content

Commit 8a26283

Browse files
committed
Merge #68: Impl PartialOrd, Ord for 3 types
1e64777 Impl PartialOrd, Ord for 3 types (Riccardo Casatta) Pull request description: RangeProof, SurjectionProof and PedersenCommitment The purpose of this is having downstream types like elements::Transaction be usable in ordered collections. bitcoin::Transaction already support this for the same reason ACKs for top commit: apoelstra: ACK 1e64777 Tree-SHA512: b523ce6f85a255d9c7f8881171fb68ac9e1e21c2ae1429183a469f2fb3379f883cc756e3847c6e489a09ea4bd7fa5eaf7c493c8934c66a71dc319804b8c99847
2 parents 9282b10 + 1e64777 commit 8a26283

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

secp256k1-zkp-sys/src/zkp.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,26 @@ impl PartialEq for SurjectionProof {
426426

427427
impl Eq for SurjectionProof {}
428428

429+
impl Ord for SurjectionProof {
430+
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
431+
match self.n_inputs.cmp(&other.n_inputs) {
432+
core::cmp::Ordering::Equal => {}
433+
ord => return ord,
434+
}
435+
match self.used_inputs.cmp(&other.used_inputs) {
436+
core::cmp::Ordering::Equal => {}
437+
ord => return ord,
438+
}
439+
self.data.cmp(&other.data)
440+
}
441+
}
442+
443+
impl PartialOrd for SurjectionProof {
444+
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
445+
Some(self.cmp(other))
446+
}
447+
}
448+
429449
impl Default for SurjectionProof {
430450
fn default() -> Self {
431451
SurjectionProof::new()
@@ -454,7 +474,7 @@ impl SurjectionProof {
454474

455475
#[cfg(feature = "std")]
456476
#[repr(C)]
457-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
477+
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
458478
pub struct RangeProof(Box<[c_uchar]>);
459479

460480
#[cfg(feature = "std")]
@@ -513,7 +533,7 @@ impl From<Tag> for [u8; 32] {
513533

514534
// TODO: Replace this with ffi::PublicKey?
515535
#[repr(C)]
516-
#[derive(Copy, Clone)]
536+
#[derive(Copy, Clone, PartialOrd, Ord)]
517537
pub struct PedersenCommitment([c_uchar; 64]);
518538
impl_array_newtype!(PedersenCommitment, c_uchar, 64);
519539
impl_raw_debug!(PedersenCommitment);

src/zkp/pedersen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{from_hex, Error, Generator, Secp256k1, Signing, Tweak, ZERO_TWEAK};
55
use core::{fmt, slice, str};
66

77
/// Represents a commitment to a single u64 value.
8-
#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)]
8+
#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash, PartialOrd, Ord)]
99
pub struct PedersenCommitment(ffi::PedersenCommitment);
1010

1111
impl PedersenCommitment {

src/zkp/rangeproof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::str;
1313
/// Represents a range proof.
1414
///
1515
/// TODO: Store rangeproof info
16-
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
16+
#[derive(Debug, PartialEq, Clone, Eq, Hash, PartialOrd, Ord)]
1717
pub struct RangeProof {
1818
inner: ffi::RangeProof,
1919
}

src/zkp/surjection_proof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::mem::size_of;
66
use std::str;
77

88
/// Represents a surjection proof.
9-
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
9+
#[derive(Debug, PartialEq, Clone, Eq, Hash, PartialOrd, Ord)]
1010
pub struct SurjectionProof {
1111
inner: ffi::SurjectionProof,
1212
}

0 commit comments

Comments
 (0)