Bitcoin Core  24.99.0
P2P Digital Currency
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
miniscript::Node< Key > Struct Template Reference

A node in a miniscript expression. More...

#include <miniscript.h>

Collaboration diagram for miniscript::Node< Key >:
[legend]

Public Member Functions

template<typename Ctx >
CScript ToScript (const Ctx &ctx) const
 
template<typename CTx >
std::optional< std::string > ToString (const CTx &ctx) const
 
template<typename Ctx >
void DuplicateKeyCheck (const Ctx &ctx) const
 Update duplicate key information in this Node. More...
 
size_t ScriptSize () const
 Return the size of the script for this expression (faster than ToScript().size()). More...
 
uint32_t GetOps () const
 Return the maximum number of ops needed to satisfy this script non-malleably. More...
 
bool CheckOpsLimit () const
 Check the ops limit of this script against the consensus limit. More...
 
uint32_t GetStackSize () const
 Return the maximum number of stack elements needed to satisfy this script non-malleably, including the script push. More...
 
bool CheckStackSize () const
 Check the maximum stack size for this script against the policy limit. More...
 
Type GetType () const
 Return the expression type. More...
 
const NodeFindInsaneSub () const
 Find an insane subnode which has no insane children. Nullptr if there is none. More...
 
bool IsValid () const
 Check whether this node is valid at all. More...
 
bool IsValidTopLevel () const
 Check whether this node is valid as a script on its own. More...
 
bool IsNonMalleable () const
 Check whether this script can always be satisfied in a non-malleable way. More...
 
bool NeedsSignature () const
 Check whether this script always needs a signature. More...
 
bool CheckTimeLocksMix () const
 Check whether there is no satisfaction path that contains both timelocks and heightlocks. More...
 
bool CheckDuplicateKey () const
 Check whether there is no duplicate key across this fragment and all its sub-fragments. More...
 
bool ValidSatisfactions () const
 Whether successful non-malleable satisfactions are guaranteed to be valid. More...
 
bool IsSaneSubexpression () const
 Whether the apparent policy of this node matches its script semantics. Doesn't guarantee it is a safe script on its own. More...
 
bool IsSane () const
 Check whether this node is safe as a script on its own. More...
 
bool operator== (const Node< Key > &arg) const
 Equality testing. More...
 
 Node (internal::NoDupCheck, Fragment nt, std::vector< NodeRef< Key >> sub, std::vector< unsigned char > arg, uint32_t val=0)
 
 Node (internal::NoDupCheck, Fragment nt, std::vector< unsigned char > arg, uint32_t val=0)
 
 Node (internal::NoDupCheck, Fragment nt, std::vector< NodeRef< Key >> sub, std::vector< Key > key, uint32_t val=0)
 
 Node (internal::NoDupCheck, Fragment nt, std::vector< Key > key, uint32_t val=0)
 
 Node (internal::NoDupCheck, Fragment nt, std::vector< NodeRef< Key >> sub, uint32_t val=0)
 
 Node (internal::NoDupCheck, Fragment nt, uint32_t val=0)
 
template<typename Ctx >
 Node (const Ctx &ctx, Fragment nt, std::vector< NodeRef< Key >> sub, std::vector< unsigned char > arg, uint32_t val=0)
 
template<typename Ctx >
 Node (const Ctx &ctx, Fragment nt, std::vector< unsigned char > arg, uint32_t val=0)
 
template<typename Ctx >
 Node (const Ctx &ctx, Fragment nt, std::vector< NodeRef< Key >> sub, std::vector< Key > key, uint32_t val=0)
 
template<typename Ctx >
 Node (const Ctx &ctx, Fragment nt, std::vector< Key > key, uint32_t val=0)
 
template<typename Ctx >
 Node (const Ctx &ctx, Fragment nt, std::vector< NodeRef< Key >> sub, uint32_t val=0)
 
template<typename Ctx >
 Node (const Ctx &ctx, Fragment nt, uint32_t val=0)
 

Public Attributes

