Skip to content

Commit d82afc6

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#761: Taproot trivial post-merge fixups
7f06e91 LowerHex and UpperHex implementations for LeafVersion (Dr Maxim Orlovsky) 6a3f3aa Inverse alternative formatting for LeafVersion type (Dr Maxim Orlovsky) bec6694 Fix docs on error conditions in LeafVersion::from_consensus (Dr Maxim Orlovsky) 7c28b47 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 7f06e91 sanket1729: ACK 7f06e91 Tree-SHA512: d94c4bd3d0b466287c8965103f74ecaba185d14c13b6c3f37d9fbe194343b3fc902fd2c7716554ad01fe28ff89cda933df199b7e8388a3fa6097028caf62522b
2 parents 476eed7 + 7f06e91 commit d82afc6

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/util/taproot.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ sha256t_hash_newtype!(TapSighashHash, TapSighashTag, MIDSTATE_TAPSIGHASH, 64,
9898
);
9999

100100
impl TapTweakHash {
101-
102101
/// Create a new BIP341 [`TapTweakHash`] from key and tweak
103102
/// Produces H_taptweak(P||R) where P is internal key and R is the merkle root
104103
pub fn from_key_and_tweak(
@@ -791,6 +790,20 @@ impl fmt::Display for FutureLeafVersion {
791790
}
792791
}
793792

793+
impl fmt::LowerHex for FutureLeafVersion {
794+
#[inline]
795+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
796+
fmt::LowerHex::fmt(&self.0, f)
797+
}
798+
}
799+
800+
impl fmt::UpperHex for FutureLeafVersion {
801+
#[inline]
802+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
803+
fmt::UpperHex::fmt(&self.0, f)
804+
}
805+
}
806+
794807
/// The leaf version for tapleafs
795808
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
796809
pub enum LeafVersion {
@@ -807,7 +820,6 @@ impl LeafVersion {
807820
/// # Errors
808821
/// - If the last bit of the `version` is odd.
809822
/// - If the `version` is 0x50 ([`TAPROOT_ANNEX_PREFIX`]).
810-
/// - If the `version` is not a valid [`LeafVersion`] byte.
811823
// Text from BIP341:
812824
// In order to support some forms of static analysis that rely on
813825
// being able to identify script spends without access to the output being
@@ -837,14 +849,26 @@ impl LeafVersion {
837849
impl fmt::Display for LeafVersion {
838850
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
839851
match (self, f.alternate()) {
840-
(LeafVersion::TapScript, false) => f.write_str("tapscript"),
841-
(LeafVersion::TapScript, true) => fmt::Display::fmt(&TAPROOT_LEAF_TAPSCRIPT, f),
842-
(LeafVersion::Future(version), false) => write!(f, "future_script_{:#02x}", version.0),
843-
(LeafVersion::Future(version), true) => fmt::Display::fmt(version, f),
852+
(LeafVersion::TapScript, true) => f.write_str("tapscript"),
853+
(LeafVersion::TapScript, false) => fmt::Display::fmt(&TAPROOT_LEAF_TAPSCRIPT, f),
854+
(LeafVersion::Future(version), true) => write!(f, "future_script_{:#02x}", version.0),
855+
(LeafVersion::Future(version), false) => fmt::Display::fmt(version, f),
844856
}
845857
}
846858
}
847859

860+
impl fmt::LowerHex for LeafVersion {
861+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
862+
fmt::LowerHex::fmt(&self.into_consensus(), f)
863+
}
864+
}
865+
866+
impl fmt::UpperHex for LeafVersion {
867+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
868+
fmt::UpperHex::fmt(&self.into_consensus(), f)
869+
}
870+
}
871+
848872
#[cfg(feature = "serde")]
849873
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
850874
impl ::serde::Serialize for LeafVersion {

0 commit comments

Comments
 (0)