mining.rs (964B)
1 use super::hex_hash; 2 3 pub(super) fn mine_payload( 4 recipient: &str, 5 anchor: &str, 6 salt: u64, 7 nonce: u64, 8 difficulty_bits: u32, 9 ) -> String { 10 format!("iuna-mine:{recipient}:{anchor}:{salt}:{nonce}:{difficulty_bits}") 11 } 12 13 pub(super) fn mine_signature( 14 recipient: &str, 15 anchor: &str, 16 salt: u64, 17 nonce: u64, 18 difficulty_bits: u32, 19 ) -> String { 20 hex_hash(mine_payload( 21 recipient, 22 anchor, 23 salt, 24 nonce, 25 difficulty_bits, 26 )) 27 } 28 29 #[cfg(test)] 30 mod tests { 31 use super::{mine_payload, mine_signature}; 32 33 #[test] 34 fn mine_signature_hashes_canonical_mine_payload() { 35 let payload = mine_payload("recipient", "anchor", 1, 2, 12); 36 37 assert_eq!(payload, "iuna-mine:recipient:anchor:1:2:12"); 38 assert_eq!( 39 mine_signature("recipient", "anchor", 1, 2, 12), 40 "47f9ad353685fdb9b4932cefa9dd1d27f8af70e27eaedf15c4f9ffbbb64300a3" 41 ); 42 } 43 }