Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit b8d52cc

Browse files
committed
Make the Discovery event into a struct instead of a tuple
1 parent 7d9bab9 commit b8d52cc

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ use std::sync::mpsc::SendError;
3737

3838
fn create_log(hist: &Historian) -> Result<(), SendError<Event>> {
3939
sleep(Duration::from_millis(15));
40-
hist.sender.send(Event::Discovery(Sha256Hash::default()))?;
40+
let data = Sha256Hash::default();
41+
hist.sender.send(Event::Discovery { data })?;
4142
sleep(Duration::from_millis(10));
4243
Ok(())
4344
}
@@ -62,7 +63,7 @@ Running the program should produce a log similar to:
6263

6364
```rust
6465
Entry { num_hashes: 0, end_hash: [0, ...], event: Tick }
65-
Entry { num_hashes: 2, end_hash: [67, ...], event: Discovery(3735928559) }
66+
Entry { num_hashes: 2, end_hash: [67, ...], event: Discovery { data: [37, ...] } }
6667
Entry { num_hashes: 3, end_hash: [123, ...], event: Tick }
6768
```
6869

src/bin/demo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::sync::mpsc::SendError;
88

99
fn create_log(hist: &Historian) -> Result<(), SendError<Event>> {
1010
sleep(Duration::from_millis(15));
11-
hist.sender.send(Event::Discovery(Sha256Hash::default()))?;
11+
let data = Sha256Hash::default();
12+
hist.sender.send(Event::Discovery { data })?;
1213
sleep(Duration::from_millis(10));
1314
Ok(())
1415
}

src/historian.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ mod tests {
137137

138138
hist.sender.send(Event::Tick).unwrap();
139139
sleep(Duration::new(0, 1_000_000));
140-
hist.sender.send(Event::Discovery(zero)).unwrap();
140+
hist.sender.send(Event::Discovery { data: zero }).unwrap();
141141
sleep(Duration::new(0, 1_000_000));
142142
hist.sender.send(Event::Tick).unwrap();
143143

@@ -171,7 +171,7 @@ mod tests {
171171
let zero = Sha256Hash::default();
172172
let hist = Historian::new(&zero, Some(20));
173173
sleep(Duration::from_millis(30));
174-
hist.sender.send(Event::Discovery(zero)).unwrap();
174+
hist.sender.send(Event::Discovery { data: zero }).unwrap();
175175
sleep(Duration::from_millis(15));
176176
drop(hist.sender);
177177
assert_eq!(

src/log.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ pub struct Entry {
3535
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
3636
pub enum Event {
3737
Tick,
38-
Discovery(Sha256Hash),
38+
Discovery {
39+
data: Sha256Hash,
40+
},
3941
Claim {
4042
key: PublicKey,
4143
data: Sha256Hash,
@@ -97,7 +99,7 @@ pub fn extend_and_hash(end_hash: &Sha256Hash, ty: u8, val: &[u8]) -> Sha256Hash
9799
pub fn hash_event(end_hash: &Sha256Hash, event: &Event) -> Sha256Hash {
98100
match *event {
99101
Event::Tick => *end_hash,
100-
Event::Discovery(data) => extend_and_hash(end_hash, 1, &data),
102+
Event::Discovery { data } => extend_and_hash(end_hash, 1, &data),
101103
Event::Claim { key, data, sig } => {
102104
let mut event_data = data.to_vec();
103105
event_data.extend_from_slice(&sig);
@@ -218,7 +220,10 @@ mod tests {
218220

219221
// First, verify Discovery events
220222
let mut end_hash = zero;
221-
let events = [Event::Discovery(zero), Event::Discovery(one)];
223+
let events = [
224+
Event::Discovery { data: zero },
225+
Event::Discovery { data: one },
226+
];
222227
let mut entries: Vec<Entry> = events
223228
.iter()
224229
.map(|event| {

0 commit comments

Comments
 (0)