extended api for wallet
This commit is contained in:
parent
7886f7cd3d
commit
c0621eb2f2
5 changed files with 44 additions and 13 deletions
|
|
@ -768,7 +768,7 @@ bool simple_wallet::list_recent_transfers(const std::vector<std::string>& args)
|
|||
std::vector<tools::wallet_public::wallet_transfer_info> recent;
|
||||
uint64_t total = 0;
|
||||
uint64_t last_index = 0;
|
||||
m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false);
|
||||
m_wallet->get_recent_transfers_history(recent, std::stoll(args[0]), std::stoll(args[1]), total, last_index, false, false);
|
||||
m_wallet->get_unconfirmed_transfers(unconfirmed, false);
|
||||
//workaround for missed fee
|
||||
|
||||
|
|
|
|||
|
|
@ -3192,29 +3192,49 @@ uint64_t wallet2::get_transfer_entries_count()
|
|||
return m_transfers.size();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs)
|
||||
|
||||
template<typename callback_t, typename iterator_t>
|
||||
bool enum_container(iterator_t it_begin, iterator_t it_end, callback_t cb)
|
||||
{
|
||||
for (iterator_t it = it_begin; it != it_end; it++)
|
||||
{
|
||||
if (!cb(*it, it - it_begin))
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs, bool start_from_end)
|
||||
{
|
||||
if (!count || offset >= m_transfer_history.size())
|
||||
return;
|
||||
|
||||
for (auto it = m_transfer_history.rbegin() + offset; it != m_transfer_history.rend(); it++)
|
||||
{
|
||||
auto cb = [&](wallet_public::wallet_transfer_info& wti, size_t local_offset) {
|
||||
|
||||
if (exclude_mining_txs)
|
||||
{
|
||||
if(currency::is_coinbase(it->tx))
|
||||
continue;
|
||||
if (currency::is_coinbase(wti.tx))
|
||||
return true;
|
||||
}
|
||||
trs.push_back(*it);
|
||||
trs.push_back(wti);
|
||||
load_wallet_transfer_info_flags(trs.back());
|
||||
last_item_index = it - m_transfer_history.rbegin();
|
||||
last_item_index = offset + local_offset;
|
||||
trs.back().transfer_internal_index = last_item_index;
|
||||
|
||||
|
||||
if (trs.size() >= count)
|
||||
{
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if(start_from_end)
|
||||
enum_container(m_transfer_history.rbegin() + offset, m_transfer_history.rend(), cb);
|
||||
else
|
||||
enum_container(m_transfer_history.begin() + offset, m_transfer_history.end(), cb);
|
||||
|
||||
total = m_transfer_history.size();
|
||||
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id)
|
||||
|
|
|
|||
|
|
@ -509,7 +509,7 @@ namespace tools
|
|||
currency::account_base& get_account() { return m_account; }
|
||||
const currency::account_base& get_account() const { return m_account; }
|
||||
|
||||
void get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs = false);
|
||||
void get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs = false, bool start_from_end = true);
|
||||
uint64_t get_recent_transfers_total_count();
|
||||
uint64_t get_transfer_entries_count();
|
||||
void get_unconfirmed_transfers(std::vector<wallet_public::wallet_transfer_info>& trs, bool exclude_mining_txs = false);
|
||||
|
|
|
|||
|
|
@ -318,6 +318,10 @@ namespace wallet_public
|
|||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
#define ORDER_FROM_BEGIN_TO_END "FROM_BEGIN_TO_END"
|
||||
#define ORDER_FROM_FROM_END_TO_BEGIN "FROM_END_TO_BEGIN"
|
||||
|
||||
struct COMMAND_RPC_GET_RECENT_TXS_AND_INFO
|
||||
{
|
||||
struct request
|
||||
|
|
@ -338,12 +342,14 @@ namespace wallet_public
|
|||
*/
|
||||
bool update_provision_info;
|
||||
bool exclude_mining_txs;
|
||||
std::string order; // "FROM_BEGIN_TO_END" or "FROM_END_TO_BEGIN"
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(offset)
|
||||
KV_SERIALIZE(count)
|
||||
KV_SERIALIZE(update_provision_info)
|
||||
KV_SERIALIZE(exclude_mining_txs)
|
||||
KV_SERIALIZE(order)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -252,7 +252,12 @@ namespace tools
|
|||
if (req.offset == 0)
|
||||
m_wallet.get_unconfirmed_transfers(res.transfers, req.exclude_mining_txs);
|
||||
|
||||
m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs);
|
||||
bool start_from_end = true;
|
||||
if (req.order == ORDER_FROM_BEGIN_TO_END)
|
||||
{
|
||||
start_from_end = false;
|
||||
}
|
||||
m_wallet.get_recent_transfers_history(res.transfers, req.offset, req.count, res.total_transfers, res.last_item_index, req.exclude_mining_txs, start_from_end);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue