Skip to content

Improve SchnorrSigHashType#903

Merged
dr-orlovsky merged 3 commits intorust-bitcoin:masterfrom
tcharding:schnorr-sighash-str
Mar 24, 2022
Merged

Improve SchnorrSigHashType#903
dr-orlovsky merged 3 commits intorust-bitcoin:masterfrom
tcharding:schnorr-sighash-str

Conversation

@tcharding
Copy link
Copy Markdown
Member

Implement Display/FromStr for SchnorrSigHashType

We currently implement Display and FromStr on EcdsaSigHashType and use them in the serde_string_impl macro to implement ser/de.

Mirror this logic in SchnorrSigHashType.

Patch 1 and 2 are preparatory patches for patch 3.

Notes to reviewers

This PR has some conflicts with #898 but is pushing in the same direction, I'm happy to let 898 go in first and rebase on top.

As is done in the rest of the `internal_macros` module use the fully
qualified path for the `String` type.

Done in preparation for using `serde_string_impl` in the `sighash`
module.
In preparation for constructing an error outside of this module improve
the `SigHashTypeParseError` by doing:

- Make the field public
- Rename the field to `unrecognized` to better describe its usage
@tcharding tcharding force-pushed the schnorr-sighash-str branch from 1f70983 to e04eb11 Compare March 24, 2022 01:30
We currently implement `Display` and `FromStr` on `EcdsaSigHashType` and
use them in the `serde_string_impl` macro to implement ser/de.

Mirror this logic in `SchnorrSigHashType`.
@tcharding tcharding force-pushed the schnorr-sighash-str branch from e04eb11 to 35b682d Compare March 24, 2022 01:47
@tcharding
Copy link
Copy Markdown
Member Author

All the force pushes are me finally working out that ToOwned is only in scope if we have use prelude::*. Ouch.

Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 35b682d. Thanks, much easier to review now that the diff is small

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 35b682d

impl fmt::Display for SigHashTypeParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "can't recognize SIGHASH string '{}'", self.string)
write!(f, "Unrecognized SIGHASH string '{}'", self.unrecognized)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: error strings usually starts with small letter, since they are appended after Error: when printed out by default printer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, I was wondering this. I'll rectify this as I do other clean ups.

];
for s in sht_mistakes {
assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err().to_string(), format!("can't recognize SIGHASH string '{}'", s));
assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err().to_string(), format!("Unrecognized SIGHASH string '{}'", s));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit as above

@dr-orlovsky dr-orlovsky merged commit 86c6ab7 into rust-bitcoin:master Mar 24, 2022
@tcharding tcharding deleted the schnorr-sighash-str branch March 24, 2022 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants