From f4a1f5bd34ebc529e4de5ea69f7ffde43d5f0074 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 9 Jul 2018 16:11:56 +1000 Subject: [PATCH] Add RLP encoding for AggregateVote --- src/state/aggregate_vote.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/state/aggregate_vote.rs b/src/state/aggregate_vote.rs index 3c550e625..df7fb8b13 100644 --- a/src/state/aggregate_vote.rs +++ b/src/state/aggregate_vote.rs @@ -1,5 +1,6 @@ use super::utils::types::*; use super::utils::bls::AggregateSignature; +use super::rlp::{ RlpStream, Encodable }; pub struct AggregateVote { pub shard_id: u16, @@ -21,9 +22,22 @@ impl AggregateVote { } } +/* + * RLP Encoding + */ +impl Encodable for AggregateVote { + fn rlp_append(&self, s: &mut RlpStream) { + s.append(&self.shard_id); + s.append(&self.shard_block_hash); + s.append(&self.notary_bitfield); + // s.append(&self.aggregate_sig); // TODO: represent this in RLP + } +} + #[cfg(test)] mod tests { + use super::super::rlp; use super::*; #[test] @@ -34,4 +48,20 @@ mod tests { assert_eq!(v.shard_id, id); assert_eq!(v.shard_block_hash, hash); } + + #[test] + fn test_serialization() { + let a = AggregateVote { + shard_id: 100, + shard_block_hash: Sha256Digest::zero(), + notary_bitfield: Vec::new(), + aggregate_sig: AggregateSignature::new() + }; + let e = rlp::encode(&a); + assert_eq!(e.len(), 35); + assert_eq!(e[0], 100); + assert_eq!(e[1], 160); + assert_eq!(e[2..34], [0; 32]); + assert_eq!(e[34], 128); + } }