Skip to content

Commit a5f22fe

Browse files
authored
Merge pull request #172 from AdExNetwork/spec-validator-tuple-instead-of-array
SpecValidators tuple instead of array
2 parents be3a862 + 0073e16 commit a5f22fe

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

primitives/src/channel.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ pub struct ChannelSpec {
7070
}
7171

7272
#[derive(Serialize, Deserialize, Debug, Clone)]
73-
#[serde(transparent)]
74-
pub struct SpecValidators([ValidatorDesc; 2]);
73+
/// A (leader, follower) tuple
74+
pub struct SpecValidators(ValidatorDesc, ValidatorDesc);
7575

7676
pub enum SpecValidator<'a> {
7777
Leader(&'a ValidatorDesc),
@@ -94,15 +94,15 @@ impl<'a> SpecValidator<'a> {
9494

9595
impl SpecValidators {
9696
pub fn new(leader: ValidatorDesc, follower: ValidatorDesc) -> Self {
97-
Self([leader, follower])
97+
Self(leader, follower)
9898
}
9999

100100
pub fn leader(&self) -> &ValidatorDesc {
101-
&self.0[0]
101+
&self.0
102102
}
103103

104104
pub fn follower(&self) -> &ValidatorDesc {
105-
&self.0[1]
105+
&self.1
106106
}
107107

108108
pub fn find(&self, validator_id: &ValidatorId) -> SpecValidator<'_> {
@@ -116,12 +116,13 @@ impl SpecValidators {
116116
}
117117
}
118118

119-
impl From<[ValidatorDesc; 2]> for SpecValidators {
120-
fn from(slice: [ValidatorDesc; 2]) -> Self {
121-
Self(slice)
119+
impl From<(ValidatorDesc, ValidatorDesc)> for SpecValidators {
120+
fn from((leader, follower): (ValidatorDesc, ValidatorDesc)) -> Self {
121+
Self(leader, follower)
122122
}
123123
}
124124

125+
/// Fixed size iterator of 2, as we need an iterator in couple of occasions
125126
impl<'a> IntoIterator for &'a SpecValidators {
126127
type Item = &'a ValidatorDesc;
127128
type IntoIter = ::std::vec::IntoIter<Self::Item>;

validator_worker/src/core/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod test {
100100
deposit_amount: 10_000.into(),
101101
..DUMMY_CHANNEL.clone()
102102
};
103-
channel.spec.validators = [leader, follower].into();
103+
channel.spec.validators = (leader, follower).into();
104104

105105
let balances_before_fees: BalancesMap =
106106
vec![("a".to_string(), 100.into()), ("b".to_string(), 200.into())]
@@ -141,7 +141,7 @@ mod test {
141141
};
142142

143143
let spec = ChannelSpec {
144-
validators: [leader, follower].into(),
144+
validators: (leader, follower).into(),
145145
..DUMMY_CHANNEL.spec.clone()
146146
};
147147
let channel = Channel {

validator_worker/src/core/fees.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mod test {
161161
};
162162

163163
let mut spec = DUMMY_CHANNEL.spec.clone();
164-
spec.validators = [leader, follower].into();
164+
spec.validators = (leader, follower).into();
165165

166166
Channel {
167167
deposit_amount: 100_000.into(),
@@ -185,7 +185,7 @@ mod test {
185185
};
186186

187187
let mut spec = DUMMY_CHANNEL.spec.clone();
188-
spec.validators = [leader, follower].into();
188+
spec.validators = (leader, follower).into();
189189

190190
let channel = Channel {
191191
deposit_amount: 10_000.into(),
@@ -315,7 +315,7 @@ mod test {
315315
};
316316

317317
let mut spec = DUMMY_CHANNEL.spec.clone();
318-
spec.validators = [leader, follower].into();
318+
spec.validators = (leader, follower).into();
319319

320320
let channel = Channel {
321321
deposit_amount: 1_000.into(),

0 commit comments

Comments
 (0)