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. 24
      src/wallet/rpckeva.cpp

24
src/wallet/rpckeva.cpp

@ -131,7 +131,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request) @@ -131,7 +131,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
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);
for (const auto& item : pwallet->mapWallet) {
@ -170,22 +170,36 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request) @@ -170,22 +170,36 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
continue;
}
const bool mine = IsMine(*pwallet, kevaOp.getAddress());
CKevaData data;
if (mine && pcoinsTip->GetNamespace(nameSpace, data)) {
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] = displayName;
mapObjects[nameSpaceStr] = std::make_tuple(depth, mine, displayName);
}
}
}
}
}
UniValue res(UniValue::VARR);
for (const auto& item : mapObjects) {
if (std::get<1>(item.second)) {
// Only show our namespaces.
UniValue obj(UniValue::VOBJ);
obj.pushKV("namespaceId", item.first);
obj.pushKV("displayName", item.second);
obj.pushKV("displayName", std::get<2>(item.second));
res.push_back(obj);
}
}
{
LOCK (mempool.cs);

Loading…
Cancel
Save