const Fragment fragment
 What node type this node is. More...
 
const uint32_t k = 0
 The k parameter (time for OLDER/AFTER, threshold for THRESH(_M)) More...
 
const std::vector< Key > keys
 The keys used by this expression (only for PK_K/PK_H/MULTI) More...
 
const std::vector< unsigned char > data
 The data bytes in this expression (only for HASH160/HASH256/SHA256/RIPEMD10). More...
 
const std::vector< NodeRef< Key > > subs
 Subexpressions (for WRAP_*‍/AND_*‍/OR_*‍/ANDOR/THRESH) More...
 

Private Member Functions

size_t CalcScriptLen () const
 Compute the length of the script for this miniscript (including children). More...
 
template<typename Result , typename State , typename DownFn , typename UpFn >
std::optional< Result > TreeEvalMaybe (State root_state, DownFn downfn, UpFn upfn) const
 
template<typename Result , typename UpFn >
std::optional< Result > TreeEvalMaybe (UpFn upfn) const
 Like TreeEvalMaybe, but without downfn or State type. More...
 
template<typename Result , typename State , typename DownFn , typename UpFn >
Result TreeEval (State root_state, DownFn &&downfn, UpFn upfn) const
 Like TreeEvalMaybe, but always produces a result. More...
 
template<typename Result , typename UpFn >
Result TreeEval (UpFn upfn) const
 Like TreeEval, but without downfn or State type. More...
 
Type CalcType () const
 Compute the type for this miniscript. More...
 
internal::Ops CalcOps () const
 
internal::StackSize CalcStackSize () const
 

Private Attributes

const internal::Ops ops
 Cached ops counts. More...
 
const internal::StackSize ss
 Cached stack size bounds. More...
 
const Type typ
 Cached expression type (computed by CalcType and fed through SanitizeType). More...
 
const size_t scriptlen
 Cached script length (computed by CalcScriptLen). More...
 
std::optional< bool > has_duplicate_keys
 Whether a public key appears more than once in this node. More...
 

Friends

int Compare (const Node< Key > &node1, const Node< Key > &node2)
 Compare two miniscript subtrees, using a non-recursive algorithm. More...
 

Detailed Description

template<typename Key>
struct miniscript::Node< Key >

A node in a miniscript expression.

Definition at line 285 of file miniscript.h.

Constructor & Destructor Documentation

◆ Node() [1/12]

template<typename Key >
miniscript::Node< Key >::Node ( internal::NoDupCheck  ,
Fragment  nt,
std::vector< NodeRef< Key >>  sub,
std::vector< unsigned char >  arg,
uint32_t  val = 0 
)
inline

Definition at line 911 of file miniscript.h.

◆ Node() [2/12]

template<typename Key >
miniscript::Node< Key >::Node ( internal::NoDupCheck  ,
Fragment  nt,
std::vector< unsigned char >  arg,
uint32_t  val = 0 
)
inline

Definition at line 912 of file miniscript.h.

◆ Node() [3/12]

template<typename Key >
miniscript::Node< Key >::Node ( internal::NoDupCheck  ,
Fragment  nt,
std::vector< NodeRef< Key >>  sub,
std::vector< Key >  key,
uint32_t  val = 0 
)
inline

Definition at line 913 of file miniscript.h.

◆ Node() [4/12]

template<typename Key >
miniscript::Node< Key >::Node ( internal::NoDupCheck  ,
Fragment  nt,
std::vector< Key >  key,
uint32_t  val = 0 
)
inline

Definition at line 914 of file miniscript.h.

◆ Node() [5/12]

template<typename Key >
miniscript::Node< Key >::Node ( internal::NoDupCheck  ,
Fragment  nt,
std::vector< NodeRef< Key >>  sub,
uint32_t  val = 0 
)
inline

Definition at line 915 of file miniscript.h.

◆ Node() [6/12]

template<typename Key >
miniscript::Node< Key >::Node ( internal::NoDupCheck  ,
Fragment  nt,
uint32_t  val = 0 
)
inline

