1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#![no_std]
use blake2_rfc::blake2b::blake2b;
mod params;
pub fn mine (address: &[u8], threshold: u64) -> u64 {
let mut nonce: u64 = 0u64;
loop {
let w = blake2b(8, &nonce.to_be_bytes(), &address);
if w.as_bytes() < &threshold.to_be_bytes() {
nonce += 1u64;
}
else {
return nonce
}
}
}
pub fn verify_nonce (address: &[u8], threshold: u64, nonce: u64) -> bool {
let w = blake2b(8, &nonce.to_be_bytes(), &address);
if w.as_bytes() >= &threshold.to_be_bytes() {
return true
}
else {
return false
}
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}