aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/wallet/wallet2.cpp44
-rw-r--r--src/wallet/wallet2.h33
2 files changed, 66 insertions, 11 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 834095539..788f96415 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -150,7 +150,7 @@ bool wallet2::is_deprecated() const
//----------------------------------------------------------------------------------------------------
void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_t height)
{
- process_unconfirmed(tx);
+ process_unconfirmed(tx, height);
std::vector<size_t> outs;
uint64_t tx_money_got_in_outs = 0;
crypto::public_key tx_pub_key = null_pkey;
@@ -283,11 +283,22 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
}
}
//----------------------------------------------------------------------------------------------------
-void wallet2::process_unconfirmed(const cryptonote::transaction& tx)
-{
- auto unconf_it = m_unconfirmed_txs.find(get_transaction_hash(tx));
- if(unconf_it != m_unconfirmed_txs.end())
+void wallet2::process_unconfirmed(const cryptonote::transaction& tx, uint64_t height)
+{
+ crypto::hash txid = get_transaction_hash(tx);
+ auto unconf_it = m_unconfirmed_txs.find(txid);
+ if(unconf_it != m_unconfirmed_txs.end()) {
+ if (store_tx_keys()) {
+ try {
+ m_confirmed_txs.insert(std::make_pair(txid, confirmed_transfer_details(unconf_it->second, height)));
+ }
+ catch (...) {
+ // can fail if the tx has unexpected input types
+ LOG_PRINT_L0("Failed to add outgoing transaction to confirmed transaction map");
+ }
+ }
m_unconfirmed_txs.erase(unconf_it);
+ }
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height)
@@ -1021,17 +1032,34 @@ 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
+void wallet2::get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height, uint64_t max_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)
+ std::for_each(range.first, range.second, [&payments, &min_height, &max_height](const payment_container::value_type& x) {
+ if (min_height < x.second.m_block_height && max_height >= x.second.m_block_height)
{
payments.push_back(x);
}
});
}
//----------------------------------------------------------------------------------------------------
+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
+{
+ for (auto i = m_confirmed_txs.begin(); i != m_confirmed_txs.end(); ++i) {
+ if (i->second.m_block_height > min_height && i->second.m_block_height <= max_height) {
+ confirmed_payments.push_back(*i);
+ }
+ }
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments) const
+{
+ for (auto i = m_unconfirmed_txs.begin(); i != m_unconfirmed_txs.end(); ++i) {
+ unconfirmed_payments.push_back(*i);
+ }
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::rescan_spent()
{
std::vector<std::string> key_images;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index c9732cdd6..dbd305a02 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -109,6 +109,17 @@ namespace tools
time_t m_sent_time;
};
+ struct confirmed_transfer_details
+ {
+ uint64_t m_amount_in;
+ uint64_t m_amount_out;
+ uint64_t m_change;
+ uint64_t m_block_height;
+ confirmed_transfer_details() {}
+ confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height):
+ m_amount_out(get_outs_money_amount(utd.m_tx)), m_change(utd.m_change), m_block_height(height) { get_inputs_money_amount(utd.m_tx, m_amount_in); }
+ };
+
typedef std::vector<transfer_details> transfer_container;
typedef std::unordered_multimap<crypto::hash, payment_details> payment_container;
@@ -244,7 +255,10 @@ 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;
+ 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;
+ 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;
+ void get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments) const;
uint64_t get_blockchain_current_height() const { return m_local_bc_height; }
void rescan_spent();
template <class t_archive>
@@ -265,6 +279,9 @@ namespace tools
if(ver < 8)
return;
a & m_tx_keys;
+ if(ver < 9)
+ return;
+ a & m_confirmed_txs;
}
/*!
@@ -323,7 +340,7 @@ namespace tools
void pull_blocks(uint64_t start_height, uint64_t& blocks_added);
uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, std::list<transfer_container::iterator>& selected_transfers);
bool prepare_file_names(const std::string& file_path);
- void process_unconfirmed(const cryptonote::transaction& tx);
+ void process_unconfirmed(const cryptonote::transaction& tx, uint64_t height);
void add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t change_amount);
void generate_genesis(cryptonote::block& b);
void check_genesis(const crypto::hash& genesis_hash) const; //throws
@@ -337,6 +354,7 @@ namespace tools
std::vector<crypto::hash> m_blockchain;
std::atomic<uint64_t> m_local_bc_height; //temporary workaround
std::unordered_map<crypto::hash, unconfirmed_transfer_details> m_unconfirmed_txs;
+ std::unordered_map<crypto::hash, confirmed_transfer_details> m_confirmed_txs;
std::unordered_map<crypto::hash, crypto::secret_key> m_tx_keys;
transfer_container m_transfers;
@@ -358,7 +376,7 @@ namespace tools
uint32_t m_default_mixin;
};
}
-BOOST_CLASS_VERSION(tools::wallet2, 8)
+BOOST_CLASS_VERSION(tools::wallet2, 9)
namespace boost
{
@@ -384,6 +402,15 @@ namespace boost
}
template <class Archive>
+ inline void serialize(Archive &a, tools::wallet2::confirmed_transfer_details &x, const boost::serialization::version_type ver)
+ {
+ a & x.m_amount_in;
+ a & x.m_amount_out;
+ a & x.m_change;
+ a & x.m_block_height;
+ }
+
+ template <class Archive>
inline void serialize(Archive& a, tools::wallet2::payment_details& x, const boost::serialization::version_type ver)
{
a & x.m_tx_hash;