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; }
// FUNCTION CALL EXPRESSION. Take care of PRINT/READ functions bool SuperastCPP::TraverseCallExpr(clang::CallExpr* call) { // Get call declaration auto decl = llvm::dyn_cast<clang::FunctionDecl>(call->getCalleeDecl()); if (!decl) { std::cerr << "UNKNOWN FUNCTION_CALL\n"; return true; } const std::string functionName = decl->getNameInfo().getAsString(); rapidjson::Value functionCallValue(rapidjson::kObjectType); addId(functionCallValue); addPos(functionCallValue, call); functionCallValue.AddMember("type", "function-call", allocator); rapidjson::Value nameValue(functionName.c_str(), functionName.size(), allocator); functionCallValue.AddMember("name", nameValue, allocator); rapidjson::Value argumentsValue(rapidjson::kArrayType); for (auto arg : call->arguments()) { TRY_TO(TraverseStmt(arg)); argumentsValue.PushBack(sonValue, allocator); } functionCallValue.AddMember("arguments", argumentsValue, allocator); sonValue = functionCallValue; return true; }
json_spirit::Value name_scan (const json_spirit::Array& params, bool fHelp) { if (fHelp || params.size () > 2) throw std::runtime_error ( "name_scan (\"start\" (\"count\"))\n" "\nList names in the database.\n" "\nArguments:\n" "1. \"start\" (string, optional) skip initially to this name\n" "2. \"count\" (numeric, optional, default=500) stop after this many names\n" "\nResult:\n" "[\n" + getNameInfoHelp (" ", ",") + " ...\n" "]\n" "\nExamples:\n" + HelpExampleCli ("name_scan", "") + HelpExampleCli ("name_scan", "\"d/abc\"") + HelpExampleCli ("name_scan", "\"d/abc\" 10") + HelpExampleRpc ("name_scan", "\"d/abc\"") ); if (IsInitialBlockDownload ()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Namecoin is downloading blocks..."); valtype start; if (params.size () >= 1) start = ValtypeFromString (params[0].get_str ()); int count = 500; if (params.size () >= 2) count = params[1].get_int (); json_spirit::Array res; if (count <= 0) return res; { LOCK (cs_main); pcoinsTip->Flush (); valtype name; CNameData data; for (std::auto_ptr<CNameIterator> iter(pcoinsTip->IterateNames (start)); count > 0 && iter->next (name, data); --count) res.push_back (getNameInfo (name, data)); } return res; }
UniValue name_show (const UniValue& params, bool fHelp) { if (fHelp || params.size () != 1) throw std::runtime_error ( "name_show \"name\"\n" "\nLook up the current data for the given name." " Fails if the name doesn't exist.\n" "\nArguments:\n" "1. \"name\" (string, required) the name to query for\n" "\nResult:\n" + getNameInfoHelp ("", "") + "\nExamples:\n" + HelpExampleCli ("name_show", "\"myname\"") + HelpExampleRpc ("name_show", "\"myname\"") ); 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; { LOCK (cs_main); if (!pcoinsTip->GetName (name, data)) { std::ostringstream msg; msg << "name not found: '" << nameStr << "'"; throw JSONRPCError (RPC_WALLET_ERROR, msg.str ()); } } return getNameInfo (name, data); }
/** * Return name info object for a CNameData object. * @param name The name. * @param data The name's data. * @return A JSON object to return. */ UniValue getNameInfo (const valtype& name, const CNameData& data) { return getNameInfo (name, data.getValue (), data.getUpdateOutpoint (), data.getAddress (), data.getHeight ()); }
UniValue name_filter (const UniValue& params, bool fHelp) { if (fHelp || params.size () > 5) throw std::runtime_error ( "name_filter (\"regexp\" (\"maxage\" (\"from\" (\"nb\" (\"stat\")))))\n" "\nScan and list names matching a regular expression.\n" "\nArguments:\n" "1. \"regexp\" (string, optional) filter names with this regexp\n" "2. \"maxage\" (numeric, optional, default=36000) only consider names updated in the last \"maxage\" blocks; 0 means all names\n" "3. \"from\" (numeric, optional, default=0) return from this position onward; index starts at 0\n" "4. \"nb\" (numeric, optional, default=0) return only \"nb\" entries; 0 means all\n" "5. \"stat\" (string, optional) if set to the string \"stat\", print statistics instead of returning the names\n" "\nResult:\n" "[\n" + getNameInfoHelp (" ", ",") + " ...\n" "]\n" "\nExamples:\n" + HelpExampleCli ("name_filter", "\"\" 5") + HelpExampleCli ("name_filter", "\"^id/\"") + HelpExampleCli ("name_filter", "\"^id/\" 36000 0 0 \"stat\"") + HelpExampleRpc ("name_scan", "\"^d/\"") ); if (IsInitialBlockDownload ()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Namecoin is downloading blocks..."); /* ********************** */ /* Interpret parameters. */ bool haveRegexp(false); boost::xpressive::sregex regexp; int maxage(36000), from(0), nb(0); bool stats(false); if (params.size () >= 1) { haveRegexp = true; regexp = boost::xpressive::sregex::compile (params[0].get_str ()); } if (params.size () >= 2) maxage = params[1].get_int (); if (maxage < 0) throw JSONRPCError (RPC_INVALID_PARAMETER, "'maxage' should be non-negative"); if (params.size () >= 3) from = params[2].get_int (); if (from < 0) throw JSONRPCError (RPC_INVALID_PARAMETER, "'from' should be non-negative"); if (params.size () >= 4) nb = params[3].get_int (); if (nb < 0) throw JSONRPCError (RPC_INVALID_PARAMETER, "'nb' should be non-negative"); if (params.size () >= 5) { if (params[4].get_str () != "stat") throw JSONRPCError (RPC_INVALID_PARAMETER, "fifth argument must be the literal string 'stat'"); stats = true; } /* ******************************************* */ /* Iterate over names to build up the result. */ UniValue names(UniValue::VARR); unsigned count(0); LOCK (cs_main); valtype name; CNameData data; std::unique_ptr<CNameIterator> iter(pcoinsTip->IterateNames ()); while (iter->next (name, data)) { const int age = chainActive.Height () - data.getHeight (); assert (age >= 0); if (maxage != 0 && age >= maxage) continue; if (haveRegexp) { const std::string nameStr = ValtypeToString (name); boost::xpressive::smatch matches; if (!boost::xpressive::regex_search (nameStr, matches, regexp)) continue; } if (from > 0) { --from; continue; } assert (from == 0); if (stats) ++count; else names.push_back (getNameInfo (name, data)); if (nb > 0) { --nb; if (nb == 0) break; } } /* ********************************************************** */ /* Return the correct result (take stats mode into account). */ if (stats) { UniValue res(UniValue::VOBJ); res.push_back (Pair ("blocks", chainActive.Height ())); res.push_back (Pair ("count", static_cast<int> (count))); return res; } return names; }
bool SuperastCPP::TraverseCXXOperatorCallExpr(clang::CXXOperatorCallExpr* operatorCallExpr) { // IF THERE IS A PRINT auto decl = llvm::dyn_cast<clang::FunctionDecl>(operatorCallExpr->getCalleeDecl()); if (!decl) { std::cerr << "Unknown function in CXXOperatorCallExpr" << std::endl; return true; } const std::string functionName = decl->getNameInfo().getAsString(); if (functionName == PRINT_NAME || functionName == READ_NAME) { bool isFirst = false; if (!iofunctionStarted) { isFirst = true; iofunctionStarted = true; } rapidjson::Value arrayValue(rapidjson::kArrayType); for (unsigned i = 0; i < operatorCallExpr->getNumArgs(); ++i) { TRY_TO(TraverseStmt(operatorCallExpr->getArg(i))); if (i == 0) { // If sonValue is not an array, is because it reached the begin of // call, which is the cout/cerr/stream class if (sonValue.IsArray()) { arrayValue = sonValue; } } else { arrayValue.PushBack(sonValue, allocator); } } if (!isFirst) { sonValue = arrayValue; } else { iofunctionStarted = false; rapidjson::Value functionValue(rapidjson::kObjectType); addId(functionValue); addPos(functionValue, operatorCallExpr); functionValue.AddMember("type", "function-call", allocator); if (functionName == PRINT_NAME) functionValue.AddMember("name", "print", allocator); else functionValue.AddMember("name", "read", allocator); functionValue.AddMember("arguments", arrayValue, allocator); sonValue = functionValue; } } else if (functionName == VECTOR_POS_NAME) { // Operator [] TRY_TO(TraverseStmt(operatorCallExpr->getArg(0))); rapidjson::Value leftValue(rapidjson::kObjectType); leftValue = sonValue; TRY_TO(TraverseStmt(operatorCallExpr->getArg(1))); rapidjson::Value rightValue(rapidjson::kObjectType); rightValue = sonValue; sonValue = createBinOpValue("[]", leftValue, rightValue); } else { std::cerr << "Operator call not defined: " << functionName << std::endl; } return true; }