fixed small claim names coming out as numeric

This commit is contained in:
Brannon King 2019-03-14 14:09:42 -06:00
parent 40a3668c97
commit 21f065aff9
2 changed files with 36 additions and 4 deletions

View file

@ -77,6 +77,10 @@ std::string SighashToStr(unsigned char sighash_type)
return it->second; 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. * Create the assembly string representation of a CScript object.
* @param[in] script CScript object to convert into the asm string representation. * @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; opcodetype opcode;
std::vector<unsigned char> vch; std::vector<unsigned char> vch;
CScript::const_iterator pc = script.begin(); CScript::const_iterator pc = script.begin();
bool isClaimScript = false;
while (pc < script.end()) { while (pc < script.end()) {
if (!str.empty()) { if (!str.empty()) {
str += " "; str += " ";
@ -98,8 +103,9 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco
str += "[error]"; str += "[error]";
return str; return str;
} }
isClaimScript |= IsClaimOpCode(opcode);
if (0 <= opcode && opcode <= OP_PUSHDATA4) { if (0 <= opcode && opcode <= OP_PUSHDATA4) {
if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4)) { if (vch.size() <= static_cast<std::vector<unsigned char>::size_type>(4) && !isClaimScript) {
str += strprintf("%d", CScriptNum(vch, false).getint()); str += strprintf("%d", CScriptNum(vch, false).getint());
} else { } else {
// the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature // the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature

View file

@ -1,7 +1,8 @@
#include "nameclaim.h" #include <nameclaim.h>
#include "primitives/transaction.h" #include <core_io.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "test/test_bitcoin.h" #include <primitives/transaction.h>
#include <test/test_bitcoin.h>
BOOST_FIXTURE_TEST_SUITE(nameclaim_tests, BasicTestingSetup) 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<unsigned char>{ 'h', 'i' }
<< std::vector<unsigned char>{ '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<unsigned char>{ 'h', 'i' }
<< std::vector<unsigned char>{ 'i', 'd' }
<< std::vector<unsigned char>{ '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<unsigned char>{ 'h', 'i' }
<< std::vector<unsigned char>{ '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() BOOST_AUTO_TEST_SUITE_END()