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

Method block_info

code/chapter09/blockchain/blockchain8/core/src/blockchain.rs:93–118  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

91 }
92
93 pub fn block_info(&self) {
94 let mut hash = self.curr_hash.clone();
95 let hmap = self.blocks_index.lock().unwrap();
96 let mut blocks: Vec<Block> = Vec::new();
97
98 loop {
99 if let Some(b) = hmap.get(&hash) {
100 blocks.push(b.clone());
101 hash = b.header.pre_hash.clone();
102 } else {
103 panic!("Error getting block");
104 }
105
106 if hash == self.gnes_hash {
107 if let Some(b) = hmap.get(&hash) {
108 blocks.push(b.clone());
109 }
110 break;
111 }
112 }
113 blocks.reverse();
114
115 for b in blocks {
116 println!("{:#?}", b);
117 }
118 }
119}

Callers 1

mainFunction · 0.45

Calls 2

getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected