Remove old tree_hash_vector file

This commit is contained in:
Paul Hauner 2019-05-13 14:14:40 +10:00
parent ce8ebeccbc
commit afa8fff31a
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 0 additions and 144 deletions

View File

@ -27,7 +27,6 @@ pub mod pending_attestation;
pub mod proposer_slashing; pub mod proposer_slashing;
pub mod slashable_attestation; pub mod slashable_attestation;
pub mod transfer; pub mod transfer;
// pub mod tree_hash_vector;
pub mod voluntary_exit; pub mod voluntary_exit;
#[macro_use] #[macro_use]
pub mod slot_epoch_macros; pub mod slot_epoch_macros;
@ -66,7 +65,6 @@ pub use crate::slashable_attestation::SlashableAttestation;
pub use crate::slot_epoch::{Epoch, Slot}; pub use crate::slot_epoch::{Epoch, Slot};
pub use crate::slot_height::SlotHeight; pub use crate::slot_height::SlotHeight;
pub use crate::transfer::Transfer; pub use crate::transfer::Transfer;
// pub use crate::tree_hash_vector::TreeHashVector;
pub use crate::validator::Validator; pub use crate::validator::Validator;
pub use crate::voluntary_exit::VoluntaryExit; pub use crate::voluntary_exit::VoluntaryExit;

View File

@ -1,142 +0,0 @@
use crate::test_utils::{RngCore, TestRandom};
use cached_tree_hash::CachedTreeHash;
use serde_derive::{Deserialize, Serialize};
use ssz::{Decodable, DecodeError, Encodable, SszStream};
use std::ops::{Deref, DerefMut};
use tree_hash::TreeHash;
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct TreeHashVector<T>(Vec<T>);
impl<T> From<Vec<T>> for TreeHashVector<T> {
fn from(vec: Vec<T>) -> TreeHashVector<T> {
TreeHashVector(vec)
}
}
impl<T> Into<Vec<T>> for TreeHashVector<T> {
fn into(self) -> Vec<T> {
self.0
}
}
impl<T> Deref for TreeHashVector<T> {
type Target = Vec<T>;
fn deref(&self) -> &Vec<T> {
&self.0
}
}
impl<T> DerefMut for TreeHashVector<T> {
fn deref_mut(&mut self) -> &mut Vec<T> {
&mut self.0
}
}
impl<T> tree_hash::TreeHash for TreeHashVector<T>
where
T: TreeHash,
{
fn tree_hash_type() -> tree_hash::TreeHashType {
tree_hash::TreeHashType::Vector
}
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
unreachable!("Vector should never be packed.")
}
fn tree_hash_packing_factor() -> usize {
unreachable!("Vector should never be packed.")
}
fn tree_hash_root(&self) -> Vec<u8> {
tree_hash::impls::vec_tree_hash_root(self)
}
}
impl<T> CachedTreeHash for TreeHashVector<T>
where
T: CachedTreeHash + TreeHash,
{
fn new_tree_hash_cache(
&self,
depth: usize,
) -> Result<cached_tree_hash::TreeHashCache, cached_tree_hash::Error> {
let (cache, _overlay) = cached_tree_hash::vec::new_tree_hash_cache(self, depth)?;
Ok(cache)
}
fn tree_hash_cache_schema(&self, depth: usize) -> cached_tree_hash::BTreeSchema {
cached_tree_hash::vec::produce_schema(self, depth)
}
fn update_tree_hash_cache(
&self,
cache: &mut cached_tree_hash::TreeHashCache,
) -> Result<(), cached_tree_hash::Error> {
cached_tree_hash::vec::update_tree_hash_cache(self, cache)?;
Ok(())
}
}
impl<T> Encodable for TreeHashVector<T>
where
T: Encodable,
{
fn ssz_append(&self, s: &mut SszStream) {
s.append_vec(self)
}
}
impl<T> Decodable for TreeHashVector<T>
where
T: Decodable,
{
fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError> {
ssz::decode_ssz_list(bytes, index).and_then(|(vec, i)| Ok((vec.into(), i)))
}
}
impl<U> TestRandom for TreeHashVector<U>
where
U: TestRandom,
{
fn random_for_test(rng: &mut impl RngCore) -> Self {
TreeHashVector::from(vec![
U::random_for_test(rng),
U::random_for_test(rng),
U::random_for_test(rng),
])
}
}
#[cfg(test)]
mod test {
use super::*;
use tree_hash::TreeHash;
#[test]
pub fn test_cached_tree_hash() {
let original = TreeHashVector::from(vec![1_u64, 2, 3, 4]);
let mut cache = cached_tree_hash::TreeHashCache::new(&original).unwrap();
assert_eq!(
cache.tree_hash_root().unwrap().to_vec(),
original.tree_hash_root()
);
let modified = TreeHashVector::from(vec![1_u64, 1, 1, 1]);
cache.update(&modified).unwrap();
assert_eq!(
cache.tree_hash_root().unwrap().to_vec(),
modified.tree_hash_root()
);
}
}