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

Method new

code/chapter09/blockchain/blockchain2/core/src/block.rs:25–47  ·  view source on GitHub ↗
(txs: String, pre_hash: String, bits: u32)

Source from the content-addressed store, hash-verified

23
24impl 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

Calls 4

serializeFunction · 0.50
hash_strFunction · 0.50
to_stringMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected