Merge pull request #214

87839cd Allow get_bulk_payments to return all payments regardless of payment ID (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2015-01-15 13:59:37 +02:00
commit 580e003357
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
3 changed files with 45 additions and 12 deletions

View file

@ -227,13 +227,16 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
} }
tx_extra_nonce extra_nonce; tx_extra_nonce extra_nonce;
crypto::hash payment_id = null_hash;
if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce)) if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
{ {
crypto::hash payment_id;
if(get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id)) if(get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
{ {
// We got a payment ID to go with this tx
}
}
uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0; uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
if (0 < received && null_hash != payment_id) if (0 < received)
{ {
payment_details payment; payment_details payment;
payment.m_tx_hash = cryptonote::get_transaction_hash(tx); payment.m_tx_hash = cryptonote::get_transaction_hash(tx);
@ -243,8 +246,6 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
m_payments.emplace(payment_id, payment); m_payments.emplace(payment_id, payment);
LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount); LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount);
} }
}
}
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void wallet2::process_unconfirmed(const cryptonote::transaction& tx) void wallet2::process_unconfirmed(const cryptonote::transaction& tx)
@ -816,6 +817,17 @@ void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::pa
}); });
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void wallet2::get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height) const
{
auto range = std::make_pair(m_payments.begin(), m_payments.end());
std::for_each(range.first, range.second, [&payments, &min_height](const payment_container::value_type& x) {
if (min_height < x.second.m_block_height)
{
payments.push_back(x);
}
});
}
//----------------------------------------------------------------------------------------------------
bool wallet2::is_transfer_unlocked(const transfer_details& td) const bool wallet2::is_transfer_unlocked(const transfer_details& td) const
{ {
if(!is_tx_spendtime_unlocked(td.m_tx.unlock_time)) if(!is_tx_spendtime_unlocked(td.m_tx.unlock_time))

View file

@ -211,6 +211,7 @@ namespace tools
bool check_connection(); bool check_connection();
void get_transfers(wallet2::transfer_container& incoming_transfers) const; void get_transfers(wallet2::transfer_container& incoming_transfers) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const; void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height) const;
uint64_t get_blockchain_current_height() const { return m_local_bc_height; } uint64_t get_blockchain_current_height() const { return m_local_bc_height; }
template <class t_archive> template <class t_archive>
inline void serialize(t_archive &a, const unsigned int ver) inline void serialize(t_archive &a, const unsigned int ver)

View file

@ -315,6 +315,26 @@ namespace tools
{ {
res.payments.clear(); res.payments.clear();
/* If the payment ID list is empty, we get payments to any payment ID (or lack thereof) */
if (req.payment_ids.empty())
{
std::list<std::pair<crypto::hash,wallet2::payment_details>> payment_list;
m_wallet.get_payments(payment_list, req.min_block_height);
for (auto & payment : payment_list)
{
wallet_rpc::payment_details rpc_payment;
rpc_payment.payment_id = epee::string_tools::pod_to_hex(payment.first);
rpc_payment.tx_hash = epee::string_tools::pod_to_hex(payment.second.m_tx_hash);
rpc_payment.amount = payment.second.m_amount;
rpc_payment.block_height = payment.second.m_block_height;
rpc_payment.unlock_time = payment.second.m_unlock_time;
res.payments.push_back(std::move(rpc_payment));
}
return true;
}
for (auto & payment_id_str : req.payment_ids) for (auto & payment_id_str : req.payment_ids)
{ {
crypto::hash payment_id; crypto::hash payment_id;