Skip to content

Commit 87cea8b

Browse files
committed
VectorToArrayConversionError
1 parent 5abb9db commit 87cea8b

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub enum Error {
4343
HexError(#[from] FromHexError),
4444
#[error("unsupported operation: {0}")]
4545
UnsupportedOperation(String),
46-
#[error("failed to convert vector to array")]
47-
PrivateKeyConversionError,
46+
#[error("failed to convert vector {0:?} to array")]
47+
VectorToArrayConversionError(Vec<u8>),
4848
#[error("alias must be {min_length:?} to {max_length:?} length of {alphabet:?} and may have a prefix \"{max_length:?}{chain_id:?}:\"")]
4949
InvalidAliasName {
5050
min_length: u8,

src/model/account/private_key.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ impl std::str::FromStr for PrivateKey {
1717

1818
fn from_str(base58string: &str) -> Result<PrivateKey> {
1919
let bytes = Base58::decode(base58string)?;
20-
let bytes_array: [u8; 32] = match bytes.try_into() {
21-
Ok(v) => v,
22-
Err(_) => return Err(Error::PrivateKeyConversionError),
23-
};
20+
let bytes_array: [u8; 32] = bytes.try_into().map_err(|e| Error::VectorToArrayConversionError(e))?;
2421
PrivateKey::from_bytes(bytes_array)
2522
}
2623
}

0 commit comments

Comments
 (0)