From 00c22ba62c6db0cf1fb4062c0dcfa20d778537fa Mon Sep 17 00:00:00 2001 From: willcl-ark Date: Wed, 15 Nov 2023 20:55:01 +0000 Subject: [PATCH] script: add BracketStr helper fn wrap a pushed value in angle brackets --- src/core_write.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core_write.cpp b/src/core_write.cpp index 6047415e329379..3bf80096177616 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -88,6 +88,15 @@ std::string SighashToStr(unsigned char sighash_type) return it->second; } +/** + * Wrap a string in angle brackets for ASM + */ +std::string BracketStr(std::string h) +{ + std::string s = "<" + h + ">"; + return s; +} + /** * Create the assembly string representation of a CScript object. * @param[in] script CScript object to convert into the asm string representation. @@ -128,17 +137,13 @@ std::string ScriptToAsmStr(const CScript& script) str += strprintf("%lld", LittleEndianBytesToDecimal(vch)); } else { // Otherwise display the push as LE hex enclosed in angle brackets - str += "<"; - str += HexStr(vch); - str += ">"; + str += BracketStr(HexStr(vch)); } continue; } - // If push not minimally-encoded prepend with opcode name + // If push not minimally-encoded prepend with opcode name and enclose in angle brackets str += GetOpNameAsm(opcode); - str += "<"; - str += HexStr(vch); - str += ">"; + str += BracketStr(HexStr(vch)); continue; } // Handle unknown opcodes