diff --git a/crates/chia-sdk-driver/src/layers/cat_layer.rs b/crates/chia-sdk-driver/src/layers/cat_layer.rs index 849f672..d492520 100644 --- a/crates/chia-sdk-driver/src/layers/cat_layer.rs +++ b/crates/chia-sdk-driver/src/layers/cat_layer.rs @@ -115,6 +115,8 @@ mod tests { use chia_protocol::Coin; use chia_puzzles::CoinProof; + use crate::ValueLayer; + use super::*; #[test] @@ -122,17 +124,17 @@ mod tests { let mut ctx = SpendContext::new(); let asset_id = Bytes32::new([1; 32]); - let layer = CatLayer::new(asset_id, "Hello, world!".to_string()); + let layer = CatLayer::new(asset_id, ValueLayer("Hello, world!".to_string())); let ptr = layer.construct_puzzle(&mut ctx)?; let puzzle = Puzzle::parse(&ctx.allocator, ptr); - let roundtrip = - CatLayer::::parse_puzzle(&ctx.allocator, puzzle)?.expect("invalid CAT layer"); + let roundtrip = CatLayer::>::parse_puzzle(&ctx.allocator, puzzle)? + .expect("invalid CAT layer"); assert_eq!(roundtrip.asset_id, layer.asset_id); assert_eq!(roundtrip.inner_puzzle, layer.inner_puzzle); - let expected = CatArgs::curry_tree_hash(asset_id, layer.inner_puzzle.tree_hash()); + let expected = CatArgs::curry_tree_hash(asset_id, layer.inner_puzzle.0.tree_hash()); assert_eq!(hex::encode(ctx.tree_hash(ptr)), hex::encode(expected)); Ok(()) @@ -142,7 +144,7 @@ mod tests { fn test_cat_solution() -> anyhow::Result<()> { let mut ctx = SpendContext::new(); - let layer = CatLayer::new(Bytes32::default(), NodePtr::NIL); + let layer = CatLayer::new(Bytes32::default(), ValueLayer(NodePtr::NIL)); let solution = CatSolution { inner_puzzle_solution: NodePtr::NIL, @@ -165,7 +167,8 @@ mod tests { assert_eq!(hex::encode(actual_hash), hex::encode(expected_hash)); - let roundtrip = CatLayer::::parse_solution(&ctx.allocator, actual_ptr)?; + let roundtrip = + CatLayer::>::parse_solution(&ctx.allocator, actual_ptr)?; assert_eq!(roundtrip, solution); Ok(()) diff --git a/crates/chia-sdk-driver/src/layers/p2_singleton_layer.rs b/crates/chia-sdk-driver/src/layers/p2_singleton_layer.rs index 13c9189..db3fa75 100644 --- a/crates/chia-sdk-driver/src/layers/p2_singleton_layer.rs +++ b/crates/chia-sdk-driver/src/layers/p2_singleton_layer.rs @@ -115,7 +115,7 @@ mod tests { use super::*; - use crate::{Launcher, SingletonLayer, SpendWithConditions, StandardLayer}; + use crate::{Launcher, SingletonLayer, SpendWithConditions, StandardLayer, ValueLayer}; #[test] fn test_p2_singleton_layer() -> anyhow::Result<()> { @@ -149,19 +149,20 @@ mod tests { .create_puzzle_announcement(p2_coin.coin_id().into()), )? .solution; - let singleton_spend = SingletonLayer::new(launcher_id, p2.construct_puzzle(ctx)?) - .construct_coin_spend( - ctx, - singleton, - SingletonSolution { - lineage_proof: Proof::Eve(EveProof { - parent_parent_coin_info: coin.coin_id(), - parent_amount: 1, - }), - amount: singleton.amount, - inner_solution, - }, - )?; + let singleton_spend = + SingletonLayer::new(launcher_id, ValueLayer(p2.construct_puzzle(ctx)?)) + .construct_coin_spend( + ctx, + singleton, + SingletonSolution { + lineage_proof: Proof::Eve(EveProof { + parent_parent_coin_info: coin.coin_id(), + parent_amount: 1, + }), + amount: singleton.amount, + inner_solution, + }, + )?; ctx.insert(singleton_spend); sim.spend_coins(ctx.take(), &[sk])?; diff --git a/crates/chia-sdk-driver/src/primitives/cat.rs b/crates/chia-sdk-driver/src/primitives/cat.rs index ae2a333..f015a7f 100644 --- a/crates/chia-sdk-driver/src/primitives/cat.rs +++ b/crates/chia-sdk-driver/src/primitives/cat.rs @@ -8,7 +8,7 @@ use chia_sdk_types::{run_puzzle, Condition, Conditions, CreateCoin}; use clvm_traits::{clvm_quote, FromClvm}; use clvmr::{Allocator, NodePtr}; -use crate::{CatLayer, DriverError, Layer, Puzzle, Spend, SpendContext}; +use crate::{CatLayer, DriverError, Layer, Puzzle, Spend, SpendContext, ValueLayer}; mod cat_spend; mod single_cat_spend; @@ -85,7 +85,7 @@ impl Cat { conditions: Conditions, ) -> Result<(Conditions, Cat), DriverError> { let inner_puzzle = ctx.alloc(&clvm_quote!(conditions))?; - let eve_layer = CatLayer::new(asset_id, inner_puzzle); + let eve_layer = CatLayer::new(asset_id, ValueLayer(inner_puzzle)); let inner_puzzle_hash = ctx.tree_hash(inner_puzzle).into(); let puzzle_ptr = eve_layer.construct_puzzle(ctx)?; let puzzle_hash = ctx.tree_hash(puzzle_ptr).into(); @@ -169,7 +169,7 @@ impl Cat { /// Creates a coin spend for this CAT. pub fn spend(&self, ctx: &mut SpendContext, spend: SingleCatSpend) -> Result<(), DriverError> { - let cat_layer = CatLayer::new(self.asset_id, spend.inner_spend.puzzle); + let cat_layer = CatLayer::new(self.asset_id, ValueLayer(spend.inner_spend.puzzle)); let puzzle = cat_layer.construct_puzzle(ctx)?; let solution = cat_layer.construct_solution( diff --git a/crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs b/crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs index 6be2036..edf7f46 100644 --- a/crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs +++ b/crates/chia-sdk-driver/src/primitives/datalayer/datastore.rs @@ -16,7 +16,9 @@ use clvm_utils::{tree_hash, CurriedProgram, ToTreeHash, TreeHash}; use clvmr::{Allocator, NodePtr}; use num_bigint::BigInt; -use crate::{DriverError, Layer, NftStateLayer, Puzzle, SingletonLayer, Spend, SpendContext}; +use crate::{ + DriverError, Layer, NftStateLayer, Puzzle, SingletonLayer, Spend, SpendContext, ValueLayer, +}; use super::{ get_merkle_tree, DataStoreInfo, DataStoreMetadata, DelegatedPuzzle, HintType, @@ -51,7 +53,7 @@ where let layers = self .info .clone() - .into_layers_without_delegation_layer(inner_spend.puzzle); + .into_layers_without_delegation_layer(ValueLayer(inner_spend.puzzle)); let solution_ptr = layers.construct_solution( ctx, diff --git a/crates/chia-sdk-driver/src/primitives/did.rs b/crates/chia-sdk-driver/src/primitives/did.rs index b112594..f41f998 100644 --- a/crates/chia-sdk-driver/src/primitives/did.rs +++ b/crates/chia-sdk-driver/src/primitives/did.rs @@ -11,6 +11,7 @@ use clvmr::{Allocator, NodePtr}; use crate::{ DidLayer, DriverError, Layer, Puzzle, SingletonLayer, Spend, SpendContext, SpendWithConditions, + ValueLayer, }; mod did_info; @@ -85,7 +86,10 @@ where { /// Creates a coin spend for this DID. pub fn spend(&self, ctx: &mut SpendContext, inner_spend: Spend) -> Result<(), DriverError> { - let layers = self.info.clone().into_layers(inner_spend.puzzle); + let layers = self + .info + .clone() + .into_layers(ValueLayer(inner_spend.puzzle)); let puzzle = layers.construct_puzzle(ctx)?; let solution = layers.construct_solution( @@ -230,7 +234,7 @@ where } let singleton_solution = - SingletonLayer::::parse_solution(allocator, parent_solution)?; + SingletonLayer::::parse_solution(allocator, parent_solution)?; let output = run_puzzle( allocator, diff --git a/crates/chia-sdk-driver/src/primitives/nft.rs b/crates/chia-sdk-driver/src/primitives/nft.rs index aed7c39..2bd232c 100644 --- a/crates/chia-sdk-driver/src/primitives/nft.rs +++ b/crates/chia-sdk-driver/src/primitives/nft.rs @@ -15,7 +15,7 @@ use clvmr::{sha2::Sha256, Allocator, NodePtr}; use crate::{ DriverError, Layer, NftOwnershipLayer, NftStateLayer, Puzzle, RoyaltyTransferLayer, - SettlementLayer, SingletonLayer, Spend, SpendContext, SpendWithConditions, + SettlementLayer, SingletonLayer, Spend, SpendContext, SpendWithConditions, ValueLayer, }; mod did_owner; @@ -106,7 +106,10 @@ where { /// Creates a coin spend for this NFT. pub fn spend(&self, ctx: &mut SpendContext, inner_spend: Spend) -> Result<(), DriverError> { - let layers = self.info.clone().into_layers(inner_spend.puzzle); + let layers = self + .info + .clone() + .into_layers(ValueLayer(inner_spend.puzzle)); let puzzle = layers.construct_puzzle(ctx)?; let solution = layers.construct_solution( diff --git a/crates/chia-sdk-types/src/puzzle_mod.rs b/crates/chia-sdk-types/src/puzzle_mod.rs index 169cdaa..5a8724c 100644 --- a/crates/chia-sdk-types/src/puzzle_mod.rs +++ b/crates/chia-sdk-types/src/puzzle_mod.rs @@ -42,6 +42,15 @@ pub trait Mod { } } +impl Mod for &T +where + T: Mod, +{ + const MOD_REVEAL: &'static [u8] = T::MOD_REVEAL; + const MOD_HASH: TreeHash = T::MOD_HASH; + type Solution = T::Solution; +} + impl Mod for StandardArgs { const MOD_REVEAL: &[u8] = &STANDARD_PUZZLE; const MOD_HASH: TreeHash = STANDARD_PUZZLE_HASH;