Skip to content

Commit

Permalink
Slightly improve error conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Oct 28, 2024
1 parent 06d3028 commit 944f931
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ pub mod pallet {
FailedAttestationCheck,
}

impl<T> From<pck::PckParseVerifyError> for Error<T> {
fn from(error: pck::PckParseVerifyError) -> Self {
match error {
pck::PckParseVerifyError::Parse => Error::<T>::PckCertificateParse,
pck::PckParseVerifyError::Verify => Error::<T>::PckCertificateVerify,
pck::PckParseVerifyError::BadPublicKey => Error::<T>::PckCertificateBadPublicKey,
pck::PckParseVerifyError::NoCertificate => Error::<T>::PckCertificateNoCertificate,
}
}
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -545,16 +556,11 @@ pub mod pallet {
T::PckCertChainVerifier::verify_pck_certificate_chain(
joining_server_info.pck_certificate_chain,
)
.map_err(|error| match error {
pck::PckParseVerifyError::Parse => Error::<T>::PckCertificateParse,
pck::PckParseVerifyError::Verify => Error::<T>::PckCertificateVerify,
pck::PckParseVerifyError::BadPublicKey => {
Error::<T>::PckCertificateBadPublicKey
},
pck::PckParseVerifyError::NoCertificate => {
Error::<T>::PckCertificateNoCertificate
},
.map_err(|error| {
let e: Error<T> = error.into();
e
})?;

let server_info = ServerInfo::<T::AccountId> {
tss_account: joining_server_info.tss_account,
x25519_public_key: joining_server_info.x25519_public_key,
Expand Down

0 comments on commit 944f931

Please sign in to comment.