Merge rust-bitcoin/rust-bitcoin#761: Taproot trivial post-merge fixups

7f06e91a93 LowerHex and UpperHex implementations for LeafVersion (Dr Maxim Orlovsky)
6a3f3aabaf Inverse alternative formatting for LeafVersion type (Dr Maxim Orlovsky)
bec6694233 Fix docs on error conditions in LeafVersion::from_consensus (Dr Maxim Orlovsky)
7c28b47451 LowerHex and UpperHex implementations for FutureLeafVersion (Dr Maxim Orlovsky)

Pull request description:

  Trivial post-merge fixups from review comments in #718

ACKs for top commit:
  Kixunil:
    ACK 7f06e91a93
  sanket1729:
    ACK 7f06e91a93

Tree-SHA512: d94c4bd3d0b466287c8965103f74ecaba185d14c13b6c3f37d9fbe194343b3fc902fd2c7716554ad01fe28ff89cda933df199b7e8388a3fa6097028caf62522b
This commit is contained in:
sanket1729 2022-01-10 04:17:38 +05:30
commit d82afc6ef5
No known key found for this signature in database
GPG Key ID: 648FFB183E0870A2
1 changed files with 30 additions and 6 deletions

View File

@ -98,7 +98,6 @@ sha256t_hash_newtype!(TapSighashHash, TapSighashTag, MIDSTATE_TAPSIGHASH, 64,
); );
impl TapTweakHash { impl TapTweakHash {
/// Create a new BIP341 [`TapTweakHash`] from key and tweak /// Create a new BIP341 [`TapTweakHash`] from key and tweak
/// Produces H_taptweak(P||R) where P is internal key and R is the merkle root /// Produces H_taptweak(P||R) where P is internal key and R is the merkle root
pub fn from_key_and_tweak( pub fn from_key_and_tweak(
@ -791,6 +790,20 @@ impl fmt::Display for FutureLeafVersion {
} }
} }
impl fmt::LowerHex for FutureLeafVersion {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::LowerHex::fmt(&self.0, f)
}
}
impl fmt::UpperHex for FutureLeafVersion {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::UpperHex::fmt(&self.0, f)
}
}
/// The leaf version for tapleafs /// The leaf version for tapleafs
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum LeafVersion { pub enum LeafVersion {
@ -807,7 +820,6 @@ impl LeafVersion {
/// # Errors /// # Errors
/// - If the last bit of the `version` is odd. /// - If the last bit of the `version` is odd.
/// - If the `version` is 0x50 ([`TAPROOT_ANNEX_PREFIX`]). /// - If the `version` is 0x50 ([`TAPROOT_ANNEX_PREFIX`]).
/// - If the `version` is not a valid [`LeafVersion`] byte.
// Text from BIP341: // Text from BIP341:
// In order to support some forms of static analysis that rely on // In order to support some forms of static analysis that rely on
// being able to identify script spends without access to the output being // being able to identify script spends without access to the output being
@ -837,14 +849,26 @@ impl LeafVersion {
impl fmt::Display for LeafVersion { impl fmt::Display for LeafVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match (self, f.alternate()) { match (self, f.alternate()) {
(LeafVersion::TapScript, false) => f.write_str("tapscript"), (LeafVersion::TapScript, true) => f.write_str("tapscript"),
(LeafVersion::TapScript, true) => fmt::Display::fmt(&TAPROOT_LEAF_TAPSCRIPT, f), (LeafVersion::TapScript, false) => fmt::Display::fmt(&TAPROOT_LEAF_TAPSCRIPT, f),
(LeafVersion::Future(version), false) => write!(f, "future_script_{:#02x}", version.0), (LeafVersion::Future(version), true) => write!(f, "future_script_{:#02x}", version.0),
(LeafVersion::Future(version), true) => fmt::Display::fmt(version, f), (LeafVersion::Future(version), false) => fmt::Display::fmt(version, f),
} }
} }
} }
impl fmt::LowerHex for LeafVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::LowerHex::fmt(&self.into_consensus(), f)
}
}
impl fmt::UpperHex for LeafVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::UpperHex::fmt(&self.into_consensus(), f)
}
}
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))] #[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl ::serde::Serialize for LeafVersion { impl ::serde::Serialize for LeafVersion {