Skip to content

Commit 7319377

Browse files
committed
primivies - ValidatorId change errors to address::Error
1 parent a6afc37 commit 7319377

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

adapter/src/ethereum/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub enum KeystoreError {
8484
/// `address` key is missing from the keystore file
8585
AddressMissing,
8686
/// The `address` key in the keystore file is not a valid `ValidatorId`
87-
AddressInvalid(primitives::DomainError),
87+
AddressInvalid(primitives::address::Error),
8888
/// reading the keystore file failed
8989
ReadingFile(std::io::Error),
9090
/// Deserializing the keystore file failed

primitives/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ impl fmt::Display for DomainError {
7474
}
7575
}
7676

77+
impl From<address::Error> for DomainError {
78+
fn from(error: address::Error) -> Self {
79+
Self::InvalidArgument(error.to_string())
80+
}
81+
}
82+
7783
impl error::Error for DomainError {
7884
fn cause(&self) -> Option<&dyn error::Error> {
7985
None

primitives/src/sentry.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ pub mod message {
101101
};
102102

103103
pretty_assertions::assert_eq!(expected_message, actual_message);
104-
pretty_assertions::assert_eq!(to_value(expected_message).expect("should serialize"), approve_state_message);
105-
104+
pretty_assertions::assert_eq!(
105+
to_value(expected_message).expect("should serialize"),
106+
approve_state_message
107+
);
106108
}
107109
}
108110
}

primitives/src/validator.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use std::{convert::TryFrom, fmt, str::FromStr};
33

4-
use crate::{targeting::Value, Address, BigNum, DomainError, ToETHChecksum, ToHex};
4+
use crate::{address::Error, targeting::Value, Address, BigNum, DomainError, ToETHChecksum, ToHex};
55

66
pub use messages::*;
77

@@ -58,24 +58,22 @@ impl AsRef<[u8]> for ValidatorId {
5858
}
5959

6060
impl FromStr for ValidatorId {
61-
type Err = crate::address::Error;
61+
type Err = Error;
6262

6363
fn from_str(s: &str) -> Result<Self, Self::Err> {
6464
Address::try_from(s).map(Self)
6565
}
6666
}
6767

6868
impl TryFrom<&str> for ValidatorId {
69-
type Error = DomainError;
69+
type Error = Error;
7070
fn try_from(value: &str) -> Result<Self, Self::Error> {
71-
Address::try_from(value)
72-
.map_err(|err| DomainError::InvalidArgument(err.to_string()))
73-
.map(Self)
71+
Address::try_from(value).map(Self)
7472
}
7573
}
7674

7775
impl TryFrom<&String> for ValidatorId {
78-
type Error = DomainError;
76+
type Error = Error;
7977

8078
fn try_from(value: &String) -> Result<Self, Self::Error> {
8179
Self::try_from(value.as_str())

sentry/src/routes/validator_message.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use primitives::adapter::Adapter;
55
use primitives::sentry::ValidatorMessageResponse;
66
use primitives::{Channel, DomainError, ValidatorId};
77
use serde::Deserialize;
8-
use std::convert::TryFrom;
98

109
#[derive(Deserialize)]
1110
pub struct ValidatorMessagesListQuery {
@@ -28,7 +27,7 @@ pub fn extract_params(from_path: &str) -> Result<(Option<ValidatorId>, Vec<Strin
2827
// filter an empty string
2928
.filter(|string| !string.is_empty())
3029
// then try to map it to ValidatorId
31-
.map(|string| ValidatorId::try_from(*string))
30+
.map(|string| string.parse())
3231
// Transpose in order to check for an error from the conversion
3332
.transpose()?;
3433

0 commit comments

Comments
 (0)