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

Method mine_block

code/chapter09/blockchain/blockchain7/core/src/miner.rs:24–37  ·  view source on GitHub ↗
(&self, txs: &mut Vec<Transaction>, pre_hash: String, bits: u32)

Source from the content-addressed store, hash-verified

22 }
23
24 pub fn mine_block(&self, txs: &mut Vec<Transaction>, pre_hash: String, bits: u32)
25 -> Block {
26 let from = "0x0000".to_string();
27 let to = self.address.clone();
28 let sign = format!("{} -> {}: 50 btc", from, to);
29 let coinbase = Transaction::new(from, to, 0, 0, 0, sign);
30
31 // 加入 coinbase 交易和普通交易
32 let mut txs_2: Vec<Transaction> = Vec::new();
33 txs_2.push(coinbase);
34 txs_2.append(txs);
35
36 Self::mine_job(txs_2, pre_hash, bits)
37 }
38
39 // 挖矿任务-工作量证明
40 fn mine_job(txs: Vec<Transaction>, pre_hash: String, bits: u32) -> Block {

Callers 1

miningMethod · 0.45

Calls 3

to_stringMethod · 0.45
pushMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected