Skip to content

Commit

Permalink
consensus: implement Display for sighash types
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 16, 2024
1 parent 4bad1a1 commit 7da1d90
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion consensus/src/sigtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt::{self, Display, Formatter};
use std::iter;

use amplify::{ByteArray, Bytes32, Wrapper};
Expand All @@ -27,14 +28,15 @@ use secp256k1::{ecdsa, schnorr};

use crate::{NonStandardValue, ScriptBytes, ScriptPubkey, WitnessScript, LIB_NAME_BITCOIN};

#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Default)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Display, Default)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BITCOIN, tags = repr, into_u8, try_from_u8)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
#[display(uppercase)]
#[repr(u8)]
pub enum SighashFlag {
/// 0x1: Sign all outputs.
Expand Down Expand Up @@ -184,6 +186,16 @@ impl SighashType {
}
}

impl Display for SighashType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.flag, f)?;
if self.anyone_can_pay {
f.write_str(" | ANYONECANPAY")?;
}
Ok(())
}
}

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Index, RangeOps, AsSlice, BorrowSlice, Hex, Display, FromStr)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
Expand Down

0 comments on commit 7da1d90

Please sign in to comment.