pub fn attach_block(&self, block: packed::L2Block) -> Result<(), Error> {
        let raw = block.raw();
        let raw_number = raw.number();
        let block_hash = raw.hash();

        // build tx info
        for (index, tx) in block.transactions().into_iter().enumerate() {
            let key = TransactionKey::build_transaction_key(block_hash.pack(), index as u32);
            let info = packed::TransactionInfo::new_builder()
                .key(key)
                .block_number(raw_number.clone())
                .build();
            let tx_hash = tx.hash();
            self.insert_raw(COLUMN_TRANSACTION_INFO, &tx_hash, info.as_slice())?;
        }

        // build withdrawal info
        for (index, withdrawal) in block.withdrawals().into_iter().enumerate() {
            let key = WithdrawalKey::build_withdrawal_key(block_hash.pack(), index as u32);
            let info = packed::WithdrawalInfo::new_builder()
                .key(key)
                .block_number(raw_number.clone())
                .build();
            let withdrawal_hash = withdrawal.hash();
            self.insert_raw(COLUMN_WITHDRAWAL_INFO, &withdrawal_hash, info.as_slice())?;
        }

        // build main chain index
        self.insert_raw(COLUMN_INDEX, raw_number.as_slice(), &block_hash)?;
        self.insert_raw(COLUMN_INDEX, &block_hash, raw_number.as_slice())?;

        // update block tree
        let mut block_smt = self.block_smt()?;
        block_smt
            .update(raw.smt_key().into(), raw.hash().into())
            .map_err(|err| Error::from(format!("SMT error {}", err)))?;
        let root = block_smt.root();
        self.set_block_smt_root(*root)?;

        // update tip
        self.insert_raw(COLUMN_META, META_TIP_BLOCK_HASH_KEY, &block_hash)?;
        self.set_last_valid_tip_block_hash(&block_hash.into())?;

        Ok(())
    }
/// Attach block to the rollup main chain
Attach block to the rollup main chain
Attach block to the rollup main chain
pub fn attach_block(&self, block: packed::L2Block) -> Result<(), Error> {
        let raw = block.raw();
        let raw_number = raw.number();
        let block_hash = raw.hash();
        // build tx info
        for (index, tx) in block.transactions().into_iter().enumerate() {
            let key = TransactionKey::build_transaction_key(block_hash.pack(), index as u32);
            let info = packed::TransactionInfo::new_builder()
                .key(key)
                .block_number(raw_number.clone())
                .build();
            let tx_hash = tx.hash();
            self.insert_raw(COLUMN_TRANSACTION_INFO, &tx_hash, info.as_slice())?;
        }
        // build withdrawal info
        for (index, withdrawal) in block.withdrawals().into_iter().enumerate() {
            let key = WithdrawalKey::build_withdrawal_key(block_hash.pack(), index as u32);
            let info = packed::WithdrawalInfo::new_builder()
                .key(key)
                .block_number(raw_number.clone())
                .build();
            let withdrawal_hash = withdrawal.hash();
            self.insert_raw(COLUMN_WITHDRAWAL_INFO, &withdrawal_hash, info.as_slice())?;
        }
        // build main chain index
        self.insert_raw(COLUMN_INDEX, raw_number.as_slice(), &block_hash)?;
        self.insert_raw(COLUMN_INDEX, &block_hash, raw_number.as_slice())?;
        // update block tree
        let mut block_smt = self.block_smt()?;
        block_smt
            .update(raw.smt_key().into(), raw.hash().into())
            .map_err(|err| Error::from(format!("SMT error {}", err)))?;
        let root = block_smt.root();
        self.set_block_smt_root(*root)?;
        // update tip
        self.insert_raw(COLUMN_META, META_TIP_BLOCK_HASH_KEY, &block_hash)?;
        self.set_last_valid_tip_block_hash(&block_hash.into())?;
        Ok(())
    }
pub fn attach_block ( & self , block : packed :: L2Block ) -> Result < ( ) , Error > { let raw = block . raw ( ) ; let raw_number = raw . number ( ) ; let block_hash = raw . hash ( ) ; // build tx info for ( index , tx ) in block . transactions ( ) . into_iter ( ) . enumerate ( ) { let key = TransactionKey :: build_transaction_key ( block_hash . pack ( ) , index as u32 ) ; let info = packed :: TransactionInfo :: new_builder ( ) . key ( key ) . block_number ( raw_number . clone ( ) ) . build ( ) ; let tx_hash = tx . hash ( ) ; self . insert_raw ( COLUMN_TRANSACTION_INFO , & tx_hash , info . as_slice ( ) ) ? ; } // build withdrawal info for ( index , withdrawal ) in block . withdrawals ( ) . into_iter ( ) . enumerate ( ) { let key = WithdrawalKey :: build_withdrawal_key ( block_hash . pack ( ) , index as u32 ) ; let info = packed :: WithdrawalInfo :: new_builder ( ) . key ( key ) . block_number ( raw_number . clone ( ) ) . build ( ) ; let withdrawal_hash = withdrawal . hash ( ) ; self . insert_raw ( COLUMN_WITHDRAWAL_INFO , & withdrawal_hash , info . as_slice ( ) ) ? ; } // build main chain index self . insert_raw ( COLUMN_INDEX , raw_number . as_slice ( ) , & block_hash ) ? ; self . insert_raw ( COLUMN_INDEX , & block_hash , raw_number . as_slice ( ) ) ? ; // update block tree let mut block_smt = self . block_smt ( ) ? ; block_smt . update ( raw . smt_key ( ) . into ( ) , raw . hash ( ) . into ( ) ) . map_err ( | err | Error :: from ( format ! ( " " err ) ) ) ? ; let root = block_smt . root ( ) ; self . set_block_smt_root ( * root ) ? ; // update tip self . insert_raw ( COLUMN_META , META_TIP_BLOCK_HASH_KEY , & block_hash ) ? ; self . set_last_valid_tip_block_hash ( & block_hash . into ( ) ) ? ; Ok ( ( ) ) }
Attach block to the rollup main chain
Attach block to the rollup main chain
&self
block
packed::L2Block
&self
block
packed::L2Block