From 45fecd334e3481c57c13dd4fe8a52ffc1b27d461 Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Thu, 1 Nov 2018 14:35:55 -0700 Subject: [PATCH] Changed HasNamespace to GetNamespace. Fixed BackedView error. Started working on keva_put. --- src/coins.cpp | 21 +++++++++++++++------ src/coins.h | 8 ++++---- src/keva/common.cpp | 8 +++----- src/keva/common.h | 5 +---- src/txdb.cpp | 5 +++++ src/txdb.h | 1 + src/wallet/rpckeva.cpp | 42 ++++++++++++------------------------------ 7 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 20863f375..778602449 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -10,7 +10,7 @@ bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; } uint256 CCoinsView::GetBestBlock() const { return uint256(); } std::vector CCoinsView::GetHeadBlocks() const { return std::vector(); } -bool CCoinsView::HasNamespace(const valtype &nameSpace) const { return false; } +bool CCoinsView::GetNamespace(const valtype &nameSpace, CKevaData &data) const { return false; } bool CCoinsView::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const { return false; } bool CCoinsView::GetNamesForHeight(unsigned nHeight, std::set& names) const { return false; } CNameIterator* CCoinsView::IterateNames() const { assert (false); } @@ -29,9 +29,15 @@ bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { re bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); } uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); } std::vector CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); } -bool CCoinsViewBacked::HasNamespace(const valtype &nameSpace) const { return false; } -bool CCoinsViewBacked::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const { return false; } -bool CCoinsViewBacked::GetNamesForHeight(unsigned nHeight, std::set& names) const { return false; } +bool CCoinsViewBacked::GetNamespace(const valtype &nameSpace, CKevaData &data) const { + return base->GetNamespace(nameSpace, data); +} +bool CCoinsViewBacked::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const { + return base->GetName(nameSpace, key, data); +} +bool CCoinsViewBacked::GetNamesForHeight(unsigned nHeight, std::set& names) const { + return base->GetNamesForHeight(nHeight, names); +} CNameIterator* CCoinsViewBacked::IterateNames() const { return base->IterateNames(); } void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; } bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const CKevaCache &names) { @@ -154,8 +160,11 @@ void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) { hashBlock = hashBlockIn; } -bool CCoinsViewCache::HasNamespace(const valtype &nameSpace) const { - return cacheNames.hasNamespace(nameSpace); +bool CCoinsViewCache::GetNamespace(const valtype &nameSpace, CKevaData &data) const { + if (cacheNames.GetNamespace(nameSpace, data)) { + return true; + } + return base->GetNamespace(nameSpace, data); } bool CCoinsViewCache::GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const { diff --git a/src/coins.h b/src/coins.h index 166cc6650..5e0f178e2 100644 --- a/src/coins.h +++ b/src/coins.h @@ -165,7 +165,7 @@ public: virtual std::vector GetHeadBlocks() const; // Check if a namespace exists. - virtual bool HasNamespace(const valtype& nameSpace) const; + virtual bool GetNamespace(const valtype& nameSpace, CKevaData& data) const; // Get a name (if it exists) virtual bool GetName(const valtype& nameSpace, const valtype& key, CKevaData& data) const; @@ -206,7 +206,7 @@ public: bool HaveCoin(const COutPoint &outpoint) const override; uint256 GetBestBlock() const override; std::vector GetHeadBlocks() const override; - bool HasNamespace(const valtype& nameSpace) const override; + bool GetNamespace(const valtype& nameSpace, CKevaData& data) const override; bool GetName(const valtype& nameSpace, const valtype& key, CKevaData& data) const override; bool GetNamesForHeight(unsigned nHeight, std::set& names) const override; CNameIterator* IterateNames() const override; @@ -248,8 +248,8 @@ public: bool HaveCoin(const COutPoint &outpoint) const override; uint256 GetBestBlock() const override; void SetBestBlock(const uint256 &hashBlock); - bool HasNamespace(const valtype &nameSpace) const override; - bool GetName(const valtype &nameSpace, const valtype &key, CKevaData &data) const override; + bool GetNamespace(const valtype &nameSpace, CKevaData& data) const override; + bool GetName(const valtype &nameSpace, const valtype &key, CKevaData& data) const override; bool GetNamesForHeight(unsigned nHeight, std::set& names) const override; CNameIterator* IterateNames() const override; bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const CKevaCache &names) override; diff --git a/src/keva/common.cpp b/src/keva/common.cpp index a9651ed67..2e7a4bf79 100644 --- a/src/keva/common.cpp +++ b/src/keva/common.cpp @@ -194,10 +194,10 @@ CKevaCache::get(const valtype& nameSpace, const valtype& key, CKevaData& data) c return true; } -bool CKevaCache::hasNamespace(const valtype& nameSpace) const +bool +CKevaCache::GetNamespace(const valtype& nameSpace, CKevaData& data) const { - auto ni = namespaces.find(nameSpace); - return (ni != namespaces.end()); + return get(nameSpace, ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY), data); } void @@ -215,8 +215,6 @@ CKevaCache::set(const valtype& nameSpace, const valtype& key, const CKevaData& d ei->second = data; else entries.insert (std::make_pair(name, data)); - - namespaces.insert(nameSpace); } void diff --git a/src/keva/common.h b/src/keva/common.h index eaaa62896..52df9fdc3 100644 --- a/src/keva/common.h +++ b/src/keva/common.h @@ -379,7 +379,6 @@ public: * by the unit tests. */ typedef std::map, CKevaData, NameComparator> EntryMap; - typedef std::set NamespaceSet; private: @@ -387,8 +386,6 @@ private: EntryMap entries; /** Deleted names. */ std::set deleted; - /** Namespaces */ - NamespaceSet namespaces; #if 0 /** @@ -455,7 +452,7 @@ public: in entries, and doesn't care about deleted data. */ bool get(const valtype& nameSpace, const valtype& key, CKevaData& data) const; - bool hasNamespace(const valtype& nameSpace) const; + bool GetNamespace(const valtype& nameSpace, CKevaData& data) const; /* Insert (or update) a name. If it is marked as "deleted", this also removes the "deleted" mark. */ diff --git a/src/txdb.cpp b/src/txdb.cpp index 0ce168a7b..3e86f92c2 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -13,6 +13,7 @@ #include #include #include +#include