Skip to content

Commit

Permalink
type-gen: also support immutable refs from mutable polymorphic ref types
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Oct 11, 2023
1 parent a320fad commit 72ea4d5
Show file tree
Hide file tree
Showing 8 changed files with 1,366 additions and 2 deletions.
168 changes: 168 additions & 0 deletions ethereum-consensus/src/types/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,23 @@ impl<
MAX_BLOB_COMMITMENTS_PER_BLOCK,
>
{
pub fn phase0(
&self,
) -> Option<
&phase0::BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
>,
> {
match self {
Self::Phase0(inner) => Some(inner),
_ => None,
}
}
pub fn phase0_mut(
&mut self,
) -> Option<
Expand All @@ -1303,6 +1320,24 @@ impl<
_ => None,
}
}
pub fn altair(
&self,
) -> Option<
&altair::BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
>,
> {
match self {
Self::Altair(inner) => Some(inner),
_ => None,
}
}
pub fn altair_mut(
&mut self,
) -> Option<
Expand All @@ -1321,6 +1356,28 @@ impl<
_ => None,
}
}
pub fn bellatrix(
&self,
) -> Option<
&bellatrix::BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
> {
match self {
Self::Bellatrix(inner) => Some(inner),
_ => None,
}
}
pub fn bellatrix_mut(
&mut self,
) -> Option<
Expand All @@ -1343,6 +1400,30 @@ impl<
_ => None,
}
}
pub fn capella(
&self,
) -> Option<
&capella::BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
>,
> {
match self {
Self::Capella(inner) => Some(inner),
_ => None,
}
}
pub fn capella_mut(
&mut self,
) -> Option<
Expand All @@ -1367,6 +1448,31 @@ impl<
_ => None,
}
}
pub fn deneb(
&self,
) -> Option<
&deneb::BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
MAX_BLOB_COMMITMENTS_PER_BLOCK,
>,
> {
match self {
Self::Deneb(inner) => Some(inner),
_ => None,
}
}
pub fn deneb_mut(
&mut self,
) -> Option<
Expand Down Expand Up @@ -1401,6 +1507,15 @@ impl<
Self::Deneb(_) => Version::Deneb,
}
}
pub fn slot(&self) -> &Slot {
match self {
Self::Phase0(inner) => &inner.slot,
Self::Altair(inner) => &inner.slot,
Self::Bellatrix(inner) => &inner.slot,
Self::Capella(inner) => &inner.slot,
Self::Deneb(inner) => &inner.slot,
}
}
pub fn slot_mut(&mut self) -> &mut Slot {
match self {
Self::Phase0(inner) => &mut inner.slot,
Expand All @@ -1410,6 +1525,15 @@ impl<
Self::Deneb(inner) => &mut inner.slot,
}
}
pub fn proposer_index(&self) -> &ValidatorIndex {
match self {
Self::Phase0(inner) => &inner.proposer_index,
Self::Altair(inner) => &inner.proposer_index,
Self::Bellatrix(inner) => &inner.proposer_index,
Self::Capella(inner) => &inner.proposer_index,
Self::Deneb(inner) => &inner.proposer_index,
}
}
pub fn proposer_index_mut(&mut self) -> &mut ValidatorIndex {
match self {
Self::Phase0(inner) => &mut inner.proposer_index,
Expand All @@ -1419,6 +1543,15 @@ impl<
Self::Deneb(inner) => &mut inner.proposer_index,
}
}
pub fn parent_root(&self) -> &Root {
match self {
Self::Phase0(inner) => &inner.parent_root,
Self::Altair(inner) => &inner.parent_root,
Self::Bellatrix(inner) => &inner.parent_root,
Self::Capella(inner) => &inner.parent_root,
Self::Deneb(inner) => &inner.parent_root,
}
}
pub fn parent_root_mut(&mut self) -> &mut Root {
match self {
Self::Phase0(inner) => &mut inner.parent_root,
Expand All @@ -1428,6 +1561,15 @@ impl<
Self::Deneb(inner) => &mut inner.parent_root,
}
}
pub fn state_root(&self) -> &Root {
match self {
Self::Phase0(inner) => &inner.state_root,
Self::Altair(inner) => &inner.state_root,
Self::Bellatrix(inner) => &inner.state_root,
Self::Capella(inner) => &inner.state_root,
Self::Deneb(inner) => &inner.state_root,
}
}
pub fn state_root_mut(&mut self) -> &mut Root {
match self {
Self::Phase0(inner) => &mut inner.state_root,
Expand All @@ -1437,6 +1579,32 @@ impl<
Self::Deneb(inner) => &mut inner.state_root,
}
}
pub fn body(
&self,
) -> BeaconBlockBodyRef<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
MAX_BLOB_COMMITMENTS_PER_BLOCK,
> {
match self {
Self::Phase0(inner) => From::from(&inner.body),
Self::Altair(inner) => From::from(&inner.body),
Self::Bellatrix(inner) => From::from(&inner.body),
Self::Capella(inner) => From::from(&inner.body),
Self::Deneb(inner) => From::from(&inner.body),
}
}
pub fn body_mut(
&mut self,
) -> BeaconBlockBodyRefMut<
Expand Down
Loading

0 comments on commit 72ea4d5

Please sign in to comment.