Struct simplicity::node::Node
source · pub struct Node<N: Marker> { /* private fields */ }Expand description
A node in a Simplicity expression.
There are three node types provided by this library: ConstructNode, CommitNode,
and RedeemNode, which represent Simplicty programs during construction, at
commitment time, and at redemption time, respectively.
This generic structure is used to define conversions and mapping functions over nodes and DAGs, and allows users to define their own custom node types.
For equality and hashing purposes, nodes are characterized entirely by their
CMR and cached data. Users who create custom nodes should define a custom type
for Marker::CachedData and think carefully about whether and how to
implement the std::hash::Hash or equality traits.
Implementations§
source§impl<J: Jet> Node<Named<Commit<J>>>
impl<J: Jet> Node<Named<Commit<J>>>
pub fn from_node(root: &CommitNode<J>) -> Arc<Self>
sourcepub fn arrow(&self) -> &FinalArrow
pub fn arrow(&self) -> &FinalArrow
Accessor for the node’s type arrow
sourcepub fn to_commit_node(&self) -> Arc<CommitNode<J>>
pub fn to_commit_node(&self) -> Arc<CommitNode<J>>
Forget the names, yielding an ordinary CommitNode.
pub fn to_witness_node( &self, witness: &HashMap<Arc<str>, Arc<Value>>, disconnect: &HashMap<Arc<str>, Arc<NamedCommitNode<J>>> ) -> Arc<WitnessNode<J>>
sourcepub fn encode<W: Write>(&self, w: &mut BitWriter<W>) -> Result<usize>
pub fn encode<W: Write>(&self, w: &mut BitWriter<W>) -> Result<usize>
Encode a Simplicity expression to bits without any witness data
sourcepub fn encode_to_vec(&self) -> Vec<u8>
pub fn encode_to_vec(&self) -> Vec<u8>
Encode a Simplicity program to a vector of bytes, without any witness data.
source§impl<J: Jet> Node<Named<Construct<J>>>
impl<J: Jet> Node<Named<Construct<J>>>
sourcepub fn new(
name: Arc<str>,
position: Position,
user_source_types: Arc<[Type]>,
user_target_types: Arc<[Type]>,
inner: Inner<Arc<Self>, J, Arc<Self>, WitnessOrHole>
) -> Result<Self, Error>
pub fn new( name: Arc<str>, position: Position, user_source_types: Arc<[Type]>, user_target_types: Arc<[Type]>, inner: Inner<Arc<Self>, J, Arc<Self>, WitnessOrHole> ) -> Result<Self, Error>
Construct a named construct node from parts.
sourcepub fn renamed(&self, new_name: Arc<str>) -> Self
pub fn renamed(&self, new_name: Arc<str>) -> Self
Creates a copy of a node with a different name.
sourcepub fn finalize_types_main(&self) -> Result<Arc<NamedCommitNode<J>>, ErrorSet>
pub fn finalize_types_main(&self) -> Result<Arc<NamedCommitNode<J>>, ErrorSet>
Finalizes the types of the underlying [ConstructNode].
sourcepub fn finalize_types_non_main(
&self
) -> Result<Arc<NamedCommitNode<J>>, ErrorSet>
pub fn finalize_types_non_main( &self ) -> Result<Arc<NamedCommitNode<J>>, ErrorSet>
Finalizes the types of the underlying [ConstructNode], without setting
the root node’s arrow to 1->1.
pub fn finalize_types_inner( &self, for_main: bool ) -> Result<Arc<NamedCommitNode<J>>, ErrorSet>
source§impl<J: Jet> Node<Commit<J>>
impl<J: Jet> Node<Commit<J>>
sourcepub fn arrow(&self) -> &FinalArrow
pub fn arrow(&self) -> &FinalArrow
Accessor for the node’s arrow
sourcepub fn finalize<C: Converter<Commit<J>, Redeem<J>>>(
&self,
converter: &mut C
) -> Result<Arc<RedeemNode<J>>, C::Error>
pub fn finalize<C: Converter<Commit<J>, Redeem<J>>>( &self, converter: &mut C ) -> Result<Arc<RedeemNode<J>>, C::Error>
Finalizes a DAG, by iterating through through it without sharing, attaching witnesses, and hiding branches.
This is a thin wrapper around Node::convert which fixes a few types to make
it easier to use.
sourcepub fn unfinalize_types(&self) -> Result<Arc<ConstructNode<J>>, Error>
pub fn unfinalize_types(&self) -> Result<Arc<ConstructNode<J>>, Error>
Convert a CommitNode back to a ConstructNode by redoing type inference
sourcepub fn decode<I: Iterator<Item = u8>>(
bits: &mut BitIter<I>
) -> Result<Arc<Self>, Error>
pub fn decode<I: Iterator<Item = u8>>( bits: &mut BitIter<I> ) -> Result<Arc<Self>, Error>
Decode a Simplicity program from bits, without witness data.
§Usage
Use this method only if the serialization does not include the witness data. This means, the program simply has no witness during commitment, or the witness is provided by other means.
If the serialization contains the witness data, then use RedeemNode::decode().
sourcepub fn encode<W: Write>(&self, w: &mut BitWriter<W>) -> Result<usize>
pub fn encode<W: Write>(&self, w: &mut BitWriter<W>) -> Result<usize>
Encode a Simplicity expression to bits without any witness data
sourcepub fn encode_to_vec(&self) -> Vec<u8>
pub fn encode_to_vec(&self) -> Vec<u8>
Encode a Simplicity program to a vector of bytes, without any witness data.
source§impl<J: Jet> Node<Construct<J>>
impl<J: Jet> Node<Construct<J>>
sourcepub fn set_arrow_to_program(&self) -> Result<(), Error>
pub fn set_arrow_to_program(&self) -> Result<(), Error>
Sets the source and target type of the node to unit
sourcepub fn finalize_types(&self) -> Result<Arc<CommitNode<J>>, Error>
pub fn finalize_types(&self) -> Result<Arc<CommitNode<J>>, Error>
Convert a ConstructNode to a CommitNode by finalizing all of the types.
Also sets the source and target type of this node to unit. This is almost
certainly what you want, since the resulting CommitNode cannot be further
composed, and needs to be 1->1 to go on-chain. But if you don’t, call
[Self::finalize_types_without_fixing] instead.
sourcepub fn finalize_types_non_program(&self) -> Result<Arc<CommitNode<J>>, Error>
pub fn finalize_types_non_program(&self) -> Result<Arc<CommitNode<J>>, Error>
Convert a ConstructNode to a CommitNode by finalizing all of the types.
Does not sets the source and target type of this node to unit.
sourcepub fn decode<I: Iterator<Item = u8>>(
bits: &mut BitIter<I>
) -> Result<Arc<Self>, Error>
pub fn decode<I: Iterator<Item = u8>>( bits: &mut BitIter<I> ) -> Result<Arc<Self>, Error>
Decode a Simplicity expression from bits, without witness data.
§Usage
Use this method only if the serialization does not include the witness data. This means, the program simply has no witness during commitment, or the witness is provided by other means.
If the serialization contains the witness data, then use [RedeemNode::decode()].
source§impl<J: Jet> Node<Redeem<J>>
impl<J: Jet> Node<Redeem<J>>
sourcepub fn arrow(&self) -> &FinalArrow
pub fn arrow(&self) -> &FinalArrow
Accessor for the node’s type arrow
sourcepub fn bounds(&self) -> NodeBounds
pub fn bounds(&self) -> NodeBounds
Accessor for the node’s bit machine bounds
sourcepub fn unfinalize(&self) -> Result<Arc<CommitNode<J>>, Error>
pub fn unfinalize(&self) -> Result<Arc<CommitNode<J>>, Error>
Convert a RedeemNode back to a CommitNode by forgetting witnesses
and cached data.
sourcepub fn to_witness_node(&self) -> Arc<WitnessNode<J>>
pub fn to_witness_node(&self) -> Arc<WitnessNode<J>>
Convert a RedeemNode back into a WitnessNode
by loosening the finalized types, witness data and disconnected branches.
sourcepub fn decode<I: Iterator<Item = u8>>(
bits: &mut BitIter<I>
) -> Result<Arc<Self>, Error>
pub fn decode<I: Iterator<Item = u8>>( bits: &mut BitIter<I> ) -> Result<Arc<Self>, Error>
Decode a Simplicity program from bits, including the witness data.
sourcepub fn encode<W: Write>(&self, w: &mut BitWriter<W>) -> Result<usize>
pub fn encode<W: Write>(&self, w: &mut BitWriter<W>) -> Result<usize>
Encode the program to bits.
Includes witness data. Returns the number of written bits.
sourcepub fn encode_to_vec(&self) -> Vec<u8>
pub fn encode_to_vec(&self) -> Vec<u8>
Encode the program to a byte vector.
Includes witness data.
source§impl<J: Jet> Node<Witness<J>>
impl<J: Jet> Node<Witness<J>>
sourcepub fn pruned(&self) -> Arc<Self>
pub fn pruned(&self) -> Arc<Self>
Creates a copy of the node (and its entire DAG with the prune bit set)
sourcepub fn must_prune(&self) -> bool
pub fn must_prune(&self) -> bool
Whether the “must prune” bit is set on this node
pub fn prune_and_retype(&self) -> Arc<Self>
pub fn finalize(&self) -> Result<Arc<RedeemNode<J>>, Error>
source§impl<N: Marker> Node<N>
impl<N: Marker> Node<N>
sourcepub fn inner(&self) -> &Inner<Arc<Node<N>>, N::Jet, N::Disconnect, N::Witness>
pub fn inner(&self) -> &Inner<Arc<Node<N>>, N::Jet, N::Disconnect, N::Witness>
Accessor for the node’s “inner value”, i.e. its combinator
sourcepub fn sharing_id(&self) -> Option<N::SharingId>
pub fn sharing_id(&self) -> Option<N::SharingId>
Accessor for the node’s cached data
sourcepub fn cached_data(&self) -> &N::CachedData
pub fn cached_data(&self) -> &N::CachedData
Accessor for the node’s cached data
sourcepub fn from_parts(
inner: Inner<Arc<Self>, N::Jet, N::Disconnect, N::Witness>,
data: N::CachedData
) -> Self
pub fn from_parts( inner: Inner<Arc<Self>, N::Jet, N::Disconnect, N::Witness>, data: N::CachedData ) -> Self
Contruct a node from its constituent parts.
This method can be used to directly costruct a node. It will compute the CMR
automatically based on the value of inner but requires that cached_data
be provided.
If available, [`Constructible’] and its dependent traits will be easier to use.
sourcepub fn convert<S, M, C>(
&self,
converter: &mut C
) -> Result<Arc<Node<M>>, C::Error>
pub fn convert<S, M, C>( &self, converter: &mut C ) -> Result<Arc<Node<M>>, C::Error>
Generic conversion function from one type of node to another, with the ability to prune during the conversion.
Parameterized over what kind of sharing to use when iterating over the DAG, and what conversion logic to use.
See the documentation for Converter for details.