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

Method new

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

Source from the content-addressed store, hash-verified

21
22impl Block {
23 pub fn new(txs: String, pre_hash: String, bits: u32) -> Self {
24 let time = Utc::now().timestamp();
25 let txs_ser = serialize(&txs);
26 let txs_hash = hash_str(&txs_ser);
27
28 let mut block = Block {
29 header: BlockHeader {
30 time: time,
31 txs_hash: txs_hash,
32 pre_hash: pre_hash,
33 bits: bits,
34 nonce: 0,
35 },
36 tranxs: txs,
37 hash: "".to_string(),
38 };
39
40 let pow = ProofOfWork::new(bits);
41 pow.run(&mut block);
42
43 block
44 }
45}

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