chia_sdk_driver/action_system/spend_kind/
settlement_spend.rs

1use std::collections::HashSet;
2
3use chia_puzzle_types::offer::NotarizedPayment;
4
5use crate::{Output, OutputSet};
6
7#[derive(Debug, Default, Clone)]
8pub struct SettlementSpend {
9    notarized_payments: Vec<NotarizedPayment>,
10    outputs: HashSet<Output>,
11}
12
13impl SettlementSpend {
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    pub fn add_notarized_payment(&mut self, notarized_payment: NotarizedPayment) {
19        for payment in &notarized_payment.payments {
20            self.outputs
21                .insert(Output::new(payment.puzzle_hash, payment.amount));
22        }
23
24        self.notarized_payments.push(notarized_payment);
25    }
26
27    pub fn finish(self) -> Vec<NotarizedPayment> {
28        self.notarized_payments
29    }
30}
31
32impl OutputSet for SettlementSpend {
33    fn has_output(&self, output: &Output) -> bool {
34        self.outputs.contains(output)
35    }
36
37    fn can_run_cat_tail(&self) -> bool {
38        false
39    }
40
41    fn missing_singleton_output(&self) -> bool {
42        !self.outputs.iter().any(|output| output.amount % 2 == 1)
43    }
44}