wallet-rpc: filter getbalance response by address index

This commit is contained in:
stoffu 2018-07-23 23:58:31 +09:00
parent 702a41034d
commit 9127a8b79f
No known key found for this signature in database
GPG key ID: 41DAB8343A9EC012
2 changed files with 13 additions and 5 deletions

View file

@ -355,14 +355,20 @@ namespace tools
std::map<uint32_t, uint64_t> unlocked_balance_per_subaddress = m_wallet->unlocked_balance_per_subaddress(req.account_index); std::map<uint32_t, uint64_t> unlocked_balance_per_subaddress = m_wallet->unlocked_balance_per_subaddress(req.account_index);
std::vector<tools::wallet2::transfer_details> transfers; std::vector<tools::wallet2::transfer_details> transfers;
m_wallet->get_transfers(transfers); m_wallet->get_transfers(transfers);
for (const auto& i : balance_per_subaddress) std::set<uint32_t> address_indices = req.address_indices;
if (address_indices.empty())
{
for (const auto& i : balance_per_subaddress)
address_indices.insert(i.first);
}
for (uint32_t i : address_indices)
{ {
wallet_rpc::COMMAND_RPC_GET_BALANCE::per_subaddress_info info; wallet_rpc::COMMAND_RPC_GET_BALANCE::per_subaddress_info info;
info.address_index = i.first; info.address_index = i;
cryptonote::subaddress_index index = {req.account_index, info.address_index}; cryptonote::subaddress_index index = {req.account_index, info.address_index};
info.address = m_wallet->get_subaddress_as_str(index); info.address = m_wallet->get_subaddress_as_str(index);
info.balance = i.second; info.balance = balance_per_subaddress[i];
info.unlocked_balance = unlocked_balance_per_subaddress[i.first]; info.unlocked_balance = unlocked_balance_per_subaddress[i];
info.label = m_wallet->get_subaddress_label(index); info.label = m_wallet->get_subaddress_label(index);
info.num_unspent_outputs = std::count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; }); info.num_unspent_outputs = std::count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; });
res.per_subaddress.push_back(info); res.per_subaddress.push_back(info);

View file

@ -47,7 +47,7 @@
// advance which version they will stop working with // advance which version they will stop working with
// Don't go over 32767 for any of these // Don't go over 32767 for any of these
#define WALLET_RPC_VERSION_MAJOR 1 #define WALLET_RPC_VERSION_MAJOR 1
#define WALLET_RPC_VERSION_MINOR 1 #define WALLET_RPC_VERSION_MINOR 2
#define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor)) #define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR) #define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
namespace tools namespace tools
@ -62,8 +62,10 @@ namespace wallet_rpc
struct request struct request
{ {
uint32_t account_index; uint32_t account_index;
std::set<uint32_t> address_indices;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(account_index) KV_SERIALIZE(account_index)
KV_SERIALIZE(address_indices)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };