pub fn add_block(store: &mut Store, buffer: &[u8]) {


    let block_logger = slog::Logger::new(&store.logger, o!());
    info!(block_logger, "add_block - start");

    // parse & hash block
    let block      = Block::new(buffer) .unwrap();
    let block_hash = Hash32Buf::double_sha256( block.header.to_raw());

    info!(block_logger, "add_block - hashed"; "hash" => format!("{:?}", block_hash));

    // already done?
    if block_exists(store, block_hash.as_ref()) {
        info!(store.logger, "add_block - Block already exists");
        return;
    }

    block.verify_block_size().unwrap();

    // check and store the transactions in block_content and check the merkle_root
    let spend_tree_ptrs = verify_and_store_transactions(store, &block).unwrap();

    // store the blockheader in block_content
    let block_header_ptr = store.block_headers.write( &block.header.to_raw());

    // we also store the txcount, although we only use it for a reindex benchmark
    let _ = store.block_headers.write_fixed( &block.txs.len());

    // store the block in the spend_tree

    let block_ptr       = store.spend_tree.store_block(block_header_ptr, spend_tree_ptrs);


    if is_genesis_block(block_hash.as_ref()) {

        info ! (block_logger, "add_block - storing genesis block");

        // there is None previous block, but we call connect_block anyway as this will also
        // connect to next blocks if they are already in
        connect_block(store, block_hash.as_ref(), None, block_ptr).unwrap();
    }
    else {

        // we retrieve the pointer to the end of the previous block from the hash-index
        // if it is not yet in, this hash will be inserted as a guard-block
        let previous_block = store.block_index.get_or_set( block.header.prev_hash, block_ptr.to_guard());

        info! (block_logger, "add_block - block-index done";
            "previous" => format!("{:?}", block.header.prev_hash),
            "ptr" => format!("{:?}", previous_block));

        // if it is in, we will connect
        if let Some(previous_block) = previous_block {

            connect_block(store, block_hash.as_ref(), Some(previous_block), block_ptr).unwrap();
        }

    }

    tips::add_tip(&store.tips, block_hash, None, 0, 0);


    // TODO verify amounts
    // TODO verify PoW
    // TODO verify header-syntax

    info!(block_logger, "add_block - done");
}
/// Validates and stores a block;
///
/// For now; this panics on invalids; but all underlying functions
/// propagate problems to jere
Validates and stores a block;
For now; this panics on invalids; but all underlying functions
propagate problems to jere
Validates and stores a block ; For now ; this panics on invalids ; but all underlying functions propagate problems to jere
pub fn add_block(store: &mut Store, buffer: &[u8]) {
    let block_logger = slog::Logger::new(&store.logger, o!());
    info!(block_logger, "add_block - start");
    // parse & hash block
    let block      = Block::new(buffer) .unwrap();
    let block_hash = Hash32Buf::double_sha256( block.header.to_raw());
    info!(block_logger, "add_block - hashed"; "hash" => format!("{:?}", block_hash));
    // already done?
    if block_exists(store, block_hash.as_ref()) {
        info!(store.logger, "add_block - Block already exists");
        return;
    }
    block.verify_block_size().unwrap();
    // check and store the transactions in block_content and check the merkle_root
    let spend_tree_ptrs = verify_and_store_transactions(store, &block).unwrap();
    // store the blockheader in block_content
    let block_header_ptr = store.block_headers.write( &block.header.to_raw());
    // we also store the txcount, although we only use it for a reindex benchmark
    let _ = store.block_headers.write_fixed( &block.txs.len());
    // store the block in the spend_tree
    let block_ptr       = store.spend_tree.store_block(block_header_ptr, spend_tree_ptrs);
    if is_genesis_block(block_hash.as_ref()) {
        info ! (block_logger, "add_block - storing genesis block");
        // there is None previous block, but we call connect_block anyway as this will also
        // connect to next blocks if they are already in
        connect_block(store, block_hash.as_ref(), None, block_ptr).unwrap();
    }
    else {
        // we retrieve the pointer to the end of the previous block from the hash-index
        // if it is not yet in, this hash will be inserted as a guard-block
        let previous_block = store.block_index.get_or_set( block.header.prev_hash, block_ptr.to_guard());
        info! (block_logger, "add_block - block-index done";
            "previous" => format!("{:?}", block.header.prev_hash),
            "ptr" => format!("{:?}", previous_block));
        // if it is in, we will connect
        if let Some(previous_block) = previous_block {
            connect_block(store, block_hash.as_ref(), Some(previous_block), block_ptr).unwrap();
        }
    }
    tips::add_tip(&store.tips, block_hash, None, 0, 0);
    // TODO verify amounts
    // TODO verify PoW
    // TODO verify header-syntax
    info!(block_logger, "add_block - done");
}
pub fn add_block ( store : & mut Store , buffer : & [ u8 ] ) { let block_logger = slog :: Logger :: new ( & store . logger , o ! ( ) ) ; info ! ( block_logger " " ) ; // parse & hash block let block = Block :: new ( buffer ) . unwrap ( ) ; let block_hash = Hash32Buf :: double_sha256 ( block . header . to_raw ( ) ) ; info ! ( block_logger " " " " format ( " " block_hash ) ) ; // already done? if block_exists ( store , block_hash . as_ref ( ) ) { info ! ( store logger " " ) ; return ; } block . verify_block_size ( ) . unwrap ( ) ; // check and store the transactions in block_content and check the merkle_root let spend_tree_ptrs = verify_and_store_transactions ( store , & block ) . unwrap ( ) ; // store the blockheader in block_content let block_header_ptr = store . block_headers . write ( & block . header . to_raw ( ) ) ; // we also store the txcount, although we only use it for a reindex benchmark let _ = store . block_headers . write_fixed ( & block . txs . len ( ) ) ; // store the block in the spend_tree let block_ptr = store . spend_tree . store_block ( block_header_ptr , spend_tree_ptrs ) ; if is_genesis_block ( block_hash . as_ref ( ) ) { info ! ( block_logger " " ) ; // there is None previous block, but we call connect_block anyway as this will also // connect to next blocks if they are already in connect_block ( store , block_hash . as_ref ( ) , None , block_ptr ) . unwrap ( ) ; } else { // we retrieve the pointer to the end of the previous block from the hash-index // if it is not yet in, this hash will be inserted as a guard-block let previous_block = store . block_index . get_or_set ( block . header . prev_hash , block_ptr . to_guard ( ) ) ; info ! ( block_logger " " " " format ( " " block header prev_hash ) " " format ( " " previous_block ) ) ; // if it is in, we will connect if let Some ( previous_block ) = previous_block { connect_block ( store , block_hash . as_ref ( ) , Some ( previous_block ) , block_ptr ) . unwrap ( ) ; } } tips :: add_tip ( & store . tips , block_hash , None , 0 , 0 ) ; // TODO verify amounts // TODO verify PoW // TODO verify header-syntax info ! ( block_logger " " ) ; }
Validates and stores a block;
For now; this panics on invalids; but all underlying functions
propagate problems to jere
Validates and stores a block ; For now ; this panics on invalids ; but all underlying functions propagate problems to jere
store
&mut Store
buffer
&[u8]
store
&mut Store
buffer
&[u8]