diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-01-10 19:32:08 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-01-11 12:04:05 +0000 |
commit | 87839cd4843efb231f0406881437d724dbf0161c (patch) | |
tree | 1e9cc35a0c81dadf4f0ff3bf0ee0f07d2b2d4a1d /src | |
parent | Merge pull request #206 (diff) | |
download | monero-87839cd4843efb231f0406881437d724dbf0161c.tar.xz |
Allow get_bulk_payments to return all payments regardless of payment ID
by giving an empty list of payment IDs.
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/wallet2.cpp | 36 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 1 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 20 |
3 files changed, 45 insertions, 12 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index da8898132..6698e7296 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -227,24 +227,25 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ } tx_extra_nonce extra_nonce; + crypto::hash payment_id = null_hash; 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)) { - 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) - { - payment_details payment; - payment.m_tx_hash = cryptonote::get_transaction_hash(tx); - payment.m_amount = received; - payment.m_block_height = height; - payment.m_unlock_time = tx.unlock_time; - m_payments.emplace(payment_id, payment); - LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount); - } + // 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; + if (0 < received) + { + payment_details payment; + payment.m_tx_hash = cryptonote::get_transaction_hash(tx); + payment.m_amount = received; + payment.m_block_height = height; + payment.m_unlock_time = tx.unlock_time; + m_payments.emplace(payment_id, payment); + LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount); + } } //---------------------------------------------------------------------------------------------------- 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 { if(!is_tx_spendtime_unlocked(td.m_tx.unlock_time)) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 073fff58b..9b60d6ac5 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -211,6 +211,7 @@ namespace tools bool check_connection(); 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(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; } template <class t_archive> inline void serialize(t_archive &a, const unsigned int ver) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index d7b3f8434..6b6bb4fe2 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -315,6 +315,26 @@ namespace tools { 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) { crypto::hash payment_id; |