use chia_puzzle_types::Memos;
use chia_wallet_sdk::driver::{SpendContext, SpendWithConditions};
use chia_wallet_sdk::types::Conditions;
use crate::error::{Error, Result};
use crate::types::{CreatedOption, OptionSpend, Owner};
pub fn clawback(
ctx: &mut SpendContext,
creator: &Owner,
created: &CreatedOption,
) -> Result<OptionSpend> {
if let Some(puzzle_hash) = creator.standard_puzzle_hash() {
if puzzle_hash != created.underlying.creator_puzzle_hash {
return Err(Error::invalid(
"clawback owner does not match the option's creator puzzle hash",
));
}
}
let inner = creator.spend_with_conditions(
ctx,
Conditions::new().create_coin(
created.underlying.creator_puzzle_hash,
created.underlying_coin.amount,
Memos::None,
),
)?;
created
.underlying
.clawback_coin_spend(ctx, created.underlying_coin, inner)?;
Ok(OptionSpend {
coin_spends: ctx.take(),
created: None,
})
}