Rename SSZ traits (Encodable -> Encode)

This commit is contained in:
Paul Hauner 2019-05-13 15:12:19 +10:00
parent 94ab2479fe
commit a0148b5aae
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
39 changed files with 130 additions and 131 deletions

View File

@ -1,6 +1,6 @@
use super::BLOCKS_DB_COLUMN as DB_COLUMN; use super::BLOCKS_DB_COLUMN as DB_COLUMN;
use super::{ClientDB, DBError}; use super::{ClientDB, DBError};
use ssz::Decodable; use ssz::Decode;
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconBlock, Hash256, Slot}; use types::{BeaconBlock, Hash256, Slot};

View File

@ -1,6 +1,6 @@
use super::STATES_DB_COLUMN as DB_COLUMN; use super::STATES_DB_COLUMN as DB_COLUMN;
use super::{ClientDB, DBError}; use super::{ClientDB, DBError};
use ssz::Decodable; use ssz::Decode;
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconState, EthSpec, Hash256}; use types::{BeaconState, EthSpec, Hash256};

View File

@ -4,7 +4,7 @@ use self::bytes::{BufMut, BytesMut};
use super::VALIDATOR_DB_COLUMN as DB_COLUMN; use super::VALIDATOR_DB_COLUMN as DB_COLUMN;
use super::{ClientDB, DBError}; use super::{ClientDB, DBError};
use bls::PublicKey; use bls::PublicKey;
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
use std::sync::Arc; use std::sync::Arc;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View File

