mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-25 21:17:17 +00:00
Clean out some occurances of SszStream
This commit is contained in:
parent
5550d14d62
commit
759d0250c5
@ -13,7 +13,7 @@ use libp2p::{
|
||||
NetworkBehaviour, PeerId,
|
||||
};
|
||||
use slog::{debug, o, trace, warn};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
|
||||
use types::{Attestation, BeaconBlock};
|
||||
use types::{Topic, TopicHash};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{Decodable, DecodeError, Encodable};
|
||||
/// Available RPC methods types and ids.
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use types::{BeaconBlockBody, BeaconBlockHeader, Epoch, Hash256, Slot};
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::methods::*;
|
||||
use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError as SSZDecodeError, Encodable, SszStream};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError as SSZDecodeError, Encodable};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::io;
|
||||
use std::iter;
|
||||
|
@ -2,11 +2,12 @@ use self::epoch_cache::{get_active_validator_indices, EpochCache, Error as Epoch
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::*;
|
||||
use cached_tree_hash::{Error as TreeHashCacheError, TreeHashCache};
|
||||
use hashing::hash;
|
||||
use int_to_bytes::int_to_bytes32;
|
||||
use pubkey_cache::PubkeyCache;
|
||||
use rand::RngCore;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::{hash, ssz_encode};
|
||||
use ssz::ssz_encode;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash::TreeHash;
|
||||
|
@ -14,7 +14,7 @@ use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use slog;
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
|
||||
use std::cmp::{Ord, Ordering};
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
@ -144,11 +144,13 @@ mod epoch_tests {
|
||||
#[test]
|
||||
fn max_epoch_ssz() {
|
||||
let max_epoch = Epoch::max_value();
|
||||
let mut ssz = SszStream::new();
|
||||
ssz.append(&max_epoch);
|
||||
let encoded = ssz.drain();
|
||||
assert_eq!(&encoded, &[255, 255, 255, 255, 255, 255, 255, 255]);
|
||||
let (decoded, _i): (Epoch, usize) = <_>::ssz_decode(&encoded, 0).unwrap();
|
||||
assert_eq!(max_epoch, decoded);
|
||||
assert_eq!(
|
||||
&max_epoch.as_ssz_bytes(),
|
||||
&[255, 255, 255, 255, 255, 255, 255, 255]
|
||||
);
|
||||
assert_eq!(
|
||||
max_epoch,
|
||||
Epoch::from_ssz_bytes(&max_epoch.as_ssz_bytes()).unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -193,16 +193,30 @@ macro_rules! impl_display {
|
||||
macro_rules! impl_ssz {
|
||||
($type: ident) => {
|
||||
impl Encodable for $type {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append(&self.0);
|
||||
fn is_ssz_fixed_len() -> bool {
|
||||
<u64 as Encodable>::is_ssz_fixed_len()
|
||||
}
|
||||
|
||||
fn ssz_fixed_len() -> usize {
|
||||
<u64 as Encodable>::ssz_fixed_len()
|
||||
}
|
||||
|
||||
fn ssz_append(&self, buf: &mut Vec<u8>) {
|
||||
self.0.ssz_append(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for $type {
|
||||
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
|
||||
let (value, i) = <_>::ssz_decode(bytes, i)?;
|
||||
fn is_ssz_fixed_len() -> bool {
|
||||
<u64 as Decodable>::is_ssz_fixed_len()
|
||||
}
|
||||
|
||||
Ok(($type(value), i))
|
||||
fn ssz_fixed_len() -> usize {
|
||||
<u64 as Decodable>::ssz_fixed_len()
|
||||
}
|
||||
|
||||
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
|
||||
Ok($type(u64::from_ssz_bytes(bytes)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use crate::slot_epoch::{Epoch, Slot};
|
||||
use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
use serde_derive::Serialize;
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
|
||||
use std::cmp::{Ord, Ordering};
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::test_utils::{RngCore, TestRandom};
|
||||
use cached_tree_hash::CachedTreeHash;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{Decodable, DecodeError, Encodable};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use tree_hash::TreeHash;
|
||||
|
||||
|
@ -3,7 +3,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector;
|
||||
use serde::de::{Deserialize, Deserializer};
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
use serde_hex::{encode as hex_encode, PrefixedHexVisitor};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
|
||||
use tree_hash::tree_hash_ssz_encoding_as_vector;
|
||||
|
||||
/// A BLS aggregate signature.
|
||||
|
@ -4,7 +4,7 @@ use hex::encode as hex_encode;
|
||||
use serde::de::{Deserialize, Deserializer};
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
use serde_hex::HexVisitor;
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable};
|
||||
use tree_hash::tree_hash_ssz_encoding_as_vector;
|
||||
|
||||
/// A single BLS signature.
|
||||
|
@ -93,7 +93,7 @@ pub fn ssz_encode_derive(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
fn ssz_fixed_len() -> usize {
|
||||
if <Self as Encodable>::is_ssz_fixed_len() {
|
||||
if <Self as ssz::Encodable>::is_ssz_fixed_len() {
|
||||
#(
|
||||
<#field_types_b as ssz::Encodable>::ssz_fixed_len() +
|
||||
)*
|
||||
@ -161,7 +161,7 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
|
||||
if should_skip_deserializing(field) {
|
||||
// Field should not be deserialized; use a `Default` impl to instantiate.
|
||||
decodes.push(quote! {
|
||||
#ident: <_>::default(),
|
||||
#ident: <_>::default()
|
||||
});
|
||||
} else {
|
||||
let ty = &field.ty;
|
||||
|
Loading…
Reference in New Issue
Block a user