fn populate_db(db: &mut LedgerDB, n_blocks: u64) -> Vec<Block> {
        let initial_amount: u64 = 5_000 * 1_000_000_000_000;
        let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);

        // Generate 1 public / private addresses and create transactions.
        let account_key = AccountKey::random(&mut rng);

        let mut parent_block: Option<Block> = None;
        let mut blocks: Vec<Block> = Vec::new();

        for block_index in 0..n_blocks {
            let tx_out = TxOut::new(
                initial_amount,
                &account_key.default_subaddress(),
                &RistrettoPrivate::from_random(&mut rng),
                Default::default(),
                &mut rng,
            )
            .unwrap();

            let outputs = vec![tx_out];
            let block_contents = BlockContents::new(vec![], outputs.clone());

            let block = match parent_block {
                None => Block::new_origin_block(&outputs),
                Some(parent) => Block::new(
                    BLOCK_VERSION,
                    &parent.id,
                    block_index,
                    &Default::default(),
                    &block_contents,
                ),
            };

            db.append_block(&block, &block_contents, None)
                .expect("failed writing initial transactions");
            blocks.push(block.clone());
            parent_block = Some(block);
        }

        // Verify that db now contains n transactions.
        assert_eq!(db.num_blocks().unwrap(), n_blocks as u64);

        blocks
    }
/// Populates the LedgerDB with initial data, and returns the Block entities that were written.
///
/// # Arguments
/// * `n_blocks` - number of blocks of transactions to write to `db`.
///
Populates the LedgerDB with initial data, and returns the Block entities that were written.
Populates the LedgerDB with initial data and returns the Block entities that were written .
fn populate_db(db: &mut LedgerDB, n_blocks: u64) -> Vec<Block> {
        let initial_amount: u64 = 5_000 * 1_000_000_000_000;
        let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
        // Generate 1 public / private addresses and create transactions.
        let account_key = AccountKey::random(&mut rng);
        let mut parent_block: Option<Block> = None;
        let mut blocks: Vec<Block> = Vec::new();
        for block_index in 0..n_blocks {
            let tx_out = TxOut::new(
                initial_amount,
                &account_key.default_subaddress(),
                &RistrettoPrivate::from_random(&mut rng),
                Default::default(),
                &mut rng,
            )
            .unwrap();
            let outputs = vec![tx_out];
            let block_contents = BlockContents::new(vec![], outputs.clone());
            let block = match parent_block {
                None => Block::new_origin_block(&outputs),
                Some(parent) => Block::new(
                    BLOCK_VERSION,
                    &parent.id,
                    block_index,
                    &Default::default(),
                    &block_contents,
                ),
            };
            db.append_block(&block, &block_contents, None)
                .expect("failed writing initial transactions");
            blocks.push(block.clone());
            parent_block = Some(block);
        }
        // Verify that db now contains n transactions.
        assert_eq!(db.num_blocks().unwrap(), n_blocks as u64);
        blocks
    }
fn populate_db ( db : & mut LedgerDB , n_blocks : u64 ) -> Vec < Block > { let initial_amount : u64 = 5_000 * 1_000_000_000_000 ; let mut rng : StdRng = SeedableRng :: from_seed ( [ 1u8 ; 32 ] ) ; // Generate 1 public / private addresses and create transactions. let account_key = AccountKey :: random ( & mut rng ) ; let mut parent_block : Option < Block > = None ; let mut blocks : Vec < Block > = Vec :: new ( ) ; for block_index in 0 .. n_blocks { let tx_out = TxOut :: new ( initial_amount , & account_key . default_subaddress ( ) , & RistrettoPrivate :: from_random ( & mut rng ) , Default :: default ( ) , & mut rng , ) . unwrap ( ) ; let outputs = vec ! [ tx_out ] ; let block_contents = BlockContents :: new ( vec ! [ ] , outputs . clone ( ) ) ; let block = match parent_block { None => Block :: new_origin_block ( & outputs ) , Some ( parent ) => Block :: new ( BLOCK_VERSION , & parent . id , block_index , & Default :: default ( ) , & block_contents , ) , } ; db . append_block ( & block , & block_contents , None ) . expect ( " " ) ; blocks . push ( block . clone ( ) ) ; parent_block = Some ( block ) ; } // Verify that db now contains n transactions. assert_eq ! ( db num_blocks ( ) unwrap ( ) n_blocks as u64 ) ; blocks }
Populates the LedgerDB with initial data, and returns the Block entities that were written.
Populates the LedgerDB with initial data and returns the Block entities that were written .
db
&mut LedgerDB
n_blocks
u64
db
&mut LedgerDB
n_blocks
u64