@@ -224,10 +224,10 @@ enum class Fragment {
224
224
namespace internal {
225
225
226
226
// ! Helper function for Node::CalcType.
227
- Type ComputeType (Fragment nodetype , 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);
227
+ 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);
228
228
229
229
// ! Helper function for Node::CalcScriptLen.
230
- size_t ComputeScriptLen (Fragment nodetype , Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys);
230
+ size_t ComputeScriptLen (Fragment fragment , Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys);
231
231
232
232
// ! A helper sanitizer/checker for the output of CalcType.
233
233
Type SanitizeType (Type x);
@@ -279,7 +279,7 @@ struct StackSize {
279
279
template <typename Key>
280
280
struct Node {
281
281
// ! What node type this node is.
282
- const Fragment nodetype ;
282
+ const Fragment fragment ;
283
283
// ! The k parameter (time for OLDER/AFTER, threshold for THRESH(_M))
284
284
const uint32_t k = 0 ;
285
285
// ! The keys used by this expression (only for PK_K/PK_H/MULTI)
@@ -306,7 +306,7 @@ struct Node {
306
306
subsize += sub->ScriptSize ();
307
307
}
308
308
Type sub0type = subs.size () > 0 ? subs[0 ]->GetType () : " " _mst;
309
- return internal::ComputeScriptLen (nodetype , sub0type, subsize, k, subs.size (), keys.size ());
309
+ return internal::ComputeScriptLen (fragment , sub0type, subsize, k, subs.size (), keys.size ());
310
310
}
311
311
312
312
/* Apply a recursive algorithm to a Miniscript tree, without actual recursive calls.
@@ -414,15 +414,15 @@ struct Node {
414
414
415
415
// THRESH has a variable number of subexpressions
416
416
std::vector<Type> sub_types;
417
- if (nodetype == Fragment::THRESH) {
417
+ if (fragment == Fragment::THRESH) {
418
418
for (const auto & sub : subs) sub_types.push_back (sub->GetType ());
419
419
}
420
420
// All other nodes than THRESH can be computed just from the types of the 0-3 subexpressions.
421
421
Type x = subs.size () > 0 ? subs[0 ]->GetType () : " " _mst;
422
422
Type y = subs.size () > 1 ? subs[1 ]->GetType () : " " _mst;
423
423
Type z = subs.size () > 2 ? subs[2 ]->GetType () : " " _mst;
424
424
425
- return SanitizeType (ComputeType (nodetype , x, y, z, sub_types, k, data.size (), subs.size (), keys.size ()));
425
+ return SanitizeType (ComputeType (fragment , x, y, z, sub_types, k, data.size (), subs.size (), keys.size ()));
426
426
}
427
427
428
428
public:
@@ -434,17 +434,17 @@ struct Node {
434
434
// by an OP_VERIFY (which may need to be combined with the last script opcode).
435
435
auto downfn = [](bool verify, const Node& node, size_t index) {
436
436
// For WRAP_V, the subexpression is certainly followed by OP_VERIFY.
437
- if (node.nodetype == Fragment::WRAP_V) return true ;
437
+ if (node.fragment == Fragment::WRAP_V) return true ;
438
438
// The subexpression of WRAP_S, and the last subexpression of AND_V
439
439
// inherit the followed-by-OP_VERIFY property from the parent.
440
- if (node.nodetype == Fragment::WRAP_S ||
441
- (node.nodetype == Fragment::AND_V && index == 1 )) return verify;
440
+ if (node.fragment == Fragment::WRAP_S ||
441
+ (node.fragment == Fragment::AND_V && index == 1 )) return verify;
442
442
return false ;
443
443
};
444
444
// The upward function computes for a node, given its followed-by-OP_VERIFY status
445
445
// and the CScripts of its child nodes, the CScript of the node.
446
446
auto upfn = [&ctx](bool verify, const Node& node, Span<CScript> subs) -> CScript {
447
- switch (node.nodetype ) {
447
+ switch (node.fragment ) {
448
448
case Fragment::PK_K: return BuildScript (ctx.ToPKBytes (node.keys [0 ]));
449
449
case Fragment::PK_H: return BuildScript (OP_DUP, OP_HASH160, ctx.ToPKHBytes (node.keys [0 ]), OP_EQUALVERIFY);
450
450
case Fragment::OLDER: return BuildScript (node.k , OP_CHECKSEQUENCEVERIFY);
@@ -502,30 +502,30 @@ struct Node {
502
502
// the TreeEvalMaybe algorithm. The State is a boolean: whether the parent node is a
503
503
// wrapper. If so, non-wrapper expressions must be prefixed with a ":".
504
504
auto downfn = [](bool , const Node& node, size_t ) {
505
- return (node.nodetype == Fragment::WRAP_A || node.nodetype == Fragment::WRAP_S ||
506
- node.nodetype == Fragment::WRAP_D || node.nodetype == Fragment::WRAP_V ||
507
- node.nodetype == Fragment::WRAP_J || node.nodetype == Fragment::WRAP_N ||
508
- node.nodetype == Fragment::WRAP_C ||
509
- (node.nodetype == Fragment::AND_V && node.subs [1 ]->nodetype == Fragment::JUST_1) ||
510
- (node.nodetype == Fragment::OR_I && node.subs [0 ]->nodetype == Fragment::JUST_0) ||
511
- (node.nodetype == Fragment::OR_I && node.subs [1 ]->nodetype == Fragment::JUST_0));
505
+ return (node.fragment == Fragment::WRAP_A || node.fragment == Fragment::WRAP_S ||
506
+ node.fragment == Fragment::WRAP_D || node.fragment == Fragment::WRAP_V ||
507
+ node.fragment == Fragment::WRAP_J || node.fragment == Fragment::WRAP_N ||
508
+ node.fragment == Fragment::WRAP_C ||
509
+ (node.fragment == Fragment::AND_V && node.subs [1 ]->fragment == Fragment::JUST_1) ||
510
+ (node.fragment == Fragment::OR_I && node.subs [0 ]->fragment == Fragment::JUST_0) ||
511
+ (node.fragment == Fragment::OR_I && node.subs [1 ]->fragment == Fragment::JUST_0));
512
512
};
513
513
// The upward function computes for a node, given whether its parent is a wrapper,
514
514
// and the string representations of its child nodes, the string representation of the node.
515
515
auto upfn = [&ctx](bool wrapped, const Node& node, Span<std::string> subs) -> std::optional<std::string> {
516
516
std::string ret = wrapped ? " :" : " " ;
517
517
518
- switch (node.nodetype ) {
518
+ switch (node.fragment ) {
519
519
case Fragment::WRAP_A: return " a" + std::move (subs[0 ]);
520
520
case Fragment::WRAP_S: return " s" + std::move (subs[0 ]);
521
521
case Fragment::WRAP_C:
522
- if (node.subs [0 ]->nodetype == Fragment::PK_K) {
522
+ if (node.subs [0 ]->fragment == Fragment::PK_K) {
523
523
// pk(K) is syntactic sugar for c:pk_k(K)
524
524
std::string key_str;
525
525
if (!ctx.ToString (node.subs [0 ]->keys [0 ], key_str)) return {};
526
526
return std::move (ret) + " pk(" + std::move (key_str) + " )" ;
527
527
}
528
- if (node.subs [0 ]->nodetype == Fragment::PK_H) {
528
+ if (node.subs [0 ]->fragment == Fragment::PK_H) {
529
529
// pkh(K) is syntactic sugar for c:pk_h(K)
530
530
std::string key_str;
531
531
if (!ctx.ToString (node.subs [0 ]->keys [0 ], key_str)) return {};
@@ -538,15 +538,15 @@ struct Node {
538
538
case Fragment::WRAP_N: return " n" + std::move (subs[0 ]);
539
539
case Fragment::AND_V:
540
540
// t:X is syntactic sugar for and_v(X,1).
541
- if (node.subs [1 ]->nodetype == Fragment::JUST_1) return " t" + std::move (subs[0 ]);
541
+ if (node.subs [1 ]->fragment == Fragment::JUST_1) return " t" + std::move (subs[0 ]);
542
542
break ;
543
543
case Fragment::OR_I:
544
- if (node.subs [0 ]->nodetype == Fragment::JUST_0) return " l" + std::move (subs[1 ]);
545
- if (node.subs [1 ]->nodetype == Fragment::JUST_0) return " u" + std::move (subs[0 ]);
544
+ if (node.subs [0 ]->fragment == Fragment::JUST_0) return " l" + std::move (subs[1 ]);
545
+ if (node.subs [1 ]->fragment == Fragment::JUST_0) return " u" + std::move (subs[0 ]);
546
546
break ;
547
547
default : break ;
548
548
}
549
- switch (node.nodetype ) {
549
+ switch (node.fragment ) {
550
550
case Fragment::PK_K: {
551
551
std::string key_str;
552
552
if (!ctx.ToString (node.keys [0 ], key_str)) return {};
@@ -573,7 +573,7 @@ struct Node {
573
573
case Fragment::OR_I: return std::move (ret) + " or_i(" + std::move (subs[0 ]) + " ," + std::move (subs[1 ]) + " )" ;
574
574
case Fragment::ANDOR:
575
575
// and_n(X,Y) is syntactic sugar for andor(X,Y,0).
576
- if (node.subs [2 ]->nodetype == Fragment::JUST_0) return std::move (ret) + " and_n(" + std::move (subs[0 ]) + " ," + std::move (subs[1 ]) + " )" ;
576
+ if (node.subs [2 ]->fragment == Fragment::JUST_0) return std::move (ret) + " and_n(" + std::move (subs[0 ]) + " ," + std::move (subs[1 ]) + " )" ;
577
577
return std::move (ret) + " andor(" + std::move (subs[0 ]) + " ," + std::move (subs[1 ]) + " ," + std::move (subs[2 ]) + " )" ;
578
578
case Fragment::MULTI: {
579
579
auto str = std::move (ret) + " multi(" + ::ToString (node.k );
@@ -602,7 +602,7 @@ struct Node {
602
602
}
603
603
604
604
internal::Ops CalcOps () const {
605
- switch (nodetype ) {
605
+ switch (fragment ) {
606
606
case Fragment::JUST_1: return {0 , 0 , {}};
607
607
case Fragment::JUST_0: return {0 , {}, 0 };
608
608
case Fragment::PK_K: return {0 , 0 , 0 };
@@ -676,7 +676,7 @@ struct Node {
676
676
}
677
677
678
678
internal::StackSize CalcStackSize () const {
679
- switch (nodetype ) {
679
+ switch (fragment ) {
680
680
case Fragment::JUST_0: return {{}, 0 };
681
681
case Fragment::JUST_1:
682
682
case Fragment::OLDER:
@@ -767,7 +767,7 @@ struct Node {
767
767
// ! Equality testing.
768
768
bool operator ==(const Node<Key>& arg) const
769
769
{
770
- if (nodetype != arg.nodetype ) return false ;
770
+ if (fragment != arg.fragment ) return false ;
771
771
if (k != arg.k ) return false ;
772
772
if (data != arg.data ) return false ;
773
773
if (keys != arg.keys ) return false ;
@@ -781,12 +781,12 @@ struct Node {
781
781
}
782
782
783
783
// Constructors with various argument combinations.
784
- Node (Fragment nt, std::vector<NodeRef<Key>> sub, std::vector<unsigned char > arg, uint32_t val = 0 ) : nodetype (nt), k(val), data(std::move(arg)), subs(std::move(sub)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
785
- Node (Fragment nt, std::vector<unsigned char > arg, uint32_t val = 0 ) : nodetype (nt), k(val), data(std::move(arg)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
786
- Node (Fragment nt, std::vector<NodeRef<Key>> sub, std::vector<Key> key, uint32_t val = 0 ) : nodetype (nt), k(val), keys(std::move(key)), subs(std::move(sub)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
787
- Node (Fragment nt, std::vector<Key> key, uint32_t val = 0 ) : nodetype (nt), k(val), keys(std::move(key)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
788
- Node (Fragment nt, std::vector<NodeRef<Key>> sub, uint32_t val = 0 ) : nodetype (nt), k(val), subs(std::move(sub)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
789
- Node (Fragment nt, uint32_t val = 0 ) : nodetype (nt), k(val), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
784
+ Node (Fragment nt, std::vector<NodeRef<Key>> sub, std::vector<unsigned char > arg, uint32_t val = 0 ) : fragment (nt), k(val), data(std::move(arg)), subs(std::move(sub)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
785
+ Node (Fragment nt, std::vector<unsigned char > arg, uint32_t val = 0 ) : fragment (nt), k(val), data(std::move(arg)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
786
+ Node (Fragment nt, std::vector<NodeRef<Key>> sub, std::vector<Key> key, uint32_t val = 0 ) : fragment (nt), k(val), keys(std::move(key)), subs(std::move(sub)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
787
+ Node (Fragment nt, std::vector<Key> key, uint32_t val = 0 ) : fragment (nt), k(val), keys(std::move(key)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
788
+ Node (Fragment nt, std::vector<NodeRef<Key>> sub, uint32_t val = 0 ) : fragment (nt), k(val), subs(std::move(sub)), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
789
+ Node (Fragment nt, uint32_t val = 0 ) : fragment (nt), k(val), ops(CalcOps()), ss(CalcStackSize()), typ(CalcType()), scriptlen(CalcScriptLen()) {}
790
790
};
791
791
792
792
namespace internal {
0 commit comments