diff --git a/beacon_chain/utils/ssz/src/impl_decode.rs b/beacon_chain/utils/ssz/src/impl_decode.rs index b926c23ef..134e438e1 100644 --- a/beacon_chain/utils/ssz/src/impl_decode.rs +++ b/beacon_chain/utils/ssz/src/impl_decode.rs @@ -1,5 +1,5 @@ use super::decode::decode_ssz_list; -use super::ethereum_types::H256; +use super::ethereum_types::{Address, H256}; use super::{Decodable, DecodeError}; macro_rules! impl_decodable_for_uint { @@ -49,6 +49,16 @@ impl Decodable for H256 { } } +impl Decodable for Address { + fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError> { + if bytes.len() < 20 || bytes.len() - 20 < index { + Err(DecodeError::TooShort) + } else { + Ok((Address::from(&bytes[index..(index + 20)]), index + 20)) + } + } +} + impl Decodable for Vec where T: Decodable, diff --git a/beacon_chain/utils/ssz/src/impl_encode.rs b/beacon_chain/utils/ssz/src/impl_encode.rs index f316a21ea..63de18058 100644 --- a/beacon_chain/utils/ssz/src/impl_encode.rs +++ b/beacon_chain/utils/ssz/src/impl_encode.rs @@ -1,7 +1,7 @@ extern crate bytes; use self::bytes::{BufMut, BytesMut}; -use super::ethereum_types::H256; +use super::ethereum_types::{Address, H256}; use super::{Encodable, SszStream}; /* @@ -52,6 +52,21 @@ impl Encodable for H256 { } } +impl Encodable for Address { + fn ssz_append(&self, s: &mut SszStream) { + s.append_encoded_raw(&self.to_vec()); + } +} + +impl Encodable for Vec +where + T: Encodable, +{ + fn ssz_append(&self, s: &mut SszStream) { + s.append_vec(&self); + } +} + #[cfg(test)] mod tests { use super::*;