chik_puzzle_types/puzzles/
singleton.rs1use chik_protocol::Bytes32;
2use chik_puzzles::{SINGLETON_LAUNCHER_HASH, SINGLETON_TOP_LAYER_V1_1_HASH};
3use klvm_traits::{FromKlvm, ToKlvm};
4use klvm_utils::{CurriedProgram, ToTreeHash, TreeHash};
5
6use crate::Proof;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, ToKlvm, FromKlvm)]
9#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10#[klvm(curry)]
11pub struct SingletonArgs<I> {
12 pub singleton_struct: SingletonStruct,
13 pub inner_puzzle: I,
14}
15
16impl<I> SingletonArgs<I> {
17 pub fn new(launcher_id: Bytes32, inner_puzzle: I) -> Self {
18 Self {
19 singleton_struct: SingletonStruct::new(launcher_id),
20 inner_puzzle,
21 }
22 }
23}
24
25impl SingletonArgs<TreeHash> {
26 pub fn curry_tree_hash(launcher_id: Bytes32, inner_puzzle: TreeHash) -> TreeHash {
27 CurriedProgram {
28 program: TreeHash::new(SINGLETON_TOP_LAYER_V1_1_HASH),
29 args: SingletonArgs::new(launcher_id, inner_puzzle),
30 }
31 .tree_hash()
32 }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq, ToKlvm, FromKlvm)]
36#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
37#[klvm(list)]
38pub struct SingletonStruct {
39 pub mod_hash: Bytes32,
40 pub launcher_id: Bytes32,
41 #[klvm(rest)]
42 pub launcher_puzzle_hash: Bytes32,
43}
44
45impl SingletonStruct {
46 pub fn new(launcher_id: Bytes32) -> Self {
47 Self {
48 mod_hash: SINGLETON_TOP_LAYER_V1_1_HASH.into(),
49 launcher_id,
50 launcher_puzzle_hash: SINGLETON_LAUNCHER_HASH.into(),
51 }
52 }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, ToKlvm, FromKlvm)]
56#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
57#[klvm(list)]
58pub struct SingletonSolution<I> {
59 pub lineage_proof: Proof,
60 pub amount: u64,
61 pub inner_solution: I,
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq, ToKlvm, FromKlvm)]
65#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
66#[klvm(list)]
67pub struct LauncherSolution<T> {
68 pub singleton_puzzle_hash: Bytes32,
69 pub amount: u64,
70 pub key_value_list: T,
71}