initial commit of metadata on supports

This commit is contained in:
Brannon King 2019-09-04 14:27:07 -06:00
parent 4da4ab1995
commit b434864f18
7 changed files with 51 additions and 20 deletions

View file

@ -149,7 +149,7 @@ bool ProcessClaim(CClaimScriptOp& claimOp, CClaimTrieCache& trieCache, const CSc
{
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (!DecodeClaimScript(scriptPubKey, op, vvchParams))
if (!DecodeClaimScript(scriptPubKey, op, vvchParams, trieCache.allowSupportMetadata()))
return false;
switch (op) {

View file

@ -778,6 +778,8 @@ public:
void initializeIncrement() override;
bool finalizeDecrement(std::vector<std::pair<std::string, int>>& takeoverHeightUndo) override;
bool allowSupportMetadata() const;
protected:
uint256 recursiveComputeMerkleHash(CClaimPrefixTrie::iterator& it) override;

View file

@ -499,3 +499,7 @@ bool CClaimTrieCacheHashFork::finalizeDecrement(std::vector<std::pair<std::strin
copyAllBaseToCache();
return ret;
}
bool CClaimTrieCacheHashFork::allowSupportMetadata() const {
return nNextHeight >= Params().GetConsensus().nAllClaimsInMerkleForkHeight;
}

View file

@ -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<unsigned char> vchName(name.begin(), name.end());
std::vector<unsigned char> 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<unsigned char> 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<std::vector<unsigned char> >& vvchParams)
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& 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<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc)
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc, bool allowSupportMetadata)
{
op = -1;
opcodetype opcode;
@ -83,6 +89,7 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector
// OP_CLAIM_NAME vchName vchValue OP_2DROP OP_DROP pubkeyscript
// OP_UPDATE_CLAIM vchName vchClaimId vchValue OP_2DROP OP_2DROP pubkeyscript
// OP_SUPPORT_CLAIM vchName vchClaimId OP_2DROP OP_DROP pubkeyscript
// OP_SUPPORT_CLAIM vchName vchClaimId vchValue OP_2DROP OP_2DROP pubkeyscript
// All others are invalid.
if (!scriptIn.GetOp(pc, opcode, vchParam1) || opcode < 0 || opcode > OP_PUSHDATA4)
@ -100,35 +107,42 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector
return false;
}
}
if (op == OP_UPDATE_CLAIM)
{
if (!scriptIn.GetOp(pc, opcode, vchParam3) || opcode < 0 || opcode > OP_PUSHDATA4)
if (!scriptIn.GetOp(pc, opcode, vchParam3))
{
return false;
}
}
if (!scriptIn.GetOp(pc, opcode) || opcode != OP_2DROP)
auto last_drop = OP_DROP;
if (opcode >= 0 && opcode <= OP_PUSHDATA4 && op != OP_CLAIM_NAME)
{
return false;
}
if (!scriptIn.GetOp(pc, opcode))
{
return false;
}
if ((op == OP_CLAIM_NAME || op == OP_SUPPORT_CLAIM) && opcode != OP_DROP)
last_drop = OP_2DROP;
}
else if (op == OP_UPDATE_CLAIM)
{
return false;
}
else if ((op == OP_UPDATE_CLAIM) && opcode != OP_2DROP)
if (opcode != OP_2DROP)
{
return false;
}
if (!scriptIn.GetOp(pc, opcode) || opcode != last_drop)
{
return false;
}
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;
}

View file

@ -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<std::vector<unsigned char> >& vvchParams);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, bool allowSupportMetadata=true);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& 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);

View file

@ -179,6 +179,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getclaimproofbybid", 1, "bid"},
{ "getclaimproofbyseq", 1, "sequence"},
{ "supportclaim", 4, "isTip"},
{ "gettotalvalueofclaims", 0, "controlling_only"},
};
class CRPCConvertTable

View file

@ -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<std::vector<unsigned char>> 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)