Merge rust-bitcoin/rust-bitcoin#2897: psbt: implement `const` for `PsbtSighashType::ALL`
2bde5d002e
api: Run just check-api (Jose Storopoli)d1f84329e4
psbt: implement const for PsbtSighashType::ALL (Jose Storopoli) Pull request description: Closes #2751. I only did the `ALL` which is by far the most common case. ACKs for top commit: tcharding: ACK2bde5d002e
apoelstra: ACK2bde5d002e
Tree-SHA512: 693575de758657a3e172d86ba5114ec0bf3b12b82df598e38c6a7916c99c20cfb5c4e74442108b51ae4e7bb1f1e940fd4a7269145e3f9838f727675c7711c890
This commit is contained in:
commit
40d1335f08
|
@ -6350,6 +6350,7 @@ pub const bitcoin::pow::Target::MAX_ATTAINABLE_SIGNET: Self
|
||||||
pub const bitcoin::pow::Target::MAX_ATTAINABLE_TESTNET: Self
|
pub const bitcoin::pow::Target::MAX_ATTAINABLE_TESTNET: Self
|
||||||
pub const bitcoin::pow::Target::ZERO: bitcoin::pow::Target
|
pub const bitcoin::pow::Target::ZERO: bitcoin::pow::Target
|
||||||
pub const bitcoin::psbt::Psbt::DEFAULT_MAX_FEE_RATE: bitcoin_units::fee_rate::FeeRate
|
pub const bitcoin::psbt::Psbt::DEFAULT_MAX_FEE_RATE: bitcoin_units::fee_rate::FeeRate
|
||||||
|
pub const bitcoin::psbt::PsbtSighashType::ALL: bitcoin::psbt::PsbtSighashType
|
||||||
pub const bitcoin::script::witness_program::MAX_SIZE: usize = 40usize
|
pub const bitcoin::script::witness_program::MAX_SIZE: usize = 40usize
|
||||||
pub const bitcoin::script::witness_program::MIN_SIZE: usize = 2usize
|
pub const bitcoin::script::witness_program::MIN_SIZE: usize = 2usize
|
||||||
pub const bitcoin::sign_message::BITCOIN_SIGNED_MSG_PREFIX: &[u8]
|
pub const bitcoin::sign_message::BITCOIN_SIGNED_MSG_PREFIX: &[u8]
|
||||||
|
|
|
@ -6052,6 +6052,7 @@ pub const bitcoin::pow::Target::MAX_ATTAINABLE_SIGNET: Self
|
||||||
pub const bitcoin::pow::Target::MAX_ATTAINABLE_TESTNET: Self
|
pub const bitcoin::pow::Target::MAX_ATTAINABLE_TESTNET: Self
|
||||||
pub const bitcoin::pow::Target::ZERO: bitcoin::pow::Target
|
pub const bitcoin::pow::Target::ZERO: bitcoin::pow::Target
|
||||||
pub const bitcoin::psbt::Psbt::DEFAULT_MAX_FEE_RATE: bitcoin_units::fee_rate::FeeRate
|
pub const bitcoin::psbt::Psbt::DEFAULT_MAX_FEE_RATE: bitcoin_units::fee_rate::FeeRate
|
||||||
|
pub const bitcoin::psbt::PsbtSighashType::ALL: bitcoin::psbt::PsbtSighashType
|
||||||
pub const bitcoin::script::witness_program::MAX_SIZE: usize = 40usize
|
pub const bitcoin::script::witness_program::MAX_SIZE: usize = 40usize
|
||||||
pub const bitcoin::script::witness_program::MIN_SIZE: usize = 2usize
|
pub const bitcoin::script::witness_program::MIN_SIZE: usize = 2usize
|
||||||
pub const bitcoin::sign_message::BITCOIN_SIGNED_MSG_PREFIX: &[u8]
|
pub const bitcoin::sign_message::BITCOIN_SIGNED_MSG_PREFIX: &[u8]
|
||||||
|
|
|
@ -5433,6 +5433,7 @@ pub const bitcoin::pow::Target::MAX_ATTAINABLE_SIGNET: Self
|
||||||
pub const bitcoin::pow::Target::MAX_ATTAINABLE_TESTNET: Self
|
pub const bitcoin::pow::Target::MAX_ATTAINABLE_TESTNET: Self
|
||||||
pub const bitcoin::pow::Target::ZERO: bitcoin::pow::Target
|
pub const bitcoin::pow::Target::ZERO: bitcoin::pow::Target
|
||||||
pub const bitcoin::psbt::Psbt::DEFAULT_MAX_FEE_RATE: bitcoin_units::fee_rate::FeeRate
|
pub const bitcoin::psbt::Psbt::DEFAULT_MAX_FEE_RATE: bitcoin_units::fee_rate::FeeRate
|
||||||
|
pub const bitcoin::psbt::PsbtSighashType::ALL: bitcoin::psbt::PsbtSighashType
|
||||||
pub const bitcoin::script::witness_program::MAX_SIZE: usize = 40usize
|
pub const bitcoin::script::witness_program::MAX_SIZE: usize = 40usize
|
||||||
pub const bitcoin::script::witness_program::MIN_SIZE: usize = 2usize
|
pub const bitcoin::script::witness_program::MIN_SIZE: usize = 2usize
|
||||||
pub const bitcoin::sign_message::BITCOIN_SIGNED_MSG_PREFIX: &[u8]
|
pub const bitcoin::sign_message::BITCOIN_SIGNED_MSG_PREFIX: &[u8]
|
||||||
|
|
|
@ -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