action_layer_driver/singleton/
types.rs1use chia::protocol::{Bytes32, Coin};
4use chia::puzzles::{EveProof, LineageProof, Proof};
5use clvm_utils::TreeHash;
6
7#[derive(Debug, Clone)]
9pub enum SingletonLineage {
10 Eve {
12 launcher_parent_id: Bytes32,
14 amount: u64,
16 },
17 Lineage {
19 parent_coin: Coin,
21 parent_inner_hash: TreeHash,
23 },
24}
25
26impl SingletonLineage {
27 pub fn to_proof(&self) -> Proof {
29 match self {
30 SingletonLineage::Eve {
31 launcher_parent_id,
32 amount,
33 } => Proof::Eve(EveProof {
34 parent_parent_coin_info: *launcher_parent_id,
35 parent_amount: *amount,
36 }),
37 SingletonLineage::Lineage {
38 parent_coin,
39 parent_inner_hash,
40 } => Proof::Lineage(LineageProof {
41 parent_parent_coin_info: parent_coin.parent_coin_info,
42 parent_inner_puzzle_hash: (*parent_inner_hash).into(),
43 parent_amount: parent_coin.amount,
44 }),
45 }
46 }
47
48 pub fn eve(funding_coin_id: Bytes32, singleton_amount: u64) -> Self {
50 SingletonLineage::Eve {
51 launcher_parent_id: funding_coin_id,
52 amount: singleton_amount,
53 }
54 }
55
56 pub fn lineage(parent_coin: Coin, parent_inner_hash: TreeHash) -> Self {
58 SingletonLineage::Lineage {
59 parent_coin,
60 parent_inner_hash,
61 }
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct SingletonCoin {
68 pub launcher_id: Bytes32,
70 pub coin: Coin,
72 pub lineage: SingletonLineage,
74}
75
76impl SingletonCoin {
77 pub fn new(launcher_id: Bytes32, coin: Coin, lineage: SingletonLineage) -> Self {
79 Self {
80 launcher_id,
81 coin,
82 lineage,
83 }
84 }
85
86 pub fn proof(&self) -> Proof {
88 self.lineage.to_proof()
89 }
90
91 pub fn coin_id(&self) -> Bytes32 {
93 self.coin.coin_id()
94 }
95}
96
97#[derive(Debug, Clone)]
99pub struct LaunchResult {
100 pub launcher_id: Bytes32,
102 pub coin: Coin,
104 pub conditions: chia_wallet_sdk::types::Conditions,
106}
107
108#[derive(Debug, Clone)]
110pub struct ActionSpendResult<T> {
111 pub new_coin: Option<Coin>,
113 pub new_lineage: Option<SingletonLineage>,
115 pub output: T,
117}
118
119impl<T> ActionSpendResult<T> {
120 pub fn normal(new_coin: Coin, new_lineage: SingletonLineage, output: T) -> Self {
122 Self {
123 new_coin: Some(new_coin),
124 new_lineage: Some(new_lineage),
125 output,
126 }
127 }
128
129 pub fn melted(output: T) -> Self {
131 Self {
132 new_coin: None,
133 new_lineage: None,
134 output,
135 }
136 }
137
138 pub fn is_melted(&self) -> bool {
140 self.new_coin.is_none()
141 }
142}
143
144#[derive(Debug, Clone, Copy, Default)]
146pub struct NoOutput;
147
148#[derive(Debug, Clone, Copy)]
150pub struct Melted;