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

Method add_block

code/chapter09/blockchain/blockchain3/core/src/blockchain.rs:37–48  ·  view source on GitHub ↗
(&mut self, txs: String)

Source from the content-addressed store, hash-verified

35 }
36
37 pub fn add_block(&mut self, txs: String) {
38 let pre_block = &self.blocks[self.blocks.len() - 1];
39 let pre_hash = pre_block.hash.clone();
40 let new_block = Block::new(txs, pre_hash, self.curr_bits);
41
42 // 数据写入库
43 Self::write_block(&mut (self.blocks_db), &new_block);
44 Self::write_tail(&mut (self.blocks_db), &new_block);
45
46 println!("New produced block saved!\n");
47 self.blocks.push(new_block);
48 }
49
50 fn write_block(db: &mut Database<BKey>, block: &Block) {
51 // 基于区块的 header 生成 key

Callers 1

mainFunction · 0.45

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected