Skip to content

Commit 3e02a52

Browse files
committed
fix: removed uneeded clones & flags
1 parent 49da9cd commit 3e02a52

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

adapter/src/ethereum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Adapter for EthereumAdapter {
7979
}
8080
};
8181

82-
let identity = ValidatorId::try_from(address)?;
82+
let identity = ValidatorId::try_from(address.as_str())?;
8383

8484
Ok(Self {
8585
address: identity,
@@ -129,7 +129,7 @@ impl Adapter for EthereumAdapter {
129129
fn verify(&self, signer: &ValidatorId, state_root: &str, sig: &str) -> AdapterResult<bool> {
130130
let decoded_signature = hex::decode(sig)
131131
.map_err(|_| AdapterError::Signature("invalid signature".to_string()))?;
132-
let address = Address::from_slice(signer.into_inner());
132+
let address = Address::from_slice(&signer.inner());
133133
let signature = Signature::from_electrum(&decoded_signature);
134134
let message = Message::from_slice(&hash_message(state_root));
135135

@@ -385,7 +385,7 @@ pub fn ewt_verify(
385385
let payload: Payload = serde_json::from_str(&payload_string)?;
386386

387387
let verified_payload = VerifyPayload {
388-
from: ValidatorId::try_from(format!("{:?}", address))?,
388+
from: ValidatorId::try_from(format!("{:?}", address).as_str())?,
389389
payload,
390390
};
391391

primitives/src/validator.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl ValidatorId {
2929
format!("0x{}", hex::encode(self.0))
3030
}
3131

32-
pub fn into_inner(&self) -> &[u8; 20] {
33-
&self.0
32+
pub fn inner(&self) -> [u8; 20] {
33+
self.0
3434
}
3535

3636
pub fn to_hex_checksummed_string(&self) -> String {
@@ -40,14 +40,13 @@ impl ValidatorId {
4040

4141
impl TryFrom<&str> for ValidatorId {
4242
type Error = DomainError;
43-
// 0x prefixed string
4443
fn try_from(value: &str) -> Result<Self, Self::Error> {
45-
// use hex::FromHex;
46-
// @TODO: Should we have some constrains(like valid hex string starting with `0x`)? If not this should be just `From`.
47-
let mut hex_value = value;
48-
if value.len() == 42 {
49-
hex_value = &value[2..];
50-
}
44+
let hex_value = if value.len() == 42 {
45+
&value[2..]
46+
} else {
47+
value
48+
};
49+
5150
let result = hex::decode(hex_value).map_err(|_| {
5251
DomainError::InvalidArgument("Failed to deserialize validator id".to_string())
5352
})?;
@@ -57,23 +56,9 @@ impl TryFrom<&str> for ValidatorId {
5756
}
5857
}
5958

60-
impl TryFrom<String> for ValidatorId {
61-
type Error = DomainError;
62-
// 0x prefixed string
63-
fn try_from(value: String) -> Result<Self, Self::Error> {
64-
// @TODO: Should we have some constrains(like valid hex string starting with `0x`)? If not this should be just `From`.
65-
let result = hex::decode(&value[2..]).map_err(|_| {
66-
DomainError::InvalidArgument("Failed to deserialize validator id".to_string())
67-
})?;
68-
let mut id: [u8; 20] = [0; 20];
69-
id.copy_from_slice(&result[..]);
70-
Ok(Self(id))
71-
}
72-
}
73-
// returns a 0x prefix string
7459
impl Into<String> for ValidatorId {
7560
fn into(self) -> String {
76-
format!("{}", hex::encode(self.0))
61+
hex::encode(self.0)
7762
}
7863
}
7964

validator_worker/src/heartbeat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ pub async fn heartbeat<A: Adapter + 'static>(
6060
}
6161

6262
fn is_channel_not_exhausted(channel: &Channel, balances: &BalancesMap) -> bool {
63-
!(balances.values().sum::<BigNum>() == channel.deposit_amount)
63+
balances.values().sum::<BigNum>() != channel.deposit_amount
6464
}

0 commit comments

Comments
 (0)