psbt: implement const for PsbtSighashType::ALL
This commit is contained in:
parent
09740853a9
commit
d1f84329e4
|
@ -197,6 +197,22 @@ impl From<TapSighashType> for PsbtSighashType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PsbtSighashType {
|
impl PsbtSighashType {
|
||||||
|
/// Ambiguous `ALL` sighash type, may refer to either [`EcdsaSighashType::All`]
|
||||||
|
/// or [`TapSighashType::All`].
|
||||||
|
///
|
||||||
|
/// This is equivalent to either `EcdsaSighashType::All.into()` or `TapSighashType::All.into()`.
|
||||||
|
/// For sighash types other than `ALL` use the ECDSA or Taproot sighash type directly.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use bitcoin::{EcdsaSighashType, TapSighashType};
|
||||||
|
/// use bitcoin::psbt::PsbtSighashType;
|
||||||
|
/// let ecdsa_sighash_anyone_can_pay: PsbtSighashType = EcdsaSighashType::AllPlusAnyoneCanPay.into();
|
||||||
|
/// let tap_sighash_anyone_can_pay: PsbtSighashType = TapSighashType::AllPlusAnyoneCanPay.into();
|
||||||
|
/// ```
|
||||||
|
pub const ALL: PsbtSighashType = PsbtSighashType { inner: 0x01 };
|
||||||
|
|
||||||
/// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be
|
/// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be
|
||||||
/// converted to one.
|
/// converted to one.
|
||||||
pub fn ecdsa_hash_ty(self) -> Result<EcdsaSighashType, NonStandardSighashTypeError> {
|
pub fn ecdsa_hash_ty(self) -> Result<EcdsaSighashType, NonStandardSighashTypeError> {
|
||||||
|
@ -545,4 +561,11 @@ mod test {
|
||||||
assert_eq!(back.ecdsa_hash_ty(), Err(NonStandardSighashTypeError(nonstd)));
|
assert_eq!(back.ecdsa_hash_ty(), Err(NonStandardSighashTypeError(nonstd)));
|
||||||
assert_eq!(back.taproot_hash_ty(), Err(InvalidSighashTypeError(nonstd)));
|
assert_eq!(back.taproot_hash_ty(), Err(InvalidSighashTypeError(nonstd)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn psbt_sighash_const_all() {
|
||||||
|
assert_eq!(PsbtSighashType::ALL.to_u32(), 0x01);
|
||||||
|
assert_eq!(PsbtSighashType::ALL.ecdsa_hash_ty().unwrap(), EcdsaSighashType::All);
|
||||||
|
assert_eq!(PsbtSighashType::ALL.taproot_hash_ty().unwrap(), TapSighashType::All);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue