Impl ssz Enc/Decode on Address. Decode on Vec<T>
This commit is contained in:
parent
d9c472ec37
commit
e6977b5f4b
@ -1,5 +1,5 @@
|
|||||||
use super::decode::decode_ssz_list;
|
use super::decode::decode_ssz_list;
|
||||||
use super::ethereum_types::H256;
|
use super::ethereum_types::{Address, H256};
|
||||||
use super::{Decodable, DecodeError};
|
use super::{Decodable, DecodeError};
|
||||||
|
|
||||||
macro_rules! impl_decodable_for_uint {
|
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<T> Decodable for Vec<T>
|
impl<T> Decodable for Vec<T>
|
||||||
where
|
where
|
||||||
T: Decodable,
|
T: Decodable,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
extern crate bytes;
|
extern crate bytes;
|
||||||
|
|
||||||
use self::bytes::{BufMut, BytesMut};
|
use self::bytes::{BufMut, BytesMut};
|
||||||
use super::ethereum_types::H256;
|
use super::ethereum_types::{Address, H256};
|
||||||
use super::{Encodable, SszStream};
|
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<T> Encodable for Vec<T>
|
||||||
|
where
|
||||||
|
T: Encodable,
|
||||||
|
{
|
||||||
|
fn ssz_append(&self, s: &mut SszStream) {
|
||||||
|
s.append_vec(&self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user