Definition at line 916 of file miniscript.h.

◆ Node() [7/12]

template<typename Key >
template<typename Ctx >
miniscript::Node< Key >::Node ( const Ctx &  ctx,
Fragment  nt,
std::vector< NodeRef< Key >>  sub,
std::vector< unsigned char >  arg,
uint32_t  val = 0 
)
inline

Definition at line 919 of file miniscript.h.

Here is the call graph for this function:

◆ Node() [8/12]

template<typename Key >
template<typename Ctx >
miniscript::Node< Key >::Node ( const Ctx &  ctx,
Fragment  nt,
std::vector< unsigned char >  arg,
uint32_t  val = 0 
)
inline

Definition at line 920 of file miniscript.h.

Here is the call graph for this function:

◆ Node() [9/12]

template<typename Key >
template<typename Ctx >
miniscript::Node< Key >::Node ( const Ctx &  ctx,
Fragment  nt,
std::vector< NodeRef< Key >>  sub,
std::vector< Key >  key,
uint32_t  val = 0 
)
inline

Definition at line 921 of file miniscript.h.

Here is the call graph for this function:

◆ Node() [10/12]

template<typename Key >
template<typename Ctx >
miniscript::Node< Key >::Node ( const Ctx &  ctx,
Fragment  nt,
std::vector< Key >  key,
uint32_t  val = 0 
)
inline

Definition at line 922 of file miniscript.h.

Here is the call graph for this function:

◆ Node() [11/12]

template<typename Key >
template<typename Ctx >
miniscript::Node< Key >::Node ( const Ctx &  ctx,
Fragment  nt,
std::vector< NodeRef< Key >>  sub,
uint32_t  val = 0 
)
inline

Definition at line 923 of file miniscript.h.

Here is the call graph for this function:

◆ Node() [12/12]

template<typename Key >
template<typename Ctx >
miniscript::Node< Key >::Node ( const Ctx &  ctx,
Fragment  nt,
uint32_t  val = 0 
)
inline

Definition at line 924 of file miniscript.h.

Here is the call graph for this function:

Member Function Documentation

◆ CalcOps()

template<typename Key >
internal::Ops miniscript::Node< Key >::CalcOps ( ) const
inlineprivate

Definition at line 665 of file miniscript.h.

Here is the call graph for this function:

◆ CalcScriptLen()

template<typename Key >
size_t miniscript::Node< Key >::CalcScriptLen ( ) const
inlineprivate

Compute the length of the script for this miniscript (including children).

Definition at line 315 of file miniscript.h.

Here is the call graph for this function:

◆ CalcStackSize()

template<typename Key >
internal::StackSize miniscript::Node< Key >::CalcStackSize ( ) const
inlineprivate

Definition at line 738 of file miniscript.h.

Here is the call graph for this function:

◆ CalcType()

template<typename Key >
Type miniscript::Node< Key >::CalcType ( ) const
inlineprivate

Compute the type for this miniscript.

Definition at line 475 of file miniscript.h.

Here is the call graph for this function:

◆ CheckDuplicateKey()

template<typename Key >
bool miniscript::Node< Key >::CheckDuplicateKey ( ) const
inline

Check whether there is no duplicate key across this fragment and all its sub-fragments.

Definition at line 896 of file miniscript.h.

Here is the caller graph for this function:

◆ CheckOpsLimit()

template<typename Key >
bool miniscript::Node< Key >::CheckOpsLimit ( ) const
inline

Check the ops limit of this script against the consensus limit.

Definition at line 859 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckStackSize()

template<typename Key >
bool miniscript::Node< Key >::CheckStackSize ( ) const
inline

Check the maximum stack size for this script against the policy limit.

Definition at line 866 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckTimeLocksMix()

template<typename Key >
bool miniscript::Node< Key >::CheckTimeLocksMix ( ) const
inline

Check whether there is no satisfaction path that contains both timelocks and heightlocks.

Definition at line 893 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DuplicateKeyCheck()

