-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver): Allow the driver to raise errors in some occasions
- Loading branch information
Showing
6 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use core::fmt; | ||
|
||
use malachite_common::{Context, SignedVote, Validator}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Error<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
/// Proposer not found | ||
ProposerNotFound(Ctx::Address), | ||
|
||
/// Validator not found in validator set | ||
ValidatorNotFound(Ctx::Address), | ||
|
||
/// Invalid vote signature | ||
InvalidVoteSignature(SignedVote<Ctx>, Ctx::Validator), | ||
} | ||
|
||
impl<Ctx> fmt::Display for Error<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Error::ProposerNotFound(addr) => write!(f, "Proposer not found: {addr}"), | ||
Error::ValidatorNotFound(addr) => write!(f, "Validator not found: {addr}"), | ||
Error::InvalidVoteSignature(vote, validator) => write!( | ||
f, | ||
"Invalid vote signature by {} on vote {vote:?}", | ||
validator.address() | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl<Ctx> PartialEq for Error<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
fn eq(&self, other: &Self) -> bool { | ||
match (self, other) { | ||
(Error::ProposerNotFound(addr1), Error::ProposerNotFound(addr2)) => addr1 == addr2, | ||
(Error::ValidatorNotFound(addr1), Error::ValidatorNotFound(addr2)) => addr1 == addr2, | ||
( | ||
Error::InvalidVoteSignature(vote1, validator1), | ||
Error::InvalidVoteSignature(vote2, validator2), | ||
) => vote1 == vote2 && validator1 == validator2, | ||
_ => false, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters