/ ledger / puzzle / src / solution / mod.rs
mod.rs
 1  // Copyright (c) 2019-2025 Alpha-Delta Network Inc.
 2  // This file is part of the deltavm 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  
16  mod bytes;
17  mod serialize;
18  mod string;
19  
20  use crate::{PartialSolution, SolutionID};
21  use console::{account::Address, network::prelude::*, prelude::DeserializeExt};
22  
23  /// A helper struct around a puzzle solution.
24  #[derive(Copy, Clone, Eq, PartialEq, Hash)]
25  pub struct Solution<N: Network> {
26      /// The partial solution.
27      partial_solution: PartialSolution<N>,
28      /// The solution target.
29      pub(super) target: u64,
30  }
31  
32  impl<N: Network> Solution<N> {
33      /// Initializes a new instance of the solution.
34      pub fn new(partial_solution: PartialSolution<N>, target: u64) -> Self {
35          Self { partial_solution, target }
36      }
37  
38      /// Returns the partial solution..
39      pub const fn partial_solution(&self) -> &PartialSolution<N> {
40          &self.partial_solution
41      }
42  
43      /// Returns the solution ID.
44      pub const fn id(&self) -> SolutionID<N> {
45          self.partial_solution.id()
46      }
47  
48      /// Returns the epoch hash of the solution.
49      pub const fn epoch_hash(&self) -> N::BlockHash {
50          self.partial_solution.epoch_hash()
51      }
52  
53      /// Returns the address of the prover.
54      pub const fn address(&self) -> Address<N> {
55          self.partial_solution.address()
56      }
57  
58      /// Returns the counter for the solution.
59      pub const fn counter(&self) -> u64 {
60          self.partial_solution.counter()
61      }
62  
63      /// Returns the target for the solution.
64      pub const fn target(&self) -> u64 {
65          self.target
66      }
67  }