Skip to content

Commit 5922c66

Browse files
darosiorsipa
andcommitted
scripted-diff: miniscript: rename 'nodetype' variables to 'fragment'
The 'Fragment' type was previously named 'Nodetype'. For clarity, name the variables the same. -BEGIN VERIFY SCRIPT- sed -i 's/nodetype/fragment/g' src/script/miniscript.* -END VERIFY SCRIPT- Co-authored-by: Pieter Wuille <[email protected]>
1 parent c5f65db commit 5922c66

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

src/script/miniscript.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,51 @@ Type SanitizeType(Type e) {
3333
return e;
3434
}
3535

36-
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) {
36+
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) {
3737
// Sanity check on data
38-
if (nodetype == Fragment::SHA256 || nodetype == Fragment::HASH256) {
38+
if (fragment == Fragment::SHA256 || fragment == Fragment::HASH256) {
3939
assert(data_size == 32);
40-
} else if (nodetype == Fragment::RIPEMD160 || nodetype == Fragment::HASH160) {
40+
} else if (fragment == Fragment::RIPEMD160 || fragment == Fragment::HASH160) {
4141
assert(data_size == 20);
4242
} else {
4343
assert(data_size == 0);
4444
}
4545
// Sanity check on k
46-
if (nodetype == Fragment::OLDER || nodetype == Fragment::AFTER) {
46+
if (fragment == Fragment::OLDER || fragment == Fragment::AFTER) {
4747
assert(k >= 1 && k < 0x80000000UL);
48-
} else if (nodetype == Fragment::MULTI) {
48+
} else if (fragment == Fragment::MULTI) {
4949
assert(k >= 1 && k <= n_keys);
50-
} else if (nodetype == Fragment::THRESH) {
50+
} else if (fragment == Fragment::THRESH) {
5151
assert(k >= 1 && k <= n_subs);
5252
} else {
5353
assert(k == 0);
5454
}
5555
// Sanity check on subs
56-
if (nodetype == Fragment::AND_V || nodetype == Fragment::AND_B || nodetype == Fragment::OR_B ||
57-
nodetype == Fragment::OR_C || nodetype == Fragment::OR_I || nodetype == Fragment::OR_D) {
56+
if (fragment == Fragment::AND_V || fragment == Fragment::AND_B || fragment == Fragment::OR_B ||
57+
fragment == Fragment::OR_C || fragment == Fragment::OR_I || fragment == Fragment::OR_D) {
5858
assert(n_subs == 2);
59-
} else if (nodetype == Fragment::ANDOR) {
59+
} else if (fragment == Fragment::ANDOR) {
6060
assert(n_subs == 3);
61-
} else if (nodetype == Fragment::WRAP_A || nodetype == Fragment::WRAP_S || nodetype == Fragment::WRAP_C ||
62-
nodetype == Fragment::WRAP_D || nodetype == Fragment::WRAP_V || nodetype == Fragment::WRAP_J ||
63-
nodetype == Fragment::WRAP_N) {
61+
} else if (fragment == Fragment::WRAP_A || fragment == Fragment::WRAP_S || fragment == Fragment::WRAP_C ||
62+
fragment == Fragment::WRAP_D || fragment == Fragment::WRAP_V || fragment == Fragment::WRAP_J ||
63+
fragment == Fragment::WRAP_N) {
6464
assert(n_subs == 1);
65-
} else if (nodetype != Fragment::THRESH) {
65+
} else if (fragment != Fragment::THRESH) {
6666
assert(n_subs == 0);
6767
}
6868
// Sanity check on keys
69-
if (nodetype == Fragment::PK_K || nodetype == Fragment::PK_H) {
69+
if (fragment == Fragment::PK_K || fragment == Fragment::PK_H) {
7070
assert(n_keys == 1);
71-
} else if (nodetype == Fragment::MULTI) {
71+
} else if (fragment == Fragment::MULTI) {
7272
assert(n_keys >= 1 && n_keys <= 20);
7373
} else {
7474
assert(n_keys == 0);
7575
}
7676

77-
// Below is the per-nodetype logic for computing the expression types.
77+
// Below is the per-fragment logic for computing the expression types.
7878
// It heavily relies on Type's << operator (where "X << a_mst" means
7979
// "X has all properties listed in a").
80-
switch (nodetype) {
80+
switch (fragment) {
8181
case Fragment::PK_K: return "Konudemsxk"_mst;
8282
case Fragment::PK_H: return "Knudemsxk"_mst;
8383
case Fragment::OLDER: return
@@ -248,8 +248,8 @@ Type ComputeType(Fragment nodetype, Type x, Type y, Type z, const std::vector<Ty
248248
return ""_mst;
249249
}
250250

251-
size_t ComputeScriptLen(Fragment nodetype, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys) {
252-
switch (nodetype) {
251+
size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys) {
252+
switch (fragment) {
253253
case Fragment::JUST_1:
254254
case Fragment::JUST_0: return 1;
255255
case Fragment::PK_K: return 34;

src/script/miniscript.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ enum class Fragment {
224224
namespace internal {
225225

226226
//! 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);
228228

229229
//! 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);
231231

232232
//! A helper sanitizer/checker for the output of CalcType.
233233
Type SanitizeType(Type x);
@@ -279,7 +279,7 @@ struct StackSize {
279279
template<typename Key>
280280
struct Node {
281281
//! What node type this node is.
282-
const Fragment nodetype;
282+
const Fragment fragment;
283283
//! The k parameter (time for OLDER/AFTER, threshold for THRESH(_M))
284284
const uint32_t k = 0;
285285
//! The keys used by this expression (only for PK_K/PK_H/MULTI)
@@ -306,7 +306,7 @@ struct Node {
306306
subsize += sub->ScriptSize();
307307
}
308308
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());
310310
}
311311

312312
/* Apply a recursive algorithm to a Miniscript tree, without actual recursive calls.
@@ -414,15 +414,15 @@ struct Node {
414414

415415
// THRESH has a variable number of subexpressions
416416
std::vector<Type> sub_types;
417-
if (nodetype == Fragment::THRESH) {
417+
if (fragment == Fragment::THRESH) {
418418
for (const auto& sub : subs) sub_types.push_back(sub->GetType());
419419
}
420420
// All other nodes than THRESH can be computed just from the types of the 0-3 subexpressions.
421421
Type x = subs.size() > 0 ? subs[0]->GetType() : ""_mst;
422422
Type y = subs.size() > 1 ? subs[1]->GetType() : ""_mst;
423423
Type z = subs.size() > 2 ? subs[2]->GetType() : ""_mst;
424424

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()));
426426
}
427427

428428
public:
@@ -434,17 +434,17 @@ struct Node {
434434
// by an OP_VERIFY (which may need to be combined with the last script opcode).
435435
auto downfn = [](bool verify, const Node& node, size_t index) {
436436
// 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;
438438
// The subexpression of WRAP_S, and the last subexpression of AND_V
439439
// 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;
442442
return false;
443443
};
444444
// The upward function computes for a node, given its followed-by-OP_VERIFY status
445445
// and the CScripts of its child nodes, the CScript of the node.
446446
auto upfn = [&ctx](bool verify, const Node& node, Span<CScript> subs) -> CScript {
447-
switch (node.nodetype) {
447+
switch (node.fragment) {
448448
case Fragment::PK_K: return BuildScript(ctx.ToPKBytes(node.keys[0]));
449449
case Fragment::PK_H: return BuildScript(OP_DUP, OP_HASH160, ctx.ToPKHBytes(node.keys[0]), OP_EQUALVERIFY);
450450
case Fragment::OLDER: return BuildScript(node.k, OP_CHECKSEQUENCEVERIFY);
@@ -502,30 +502,30 @@ struct Node {
502502
// the TreeEvalMaybe algorithm. The State is a boolean: whether the parent node is a
503503
// wrapper. If so, non-wrapper expressions must be prefixed with a ":".
504504
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));
512512
};
513513
// The upward function computes for a node, given whether its parent is a wrapper,
514514
// and the string representations of its child nodes, the string representation of the node.
515515
auto upfn = [&ctx](bool wrapped, const Node& node, Span<std::string> subs) -> std::optional<std::string> {
516516
std::string ret = wrapped ? ":" : "";
517517

518-
switch (node.nodetype) {
518+
switch (node.fragment) {
519519
case Fragment::WRAP_A: return "a" + std::move(subs[0]);
520520
case Fragment::WRAP_S: return "s" + std::move(subs[0]);
521521
case Fragment::WRAP_C:
522-
if (node.subs[0]->nodetype == Fragment::PK_K) {
522+
if (node.subs[0]->fragment == Fragment::PK_K) {
523523
// pk(K) is syntactic sugar for c:pk_k(K)
524524
std::string key_str;
525525
if (!ctx.ToString(node.subs[0]->keys[0], key_str)) return {};
526526
return std::move(ret) + "pk(" + std::move(key_str) + ")";
527527
}
528-
if (node.subs[0]->nodetype == Fragment::PK_H) {
528+
if (node.subs[0]->fragment == Fragment::PK_H) {
529529
// pkh(K) is syntactic sugar for c:pk_h(K)
530530
std::string key_str;
531531
if (!ctx.ToString(node.subs[0]->keys[0], key_str)) return {};
@@ -538,15 +538,15 @@ struct Node {
538538
case Fragment::WRAP_N: return "n" + std::move(subs[0]);
539539
case Fragment::AND_V:
540540
// 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]);
542542
break;
543543
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]);
546546
break;
547547
default: break;
548548
}
549-
switch (node.nodetype) {
549+
switch (node.fragment) {
550550
case Fragment::PK_K: {
551551
std::string key_str;
552552
if (!ctx.ToString(node.keys[0], key_str)) return {};
@@ -573,7 +573,7 @@ struct Node {
573573
case Fragment::OR_I: return std::move(ret) + "or_i(" + std::move(subs[0]) + "," + std::move(subs[1]) + ")";
574574
case Fragment::ANDOR:
575575
// 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]) + ")";
577577
return std::move(ret) + "andor(" + std::move(subs[0]) + "," + std::move(subs[1]) + "," + std::move(subs[2]) + ")";
578578
case Fragment::MULTI: {
579579
auto str = std::move(ret) + "multi(" + ::ToString(node.k);
@@ -602,7 +602,7 @@ struct Node {
602602
}
603603

604604
internal::Ops CalcOps() const {
605-
switch (nodetype) {
605+
switch (fragment) {
606606
case Fragment::JUST_1: return {0, 0, {}};
607607
case Fragment::JUST_0: return {0, {}, 0};
608608
case Fragment::PK_K: return {0, 0, 0};
@@ -676,7 +676,7 @@ struct Node {
676676
}
677677

678678
internal::StackSize CalcStackSize() const {
679-
switch (nodetype) {
679+
switch (fragment) {
680680
case Fragment::JUST_0: return {{}, 0};
681681
case Fragment::JUST_1:
682682
case Fragment::OLDER:
@@ -767,7 +767,7 @@ struct Node {
767767
//! Equality testing.
768768
bool operator==(const Node<Key>& arg) const
769769
{
770-
if (nodetype != arg.nodetype) return false;
770+
if (fragment != arg.fragment) return false;
771771
if (k != arg.k) return false;
772772
if (data != arg.data) return false;
773773
if (keys != arg.keys) return false;
@@ -781,12 +781,12 @@ struct Node {
781781
}
782782

783783
// 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()) {}
790790
};
791791

792792
namespace internal {

0 commit comments

Comments
 (0)