pub trait Layer {
type Solution;
// Required methods
fn parse_puzzle(
allocator: &Allocator,
puzzle: Puzzle,
) -> Result<Option<Self>, DriverError>
where Self: Sized;
fn parse_solution(
allocator: &Allocator,
solution: NodePtr,
) -> Result<Self::Solution, DriverError>;
fn construct_puzzle(
&self,
ctx: &mut SpendContext,
) -> Result<NodePtr, DriverError>;
fn construct_solution(
&self,
ctx: &mut SpendContext,
solution: Self::Solution,
) -> Result<NodePtr, DriverError>;
// Provided methods
fn construct_spend(
&self,
ctx: &mut SpendContext,
solution: Self::Solution,
) -> Result<Spend, DriverError> { ... }
fn construct_coin_spend(
&self,
ctx: &mut SpendContext,
coin: Coin,
solution: Self::Solution,
) -> Result<CoinSpend, DriverError> { ... }
}Expand description
An individual layer in a puzzle’s hierarchy.
Required Associated Types§
sourcetype Solution
type Solution
Most of the time, this is an actual CLVM type representing the solution.
However, you can also use a helper struct and customize Layer::construct_solution and Layer::parse_solution.
Required Methods§
sourcefn parse_puzzle(
allocator: &Allocator,
puzzle: Puzzle,
) -> Result<Option<Self>, DriverError>where
Self: Sized,
fn parse_puzzle(
allocator: &Allocator,
puzzle: Puzzle,
) -> Result<Option<Self>, DriverError>where
Self: Sized,
Parses this layer from the given puzzle, returning None if the puzzle doesn’t match.
An error is returned if the puzzle should have matched but couldn’t be parsed.
sourcefn parse_solution(
allocator: &Allocator,
solution: NodePtr,
) -> Result<Self::Solution, DriverError>
fn parse_solution( allocator: &Allocator, solution: NodePtr, ) -> Result<Self::Solution, DriverError>
Parses the Layer::Solution type from a CLVM solution pointer.
sourcefn construct_puzzle(
&self,
ctx: &mut SpendContext,
) -> Result<NodePtr, DriverError>
fn construct_puzzle( &self, ctx: &mut SpendContext, ) -> Result<NodePtr, DriverError>
Constructs the full curried puzzle for this layer.
Ideally, the puzzle itself should be cached in the SpendContext.
sourcefn construct_solution(
&self,
ctx: &mut SpendContext,
solution: Self::Solution,
) -> Result<NodePtr, DriverError>
fn construct_solution( &self, ctx: &mut SpendContext, solution: Self::Solution, ) -> Result<NodePtr, DriverError>
Constructs the full solution for this layer. Can be used to construct the solution from a helper struct, if it’s not directly a CLVM type. It’s also possible to influence the solution based on the puzzle, if needed.
Provided Methods§
sourcefn construct_spend(
&self,
ctx: &mut SpendContext,
solution: Self::Solution,
) -> Result<Spend, DriverError>
fn construct_spend( &self, ctx: &mut SpendContext, solution: Self::Solution, ) -> Result<Spend, DriverError>
Creates a spend for this layer.
sourcefn construct_coin_spend(
&self,
ctx: &mut SpendContext,
coin: Coin,
solution: Self::Solution,
) -> Result<CoinSpend, DriverError>
fn construct_coin_spend( &self, ctx: &mut SpendContext, coin: Coin, solution: Self::Solution, ) -> Result<CoinSpend, DriverError>
Creates a coin spend for this layer.