Claimid rpc updates #15
3 changed files with 108 additions and 0 deletions
|
@ -458,6 +458,73 @@ bool CClaimTrie::getLastTakeoverForName(const std::string& name, int& lastTakeov
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
|
||||||
|
{
|
||||||
|
std::vector<CClaimValue> claims;
|
||||||
|
std::vector<CSupportValue> supports;
|
||||||
|
int nLastTakeoverHeight = 0;
|
||||||
|
const CClaimTrieNode* current = getNodeForName(name);
|
||||||
|
if (current)
|
||||||
|
{
|
||||||
|
if (!current->claims.empty())
|
||||||
|
{
|
||||||
|
nLastTakeoverHeight = current->nHeightOfLastTakeover;
|
||||||
|
}
|
||||||
|
for (std::vector<CClaimValue>::const_iterator itClaims = current->claims.begin(); itClaims != current->claims.end(); ++itClaims)
|
||||||
|
{
|
||||||
|
claims.push_back(*itClaims);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
supportMapEntryType supportNode;
|
||||||
|
if (getSupportNode(name, supportNode))
|
||||||
|
{
|
||||||
|
for (std::vector<CSupportValue>::const_iterator itSupports = supportNode.begin(); itSupports != supportNode.end(); ++itSupports)
|
||||||
|
{
|
||||||
|
supports.push_back(*itSupports);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queueNameRowType namedClaimRow;
|
||||||
|
if (getQueueNameRow(name, namedClaimRow))
|
||||||
|
{
|
||||||
|
for (queueNameRowType::const_iterator itClaimsForName = namedClaimRow.begin(); itClaimsForName != namedClaimRow.end(); ++itClaimsForName)
|
||||||
|
{
|
||||||
|
claimQueueRowType claimRow;
|
||||||
|
if (getQueueRow(itClaimsForName->nHeight, claimRow))
|
||||||
|
{
|
||||||
|
for (claimQueueRowType::const_iterator itClaimRow = claimRow.begin(); itClaimRow != claimRow.end(); ++itClaimRow)
|
||||||
|
{
|
||||||
|
if (itClaimRow->first == name && itClaimRow->second.outPoint == itClaimsForName->outPoint)
|
||||||
|
{
|
||||||
|
claims.push_back(itClaimRow->second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queueNameRowType namedSupportRow;
|
||||||
|
if (getSupportQueueNameRow(name, namedSupportRow))
|
||||||
|
{
|
||||||
|
for (queueNameRowType::const_iterator itSupportsForName = namedSupportRow.begin(); itSupportsForName != namedSupportRow.end(); ++itSupportsForName)
|
||||||
|
{
|
||||||
|
supportQueueRowType supportRow;
|
||||||
|
if (getSupportQueueRow(itSupportsForName->nHeight, supportRow))
|
||||||
|
{
|
||||||
|
for (supportQueueRowType::const_iterator itSupportRow = supportRow.begin(); itSupportRow != supportRow.end(); ++itSupportRow)
|
||||||
|
{
|
||||||
|
if (itSupportRow->first == name && itSupportRow->second.outPoint == itSupportsForName->outPoint)
|
||||||
|
{
|
||||||
|
supports.push_back(itSupportRow->second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
claimsForNameType allClaims(claims, supports, nLastTakeoverHeight);
|
||||||
|
return allClaims;
|
||||||
|
}
|
||||||
|
|
||||||
bool CClaimTrie::checkConsistency() const
|
bool CClaimTrie::checkConsistency() const
|
||||||
{
|
{
|
||||||
if (empty())
|
if (empty())
|
||||||
|
|
|
@ -265,6 +265,16 @@ typedef std::map<std::string, CClaimTrieNode*, nodenamecompare> nodeCacheType;
|
||||||
|
|
||||||
typedef std::map<std::string, uint256> hashMapType;
|
typedef std::map<std::string, uint256> hashMapType;
|
||||||
|
|
||||||
|
struct claimsForNameType
|
||||||
|
{
|
||||||
|
std::vector<CClaimValue> claims;
|
||||||
|
std::vector<CSupportValue> supports;
|
||||||
|
int nLastTakeoverHeight;
|
||||||
|
|
||||||
|
claimsForNameType(std::vector<CClaimValue> claims, std::vector<CSupportValue> supports, int nLastTakeoverHeight)
|
||||||
|
: claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {}
|
||||||
|
};
|
||||||
|
|
||||||
class CClaimTrieCache;
|
class CClaimTrieCache;
|
||||||
|
|
||||||
class CClaimTrie
|
class CClaimTrie
|
||||||
|
@ -290,6 +300,8 @@ public:
|
||||||
std::vector<namedNodeType> flattenTrie() const;
|
std::vector<namedNodeType> flattenTrie() const;
|
||||||
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
|
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
|
||||||
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
|
||||||
|
|
||||||
|
claimsForNameType getClaimsForName(const std::string& name) const;
|
||||||
|
|
||||||
bool queueEmpty() const;
|
bool queueEmpty() const;
|
||||||
bool supportEmpty() const;
|
bool supportEmpty() const;
|
||||||
|
|
|
@ -181,6 +181,34 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue getclaimsforname(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() != 1)
|
||||||
|
throw std::runtime_error(
|
||||||
|
"getclaimsforname\n"
|
||||||
|
"Return a whole bunch of stuff, I tell you what"
|
||||||
|
);
|
||||||
|
|
||||||
|
LOCK(cs_main);
|
||||||
|
std::string name = params[0].get_str();
|
||||||
|
claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name);
|
||||||
|
UniValue ret(UniValue::VARR);
|
||||||
|
for (std::vector<CClaimValue>::const_iterator itClaims = claimsForName.claims.begin(); itClaims != claimsForName.claims.end(); ++itClaims)
|
||||||
|
{
|
||||||
|
UniValue claim(UniValue::VOBJ);
|
||||||
|
claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex()));
|
||||||
|
ret.push_back(claim);
|
||||||
|
}
|
||||||
|
for (std::vector<CSupportValue>::const_iterator itSupports = claimsForName.supports.begin(); itSupports != claimsForName.supports.end(); ++itSupports)
|
||||||
|
{
|
||||||
|
UniValue support(UniValue::VOBJ);
|
||||||
|
support.push_back(Pair("txid", itSupports->outPoint.hash.GetHex()));
|
||||||
|
ret.push_back(support);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
UniValue gettotalclaimednames(const UniValue& params, bool fHelp)
|
UniValue gettotalclaimednames(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 0)
|
if (fHelp || params.size() != 0)
|
||||||
|
@ -535,6 +563,7 @@ static const CRPCCommand commands[] =
|
||||||
{ "Claimtrie", "getclaimsintrie", &getclaimsintrie, true },
|
{ "Claimtrie", "getclaimsintrie", &getclaimsintrie, true },
|
||||||
{ "Claimtrie", "getclaimtrie", &getclaimtrie, true },
|
{ "Claimtrie", "getclaimtrie", &getclaimtrie, true },
|
||||||
{ "Claimtrie", "getvalueforname", &getvalueforname, true },
|
{ "Claimtrie", "getvalueforname", &getvalueforname, true },
|
||||||
|
{ "Claimtrie", "getclaimsforname", &getclaimsforname, true },
|
||||||
{ "Claimtrie", "gettotalclaimednames", &gettotalclaimednames, true },
|
{ "Claimtrie", "gettotalclaimednames", &gettotalclaimednames, true },
|
||||||
{ "Claimtrie", "gettotalclaims", &gettotalclaims, true },
|
{ "Claimtrie", "gettotalclaims", &gettotalclaims, true },
|
||||||
{ "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
|
{ "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
|
||||||
|
|
Loading…
Reference in a new issue