pub fn initialize_ledger<L: Ledger, R: RngCore + CryptoRng>(
    ledger: &mut L,
    n_blocks: u64,
    account_key: &AccountKey,
    rng: &mut R,
) -> Vec<Block> {
    let value: u64 = INITIALIZE_LEDGER_AMOUNT;

    // TxOut from the previous block
    let mut to_spend: Option<TxOut> = None;
    let mut parent: Option<Block> = None;

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

    for block_index in 0..n_blocks {
        let (block, redacted_transactions) = match to_spend {
            Some(tx_out) => {
                let tx = create_transaction(
                    ledger,
                    &tx_out,
                    account_key,
                    &account_key.default_subaddress(),
                    block_index + 1,
                    rng,
                );

                let redacted_transactions = vec![tx.redact()];

                let block = Block::new(
                    BLOCK_VERSION,
                    &parent.as_ref().unwrap().id,
                    block_index,
                    &Default::default(),
                    &redacted_transactions,
                );

                (block, redacted_transactions)
            }
            None => {
                // Create an origin block.
                let outputs: Vec<TxOut> = (0..RING_SIZE)
                    .map(|_i| {
                        TxOut::new(
                            value,
                            &account_key.default_subaddress(),
                            &RistrettoPrivate::from_random(rng),
                            Default::default(),
                            rng,
                        )
                        .unwrap()
                    })
                    .collect();

                let redacted_transactions = vec![RedactedTx {
                    outputs,
                    key_images: vec![],
                }];

                let block = Block::new_origin_block(&redacted_transactions);
                (block, redacted_transactions)
            }
        };

        ledger
            .append_block(&block, &redacted_transactions, None)
            .expect("failed writing initial transactions");

        blocks.push(block.clone());
        parent = Some(block);
        let tx_out = redacted_transactions[0].outputs[0].clone();
        to_spend = Some(tx_out);
    }

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

    blocks
}
/// Populates the LedgerDB with initial data.
///
/// Creates a number of blocks, each of which contains a single transaction.
/// The first contains RING_SIZE txos so we can create more valid transactions.
/// The rest have a single TxOut.
///
/// The first block "mints" coins, and each subsequent block spends the TxOut produced by the
/// previous block.
///
/// # Arguments
/// * `ledger` -
/// * `n_blocks` - The number of blocks of transactions to write to `db`.
/// * `account_key` - The recipient of all TxOuts generated.
/// * `rng` -
///
/// Returns the blocks that were created.
Populates the LedgerDB with initial data.
Creates a number of blocks, each of which contains a single transaction.
The first contains RING_SIZE txos so we can create more valid transactions.
The rest have a single TxOut.

The first block "mints" coins, and each subsequent block spends the TxOut produced by the
previous block.
Populates the LedgerDB with initial data . Creates a number of blocks each of which contains a single transaction . The first contains RING_SIZE txos so we can create more valid transactions . The rest have a single TxOut . The first block " mints " coins and each subsequent block spends the TxOut produced by the previous block .
pub fn initialize_ledger<L: Ledger, R: RngCore + CryptoRng>(
    ledger: &mut L,
    n_blocks: u64,
    account_key: &AccountKey,
    rng: &mut R,
) -> Vec<Block> {
    let value: u64 = INITIALIZE_LEDGER_AMOUNT;
    // TxOut from the previous block
    let mut to_spend: Option<TxOut> = None;
    let mut parent: Option<Block> = None;
    let mut blocks: Vec<Block> = Vec::new();
    for block_index in 0..n_blocks {
        let (block, redacted_transactions) = match to_spend {
            Some(tx_out) => {
                let tx = create_transaction(
                    ledger,
                    &tx_out,
                    account_key,
                    &account_key.default_subaddress(),
                    block_index + 1,
                    rng,
                );
                let redacted_transactions = vec![tx.redact()];
                let block = Block::new(
                    BLOCK_VERSION,
                    &parent.as_ref().unwrap().id,
                    block_index,
                    &Default::default(),
                    &redacted_transactions,
                );
                (block, redacted_transactions)
            }
            None => {
                // Create an origin block.
                let outputs: Vec<TxOut> = (0..RING_SIZE)
                    .map(|_i| {
                        TxOut::new(
                            value,
                            &account_key.default_subaddress(),
                            &RistrettoPrivate::from_random(rng),
                            Default::default(),
                            rng,
                        )
                        .unwrap()
                    })
                    .collect();
                let redacted_transactions = vec![RedactedTx {
                    outputs,
                    key_images: vec![],
                }];
                let block = Block::new_origin_block(&redacted_transactions);
                (block, redacted_transactions)
            }
        };
        ledger
            .append_block(&block, &redacted_transactions, None)
            .expect("failed writing initial transactions");
        blocks.push(block.clone());
        parent = Some(block);
        let tx_out = redacted_transactions[0].outputs[0].clone();
        to_spend = Some(tx_out);
    }
    // Verify that db now contains n transactions.
    assert_eq!(ledger.num_blocks().unwrap(), n_blocks as u64);
    assert_eq!(ledger.num_txs().unwrap(), n_blocks as u64);
    blocks
}
pub fn initialize_ledger < L : Ledger , R : RngCore + CryptoRng > ( ledger : & mut L , n_blocks : u64 , account_key : & AccountKey , rng : & mut R , ) -> Vec < Block > { let value : u64 = INITIALIZE_LEDGER_AMOUNT ; // TxOut from the previous block let mut to_spend : Option < TxOut > = None ; let mut parent : Option < Block > = None ; let mut blocks : Vec < Block > = Vec :: new ( ) ; for block_index in 0 .. n_blocks { let ( block , redacted_transactions ) = match to_spend { Some ( tx_out ) => { let tx = create_transaction ( ledger , & tx_out , account_key , & account_key . default_subaddress ( ) , block_index + 1 , rng , ) ; let redacted_transactions = vec ! [ tx redact ( ) ] ; let block = Block :: new ( BLOCK_VERSION , & parent . as_ref ( ) . unwrap ( ) . id , block_index , & Default :: default ( ) , & redacted_transactions , ) ; ( block , redacted_transactions ) } None => { // Create an origin block. let outputs : Vec < TxOut > = ( 0 .. RING_SIZE ) . map ( | _i | { TxOut :: new ( value , & account_key . default_subaddress ( ) , & RistrettoPrivate :: from_random ( rng ) , Default :: default ( ) , rng , ) . unwrap ( ) } ) . collect ( ) ; let redacted_transactions = vec ! [ RedactedTx { outputs key_images vec [ ] } ] ; let block = Block :: new_origin_block ( & redacted_transactions ) ; ( block , redacted_transactions ) } } ; ledger . append_block ( & block , & redacted_transactions , None ) . expect ( " " ) ; blocks . push ( block . clone ( ) ) ; parent = Some ( block ) ; let tx_out = redacted_transactions [ 0 ] . outputs [ 0 ] . clone ( ) ; to_spend = Some ( tx_out ) ; } // Verify that db now contains n transactions. assert_eq ! ( ledger num_blocks ( ) unwrap ( ) n_blocks as u64 ) ; assert_eq ! ( ledger num_txs ( ) unwrap ( ) n_blocks as u64 ) ; blocks }
Populates the LedgerDB with initial data.
Populates the LedgerDB with initial data .
ledger
&mut L
n_blocks
u64
account_key
&AccountKey
rng
&mut R
ledger
&mut L
n_blocks
u64
account_key
&AccountKey
rng
&mut R