Browse Source

Handled the cases that the namespace has been transferred to an address of different wallet.

issue_19
Just Wonder 4 years ago
parent
commit
c07b4d21c3
  1. 32
      src/wallet/rpckeva.cpp

32
src/wallet/rpckeva.cpp

@ -131,7 +131,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
ObserveSafeMode (); ObserveSafeMode ();
std::map<std::string, std::string> mapObjects; std::map<std::string, std::tuple<int, bool, std::string>> mapObjects;
{ {
LOCK2 (cs_main, pwallet->cs_wallet); LOCK2 (cs_main, pwallet->cs_wallet);
for (const auto& item : pwallet->mapWallet) { for (const auto& item : pwallet->mapWallet) {
@ -170,21 +170,35 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
continue; continue;
} }
const bool mine = IsMine(*pwallet, kevaOp.getAddress());
CKevaData data; CKevaData data;
if (mine && pcoinsTip->GetNamespace(nameSpace, data)) { if (pcoinsTip->GetNamespace(nameSpace, data)) {
std::string displayName = ValtypeToString(data.getValue()); const bool mine = IsMine(*pwallet, kevaOp.getAddress());
mapObjects[nameSpaceStr] = displayName; 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); UniValue res(UniValue::VARR);
for (const auto& item : mapObjects) { for (const auto& item : mapObjects) {
UniValue obj(UniValue::VOBJ); if (std::get<1>(item.second)) {
obj.pushKV("namespaceId", item.first); // Only show our namespaces.
obj.pushKV("displayName", item.second); UniValue obj(UniValue::VOBJ);
res.push_back(obj); obj.pushKV("namespaceId", item.first);
obj.pushKV("displayName", std::get<2>(item.second));
res.push_back(obj);
}
} }
{ {

Loading…
Cancel
Save