-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: keychain module * fix: run rustfmt * refactor: better organize errors modules
- Loading branch information
1 parent
4e8196c
commit 06b0f99
Showing
17 changed files
with
104 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
use crate::hex::HexError; | ||
|
||
#[derive(Debug)] | ||
pub enum AccountError { | ||
InvalidHexAddress, | ||
InvalidKeyLength, | ||
} | ||
|
||
impl std::fmt::Display for AccountError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::InvalidHexAddress => write!(f, "Invalid hex address"), | ||
Self::InvalidKeyLength => write!(f, "Invalid key length"), | ||
} | ||
} | ||
} | ||
|
||
impl From<HexError> for AccountError { | ||
fn from(error: HexError) -> Self { | ||
match error { | ||
HexError::InvalidHex => Self::InvalidHexAddress, | ||
HexError::InvalidHexLength => Self::InvalidHexAddress, | ||
HexError::InvalidHexAddress => Self::InvalidHexAddress, | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for AccountError {} |
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,5 @@ | ||
pub mod account; | ||
pub mod errors; | ||
|
||
pub use account::Account; | ||
pub use errors::AccountError; |
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
pub mod account; | ||
pub mod errors; | ||
pub mod keychain; | ||
pub mod signer; | ||
pub mod vault; | ||
|
||
pub use account::*; | ||
pub use errors::*; | ||
pub use keychain::*; | ||
pub use signer::*; | ||
pub use vault::*; |
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,14 @@ | ||
#[derive(Debug)] | ||
pub enum SignerError { | ||
InvalidPrivateKey, | ||
} | ||
|
||
impl std::fmt::Display for SignerError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::InvalidPrivateKey => write!(f, "Invalid private key"), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for SignerError {} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,46 @@ | ||
use std::{error::Error, fmt::Display}; | ||
|
||
use crate::{AccountError, SignerError}; | ||
|
||
#[derive(Debug)] | ||
pub enum VaultError { | ||
ForbiddenWhileLocked, | ||
AccountCreation, | ||
InvalidPassword, | ||
InvalidMnemonic, | ||
SignerCreation, | ||
KeyDerivation, | ||
AlreadyUnlocked, | ||
SafeCreation, | ||
SafeDecrypt, | ||
} | ||
|
||
impl Display for VaultError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::ForbiddenWhileLocked => write!(f, "Forbidden while locked"), | ||
Self::AccountCreation => write!(f, "Account creation error"), | ||
Self::InvalidPassword => write!(f, "Invalid password"), | ||
Self::InvalidMnemonic => write!(f, "Invalid mnemonic"), | ||
Self::SignerCreation => write!(f, "Signer creation error"), | ||
Self::KeyDerivation => write!(f, "Key derivation error"), | ||
Self::AlreadyUnlocked => write!(f, "Already unlocked"), | ||
Self::SafeCreation => write!(f, "Safe creation error"), | ||
Self::SafeDecrypt => write!(f, "Safe decryption error"), | ||
} | ||
} | ||
} | ||
|
||
impl From<AccountError> for VaultError { | ||
fn from(_: AccountError) -> Self { | ||
Self::AccountCreation | ||
} | ||
} | ||
|
||
impl From<SignerError> for VaultError { | ||
fn from(_: SignerError) -> Self { | ||
Self::SignerCreation | ||
} | ||
} | ||
|
||
impl Error for VaultError {} |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod account; | ||
pub mod keychain; | ||
pub mod utils; | ||
|
||
pub use account::*; | ||
pub use keychain::*; | ||
pub use utils::*; |