template<typename Key >
template<typename Ctx >
void miniscript::Node< Key >::DuplicateKeyCheck ( const Ctx &  ctx) const
inline

Update duplicate key information in this Node.

This uses a custom key comparator provided by the context in order to still detect duplicates for more complicated types.

Definition at line 794 of file miniscript.h.

Here is the caller graph for this function:

◆ FindInsaneSub()

template<typename Key >
const Node* miniscript::Node< Key >::FindInsaneSub ( ) const
inline

Find an insane subnode which has no insane children. Nullptr if there is none.

Definition at line 872 of file miniscript.h.

◆ GetOps()

template<typename Key >
uint32_t miniscript::Node< Key >::GetOps ( ) const
inline

Return the maximum number of ops needed to satisfy this script non-malleably.

Definition at line 856 of file miniscript.h.

Here is the caller graph for this function:

◆ GetStackSize()

template<typename Key >
uint32_t miniscript::Node< Key >::GetStackSize ( ) const
inline

Return the maximum number of stack elements needed to satisfy this script non-malleably, including the script push.

Definition at line 863 of file miniscript.h.

Here is the caller graph for this function:

◆ GetType()

template<typename Key >
Type miniscript::Node< Key >::GetType ( ) const
inline

Return the expression type.

Definition at line 869 of file miniscript.h.

Here is the caller graph for this function:

◆ IsNonMalleable()

template<typename Key >
bool miniscript::Node< Key >::IsNonMalleable ( ) const
inline

Check whether this script can always be satisfied in a non-malleable way.

Definition at line 887 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSane()

template<typename Key >
bool miniscript::Node< Key >::IsSane ( ) const
inline

Check whether this node is safe as a script on its own.

Definition at line 905 of file miniscript.h.

Here is the call graph for this function:

◆ IsSaneSubexpression()

template<typename Key >
bool miniscript::Node< Key >::IsSaneSubexpression ( ) const
inline

Whether the apparent policy of this node matches its script semantics. Doesn't guarantee it is a safe script on its own.

Definition at line 902 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsValid()

template<typename Key >
bool miniscript::Node< Key >::IsValid ( ) const
inline

Check whether this node is valid at all.

Definition at line 881 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsValidTopLevel()

template<typename Key >
bool miniscript::Node< Key >::IsValidTopLevel ( ) const
inline

Check whether this node is valid as a script on its own.

Definition at line 884 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NeedsSignature()

template<typename Key >
bool miniscript::Node< Key >::NeedsSignature ( ) const
inline

Check whether this script always needs a signature.

Definition at line 890 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==()

template<typename Key >
bool miniscript::Node< Key >::operator== ( const Node< Key > &  arg) const
inline

Equality testing.

Definition at line 908 of file miniscript.h.

◆ ScriptSize()

template<typename Key >
size_t miniscript::Node< Key >::ScriptSize ( ) const
inline

Return the size of the script for this expression (faster than ToScript().size()).

Definition at line 853 of file miniscript.h.

Here is the caller graph for this function:

◆ ToScript()

template<typename Key >
template<typename Ctx >
CScript miniscript::Node< Key >::ToScript ( const Ctx &  ctx) const
inline

Definition at line 493 of file miniscript.h.

Here is the call graph for this function:

◆ ToString()

template<typename Key >
template<typename CTx >
std::optional<std::string> miniscript::Node< Key >::ToString ( const CTx &  ctx) const
inline

Definition at line 562 of file miniscript.h.

Here is the call graph for this function:

◆ TreeEval() [1/2]

template<typename Key >
template<typename Result , typename State , typename DownFn , typename UpFn >
Result miniscript::Node< Key >::TreeEval ( State  root_state,
DownFn &&  downfn,
UpFn  upfn 
) const
inlineprivate

Like TreeEvalMaybe, but always produces a result.

upfn must return Result.

Definition at line 426 of file miniscript.h.

◆ TreeEval() [2/2]

template<typename Key >
template<typename Result , typename UpFn >
Result miniscript::Node< Key >::TreeEval ( UpFn  upfn) const
inlineprivate

