Offence reporting returns a result (#5082)

* Offence reporting returns a result

* Bump spec_version

* Use unwrap instead of assertions

* Fix more review grumbles
This commit is contained in:
Fedor Sakharov
2020-03-02 13:00:38 +03:00
committed by GitHub
parent d7e4aa41b9
commit 8539b85c99
7 changed files with 51 additions and 22 deletions
+25 -2
View File
@@ -91,14 +91,37 @@ pub trait Offence<Offender> {
) -> Perbill;
}
/// Errors that may happen on offence reports.
#[derive(PartialEq, sp_runtime::RuntimeDebug)]
pub enum OffenceError {
/// The report has already been sumbmitted.
DuplicateReport,
/// Other error has happened.
Other(u8),
}
impl sp_runtime::traits::Printable for OffenceError {
fn print(&self) {
"OffenceError".print();
match self {
Self::DuplicateReport => "DuplicateReport".print(),
Self::Other(e) => {
"Other".print();
e.print();
}
}
}
}
/// A trait for decoupling offence reporters from the actual handling of offence reports.
pub trait ReportOffence<Reporter, Offender, O: Offence<Offender>> {
/// Report an `offence` and reward given `reporters`.
fn report_offence(reporters: Vec<Reporter>, offence: O);
fn report_offence(reporters: Vec<Reporter>, offence: O) -> Result<(), OffenceError>;
}
impl<Reporter, Offender, O: Offence<Offender>> ReportOffence<Reporter, Offender, O> for () {
fn report_offence(_reporters: Vec<Reporter>, _offence: O) {}
fn report_offence(_reporters: Vec<Reporter>, _offence: O) -> Result<(), OffenceError> { Ok(()) }
}
/// A trait to take action on an offence.