Skip to content

Commit 8323e42

Browse files
committed
miniscript: add an OpCode typedef for readability
Suggested-by: Vincenzo Palazzo
1 parent 7a549c6 commit 8323e42

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/script/miniscript.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_
281281
return 0;
282282
}
283283

284-
std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> DecomposeScript(const CScript& script)
284+
std::optional<std::vector<Opcode>> DecomposeScript(const CScript& script)
285285
{
286-
std::vector<std::pair<opcodetype, std::vector<unsigned char>>> out;
286+
std::vector<Opcode> out;
287287
CScript::const_iterator it = script.begin(), itend = script.end();
288288
while (it != itend) {
289289
std::vector<unsigned char> push_data;
@@ -317,7 +317,7 @@ std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> De
317317
return out;
318318
}
319319

320-
std::optional<int64_t> ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in) {
320+
std::optional<int64_t> ParseScriptNumber(const Opcode& in) {
321321
if (in.first == OP_0) {
322322
return 0;
323323
}

src/script/miniscript.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ inline constexpr Type operator"" _mst(const char* c, size_t l) {
180180
return typ;
181181
}
182182

183+
using Opcode = std::pair<opcodetype, std::vector<unsigned char>>;
184+
183185
template<typename Key> struct Node;
184186
template<typename Key> using NodeRef = std::shared_ptr<const Node<Key>>;
185187

@@ -1269,10 +1271,10 @@ inline NodeRef<Key> Parse(Span<const char> in, const Ctx& ctx)
12691271
* and OP_EQUALVERIFY are decomposed into OP_CHECKSIG, OP_CHECKMULTISIG, OP_EQUAL
12701272
* respectively, plus OP_VERIFY.
12711273
*/
1272-
std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> DecomposeScript(const CScript& script);
1274+
std::optional<std::vector<Opcode>> DecomposeScript(const CScript& script);
12731275

12741276
/** Determine whether the passed pair (created by DecomposeScript) is pushing a number. */
1275-
std::optional<int64_t> ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in);
1277+
std::optional<int64_t> ParseScriptNumber(const Opcode& in);
12761278

12771279
enum class DecodeContext {
12781280
/** A single expression of type B, K, or V. Specifically, this can't be an

0 commit comments

Comments
 (0)