diff options
author | Ilya Kitaev <mbg033@gmail.com> | 2016-04-29 16:26:14 +0300 |
---|---|---|
committer | Ilya Kitaev <mbg033@gmail.com> | 2016-06-23 16:01:26 +0300 |
commit | e6fdd5dd10efa29029aa6babf821c429084d786f (patch) | |
tree | c3a392307e0d204082b8d2c7292013c84ed368e0 /src | |
parent | merged with upstream (diff) | |
download | monero-e6fdd5dd10efa29029aa6babf821c429084d786f.tar.xz |
TransactionHistory continued
Diffstat (limited to 'src')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 2 | ||||
-rw-r--r-- | src/wallet/api/transaction_history.cpp | 79 | ||||
-rw-r--r-- | src/wallet/api/transaction_info.cpp | 17 | ||||
-rw-r--r-- | src/wallet/api/transaction_info.h | 7 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 12 |
5 files changed, 104 insertions, 13 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 22ddb0639..0581d9de9 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2999,7 +2999,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_) } LOCK_REFRESH_THREAD_SCOPE(); - + // optional in/out selector if (local_args.size() > 0) { if (local_args[0] == "in" || local_args[0] == "incoming") { diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index c7e7472e9..db42e2141 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -82,8 +82,9 @@ void TransactionHistoryImpl::refresh() // delete old transactions; for (auto t : m_history) delete t; + m_history.clear(); + - std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; // transactions are stored in wallet2: // - confirmed_transfer_details - out transfers @@ -91,8 +92,11 @@ void TransactionHistoryImpl::refresh() // - payment_details - input transfers // payments are "input transactions"; - m_wallet->m_wallet->get_payments(payments, min_height, max_height); - for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) { + // one input transaction contains only one transfer. e.g. <transaction_id> - <100XMR> + + std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> in_payments; + m_wallet->m_wallet->get_payments(in_payments, min_height, max_height); + for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = in_payments.begin(); i != in_payments.end(); ++i) { const tools::wallet2::payment_details &pd = i->second; std::string payment_id = string_tools::pod_to_hex(i->first); if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) @@ -111,8 +115,75 @@ void TransactionHistoryImpl::refresh() /* output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%20.20s %s %s %s") % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) - % payment_id % "-").str())));*/ + % payment_id % "-").str()))); */ + } + + // confirmed output transactions + // one output transaction may contain more than one money transfer, e.g. + // <transaction_id>: + // transfer1: 100XMR to <address_1> + // transfer2: 50XMR to <address_2> + // fee: fee charged per transaction + // + + std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> out_payments; + m_wallet->m_wallet->get_payments_out(out_payments, min_height, max_height); + + for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = out_payments.begin(); + i != out_payments.end(); ++i) { + + const crypto::hash &hash = i->first; + const tools::wallet2::confirmed_transfer_details &pd = i->second; + + uint64_t fee = pd.m_amount_in - pd.m_amount_out; + uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known + + + std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id); + if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) + payment_id = payment_id.substr(0,16); + + + TransactionInfoImpl * ti = new TransactionInfoImpl(); + ti->m_paymentid = payment_id; + ti->m_amount = pd.m_amount_in - change - fee; + ti->m_fee = fee; + ti->m_direction = TransactionInfo::Direction_Out; + ti->m_hash = string_tools::pod_to_hex(hash); + ti->m_blockheight = pd.m_block_height; + + // single output transaction might contain multiple transfers + for (const auto &d: pd.m_dests) { + ti->m_transfers.push_back({d.amount, get_account_address_as_str(m_wallet->m_wallet->testnet(), d.addr)}); + } + m_history.push_back(ti); } + + // unconfirmed output transactions + std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments; + m_wallet->m_wallet->get_unconfirmed_payments_out(upayments); + for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) { + const tools::wallet2::unconfirmed_transfer_details &pd = i->second; + const crypto::hash &hash = i->first; + uint64_t amount = 0; + cryptonote::get_inputs_money_amount(pd.m_tx, amount); + uint64_t fee = amount - get_outs_money_amount(pd.m_tx); + std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id); + if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) + payment_id = payment_id.substr(0,16); + bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; + + TransactionInfoImpl * ti = new TransactionInfoImpl(); + ti->m_paymentid = payment_id; + ti->m_amount = amount - pd.m_change; + ti->m_fee = fee; + ti->m_direction = TransactionInfo::Direction_Out; + ti->m_failed = is_failed; + ti->m_pending = true; + ti->m_hash = string_tools::pod_to_hex(hash); + m_history.push_back(ti); + } + } TransactionInfo *TransactionHistoryImpl::transaction(int index) const diff --git a/src/wallet/api/transaction_info.cpp b/src/wallet/api/transaction_info.cpp index 578b84832..f25c53a90 100644 --- a/src/wallet/api/transaction_info.cpp +++ b/src/wallet/api/transaction_info.cpp @@ -37,9 +37,13 @@ namespace Bitmonero { TransactionInfo::~TransactionInfo() {} +TransactionInfo::Transfer::Transfer(uint64_t _amount, const string &_address) + : amount(_amount), address(_address) {} + + TransactionInfoImpl::TransactionInfoImpl() : m_direction(Direction_Out) - , m_hold(false) + , m_pending(false) , m_failed(false) , m_amount(0) , m_fee(0) @@ -56,13 +60,13 @@ TransactionInfoImpl::~TransactionInfoImpl() int TransactionInfoImpl::direction() const { - return TransactionInfo::Direction_In; + return m_direction; } -bool TransactionInfoImpl::isHold() const +bool TransactionInfoImpl::isPending() const { - return m_hold; + return m_pending; } bool TransactionInfoImpl::isFailed() const @@ -100,4 +104,9 @@ string TransactionInfoImpl::paymentId() const return m_paymentid; } +const std::vector<TransactionInfo::Transfer> &TransactionInfoImpl::transfers() const +{ + return m_transfers; +} + } // namespace diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h index a06bc367e..82ab2cc6b 100644 --- a/src/wallet/api/transaction_info.h +++ b/src/wallet/api/transaction_info.h @@ -44,7 +44,7 @@ public: //! in/out virtual int direction() const; //! true if hold - virtual bool isHold() const; + virtual bool isPending() const; virtual bool isFailed() const; virtual uint64_t amount() const; //! always 0 for incoming txes @@ -54,10 +54,11 @@ public: virtual std::string hash() const; virtual std::time_t timestamp() const; virtual std::string paymentId() const; + virtual const std::vector<Transfer> &transfers() const; private: int m_direction; - bool m_hold; + bool m_pending; bool m_failed; uint64_t m_amount; uint64_t m_fee; @@ -65,7 +66,7 @@ private: std::string m_hash; std::time_t m_timestamp; std::string m_paymentid; - + std::vector<Transfer> m_transfers; friend class TransactionHistoryImpl; diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index ab715dbf9..43f5c9472 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -68,16 +68,26 @@ struct TransactionInfo Direction_In, Direction_Out }; + + struct Transfer { + Transfer(uint64_t _amount, const std::string &address); + const uint64_t amount; + const std::string address; + }; + virtual ~TransactionInfo() = 0; virtual int direction() const = 0; - virtual bool isHold() const = 0; + virtual bool isPending() const = 0; virtual bool isFailed() const = 0; virtual uint64_t amount() const = 0; virtual uint64_t fee() const = 0; virtual uint64_t blockHeight() const = 0; + //! transaction_id virtual std::string hash() const = 0; virtual std::time_t timestamp() const = 0; virtual std::string paymentId() const = 0; + //! only applicable for output transactions + virtual const std::vector<Transfer> & transfers() const = 0; }; /** * @brief The TransactionHistory - interface for displaying transaction history |