/* undo is set if the change is due to disconnecting blocks / going back in time. The ordinary case (!undo) means that we update the name normally, going forward in time. This is important for keeping track of the name history. */ void CCoinsViewCache::SetName(const valtype &name, const CNameData& data, bool undo) { CNameData oldData; if (GetName(name, oldData)) { cacheNames.removeExpireIndex(name, oldData.getHeight()); /* Update the name history. If we are undoing, we expect that the top history item matches the data being set now. If we are not undoing, push the overwritten data onto the history stack. Note that we only have to do this if the name already existed in the database. Otherwise, no special action is required for the name history. */ if (fNameHistory) { CNameHistory history; if (!GetNameHistory(name, history)) { /* Ensure that the history stack is indeed (still) empty and was not modified by the failing GetNameHistory call. */ assert(history.empty()); } if (undo) history.pop(data); else history.push(oldData); cacheNames.setHistory(name, history); } } else assert (!undo); cacheNames.set(name, data); cacheNames.addExpireIndex(name, data.getHeight()); }
UniValue name_history (const UniValue& params, bool fHelp) { if (fHelp || params.size () != 1) throw std::runtime_error ( "name_history \"name\"\n" "\nLook up the current and all past data for the given name." " -namehistory must be enabled.\n" "\nArguments:\n" "1. \"name\" (string, required) the name to query for\n" "\nResult:\n" "[\n" + getNameInfoHelp (" ", ",") + " ...\n" "]\n" "\nExamples:\n" + HelpExampleCli ("name_history", "\"myname\"") + HelpExampleRpc ("name_history", "\"myname\"") ); if (!fNameHistory) throw std::runtime_error ("-namehistory is not enabled"); if (IsInitialBlockDownload ()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Namecoin is downloading blocks..."); const std::string nameStr = params[0].get_str (); const valtype name = ValtypeFromString (nameStr); CNameData data; CNameHistory history; { LOCK (cs_main); if (!pcoinsTip->GetName (name, data)) { std::ostringstream msg; msg << "name not found: '" << nameStr << "'"; throw JSONRPCError (RPC_WALLET_ERROR, msg.str ()); } if (!pcoinsTip->GetNameHistory (name, history)) assert (history.empty ()); } UniValue res(UniValue::VARR); BOOST_FOREACH (const CNameData& entry, history.getData ()) res.push_back (getNameInfo (name, entry)); res.push_back (getNameInfo (name, data)); return res; }
void CCoinsViewCache::DeleteName(const valtype &name) { CNameData oldData; if (GetName(name, oldData)) cacheNames.removeExpireIndex(name, oldData.getHeight()); else assert(false); if (fNameHistory) { /* When deleting a name, the history should already be clean. */ CNameHistory history; assert (!GetNameHistory(name, history) || history.empty()); } cacheNames.remove(name); }