chik_sdk_bindings/puzzle/
cat.rs

1use binky::Result;
2use chik_protocol::Bytes32;
3use chik_puzzle_types::LineageProof;
4use chik_sdk_driver::{Cat, CatInfo};
5use klvm_utils::TreeHash;
6
7use crate::{Puzzle, Spend};
8
9pub trait CatExt {
10    fn child_lineage_proof(&self) -> Result<LineageProof>;
11    fn child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Result<Cat>;
12    fn unrevocable_child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Result<Cat>;
13}
14
15impl CatExt for Cat {
16    fn child_lineage_proof(&self) -> Result<LineageProof> {
17        Ok(self.child_lineage_proof())
18    }
19
20    fn child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Result<Cat> {
21        Ok(self.child(p2_puzzle_hash, amount))
22    }
23
24    fn unrevocable_child(&self, p2_puzzle_hash: Bytes32, amount: u64) -> Result<Cat> {
25        Ok(self.unrevocable_child(p2_puzzle_hash, amount))
26    }
27}
28
29pub trait CatInfoExt {
30    fn inner_puzzle_hash(&self) -> Result<TreeHash>;
31    fn puzzle_hash(&self) -> Result<TreeHash>;
32}
33
34impl CatInfoExt for CatInfo {
35    fn inner_puzzle_hash(&self) -> Result<TreeHash> {
36        Ok(self.inner_puzzle_hash())
37    }
38
39    fn puzzle_hash(&self) -> Result<TreeHash> {
40        Ok(self.puzzle_hash())
41    }
42}
43
44#[derive(Clone)]
45pub struct CatSpend {
46    pub cat: Cat,
47    pub spend: Spend,
48}
49
50impl From<CatSpend> for chik_sdk_driver::CatSpend {
51    fn from(value: CatSpend) -> Self {
52        chik_sdk_driver::CatSpend::new(value.cat, value.spend.into())
53    }
54}
55
56#[derive(Clone)]
57pub struct ParsedCat {
58    pub asset_id: Bytes32,
59    pub p2_puzzle: Puzzle,
60}