diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index ed44faea..8e97fd21 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -279,6 +279,7 @@ static const CRPCCommand vRPCCommands[] = { "newgroupinvite", &newgroupinvite, false, true, false }, { "newgroupdescription", &newgroupdescription, false, true, false }, { "leavegroup", &leavegroup, false, true, false }, + { "getpieceavailability", &getpieceavailability, false, true, true }, }; CRPCTable::CRPCTable() @@ -1344,6 +1345,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 1) ConvertTo(params[1]); if (strMethod == "newgroupinvite" && n > 3) ConvertTo(params[3]); if (strMethod == "newgroupdescription" && n > 1) ConvertTo(params[1]); + if (strMethod == "getpieceavailability" && n > 1) ConvertTo(params[1]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 128a1bb3..e589ea77 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -232,5 +232,6 @@ extern json_spirit::Value getgroupinfo(const json_spirit::Array& params, bool fH extern json_spirit::Value newgroupinvite(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value newgroupdescription(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value leavegroup(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getpieceavailability(const json_spirit::Array& params, bool fHelp); #endif diff --git a/src/twister.cpp b/src/twister.cpp index 2d39cfbf..765133e8 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -3806,3 +3806,21 @@ Value leavegroup(const Array& params, bool fHelp) } +Value getpieceavailability(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 2 ) + throw runtime_error( + "getpieceavailability '\n" + "Get piece availability (peer count for this piece)"); + + EnsureWalletIsUnlocked(); + + string strUsername = params[0].get_str(); + int k = params[1].get_int(); + + torrent_handle h = getTorrentUser(strUsername); + std::vector avail; + h.piece_availability(avail); + + return avail.size() > k ? avail.at(k) : 0; +}