miniscript: add an OpCode typedef for readability

Suggested-by: Vincenzo Palazzo
This commit is contained in:
Antoine Poinsot 2022-05-16 13:07:58 +02:00
parent 7a549c6c59
commit 8323e4249d
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 7 additions and 5 deletions

View File

@ -281,9 +281,9 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_
return 0; return 0;
} }
std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> DecomposeScript(const CScript& script) std::optional<std::vector<Opcode>> DecomposeScript(const CScript& script)
{ {
std::vector<std::pair<opcodetype, std::vector<unsigned char>>> out; std::vector<Opcode> out;
CScript::const_iterator it = script.begin(), itend = script.end(); CScript::const_iterator it = script.begin(), itend = script.end();
while (it != itend) { while (it != itend) {
std::vector<unsigned char> push_data; std::vector<unsigned char> push_data;
@ -317,7 +317,7 @@ std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> De
return out; return out;
} }
std::optional<int64_t> ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in) { std::optional<int64_t> ParseScriptNumber(const Opcode& in) {
if (in.first == OP_0) { if (in.first == OP_0) {
return 0; return 0;
} }

View File

@ -180,6 +180,8 @@ inline constexpr Type operator"" _mst(const char* c, size_t l) {
return typ; return typ;
} }
using Opcode = std::pair<opcodetype, std::vector<unsigned char>>;
template<typename Key> struct Node; template<typename Key> struct Node;
template<typename Key> using NodeRef = std::shared_ptr<const Node<Key>>; template<typename Key> using NodeRef = std::shared_ptr<const Node<Key>>;
@ -1269,10 +1271,10 @@ inline NodeRef<Key> Parse(Span<const char> in, const Ctx& ctx)
* and OP_EQUALVERIFY are decomposed into OP_CHECKSIG, OP_CHECKMULTISIG, OP_EQUAL * and OP_EQUALVERIFY are decomposed into OP_CHECKSIG, OP_CHECKMULTISIG, OP_EQUAL
* respectively, plus OP_VERIFY. * respectively, plus OP_VERIFY.
*/ */
std::optional<std::vector<std::pair<opcodetype, std::vector<unsigned char>>>> DecomposeScript(const CScript& script); std::optional<std::vector<Opcode>> DecomposeScript(const CScript& script);
/** Determine whether the passed pair (created by DecomposeScript) is pushing a number. */ /** Determine whether the passed pair (created by DecomposeScript) is pushing a number. */
std::optional<int64_t> ParseScriptNumber(const std::pair<opcodetype, std::vector<unsigned char>>& in); std::optional<int64_t> ParseScriptNumber(const Opcode& in);
enum class DecodeContext { enum class DecodeContext {
/** A single expression of type B, K, or V. Specifically, this can't be an /** A single expression of type B, K, or V. Specifically, this can't be an