snarkvm_ledger_puzzle/partial_solution/
mod.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16mod bytes;
17mod serialize;
18mod string;
19
20use crate::SolutionID;
21use console::{account::Address, network::prelude::*, prelude::DeserializeExt};
22
23/// The partial solution for the puzzle from a prover.
24#[derive(Copy, Clone, Eq, PartialEq, Hash)]
25pub struct PartialSolution<N: Network> {
26    /// The solution ID.
27    solution_id: SolutionID<N>,
28    /// The epoch hash.
29    epoch_hash: N::BlockHash,
30    /// The address of the prover.
31    address: Address<N>,
32    /// The counter for the solution.
33    counter: u64,
34}
35
36impl<N: Network> PartialSolution<N> {
37    /// Initializes a new instance of the partial solution.
38    pub fn new(epoch_hash: N::BlockHash, address: Address<N>, counter: u64) -> Result<Self> {
39        // Compute the solution ID.
40        let solution_id = SolutionID::new(epoch_hash, address, counter)?;
41        // Return the partial solution.
42        Ok(Self { solution_id, epoch_hash, address, counter })
43    }
44
45    /// Returns the solution ID.
46    pub const fn id(&self) -> SolutionID<N> {
47        self.solution_id
48    }
49
50    /// Returns the epoch hash of the solution.
51    pub const fn epoch_hash(&self) -> N::BlockHash {
52        self.epoch_hash
53    }
54
55    /// Returns the address of the prover.
56    pub const fn address(&self) -> Address<N> {
57        self.address
58    }
59
60    /// Returns the counter for the solution.
61    pub const fn counter(&self) -> u64 {
62        self.counter
63    }
64}