diff options
Diffstat (limited to 'src/wallet/api')
-rw-r--r-- | src/wallet/api/transaction_history.cpp | 39 | ||||
-rw-r--r-- | src/wallet/api/transaction_history.h | 2 | ||||
-rw-r--r-- | src/wallet/api/transaction_info.cpp | 11 | ||||
-rw-r--r-- | src/wallet/api/transaction_info.h | 10 | ||||
-rw-r--r-- | src/wallet/api/wallet.cpp | 5 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 1 |
6 files changed, 56 insertions, 12 deletions
diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index 3ebcc041e..185cd164f 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -35,14 +35,20 @@ #include "crypto/hash.h" #include "wallet/wallet2.h" -#include "contrib/epee/include/string_tools.h" + #include <string> #include <list> +using namespace epee; + namespace Bitmonero { +TransactionHistory::~TransactionHistory() {} + + TransactionHistoryImpl::TransactionHistoryImpl(WalletImpl *wallet) + : m_wallet(wallet) { } @@ -54,7 +60,7 @@ TransactionHistoryImpl::~TransactionHistoryImpl() int TransactionHistoryImpl::count() const { - return 0; + return m_history.size(); } TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) const @@ -64,7 +70,7 @@ TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) cons std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const { - return std::vector<TransactionInfo*>(); + return m_history; } void TransactionHistoryImpl::refresh() @@ -73,9 +79,18 @@ void TransactionHistoryImpl::refresh() uint64_t min_height = 0; uint64_t max_height = (uint64_t)-1; - // TODO: delete old transactions; + // delete old transactions; + for (auto t : m_history) + delete t; std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; + + // transactions are stored in wallet2: + // - confirmed_transfer_details - out transfers + // - unconfirmed_transfer_details - pending out transfers + // - 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) { const tools::wallet2::payment_details &pd = i->second; @@ -83,9 +98,19 @@ void TransactionHistoryImpl::refresh() if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); // TODO - TransactionInfo * ti = new TransactionInfo(); - - //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()))); + TransactionInfoImpl * ti = new TransactionInfoImpl(); + ti->m_paymentid = payment_id; + ti->m_amount = pd.m_amount; + ti->m_direction = TransactionInfo::Direction_In; + ti->m_hash = string_tools::pod_to_hex(pd.m_tx_hash); + // TODO: + // ti->m_timestamp = pd.m_timestamp; + m_history.push_back(ti); + + /* 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())));*/ } } diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h index 1ff729b54..171fd2210 100644 --- a/src/wallet/api/transaction_history.h +++ b/src/wallet/api/transaction_history.h @@ -47,6 +47,8 @@ public: virtual void refresh(); private: + + // TransactionHistory is responsible of memory management std::vector<TransactionInfo*> m_history; WalletImpl *m_wallet; }; diff --git a/src/wallet/api/transaction_info.cpp b/src/wallet/api/transaction_info.cpp index 8de4e555f..c28c52355 100644 --- a/src/wallet/api/transaction_info.cpp +++ b/src/wallet/api/transaction_info.cpp @@ -35,7 +35,16 @@ using namespace std; namespace Bitmonero { +TransactionInfo::~TransactionInfo() {} + TransactionInfoImpl::TransactionInfoImpl() + : m_direction(Direction_Out) + , m_hold(false) + , m_failed(false) + , m_amount(0) + , m_fee(0) + , m_blockheight(0) + , m_timestamp(0) { } @@ -71,7 +80,7 @@ uint64_t TransactionInfoImpl::fee() const return 0; } -string TransactionInfoImpl::address() const +string TransactionInfoImpl::hash() const { return ""; } diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h index 3aae19a64..945b0d9ed 100644 --- a/src/wallet/api/transaction_info.h +++ b/src/wallet/api/transaction_info.h @@ -41,12 +41,16 @@ class TransactionInfoImpl : public TransactionInfo public: TransactionInfoImpl(); ~TransactionInfoImpl(); + //! in/out virtual int direction() const; + //! true if hold virtual bool isHold() const; virtual bool isFailed() const; virtual uint64_t amount() const; + //! always 0 for incoming txes virtual uint64_t fee() const; - virtual std::string address() const; + + virtual std::string hash() const; virtual std::time_t timestamp() const; virtual std::string paymentId() const; @@ -56,8 +60,8 @@ private: bool m_failed; uint64_t m_amount; uint64_t m_fee; - uint64_t b_blockheight; - std::string m_address; + uint64_t m_blockheight; + std::string m_hash; std::time_t m_timestamp; std::string m_paymentid; diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index a665fff95..5f32908de 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -31,6 +31,7 @@ #include "wallet.h" #include "pending_transaction.h" +#include "transaction_history.h" #include "common_defines.h" #include "mnemonics/electrum-words.h" @@ -58,10 +59,12 @@ WalletImpl::WalletImpl(bool testnet) :m_wallet(nullptr), m_status(Wallet::Status_Ok) { m_wallet = new tools::wallet2(testnet); + m_history = new TransactionHistoryImpl(this); } WalletImpl::~WalletImpl() { + delete m_history; delete m_wallet; } @@ -388,7 +391,7 @@ void WalletImpl::disposeTransaction(PendingTransaction *t) TransactionHistory *WalletImpl::history() const { - return nullptr; + return m_history; } bool WalletImpl::connectToDaemon() diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 6a654b13e..3eaaec59e 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -80,6 +80,7 @@ private: int m_status; std::string m_errorString; std::string m_password; + TransactionHistoryImpl * m_history; }; |