From 909d62473008f0c6a389e1e0607528a46a924168 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 9 Jul 2018 12:02:00 +1000 Subject: [PATCH] Add RLP encoding to RecentProposerRecord --- src/state/recent_proposer_record.rs | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/state/recent_proposer_record.rs b/src/state/recent_proposer_record.rs index 9f5077a1e..9e713a96a 100644 --- a/src/state/recent_proposer_record.rs +++ b/src/state/recent_proposer_record.rs @@ -1,3 +1,4 @@ +use super::rlp::{ RlpStream, Encodable }; use super::utils::types::*; pub struct RecentPropserRecord { @@ -17,3 +18,34 @@ impl RecentPropserRecord { } } } + +/* + * RLP Encoding + */ +impl Encodable for RecentPropserRecord { + fn rlp_append(&self, s: &mut RlpStream) { + s.append(&self.index); + s.append(&self.randao_commitment); + s.append(&self.balance_delta); + } +} + + +#[cfg(test)] +mod tests { + use super::super::rlp; + use super::*; + + #[test] + fn test_serialization() { + let index = 1; + let randao_commitment = Sha256Digest::zero(); + let balance_delta = 99; + let r = RecentPropserRecord::new(index, randao_commitment, balance_delta); + let e = rlp::encode(&r); + assert_eq!(e[0], 1); + assert_eq!(e[1], 160); + assert_eq!(e[2..34], [0; 32]); + assert_eq!(e[34], 99); + } +}