mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 12:47:05 +00:00
Clean up
This commit is contained in:
@@ -47,6 +47,7 @@ pub use payload::{
|
|||||||
};
|
};
|
||||||
pub use signed_bls_to_execution_change::SignedBlsToExecutionChange;
|
pub use signed_bls_to_execution_change::SignedBlsToExecutionChange;
|
||||||
pub use signed_execution_payload_bid::{
|
pub use signed_execution_payload_bid::{
|
||||||
SignedExecutionPayloadBidGloas, SignedExecutionPayloadBidHeze, SignedExecutionPayloadBidRef,
|
SignedExecutionPayloadBid, SignedExecutionPayloadBidGloas, SignedExecutionPayloadBidHeze,
|
||||||
|
SignedExecutionPayloadBidRef,
|
||||||
};
|
};
|
||||||
pub use signed_execution_payload_envelope::SignedExecutionPayloadEnvelope;
|
pub use signed_execution_payload_envelope::SignedExecutionPayloadEnvelope;
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::execution::{ExecutionPayloadBidGloas, ExecutionPayloadBidHeze, ExecutionPayloadBidRef};
|
use crate::execution::{
|
||||||
|
ExecutionPayloadBid, ExecutionPayloadBidGloas, ExecutionPayloadBidHeze, ExecutionPayloadBidRef,
|
||||||
|
};
|
||||||
|
use crate::state::BeaconStateError;
|
||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use crate::{EthSpec, ForkName};
|
use crate::{EthSpec, ForkName};
|
||||||
use bls::Signature;
|
use bls::Signature;
|
||||||
@@ -6,23 +9,92 @@ use context_deserialize::context_deserialize;
|
|||||||
use educe::Educe;
|
use educe::Educe;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
|
use superstruct::superstruct;
|
||||||
use test_random_derive::TestRandom;
|
use test_random_derive::TestRandom;
|
||||||
use tree_hash_derive::TreeHash;
|
use tree_hash_derive::TreeHash;
|
||||||
|
|
||||||
#[derive(TestRandom, TreeHash, Debug, Clone, Encode, Decode, Serialize, Deserialize, Educe)]
|
#[superstruct(
|
||||||
|
variants(Gloas, Heze),
|
||||||
|
variant_attributes(
|
||||||
|
derive(
|
||||||
|
Debug,
|
||||||
|
Clone,
|
||||||
|
Serialize,
|
||||||
|
Deserialize,
|
||||||
|
Encode,
|
||||||
|
Decode,
|
||||||
|
TestRandom,
|
||||||
|
TreeHash,
|
||||||
|
Educe,
|
||||||
|
),
|
||||||
|
educe(PartialEq, Hash(bound(E: EthSpec))),
|
||||||
|
context_deserialize(ForkName),
|
||||||
|
serde(bound = "E: EthSpec"),
|
||||||
|
cfg_attr(
|
||||||
|
feature = "arbitrary",
|
||||||
|
derive(arbitrary::Arbitrary),
|
||||||
|
arbitrary(bound = "E: EthSpec"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
cast_error(
|
||||||
|
ty = "BeaconStateError",
|
||||||
|
expr = "BeaconStateError::IncorrectStateVariant"
|
||||||
|
),
|
||||||
|
partial_getter_error(
|
||||||
|
ty = "BeaconStateError",
|
||||||
|
expr = "BeaconStateError::IncorrectStateVariant"
|
||||||
|
),
|
||||||
|
map_ref_into(ExecutionPayloadBidRef)
|
||||||
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "arbitrary",
|
feature = "arbitrary",
|
||||||
derive(arbitrary::Arbitrary),
|
derive(arbitrary::Arbitrary),
|
||||||
arbitrary(bound = "E: EthSpec")
|
arbitrary(bound = "E: EthSpec")
|
||||||
)]
|
)]
|
||||||
#[educe(PartialEq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, TreeHash)]
|
||||||
#[serde(bound = "E: EthSpec")]
|
#[serde(untagged)]
|
||||||
#[context_deserialize(ForkName)]
|
#[tree_hash(enum_behaviour = "transparent")]
|
||||||
pub struct SignedExecutionPayloadBidGloas<E: EthSpec> {
|
#[ssz(enum_behaviour = "transparent")]
|
||||||
pub message: ExecutionPayloadBidGloas<E>,
|
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||||
|
pub struct SignedExecutionPayloadBid<E: EthSpec> {
|
||||||
|
#[superstruct(flatten)]
|
||||||
|
pub message: ExecutionPayloadBid<E>,
|
||||||
pub signature: Signature,
|
pub signature: Signature,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: EthSpec> SignedExecutionPayloadBid<E> {
|
||||||
|
pub fn message(&self) -> ExecutionPayloadBidRef<'_, E> {
|
||||||
|
match self {
|
||||||
|
Self::Gloas(inner) => ExecutionPayloadBidRef::Gloas(&inner.message),
|
||||||
|
Self::Heze(inner) => ExecutionPayloadBidRef::Heze(&inner.message),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn empty_gloas() -> Self {
|
||||||
|
Self::Gloas(SignedExecutionPayloadBidGloas {
|
||||||
|
message: ExecutionPayloadBidGloas::default(),
|
||||||
|
signature: Signature::empty(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn empty_heze() -> Self {
|
||||||
|
Self::Heze(SignedExecutionPayloadBidHeze {
|
||||||
|
message: ExecutionPayloadBidHeze::default(),
|
||||||
|
signature: Signature::empty(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, E: EthSpec> SignedExecutionPayloadBidRef<'a, E> {
|
||||||
|
pub fn message(&self) -> ExecutionPayloadBidRef<'a, E> {
|
||||||
|
map_signed_execution_payload_bid_ref_into_execution_payload_bid_ref!(
|
||||||
|
&'a _,
|
||||||
|
*self,
|
||||||
|
|inner, cons| { cons(&inner.message) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> SignedExecutionPayloadBidGloas<E> {
|
impl<E: EthSpec> SignedExecutionPayloadBidGloas<E> {
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -32,20 +104,6 @@ impl<E: EthSpec> SignedExecutionPayloadBidGloas<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TestRandom, TreeHash, Debug, Clone, Encode, Decode, Serialize, Deserialize, Educe)]
|
|
||||||
#[cfg_attr(
|
|
||||||
feature = "arbitrary",
|
|
||||||
derive(arbitrary::Arbitrary),
|
|
||||||
arbitrary(bound = "E: EthSpec")
|
|
||||||
)]
|
|
||||||
#[educe(PartialEq, Hash)]
|
|
||||||
#[serde(bound = "E: EthSpec")]
|
|
||||||
#[context_deserialize(ForkName)]
|
|
||||||
pub struct SignedExecutionPayloadBidHeze<E: EthSpec> {
|
|
||||||
pub message: ExecutionPayloadBidHeze<E>,
|
|
||||||
pub signature: Signature,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: EthSpec> SignedExecutionPayloadBidHeze<E> {
|
impl<E: EthSpec> SignedExecutionPayloadBidHeze<E> {
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -55,27 +113,6 @@ impl<E: EthSpec> SignedExecutionPayloadBidHeze<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SignedExecutionPayloadBidRef<'a, E: EthSpec> {
|
|
||||||
Gloas(&'a SignedExecutionPayloadBidGloas<E>),
|
|
||||||
Heze(&'a SignedExecutionPayloadBidHeze<E>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, E: EthSpec> SignedExecutionPayloadBidRef<'a, E> {
|
|
||||||
pub fn message(&self) -> ExecutionPayloadBidRef<'a, E> {
|
|
||||||
match self {
|
|
||||||
Self::Gloas(inner) => ExecutionPayloadBidRef::Gloas(&inner.message),
|
|
||||||
Self::Heze(inner) => ExecutionPayloadBidRef::Heze(&inner.message),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn signature(&self) -> &'a Signature {
|
|
||||||
match self {
|
|
||||||
Self::Gloas(inner) => &inner.signature,
|
|
||||||
Self::Heze(inner) => &inner.signature,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user