pub fn apply_block<'a, I>(
        &'a self,
        ledger_params: &LedgerParameters,
        contents: I,
        metadata: &HeaderContentEvalContext,
    ) -> Result<Self, Error>
    where
        I: IntoIterator<Item = &'a Message>,
    {
        let mut new_ledger = self.clone();

        new_ledger.chain_length = self.chain_length.next();

        if metadata.chain_length != new_ledger.chain_length {
            return Err(Error::WrongChainLength {
                actual: metadata.chain_length,
                expected: new_ledger.chain_length,
            });
        }

        if metadata.block_date <= new_ledger.date {
            return Err(Error::NonMonotonicDate {
                block_date: metadata.block_date,
                chain_date: new_ledger.date,
            });
        }

        let (updates, settings) = new_ledger.updates.process_proposals(
            new_ledger.settings,
            new_ledger.date,
            metadata.block_date,
        )?;
        new_ledger.updates = updates;
        new_ledger.settings = settings;

        for content in contents {
            match content {
                Message::Initial(_) => return Err(Error::Block0(Block0Error::OnlyMessageReceived)),
                Message::OldUtxoDeclaration(_) => {
                    return Err(Error::Block0(Block0Error::OnlyMessageReceived))
                }
                Message::Transaction(authenticated_tx) => {
                    let (new_ledger_, _fee) =
                        new_ledger.apply_transaction(&authenticated_tx, &ledger_params)?;
                    new_ledger = new_ledger_;
                }
                Message::UpdateProposal(update_proposal) => {
                    new_ledger = new_ledger.apply_update_proposal(
                        content.id(),
                        &update_proposal,
                        metadata.block_date,
                    )?;
                }
                Message::UpdateVote(vote) => {
                    new_ledger = new_ledger.apply_update_vote(&vote)?;
                }
                Message::Certificate(authenticated_cert_tx) => {
                    let (new_ledger_, _fee) =
                        new_ledger.apply_certificate(authenticated_cert_tx, &ledger_params)?;
                    new_ledger = new_ledger_;
                }
            }
        }

        new_ledger.date = metadata.block_date;
        metadata
            .nonce
            .as_ref()
            .map(|n| new_ledger.settings.consensus_nonce.hash_with(n));
        Ok(new_ledger)
    }
/// Try to apply messages to a State, and return the new State if succesful
Try to apply messages to a State, and return the new State if succesful
Try to apply messages to a State and return the new State if succesful
pub fn apply_block<'a, I>(
        &'a self,
        ledger_params: &LedgerParameters,
        contents: I,
        metadata: &HeaderContentEvalContext,
    ) -> Result<Self, Error>
    where
        I: IntoIterator<Item = &'a Message>,
    {
        let mut new_ledger = self.clone();
        new_ledger.chain_length = self.chain_length.next();
        if metadata.chain_length != new_ledger.chain_length {
            return Err(Error::WrongChainLength {
                actual: metadata.chain_length,
                expected: new_ledger.chain_length,
            });
        }
        if metadata.block_date <= new_ledger.date {
            return Err(Error::NonMonotonicDate {
                block_date: metadata.block_date,
                chain_date: new_ledger.date,
            });
        }
        let (updates, settings) = new_ledger.updates.process_proposals(
            new_ledger.settings,
            new_ledger.date,
            metadata.block_date,
        )?;
        new_ledger.updates = updates;
        new_ledger.settings = settings;
        for content in contents {
            match content {
                Message::Initial(_) => return Err(Error::Block0(Block0Error::OnlyMessageReceived)),
                Message::OldUtxoDeclaration(_) => {
                    return Err(Error::Block0(Block0Error::OnlyMessageReceived))
                }
                Message::Transaction(authenticated_tx) => {
                    let (new_ledger_, _fee) =
                        new_ledger.apply_transaction(&authenticated_tx, &ledger_params)?;
                    new_ledger = new_ledger_;
                }
                Message::UpdateProposal(update_proposal) => {
                    new_ledger = new_ledger.apply_update_proposal(
                        content.id(),
                        &update_proposal,
                        metadata.block_date,
                    )?;
                }
                Message::UpdateVote(vote) => {
                    new_ledger = new_ledger.apply_update_vote(&vote)?;
                }
                Message::Certificate(authenticated_cert_tx) => {
                    let (new_ledger_, _fee) =
                        new_ledger.apply_certificate(authenticated_cert_tx, &ledger_params)?;
                    new_ledger = new_ledger_;
                }
            }
        }
        new_ledger.date = metadata.block_date;
        metadata
            .nonce
            .as_ref()
            .map(|n| new_ledger.settings.consensus_nonce.hash_with(n));
        Ok(new_ledger)
    }
pub fn apply_block < ' a , I > ( & ' a self , ledger_params : & LedgerParameters , contents : I , metadata : & HeaderContentEvalContext , ) -> Result < Self , Error > where I : IntoIterator < Item = & ' a Message > , { let mut new_ledger = self . clone ( ) ; new_ledger . chain_length = self . chain_length . next ( ) ; if metadata . chain_length != new_ledger . chain_length { return Err ( Error :: WrongChainLength { actual : metadata . chain_length , expected : new_ledger . chain_length , } ) ; } if metadata . block_date <= new_ledger . date { return Err ( Error :: NonMonotonicDate { block_date : metadata . block_date , chain_date : new_ledger . date , } ) ; } let ( updates , settings ) = new_ledger . updates . process_proposals ( new_ledger . settings , new_ledger . date , metadata . block_date , ) ? ; new_ledger . updates = updates ; new_ledger . settings = settings ; for content in contents { match content { Message :: Initial ( _ ) => return Err ( Error :: Block0 ( Block0Error :: OnlyMessageReceived ) ) , Message :: OldUtxoDeclaration ( _ ) => { return Err ( Error :: Block0 ( Block0Error :: OnlyMessageReceived ) ) } Message :: Transaction ( authenticated_tx ) => { let ( new_ledger_ , _fee ) = new_ledger . apply_transaction ( & authenticated_tx , & ledger_params ) ? ; new_ledger = new_ledger_ ; } Message :: UpdateProposal ( update_proposal ) => { new_ledger = new_ledger . apply_update_proposal ( content . id ( ) , & update_proposal , metadata . block_date , ) ? ; } Message :: UpdateVote ( vote ) => { new_ledger = new_ledger . apply_update_vote ( & vote ) ? ; } Message :: Certificate ( authenticated_cert_tx ) => { let ( new_ledger_ , _fee ) = new_ledger . apply_certificate ( authenticated_cert_tx , & ledger_params ) ? ; new_ledger = new_ledger_ ; } } } new_ledger . date = metadata . block_date ; metadata . nonce . as_ref ( ) . map ( | n | new_ledger . settings . consensus_nonce . hash_with ( n ) ) ; Ok ( new_ledger ) }
Try to apply messages to a State, and return the new State if succesful
Try to apply messages to a State and return the new State if succesful
&'a self
ledger_params
&LedgerParameters
contents
I
metadata
&HeaderContentEvalContext
&'a self
ledger_params
&LedgerParameters
contents
I
metadata
&HeaderContentEvalContext