Skip to content

Commit cc1935e

Browse files
committed
primitives - channel - Channel.creator to ValidatorId
1 parent e141c83 commit cc1935e

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

adapter/src/ethereum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ mod test {
557557
)
558558
.expect("prep_db: failed to deserialize channel id"),
559559
// leader_account
560-
creator: "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39".to_string(),
560+
creator: ValidatorId::try_from("Df08F82De32B8d460adbE8D72043E3a7e25A3B39")
561+
.expect("should be valid ValidatorId"),
561562
deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())),
562563
deposit_amount: 2_000.into(),
563564
valid_until: Utc::now() + Duration::days(2),

adapter/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ impl TryFrom<&Channel> for EthereumChannel {
9494
.map(|v| v.id.clone())
9595
.collect();
9696

97-
let creator = <[u8; 20]>::from_hex(&channel.creator[2..])
98-
.map_err(|_| ChannelError::InvalidArgument("failed to parse creator".into()))?;
97+
let creator = channel.creator.inner();
9998
let deposit_asset = <[u8; 20]>::from_hex(&channel.deposit_asset[2..])
10099
.map_err(|_| ChannelError::InvalidArgument("failed to parse deposit asset".into()))?;
101100

primitives/src/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl FromHex for ChannelId {
4949
#[serde(rename_all = "camelCase")]
5050
pub struct Channel {
5151
pub id: ChannelId,
52-
pub creator: String,
52+
pub creator: ValidatorId,
5353
pub deposit_asset: String,
5454
pub deposit_amount: BigNum,
5555
#[serde(with = "ts_seconds")]

primitives/src/channel_validator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::channel::{Channel, ChannelError, SpecValidator, SpecValidators};
22
use crate::config::Config;
33
use crate::ValidatorId;
44
use chrono::Utc;
5+
use std::cmp::PartialEq;
56

67
pub trait ChannelValidator {
78
fn is_channel_valid(
@@ -60,10 +61,10 @@ pub fn all_validators_listed(validators: &SpecValidators, whitelist: &[Validator
6061
}
6162
}
6263

63-
pub fn creator_listed(channel: &Channel, whitelist: &[String]) -> bool {
64+
pub fn creator_listed(channel: &Channel, whitelist: &[ValidatorId]) -> bool {
6465
// if the list is empty, return true, as we don't have a whitelist to restrict us to
6566
// or if we have a list, check if it includes the `channel.creator`
66-
whitelist.is_empty() || whitelist.iter().any(|allowed| allowed == &channel.creator)
67+
whitelist.is_empty() || whitelist.iter().any(|allowed| allowed.eq(&channel.creator))
6768
}
6869

6970
pub fn asset_listed(channel: &Channel, whitelist: &[String]) -> bool {

primitives/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Config {
3333
pub validator_tick_timeout: u32,
3434
pub ip_rate_limit: RateLimit, // HashMap??
3535
pub sid_rate_limit: RateLimit, // HashMap ??
36-
pub creators_whitelist: Vec<String>,
36+
pub creators_whitelist: Vec<ValidatorId>,
3737
pub minimal_deposit: BigNum,
3838
pub minimal_fee: BigNum,
3939
pub token_address_whitelist: Vec<String>,

primitives/src/sentry.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ pub struct Earner {
6262
pub promilles: u64,
6363
}
6464

65-
#[derive(Serialize, Dserialize)]
66-
pub struct EarnerAddress(#[serde(with = "SerHex::<StrictPfx>")] [u8; 20]);
65+
pub type EarnerAddress = ValidatorId;
6766

6867
#[derive(Debug, Serialize, Deserialize)]
6968
#[serde(rename_all = "camelCase")]

primitives/src/util/tests/prep_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ lazy_static! {
5858

5959
Channel {
6060
id: ChannelId::from_hex("061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088").expect("prep_db: failed to deserialize channel id"),
61-
creator: "0x033ed90e0fec3f3ea1c9b005c724d704501e0196".to_string(),
61+
creator: ValidatorId::try_from("033ed90e0fec3f3ea1c9b005c724d704501e0196").expect("Should be valid ValidatorId"),
6262
deposit_asset: "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359".to_string(),
6363
deposit_amount: 1_000.into(),
6464
// UNIX timestamp for 2100-01-01

0 commit comments

Comments
 (0)