20 int num_types = (e <<
"K"_mst) + (e <<
"V"_mst) + (e <<
"B"_mst) + (e <<
"W"_mst);
21 if (num_types == 0)
return ""_mst;
23 assert(!(e <<
"z"_mst) || !(e <<
"o"_mst));
24 assert(!(e <<
"n"_mst) || !(e <<
"z"_mst));
25 assert(!(e <<
"n"_mst) || !(e <<
"W"_mst));
26 assert(!(e <<
"V"_mst) || !(e <<
"d"_mst));
27 assert(!(e <<
"K"_mst) || (e <<
"u"_mst));
28 assert(!(e <<
"V"_mst) || !(e <<
"u"_mst));
29 assert(!(e <<
"e"_mst) || !(e <<
"f"_mst));
30 assert(!(e <<
"e"_mst) || (e <<
"d"_mst));
31 assert(!(e <<
"V"_mst) || !(e <<
"e"_mst));
32 assert(!(e <<
"d"_mst) || !(e <<
"f"_mst));
33 assert(!(e <<
"V"_mst) || (e <<
"f"_mst));
34 assert(!(e <<
"K"_mst) || (e <<
"s"_mst));
35 assert(!(e <<
"z"_mst) || (e <<
"m"_mst));
106 "W"_mst.If(x <<
"B"_mst) |
111 "W"_mst.If(x <<
"Bo"_mst) |
115 "B"_mst.If(x <<
"K"_mst) |
120 "B"_mst.If(x <<
"Vz"_mst) |
121 "o"_mst.If(x <<
"z"_mst) |
122 "e"_mst.If(x <<
"f"_mst) |
129 "V"_mst.If(x <<
"B"_mst) |
134 "B"_mst.If(x <<
"Bn"_mst) |
135 "e"_mst.If(x <<
"f"_mst) |
141 (x &
"Bzondfems"_mst) |
144 (y &
"KVB"_mst).If(x <<
"V"_mst) |
145 (x &
"n"_mst) | (y &
"n"_mst).If(x <<
"z"_mst) |
146 ((x | y) &
"o"_mst).If((x | y) <<
"z"_mst) |
147 (x & y &
"dmz"_mst) |
148 ((x | y) &
"s"_mst) |
149 "f"_mst.If((y <<
"f"_mst) || (x <<
"s"_mst)) |
151 ((x | y) &
"ghij"_mst) |
152 "k"_mst.If(((x & y) <<
"k"_mst) &&
153 !(((x <<
"g"_mst) && (y <<
"h"_mst)) ||
154 ((x <<
"h"_mst) && (y <<
"g"_mst)) ||
155 ((x <<
"i"_mst) && (y <<
"j"_mst)) ||
156 ((x <<
"j"_mst) && (y <<
"i"_mst))));
158 (x &
"B"_mst).If(y <<
"W"_mst) |
159 ((x | y) &
"o"_mst).If((x | y) <<
"z"_mst) |
160 (x &
"n"_mst) | (y &
"n"_mst).If(x <<
"z"_mst) |
161 (x & y &
"e"_mst).If((x & y) <<
"s"_mst) |
162 (x & y &
"dzm"_mst) |
163 "f"_mst.If(((x & y) <<
"f"_mst) || (x <<
"sf"_mst) || (y <<
"sf"_mst)) |
164 ((x | y) &
"s"_mst) |
166 ((x | y) &
"ghij"_mst) |
167 "k"_mst.If(((x & y) <<
"k"_mst) &&
168 !(((x <<
"g"_mst) && (y <<
"h"_mst)) ||
169 ((x <<
"h"_mst) && (y <<
"g"_mst)) ||
170 ((x <<
"i"_mst) && (y <<
"j"_mst)) ||
171 ((x <<
"j"_mst) && (y <<
"i"_mst))));
173 "B"_mst.If(x <<
"Bd"_mst && y <<
"Wd"_mst) |
174 ((x | y) &
"o"_mst).If((x | y) <<
"z"_mst) |
175 (x & y &
"m"_mst).If((x | y) <<
"s"_mst && (x & y) <<
"e"_mst) |
176 (x & y &
"zse"_mst) |
178 ((x | y) &
"ghij"_mst) |
181 (y &
"B"_mst).If(x <<
"Bdu"_mst) |
182 (x &
"o"_mst).If(y <<
"z"_mst) |
183 (x & y &
"m"_mst).If(x <<
"e"_mst && (x | y) <<
"s"_mst) |
187 ((x | y) &
"ghij"_mst) |
190 (y &
"V"_mst).If(x <<
"Bdu"_mst) |
191 (x &
"o"_mst).If(y <<
"z"_mst) |
192 (x & y &
"m"_mst).If(x <<
"e"_mst && (x | y) <<
"s"_mst) |
195 ((x | y) &
"ghij"_mst) |
198 (x & y &
"VBKufs"_mst) |
199 "o"_mst.If((x & y) <<
"z"_mst) |
200 ((x | y) &
"e"_mst).If((x | y) <<
"f"_mst) |
201 (x & y &
"m"_mst).If((x | y) <<
"s"_mst) |
202 ((x | y) &
"d"_mst) |
204 ((x | y) &
"ghij"_mst) |
207 (y & z &
"BKV"_mst).If(x <<
"Bdu"_mst) |
208 (x & y & z &
"z"_mst) |
209 ((x | (y & z)) &
"o"_mst).If((x | (y & z)) <<
"z"_mst) |
211 (z &
"f"_mst).If((x <<
"s"_mst) || (y <<
"f"_mst)) |
213 (z &
"e"_mst).If(x <<
"s"_mst || y <<
"f"_mst) |
214 (x & y & z &
"m"_mst).If(x <<
"e"_mst && (x | y | z) <<
"s"_mst) |
215 (z & (x | y) &
"s"_mst) |
217 ((x | y | z) &
"ghij"_mst) |
218 "k"_mst.If(((x & y & z) <<
"k"_mst) &&
219 !(((x <<
"g"_mst) && (y <<
"h"_mst)) ||
220 ((x <<
"h"_mst) && (y <<
"g"_mst)) ||
221 ((x <<
"i"_mst) && (y <<
"j"_mst)) ||
222 ((x <<
"j"_mst) && (y <<
"i"_mst))));
224 return "Bnudemsk"_mst;
227 return "Budemsk"_mst;
234 Type acc_tl =
"k"_mst;
235 for (
size_t i = 0; i < sub_types.size(); ++i) {
236 Type t = sub_types[i];
237 static constexpr auto WDU{
"Wdu"_mst}, BDU{
"Bdu"_mst};
238 if (!(
t << (i ? WDU : BDU)))
return ""_mst;
239 if (!(
t <<
"e"_mst)) all_e =
false;
240 if (!(
t <<
"m"_mst)) all_m =
false;
241 if (
t <<
"s"_mst) num_s += 1;
242 args += (
t <<
"z"_mst) ? 0 : (
t <<
"o"_mst) ? 1 : 2;
243 acc_tl = ((acc_tl |
t) &
"ghij"_mst) |
247 "k"_mst.
If(((acc_tl &
t) <<
"k"_mst) && ((
k <= 1) ||
248 ((
k > 1) && !(((acc_tl <<
"g"_mst) && (
t <<
"h"_mst)) ||
249 ((acc_tl <<
"h"_mst) && (
t <<
"g"_mst)) ||
250 ((acc_tl <<
"i"_mst) && (
t <<
"j"_mst)) ||
251 ((acc_tl <<
"j"_mst) && (
t <<
"i"_mst))))));
256 "e"_mst.
If(all_e && num_s == n_subs) |
257 "m"_mst.
If(all_e && all_m && num_s >= n_subs -
k) |
258 "s"_mst.
If(num_s >= n_subs -
k + 1) |
303 size = std::numeric_limits<size_t>::max();
359 return std::move(a.
size <= b.
size ? a : b);
361 return std::move(a.
size >= b.
size ? a : b);
371 std::vector<Opcode>
out;
373 while (it != itend) {
374 std::vector<unsigned char> push_data;
376 if (!
script.GetOp(it, opcode, push_data)) {
378 }
else if (opcode >=
OP_1 && opcode <=
OP_16) {
391 out.emplace_back(
OP_EQUAL, std::vector<unsigned char>());
403 out.emplace_back(opcode, std::move(push_data));
405 std::reverse(
out.begin(),
out.end());
410 if (in.first ==
OP_0) {
413 if (!in.second.empty()) {
424 for (
int i = 0; i < (int)sp.
size(); ++i) {
425 if (sp[i] ==
m)
return i;
427 if (sp[i] ==
')')
break;
Serialized script, used inside transaction inputs and outputs.
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
If CTxIn::nSequence encodes a relative lock-time and this flag is set, the relative lock-time has uni...
A Span is an object that can refer to a contiguous sequence of objects.
constexpr std::size_t size() const noexcept
This type encapsulates the miniscript type system properties.
constexpr Type If(bool x) const
The empty type if x is false, itself otherwise.
size_t 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.
int FindNextChar(Span< const char > sp, const char m)
std::optional< int64_t > ParseScriptNumber(const Opcode &in)
Determine whether the passed pair (created by DecomposeScript) is pushing a number.
Type SanitizeType(Type e)
A helper sanitizer/checker for the output of CalcType.
std::optional< std::vector< Opcode > > DecomposeScript(const CScript &script)
Decode a script into opcode/push pairs.
InputStack operator+(InputStack a, InputStack b)
InputStack operator|(InputStack a, InputStack b)
Type 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.
constexpr bool IsTapscript(MiniscriptContext ms_ctx)
Whether the context Tapscript, ensuring the only other possibility is P2WSH.
std::pair< opcodetype, std::vector< unsigned char > > Opcode
Fragment
The different node types in miniscript.
@ OR_I
OP_IF [X] OP_ELSE [Y] OP_ENDIF.
@ MULTI_A
[key_0] OP_CHECKSIG ([key_n] OP_CHECKSIGADD)* [k] OP_NUMEQUAL (only within Tapscript ctx)
@ RIPEMD160
OP_SIZE 32 OP_EQUALVERIFY OP_RIPEMD160 [hash] OP_EQUAL.
@ HASH160
OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 [hash] OP_EQUAL.
@ WRAP_A
OP_TOALTSTACK [X] OP_FROMALTSTACK.
@ WRAP_V
[X] OP_VERIFY (or -VERIFY version of last opcode in X)
@ ANDOR
[X] OP_NOTIF [Z] OP_ELSE [Y] OP_ENDIF
@ THRESH
[X1] ([Xn] OP_ADD)* [k] OP_EQUAL
@ OR_C
[X] OP_NOTIF [Y] OP_ENDIF
@ HASH256
OP_SIZE 32 OP_EQUALVERIFY OP_HASH256 [hash] OP_EQUAL.
@ OLDER
[n] OP_CHECKSEQUENCEVERIFY
@ SHA256
OP_SIZE 32 OP_EQUALVERIFY OP_SHA256 [hash] OP_EQUAL.
@ WRAP_J
OP_SIZE OP_0NOTEQUAL OP_IF [X] OP_ENDIF.
@ AFTER
[n] OP_CHECKLOCKTIMEVERIFY
@ OR_D
[X] OP_IFDUP OP_NOTIF [Y] OP_ENDIF
@ WRAP_D
OP_DUP OP_IF [X] OP_ENDIF.
@ AND_B
[X] [Y] OP_BOOLAND
@ PK_H
OP_DUP OP_HASH160 [keyhash] OP_EQUALVERIFY.
@ MULTI
[k] [key_n]* [n] OP_CHECKMULTISIG (only available within P2WSH context)
bool CheckMinimalPush(const std::vector< unsigned char > &data, opcodetype opcode)
static const unsigned int LOCKTIME_THRESHOLD
opcodetype
Script opcodes.
static constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A
The limit of keys in OP_CHECKSIGADD-based scripts.
CScript BuildScript(Ts &&... inputs)
Build a script by concatenating other scripts, or any argument accepted by CScript::operator<<.
static const int MAX_PUBKEYS_PER_MULTISIG
constexpr bool IsPushdataOp(opcodetype opcode)
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.