diff --git a/src/claimscriptop.cpp b/src/claimscriptop.cpp index acf3d3573..7f90f3668 100644 --- a/src/claimscriptop.cpp +++ b/src/claimscriptop.cpp @@ -149,7 +149,7 @@ bool ProcessClaim(CClaimScriptOp& claimOp, CClaimTrieCache& trieCache, const CSc { int op; std::vector > vvchParams; - if (!DecodeClaimScript(scriptPubKey, op, vvchParams)) + if (!DecodeClaimScript(scriptPubKey, op, vvchParams, trieCache.allowSupportMetadata())) return false; switch (op) { diff --git a/src/claimtrie.h b/src/claimtrie.h index f4c443ce9..e76a78cf1 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -778,6 +778,8 @@ public: void initializeIncrement() override; bool finalizeDecrement(std::vector>& takeoverHeightUndo) override; + bool allowSupportMetadata() const; + protected: uint256 recursiveComputeMerkleHash(CClaimPrefixTrie::iterator& it) override; diff --git a/src/claimtrieforks.cpp b/src/claimtrieforks.cpp index def94092f..591d2a75a 100644 --- a/src/claimtrieforks.cpp +++ b/src/claimtrieforks.cpp @@ -499,3 +499,7 @@ bool CClaimTrieCacheHashFork::finalizeDecrement(std::vector= Params().GetConsensus().nAllClaimsInMerkleForkHeight; +} diff --git a/src/nameclaim.cpp b/src/nameclaim.cpp index 52517697f..5bb818669 100644 --- a/src/nameclaim.cpp +++ b/src/nameclaim.cpp @@ -37,11 +37,17 @@ CScript ClaimNameScript(std::string name, std::string value, bool fakeSuffix) return ret; } -CScript SupportClaimScript(std::string name, uint160 claimId, bool fakeSuffix) +CScript SupportClaimScript(std::string name, uint160 claimId, std::string value, bool fakeSuffix) { std::vector vchName(name.begin(), name.end()); std::vector vchClaimId(claimId.begin(), claimId.end()); - auto ret = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP; + CScript ret; + if (value.empty()) + ret = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP; + else { + std::vector vchValue(value.begin(), value.end()); + ret = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << vchValue << OP_2DROP << OP_2DROP; + } if (fakeSuffix) ret.push_back(OP_TRUE); return ret; } @@ -54,13 +60,13 @@ CScript UpdateClaimScript(std::string name, uint160 claimId, std::string value) return CScript() << OP_UPDATE_CLAIM << vchName << vchClaimId << vchValue << OP_2DROP << OP_2DROP << OP_TRUE; } -bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams) +bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, bool allowSupportMetadata) { CScript::const_iterator pc = scriptIn.begin(); - return DecodeClaimScript(scriptIn, op, vvchParams, pc); + return DecodeClaimScript(scriptIn, op, vvchParams, pc, allowSupportMetadata); } -bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, CScript::const_iterator& pc) +bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, CScript::const_iterator& pc, bool allowSupportMetadata) { op = -1; opcodetype opcode; @@ -83,6 +89,7 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector OP_PUSHDATA4) @@ -100,35 +107,42 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector OP_PUSHDATA4) + return false; + } + auto last_drop = OP_DROP; + if (opcode >= 0 && opcode <= OP_PUSHDATA4 && op != OP_CLAIM_NAME) + { + if (!scriptIn.GetOp(pc, opcode)) { return false; } + last_drop = OP_2DROP; } - if (!scriptIn.GetOp(pc, opcode) || opcode != OP_2DROP) + else if (op == OP_UPDATE_CLAIM) { return false; } - if (!scriptIn.GetOp(pc, opcode)) + if (opcode != OP_2DROP) { return false; } - if ((op == OP_CLAIM_NAME || op == OP_SUPPORT_CLAIM) && opcode != OP_DROP) + if (!scriptIn.GetOp(pc, opcode) || opcode != last_drop) { return false; } - else if ((op == OP_UPDATE_CLAIM) && opcode != OP_2DROP) + if (op == OP_SUPPORT_CLAIM && last_drop == OP_2DROP && !allowSupportMetadata) { return false; } - vvchParams.push_back(vchParam1); - vvchParams.push_back(vchParam2); - if (op == OP_UPDATE_CLAIM) + vvchParams.push_back(std::move(vchParam1)); + vvchParams.push_back(std::move(vchParam2)); + if (last_drop == OP_2DROP) { - vvchParams.push_back(vchParam3); + vvchParams.push_back(std::move(vchParam3)); } return true; } diff --git a/src/nameclaim.h b/src/nameclaim.h index 591844327..f865f0540 100644 --- a/src/nameclaim.h +++ b/src/nameclaim.h @@ -26,10 +26,10 @@ #define MAX_CLAIM_NAME_SIZE 255 CScript ClaimNameScript(std::string name, std::string value, bool fakeSuffix=true); -CScript SupportClaimScript(std::string name, uint160 claimId, bool fakeSuffix=true); +CScript SupportClaimScript(std::string name, uint160 claimId, std::string value="", bool fakeSuffix=true); CScript UpdateClaimScript(std::string name, uint160 claimId, std::string value); -bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams); -bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, CScript::const_iterator& pc); +bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, bool allowSupportMetadata=true); +bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, CScript::const_iterator& pc, bool allowSupportMetadata=true); CScript StripClaimScriptPrefix(const CScript& scriptIn); CScript StripClaimScriptPrefix(const CScript& scriptIn, int& op); uint160 ClaimIdHash(const uint256& txhash, uint32_t nOut); diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 1ff7eb504..3369f9073 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -177,6 +177,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getclaimproofbybid", 1, "bid"}, { "getclaimproofbyseq", 1, "sequence"}, { "supportclaim", 4, "isTip"}, + { "gettotalvalueofclaims", 0, "controlling_only"}, { "stop", 0, "wait" }, }; // clang-format on diff --git a/src/test/nameclaim_tests.cpp b/src/test/nameclaim_tests.cpp index d928c2265..96c6af4ed 100644 --- a/src/test/nameclaim_tests.cpp +++ b/src/test/nameclaim_tests.cpp @@ -8,7 +8,6 @@ BOOST_FIXTURE_TEST_SUITE(nameclaim_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(calc_min_claimtrie_fee) { - CMutableTransaction tx; tx.vout.resize(1); tx.vout[0].scriptPubKey = ClaimNameScript("A","test"); @@ -31,7 +30,18 @@ BOOST_AUTO_TEST_CASE(calc_min_claimtrie_fee) CMutableTransaction tx4; tx4.vout.resize(1); BOOST_CHECK_EQUAL(CalcMinClaimTrieFee(tx4,MIN_FEE_PER_NAMECLAIM_CHAR), 0); +} +BOOST_AUTO_TEST_CASE(support_handles_value) +{ + auto script = SupportClaimScript("s1", uint160(), "me value"); + int op = 0; + std::vector> params; + BOOST_CHECK(!DecodeClaimScript(script, op, params, false)); + params.clear(); + BOOST_CHECK(DecodeClaimScript(script, op, params)); + BOOST_CHECK(params[0][0] == 's'); + BOOST_CHECK(std::string(params[2].begin(), params[2].end()) == "me value"); } BOOST_AUTO_TEST_CASE(scriptToAsmStr_output)