Method
new
(txs: String, pre_hash: String, bits: u32)
Source from the content-addressed store, hash-verified
| 23 | |
| 24 | impl Block { |
| 25 | pub fn new(txs: String, pre_hash: String, bits: u32) -> Self { |
| 26 | let time = Utc::now().timestamp(); |
| 27 | let txs_ser = serialize(&txs); |
| 28 | let txs_hash = hash_str(&txs_ser); |
| 29 | |
| 30 | let mut block = Block { |
| 31 | header: BlockHeader { |
| 32 | time: time, |
| 33 | txs_hash: txs_hash, |
| 34 | pre_hash: pre_hash, |
| 35 | bits: bits, |
| 36 | nonce: 0, |
| 37 | }, |
| 38 | tranxs: txs, |
| 39 | hash: "".to_string(), |
| 40 | }; |
| 41 | |
| 42 | // 初始化挖矿任务并开始挖矿 |
| 43 | let pow = ProofOfWork::new(bits); |
| 44 | pow.run(&mut block); |
| 45 | |
| 46 | block |
| 47 | } |
| 48 | } |
Callers
nothing calls this directly
Tested by
no test coverage detected