Skip to content

Commit

Permalink
verify returning DispatchResult
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Apr 22, 2024
1 parent 4244c64 commit 3d02164
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libs/utils/src/identity_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub trait Identity {
fn verified(&self) -> bool;

/// Returns underlying identity information.
fn info(&self) -> &Self::Info;
fn info(&self) -> Self::Info;

/// Adds justification for the underlying identity.
fn verify(&mut self, justification: Self::Justification);
fn verify(&mut self, justification: Self::Justification) -> DispatchResult;
}

/// Provides methods to retrieve an account's identity.
Expand Down
17 changes: 14 additions & 3 deletions substrate/frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,14 @@ mod tests {
}
}

struct IdentityIsAlreadyVerified;

impl From<IdentityIsAlreadyVerified> for DispatchError {
fn from(IdentityIsAlreadyVerified: IdentityIsAlreadyVerified) -> Self {
Self::Other("Identity is already verified")
}
}

#[derive(Encode, Decode, MaxEncodedLen, Clone, Default, Debug)]
pub struct DummyIdentity {
verified: bool,
Expand All @@ -1469,12 +1477,15 @@ mod tests {
self.verified
}

fn info(&self) -> &() {
&()
fn info(&self) -> () {
()
}

fn verify(&mut self, (): ()) {
fn verify(&mut self, (): ()) -> DispatchResult {
ensure!(!self.verified, IdentityIsAlreadyVerified);
self.verified = true;

Ok(())
}
}

Expand Down

0 comments on commit 3d02164

Please sign in to comment.