snarkvm_ledger_puzzle/solution_id/
mod.rs1mod bytes;
17mod serialize;
18mod string;
19
20pub use string::SOLUTION_ID_PREFIX;
21
22use console::{account::Address, network::prelude::*};
23use snarkvm_algorithms::crypto_hash::sha256d_to_u64;
24
25use core::marker::PhantomData;
26
27#[derive(Copy, Clone, Eq, PartialEq, Hash)]
29pub struct SolutionID<N: Network>(u64, PhantomData<N>);
30
31impl<N: Network> From<u64> for SolutionID<N> {
32 fn from(nonce: u64) -> Self {
34 Self(nonce, PhantomData)
35 }
36}
37
38impl<N: Network> SolutionID<N> {
39 pub fn new(epoch_hash: N::BlockHash, address: Address<N>, counter: u64) -> Result<Self> {
41 let mut bytes_le = Vec::new();
43 let lower_bytes = &epoch_hash.to_bytes_le()?[0..8];
44 bytes_le.extend_from_slice(lower_bytes);
45 bytes_le.extend_from_slice(&address.to_bytes_le()?);
46 bytes_le.extend_from_slice(&counter.to_bytes_le()?);
47 Ok(Self::from(sha256d_to_u64(&bytes_le)))
48 }
49}
50
51impl<N: Network> Deref for SolutionID<N> {
52 type Target = u64;
53
54 fn deref(&self) -> &Self::Target {
55 &self.0
56 }
57}