Skip to content

Commit

Permalink
CRC: use from_u8 in define_enum_u8 macro
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Jul 3, 2024
1 parent 7811988 commit bb21209
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions stacks-signer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,7 @@ impl TryFrom<&str> for Vote {
impl TryFrom<u8> for Vote {
type Error = String;
fn try_from(input: u8) -> Result<Vote, Self::Error> {
match input {
0 => Ok(Vote::Yes),
1 => Ok(Vote::No),
_ => Err(format!("Invalid vote: {}. Must be 0 or 1.", input)),
}
Vote::from_u8(input).ok_or_else(|| format!("Invalid vote: {}. Must be 0 or 1.", input))
}
}

Expand Down Expand Up @@ -352,7 +348,7 @@ fn parse_public_key(public_key: &str) -> Result<StacksPublicKey, String> {

/// Parse the vote
fn parse_vote(vote: &str) -> Result<Vote, String> {
Vote::try_from(vote)
vote.try_into()
}

/// Parse the hexadecimal encoded message signature
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub mod tests {
fn test_vote() {
let mut rand = rand::thread_rng();
let vote_info = VoteInfo {
vote: Vote::try_from(rand.gen_range(0..2)).unwrap(),
vote: rand.gen_range(0..2).try_into().unwrap(),
sip: rand.next_u32(),
};
let config_file = "./src/tests/conf/signer-0.toml";
Expand Down

0 comments on commit bb21209

Please sign in to comment.