Implement PublicKey ordering using FFI
Instead of selializing the key we can call down to the ffi layer to do ordering. Co-authored-by: Tobin C. Harding <me@tobin.cc>
This commit is contained in:
parent
0faf404f0e
commit
739660499b
|
@ -673,13 +673,16 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
|
||||||
|
|
||||||
impl PartialOrd for PublicKey {
|
impl PartialOrd for PublicKey {
|
||||||
fn partial_cmp(&self, other: &PublicKey) -> Option<core::cmp::Ordering> {
|
fn partial_cmp(&self, other: &PublicKey) -> Option<core::cmp::Ordering> {
|
||||||
self.serialize().partial_cmp(&other.serialize())
|
Some(self.cmp(other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for PublicKey {
|
impl Ord for PublicKey {
|
||||||
fn cmp(&self, other: &PublicKey) -> core::cmp::Ordering {
|
fn cmp(&self, other: &PublicKey) -> core::cmp::Ordering {
|
||||||
self.serialize().cmp(&other.serialize())
|
let ret = unsafe {
|
||||||
|
ffi::secp256k1_ec_pubkey_cmp(ffi::secp256k1_context_no_precomp, self.as_c_ptr(), other.as_c_ptr())
|
||||||
|
};
|
||||||
|
ret.cmp(&0i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue