fixed small claim names coming out as numeric
This commit is contained in:
parent
9c866832de
commit
9ad7b0c90f
2 changed files with 36 additions and 4 deletions
|
@ -76,6 +76,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.
|
||||
|
@ -89,6 +93,7 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco
|
|||
opcodetype opcode;
|
||||
std::vector<unsigned char> vch;
|
||||
CScript::const_iterator pc = script.begin();
|
||||
bool isClaimScript = false;
|
||||
while (pc < script.end()) {
|
||||
if (!str.empty()) {
|
||||
str += " ";
|
||||
|
@ -97,8 +102,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<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());
|
||||
} else {
|
||||
// the IsUnspendable check makes sure not to try to decode OP_RETURN data that may match the format of a signature
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "nameclaim.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include <nameclaim.h>
|
||||
#include <core_io.h>
|
||||
#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)
|
||||
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue