mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 07:17:53 +00:00
listusernamespartial rpc
This commit is contained in:
parent
dc3b1b2c47
commit
8294e75672
@ -245,7 +245,8 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "getspammsg", &getspammsg, false, true },
|
||||
{ "follow", &follow, false, true },
|
||||
{ "unfollow", &unfollow, false, true },
|
||||
{ "getfollowing", &getfollowing, false, true },
|
||||
{ "getfollowing", &getfollowing, false, true },
|
||||
{ "listusernamespartial", &listusernamespartial, false, true },
|
||||
};
|
||||
|
||||
CRPCTable::CRPCTable()
|
||||
@ -1194,6 +1195,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
|
||||
if (strMethod == "getposts" && n > 1) ConvertTo<Array>(params[1]);
|
||||
if (strMethod == "follow" && n > 0) ConvertTo<Array>(params[0]);
|
||||
if (strMethod == "unfollow" && n > 0) ConvertTo<Array>(params[0]);
|
||||
if (strMethod == "listusernamespartial" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
@ -203,5 +203,6 @@ extern json_spirit::Value getspammsg(const json_spirit::Array& params, bool fHel
|
||||
extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value unfollow(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getfollowing(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value listusernamespartial(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
#endif
|
||||
|
@ -1239,3 +1239,40 @@ Value getfollowing(const Array& params, bool fHelp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Value listusernamespartial(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() != 2))
|
||||
throw runtime_error(
|
||||
"listusernamespartial <username_starts_with> <count>\n"
|
||||
"get list of usernames starting with");
|
||||
|
||||
string userStartsWith = params[0].get_str();
|
||||
size_t count = params[1].get_int();
|
||||
|
||||
set<string> retStrings;
|
||||
|
||||
for(CBlockIndex* pindex = pindexBest; pindex && retStrings.size() < count; pindex = pindex->pprev ) {
|
||||
CBlock block;
|
||||
if( !ReadBlockFromDisk(block, pindex) )
|
||||
continue;
|
||||
|
||||
BOOST_FOREACH(const CTransaction&tx, block.vtx) {
|
||||
if( !tx.IsSpamMessage() ) {
|
||||
string txUsername = tx.userName.ExtractSmallString();
|
||||
int toCompare = std::min( userStartsWith.size(), txUsername.size() );
|
||||
if( memcmp( txUsername.data(), userStartsWith.data(), toCompare ) == 0 )
|
||||
retStrings.insert( txUsername );
|
||||
if( retStrings.size() >= count )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Array ret;
|
||||
BOOST_FOREACH(string username, retStrings) {
|
||||
ret.push_back(username);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user