MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / add_block

Method add_block

code/chapter09/blockchain/blockchain6/core/src/blockchain.rs:42–50  ·  view source on GitHub ↗
(&mut self, txs: Vec<Transaction>)

Source from the content-addressed store, hash-verified

40 }
41
42 pub fn add_block(&mut self, txs: Vec<Transaction>) {
43 let pre_block = &self.blocks[self.blocks.len() - 1];
44 let pre_hash = pre_block.hash.clone();
45 let new_block = Block::new(txs, pre_hash, self.curr_bits);
46 Self::write_block(&mut (self.blocks_db), &new_block);
47 Self::write_tail(&mut (self.blocks_db), &new_block);
48 println!("New produced block saved!\n");
49 self.blocks.push(new_block);
50 }
51
52 pub fn block_info(&self) {
53 for b in self.blocks.iter() {

Callers 1

mainFunction · 0.45

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected