Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
miniscript.h File Reference
#include <algorithm>
#include <compare>
#include <cstdint>
#include <cstdlib>
#include <iterator>
#include <memory>
#include <optional>
#include <set>
#include <stdexcept>
#include <tuple>
#include <utility>
#include <vector>
#include <consensus/consensus.h>
#include <policy/policy.h>
#include <script/interpreter.h>
#include <script/parsing.h>
#include <script/script.h>
#include <serialize.h>
#include <span.h>
#include <util/check.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/vector.h>
Include dependency graph for miniscript.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  miniscript::Type
 This type encapsulates the miniscript type system properties. More...
 
struct  miniscript::internal::InputStack
 An object representing a sequence of witness stack elements. More...
 
struct  miniscript::internal::InputResult
 A pair of a satisfaction and a dissatisfaction InputStack. More...
 
struct  miniscript::internal::MaxInt< I >
 Class whose objects represent the maximum of a list of integers. More...
 
struct  miniscript::internal::Ops
 
struct  miniscript::internal::SatInfo
 A data structure to help the calculation of stack size limits. More...
 
struct  miniscript::internal::StackSize
 
struct  miniscript::internal::WitnessSize
 
struct  miniscript::internal::NoDupCheck
 
struct  miniscript::Node< Key >
 A node in a miniscript expression. More...
 

Namespaces

namespace  miniscript
 
namespace  miniscript::internal
 

Typedefs

using miniscript::Opcode = std::pair< opcodetype, std::vector< unsigned char > >
 
template<typename Key >
using miniscript::NodeRef = std::shared_ptr< const Node< Key > >
 

Enumerations

enum class  miniscript::Fragment {
  miniscript::JUST_0 , miniscript::JUST_1 , miniscript::PK_K , miniscript::PK_H ,
  miniscript::OLDER , miniscript::AFTER , miniscript::SHA256 , miniscript::HASH256 ,
  miniscript::RIPEMD160 , miniscript::HASH160 , miniscript::WRAP_A , miniscript::WRAP_S ,
  miniscript::WRAP_C , miniscript::WRAP_D , miniscript::WRAP_V , miniscript::WRAP_J ,
  miniscript::WRAP_N , miniscript::AND_V , miniscript::AND_B , miniscript::OR_B ,
  miniscript::OR_C , miniscript::OR_D , miniscript::OR_I , miniscript::ANDOR ,
  miniscript::THRESH , miniscript::MULTI , miniscript::MULTI_A
}
 The different node types in miniscript. More...
 
enum class  miniscript::Availability { miniscript::NO , miniscript::YES , miniscript::MAYBE }
 
enum class  miniscript::MiniscriptContext { miniscript::P2WSH , miniscript::TAPSCRIPT }
 
enum class  miniscript::internal::ParseContext {
  miniscript::internal::WRAPPED_EXPR , miniscript::internal::EXPR , miniscript::internal::SWAP , miniscript::internal::ALT ,
  miniscript::internal::CHECK , miniscript::internal::DUP_IF , miniscript::internal::VERIFY , miniscript::internal::NON_ZERO ,
  miniscript::internal::ZERO_NOTEQUAL , miniscript::internal::WRAP_U , miniscript::internal::WRAP_T , miniscript::internal::AND_N ,
  miniscript::internal::AND_V , miniscript::internal::AND_B , miniscript::internal::ANDOR , miniscript::internal::OR_B ,
  miniscript::internal::OR_C , miniscript::internal::OR_D , miniscript::internal::OR_I , miniscript::internal::THRESH ,
  miniscript::internal::COMMA , miniscript::internal::CLOSE_BRACKET
}
 
enum class  miniscript::internal::DecodeContext {
  miniscript::internal::SINGLE_BKV_EXPR , miniscript::internal::BKV_EXPR , miniscript::internal::W_EXPR , miniscript::internal::SWAP ,
  miniscript::internal::ALT , miniscript::internal::CHECK , miniscript::internal::DUP_IF , miniscript::internal::VERIFY ,
  miniscript::internal::NON_ZERO , miniscript::internal::ZERO_NOTEQUAL , miniscript::internal::MAYBE_AND_V , miniscript::internal::AND_V ,
  miniscript::internal::AND_B , miniscript::internal::ANDOR , miniscript::internal::OR_B , miniscript::internal::OR_C ,
  miniscript::internal::OR_D , miniscript::internal::THRESH_W , miniscript::internal::THRESH_E , miniscript::internal::ENDIF ,
  miniscript::internal::ENDIF_NOTIF , miniscript::internal::ENDIF_ELSE
}
 

Functions

consteval Type miniscript::operator""_mst (const char *c, size_t l)
 Literal operator to construct Type objects. More...
 
template<typename Key , typename... Args>
NodeRef< Key > miniscript::MakeNodeRef (Args &&... args)
 Construct a miniscript node as a shared_ptr. More...
 
constexpr bool miniscript::IsTapscript (MiniscriptContext ms_ctx)
 Whether the context Tapscript, ensuring the only other possibility is P2WSH. More...
 
constexpr uint32_t miniscript::internal::MaxScriptSize (MiniscriptContext ms_ctx)
 The maximum size of a script depending on the context. More...
 
