Skip to content

Commit

Permalink
Simplify CAT issuance info
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed May 17, 2024
1 parent 5563f01 commit ad2eca1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/parser/puzzles/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ mod tests {
asset_id: issuance_info.asset_id,
p2_puzzle_hash: puzzle_hash,
coin: Coin::new(issuance_info.eve_coin.coin_id(), cat_puzzle_hash.into(), 1),
lineage_proof: LineageProof {
parent_parent_coin_id: issuance_info.eve_coin.parent_coin_info,
parent_inner_puzzle_hash: issuance_info.eve_inner_puzzle_hash,
parent_amount: 1,
},
lineage_proof: issuance_info.lineage_proof,
};

StandardSpend::new()
Expand Down
27 changes: 16 additions & 11 deletions src/spends/puzzles/cat/issue_cat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use chia_bls::PublicKey;
use chia_protocol::{Bytes32, Coin, CoinSpend};
use chia_puzzles::cat::{
CatArgs, CatSolution, CoinProof, EverythingWithSignatureTailArgs, CAT_PUZZLE_HASH,
use chia_puzzles::{
cat::{CatArgs, CatSolution, CoinProof, EverythingWithSignatureTailArgs, CAT_PUZZLE_HASH},
LineageProof,
};
use clvm_traits::clvm_quote;
use clvm_utils::CurriedProgram;
Expand All @@ -16,8 +17,8 @@ pub struct IssueCat {

pub struct CatIssuanceInfo {
pub asset_id: Bytes32,
pub lineage_proof: LineageProof,
pub eve_coin: Coin,
pub eve_inner_puzzle_hash: Bytes32,
}

impl IssueCat {
Expand Down Expand Up @@ -56,10 +57,10 @@ impl IssueCat {
program: tail,
solution: NodePtr::NIL,
})?)
.finish(ctx, asset_id, amount)
.finish_raw(ctx, asset_id, amount)
}

pub fn finish(
pub fn finish_raw(
self,
ctx: &mut SpendContext,
asset_id: Bytes32,
Expand All @@ -80,13 +81,13 @@ impl IssueCat {
})?;

let puzzle_hash = ctx.tree_hash(puzzle).into();
let coin = Coin::new(self.parent_coin_id, puzzle_hash, amount);
let eve_coin = Coin::new(self.parent_coin_id, puzzle_hash, amount);

let solution = ctx.serialize(CatSolution {
inner_puzzle_solution: (),
lineage_proof: None,
prev_coin_id: coin.coin_id(),
this_coin_info: coin,
prev_coin_id: eve_coin.coin_id(),
this_coin_info: eve_coin,
next_coin_proof: CoinProof {
parent_coin_info: self.parent_coin_id,
inner_puzzle_hash,
Expand All @@ -97,7 +98,7 @@ impl IssueCat {
})?;

let puzzle_reveal = ctx.serialize(puzzle)?;
ctx.spend(CoinSpend::new(coin, puzzle_reveal, solution));
ctx.spend(CoinSpend::new(eve_coin, puzzle_reveal, solution));

let chained_spend = ChainedSpend {
parent_conditions: vec![ctx.alloc(CreateCoinWithMemos {
Expand All @@ -109,8 +110,12 @@ impl IssueCat {

let issuance_info = CatIssuanceInfo {
asset_id,
eve_coin: coin,
eve_inner_puzzle_hash: inner_puzzle_hash,
lineage_proof: LineageProof {
parent_parent_coin_id: eve_coin.parent_coin_info,
parent_inner_puzzle_hash: inner_puzzle_hash,
parent_amount: eve_coin.amount,
},
eve_coin,
};

Ok((chained_spend, issuance_info))
Expand Down
8 changes: 1 addition & 7 deletions src/spends/puzzles/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,6 @@ mod tests {
let assert_cat =
offer_announcement_id(&mut ctx, cat_settlements_hash.into(), cat_payment.clone())?;

let lineage_proof = LineageProof {
parent_parent_coin_id: parent.coin_id(),
parent_inner_puzzle_hash: cat_info.eve_inner_puzzle_hash,
parent_amount: 1000,
};

let inner_spend = StandardSpend::new()
.condition(ctx.alloc(CreateCoinWithMemos {
puzzle_hash: SETTLEMENT_PAYMENTS_PUZZLE_HASH.into(),
Expand All @@ -225,7 +219,7 @@ mod tests {
.inner_spend(&mut ctx, pk)?;

CatSpend::new(cat_info.asset_id)
.spend(cat, inner_spend, lineage_proof, 0)
.spend(cat, inner_spend, cat_info.lineage_proof, 0)
.finish(&mut ctx)?;

let cat_puzzle_hash = CurriedProgram {
Expand Down

0 comments on commit ad2eca1

Please sign in to comment.