chik_sdk_bindings/
mips.rs

1mod members;
2mod memos;
3mod restrictions;
4mod spend;
5
6pub use members::*;
7pub use memos::*;
8pub use restrictions::*;
9pub use spend::*;
10
11use binky::Result;
12use chik_protocol::{Bytes32, Coin};
13use chik_sdk_driver as sdk;
14use chik_sdk_types::{puzzles::AddDelegatedPuzzleWrapper, Mod};
15use klvm_utils::TreeHash;
16
17use crate::{Program, Proof};
18
19#[derive(Clone)]
20pub struct Vault {
21    pub coin: Coin,
22    pub launcher_id: Bytes32,
23    pub proof: Proof,
24    pub custody_hash: TreeHash,
25}
26
27impl Vault {
28    pub fn child(&self, custody_hash: TreeHash) -> Result<Self> {
29        Ok(sdk::Vault::from(self.clone()).child(custody_hash).into())
30    }
31}
32
33impl From<sdk::Vault> for Vault {
34    fn from(value: sdk::Vault) -> Self {
35        Vault {
36            coin: value.coin,
37            launcher_id: value.launcher_id,
38            proof: value.proof.into(),
39            custody_hash: value.custody_hash,
40        }
41    }
42}
43
44impl From<Vault> for sdk::Vault {
45    fn from(value: Vault) -> Self {
46        sdk::Vault {
47            coin: value.coin,
48            launcher_id: value.launcher_id,
49            proof: value.proof.into(),
50            custody_hash: value.custody_hash,
51        }
52    }
53}
54
55#[derive(Clone)]
56pub struct VaultMint {
57    pub vault: Vault,
58    pub parent_conditions: Vec<Program>,
59}
60
61pub fn wrapped_delegated_puzzle_hash(
62    restrictions: Vec<Restriction>,
63    delegated_puzzle_hash: TreeHash,
64) -> Result<TreeHash> {
65    let mut delegated_puzzle_hash = delegated_puzzle_hash;
66
67    for restriction in restrictions.into_iter().rev() {
68        if !matches!(restriction.kind, RestrictionKind::DelegatedPuzzleWrapper) {
69            continue;
70        }
71
72        delegated_puzzle_hash =
73            AddDelegatedPuzzleWrapper::new(restriction.puzzle_hash, delegated_puzzle_hash)
74                .curry_tree_hash();
75    }
76
77    Ok(delegated_puzzle_hash)
78}