Skip to content

Commit

Permalink
Merge pull request #117 from xch-dev/parse-metadata-update-fix
Browse files Browse the repository at this point in the history
Fix metadata update parser
  • Loading branch information
Rigidity authored Nov 8, 2024
2 parents 37bb4b6 + cc8bc67 commit dadee36
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/chia-sdk-driver/src/primitives/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ where
) -> Result<Option<Self>, DriverError>
where
Self: Sized,
M: Clone,
{
let Some(singleton_layer) =
SingletonLayer::<Puzzle>::parse_puzzle(allocator, parent_puzzle)?
Expand Down Expand Up @@ -337,10 +338,17 @@ where
}

if let Some(new_metadata) = new_metadata {
let metadata_updater_solution = clvm_list!(
layers.inner_puzzle.metadata.clone(),
layers.inner_puzzle.metadata_updater_puzzle_hash,
new_metadata.updater_solution
)
.to_clvm(allocator)?;

let output = run_puzzle(
allocator,
new_metadata.updater_puzzle_reveal,
new_metadata.updater_solution,
metadata_updater_solution,
)?;

let output =
Expand Down Expand Up @@ -497,6 +505,7 @@ mod tests {
let _did = did.update(ctx, &p2, mint_nft)?;

let metadata_update = MetadataUpdate::NewDataUri("another.com".to_string()).spend(ctx)?;
let parent_nft = nft.clone();
let nft: Nft<NftMetadata> =
nft.transfer_with_metadata(ctx, &p2, puzzle_hash, metadata_update, Conditions::new())?;

Expand All @@ -509,10 +518,34 @@ mod tests {
}
);

let child_nft = nft.clone();
let _nft = nft.transfer(ctx, &p2, puzzle_hash, Conditions::new())?;

sim.spend_coins(ctx.take(), &[sk])?;

// Ensure that the metadata update can be parsed.
let parent_puzzle = sim
.puzzle_reveal(parent_nft.coin.coin_id())
.expect("missing puzzle");

let parent_solution = sim
.solution(parent_nft.coin.coin_id())
.expect("missing solution");

let parent_puzzle = parent_puzzle.to_clvm(&mut ctx.allocator)?;
let parent_puzzle = Puzzle::parse(&ctx.allocator, parent_puzzle);
let parent_solution = parent_solution.to_clvm(&mut ctx.allocator)?;

let new_child_nft = Nft::<NftMetadata>::parse_child(
&mut ctx.allocator,
parent_nft.coin,
parent_puzzle,
parent_solution,
)?
.expect("child is not an NFT");

assert_eq!(new_child_nft, child_nft);

Ok(())
}

Expand Down

0 comments on commit dadee36

Please sign in to comment.