Browse Source

listusernamespartial rpc

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
8294e75672
  1. 2
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 37
      src/twister.cpp

2
src/bitcoinrpc.cpp

@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] =
{ "follow", &follow, false, true }, { "follow", &follow, false, true },
{ "unfollow", &unfollow, false, true }, { "unfollow", &unfollow, false, true },
{ "getfollowing", &getfollowing, false, true }, { "getfollowing", &getfollowing, false, true },
{ "listusernamespartial", &listusernamespartial, false, true },
}; };
CRPCTable::CRPCTable() 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 == "getposts" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "follow" && n > 0) ConvertTo<Array>(params[0]); if (strMethod == "follow" && n > 0) ConvertTo<Array>(params[0]);
if (strMethod == "unfollow" && 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; return params;
} }

1
src/bitcoinrpc.h

@ -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 follow(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value unfollow(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 getfollowing(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listusernamespartial(const json_spirit::Array& params, bool fHelp);
#endif #endif

37
src/twister.cpp

@ -1239,3 +1239,40 @@ Value getfollowing(const Array& params, bool fHelp)
return ret; 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…
Cancel
Save