From c07b4d21c3e4bfb3b9a043e063215eade1f54499 Mon Sep 17 00:00:00 2001 From: Just Wonder Date: Tue, 8 Sep 2020 10:25:56 -0700 Subject: [PATCH] Handled the cases that the namespace has been transferred to an address of different wallet. --- src/wallet/rpckeva.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/wallet/rpckeva.cpp b/src/wallet/rpckeva.cpp index 281600c69..4613471d8 100644 --- a/src/wallet/rpckeva.cpp +++ b/src/wallet/rpckeva.cpp @@ -131,7 +131,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request) ObserveSafeMode (); - std::map mapObjects; + std::map> mapObjects; { LOCK2 (cs_main, pwallet->cs_wallet); for (const auto& item : pwallet->mapWallet) { @@ -170,21 +170,35 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request) continue; } - const bool mine = IsMine(*pwallet, kevaOp.getAddress()); CKevaData data; - if (mine && pcoinsTip->GetNamespace(nameSpace, data)) { - std::string displayName = ValtypeToString(data.getValue()); - mapObjects[nameSpaceStr] = displayName; + if (pcoinsTip->GetNamespace(nameSpace, data)) { + const bool mine = IsMine(*pwallet, kevaOp.getAddress()); + auto nsIter = mapObjects.find(nameSpaceStr); + if (nsIter == mapObjects.end() ) { + std::string displayName = ValtypeToString(data.getValue()); + mapObjects[nameSpaceStr] = std::make_tuple(depth, mine, displayName); + } else { + // Always use the lastest one. The address may have been + // transferred to a different wallet. + const int curDepth = std::get<0>(nsIter->second); + if (depth < curDepth) { + std::string displayName = ValtypeToString(data.getValue()); + mapObjects[nameSpaceStr] = std::make_tuple(depth, mine, displayName); + } + } } } } UniValue res(UniValue::VARR); for (const auto& item : mapObjects) { - UniValue obj(UniValue::VOBJ); - obj.pushKV("namespaceId", item.first); - obj.pushKV("displayName", item.second); - res.push_back(obj); + if (std::get<1>(item.second)) { + // Only show our namespaces. + UniValue obj(UniValue::VOBJ); + obj.pushKV("namespaceId", item.first); + obj.pushKV("displayName", std::get<2>(item.second)); + res.push_back(obj); + } } {