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:
Dr Maxim Orlovsky 2021-06-19 11:25:06 +02:00 committed by Tobin C. Harding
parent 0faf404f0e
commit 739660499b
1 changed files with 5 additions and 2 deletions

View File

@ -673,13 +673,16 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
impl PartialOrd for PublicKey {
fn partial_cmp(&self, other: &PublicKey) -> Option<core::cmp::Ordering> {
self.serialize().partial_cmp(&other.serialize())
Some(self.cmp(other))
}
}
impl Ord for PublicKey {
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)
}
}