From e22b05a951e53a91c85c01f20a0dbae01624812f Mon Sep 17 00:00:00 2001 From: Just Wonder Date: Sun, 14 Jun 2020 19:43:14 -0700 Subject: [PATCH] Added associated namespaces initialized by us. --- src/keva/common.cpp | 8 +++--- src/keva/common.h | 4 +-- src/rpc/rpckeva_nonwallet.cpp | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/keva/common.cpp b/src/keva/common.cpp index 145a3e3a1..56d729752 100644 --- a/src/keva/common.cpp +++ b/src/keva/common.cpp @@ -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; } diff --git a/src/keva/common.h b/src/keva/common.h index 69bdf19a7..9f67ae7cf 100644 --- a/src/keva/common.h +++ b/src/keva/common.h @@ -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 diff --git a/src/rpc/rpckeva_nonwallet.cpp b/src/rpc/rpckeva_nonwallet.cpp index 5afe27397..95feb27e5 100644 --- a/src/rpc/rpckeva_nonwallet.cpp +++ b/src/rpc/rpckeva_nonwallet.cpp @@ -418,6 +418,7 @@ UniValue keva_show_group(const JSONRPCRequest& request) valtype nsDisplayKey = ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY); std::unique_ptr 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 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());