From 7813f3157b4f9f995c52bacad4aeea1bb86f36e5 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Thu, 19 Mar 2015 17:16:35 -0400 Subject: [PATCH] show depth, whether spent, and whether in ncc trie for listnameclaims --- src/ncctrie.cpp | 21 +++++++++++++++++++++ src/ncctrie.h | 3 ++- src/rpcwallet.cpp | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ncctrie.cpp b/src/ncctrie.cpp index 25f25472b..4b4699b9f 100644 --- a/src/ncctrie.cpp +++ b/src/ncctrie.cpp @@ -87,6 +87,14 @@ bool CNCCTrieNode::getBestValue(CNodeValue& value) const } } +bool CNCCTrieNode::haveValue(const uint256& txhash, uint32_t nOut) const +{ + for (std::vector::const_iterator itval = values.begin(); itval != values.end(); ++itval) + if (itval->txhash == txhash && itval->nOut == nOut) + return true; + return false; +} + uint256 CNCCTrie::getMerkleHash() { return root.hash; @@ -102,6 +110,19 @@ bool CNCCTrie::queueEmpty() const return valueQueue.empty(); } +bool CNCCTrie::haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const +{ + const CNCCTrieNode* current = &root; + for (std::string::const_iterator itname = name.begin(); itname != name.end(); ++itname) + { + nodeMapType::const_iterator itchildren = current->children.find(*itname); + if (itchildren == current->children.end()) + return false; + current = itchildren->second; + } + return current->haveValue(txhash, nOut); +} + bool CNCCTrie::recursiveDumpToJSON(const std::string& name, const CNCCTrieNode* current, json_spirit::Array& ret) const { using namespace json_spirit; diff --git a/src/ncctrie.h b/src/ncctrie.h index f5c7d285c..f95af3231 100644 --- a/src/ncctrie.h +++ b/src/ncctrie.h @@ -88,7 +88,7 @@ public: bool removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val, bool * fChanged = NULL); bool getBestValue(CNodeValue& val) const; bool empty() const {return children.empty() && values.empty();} - + bool haveValue(const uint256& txhash, uint32_t nOut) const; ADD_SERIALIZE_METHODS; template @@ -159,6 +159,7 @@ public: bool getInfoForName(const std::string& name, CNodeValue& val) const; int nCurrentHeight; bool queueEmpty() const; + bool haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const; friend class CNCCTrieCache; private: bool update(nodeCacheType& cache, hashMapType& hashes, const uint256& hashBlock, valueQueueType& queueCache, int nNewHeight); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index ec0179700..b9c6f5cd7 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -610,6 +610,9 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept entry.push_back(Pair("amount", ValueFromAmount(s.amount))); entry.push_back(Pair("vout", s.vout)); entry.push_back(Pair("fee", ValueFromAmount(nFee))); + entry.push_back(Pair("confirmations", wtx.GetDepthInMainChain())); + entry.push_back(Pair("is spent", pwalletMain->IsSpent(wtx.GetHash(), s.vout))); + entry.push_back(Pair("is in ncc trie", pnccTrie->haveClaim(sName, wtx.GetHash(), s.vout))); ret.push_back(entry); } }