diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index e0bbfeb8..66fce69a 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -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 1) ConvertTo(params[1]); if (strMethod == "follow" && n > 0) ConvertTo(params[0]); if (strMethod == "unfollow" && n > 0) ConvertTo(params[0]); + if (strMethod == "listusernamespartial" && n > 1) ConvertTo(params[1]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index efe4d6fa..4fb81563 100644 --- a/src/bitcoinrpc.h +++ b/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 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 diff --git a/src/twister.cpp b/src/twister.cpp index 53e72c3b..aa4f42fc 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -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 \n" + "get list of usernames starting with"); + + string userStartsWith = params[0].get_str(); + size_t count = params[1].get_int(); + + set 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; +} +