mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 03:31:10 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user