chia_sdk_driver/action_system/spend_kind/
conditions_spend.rs

1use std::collections::HashSet;
2
3use chia_sdk_types::{Condition, Conditions};
4
5use crate::{Output, OutputSet};
6
7#[derive(Debug, Default, Clone)]
8pub struct ConditionsSpend {
9    conditions: Conditions,
10    outputs: HashSet<Output>,
11}
12
13impl ConditionsSpend {
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    pub fn add_conditions(&mut self, conditions: Conditions) {
19        for condition in conditions {
20            if let Some(create_coin) = condition.as_create_coin() {
21                let output = Output::new(create_coin.puzzle_hash, create_coin.amount);
22                self.outputs.insert(output);
23            }
24            self.conditions.push(condition);
25        }
26    }
27
28    pub fn finish(self) -> Conditions {
29        self.conditions
30    }
31}
32
33impl OutputSet for ConditionsSpend {
34    fn has_output(&self, output: &Output) -> bool {
35        self.outputs.contains(output)
36    }
37
38    fn can_run_cat_tail(&self) -> bool {
39        !self.conditions.iter().any(Condition::is_run_cat_tail)
40    }
41
42    fn missing_singleton_output(&self) -> bool {
43        !self.conditions.iter().any(|condition| {
44            condition.is_melt_singleton()
45                || condition
46                    .as_create_coin()
47                    .is_some_and(|create_coin| create_coin.amount % 2 == 1)
48        })
49    }
50}