@ -13,7 +13,7 @@ use libp2p::{
NetworkBehaviour, PeerId, NetworkBehaviour, PeerId,
}; };
use slog::{debug, o, trace, warn}; use slog::{debug, o, trace, warn};
use ssz::{ssz_encode, Decodable, DecodeError, Encodable}; use ssz::{ssz_encode, Decode, DecodeError, Encode};
use types::{Attestation, BeaconBlock}; use types::{Attestation, BeaconBlock};
use types::{Topic, TopicHash}; use types::{Topic, TopicHash};
@ -197,13 +197,13 @@ pub enum PubsubMessage {
} }
//TODO: Correctly encode/decode enums. Prefixing with integer for now. //TODO: Correctly encode/decode enums. Prefixing with integer for now.
impl Encodable for PubsubMessage { impl Encode for PubsubMessage {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }
fn ssz_append(&self, buf: &mut Vec<u8>) { fn ssz_append(&self, buf: &mut Vec<u8>) {
let offset = <u32 as Encodable>::ssz_fixed_len() + <Vec<u8> as Encodable>::ssz_fixed_len(); let offset = <u32 as Encode>::ssz_fixed_len() + <Vec<u8> as Encode>::ssz_fixed_len();
let mut encoder = ssz::SszEncoder::container(buf, offset); let mut encoder = ssz::SszEncoder::container(buf, offset);
@ -226,7 +226,7 @@ impl Encodable for PubsubMessage {
} }
} }
impl Decodable for PubsubMessage { impl Decode for PubsubMessage {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }

View File

@ -1,6 +1,6 @@
use super::methods::*; use super::methods::*;
use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use ssz::{impl_decode_via_from, impl_encode_via_from, ssz_encode, Decodable, Encodable}; use ssz::{impl_decode_via_from, impl_encode_via_from, ssz_encode, Decode, Encode};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::io; use std::io;
use std::iter; use std::iter;
@ -203,7 +203,7 @@ where
} }
} }
impl Encodable for RPCEvent { impl Encode for RPCEvent {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }
@ -213,9 +213,9 @@ impl Encodable for RPCEvent {
// This code has not been tested, it is a placeholder until we can update to the new libp2p // This code has not been tested, it is a placeholder until we can update to the new libp2p
// spec. // spec.
fn ssz_append(&self, buf: &mut Vec<u8>) { fn ssz_append(&self, buf: &mut Vec<u8>) {
let offset = <bool as Encodable>::ssz_fixed_len() let offset = <bool as Encode>::ssz_fixed_len()
+ <u16 as Encodable>::ssz_fixed_len() + <u16 as Encode>::ssz_fixed_len()
+ <Vec<u8> as Encodable>::ssz_fixed_len(); + <Vec<u8> as Encode>::ssz_fixed_len();
let mut encoder = ssz::SszEncoder::container(buf, offset); let mut encoder = ssz::SszEncoder::container(buf, offset);

View File

@ -7,7 +7,7 @@ use protos::services::{
}; };
use protos::services_grpc::AttestationService; use protos::services_grpc::AttestationService;
use slog::{error, info, trace, warn}; use slog::{error, info, trace, warn};
use ssz::{ssz_encode, Decodable}; use ssz::{ssz_encode, Decode};
use std::sync::Arc; use std::sync::Arc;
use types::{Attestation, EthSpec}; use types::{Attestation, EthSpec};

View File

@ -11,7 +11,7 @@ use protos::services::{
use protos::services_grpc::BeaconBlockService; use protos::services_grpc::BeaconBlockService;
use slog::Logger; use slog::Logger;
use slog::{error, info, trace, warn}; use slog::{error, info, trace, warn};
use ssz::{ssz_encode, Decodable}; use ssz::{ssz_encode, Decode};
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconBlock, EthSpec, Signature, Slot}; use types::{BeaconBlock, EthSpec, Signature, Slot};

View File

@ -5,7 +5,7 @@ use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
use protos::services::{ActiveValidator, GetDutiesRequest, GetDutiesResponse, ValidatorDuty}; use protos::services::{ActiveValidator, GetDutiesRequest, GetDutiesResponse, ValidatorDuty};
use protos::services_grpc::ValidatorService; use protos::services_grpc::ValidatorService;
use slog::{trace, warn}; use slog::{trace, warn};
use ssz::Decodable; use ssz::Decode;
use std::sync::Arc; use std::sync::Arc;
use types::{Epoch, EthSpec, RelativeEpoch}; use types::{Epoch, EthSpec, RelativeEpoch};

View File

@ -30,7 +30,7 @@ Rust crates containing logic common across the Lighthouse project.
- [`ssz`](utils/ssz/): an implementation of the SimpleSerialize - [`ssz`](utils/ssz/): an implementation of the SimpleSerialize
serialization/deserialization protocol used by Eth 2.0. serialization/deserialization protocol used by Eth 2.0.
- [`ssz_derive`](utils/ssz_derive/): provides procedural macros for - [`ssz_derive`](utils/ssz_derive/): provides procedural macros for
deriving SSZ `Encodable`, `Decodable`, and `TreeHash` methods. deriving SSZ `Encode`, `Decode`, and `TreeHash` methods.
- [`swap_or_not_shuffle`](utils/swap_or_not_shuffle/): a list-shuffling - [`swap_or_not_shuffle`](utils/swap_or_not_shuffle/): a list-shuffling
method which is slow, but allows for a subset of indices to be shuffled. method which is slow, but allows for a subset of indices to be shuffled.
- [`test_random_derive`](utils/test_random_derive/): provides procedural - [`test_random_derive`](utils/test_random_derive/): provides procedural

View File

@ -15,7 +15,7 @@ use crate::test_utils::TestRandom;
use rand::RngCore; use rand::RngCore;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use slog; use slog;
use ssz::{ssz_encode, Decodable, DecodeError, Encodable}; use ssz::{ssz_encode, Decode, DecodeError, Encode};
use std::cmp::{Ord, Ordering}; use std::cmp::{Ord, Ordering};
use std::fmt; use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};

View File

@ -192,13 +192,13 @@ macro_rules! impl_display {
macro_rules! impl_ssz { macro_rules! impl_ssz {
($type: ident) => { ($type: ident) => {
impl Encodable for $type { impl Encode for $type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
<u64 as Encodable>::is_ssz_fixed_len() <u64 as Encode>::is_ssz_fixed_len()
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
<u64 as Encodable>::ssz_fixed_len() <u64 as Encode>::ssz_fixed_len()
} }
fn ssz_append(&self, buf: &mut Vec<u8>) { fn ssz_append(&self, buf: &mut Vec<u8>) {
@ -206,13 +206,13 @@ macro_rules! impl_ssz {
} }
} }
impl Decodable for $type { impl Decode for $type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
<u64 as Decodable>::is_ssz_fixed_len() <u64 as Decode>::is_ssz_fixed_len()
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
<u64 as Decodable>::ssz_fixed_len() <u64 as Decode>::ssz_fixed_len()
} }
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {

View File

@ -3,7 +3,7 @@ use crate::test_utils::TestRandom;
use rand::RngCore; use rand::RngCore;
use serde_derive::Serialize; use serde_derive::Serialize;
use ssz::{ssz_encode, Decodable, DecodeError, Encodable}; use ssz::{ssz_encode, Decode, DecodeError, Encode};
use std::cmp::{Ord, Ordering}; use std::cmp::{Ord, Ordering};
use std::fmt; use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};

View File

@ -5,7 +5,7 @@ macro_rules! ssz_tests {
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {
use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use ssz::{ssz_encode, Decodable}; use ssz::{ssz_encode, Decode};
let mut rng = XorShiftRng::from_seed([42; 16]); let mut rng = XorShiftRng::from_seed([42; 16]);
let original = $type::random_for_test(&mut rng); let original = $type::random_for_test(&mut rng);

View File

@ -1,7 +1,7 @@
use crate::test_utils::{RngCore, TestRandom}; use crate::test_utils::{RngCore, TestRandom};
use cached_tree_hash::CachedTreeHash; use cached_tree_hash::CachedTreeHash;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use ssz::{Decodable, DecodeError, Encodable}; use ssz::{Decode, DecodeError, Encode};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use tree_hash::TreeHash; use tree_hash::TreeHash;
@ -82,18 +82,18 @@ where
} }
} }
impl<T> Encodable for TreeHashVector<T> impl<T> Encode for TreeHashVector<T>
where where
T: Encodable, T: Encode,
{ {
fn ssz_append(&self, s: &mut SszStream) { fn ssz_append(&self, s: &mut SszStream) {
s.append_vec(self) s.append_vec(self)
} }
} }
impl<T> Decodable for TreeHashVector<T> impl<T> Decode for TreeHashVector<T>
where where
T: Decodable, T: Decode,
{ {
fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError> { 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))) ssz::decode_ssz_list(bytes, index).and_then(|(vec, i)| Ok((vec.into(), i)))

View File

@ -6,7 +6,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, HexVisitor}; use serde_hex::{encode as hex_encode, HexVisitor};
use ssz::{Decodable, DecodeError}; use ssz::{Decode, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector; use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A BLS aggregate signature. /// A BLS aggregate signature.
@ -168,7 +168,7 @@ cached_tree_hash_ssz_encoding_as_vector!(AggregateSignature, 96);
mod tests { mod tests {
use super::super::{Keypair, Signature}; use super::super::{Keypair, Signature};
use super::*; use super::*;
use ssz::Encodable; use ssz::Encode;
#[test] #[test]
pub fn test_ssz_round_trip() { pub fn test_ssz_round_trip() {

View File

@ -3,7 +3,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, PrefixedHexVisitor}; use serde_hex::{encode as hex_encode, PrefixedHexVisitor};
use ssz::{ssz_encode, Decodable, DecodeError}; use ssz::{ssz_encode, Decode, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector; use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A BLS aggregate signature. /// A BLS aggregate signature.

View File

@ -4,7 +4,7 @@ use hex::encode as hex_encode;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::HexVisitor; use serde_hex::HexVisitor;
use ssz::{ssz_encode, Decodable, DecodeError}; use ssz::{ssz_encode, Decode, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector; use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A single BLS signature. /// A single BLS signature.

View File

@ -1,6 +1,6 @@
macro_rules! impl_ssz { macro_rules! impl_ssz {
($type: ident, $byte_size: expr, $item_str: expr) => { ($type: ident, $byte_size: expr, $item_str: expr) => {
impl ssz::Encodable for $type { impl ssz::Encode for $type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -14,7 +14,7 @@ macro_rules! impl_ssz {
} }
} }
impl ssz::Decodable for $type { impl ssz::Decode for $type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -25,7 +25,7 @@ macro_rules! impl_ssz {
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
let len = bytes.len(); let len = bytes.len();
let expected = <Self as ssz::Decodable>::ssz_fixed_len(); let expected = <Self as ssz::Decode>::ssz_fixed_len();
if len != expected { if len != expected {
Err(ssz::DecodeError::InvalidByteLength { len, expected }) Err(ssz::DecodeError::InvalidByteLength { len, expected })

View File

@ -4,7 +4,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, HexVisitor}; use serde_hex::{encode as hex_encode, HexVisitor};
use ssz::{ssz_encode, Decodable, DecodeError}; use ssz::{ssz_encode, Decode, DecodeError};
use std::default; use std::default;
use std::fmt; use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};

View File

@ -4,7 +4,7 @@ use hex::encode as hex_encode;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::HexVisitor; use serde_hex::HexVisitor;
use ssz::{ssz_encode, Decodable, DecodeError}; use ssz::{ssz_encode, Decode, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector; use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A single BLS signature. /// A single BLS signature.

View File

@ -5,7 +5,7 @@ use hex::encode as hex_encode;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::HexVisitor; use serde_hex::HexVisitor;
use ssz::{ssz_encode, Decodable, DecodeError}; use ssz::{ssz_encode, Decode, DecodeError};
use tree_hash::tree_hash_ssz_encoding_as_vector; use tree_hash::tree_hash_ssz_encoding_as_vector;
/// A single BLS signature. /// A single BLS signature.

View File

@ -7,7 +7,7 @@ use cached_tree_hash::cached_tree_hash_bytes_as_list;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::{encode, PrefixedHexVisitor}; use serde_hex::{encode, PrefixedHexVisitor};
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
use std::cmp; use std::cmp;
use std::default; use std::default;
@ -194,7 +194,7 @@ impl std::ops::BitOr for BooleanBitfield {
} }
} }
impl Encodable for BooleanBitfield { impl Encode for BooleanBitfield {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }
@ -204,7 +204,7 @@ impl Encodable for BooleanBitfield {
} }
} }
impl Decodable for BooleanBitfield { impl Decode for BooleanBitfield {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
// use cached_tree_hash::CachedTreeHash; // use cached_tree_hash::CachedTreeHash;
// use ssz::{Decodable, Encodable}; // use ssz::{Decode, Encode};
// use tree_hash::TreeHash; // use tree_hash::TreeHash;
impl<T, N: Unsigned> tree_hash::TreeHash for FixedLenVec<T, N> impl<T, N: Unsigned> tree_hash::TreeHash for FixedLenVec<T, N>
@ -51,16 +51,16 @@ where
} }
} }
impl<T, N: Unsigned> ssz::Encodable for FixedLenVec<T, N> impl<T, N: Unsigned> ssz::Encode for FixedLenVec<T, N>
where where
T: ssz::Encodable, T: ssz::Encode,
{ {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
if <Self as ssz::Encodable>::is_ssz_fixed_len() { if <Self as ssz::Encode>::is_ssz_fixed_len() {
T::ssz_fixed_len() * N::to_usize() T::ssz_fixed_len() * N::to_usize()
} else { } else {
ssz::BYTES_PER_LENGTH_OFFSET ssz::BYTES_PER_LENGTH_OFFSET
@ -86,16 +86,16 @@ where
} }
} }
impl<T, N: Unsigned> ssz::Decodable for FixedLenVec<T, N> impl<T, N: Unsigned> ssz::Decode for FixedLenVec<T, N>
where where
T: ssz::Decodable + Default, T: ssz::Decode + Default,
{ {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
T::is_ssz_fixed_len() T::is_ssz_fixed_len()
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
if <Self as ssz::Decodable>::is_ssz_fixed_len() { if <Self as ssz::Decode>::is_ssz_fixed_len() {
T::ssz_fixed_len() * N::to_usize() T::ssz_fixed_len() * N::to_usize()
} else { } else {
ssz::BYTES_PER_LENGTH_OFFSET ssz::BYTES_PER_LENGTH_OFFSET
@ -127,10 +127,10 @@ mod ssz_tests {
fn encode() { fn encode() {
let vec: FixedLenVec<u16, U2> = vec![0; 2].into(); let vec: FixedLenVec<u16, U2> = vec![0; 2].into();
assert_eq!(vec.as_ssz_bytes(), vec![0, 0, 0, 0]); assert_eq!(vec.as_ssz_bytes(), vec![0, 0, 0, 0]);
assert_eq!(<FixedLenVec<u16, U2> as Encodable>::ssz_fixed_len(), 4); assert_eq!(<FixedLenVec<u16, U2> as Encode>::ssz_fixed_len(), 4);
} }
fn round_trip<T: Encodable + Decodable + std::fmt::Debug + PartialEq>(item: T) { fn round_trip<T: Encode + Decode + std::fmt::Debug + PartialEq>(item: T) {
let encoded = &item.as_ssz_bytes(); let encoded = &item.as_ssz_bytes();
assert_eq!(T::from_ssz_bytes(&encoded), Ok(item)); assert_eq!(T::from_ssz_bytes(&encoded), Ok(item));
} }

View File

@ -38,8 +38,8 @@ spec is decided.*\
+ [bytes v0.4.9](#bytes-v049) + [bytes v0.4.9](#bytes-v049)
+ [ethereum-types](#ethereum-types) + [ethereum-types](#ethereum-types)
* [Interface](#interface) * [Interface](#interface)
+ [Encodable](#encodable) + [Encode](#encodable)
+ [Decodable](#decodable) + [Decode](#decodable)
+ [SszStream](#sszstream) + [SszStream](#sszstream)
- [new()](#new) - [new()](#new)
- [append(&mut self, value: &E) -> &mut Self](#appendmut-self-value-e---mut-self) - [append(&mut self, value: &E) -> &mut Self](#appendmut-self-value-e---mut-self)
@ -299,24 +299,24 @@ Github: [ https://github.com/paritytech/primitives ](https://github.com/parityte
## Interface ## Interface
### Encodable ### Encode
A type is **Encodable** if it has a valid ``ssz_append`` function. This is A type is **Encode** if it has a valid ``ssz_append`` function. This is
used to ensure that the object/type can be serialized. used to ensure that the object/type can be serialized.
```rust ```rust
pub trait Encodable { pub trait Encode {
fn ssz_append(&self, s: &mut SszStream); fn ssz_append(&self, s: &mut SszStream);
} }
``` ```
### Decodable ### Decode
A type is **Decodable** if it has a valid ``ssz_decode`` function. This is A type is **Decode** if it has a valid ``ssz_decode`` function. This is
used to ensure the object is deserializable. used to ensure the object is deserializable.
```rust ```rust
pub trait Decodable: Sized { pub trait Decode: Sized {
fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError>; fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError>;
} }
``` ```
@ -342,7 +342,7 @@ Appends a value that can be encoded into the stream.
| Parameter | Description | | Parameter | Description |
|:---------:|:-----------------------------------------| |:---------:|:-----------------------------------------|
| ``value`` | Encodable value to append to the stream. | | ``value`` | Encode value to append to the stream. |
**Example** **Example**
@ -371,7 +371,7 @@ Appends some vector (list) of encodable values to the stream.
| Parameter | Description | | Parameter | Description |
|:---------:|:----------------------------------------------| |:---------:|:----------------------------------------------|
| ``vec`` | Vector of Encodable objects to be serialized. | | ``vec`` | Vector of Encode objects to be serialized. |
**Example** **Example**

View File

@ -3,7 +3,7 @@ extern crate criterion;
use criterion::black_box; use criterion::black_box;
use criterion::{Benchmark, Criterion}; use criterion::{Benchmark, Criterion};
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode}; use ssz_derive::{Decode, Encode};
#[derive(Clone, Copy, Encode, Decode)] #[derive(Clone, Copy, Encode, Decode)]

View File

@ -2,7 +2,7 @@
//! //!
//! Useful for `cargo flamegraph`. //! Useful for `cargo flamegraph`.
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
fn main() { fn main() {
let vec: Vec<u64> = vec![4242; 8196]; let vec: Vec<u64> = vec![4242; 8196];

View File

@ -2,7 +2,7 @@
//! //!
//! Useful for `cargo flamegraph`. //! Useful for `cargo flamegraph`.
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode}; use ssz_derive::{Decode, Encode};
#[derive(Clone, Copy, Encode, Decode)] #[derive(Clone, Copy, Encode, Decode)]

View File

@ -1,4 +1,4 @@
use ssz::{Decodable, DecodeError, Encodable, SszDecoderBuilder, SszEncoder}; use ssz::{Decode, DecodeError, Encode, SszDecoderBuilder, SszEncoder};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Foo { pub struct Foo {
@ -7,15 +7,15 @@ pub struct Foo {
c: u16, c: u16,
} }
impl Encodable for Foo { impl Encode for Foo {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
<u16 as Encodable>::is_ssz_fixed_len() && <Vec<u16> as Encodable>::is_ssz_fixed_len() <u16 as Encode>::is_ssz_fixed_len() && <Vec<u16> as Encode>::is_ssz_fixed_len()
} }
fn ssz_append(&self, buf: &mut Vec<u8>) { fn ssz_append(&self, buf: &mut Vec<u8>) {
let offset = <u16 as Encodable>::ssz_fixed_len() let offset = <u16 as Encode>::ssz_fixed_len()
+ <Vec<u16> as Encodable>::ssz_fixed_len() + <Vec<u16> as Encode>::ssz_fixed_len()
+ <u16 as Encodable>::ssz_fixed_len(); + <u16 as Encode>::ssz_fixed_len();
let mut encoder = SszEncoder::container(buf, offset); let mut encoder = SszEncoder::container(buf, offset);
@ -27,9 +27,9 @@ impl Encodable for Foo {
} }
} }
impl Decodable for Foo { impl Decode for Foo {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
<u16 as Decodable>::is_ssz_fixed_len() && <Vec<u16> as Decodable>::is_ssz_fixed_len() <u16 as Decode>::is_ssz_fixed_len() && <Vec<u16> as Decode>::is_ssz_fixed_len()
} }
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {

View File

@ -26,7 +26,7 @@ pub enum DecodeError {
/// ///
/// See `examples/` for manual implementations or the crate root for implementations using /// See `examples/` for manual implementations or the crate root for implementations using
/// `#[derive(Decode)]`. /// `#[derive(Decode)]`.
pub trait Decodable: Sized { pub trait Decode: Sized {
/// Returns `true` if this object has a fixed-length. /// Returns `true` if this object has a fixed-length.
/// ///
/// I.e., there are no variable length items in this object or any of it's contained objects. /// I.e., there are no variable length items in this object or any of it's contained objects.
@ -80,7 +80,7 @@ impl<'a> SszDecoderBuilder<'a> {
} }
/// Declares that some type `T` is the next item in `bytes`. /// Declares that some type `T` is the next item in `bytes`.
pub fn register_type<T: Decodable>(&mut self) -> Result<(), DecodeError> { pub fn register_type<T: Decode>(&mut self) -> Result<(), DecodeError> {
if T::is_ssz_fixed_len() { if T::is_ssz_fixed_len() {
let start = self.items_index; let start = self.items_index;
self.items_index += T::ssz_fixed_len(); self.items_index += T::ssz_fixed_len();
@ -173,7 +173,7 @@ impl<'a> SszDecoderBuilder<'a> {
/// ///
/// ```rust /// ```rust
/// use ssz_derive::{Encode, Decode}; /// use ssz_derive::{Encode, Decode};
/// use ssz::{Decodable, Encodable, SszDecoder, SszDecoderBuilder}; /// use ssz::{Decode, Encode, SszDecoder, SszDecoderBuilder};
/// ///
/// #[derive(PartialEq, Debug, Encode, Decode)] /// #[derive(PartialEq, Debug, Encode, Decode)]
/// struct Foo { /// struct Foo {
@ -215,7 +215,7 @@ impl<'a> SszDecoder<'a> {
/// # Panics /// # Panics
/// ///
/// Panics when attempting to decode more items than actually exist. /// Panics when attempting to decode more items than actually exist.
pub fn decode_next<T: Decodable>(&mut self) -> Result<T, DecodeError> { pub fn decode_next<T: Decode>(&mut self) -> Result<T, DecodeError> {
T::from_ssz_bytes(self.items.remove(0)) T::from_ssz_bytes(self.items.remove(0))
} }
} }

View File

@ -3,7 +3,7 @@ use ethereum_types::H256;
macro_rules! impl_decodable_for_uint { macro_rules! impl_decodable_for_uint {
($type: ident, $bit_size: expr) => { ($type: ident, $bit_size: expr) => {
impl Decodable for $type { impl Decode for $type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -14,7 +14,7 @@ macro_rules! impl_decodable_for_uint {
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
let len = bytes.len(); let len = bytes.len();
let expected = <Self as Decodable>::ssz_fixed_len(); let expected = <Self as Decode>::ssz_fixed_len();
if len != expected { if len != expected {
Err(DecodeError::InvalidByteLength { len, expected }) Err(DecodeError::InvalidByteLength { len, expected })
@ -35,7 +35,7 @@ impl_decodable_for_uint!(u32, 32);
impl_decodable_for_uint!(u64, 64); impl_decodable_for_uint!(u64, 64);
impl_decodable_for_uint!(usize, 64); impl_decodable_for_uint!(usize, 64);
impl Decodable for bool { impl Decode for bool {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -46,7 +46,7 @@ impl Decodable for bool {
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
let len = bytes.len(); let len = bytes.len();
let expected = <Self as Decodable>::ssz_fixed_len(); let expected = <Self as Decode>::ssz_fixed_len();
if len != expected { if len != expected {
Err(DecodeError::InvalidByteLength { len, expected }) Err(DecodeError::InvalidByteLength { len, expected })
@ -64,7 +64,7 @@ impl Decodable for bool {
} }
} }
impl Decodable for H256 { impl Decode for H256 {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -75,7 +75,7 @@ impl Decodable for H256 {
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
let len = bytes.len(); let len = bytes.len();
let expected = <Self as Decodable>::ssz_fixed_len(); let expected = <Self as Decode>::ssz_fixed_len();
if len != expected { if len != expected {
Err(DecodeError::InvalidByteLength { len, expected }) Err(DecodeError::InvalidByteLength { len, expected })
@ -87,7 +87,7 @@ impl Decodable for H256 {
macro_rules! impl_decodable_for_u8_array { macro_rules! impl_decodable_for_u8_array {
($len: expr) => { ($len: expr) => {
impl Decodable for [u8; $len] { impl Decode for [u8; $len] {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -98,7 +98,7 @@ macro_rules! impl_decodable_for_u8_array {
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
let len = bytes.len(); let len = bytes.len();
let expected = <Self as Decodable>::ssz_fixed_len(); let expected = <Self as Decode>::ssz_fixed_len();
if len != expected { if len != expected {
Err(DecodeError::InvalidByteLength { len, expected }) Err(DecodeError::InvalidByteLength { len, expected })
@ -115,7 +115,7 @@ macro_rules! impl_decodable_for_u8_array {
impl_decodable_for_u8_array!(4); impl_decodable_for_u8_array!(4);
impl<T: Decodable> Decodable for Vec<T> { impl<T: Decode> Decode for Vec<T> {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }
@ -139,7 +139,7 @@ impl<T: Decodable> Decodable for Vec<T> {
/// The `ssz::SszDecoder` can also perform this functionality, however it it significantly faster /// The `ssz::SszDecoder` can also perform this functionality, however it it significantly faster
/// as it is optimized to read same-typed items whilst `ssz::SszDecoder` supports reading items of /// as it is optimized to read same-typed items whilst `ssz::SszDecoder` supports reading items of
/// differing types. /// differing types.
pub fn decode_list_of_variable_length_items<T: Decodable>( pub fn decode_list_of_variable_length_items<T: Decode>(
bytes: &[u8], bytes: &[u8],
) -> Result<Vec<T>, DecodeError> { ) -> Result<Vec<T>, DecodeError> {
let mut next_variable_byte = read_offset(bytes)?; let mut next_variable_byte = read_offset(bytes)?;

View File

@ -6,7 +6,7 @@ mod impls;
/// ///
/// See `examples/` for manual implementations or the crate root for implementations using /// See `examples/` for manual implementations or the crate root for implementations using
/// `#[derive(Encode)]`. /// `#[derive(Encode)]`.
pub trait Encodable { pub trait Encode {
/// Returns `true` if this object has a fixed-length. /// Returns `true` if this object has a fixed-length.
/// ///
/// I.e., there are no variable length items in this object or any of it's contained objects. /// I.e., there are no variable length items in this object or any of it's contained objects.
@ -50,7 +50,7 @@ pub trait Encodable {
/// ///
/// ```rust /// ```rust
/// use ssz_derive::{Encode, Decode}; /// use ssz_derive::{Encode, Decode};
/// use ssz::{Decodable, Encodable, SszEncoder}; /// use ssz::{Decode, Encode, SszEncoder};
/// ///
/// #[derive(PartialEq, Debug, Encode, Decode)] /// #[derive(PartialEq, Debug, Encode, Decode)]
/// struct Foo { /// struct Foo {
@ -65,7 +65,7 @@ pub trait Encodable {
/// }; /// };
/// ///
/// let mut buf: Vec<u8> = vec![]; /// let mut buf: Vec<u8> = vec![];
/// let offset = <u64 as Encodable>::ssz_fixed_len() + <Vec<u16> as Encodable>::ssz_fixed_len(); /// let offset = <u64 as Encode>::ssz_fixed_len() + <Vec<u16> as Encode>::ssz_fixed_len();
/// ///
/// let mut encoder = SszEncoder::container(&mut buf, offset); /// let mut encoder = SszEncoder::container(&mut buf, offset);
/// ///
@ -104,7 +104,7 @@ impl<'a> SszEncoder<'a> {
} }
/// Append some `item` to the SSZ bytes. /// Append some `item` to the SSZ bytes.
pub fn append<T: Encodable>(&mut self, item: &T) { pub fn append<T: Encode>(&mut self, item: &T) {
if T::is_ssz_fixed_len() { if T::is_ssz_fixed_len() {
item.ssz_append(&mut self.buf); item.ssz_append(&mut self.buf);
} else { } else {

View File

@ -3,7 +3,7 @@ use ethereum_types::H256;
macro_rules! impl_encodable_for_uint { macro_rules! impl_encodable_for_uint {
($type: ident, $bit_size: expr) => { ($type: ident, $bit_size: expr) => {
impl Encodable for $type { impl Encode for $type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -25,7 +25,7 @@ impl_encodable_for_uint!(u32, 32);
impl_encodable_for_uint!(u64, 64); impl_encodable_for_uint!(u64, 64);
impl_encodable_for_uint!(usize, 64); impl_encodable_for_uint!(usize, 64);
impl<T: Encodable> Encodable for Vec<T> { impl<T: Encode> Encode for Vec<T> {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
false false
} }
@ -49,7 +49,7 @@ impl<T: Encodable> Encodable for Vec<T> {
} }
} }
impl Encodable for bool { impl Encode for bool {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -63,7 +63,7 @@ impl Encodable for bool {
} }
} }
impl Encodable for H256 { impl Encode for H256 {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }
@ -79,7 +79,7 @@ impl Encodable for H256 {
macro_rules! impl_encodable_for_u8_array { macro_rules! impl_encodable_for_u8_array {
($len: expr) => { ($len: expr) => {
impl Encodable for [u8; $len] { impl Encode for [u8; $len] {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
true true
} }

View File

@ -9,7 +9,7 @@
//! //!
//! ```rust //! ```rust
//! use ssz_derive::{Encode, Decode}; //! use ssz_derive::{Encode, Decode};
//! use ssz::{Decodable, Encodable}; //! use ssz::{Decode, Encode};
//! //!
//! #[derive(PartialEq, Debug, Encode, Decode)] //! #[derive(PartialEq, Debug, Encode, Decode)]
//! struct Foo { //! struct Foo {
@ -32,17 +32,16 @@
//! //!
//! ``` //! ```
//! //!
//! See `examples/` for manual implementations of the `Encodable` and `Decodable` traits. //! See `examples/` for manual implementations of the `Encode` and `Decode` traits.
mod decode; mod decode;
mod encode; mod encode;
mod macros; mod macros;
pub use decode::{ pub use decode::{
impls::decode_list_of_variable_length_items, Decodable, DecodeError, SszDecoder, impls::decode_list_of_variable_length_items, Decode, DecodeError, SszDecoder, SszDecoderBuilder,
SszDecoderBuilder,
}; };
pub use encode::{Encodable, SszEncoder}; pub use encode::{Encode, SszEncoder};
/// The number of bytes used to represent an offset. /// The number of bytes used to represent an offset.
pub const BYTES_PER_LENGTH_OFFSET: usize = 4; pub const BYTES_PER_LENGTH_OFFSET: usize = 4;
@ -54,7 +53,7 @@ pub const MAX_LENGTH_VALUE: usize = (1 << (BYTES_PER_LENGTH_OFFSET * 8)) - 1;
/// Equivalent to `val.as_ssz_bytes()`. /// Equivalent to `val.as_ssz_bytes()`.
pub fn ssz_encode<T>(val: &T) -> Vec<u8> pub fn ssz_encode<T>(val: &T) -> Vec<u8>
where where
T: Encodable, T: Encode,
{ {
val.as_ssz_bytes() val.as_ssz_bytes()
} }

View File

@ -1,18 +1,18 @@
/// Implements `Encodable` for `$impl_type` using an implementation of `From<$impl_type> for /// Implements `Encode` for `$impl_type` using an implementation of `From<$impl_type> for
/// $from_type`. /// $from_type`.
/// ///
/// In effect, this allows for easy implementation of `Encodable` for some type that implements a /// In effect, this allows for easy implementation of `Encode` for some type that implements a
/// `From` conversion into another type that already has `Encodable` implemented. /// `From` conversion into another type that already has `Encode` implemented.
#[macro_export] #[macro_export]
macro_rules! impl_encode_via_from { macro_rules! impl_encode_via_from {
($impl_type: ty, $from_type: ty) => { ($impl_type: ty, $from_type: ty) => {
impl ssz::Encodable for $impl_type { impl ssz::Encode for $impl_type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
<$from_type as ssz::Encodable>::is_ssz_fixed_len() <$from_type as ssz::Encode>::is_ssz_fixed_len()
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
<$from_type as ssz::Encodable>::ssz_fixed_len() <$from_type as ssz::Encode>::ssz_fixed_len()
} }
fn ssz_append(&self, buf: &mut Vec<u8>) { fn ssz_append(&self, buf: &mut Vec<u8>) {
@ -24,21 +24,21 @@ macro_rules! impl_encode_via_from {
}; };
} }
/// Implements `Decodable` for `$impl_type` using an implementation of `From<$impl_type> for /// Implements `Decode` for `$impl_type` using an implementation of `From<$impl_type> for
/// $from_type`. /// $from_type`.
/// ///
/// In effect, this allows for easy implementation of `Decodable` for some type that implements a /// In effect, this allows for easy implementation of `Decode` for some type that implements a
/// `From` conversion into another type that already has `Decodable` implemented. /// `From` conversion into another type that already has `Decode` implemented.
#[macro_export] #[macro_export]
macro_rules! impl_decode_via_from { macro_rules! impl_decode_via_from {
($impl_type: ty, $from_type: tt) => { ($impl_type: ty, $from_type: tt) => {
impl ssz::Decodable for $impl_type { impl ssz::Decode for $impl_type {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
<$from_type as ssz::Decodable>::is_ssz_fixed_len() <$from_type as ssz::Decode>::is_ssz_fixed_len()
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
<$from_type as ssz::Decodable>::ssz_fixed_len() <$from_type as ssz::Decode>::ssz_fixed_len()
} }
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, ssz::DecodeError> { fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, ssz::DecodeError> {
@ -51,7 +51,7 @@ macro_rules! impl_decode_via_from {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate as ssz; use crate as ssz;
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
#[derive(PartialEq, Debug, Clone, Copy)] #[derive(PartialEq, Debug, Clone, Copy)]
struct Wrapper(u64); struct Wrapper(u64);

View File

@ -1,11 +1,11 @@
use ethereum_types::H256; use ethereum_types::H256;
use ssz::{Decodable, DecodeError, Encodable}; use ssz::{Decode, DecodeError, Encode};
use ssz_derive::{Decode, Encode}; use ssz_derive::{Decode, Encode};
mod round_trip { mod round_trip {
use super::*; use super::*;
fn round_trip<T: Encodable + Decodable + std::fmt::Debug + PartialEq>(items: Vec<T>) { fn round_trip<T: Encode + Decode + std::fmt::Debug + PartialEq>(items: Vec<T>) {
for item in items { for item in items {
let encoded = &item.as_ssz_bytes(); let encoded = &item.as_ssz_bytes();
assert_eq!(T::from_ssz_bytes(&encoded), Ok(item)); assert_eq!(T::from_ssz_bytes(&encoded), Ok(item));

View File

@ -64,7 +64,7 @@ fn should_skip_serializing(field: &syn::Field) -> bool {
false false
} }
/// Implements `ssz::Encodable` for some `struct`. /// Implements `ssz::Encode` for some `struct`.
/// ///
/// Fields are encoded in the order they are defined. /// Fields are encoded in the order they are defined.
#[proc_macro_derive(Encode, attributes(ssz))] #[proc_macro_derive(Encode, attributes(ssz))]
@ -85,18 +85,18 @@ pub fn ssz_encode_derive(input: TokenStream) -> TokenStream {
let field_types_c = field_types_a.clone(); let field_types_c = field_types_a.clone();
let output = quote! { let output = quote! {
impl #impl_generics ssz::Encodable for #name #ty_generics #where_clause { impl #impl_generics ssz::Encode for #name #ty_generics #where_clause {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
#( #(
<#field_types_a as ssz::Encodable>::is_ssz_fixed_len() && <#field_types_a as ssz::Encode>::is_ssz_fixed_len() &&
)* )*
true true
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
if <Self as ssz::Encodable>::is_ssz_fixed_len() { if <Self as ssz::Encode>::is_ssz_fixed_len() {
#( #(
<#field_types_b as ssz::Encodable>::ssz_fixed_len() + <#field_types_b as ssz::Encode>::ssz_fixed_len() +
)* )*
0 0
} else { } else {
@ -106,7 +106,7 @@ pub fn ssz_encode_derive(input: TokenStream) -> TokenStream {
fn ssz_append(&self, buf: &mut Vec<u8>) { fn ssz_append(&self, buf: &mut Vec<u8>) {
let offset = #( let offset = #(
<#field_types_c as ssz::Encodable>::ssz_fixed_len() + <#field_types_c as ssz::Encode>::ssz_fixed_len() +
)* )*
0; 0;
@ -135,7 +135,7 @@ fn should_skip_deserializing(field: &syn::Field) -> bool {
false false
} }
/// Implements `ssz::Decodable` for some `struct`. /// Implements `ssz::Decode` for some `struct`.
/// ///
/// Fields are decoded in the order they are defined. /// Fields are decoded in the order they are defined.
#[proc_macro_derive(Decode)] #[proc_macro_derive(Decode)]
@ -177,11 +177,11 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
}); });
is_fixed_lens.push(quote! { is_fixed_lens.push(quote! {
<#ty as ssz::Decodable>::is_ssz_fixed_len() <#ty as ssz::Decode>::is_ssz_fixed_len()
}); });
fixed_lens.push(quote! { fixed_lens.push(quote! {
<#ty as ssz::Decodable>::ssz_fixed_len() <#ty as ssz::Decode>::ssz_fixed_len()
}); });
} }
} }
@ -190,7 +190,7 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
} }
let output = quote! { let output = quote! {
impl #impl_generics ssz::Decodable for #name #ty_generics #where_clause { impl #impl_generics ssz::Decode for #name #ty_generics #where_clause {
fn is_ssz_fixed_len() -> bool { fn is_ssz_fixed_len() -> bool {
#( #(
#is_fixed_lens && #is_fixed_lens &&
@ -199,7 +199,7 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream {
} }
fn ssz_fixed_len() -> usize { fn ssz_fixed_len() -> usize {
if <Self as ssz::Decodable>::is_ssz_fixed_len() { if <Self as ssz::Decode>::is_ssz_fixed_len() {
#( #(
#fixed_lens + #fixed_lens +
)* )*

View File

@ -1,4 +1,4 @@
use ssz::Encodable; use ssz::Encode;
use ssz_derive::Encode; use ssz_derive::Encode;
#[derive(Debug, PartialEq, Encode)] #[derive(Debug, PartialEq, Encode)]

View File

@ -1,7 +1,7 @@
use super::beacon_node_attestation::BeaconNodeAttestation; use super::beacon_node_attestation::BeaconNodeAttestation;
use crate::block_producer::{BeaconNodeError, PublishOutcome}; use crate::block_producer::{BeaconNodeError, PublishOutcome};
use protos::services_grpc::AttestationServiceClient; use protos::services_grpc::AttestationServiceClient;
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
use protos::services::{ use protos::services::{
Attestation as GrpcAttestation, ProduceAttestationDataRequest, PublishAttestationRequest, Attestation as GrpcAttestation, ProduceAttestationDataRequest, PublishAttestationRequest,

View File

@ -3,7 +3,7 @@ use protos::services::{
BeaconBlock as GrpcBeaconBlock, ProduceBeaconBlockRequest, PublishBeaconBlockRequest, BeaconBlock as GrpcBeaconBlock, ProduceBeaconBlockRequest, PublishBeaconBlockRequest,
}; };
use protos::services_grpc::BeaconBlockServiceClient; use protos::services_grpc::BeaconBlockServiceClient;
use ssz::{Decodable, Encodable}; use ssz::{Decode, Encode};
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconBlock, Signature, Slot}; use types::{BeaconBlock, Signature, Slot};