Skip to content

Commit 2dc851b

Browse files
committed
Use 4 character indentation
Bizarrely the impl block for `EcdsaSigHashType` uses 5 character indentation. Use 4 character indentation as is typical.
1 parent b136a4d commit 2dc851b

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

src/blockdata/transaction.rs

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -736,69 +736,69 @@ impl str::FromStr for EcdsaSigHashType {
736736
}
737737

738738
impl EcdsaSigHashType {
739-
/// Break the sighash flag into the "real" sighash flag and the ANYONECANPAY boolean
740-
pub(crate) fn split_anyonecanpay_flag(self) -> (EcdsaSigHashType, bool) {
741-
match self {
742-
EcdsaSigHashType::All => (EcdsaSigHashType::All, false),
743-
EcdsaSigHashType::None => (EcdsaSigHashType::None, false),
744-
EcdsaSigHashType::Single => (EcdsaSigHashType::Single, false),
745-
EcdsaSigHashType::AllPlusAnyoneCanPay => (EcdsaSigHashType::All, true),
746-
EcdsaSigHashType::NonePlusAnyoneCanPay => (EcdsaSigHashType::None, true),
747-
EcdsaSigHashType::SinglePlusAnyoneCanPay => (EcdsaSigHashType::Single, true)
748-
}
749-
}
750-
751-
/// Reads a 4-byte uint32 as a sighash type.
752-
#[deprecated(since="0.26.1", note="please use `from_u32_consensus` or `from_u32_standard` instead")]
753-
pub fn from_u32(n: u32) -> EcdsaSigHashType {
754-
Self::from_u32_consensus(n)
755-
}
756-
757-
/// Reads a 4-byte uint32 as a sighash type.
758-
///
759-
/// **Note**: this replicates consensus behaviour, for current standardness rules correctness
760-
/// you probably want [Self::from_u32_standard].
761-
/// This might cause unexpected behavior because it does not roundtrip. That is,
762-
/// `EcdsaSigHashType::from_u32_consensus(n) as u32 != n` for non-standard values of
763-
/// `n`. While verifying signatures, the user should retain the `n` and use it compute the
764-
/// signature hash message.
765-
pub fn from_u32_consensus(n: u32) -> EcdsaSigHashType {
766-
// In Bitcoin Core, the SignatureHash function will mask the (int32) value with
767-
// 0x1f to (apparently) deactivate ACP when checking for SINGLE and NONE bits.
768-
// We however want to be matching also against on ACP-masked ALL, SINGLE, and NONE.
769-
// So here we re-activate ACP.
770-
let mask = 0x1f | 0x80;
771-
match n & mask {
772-
// "real" sighashes
773-
0x01 => EcdsaSigHashType::All,
774-
0x02 => EcdsaSigHashType::None,
775-
0x03 => EcdsaSigHashType::Single,
776-
0x81 => EcdsaSigHashType::AllPlusAnyoneCanPay,
777-
0x82 => EcdsaSigHashType::NonePlusAnyoneCanPay,
778-
0x83 => EcdsaSigHashType::SinglePlusAnyoneCanPay,
779-
// catchalls
780-
x if x & 0x80 == 0x80 => EcdsaSigHashType::AllPlusAnyoneCanPay,
781-
_ => EcdsaSigHashType::All
782-
}
783-
}
784-
785-
/// Read a 4-byte uint32 as a standard sighash type, returning an error if the type
786-
/// is non standard.
787-
pub fn from_u32_standard(n: u32) -> Result<EcdsaSigHashType, NonStandardSigHashType> {
788-
match n {
789-
// Standard sighashes, see https://github.com/bitcoin/bitcoin/blob/b805dbb0b9c90dadef0424e5b3bf86ac308e103e/src/script/interpreter.cpp#L189-L198
790-
0x01 => Ok(EcdsaSigHashType::All),
791-
0x02 => Ok(EcdsaSigHashType::None),
792-
0x03 => Ok(EcdsaSigHashType::Single),
793-
0x81 => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay),
794-
0x82 => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay),
795-
0x83 => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay),
796-
non_standard => Err(NonStandardSigHashType(non_standard))
797-
}
798-
}
799-
800-
/// Converts to a u32
801-
pub fn as_u32(self) -> u32 { self as u32 }
739+
/// Break the sighash flag into the "real" sighash flag and the ANYONECANPAY boolean
740+
pub(crate) fn split_anyonecanpay_flag(self) -> (EcdsaSigHashType, bool) {
741+
match self {
742+
EcdsaSigHashType::All => (EcdsaSigHashType::All, false),
743+
EcdsaSigHashType::None => (EcdsaSigHashType::None, false),
744+
EcdsaSigHashType::Single => (EcdsaSigHashType::Single, false),
745+
EcdsaSigHashType::AllPlusAnyoneCanPay => (EcdsaSigHashType::All, true),
746+
EcdsaSigHashType::NonePlusAnyoneCanPay => (EcdsaSigHashType::None, true),
747+
EcdsaSigHashType::SinglePlusAnyoneCanPay => (EcdsaSigHashType::Single, true)
748+
}
749+
}
750+
751+
/// Reads a 4-byte uint32 as a sighash type.
752+
#[deprecated(since="0.26.1", note="please use `from_u32_consensus` or `from_u32_standard` instead")]
753+
pub fn from_u32(n: u32) -> EcdsaSigHashType {
754+
Self::from_u32_consensus(n)
755+
}
756+
757+
/// Reads a 4-byte uint32 as a sighash type.
758+
///
759+
/// **Note**: this replicates consensus behaviour, for current standardness rules correctness
760+
/// you probably want [Self::from_u32_standard].
761+
/// This might cause unexpected behavior because it does not roundtrip. That is,
762+
/// `EcdsaSigHashType::from_u32_consensus(n) as u32 != n` for non-standard values of
763+
/// `n`. While verifying signatures, the user should retain the `n` and use it compute the
764+
/// signature hash message.
765+
pub fn from_u32_consensus(n: u32) -> EcdsaSigHashType {
766+
// In Bitcoin Core, the SignatureHash function will mask the (int32) value with
767+
// 0x1f to (apparently) deactivate ACP when checking for SINGLE and NONE bits.
768+
// We however want to be matching also against on ACP-masked ALL, SINGLE, and NONE.
769+
// So here we re-activate ACP.
770+
let mask = 0x1f | 0x80;
771+
match n & mask {
772+
// "real" sighashes
773+
0x01 => EcdsaSigHashType::All,
774+
0x02 => EcdsaSigHashType::None,
775+
0x03 => EcdsaSigHashType::Single,
776+
0x81 => EcdsaSigHashType::AllPlusAnyoneCanPay,
777+
0x82 => EcdsaSigHashType::NonePlusAnyoneCanPay,
778+
0x83 => EcdsaSigHashType::SinglePlusAnyoneCanPay,
779+
// catchalls
780+
x if x & 0x80 == 0x80 => EcdsaSigHashType::AllPlusAnyoneCanPay,
781+
_ => EcdsaSigHashType::All
782+
}
783+
}
784+
785+
/// Read a 4-byte uint32 as a standard sighash type, returning an error if the type
786+
/// is non standard.
787+
pub fn from_u32_standard(n: u32) -> Result<EcdsaSigHashType, NonStandardSigHashType> {
788+
match n {
789+
// Standard sighashes, see https://github.com/bitcoin/bitcoin/blob/b805dbb0b9c90dadef0424e5b3bf86ac308e103e/src/script/interpreter.cpp#L189-L198
790+
0x01 => Ok(EcdsaSigHashType::All),
791+
0x02 => Ok(EcdsaSigHashType::None),
792+
0x03 => Ok(EcdsaSigHashType::Single),
793+
0x81 => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay),
794+
0x82 => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay),
795+
0x83 => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay),
796+
non_standard => Err(NonStandardSigHashType(non_standard))
797+
}
798+
}
799+
800+
/// Converts to a u32
801+
pub fn as_u32(self) -> u32 { self as u32 }
802802
}
803803

804804
impl From<EcdsaSigHashType> for u32 {

0 commit comments

Comments
 (0)