refactor: remove SchnorrSignatureHash::Reserved variant

This commit is contained in:
eunoia_1729 2022-06-02 03:18:58 +05:30
parent 471f90923d
commit 69707b0ccd
No known key found for this signature in database
GPG Key ID: 9250C363C00A1E70
2 changed files with 1 additions and 24 deletions

View File

@ -162,7 +162,7 @@ pub struct PsbtSighashType {
impl fmt::Display for PsbtSighashType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.schnorr_hash_ty() {
Ok(SchnorrSighashType::Reserved) | Err(_) => write!(f, "{:#x}", self.inner),
Err(_) => write!(f, "{:#x}", self.inner),
Ok(schnorr_hash_ty) => fmt::Display::fmt(&schnorr_hash_ty, f),
}
}
@ -179,7 +179,6 @@ impl FromStr for PsbtSighashType {
// inputs. We also do not support SIGHASH_RESERVED in verbatim form
// ("0xFF" string should be used instead).
match SchnorrSighashType::from_str(s) {
Ok(SchnorrSighashType::Reserved) => return Err(SighashTypeParseError{ unrecognized: s.to_owned() }),
Ok(ty) => return Ok(ty.into()),
Err(_) => {}
}
@ -579,20 +578,6 @@ mod test {
}
}
#[test]
fn psbt_sighash_type_schnorr_notstd() {
for (schnorr, schnorr_str) in &[
(SchnorrSighashType::Reserved, "0xff"),
] {
let sighash = PsbtSighashType::from(*schnorr);
let s = format!("{}", sighash);
assert_eq!(&s, schnorr_str);
let back = PsbtSighashType::from_str(&s).unwrap();
assert_eq!(back, sighash);
assert_eq!(back.schnorr_hash_ty().unwrap(), *schnorr);
}
}
#[test]
fn psbt_sighash_type_notstd() {
let nonstd = 0xdddddddd;

View File

@ -125,9 +125,6 @@ pub enum SchnorrSighashType {
NonePlusAnyoneCanPay = 0x82,
/// 0x83: Sign one output and only this input (see `Single` for what "one output" means).
SinglePlusAnyoneCanPay = 0x83,
/// Reserved for future use, `#[non_exhaustive]` is not available with MSRV 1.29.0
Reserved = 0xFF,
}
serde_string_impl!(SchnorrSighashType, "a SchnorrSighashType data");
@ -141,7 +138,6 @@ impl fmt::Display for SchnorrSighashType {
SchnorrSighashType::AllPlusAnyoneCanPay => "SIGHASH_ALL|SIGHASH_ANYONECANPAY",
SchnorrSighashType::NonePlusAnyoneCanPay => "SIGHASH_NONE|SIGHASH_ANYONECANPAY",
SchnorrSighashType::SinglePlusAnyoneCanPay => "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY",
SchnorrSighashType::Reserved => "SIGHASH_RESERVED",
};
f.write_str(s)
}
@ -159,7 +155,6 @@ impl str::FromStr for SchnorrSighashType {
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::AllPlusAnyoneCanPay),
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::NonePlusAnyoneCanPay),
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::SinglePlusAnyoneCanPay),
"SIGHASH_RESERVED" => Ok(SchnorrSighashType::Reserved),
_ => Err(SighashTypeParseError{ unrecognized: s.to_owned() }),
}
}
@ -330,7 +325,6 @@ impl SchnorrSighashType {
SchnorrSighashType::AllPlusAnyoneCanPay => (SchnorrSighashType::All, true),
SchnorrSighashType::NonePlusAnyoneCanPay => (SchnorrSighashType::None, true),
SchnorrSighashType::SinglePlusAnyoneCanPay => (SchnorrSighashType::Single, true),
SchnorrSighashType::Reserved => (SchnorrSighashType::Reserved, false),
}
}
@ -344,7 +338,6 @@ impl SchnorrSighashType {
0x81 => Ok(SchnorrSighashType::AllPlusAnyoneCanPay),
0x82 => Ok(SchnorrSighashType::NonePlusAnyoneCanPay),
0x83 => Ok(SchnorrSighashType::SinglePlusAnyoneCanPay),
0xFF => Ok(SchnorrSighashType::Reserved),
x => Err(Error::InvalidSighashType(x as u32)),
}
}
@ -1174,7 +1167,6 @@ mod tests {
("SIGHASH_ALL|SIGHASH_ANYONECANPAY", SchnorrSighashType::AllPlusAnyoneCanPay),
("SIGHASH_NONE|SIGHASH_ANYONECANPAY", SchnorrSighashType::NonePlusAnyoneCanPay),
("SIGHASH_SINGLE|SIGHASH_ANYONECANPAY", SchnorrSighashType::SinglePlusAnyoneCanPay),
("SIGHASH_RESERVED", SchnorrSighashType::Reserved),
];
for (s, sht) in sighashtypes {
assert_eq!(sht.to_string(), s);