diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 36cf0171..a93ff3ca 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1258,6 +1258,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 1) ConvertTo(params[1]); if (strMethod == "unfollow" && n > 1) ConvertTo(params[1]); if (strMethod == "listusernamespartial" && n > 1) ConvertTo(params[1]); + if (strMethod == "listusernamespartial" && n > 2) ConvertTo(params[2]); return params; } diff --git a/src/twister.cpp b/src/twister.cpp index 89126023..1fd4d421 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1548,13 +1548,16 @@ Value getlasthave(const Array& params, bool fHelp) Value listusernamespartial(const Array& params, bool fHelp) { - if (fHelp || (params.size() != 2)) + if (fHelp || (params.size() < 2 || params.size() > 3)) throw runtime_error( - "listusernamespartial \n" + "listusernamespartial [exact_match]\n" "get list of usernames starting with"); string userStartsWith = params[0].get_str(); size_t count = params[1].get_int(); + bool exact_match = false; + if( params.size() > 2 ) + exact_match = params[2].get_bool(); set retStrings; @@ -1564,6 +1567,8 @@ Value listusernamespartial(const Array& params, bool fHelp) BOOST_FOREACH(const PAIRTYPE(CKeyID, CKeyMetadata)& item, pwalletMain->mapKeyMetadata) { LOCK(cs_twister); BOOST_FOREACH(const string &user, m_users[item.second.username].m_following) { + if( exact_match && userStartsWith.size() != user.size() ) + break; int toCompare = std::min( userStartsWith.size(), user.size() ); if( memcmp( user.data(), userStartsWith.data(), toCompare ) == 0 ) retStrings.insert( user ); @@ -1582,6 +1587,8 @@ Value listusernamespartial(const Array& params, bool fHelp) BOOST_FOREACH(const CTransaction&tx, block.vtx) { if( !tx.IsSpamMessage() ) { string txUsername = tx.userName.ExtractSmallString(); + if( exact_match && userStartsWith.size() != txUsername.size() ) + break; int toCompare = std::min( userStartsWith.size(), txUsername.size() ); if( memcmp( txUsername.data(), userStartsWith.data(), toCompare ) == 0 ) retStrings.insert( txUsername );