MCPcopy Create free account
hub / github.com/PacktPublishing/Rust-for-Blockchain-Application-Development / run

Method run

chapter 3/block.rs:137–156  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

135
136
137 pub fn run(&self) -> (i64, String) {
138 let mut nonce = 0;
139 let mut hash = Vec::new();
140 println!("Mining the block");
141 while nonce < MAX_NONCE {
142 let data = self.prepare_data(nonce);
143 hash = crate::sha256_digest(data.as_slice());
144 let hash_int = BigInt::from_bytes_be(Sign::Plus, hash.as_slice());
145
146
147 if hash_int.lt(self.target.borrow()) {
148 println!("{}", HEXLOWER.encode(hash.as_slice()));
149 break;
150 } else {
151 nonce += 1;
152 }
153 }
154 println!();
155 return (nonce, HEXLOWER.encode(hash.as_slice()));
156 }
157}

Callers 2

new_blockMethod · 0.45
mainFunction · 0.45

Calls 2

sha256_digestFunction · 0.50
prepare_dataMethod · 0.45

Tested by

no test coverage detected