Skip to content

Commit 8654325

Browse files
apollo_propeller: add core unit struct with accessors
1 parent 5e29cdb commit 8654325

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

crates/apollo_propeller/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub mod signature;
99
#[cfg(test)]
1010
mod signature_test;
1111
pub mod types;
12+
pub mod unit;
1213

13-
pub use merkle::MerkleHash;
14+
pub use merkle::{MerkleHash, MerkleProof, MerkleTree};
1415
pub use types::{Channel, MessageRoot, ShardIndex};
16+
pub use unit::PropellerUnit;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//! Message types for the Propeller protocol.
2+
3+
use libp2p::core::PeerId;
4+
5+
use crate::types::{Channel, MessageRoot, ShardIndex};
6+
use crate::MerkleProof;
7+
8+
// TODO(AndrewL): consider making fields public and remove
9+
// constructor, getters and setters.
10+
11+
/// A single shard unit in the Propeller protocol.
12+
///
13+
/// Contains one shard of data along with its merkle proof, allowing
14+
/// receivers to verify the shard is part of the original message.
15+
#[derive(Debug, PartialEq, Clone)]
16+
pub struct PropellerUnit {
17+
channel: Channel,
18+
publisher: PeerId,
19+
root: MessageRoot,
20+
signature: Vec<u8>,
21+
index: ShardIndex,
22+
shard: Vec<u8>,
23+
proof: MerkleProof,
24+
}
25+
26+
impl PropellerUnit {
27+
pub fn new(
28+
channel: Channel,
29+
publisher: PeerId,
30+
root: MessageRoot,
31+
signature: Vec<u8>,
32+
index: ShardIndex,
33+
shard: Vec<u8>,
34+
proof: MerkleProof,
35+
) -> Self {
36+
Self { channel, root, publisher, signature, index, shard, proof }
37+
}
38+
39+
pub fn channel(&self) -> Channel {
40+
self.channel
41+
}
42+
43+
pub fn publisher(&self) -> PeerId {
44+
self.publisher
45+
}
46+
47+
pub fn signature(&self) -> &[u8] {
48+
&self.signature
49+
}
50+
51+
pub fn index(&self) -> ShardIndex {
52+
self.index
53+
}
54+
55+
pub fn shard(&self) -> &[u8] {
56+
&self.shard
57+
}
58+
59+
pub fn shard_mut(&mut self) -> &mut Vec<u8> {
60+
&mut self.shard
61+
}
62+
63+
pub fn proof(&self) -> &MerkleProof {
64+
&self.proof
65+
}
66+
67+
pub fn root(&self) -> MessageRoot {
68+
self.root
69+
}
70+
}

0 commit comments

Comments
 (0)