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

Method genesis_block

code/chapter09/blockchain/blockchain8/core/src/blockchain.rs:47–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45 }
46
47 fn genesis_block() -> Block {
48 println!("Start mining .... ");
49 let from = "0x0000".to_string();
50 let to = "0x0000".to_string();
51 let sign = "创世区块".to_string();
52 let tx = Transaction::new(from, to, 0, 0, 0, sign);
53 let mut block = Block::new(vec![tx], PRE_HASH.to_string(), INIT_BITS);
54
55 let header_ser = ProofOfWork::prepare_data(&mut block, 0);
56 block.hash = hash_str(&header_ser);
57 println!("Produced a new block!");
58
59 block
60 }
61
62 pub fn add_block(&mut self, block: Block) {
63 Self::write_block(&mut (self.blocks_db), &block);

Callers

nothing calls this directly

Calls 2

hash_strFunction · 0.50
to_stringMethod · 0.45

Tested by

no test coverage detected