mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-02-04 19:24:20 +00:00
Added associated namespaces initialized by us.
This commit is contained in:
parent
9a23025a3f
commit
e22b05a951
@ -14,6 +14,8 @@
|
||||
/* ************************************************************************** */
|
||||
/* CKevaData. */
|
||||
|
||||
const std::string CKevaData::ASSOCIATE_PREFIX = "_g:";
|
||||
|
||||
void
|
||||
CKevaData::fromScript (unsigned h, const COutPoint& out,
|
||||
const CKevaScript& script)
|
||||
@ -192,8 +194,6 @@ bool CCacheKeyIterator::next(valtype& key, CKevaData& data)
|
||||
/* ************************************************************************** */
|
||||
/* CKevaCache. */
|
||||
|
||||
const std::string CKevaCache::associatePrefix = "_g:";
|
||||
|
||||
bool
|
||||
CKevaCache::get(const valtype& nameSpace, const valtype& key, CKevaData& data) const
|
||||
{
|
||||
@ -250,10 +250,10 @@ bool
|
||||
CKevaCache::getAssociateNamespaces(const valtype& value, valtype& nameSpace)
|
||||
{
|
||||
std::string valueStr = ValtypeToString(value);
|
||||
if (valueStr.rfind(associatePrefix, 0) != 0) {
|
||||
if (valueStr.rfind(CKevaData::ASSOCIATE_PREFIX, 0) != 0) {
|
||||
return false;
|
||||
}
|
||||
valueStr.erase(0, associatePrefix.length());
|
||||
valueStr.erase(0, CKevaData::ASSOCIATE_PREFIX.length());
|
||||
if (!DecodeKevaNamespace(valueStr, Params(), nameSpace)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -56,6 +56,8 @@ ValtypeToString (const valtype& val)
|
||||
*/
|
||||
class CKevaData
|
||||
{
|
||||
public:
|
||||
const static std::string ASSOCIATE_PREFIX;
|
||||
|
||||
private:
|
||||
|
||||
@ -298,8 +300,6 @@ class CKevaCache
|
||||
|
||||
private:
|
||||
|
||||
const static std::string associatePrefix;
|
||||
|
||||
/**
|
||||
* Special comparator class for names that compares by length first.
|
||||
* This is used to sort the cache entry map in the same way as the
|
||||
|
@ -418,6 +418,7 @@ UniValue keva_show_group(const JSONRPCRequest& request)
|
||||
valtype nsDisplayKey = ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY);
|
||||
std::unique_ptr<CKevaIterator> iter(pcoinsTip->IterateAssociatedNamespaces(nameSpace));
|
||||
|
||||
// Find the namespace connection initialized by others.
|
||||
while (iter->next(ns, data)) {
|
||||
const int age = chainActive.Height() - data.getHeight();
|
||||
assert(age >= 0);
|
||||
@ -450,6 +451,55 @@ UniValue keva_show_group(const JSONRPCRequest& request)
|
||||
}
|
||||
}
|
||||
|
||||
// Find the namespace connection initialized by us.
|
||||
std::unique_ptr<CKevaIterator> iterKeys(pcoinsTip->IterateKeys(nameSpace));
|
||||
valtype targetNS;
|
||||
valtype key;
|
||||
while (iterKeys->next(key, data)) {
|
||||
|
||||
// Find the value with the format _g:NamespaceId
|
||||
std::string keyStr = ValtypeToString(key);
|
||||
if (keyStr.rfind(CKevaData::ASSOCIATE_PREFIX, 0) != 0) {
|
||||
continue;
|
||||
}
|
||||
keyStr.erase(0, CKevaData::ASSOCIATE_PREFIX.length());
|
||||
if (!DecodeKevaNamespace(keyStr, Params(), targetNS)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int age = chainActive.Height() - data.getHeight();
|
||||
assert(age >= 0);
|
||||
if (maxage != 0 && age >= maxage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (from > 0) {
|
||||
--from;
|
||||
continue;
|
||||
}
|
||||
assert(from == 0);
|
||||
|
||||
if (stats) {
|
||||
++count;
|
||||
}
|
||||
else {
|
||||
CKevaData nsData;
|
||||
valtype nsName;
|
||||
if (pcoinsTip->GetName(targetNS, nsDisplayKey, nsData)) {
|
||||
nsName = nsData.getValue();
|
||||
}
|
||||
namespaces.push_back(getNamespaceInfo(targetNS, nsName, data.getUpdateOutpoint(),
|
||||
data.getAddress(), data.getHeight(), false));
|
||||
}
|
||||
|
||||
if (nb > 0) {
|
||||
--nb;
|
||||
if (nb == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (stats) {
|
||||
UniValue res(UniValue::VOBJ);
|
||||
res.pushKV("blocks", chainActive.Height());
|
||||
|
Loading…
x
Reference in New Issue
Block a user