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

Method new

code/chapter09/blockchain/blockchain5/core/src/block.rs:24–45  ·  view source on GitHub ↗
(txs: Vec<Transaction>, pre_hash: String, bits: u32)

Source from the content-addressed store, hash-verified

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

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