| 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 { |