pub(super) fn new(
        swunit: SignedWireUnit<C>,
        fork_choice: Option<&C::Hash>,
        state: &State<C>,
    ) -> (Unit<C>, Option<C::ConsensusValue>) {
        let SignedWireUnit {
            hashed_wire_unit,
            signature,
        } = swunit;
        let hash = hashed_wire_unit.hash();
        let wunit = hashed_wire_unit.into_inner();
        let block = if wunit.value.is_some() {
            hash // A unit with a new block votes for itself.
        } else {
            // If the unit didn't introduce a new block, it votes for the fork choice itself.
            // `pre_validate_unit` checks that the panorama has a `Correct` entry.
            fork_choice
                .cloned()
                .expect("nonempty panorama has nonempty fork choice")
        };
        let mut skip_idx = Vec::new();
        if let Some(hash) = wunit.panorama[wunit.creator].correct() {
            skip_idx.push(*hash);
            for i in 0..wunit.seq_number.trailing_zeros() as usize {
                let old_unit = state.unit(&skip_idx[i]);
                skip_idx.push(old_unit.skip_idx[i]);
            }
        }
        let unit = Unit {
            panorama: wunit.panorama,
            seq_number: wunit.seq_number,
            creator: wunit.creator,
            block,
            skip_idx,
            timestamp: wunit.timestamp,
            signature,
            round_exp: wunit.round_exp,
            endorsed: wunit.endorsed,
        };
        (unit, wunit.value)
    }
/// Creates a new `Unit` from the `WireUnit`, and returns the value if it contained any.
/// Values must be stored as a block, with the same hash.
Creates a new `Unit` from the `WireUnit`, and returns the value if it contained any.
Values must be stored as a block, with the same hash.
Creates a new ` Unit ` from the ` WireUnit ` and returns the value if it contained any . Values must be stored as a block with the same hash .
pub(super) fn new(
        swunit: SignedWireUnit<C>,
        fork_choice: Option<&C::Hash>,
        state: &State<C>,
    ) -> (Unit<C>, Option<C::ConsensusValue>) {
        let SignedWireUnit {
            hashed_wire_unit,
            signature,
        } = swunit;
        let hash = hashed_wire_unit.hash();
        let wunit = hashed_wire_unit.into_inner();
        let block = if wunit.value.is_some() {
            hash // A unit with a new block votes for itself.
        } else {
            // If the unit didn't introduce a new block, it votes for the fork choice itself.
            // `pre_validate_unit` checks that the panorama has a `Correct` entry.
            fork_choice
                .cloned()
                .expect("nonempty panorama has nonempty fork choice")
        };
        let mut skip_idx = Vec::new();
        if let Some(hash) = wunit.panorama[wunit.creator].correct() {
            skip_idx.push(*hash);
            for i in 0..wunit.seq_number.trailing_zeros() as usize {
                let old_unit = state.unit(&skip_idx[i]);
                skip_idx.push(old_unit.skip_idx[i]);
            }
        }
        let unit = Unit {
            panorama: wunit.panorama,
            seq_number: wunit.seq_number,
            creator: wunit.creator,
            block,
            skip_idx,
            timestamp: wunit.timestamp,
            signature,
            round_exp: wunit.round_exp,
            endorsed: wunit.endorsed,
        };
        (unit, wunit.value)
    }
pub ( super ) fn new ( swunit : SignedWireUnit < C > , fork_choice : Option < & C :: Hash > , state : & State < C > , ) -> ( Unit < C > , Option < C :: ConsensusValue > ) { let SignedWireUnit { hashed_wire_unit , signature , } = swunit ; let hash = hashed_wire_unit . hash ( ) ; let wunit = hashed_wire_unit . into_inner ( ) ; let block = if wunit . value . is_some ( ) { hash // A unit with a new block votes for itself. } else { // If the unit didn't introduce a new block, it votes for the fork choice itself. // `pre_validate_unit` checks that the panorama has a `Correct` entry. fork_choice . cloned ( ) . expect ( " " ) } ; let mut skip_idx = Vec :: new ( ) ; if let Some ( hash ) = wunit . panorama [ wunit . creator ] . correct ( ) { skip_idx . push ( * hash ) ; for i in 0 .. wunit . seq_number . trailing_zeros ( ) as usize { let old_unit = state . unit ( & skip_idx [ i ] ) ; skip_idx . push ( old_unit . skip_idx [ i ] ) ; } } let unit = Unit { panorama : wunit . panorama , seq_number : wunit . seq_number , creator : wunit . creator , block , skip_idx , timestamp : wunit . timestamp , signature , round_exp : wunit . round_exp , endorsed : wunit . endorsed , } ; ( unit , wunit . value ) }
Creates a new `Unit` from the `WireUnit`, and returns the value if it contained any.
Creates a new ` Unit ` from the ` WireUnit ` and returns the value if it contained any .
swunit
SignedWireUnit<C>
fork_choice
Option<&C::Hash>
state
&State<C>
swunit
SignedWireUnit<C>
fork_choice
Option<&C::Hash>
state
&State<C>