Skip to content

Commit

Permalink
wallet2: substituted "min_height" for "threshold" and reverted to ori…
Browse files Browse the repository at this point in the history
…ginal get_payments logic

Dictionaries define **minimum** as "the least quantity or amount possible", while threshold is "the point that must be exceeded to begin producing a given effect".
  • Loading branch information
fullmetalScience committed Jun 5, 2019
1 parent e65fd7f commit 0710b8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
24 changes: 12 additions & 12 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5670,11 +5670,11 @@ void wallet2::get_transfers(wallet2::transfer_container& incoming_transfers) con
incoming_transfers = m_transfers;
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t threshold, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
{
auto range = m_payments.equal_range(payment_id);
std::for_each(range.first, range.second, [&payments, &min_height, &subaddr_account, &subaddr_indices](const payment_container::value_type& x) {
if (min_height < x.second.m_block_height &&
std::for_each(range.first, range.second, [&payments, &threshold, &subaddr_account, &subaddr_indices](const payment_container::value_type& x) {
if (threshold < x.second.m_block_height &&
(!subaddr_account || *subaddr_account == x.second.m_subaddr_index.major) &&
(subaddr_indices.empty() || subaddr_indices.count(x.second.m_subaddr_index.minor) == 1))
{
Expand All @@ -5686,14 +5686,14 @@ 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,
const payment_container& actual_payments,
uint64_t min_height,
uint64_t threshold,
uint64_t max_height,
const boost::optional<uint32_t>& subaddr_account,
const std::set<uint32_t>& subaddr_indices) const
{
auto range = std::make_pair(actual_payments.begin(), actual_payments.end());
std::for_each(range.first, range.second, [&payments, &min_height, &max_height, &subaddr_account, &subaddr_indices](const payment_container::value_type& x) {
if (min_height <= x.second.m_block_height && max_height >= x.second.m_block_height &&
std::for_each(range.first, range.second, [&payments, &threshold, &max_height, &subaddr_account, &subaddr_indices](const payment_container::value_type& x) {
if (threshold < x.second.m_block_height && max_height >= x.second.m_block_height &&
(!subaddr_account || *subaddr_account == x.second.m_subaddr_index.major) &&
(subaddr_indices.empty() || subaddr_indices.count(x.second.m_subaddr_index.minor) == 1))
{
Expand All @@ -5703,21 +5703,21 @@ void wallet2::get_payments(
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments,
uint64_t min_height, uint64_t max_height, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
uint64_t threshold, uint64_t max_height, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
{
get_payments(payments, m_payments, min_height, max_height, subaddr_account, subaddr_indices);
get_payments(payments, m_payments, threshold, max_height, subaddr_account, subaddr_indices);
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_payments_out(
std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
const std::unordered_map<crypto::hash, confirmed_transfer_details>& actual_confirmed_txs,
uint64_t min_height,
uint64_t threshold,
uint64_t max_height,
const boost::optional<uint32_t>& subaddr_account,
const std::set<uint32_t>& subaddr_indices) const
{
for (auto i = actual_confirmed_txs.begin(); i != actual_confirmed_txs.end(); ++i) {
if (i->second.m_block_height < min_height || i->second.m_block_height > max_height)
if (i->second.m_block_height <= threshold || i->second.m_block_height > max_height)
continue;
if (subaddr_account && *subaddr_account != i->second.m_subaddr_account)
continue;
Expand All @@ -5728,9 +5728,9 @@ void wallet2::get_payments_out(
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
uint64_t min_height, uint64_t max_height, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
uint64_t threshold, uint64_t max_height, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
{
get_payments_out(confirmed_payments, m_confirmed_txs, min_height, max_height, subaddr_account, subaddr_indices);
get_payments_out(confirmed_payments, m_confirmed_txs, threshold, max_height, subaddr_account, subaddr_indices);
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments, const boost::optional<uint32_t>& subaddr_account, const std::set<uint32_t>& subaddr_indices) const
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,13 @@ namespace tools
void discard_unmixable_outputs();
bool check_connection(uint32_t *version = NULL, bool *ssl = NULL, uint32_t timeout = 200000);
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 boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, const payment_container& actual_payments, uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t threshold = 0, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, const payment_container& actual_payments, uint64_t threshold, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t threshold, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments, const std::unordered_map<crypto::hash, confirmed_transfer_details>& actual_confirmed_txs,
uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
uint64_t threshold, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
uint64_t threshold, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_unconfirmed_payments(std::list<std::pair<crypto::hash,wallet2::pool_payment_details>>& unconfirmed_payments, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;

Expand Down
30 changes: 15 additions & 15 deletions tests/unit_tests/get_payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GetPayments : public ::testing::Test
const std::string password = "testpass";
crypto::secret_key recovery_key = crypto::secret_key();

uint64_t min_height = 0;
uint64_t threshold = 0;
uint64_t max_height = (uint64_t)-1;

uint64_t block_height_that_has_transaction;
Expand All @@ -88,13 +88,13 @@ class GetPayments : public ::testing::Test
};


TEST_F(GetPayments, NotFoundBelowMinHeight)
TEST_F(GetPayments, NotFoundBelowThreshold)
{
m_wallet.get_payments(matched_payments, actual_payments,
++block_height_that_has_transaction, block_height_that_has_transaction);
ASSERT_EQ(0, matched_payments.size());
}
TEST_F(GetPayments, NotFoundBelowMinHeight_Out)
TEST_F(GetPayments, NotFoundBelowThreshold_Out)
{
m_wallet.get_payments_out(confirmed_payments, actual_confirmed_txs,
++block_height_that_has_transaction, block_height_that_has_transaction);
Expand Down Expand Up @@ -144,57 +144,57 @@ TEST_F(GetPayments, NotFoundIfNegativeReversed_Out)
}


TEST_F(GetPayments, NotFoundIfMinHeightAboveMaxHeight)
TEST_F(GetPayments, NotFoundIfThresholdAboveMaxHeight)
{
m_wallet.get_payments(matched_payments, actual_payments,
max_height, min_height);
max_height, threshold);
ASSERT_EQ(0, matched_payments.size());
}
TEST_F(GetPayments, NotFoundIfMinHeightAboveMaxHeight_Out)
TEST_F(GetPayments, NotFoundIfThresholdAboveMaxHeight_Out)
{
m_wallet.get_payments_out(confirmed_payments, actual_confirmed_txs,
max_height, min_height);
max_height, threshold);
ASSERT_EQ(0, confirmed_payments.size());
}


TEST_F(GetPayments, IsFoundWithinZeroAndMax)
{
m_wallet.get_payments(matched_payments, actual_payments,
min_height, max_height);
threshold, max_height);
ASSERT_EQ(1, matched_payments.size());
}
TEST_F(GetPayments, IsFoundWithinZeroAndMax_Out)
{
m_wallet.get_payments_out(confirmed_payments, actual_confirmed_txs,
min_height, max_height);
threshold, max_height);
ASSERT_EQ(1, confirmed_payments.size());
}


TEST_F(GetPayments, IsFoundAtMinHeight)
TEST_F(GetPayments, NotFoundAtThreshold)
{
m_wallet.get_payments(matched_payments, actual_payments,
block_height_that_has_transaction, block_height_that_has_transaction);
ASSERT_EQ(1, matched_payments.size());
ASSERT_EQ(0, matched_payments.size());
}
TEST_F(GetPayments, IsFoundAtMinHeight_Out)
TEST_F(GetPayments, NotFoundAtThreshold_Out)
{
m_wallet.get_payments_out(confirmed_payments, actual_confirmed_txs,
block_height_that_has_transaction, block_height_that_has_transaction);
ASSERT_EQ(1, confirmed_payments.size());
ASSERT_EQ(0, confirmed_payments.size());
}


TEST_F(GetPayments, IsFoundAtMaxHeight)
{
m_wallet.get_payments(matched_payments, actual_payments,
min_height, block_height_that_has_transaction);
threshold, block_height_that_has_transaction);
ASSERT_EQ(1, matched_payments.size());
}
TEST_F(GetPayments, IsFoundAtMaxHeight_Out)
{
m_wallet.get_payments_out(confirmed_payments, actual_confirmed_txs,
min_height, block_height_that_has_transaction);
threshold, block_height_that_has_transaction);
ASSERT_EQ(1, confirmed_payments.size());
}

0 comments on commit 0710b8f

Please sign in to comment.