From 739660499b0b417a438864f3e78a3ad7117f20f8 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 19 Jun 2021 11:25:06 +0200 Subject: [PATCH] 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 --- src/key.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/key.rs b/src/key.rs index 4eec0f6..7bf5997 100644 --- a/src/key.rs +++ b/src/key.rs @@ -673,13 +673,16 @@ impl<'de> serde::Deserialize<'de> for PublicKey { impl PartialOrd for PublicKey { fn partial_cmp(&self, other: &PublicKey) -> Option { - 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) } }