@@ -2,103 +2,32 @@ use crate::test_utils::TestRandom;
22use crate :: * ;
33use beacon_block_body:: KzgCommitments ;
44use educe:: Educe ;
5- use serde:: de:: { Deserializer , Error as _} ;
65use serde:: { Deserialize , Serialize } ;
76use ssz_derive:: { Decode , Encode } ;
8- use superstruct:: superstruct;
97use test_random_derive:: TestRandom ;
108use tree_hash_derive:: TreeHash ;
119
12- // in all likelihood, this will be superstructed so might as well start early eh?
13- #[ superstruct(
14- variants( Gloas , NextFork ) ,
15- variant_attributes(
16- derive(
17- Debug ,
18- Clone ,
19- Serialize ,
20- Deserialize ,
21- Encode ,
22- Decode ,
23- TreeHash ,
24- TestRandom ,
25- Educe
26- ) ,
27- cfg_attr( feature = "arbitrary" , derive( arbitrary:: Arbitrary ) ) ,
28- educe( PartialEq , Hash ( bound( E : EthSpec ) ) ) ,
29- serde( bound = "E: EthSpec" , deny_unknown_fields) ,
30- cfg_attr( feature = "arbitrary" , arbitrary( bound = "E: EthSpec" ) )
31- ) ,
32- ref_attributes(
33- derive( Debug , PartialEq , TreeHash ) ,
34- tree_hash( enum_behaviour = "transparent" )
35- ) ,
36- cast_error( ty = "Error" , expr = "BeaconStateError::IncorrectStateVariant" ) ,
37- partial_getter_error( ty = "Error" , expr = "BeaconStateError::IncorrectStateVariant" )
38- ) ]
39- #[ derive( Debug , Clone , Serialize , Encode , Deserialize , TreeHash , Educe ) ]
10+ #[ derive( Debug , Clone , Serialize , Encode , Decode , Deserialize , TestRandom , TreeHash , Educe ) ]
4011#[ educe( PartialEq , Hash ( bound( E : EthSpec ) ) ) ]
41- #[ serde( bound = "E: EthSpec" , untagged) ]
42- #[ ssz( enum_behaviour = "transparent" ) ]
43- #[ tree_hash( enum_behaviour = "transparent" ) ]
12+ #[ context_deserialize( ForkName ) ]
13+ #[ serde( bound = "E: EthSpec" ) ]
4414pub struct ExecutionPayloadEnvelope < E : EthSpec > {
45- #[ superstruct( only( Gloas ) , partial_getter( rename = "payload_gloas" ) ) ]
46- pub payload : ExecutionPayloadGloas < E > ,
47- #[ superstruct( only( NextFork ) , partial_getter( rename = "payload_next_fork" ) ) ]
4815 pub payload : ExecutionPayloadGloas < E > ,
4916 pub execution_requests : ExecutionRequests < E > ,
5017 #[ serde( with = "serde_utils::quoted_u64" ) ]
51- #[ superstruct( getter( copy) ) ]
5218 pub builder_index : u64 ,
53- #[ superstruct( getter( copy) ) ]
5419 pub beacon_block_root : Hash256 ,
55- #[ superstruct( getter( copy) ) ]
5620 pub slot : Slot ,
5721 pub blob_kzg_commitments : KzgCommitments < E > ,
58- #[ superstruct( getter( copy) ) ]
5922 pub state_root : Hash256 ,
6023}
6124
6225impl < E : EthSpec > SignedRoot for ExecutionPayloadEnvelope < E > { }
63- impl < ' a , E : EthSpec > SignedRoot for ExecutionPayloadEnvelopeRef < ' a , E > { }
64-
65- impl < ' a , E : EthSpec > ExecutionPayloadEnvelopeRef < ' a , E > {
66- pub fn payload ( & self ) -> ExecutionPayloadRef < ' a , E > {
67- match self {
68- Self :: Gloas ( envelope) => ExecutionPayloadRef :: Gloas ( & envelope. payload ) ,
69- Self :: NextFork ( envelope) => ExecutionPayloadRef :: Gloas ( & envelope. payload ) ,
70- }
71- }
72- }
73-
74- impl < ' de , E : EthSpec > ContextDeserialize < ' de , ForkName > for ExecutionPayloadEnvelope < E > {
75- fn context_deserialize < D > ( deserializer : D , context : ForkName ) -> Result < Self , D :: Error >
76- where
77- D : Deserializer < ' de > ,
78- {
79- let value: Self = serde:: Deserialize :: deserialize ( deserializer) ?;
80-
81- match ( context, & value) {
82- ( ForkName :: Gloas , Self :: Gloas { .. } ) => Ok ( value) ,
83- _ => Err ( D :: Error :: custom ( format ! (
84- "ExecutionPayloadEnvelope does not support fork {context:?}"
85- ) ) ) ,
86- }
87- }
88- }
8926
9027#[ cfg( test) ]
9128mod tests {
9229 use super :: * ;
9330 use crate :: MainnetEthSpec ;
9431
95- mod gloas {
96- use super :: * ;
97- ssz_and_tree_hash_tests ! ( ExecutionPayloadEnvelopeGloas <MainnetEthSpec >) ;
98- }
99-
100- mod next_fork {
101- use super :: * ;
102- ssz_and_tree_hash_tests ! ( ExecutionPayloadEnvelopeNextFork <MainnetEthSpec >) ;
103- }
32+ ssz_and_tree_hash_tests ! ( ExecutionPayloadEnvelope <MainnetEthSpec >) ;
10433}
0 commit comments