Type miniscript::internal::ComputeType (Fragment fragment, Type x, Type y, Type z, const std::vector< Type > &sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys, MiniscriptContext ms_ctx)
 Helper function for Node::CalcType. More...
 
size_t miniscript::internal::ComputeScriptLen (Fragment fragment, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys, MiniscriptContext ms_ctx)
 Helper function for Node::CalcScriptLen. More...
 
Type miniscript::internal::SanitizeType (Type x)
 A helper sanitizer/checker for the output of CalcType. More...
 
int miniscript::internal::FindNextChar (Span< const char > sp, const char m)
 
template<typename Key , typename Ctx >
std::optional< std::pair< Key, int > > miniscript::internal::ParseKeyEnd (Span< const char > in, const Ctx &ctx)
 Parse a key string ending at the end of the fragment's text representation. More...
 
template<typename Ctx >
std::optional< std::pair< std::vector< unsigned char >, int > > miniscript::internal::ParseHexStrEnd (Span< const char > in, const size_t expected_size, const Ctx &ctx)
 Parse a hex string ending at the end of the fragment's text representation. More...
 
template<typename Key >
void miniscript::internal::BuildBack (const MiniscriptContext script_ctx, Fragment nt, std::vector< NodeRef< Key > > &constructed, const bool reverse=false)
 BuildBack pops the last two elements off constructed and wraps them in the specified Fragment. More...
 
template<typename Key , typename Ctx >
NodeRef< Key > miniscript::internal::Parse (Span< const char > in, const Ctx &ctx)
 Parse a miniscript from its textual descriptor form. More...
 
std::optional< std::vector< Opcode > > miniscript::internal::DecomposeScript (const CScript &script)
 Decode a script into opcode/push pairs. More...
 
std::optional< int64_t > miniscript::internal::ParseScriptNumber (const Opcode &in)
 Determine whether the passed pair (created by DecomposeScript) is pushing a number. More...
 
template<typename Key , typename Ctx , typename I >
NodeRef< Key > miniscript::internal::DecodeScript (I &in, I last, const Ctx &ctx)
 Parse a miniscript from a bitcoin script. More...
 
template<typename Ctx >
NodeRef< typename Ctx::Key > miniscript::FromString (const std::string &str, const Ctx &ctx)
 
template<typename Ctx >
NodeRef< typename Ctx::Key > miniscript::FromScript (const CScript &script, const Ctx &ctx)
 

Variables

static constexpr uint32_t miniscript::internal::MAX_TAPMINISCRIPT_STACK_ELEM_SIZE {65}
 The maximum size of a witness item for a Miniscript under Tapscript context. (A BIP340 signature with a sighash type byte.) More...
 
constexpr uint32_t miniscript::internal::TX_OVERHEAD {4 + 4}
 version + nLockTime More...
 
constexpr uint32_t miniscript::internal::TXIN_BYTES_NO_WITNESS {36 + 4 + 1}
 prevout + nSequence + scriptSig More...
 
constexpr uint32_t miniscript::internal::P2WSH_TXOUT_BYTES {8 + 1 + 1 + 33}
 nValue + script len + OP_0 + pushdata 32. More...
 
constexpr uint32_t miniscript::internal::TX_BODY_LEEWAY_WEIGHT {(TX_OVERHEAD + GetSizeOfCompactSize(1) + TXIN_BYTES_NO_WITNESS + GetSizeOfCompactSize(1) + P2WSH_TXOUT_BYTES) * WITNESS_SCALE_FACTOR + 2}
 Data other than the witness in a transaction. Overhead + vin count + one vin + vout count + one vout + segwit marker. More...
 
constexpr uint32_t miniscript::internal::MAX_TAPSCRIPT_SAT_SIZE {GetSizeOfCompactSize(MAX_STACK_SIZE) + (GetSizeOfCompactSize(MAX_TAPMINISCRIPT_STACK_ELEM_SIZE) + MAX_TAPMINISCRIPT_STACK_ELEM_SIZE) * MAX_STACK_SIZE + GetSizeOfCompactSize(TAPROOT_CONTROL_MAX_SIZE) + TAPROOT_CONTROL_MAX_SIZE}
 Maximum possible stack size to spend a Taproot output (excluding the script itself). More...
 
static const auto miniscript::internal::ZERO = InputStack(std::vector<unsigned char>())
 A stack consisting of a single zero-length element (interpreted as 0 by the script interpreter in numeric context). More...
 
static const auto miniscript::internal::ZERO32 = InputStack(std::vector<unsigned char>(32, 0)).SetMalleable()
 A stack consisting of a single malleable 32-byte 0x0000...0000 element (for dissatisfying hash challenges). More...
 
static const auto miniscript::internal::ONE = InputStack(Vector((unsigned char)1))
 A stack consisting of a single 0x01 element (interpreted as 1 by the script interpreted in numeric context). More...
 
static const auto miniscript::internal::EMPTY = InputStack()
 The empty stack. More...
 
static const auto miniscript::internal::INVALID = InputStack().SetAvailable(Availability::NO)
 A stack representing the lack of any (dis)satisfactions. More...