chik_sdk_bindings/puzzle/
streamed_cat.rs1use binky::Result;
2use chik_protocol::{Bytes, Bytes32};
3use chik_sdk_driver::{StreamedCat, StreamingPuzzleInfo};
4
5pub trait StreamedCatExt {}
6
7impl StreamedCatExt for StreamedCat {}
8
9pub trait StreamingPuzzleInfoExt: Sized {
10 fn amount_to_be_paid(&self, my_coin_amount: u64, payment_time: u64) -> Result<u64>;
11 fn get_hint(recipient: Bytes32) -> Result<Bytes32>;
12 fn get_launch_hints(&self) -> Result<Vec<Bytes>>;
13 fn inner_puzzle_hash(&self) -> Result<Bytes32>;
14 fn from_memos(memos: Vec<Bytes>) -> Result<Option<Self>>;
15}
16
17impl StreamingPuzzleInfoExt for StreamingPuzzleInfo {
18 fn amount_to_be_paid(&self, my_coin_amount: u64, payment_time: u64) -> Result<u64> {
19 Ok(my_coin_amount * (payment_time - self.last_payment_time)
22 / (self.end_time - self.last_payment_time))
23 }
24
25 fn get_hint(recipient: Bytes32) -> Result<Bytes32> {
26 Ok(Self::get_hint(recipient))
27 }
28
29 fn get_launch_hints(&self) -> Result<Vec<Bytes>> {
30 Ok(self.get_launch_hints())
31 }
32
33 fn inner_puzzle_hash(&self) -> Result<Bytes32> {
34 Ok(self.inner_puzzle_hash().into())
35 }
36
37 fn from_memos(memos: Vec<Bytes>) -> Result<Option<Self>> {
38 Ok(Self::from_memos(&memos)?)
39 }
40}
41
42#[derive(Clone)]
43pub struct StreamedCatParsingResult {
44 pub streamed_cat: Option<StreamedCat>,
45 pub last_spend_was_clawback: bool,
46 pub last_payment_amount_if_clawback: u64,
47}