Skip to content

Commit

Permalink
Merge rust-bitcoin#361: Add basic derives for Parity
Browse files Browse the repository at this point in the history
1671dfc Release 0.21.2 (sanket1729)
837be22 Basic derives for Parity (sanket1729)
7059192 Wildcard export from key module (sanket1729)

Pull request description:

  Sorry for getting another point release. This time I have tested against this branch for rust-bitcoin rust-bitcoin/rust-bitcoin#755. Hopefully, this is the last release.

  Next release, we should have a Release Candidate for a couple of days before publishing a release.

ACKs for top commit:
  apoelstra:
    ACK 1671dfc

Tree-SHA512: 263ad027da3da764bd76f719200382c47ba21a976caefc23ebef45d1c4be35ddfc80ce619b57326310aaab22bbf75ca7f1db80b45e95ec076584805efb791f3f
  • Loading branch information
apoelstra committed Jan 6, 2022
2 parents 74e8fc7 + 1671dfc commit 6911734
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256k1"
version = "0.21.1"
version = "0.21.2"
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
"Andrew Poelstra <[email protected]>" ]
license = "CC0-1.0"
Expand Down
34 changes: 34 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ impl XOnlyPublicKey {
}

/// Opaque type used to hold the parity passed between FFI function calls.
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
pub struct Parity(i32);

impl From<i32> for Parity {
Expand All @@ -924,6 +925,39 @@ impl From<Parity> for i32 {
}
}

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl ::serde::Serialize for Parity {
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_i32(self.0)
}
}

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> ::serde::Deserialize<'de> for Parity {
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
struct I32Visitor;

impl<'de> ::serde::de::Visitor<'de> for I32Visitor
{
type Value = Parity;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("Expecting a 4 byte int i32")
}

fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>
where E: ::serde::de::Error
{
Ok(Parity::from(v))
}
}

d.deserialize_i32(I32Visitor)
}
}

impl CPtr for XOnlyPublicKey {
type Target = ffi::XOnlyPublicKey;
fn as_c_ptr(&self) -> *const Self::Target {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub mod schnorr;
#[cfg(feature = "serde")]
mod serde_util;

pub use key::{SecretKey, PublicKey, ONE_KEY, KeyPair, XOnlyPublicKey, Parity};
pub use key::*;
pub use context::*;
use core::marker::PhantomData;
use core::{mem, fmt, str};
Expand Down

0 comments on commit 6911734

Please sign in to comment.