diff --git a/src/core_write.cpp b/src/core_write.cpp index 6331a3d88..34a9d2360 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -77,6 +77,10 @@ std::string SighashToStr(unsigned char sighash_type) return it->second; } +bool IsClaimOpCode(opcodetype code) { + return code == opcodetype::OP_CLAIM_NAME || code == opcodetype::OP_SUPPORT_CLAIM || code == opcodetype::OP_UPDATE_CLAIM; +} + /** * Create the assembly string representation of a CScript object. * @param[in] script CScript object to convert into the asm string representation. @@ -90,6 +94,7 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco opcodetype opcode; std::vector vch; CScript::const_iterator pc = script.begin(); + bool isClaimScript = false; while (pc < script.end()) { if (!str.empty()) { str += " "; @@ -98,8 +103,9 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco str += "[error]"; return str; } + isClaimScript |= IsClaimOpCode(opcode); if (0 <= opcode && opcode <= OP_PUSHDATA4) { - if (vch.size() <= static_cast::size_type>(4)) { + if (vch.size() <= static_cast::size_type>(4) && !isClaimScript) { str += strprintf("%d", CScriptNum(vch, false).getint()); } else { // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature diff --git a/src/test/nameclaim_tests.cpp b/src/test/nameclaim_tests.cpp index a22cafc46..d928c2265 100644 --- a/src/test/nameclaim_tests.cpp +++ b/src/test/nameclaim_tests.cpp @@ -1,7 +1,8 @@ -#include "nameclaim.h" -#include "primitives/transaction.h" +#include +#include #include -#include "test/test_bitcoin.h" +#include +#include BOOST_FIXTURE_TEST_SUITE(nameclaim_tests, BasicTestingSetup) @@ -33,4 +34,29 @@ BOOST_AUTO_TEST_CASE(calc_min_claimtrie_fee) } +BOOST_AUTO_TEST_CASE(scriptToAsmStr_output) +{ + auto claimScript = CScript() << OP_CLAIM_NAME + << std::vector{ 'h', 'i' } + << std::vector{ 'd', 'a', 't', 'a' } << OP_2DROP << OP_DROP << OP_TRUE; + + auto result = ScriptToAsmStr(claimScript, false); + BOOST_CHECK(result.find("6869 64617461") != std::string::npos); + + auto updateScript = CScript() << OP_UPDATE_CLAIM + << std::vector{ 'h', 'i' } + << std::vector{ 'i', 'd' } + << std::vector{ 'd', 'a', 't', 'a' } << OP_2DROP << OP_2DROP << OP_TRUE; + + result = ScriptToAsmStr(updateScript, false); + BOOST_CHECK(result.find("64617461") != std::string::npos); + + auto supportScript = CScript() << OP_SUPPORT_CLAIM + << std::vector{ 'h', 'i' } + << std::vector{ 'i', 'd' } << OP_2DROP << OP_DROP << OP_TRUE; + + result = ScriptToAsmStr(supportScript, false); + BOOST_CHECK(result.find("6869 6964") != std::string::npos); +} + BOOST_AUTO_TEST_SUITE_END()