chia_sdk_driver/primitives/mips/
mips_spend.rs1use std::collections::HashMap;
2
3use clvm_utils::TreeHash;
4
5use crate::{DriverError, Spend, SpendContext};
6
7use super::InnerPuzzleSpend;
8
9#[derive(Debug, Clone)]
10pub struct MipsSpend {
11 pub delegated: Spend,
12 pub members: HashMap<TreeHash, InnerPuzzleSpend>,
13 pub restrictions: HashMap<TreeHash, Spend>,
14}
15
16impl MipsSpend {
17 pub fn new(delegated_spend: Spend) -> Self {
18 Self {
19 delegated: delegated_spend,
20 members: HashMap::new(),
21 restrictions: HashMap::new(),
22 }
23 }
24
25 pub fn spend(
26 &self,
27 ctx: &mut SpendContext,
28 custody_hash: TreeHash,
29 ) -> Result<Spend, DriverError> {
30 self.members
31 .get(&custody_hash)
32 .ok_or(DriverError::MissingSubpathSpend)?
33 .spend(ctx, self, &mut Vec::new(), true)
34 }
35}