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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.