Bitcoin Core 28.99.0
P2P Digital Currency
|
A node in a miniscript expression. More...
#include <miniscript.h>
Public Member Functions | |
~Node () | |
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... | |
std::optional< uint32_t > | GetOps () const |
Return the maximum number of ops needed to satisfy this script non-malleably. More... | |
uint32_t | GetStaticOps () const |
Return the number of ops in the script (not counting the dynamic ones that depend on execution). More... | |
bool | CheckOpsLimit () const |
Check the ops limit of this script against the consensus limit. More... | |
bool | IsBKW () const |
Whether this node is of type B, K or W. More... | |
std::optional< uint32_t > | GetStackSize () const |
Return the maximum number of stack elements needed to satisfy this script non-malleably. More... | |
std::optional< uint32_t > | GetExecStackSize () const |
Return the maximum size of the stack during execution of this script. More... | |
bool | CheckStackSize () const |
Check the maximum stack size for this script against the policy limit. More... | |
bool | IsNotSatisfiable () const |
Whether no satisfaction exists for this node. More... | |
std::optional< uint32_t > | GetWitnessSize () const |
Return the maximum size in bytes of a witness to satisfy this script non-malleably. More... | |
Type | GetType () const |
Return the expression type. More... | |
MiniscriptContext | GetMsCtx () const |
Return the script context for this node. More... | |
const Node * | FindInsaneSub () const |
Find an insane subnode which has no insane children. Nullptr if there is none. More... | |
template<typename F > | |
bool | IsSatisfiable (F fn) const |
Determine whether a Miniscript node is satisfiable. 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... | |
template<typename Ctx > | |
Availability | Satisfy (const Ctx &ctx, std::vector< std::vector< unsigned char > > &stack, bool nonmalleable=true) const |
Produce a witness for this script, if possible and given the information available in the context. More... | |
bool | operator== (const Node< Key > &arg) const |
Equality testing. More... | |
Node (internal::NoDupCheck, MiniscriptContext script_ctx, Fragment nt, std::vector< NodeRef< Key > > sub, std::vector< unsigned char > arg, uint32_t val=0) | |
Node (internal::NoDupCheck, MiniscriptContext script_ctx, Fragment nt, std::vector< unsigned char > arg, uint32_t val=0) | |
Node (internal::NoDupCheck, MiniscriptContext script_ctx, Fragment nt, std::vector< NodeRef< Key > > sub, std::vector< Key > key, uint32_t val=0) | |
Node (internal::NoDupCheck, MiniscriptContext script_ctx, Fragment nt, std::vector< Key > key, uint32_t val=0) | |
Node (internal::NoDupCheck, MiniscriptContext script_ctx, Fragment nt, std::vector< NodeRef< Key > > sub, uint32_t val=0) | |
Node (internal::NoDupCheck, MiniscriptContext script_ctx, 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... | |
std::vector< NodeRef< Key > > | subs |
Subexpressions (for WRAP_*/AND_*/OR_*/ANDOR/THRESH) More... | |
const MiniscriptContext | m_script_ctx |
The Script context for this node. Either P2WSH or Tapscript. 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 |
internal::WitnessSize | CalcWitnessSize () const |
template<typename Ctx > | |
internal::InputResult | ProduceInput (const Ctx &ctx) const |
Private Attributes | |
const internal::Ops | ops |
Cached ops counts. More... | |
const internal::StackSize | ss |
Cached stack size bounds. More... | |
const internal::WitnessSize | ws |
Cached witness 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... | |
A node in a miniscript expression.
Definition at line 504 of file miniscript.h.
|
inline |
Definition at line 520 of file miniscript.h.
|
inline |
Definition at line 1640 of file miniscript.h.
|
inline |
Definition at line 1642 of file miniscript.h.
|
inline |
Definition at line 1644 of file miniscript.h.
|
inline |
Definition at line 1646 of file miniscript.h.
|
inline |
Definition at line 1648 of file miniscript.h.
|
inline |
Definition at line 1650 of file miniscript.h.
|
inline |
Definition at line 1654 of file miniscript.h.
|
inline |
Definition at line 1656 of file miniscript.h.
|
inline |
Definition at line 1658 of file miniscript.h.
|
inline |
Definition at line 1660 of file miniscript.h.
|
inline |
Definition at line 1662 of file miniscript.h.
|
inline |
Definition at line 1664 of file miniscript.h.
|
inlineprivate |
|
inlineprivate |
Compute the length of the script for this miniscript (including children).
Definition at line 551 of file miniscript.h.
|
inlineprivate |
|
inlineprivate |
Compute the type for this miniscript.
Definition at line 712 of file miniscript.h.
|
inlineprivate |
|
inline |
Check whether there is no duplicate key across this fragment and all its sub-fragments.
Definition at line 1613 of file miniscript.h.
|
inline |
Check the ops limit of this script against the consensus limit.
Definition at line 1492 of file miniscript.h.
|
inline |
Check the maximum stack size for this script against the policy limit.
Definition at line 1516 of file miniscript.h.
|
inline |
Check whether there is no satisfaction path that contains both timelocks and heightlocks.
Definition at line 1610 of file miniscript.h.
|
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 1421 of file miniscript.h.
|
inline |
Find an insane subnode which has no insane children. Nullptr if there is none.
Definition at line 1544 of file miniscript.h.
|
inline |
Return the maximum size of the stack during execution of this script.
Definition at line 1510 of file miniscript.h.
|
inline |
Return the script context for this node.
Definition at line 1541 of file miniscript.h.
|
inline |
Return the maximum number of ops needed to satisfy this script non-malleably.
Definition at line 1483 of file miniscript.h.
|
inline |
Return the maximum number of stack elements needed to satisfy this script non-malleably.
Definition at line 1504 of file miniscript.h.
|
inline |
Return the number of ops in the script (not counting the dynamic ones that depend on execution).
Definition at line 1489 of file miniscript.h.
|
inline |
Return the expression type.
Definition at line 1538 of file miniscript.h.
|
inline |
Return the maximum size in bytes of a witness to satisfy this script non-malleably.
Note this does not include the witness script push.
Definition at line 1532 of file miniscript.h.
|
inline |
Whether this node is of type B, K or W.
(That is, anything but V.)
Definition at line 1499 of file miniscript.h.
|
inline |
Check whether this script can always be satisfied in a non-malleable way.
Definition at line 1604 of file miniscript.h.
|
inline |
Whether no satisfaction exists for this node.
Definition at line 1528 of file miniscript.h.
|
inline |
Check whether this node is safe as a script on its own.
Definition at line 1622 of file miniscript.h.
|
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 1619 of file miniscript.h.
|
inline |
Determine whether a Miniscript node is satisfiable.
fn(node) will be invoked for all key, time, and hashing nodes, and should return their satisfiability.
Definition at line 1555 of file miniscript.h.
|
inline |
Check whether this node is valid at all.
Definition at line 1595 of file miniscript.h.
|
inline |
Check whether this node is valid as a script on its own.
Definition at line 1601 of file miniscript.h.
|
inline |
Check whether this script always needs a signature.
Definition at line 1607 of file miniscript.h.
|
inline |
Equality testing.
Definition at line 1637 of file miniscript.h.
|
inlineprivate |
|
inline |
Produce a witness for this script, if possible and given the information available in the context.
The non-malleable satisfaction is guaranteed to be valid if it exists, and ValidSatisfaction() is true. If IsSane() holds, this satisfaction is guaranteed to succeed in case the node's conditions are satisfied (private keys and hash preimages available, locktimes satisfied).
Definition at line 1629 of file miniscript.h.
|
inline |
Return the size of the script for this expression (faster than ToScript().size()).
Definition at line 1480 of file miniscript.h.
|
inline |
|
inline |
|
inlineprivate |
Like TreeEvalMaybe, but always produces a result.
upfn must return Result.
Definition at line 663 of file miniscript.h.
|
inlineprivate |
Like TreeEval, but without downfn or State type.
upfn takes (const Node&, Span<Result>) and returns Result.
Definition at line 679 of file miniscript.h.
|
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 585 of file miniscript.h.
|
inlineprivate |
Like TreeEvalMaybe, but without downfn or State type.
upfn takes (const Node&, Span<Result>) and returns std::optional<Result>.
Definition at line 650 of file miniscript.h.
|
inline |
Whether successful non-malleable satisfactions are guaranteed to be valid.
Definition at line 1616 of file miniscript.h.
Compare two miniscript subtrees, using a non-recursive algorithm.
Definition at line 692 of file miniscript.h.
const std::vector<unsigned char> miniscript::Node< Key >::data |
The data bytes in this expression (only for HASH160/HASH256/SHA256/RIPEMD10).
Definition at line 512 of file miniscript.h.
const Fragment miniscript::Node< Key >::fragment |
What node type this node is.
Definition at line 506 of file miniscript.h.
|
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 547 of file miniscript.h.
const uint32_t miniscript::Node< Key >::k = 0 |
The k parameter (time for OLDER/AFTER, threshold for THRESH(_M))
Definition at line 508 of file miniscript.h.
const std::vector<Key> miniscript::Node< Key >::keys |
The keys used by this expression (only for PK_K/PK_H/MULTI)
Definition at line 510 of file miniscript.h.
const MiniscriptContext miniscript::Node< Key >::m_script_ctx |
The Script context for this node. Either P2WSH or Tapscript.
Definition at line 516 of file miniscript.h.
|
private |
Cached ops counts.
Definition at line 533 of file miniscript.h.
|
private |
Cached script length (computed by CalcScriptLen).
Definition at line 541 of file miniscript.h.
|
private |
Cached stack size bounds.
Definition at line 535 of file miniscript.h.
|
mutable |
Subexpressions (for WRAP_*/AND_*/OR_*/ANDOR/THRESH)
Definition at line 514 of file miniscript.h.
|
private |
Cached expression type (computed by CalcType and fed through SanitizeType).
Definition at line 539 of file miniscript.h.
|
private |
Cached witness size bounds.
Definition at line 537 of file miniscript.h.