Like TreeEval, but without downfn or State type.

upfn takes (const Node&, Span<Result>) and returns Result.

Definition at line 442 of file miniscript.h.

◆ TreeEvalMaybe() [1/2]

template<typename Key >
template<typename Result , typename State , typename DownFn , typename UpFn >
std::optional<Result> miniscript::Node< Key >::TreeEvalMaybe ( State  root_state,
DownFn  downfn,
UpFn  upfn 
) const
inlineprivate

Entries of the explicit stack tracked in this algorithm.

< The node being evaluated.

< How many children of this node have been expanded.

< The state for that node.

Definition at line 348 of file miniscript.h.

Here is the call graph for this function:

◆ TreeEvalMaybe() [2/2]

template<typename Key >
template<typename Result , typename UpFn >
std::optional<Result> miniscript::Node< Key >::TreeEvalMaybe ( UpFn  upfn) const
inlineprivate

Like TreeEvalMaybe, but without downfn or State type.

upfn takes (const Node&, Span<Result>) and returns std::optional<Result>.

Definition at line 413 of file miniscript.h.

◆ ValidSatisfactions()

template<typename Key >
bool miniscript::Node< Key >::ValidSatisfactions ( ) const
inline

Whether successful non-malleable satisfactions are guaranteed to be valid.

Definition at line 899 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Compare

template<typename Key >
int Compare ( const Node< Key > &  node1,
const Node< Key > &  node2 
)
friend

Compare two miniscript subtrees, using a non-recursive algorithm.

Definition at line 455 of file miniscript.h.

Member Data Documentation

◆ data

template<typename Key >
const std::vector<unsigned char> miniscript::Node< Key >::data

The data bytes in this expression (only for HASH160/HASH256/SHA256/RIPEMD10).

Definition at line 293 of file miniscript.h.

◆ fragment

template<typename Key >
const Fragment miniscript::Node< Key >::fragment

What node type this node is.

Definition at line 287 of file miniscript.h.

◆ has_duplicate_keys

template<typename Key >
std::optional<bool> miniscript::Node< Key >::has_duplicate_keys
mutableprivate

Whether a public key appears more than once in this node.

This value is initialized by all constructors except the NoDupCheck ones. The NoDupCheck ones skip the computation, requiring it to be done manually by invoking DuplicateKeyCheck(). DuplicateKeyCheck(), or a non-NoDupCheck constructor, will compute has_duplicate_keys for all subnodes as well.

Definition at line 311 of file miniscript.h.

◆ k

template<typename Key >
const uint32_t miniscript::Node< Key >::k = 0

The k parameter (time for OLDER/AFTER, threshold for THRESH(_M))

Definition at line 289 of file miniscript.h.

◆ keys

template<typename Key >
const std::vector<Key> miniscript::Node< Key >::keys

The keys used by this expression (only for PK_K/PK_H/MULTI)

Definition at line 291 of file miniscript.h.

◆ ops

template<typename Key >
const internal::Ops miniscript::Node< Key >::ops
private

Cached ops counts.

Definition at line 299 of file miniscript.h.

◆ scriptlen

template<typename Key >
const size_t miniscript::Node< Key >::scriptlen
private

Cached script length (computed by CalcScriptLen).

Definition at line 305 of file miniscript.h.

◆ ss

template<typename Key >
const internal::StackSize miniscript::Node< Key >::ss
private

Cached stack size bounds.

Definition at line 301 of file miniscript.h.

◆ subs

template<typename Key >
const std::vector<NodeRef<Key> > miniscript::Node< Key >::subs

Subexpressions (for WRAP_*‍/AND_*‍/OR_*‍/ANDOR/THRESH)

Definition at line 295 of file miniscript.h.

◆ typ

template<typename Key >
const Type miniscript::Node< Key >::typ
private

Cached expression type (computed by CalcType and fed through SanitizeType).

Definition at line 303 of file miniscript.h.


The documentation for this struct was generated from the following file: