From f83f3cbd9647b679e5c9460970b99bd2e9141858 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 20 Apr 2016 13:01:00 +0300 Subject: api implementation splitted over separate files --- src/wallet/api/common_defines.h | 7 + src/wallet/api/pending_transaction.cpp | 138 +++++++++++ src/wallet/api/pending_transaction.h | 64 +++++ src/wallet/api/transaction_history.cpp | 33 +++ src/wallet/api/transaction_history.h | 44 ++++ src/wallet/api/transaction_info.cpp | 89 +++++++ src/wallet/api/transaction_info.h | 52 +++++ src/wallet/api/wallet.cpp | 411 +++++++++++++++++++++++++++++++++ src/wallet/api/wallet.h | 86 +++++++ src/wallet/api/wallet_manager.cpp | 108 +++++++++ src/wallet/api/wallet_manager.h | 55 +++++ 11 files changed, 1087 insertions(+) create mode 100644 src/wallet/api/common_defines.h create mode 100644 src/wallet/api/pending_transaction.cpp create mode 100644 src/wallet/api/pending_transaction.h create mode 100644 src/wallet/api/transaction_history.cpp create mode 100644 src/wallet/api/transaction_history.h create mode 100644 src/wallet/api/transaction_info.cpp create mode 100644 src/wallet/api/transaction_info.h create mode 100644 src/wallet/api/wallet.cpp create mode 100644 src/wallet/api/wallet.h create mode 100644 src/wallet/api/wallet_manager.cpp create mode 100644 src/wallet/api/wallet_manager.h (limited to 'src/wallet/api') diff --git a/src/wallet/api/common_defines.h b/src/wallet/api/common_defines.h new file mode 100644 index 000000000..60a40a45a --- /dev/null +++ b/src/wallet/api/common_defines.h @@ -0,0 +1,7 @@ +#ifndef WALLET_API_COMMON_DEFINES_H__ +#define WALLET_API_COMMON_DEFINES_H__ + +#define tr(x) (x) + +#endif + diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp new file mode 100644 index 000000000..e9791ec35 --- /dev/null +++ b/src/wallet/api/pending_transaction.cpp @@ -0,0 +1,138 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "pending_transaction.h" +#include "wallet.h" +#include "common_defines.h" + +#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_core/cryptonote_format_utils.h" + +#include +#include +#include +#include + +using namespace std; + +namespace Bitmonero { + +PendingTransaction::~PendingTransaction() {} + + +TransactionImpl::TransactionImpl(WalletImpl *wallet) + : m_wallet(wallet) +{ + +} + +TransactionImpl::~TransactionImpl() +{ + +} + +int TransactionImpl::status() const +{ + return m_status; +} + +string TransactionImpl::errorString() const +{ + return m_errorString; +} + +bool TransactionImpl::commit() +{ + + LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size()); + assert(m_pending_tx.size() == 1); + try { + while (!m_pending_tx.empty()) { + auto & ptx = m_pending_tx.back(); + m_wallet->m_wallet->commit_tx(ptx); + // success_msg_writer(true) << tr("Money successfully sent, transaction ") << get_transaction_hash(ptx.tx); + // if no exception, remove element from vector + m_pending_tx.pop_back(); + } // TODO: extract method; + } catch (const tools::error::daemon_busy&) { + // TODO: make it translatable with "tr"? + m_errorString = tr("daemon is busy. Please try again later."); + m_status = Status_Error; + } catch (const tools::error::no_connection_to_daemon&) { + m_errorString = tr("no connection to daemon. Please make sure daemon is running."); + m_status = Status_Error; + } catch (const tools::error::tx_rejected& e) { + std::ostringstream writer(m_errorString); + writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status(); + m_status = Status_Error; + } catch (std::exception &e) { + m_errorString = string(tr("Unknown exception: ")) + e.what(); + m_status = Status_Error; + } catch (...) { + m_errorString = tr("Unhandled exception"); + LOG_ERROR(m_errorString); + m_status = Status_Error; + } + + return m_status == Status_Ok; +} + +uint64_t TransactionImpl::amount() const +{ + uint64_t result = 0; + for (const auto &ptx : m_pending_tx) { + for (const auto &dest : ptx.dests) { + result += dest.amount; + } + } + return result; +} + +uint64_t TransactionImpl::dust() const +{ + uint32_t result = 0; + for (const auto & ptx : m_pending_tx) { + result += ptx.dust; + } + return result; +} + +uint64_t TransactionImpl::fee() const +{ + uint32_t result = 0; + for (const auto ptx : m_pending_tx) { + result += ptx.fee; + } + return result; +} + +} + diff --git a/src/wallet/api/pending_transaction.h b/src/wallet/api/pending_transaction.h new file mode 100644 index 000000000..0ae3eb8e2 --- /dev/null +++ b/src/wallet/api/pending_transaction.h @@ -0,0 +1,64 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "wallet/wallet2_api.h" +#include "wallet/wallet2.h" + +#include +#include + + +namespace Bitmonero { + +class WalletImpl; +class PendingTransactionImpl : public PendingTransaction +{ +public: + PendingTransactionImpl(WalletImpl * wallet); + ~PendingTransactionImpl(); + int status() const; + std::string errorString() const; + bool commit(); + uint64_t amount() const; + uint64_t dust() const; + uint64_t fee() const; + // TODO: continue with interface; + +private: + friend class WalletImpl; + WalletImpl * m_wallet; + + int m_status; + std::string m_errorString; + std::vector m_pending_tx; +}; + + +} diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp new file mode 100644 index 000000000..f1aba14cb --- /dev/null +++ b/src/wallet/api/transaction_history.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "transaction_history.h" + + diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h new file mode 100644 index 000000000..cab0e0dbc --- /dev/null +++ b/src/wallet/api/transaction_history.h @@ -0,0 +1,44 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "wallet/wallet2_api.h" + +namespace Bitmonero { + +class TransactionHistoryImpl : public TransactionHistory +{ + virtual int count() const; + virtual TransactionInfo * transaction(int index) const = 0; + virtual TransactionInfo * transaction(const std::string &id) const = 0; + virtual std::vector getAll() const = 0; +}; + +} + diff --git a/src/wallet/api/transaction_info.cpp b/src/wallet/api/transaction_info.cpp new file mode 100644 index 000000000..8de4e555f --- /dev/null +++ b/src/wallet/api/transaction_info.cpp @@ -0,0 +1,89 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "transaction_info.h" + + +using namespace std; + +namespace Bitmonero { + +TransactionInfoImpl::TransactionInfoImpl() +{ + +} + +TransactionInfoImpl::~TransactionInfoImpl() +{ + +} + +int TransactionInfoImpl::direction() const +{ + return TransactionInfo::Direction_In; +} + + +bool TransactionInfoImpl::isHold() const +{ + return false; +} + +bool TransactionInfoImpl::isFailed() const +{ + return false; +} + +uint64_t TransactionInfoImpl::amount() const +{ + return 0; +} + +uint64_t TransactionInfoImpl::fee() const +{ + return 0; +} + +string TransactionInfoImpl::address() const +{ + return ""; +} + +std::time_t TransactionInfoImpl::timestamp() const +{ + return std::time_t(0); +} + +string TransactionInfoImpl::paymentId() const +{ + return ""; +} + +} // namespace diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h new file mode 100644 index 000000000..2ed8157f7 --- /dev/null +++ b/src/wallet/api/transaction_info.h @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "wallet/wallet2_api.h" +#include +#include + +namespace Bitmonero { + +class TransactionInfoImpl : public TransactionInfo +{ +public: + TransactionInfoImpl(); + ~TransactionInfoImpl(); + virtual int direction() const; + virtual bool isHold() const; + virtual bool isFailed() const; + virtual uint64_t amount() const; + virtual uint64_t fee() const; + virtual std::string address() const; + virtual std::time_t timestamp() const; + virtual std::string paymentId() const; +}; + +} // namespace diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp new file mode 100644 index 000000000..e42f04cf7 --- /dev/null +++ b/src/wallet/api/wallet.cpp @@ -0,0 +1,411 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + + +#include "wallet.h" +#include "pending_transaction.h" +#include "common_defines.h" + +#include "mnemonics/electrum-words.h" +#include + +using namespace std; +using namespace cryptonote; + +namespace Bitmonero { + +namespace { + // copy-pasted from simplewallet + static const size_t DEFAULT_MIX = 4; +} + +Wallet::~Wallet() {} + +string Wallet::displayAmount(uint64_t amount) +{ + return cryptonote::print_money(amount); +} + +///////////////////////// WalletImpl implementation //////////////////////// +WalletImpl::WalletImpl(bool testnet) + :m_wallet(nullptr), m_status(Wallet::Status_Ok) +{ + m_wallet = new tools::wallet2(testnet); +} + +WalletImpl::~WalletImpl() +{ + delete m_wallet; +} + +bool WalletImpl::create(const std::string &path, const std::string &password, const std::string &language) +{ + + clearStatus(); + + bool keys_file_exists; + bool wallet_file_exists; + tools::wallet2::wallet_exists(path, keys_file_exists, wallet_file_exists); + // TODO: figure out how to setup logger; + LOG_PRINT_L3("wallet_path: " << path << ""); + LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha + << " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha); + + + // add logic to error out if new wallet requested but named wallet file exists + if (keys_file_exists || wallet_file_exists) { + m_errorString = "attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting."; + LOG_ERROR(m_errorString); + m_status = Status_Error; + return false; + } + // TODO: validate language + m_wallet->set_seed_language(language); + crypto::secret_key recovery_val, secret_key; + try { + recovery_val = m_wallet->generate(path, password, secret_key, false, false); + m_password = password; + m_status = Status_Ok; + } catch (const std::exception &e) { + LOG_ERROR("Error creating wallet: " << e.what()); + m_status = Status_Error; + m_errorString = e.what(); + return false; + } + + return true; +} + +bool WalletImpl::open(const std::string &path, const std::string &password) +{ + clearStatus(); + try { + // TODO: handle "deprecated" + m_wallet->load(path, password); + + m_password = password; + } catch (const std::exception &e) { + LOG_ERROR("Error opening wallet: " << e.what()); + m_status = Status_Error; + m_errorString = e.what(); + } + return m_status == Status_Ok; +} + +bool WalletImpl::recover(const std::string &path, const std::string &seed) +{ + clearStatus(); + m_errorString.clear(); + if (seed.empty()) { + m_errorString = "Electrum seed is empty"; + LOG_ERROR(m_errorString); + m_status = Status_Error; + return false; + } + + crypto::secret_key recovery_key; + std::string old_language; + if (!crypto::ElectrumWords::words_to_bytes(seed, recovery_key, old_language)) { + m_errorString = "Electrum-style word list failed verification"; + m_status = Status_Error; + return false; + } + + try { + m_wallet->set_seed_language(old_language); + m_wallet->generate(path, "", recovery_key, true, false); + // TODO: wallet->init(daemon_address); + } catch (const std::exception &e) { + m_status = Status_Error; + m_errorString = e.what(); + } + return m_status == Status_Ok; +} + +bool WalletImpl::close() +{ + clearStatus(); + bool result = false; + try { + m_wallet->store(); + m_wallet->stop(); + result = true; + } catch (const std::exception &e) { + m_status = Status_Error; + m_errorString = e.what(); + LOG_ERROR("Error closing wallet: " << e.what()); + } + return result; +} + +std::string WalletImpl::seed() const +{ + std::string seed; + if (m_wallet) + m_wallet->get_seed(seed); + return seed; +} + +std::string WalletImpl::getSeedLanguage() const +{ + return m_wallet->get_seed_language(); +} + +void WalletImpl::setSeedLanguage(const std::string &arg) +{ + m_wallet->set_seed_language(arg); +} + +int WalletImpl::status() const +{ + return m_status; +} + +std::string WalletImpl::errorString() const +{ + return m_errorString; +} + +bool WalletImpl::setPassword(const std::string &password) +{ + clearStatus(); + try { + m_wallet->rewrite(m_wallet->get_wallet_file(), password); + m_password = password; + } catch (const std::exception &e) { + m_status = Status_Error; + m_errorString = e.what(); + } + return m_status == Status_Ok; +} + +std::string WalletImpl::address() const +{ + return m_wallet->get_account().get_public_address_str(m_wallet->testnet()); +} + +bool WalletImpl::store(const std::string &path) +{ + clearStatus(); + try { + if (path.empty()) { + m_wallet->store(); + } else { + m_wallet->store_to(path, m_password); + } + } catch (const std::exception &e) { + LOG_ERROR("Error storing wallet: " << e.what()); + m_status = Status_Error; + m_errorString = e.what(); + } + + return m_status == Status_Ok; +} + +bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) +{ + clearStatus(); + try { + m_wallet->init(daemon_address, upper_transaction_size_limit); + } catch (const std::exception &e) { + LOG_ERROR("Error initializing wallet: " << e.what()); + m_status = Status_Error; + m_errorString = e.what(); + } + + return m_status == Status_Ok; +} + +uint64_t WalletImpl::balance() const +{ + return m_wallet->balance(); +} + +uint64_t WalletImpl::unlockedBalance() const +{ + return m_wallet->unlocked_balance(); +} + + +bool WalletImpl::refresh() +{ + clearStatus(); + try { + m_wallet->refresh(); + } catch (const std::exception &e) { + m_status = Status_Error; + m_errorString = e.what(); + } + return m_status == Status_Ok; +} + +// TODO: +// 1 - properly handle payment id (add another menthod with explicit 'payment_id' param) +// 2 - check / design how "Transaction" can be single interface +// (instead of few different data structures within wallet2 implementation: +// - pending_tx; +// - transfer_details; +// - payment_details; +// - unconfirmed_transfer_details; +// - confirmed_transfer_details) +PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64_t amount) +{ + clearStatus(); + vector dsts; + cryptonote::tx_destination_entry de; + bool has_payment_id; + crypto::hash8 new_payment_id; + + // TODO: (https://bitcointalk.org/index.php?topic=753252.msg9985441#msg9985441) + size_t fake_outs_count = m_wallet->default_mixin(); + if (fake_outs_count == 0) + fake_outs_count = DEFAULT_MIX; + + TransactionImpl * transaction = new TransactionImpl(this); + + do { + + if(!cryptonote::get_account_integrated_address_from_str(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), dst_addr)) { + // TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982 + m_status = Status_Error; + m_errorString = "Invalid destination address"; + break; + } + + de.amount = amount; + if (de.amount <= 0) { + m_status = Status_Error; + m_errorString = "Invalid amount"; + break; + } + + dsts.push_back(de); + //std::vector ptx_vector; + std::vector extra; + + + try { + transaction->m_pending_tx = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra); + + } catch (const tools::error::daemon_busy&) { + // TODO: make it translatable with "tr"? + m_errorString = tr("daemon is busy. Please try again later."); + m_status = Status_Error; + } catch (const tools::error::no_connection_to_daemon&) { + m_errorString = tr("no connection to daemon. Please make sure daemon is running."); + m_status = Status_Error; + } catch (const tools::error::wallet_rpc_error& e) { + m_errorString = tr("RPC error: ") + e.to_string(); + m_status = Status_Error; + } catch (const tools::error::get_random_outs_error&) { + m_errorString = tr("failed to get random outputs to mix"); + m_status = Status_Error; + + } catch (const tools::error::not_enough_money& e) { + m_status = Status_Error; + std::ostringstream writer(m_errorString); + + writer << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) % + print_money(e.available()) % + print_money(e.tx_amount() + e.fee()) % + print_money(e.tx_amount()) % + print_money(e.fee()); + + } catch (const tools::error::not_enough_outs_to_mix& e) { + std::ostringstream writer(m_errorString); + writer << tr("not enough outputs for specified mixin_count") << " = " << e.mixin_count() << ":"; + for (const cryptonote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& outs_for_amount : e.scanty_outs()) { + writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.amount) << ", " << tr("found outputs to mix") << " = " << outs_for_amount.outs.size(); + } + m_status = Status_Error; + } catch (const tools::error::tx_not_constructed&) { + m_errorString = tr("transaction was not constructed"); + m_status = Status_Error; + } catch (const tools::error::tx_rejected& e) { + std::ostringstream writer(m_errorString); + writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status(); + m_status = Status_Error; + } catch (const tools::error::tx_sum_overflow& e) { + m_errorString = e.what(); + m_status = Status_Error; + } catch (const tools::error::zero_destination&) { + m_errorString = tr("one of destinations is zero"); + m_status = Status_Error; + } catch (const tools::error::tx_too_big& e) { + m_errorString = tr("failed to find a suitable way to split transactions"); + m_status = Status_Error; + } catch (const tools::error::transfer_error& e) { + m_errorString = string(tr("unknown transfer error: ")) + e.what(); + m_status = Status_Error; + } catch (const tools::error::wallet_internal_error& e) { + m_errorString = string(tr("internal error: ")) + e.what(); + m_status = Status_Error; + } catch (const std::exception& e) { + m_errorString = string(tr("unexpected error: ")) + e.what(); + m_status = Status_Error; + } catch (...) { + m_errorString = tr("unknown error"); + m_status = Status_Error; + } + } while (false); + + transaction->m_status = m_status; + transaction->m_errorString = m_errorString; + return transaction; +} + +void WalletImpl::disposeTransaction(PendingTransaction *t) +{ + delete t; +} + +TransactionHistory *WalletImpl::history() const +{ + return nullptr; +} + +bool WalletImpl::connectToDaemon() +{ + bool result = m_wallet->check_connection(); + m_status = result ? Status_Ok : Status_Error; + if (!result) { + m_errorString = "Error connecting to daemon at " + m_wallet->get_daemon_address(); + } + return result; +} + +void WalletImpl::clearStatus() +{ + m_status = Status_Ok; + m_errorString.clear(); +} + + +} // namespace diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h new file mode 100644 index 000000000..35db38f67 --- /dev/null +++ b/src/wallet/api/wallet.h @@ -0,0 +1,86 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#ifndef WALLET_IMPL_H +#define WALLET_IMPL_H + +#include "wallet/wallet2_api.h" +#include "wallet/wallet2.h" + +#include + + +namespace Bitmonero { + + +class WalletImpl : public Wallet +{ +public: + WalletImpl(bool testnet = false); + ~WalletImpl(); + bool create(const std::string &path, const std::string &password, + const std::string &language); + bool open(const std::string &path, const std::string &password); + bool recover(const std::string &path, const std::string &seed); + bool close(); + std::string seed() const; + std::string getSeedLanguage() const; + void setSeedLanguage(const std::string &arg); + // void setListener(Listener *) {} + int status() const; + std::string errorString() const; + bool setPassword(const std::string &password); + std::string address() const; + bool store(const std::string &path); + bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit); + bool connectToDaemon(); + uint64_t balance() const; + uint64_t unlockedBalance() const; + bool refresh(); + PendingTransaction * createTransaction(const std::string &dst_addr, uint64_t amount); + virtual void disposeTransaction(PendingTransaction * t); + virtual TransactionHistory * history() const; + +private: + void clearStatus(); + +private: + friend class TransactionImpl; + tools::wallet2 * m_wallet; + int m_status; + std::string m_errorString; + std::string m_password; +}; + + +} // namespace + +#endif + diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp new file mode 100644 index 000000000..c056ada2c --- /dev/null +++ b/src/wallet/api/wallet_manager.cpp @@ -0,0 +1,108 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + + +#include "wallet_manager.h" +#include "wallet.h" + +namespace epee { + unsigned int g_test_dbg_lock_sleep = 0; +} + +namespace Bitmonero { + +Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::string &password, + const std::string &language, bool testnet) +{ + WalletImpl * wallet = new WalletImpl(testnet); + wallet->create(path, password, language); + return wallet; +} + +Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password, bool testnet) +{ + WalletImpl * wallet = new WalletImpl(testnet); + wallet->open(path, password); + return wallet; +} + +Wallet *WalletManagerImpl::recoveryWallet(const std::string &path, const std::string &memo, bool testnet) +{ + WalletImpl * wallet = new WalletImpl(testnet); + wallet->recover(path, memo); + return wallet; +} + +bool WalletManagerImpl::closeWallet(Wallet *wallet) +{ + WalletImpl * wallet_ = dynamic_cast(wallet); + bool result = wallet_->close(); + if (!result) { + m_errorString = wallet_->errorString(); + } else { + delete wallet_; + } + return result; +} + +bool WalletManagerImpl::walletExists(const std::string &path) +{ + return false; +} + +std::string WalletManagerImpl::errorString() const +{ + return m_errorString; +} + +void WalletManagerImpl::setDaemonHost(const std::string &hostname) +{ + +} + + + +///////////////////// WalletManagerFactory implementation ////////////////////// +WalletManager *WalletManagerFactory::getWalletManager() +{ + + static WalletManagerImpl * g_walletManager = nullptr; + + if (!g_walletManager) { + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_MAX); + g_walletManager = new WalletManagerImpl(); + } + + return g_walletManager; +} + + + +} diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h new file mode 100644 index 000000000..d608eb7f0 --- /dev/null +++ b/src/wallet/api/wallet_manager.h @@ -0,0 +1,55 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + + +#include "wallet/wallet2_api.h" +#include + +namespace Bitmonero { + +class WalletManagerImpl : public WalletManager +{ +public: + Wallet * createWallet(const std::string &path, const std::string &password, + const std::string &language, bool testnet); + Wallet * openWallet(const std::string &path, const std::string &password, bool testnet); + virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet); + virtual bool closeWallet(Wallet *wallet); + bool walletExists(const std::string &path); + std::string errorString() const; + void setDaemonHost(const std::string &hostname); + +private: + WalletManagerImpl() {} + friend struct WalletManagerFactory; + std::string m_errorString; +}; + +} // namespace -- cgit v1.2.3 From b6aaf53a6074e8e7181da5c3275e9fef56bf20da Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 20 Apr 2016 13:17:27 +0300 Subject: transaction history api in progress --- src/wallet/api/pending_transaction.cpp | 16 +++++++------- src/wallet/api/transaction_history.cpp | 39 ++++++++++++++++++++++++++++++++++ src/wallet/api/transaction_history.h | 17 ++++++++++++--- src/wallet/api/wallet.cpp | 2 +- src/wallet/api/wallet.h | 7 ++++-- 5 files changed, 67 insertions(+), 14 deletions(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp index e9791ec35..db40851b4 100644 --- a/src/wallet/api/pending_transaction.cpp +++ b/src/wallet/api/pending_transaction.cpp @@ -48,28 +48,28 @@ namespace Bitmonero { PendingTransaction::~PendingTransaction() {} -TransactionImpl::TransactionImpl(WalletImpl *wallet) +PendingTransactionImpl::PendingTransactionImpl(WalletImpl *wallet) : m_wallet(wallet) { } -TransactionImpl::~TransactionImpl() +PendingTransactionImpl::~PendingTransactionImpl() { } -int TransactionImpl::status() const +int PendingTransactionImpl::status() const { return m_status; } -string TransactionImpl::errorString() const +string PendingTransactionImpl::errorString() const { return m_errorString; } -bool TransactionImpl::commit() +bool PendingTransactionImpl::commit() { LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size()); @@ -105,7 +105,7 @@ bool TransactionImpl::commit() return m_status == Status_Ok; } -uint64_t TransactionImpl::amount() const +uint64_t PendingTransactionImpl::amount() const { uint64_t result = 0; for (const auto &ptx : m_pending_tx) { @@ -116,7 +116,7 @@ uint64_t TransactionImpl::amount() const return result; } -uint64_t TransactionImpl::dust() const +uint64_t PendingTransactionImpl::dust() const { uint32_t result = 0; for (const auto & ptx : m_pending_tx) { @@ -125,7 +125,7 @@ uint64_t TransactionImpl::dust() const return result; } -uint64_t TransactionImpl::fee() const +uint64_t PendingTransactionImpl::fee() const { uint32_t result = 0; for (const auto ptx : m_pending_tx) { diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index f1aba14cb..6cc5a961c 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -30,4 +30,43 @@ #include "transaction_history.h" +#include +namespace Bitmonero { + +TransactionHistoryImpl::TransactionHistoryImpl(WalletImpl *wallet) +{ + +} + +TransactionHistoryImpl::~TransactionHistoryImpl() +{ + +} + +int TransactionHistoryImpl::count() const +{ + return 0; +} + +TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) const +{ + return nullptr; +} + +std::vector TransactionHistoryImpl::getAll() const +{ + return std::vector(); +} + +void TransactionHistoryImpl::refresh() +{ + +} + +TransactionInfo *TransactionHistoryImpl::transaction(int index) const +{ + return nullptr; +} + +} diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h index cab0e0dbc..1ff729b54 100644 --- a/src/wallet/api/transaction_history.h +++ b/src/wallet/api/transaction_history.h @@ -32,12 +32,23 @@ namespace Bitmonero { +class TransactionInfo; +class WalletImpl; + class TransactionHistoryImpl : public TransactionHistory { +public: + TransactionHistoryImpl(WalletImpl * wallet); + ~TransactionHistoryImpl(); virtual int count() const; - virtual TransactionInfo * transaction(int index) const = 0; - virtual TransactionInfo * transaction(const std::string &id) const = 0; - virtual std::vector getAll() const = 0; + virtual TransactionInfo * transaction(int index) const; + virtual TransactionInfo * transaction(const std::string &id) const; + virtual std::vector getAll() const; + virtual void refresh(); + +private: + std::vector m_history; + WalletImpl *m_wallet; }; } diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index e42f04cf7..a665fff95 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -288,7 +288,7 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64 if (fake_outs_count == 0) fake_outs_count = DEFAULT_MIX; - TransactionImpl * transaction = new TransactionImpl(this); + PendingTransactionImpl * transaction = new PendingTransactionImpl(this); do { diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 35db38f67..6a654b13e 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -38,7 +38,8 @@ namespace Bitmonero { - +class TransactionHistoryImpl; +class PendingTransactionImpl; class WalletImpl : public Wallet { @@ -72,7 +73,9 @@ private: void clearStatus(); private: - friend class TransactionImpl; + friend class PendingTransactionImpl; + friend class TransactionHistoryImpl; + tools::wallet2 * m_wallet; int m_status; std::string m_errorString; -- cgit v1.2.3 From a213887476136148c9162455d37d4337ef152b68 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 20 Apr 2016 13:33:54 +0300 Subject: transaction history api in progress --- src/wallet/api/transaction_history.cpp | 25 +++++++++++++++++++++++++ src/wallet/api/transaction_info.h | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'src/wallet/api') diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index 6cc5a961c..3ebcc041e 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -28,9 +28,17 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + #include "transaction_history.h" +#include "transaction_info.h" +#include "wallet.h" + +#include "crypto/hash.h" +#include "wallet/wallet2.h" +#include "contrib/epee/include/string_tools.h" #include +#include namespace Bitmonero { @@ -61,7 +69,24 @@ std::vector TransactionHistoryImpl::getAll() const void TransactionHistoryImpl::refresh() { + // TODO: configurable values; + uint64_t min_height = 0; + uint64_t max_height = (uint64_t)-1; + + // TODO: delete old transactions; + + std::list> payments; + m_wallet->m_wallet->get_payments(payments, min_height, max_height); + for (std::list>::const_iterator i = payments.begin(); i != 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) + 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()))); + } } TransactionInfo *TransactionHistoryImpl::transaction(int index) const diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h index 2ed8157f7..3aae19a64 100644 --- a/src/wallet/api/transaction_info.h +++ b/src/wallet/api/transaction_info.h @@ -34,6 +34,8 @@ namespace Bitmonero { +class TransactionHistoryImpl; + class TransactionInfoImpl : public TransactionInfo { public: @@ -47,6 +49,21 @@ public: virtual std::string address() const; virtual std::time_t timestamp() const; virtual std::string paymentId() const; + +private: + int m_direction; + bool m_hold; + bool m_failed; + uint64_t m_amount; + uint64_t m_fee; + uint64_t b_blockheight; + std::string m_address; + std::time_t m_timestamp; + std::string m_paymentid; + + + friend class TransactionHistoryImpl; + }; } // namespace -- cgit v1.2.3 From 02c9df5de247d6f8fb95e1b9272cef2b37be10f8 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 22 Apr 2016 13:21:08 +0300 Subject: Wallet API : transaction history in progress --- src/wallet/api/transaction_history.cpp | 39 ++++++++++++++++++++++++++++------ src/wallet/api/transaction_history.h | 2 ++ src/wallet/api/transaction_info.cpp | 11 +++++++++- src/wallet/api/transaction_info.h | 10 ++++++--- src/wallet/api/wallet.cpp | 5 ++++- src/wallet/api/wallet.h | 1 + 6 files changed, 56 insertions(+), 12 deletions(-) (limited to 'src/wallet/api') 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 #include +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 TransactionHistoryImpl::getAll() const { - return std::vector(); + 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> 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>::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 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; }; -- cgit v1.2.3 From 53a97bdcd381342bc7d738946a628654a2261a52 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 22 Apr 2016 13:33:09 +0300 Subject: Wallet API: transaction history in progress --- src/wallet/api/transaction_history.cpp | 1 + src/wallet/api/transaction_info.cpp | 19 ++++++++++++------- src/wallet/api/transaction_info.h | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index 185cd164f..c7e7472e9 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -103,6 +103,7 @@ void TransactionHistoryImpl::refresh() ti->m_amount = pd.m_amount; ti->m_direction = TransactionInfo::Direction_In; ti->m_hash = string_tools::pod_to_hex(pd.m_tx_hash); + ti->m_blockheight = pd.m_block_height; // TODO: // ti->m_timestamp = pd.m_timestamp; m_history.push_back(ti); diff --git a/src/wallet/api/transaction_info.cpp b/src/wallet/api/transaction_info.cpp index c28c52355..578b84832 100644 --- a/src/wallet/api/transaction_info.cpp +++ b/src/wallet/api/transaction_info.cpp @@ -62,37 +62,42 @@ int TransactionInfoImpl::direction() const bool TransactionInfoImpl::isHold() const { - return false; + return m_hold; } bool TransactionInfoImpl::isFailed() const { - return false; + return m_failed; } uint64_t TransactionInfoImpl::amount() const { - return 0; + return m_amount; } uint64_t TransactionInfoImpl::fee() const { - return 0; + return m_fee; +} + +uint64_t TransactionInfoImpl::blockHeight() const +{ + return m_blockheight; } string TransactionInfoImpl::hash() const { - return ""; + return m_hash; } std::time_t TransactionInfoImpl::timestamp() const { - return std::time_t(0); + return m_timestamp; } string TransactionInfoImpl::paymentId() const { - return ""; + return m_paymentid; } } // namespace diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h index 945b0d9ed..a06bc367e 100644 --- a/src/wallet/api/transaction_info.h +++ b/src/wallet/api/transaction_info.h @@ -49,6 +49,7 @@ public: virtual uint64_t amount() const; //! always 0 for incoming txes virtual uint64_t fee() const; + virtual uint64_t blockHeight() const; virtual std::string hash() const; virtual std::time_t timestamp() const; -- cgit v1.2.3 From 566166aafd29bbca1f4916d4383752945892eb20 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 26 Apr 2016 13:46:20 +0300 Subject: merged with upstream --- src/wallet/api/utils.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++ src/wallet/api/wallet.cpp | 19 ++++++++++-- src/wallet/api/wallet.h | 3 ++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/wallet/api/utils.cpp (limited to 'src/wallet/api') diff --git a/src/wallet/api/utils.cpp b/src/wallet/api/utils.cpp new file mode 100644 index 000000000..aa85323f0 --- /dev/null +++ b/src/wallet/api/utils.cpp @@ -0,0 +1,79 @@ +// Copyright (c) 2014-2016, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + + + +#include "include_base_utils.h" // LOG_PRINT_x +#include "net/http_client.h" // epee::net_utils::... +#include + +using namespace std; + +namespace Bitmonero { +namespace Utils { + + +// copy-pasted from simplewallet. + +bool isAddressLocal(const std::string &address) +{ + // extract host + epee::net_utils::http::url_content u_c; + if (!epee::net_utils::parse_url(address, u_c)) + { + LOG_PRINT_L1("Failed to determine whether daemon is local, assuming not"); + return false; + } + if (u_c.host.empty()) + { + LOG_PRINT_L1("Failed to determine whether daemon is local, assuming not"); + return false; + } + + // resolve to IP + boost::asio::io_service io_service; + boost::asio::ip::tcp::resolver resolver(io_service); + boost::asio::ip::tcp::resolver::query query(u_c.host, ""); + boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query); + while (i != boost::asio::ip::tcp::resolver::iterator()) + { + const boost::asio::ip::tcp::endpoint &ep = *i; + if (ep.address().is_loopback()) + return true; + ++i; + } + + return false; +} + +} + + +} // namespace diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 5f32908de..d9d24b4f0 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -56,7 +56,7 @@ string Wallet::displayAmount(uint64_t amount) ///////////////////////// WalletImpl implementation //////////////////////// WalletImpl::WalletImpl(bool testnet) - :m_wallet(nullptr), m_status(Wallet::Status_Ok) + :m_wallet(nullptr), m_status(Wallet::Status_Ok), m_trustedDaemon(false) { m_wallet = new tools::wallet2(testnet); m_history = new TransactionHistoryImpl(this); @@ -237,6 +237,10 @@ bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transact clearStatus(); try { m_wallet->init(daemon_address, upper_transaction_size_limit); + if (Utils::isAddressLocal(daemon_address)) { + this->setTrustedDaemon(true); + } + } catch (const std::exception &e) { LOG_ERROR("Error initializing wallet: " << e.what()); m_status = Status_Error; @@ -315,7 +319,8 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64 try { - transaction->m_pending_tx = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra); + transaction->m_pending_tx = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, + 0 /* unused fee arg*/, extra, m_trustedDaemon); } catch (const tools::error::daemon_busy&) { // TODO: make it translatable with "tr"? @@ -404,6 +409,16 @@ bool WalletImpl::connectToDaemon() return result; } +void WalletImpl::setTrustedDaemon(bool arg) +{ + m_trustedDaemon = arg; +} + +bool WalletImpl::trustedDaemon() const +{ + return m_trustedDaemon; +} + void WalletImpl::clearStatus() { m_status = Status_Ok; diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 3eaaec59e..3671c2f7a 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -62,6 +62,8 @@ public: bool store(const std::string &path); bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit); bool connectToDaemon(); + void setTrustedDaemon(bool arg); + bool trustedDaemon() const; uint64_t balance() const; uint64_t unlockedBalance() const; bool refresh(); @@ -81,6 +83,7 @@ private: std::string m_errorString; std::string m_password; TransactionHistoryImpl * m_history; + bool m_trustedDaemon; }; -- cgit v1.2.3 From 93119344ecb3326b452f2f8e91bc101fe1896f8c Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 29 Apr 2016 16:26:14 +0300 Subject: TransactionHistory continued --- src/wallet/api/transaction_history.cpp | 79 ++++++++++++++++++++++++++++++++-- src/wallet/api/transaction_info.cpp | 17 ++++++-- src/wallet/api/transaction_info.h | 7 +-- 3 files changed, 92 insertions(+), 11 deletions(-) (limited to 'src/wallet/api') 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> 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>::const_iterator i = payments.begin(); i != payments.end(); ++i) { + // one input transaction contains only one transfer. e.g. - <100XMR> + + std::list> in_payments; + m_wallet->m_wallet->get_payments(in_payments, min_height, max_height); + for (std::list>::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. + // : + // transfer1: 100XMR to + // transfer2: 50XMR to + // fee: fee charged per transaction + // + + std::list> out_payments; + m_wallet->m_wallet->get_payments_out(out_payments, min_height, max_height); + + for (std::list>::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> upayments; + m_wallet->m_wallet->get_unconfirmed_payments_out(upayments); + for (std::list>::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 &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 &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 m_transfers; friend class TransactionHistoryImpl; -- cgit v1.2.3 From 5dbd2b8fc3aa97f3a2e14a378cf6b7afd16bd4e2 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 5 May 2016 22:24:00 +0300 Subject: started WalletListener --- src/wallet/api/wallet.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++- src/wallet/api/wallet.h | 4 ++++ 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index d9d24b4f0..6170000b7 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -47,6 +47,47 @@ namespace { static const size_t DEFAULT_MIX = 4; } +struct Wallet2CallbackImpl : public tools::i_wallet2_callback +{ + + ~Wallet2CallbackImpl() + { + + } + + void setListener(WalletListener * listener) + { + // TODO; + } + + WalletListener * getListener() const + { + return m_listener; + } + + virtual void on_new_block(uint64_t height, const cryptonote::block& block) + { + // TODO; + } + virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, size_t out_index) + { + // TODO; + + } + virtual void on_money_spent(uint64_t height, const cryptonote::transaction& in_tx, size_t out_index, + const cryptonote::transaction& spend_tx) + { + // TODO; + } + + virtual void on_skip_transaction(uint64_t height, const cryptonote::transaction& tx) + { + // TODO; + } + + WalletListener * m_listener; +}; + Wallet::~Wallet() {} string Wallet::displayAmount(uint64_t amount) @@ -56,14 +97,17 @@ string Wallet::displayAmount(uint64_t amount) ///////////////////////// WalletImpl implementation //////////////////////// WalletImpl::WalletImpl(bool testnet) - :m_wallet(nullptr), m_status(Wallet::Status_Ok), m_trustedDaemon(false) + :m_wallet(nullptr), m_status(Wallet::Status_Ok), m_trustedDaemon(false), + m_wallet2Callback(nullptr) { m_wallet = new tools::wallet2(testnet); m_history = new TransactionHistoryImpl(this); + m_wallet2Callback = new Wallet2CallbackImpl; } WalletImpl::~WalletImpl() { + delete m_wallet2Callback; delete m_history; delete m_wallet; } @@ -399,6 +443,14 @@ TransactionHistory *WalletImpl::history() const return m_history; } +void WalletImpl::setListener(WalletListener *l) +{ + // TODO thread synchronization; + m_wallet2Callback->setListener(l); +} + + + bool WalletImpl::connectToDaemon() { bool result = m_wallet->check_connection(); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 3671c2f7a..c0fa31003 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -40,6 +40,7 @@ namespace Bitmonero { class TransactionHistoryImpl; class PendingTransactionImpl; +struct Wallet2CallbackImpl; class WalletImpl : public Wallet { @@ -70,6 +71,7 @@ public: PendingTransaction * createTransaction(const std::string &dst_addr, uint64_t amount); virtual void disposeTransaction(PendingTransaction * t); virtual TransactionHistory * history() const; + virtual void setListener(WalletListener * l); private: void clearStatus(); @@ -84,6 +86,8 @@ private: std::string m_password; TransactionHistoryImpl * m_history; bool m_trustedDaemon; + WalletListener * m_walletListener; + Wallet2CallbackImpl * m_wallet2Callback; }; -- cgit v1.2.3 From 27d86b73c63c7eea0473f11df348fc6a4a3b3e65 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 13 May 2016 16:25:31 +0300 Subject: WalletListener::moneySpent(), WalletListener::moneyReceived() --- src/wallet/api/wallet.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 6170000b7..5819e42bc 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -57,7 +57,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback void setListener(WalletListener * listener) { - // TODO; + m_listener = listener; } WalletListener * getListener() const @@ -68,16 +68,35 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback virtual void on_new_block(uint64_t height, const cryptonote::block& block) { // TODO; + LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height); } + virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, size_t out_index) { - // TODO; + std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(tx)); + uint64_t amount = tx.vout[out_index].amount; + + LOG_PRINT_L3(__FUNCTION__ << ": money received. height: " << height + << ", tx: " << tx_hash + << ", amount: " << print_money(amount)); + if (m_listener) { + m_listener->moneyReceived(tx_hash, amount); + } } + virtual void on_money_spent(uint64_t height, const cryptonote::transaction& in_tx, size_t out_index, const cryptonote::transaction& spend_tx) { // TODO; + std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(spend_tx)); + uint64_t amount = in_tx.vout[out_index].amount; + LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height + << ", tx: " << tx_hash + << ", amount: " << print_money(amount)); + if (m_listener) { + m_listener->moneySpent(tx_hash, amount); + } } virtual void on_skip_transaction(uint64_t height, const cryptonote::transaction& tx) -- cgit v1.2.3 From 40087a745f7677d29642c9ff86e1583c34ed1748 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Mon, 16 May 2016 13:11:44 +0300 Subject: WalletListener::moneySpent test --- src/wallet/api/wallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 5819e42bc..440642291 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -50,6 +50,12 @@ namespace { struct Wallet2CallbackImpl : public tools::i_wallet2_callback { + Wallet2CallbackImpl() + : m_listener(nullptr) + { + + } + ~Wallet2CallbackImpl() { @@ -109,6 +115,8 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback Wallet::~Wallet() {} +WalletListener::~WalletListener() {} + string Wallet::displayAmount(uint64_t amount) { return cryptonote::print_money(amount); -- cgit v1.2.3 From 2facbe77e485e8a824a08d862aa63f3f179480e9 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 3 Jun 2016 14:52:58 +0300 Subject: Wallet API : WalletManager::findWallets() added --- src/wallet/api/wallet_manager.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/wallet/api/wallet_manager.h | 1 + 2 files changed, 38 insertions(+) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index c056ada2c..c578098cc 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -32,6 +32,11 @@ #include "wallet_manager.h" #include "wallet.h" +#include +#include + +namespace fs = ::boost::filesystem; + namespace epee { unsigned int g_test_dbg_lock_sleep = 0; } @@ -77,6 +82,38 @@ bool WalletManagerImpl::walletExists(const std::string &path) return false; } + +std::vector WalletManagerImpl::findWallets(const std::string &path) +{ + std::vector result; + const boost::regex wallet_rx("(.*)\\.(address\\.txt)$"); + boost::filesystem::recursive_directory_iterator end_itr; // Default ctor yields past-the-end + boost::filesystem::path work_dir(path); + + for (boost::filesystem::recursive_directory_iterator itr(path); itr != end_itr; ++itr) { + // Skip if not a file + if (!boost::filesystem::is_regular_file(itr->status())) + continue; + boost::smatch what; + std::string filename = itr->path().filename().string(); + + LOG_PRINT_L3("Checking filename: " << filename); + + bool matched = boost::regex_match(filename, what, wallet_rx); + if (matched) { + // if address file found, checking if there's corresponding .keys file and wallet file itself + std::string wallet_file = (itr->path().parent_path() /= what[1]).string(); + std::string wallet_key_file = wallet_file + std::string(".keys"); + if (boost::filesystem::exists(wallet_file) + && boost::filesystem::exists(wallet_key_file)) { + LOG_PRINT_L3("Found wallet: " << wallet_file); + result.push_back(wallet_file); + } + } + } + return result; +} + std::string WalletManagerImpl::errorString() const { return m_errorString; diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h index d608eb7f0..7585c1af7 100644 --- a/src/wallet/api/wallet_manager.h +++ b/src/wallet/api/wallet_manager.h @@ -43,6 +43,7 @@ public: virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet); virtual bool closeWallet(Wallet *wallet); bool walletExists(const std::string &path); + std::vector findWallets(const std::string &path); std::string errorString() const; void setDaemonHost(const std::string &hostname); -- cgit v1.2.3 From 8f9d98b3e0cc552074ddb3f59da6399e855af311 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 3 Jun 2016 16:56:13 +0300 Subject: removed unused "using" --- src/wallet/api/wallet_manager.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index c578098cc..2327d11f8 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -35,7 +35,6 @@ #include #include -namespace fs = ::boost::filesystem; namespace epee { unsigned int g_test_dbg_lock_sleep = 0; -- cgit v1.2.3 From c554055ce435ae2752820ba317d801f143804b3c Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 10 Jun 2016 12:51:09 +0300 Subject: Wallet::filename, Wallet::keysFilename, tests for move wallet --- src/wallet/api/wallet.cpp | 10 ++++++++++ src/wallet/api/wallet.h | 2 ++ 2 files changed, 12 insertions(+) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 440642291..5b68387ea 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -303,6 +303,16 @@ bool WalletImpl::store(const std::string &path) return m_status == Status_Ok; } +string WalletImpl::filename() const +{ + return m_wallet->get_wallet_file(); +} + +string WalletImpl::keysFilename() const +{ + return m_wallet->get_keys_file(); +} + bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) { clearStatus(); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index c0fa31003..c402ef53c 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -61,6 +61,8 @@ public: bool setPassword(const std::string &password); std::string address() const; bool store(const std::string &path); + std::string filename() const; + std::string keysFilename() const; bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit); bool connectToDaemon(); void setTrustedDaemon(bool arg); -- cgit v1.2.3 From 3ac20a46b38f88757c57cbcf8581cade312b7936 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 10 Jun 2016 13:52:10 +0300 Subject: wallet::default_mixin exposed to public interface as Wallet::setDefaultMixin, Wallet::defaultMixin; wallet::create_transaction_2 used in Wallet::createTransaction --- src/wallet/api/wallet.cpp | 11 ++++++++++- src/wallet/api/wallet.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 5b68387ea..f6d7a561e 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -400,7 +400,7 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64 try { - transaction->m_pending_tx = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, + transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra, m_trustedDaemon); } catch (const tools::error::daemon_busy&) { @@ -486,6 +486,15 @@ void WalletImpl::setListener(WalletListener *l) m_wallet2Callback->setListener(l); } +uint32_t WalletImpl::defaultMixin() const +{ + return m_wallet->default_mixin(); +} + +void WalletImpl::setDefaultMixin(uint32_t arg) +{ + m_wallet->default_mixin(arg); +} bool WalletImpl::connectToDaemon() diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index c402ef53c..6c8913c25 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -74,6 +74,8 @@ public: virtual void disposeTransaction(PendingTransaction * t); virtual TransactionHistory * history() const; virtual void setListener(WalletListener * l); + virtual uint32_t defaultMixin() const; + virtual void setDefaultMixin(uint32_t arg); private: void clearStatus(); -- cgit v1.2.3 From 3318addafaf6ac7b5489f7d774083a84dce7dfa0 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 16 Jun 2016 16:42:33 +0300 Subject: double/string to monero integer convertion methods --- src/wallet/api/wallet.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index f6d7a561e..1f414b3bf 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -36,6 +36,7 @@ #include "mnemonics/electrum-words.h" #include +#include using namespace std; using namespace cryptonote; @@ -122,6 +123,22 @@ string Wallet::displayAmount(uint64_t amount) return cryptonote::print_money(amount); } +uint64_t Wallet::amountFromString(const string &amount) +{ + uint64_t result; + cryptonote::parse_amount(result, amount); + return result; +} + +uint64_t Wallet::amountFromDouble(double amount) +{ + std::stringstream ss; + ss << std::fixed << std::setprecision(CRYPTONOTE_DISPLAY_DECIMAL_POINT) << amount; + return amountFromString(ss.str()); +} + + + ///////////////////////// WalletImpl implementation //////////////////////// WalletImpl::WalletImpl(bool testnet) :m_wallet(nullptr), m_status(Wallet::Status_Ok), m_trustedDaemon(false), -- cgit v1.2.3 From f1c4a376af916604e2b142a1169d610f631bd91c Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Mon, 20 Jun 2016 22:56:30 +0300 Subject: Wallet::createTransaction: added mixin_count param --- src/wallet/api/wallet.cpp | 18 +++++++++++------- src/wallet/api/wallet.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 1f414b3bf..d72ebc8da 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -45,7 +45,7 @@ namespace Bitmonero { namespace { // copy-pasted from simplewallet - static const size_t DEFAULT_MIX = 4; + static const size_t DEFAULT_MIXIN = 4; } struct Wallet2CallbackImpl : public tools::i_wallet2_callback @@ -380,7 +380,7 @@ bool WalletImpl::refresh() // - payment_details; // - unconfirmed_transfer_details; // - confirmed_transfer_details) -PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64_t amount) +PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64_t amount, uint32_t mixin_count) { clearStatus(); vector dsts; @@ -389,9 +389,10 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64 crypto::hash8 new_payment_id; // TODO: (https://bitcointalk.org/index.php?topic=753252.msg9985441#msg9985441) - size_t fake_outs_count = m_wallet->default_mixin(); + + size_t fake_outs_count = mixin_count > 0 ? mixin_count : m_wallet->default_mixin(); if (fake_outs_count == 0) - fake_outs_count = DEFAULT_MIX; + fake_outs_count = DEFAULT_MIXIN; PendingTransactionImpl * transaction = new PendingTransactionImpl(this); @@ -436,27 +437,30 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, uint64 } catch (const tools::error::not_enough_money& e) { m_status = Status_Error; - std::ostringstream writer(m_errorString); + std::ostringstream writer; writer << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) % print_money(e.available()) % print_money(e.tx_amount() + e.fee()) % print_money(e.tx_amount()) % print_money(e.fee()); + m_errorString = writer.str(); } catch (const tools::error::not_enough_outs_to_mix& e) { - std::ostringstream writer(m_errorString); + std::ostringstream writer; writer << tr("not enough outputs for specified mixin_count") << " = " << e.mixin_count() << ":"; for (const cryptonote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& outs_for_amount : e.scanty_outs()) { writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.amount) << ", " << tr("found outputs to mix") << " = " << outs_for_amount.outs.size(); } + m_errorString = writer.str(); m_status = Status_Error; } catch (const tools::error::tx_not_constructed&) { m_errorString = tr("transaction was not constructed"); m_status = Status_Error; } catch (const tools::error::tx_rejected& e) { - std::ostringstream writer(m_errorString); + std::ostringstream writer; writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status(); + m_errorString = writer.str(); m_status = Status_Error; } catch (const tools::error::tx_sum_overflow& e) { m_errorString = e.what(); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 6c8913c25..016116e96 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -70,7 +70,7 @@ public: uint64_t balance() const; uint64_t unlockedBalance() const; bool refresh(); - PendingTransaction * createTransaction(const std::string &dst_addr, uint64_t amount); + PendingTransaction * createTransaction(const std::string &dst_addr, uint64_t amount, uint32_t mixin_count); virtual void disposeTransaction(PendingTransaction * t); virtual TransactionHistory * history() const; virtual void setListener(WalletListener * l); -- cgit v1.2.3 From 7b7cf21644f013cc9d43716b72bca8b42362832c Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 22 Jun 2016 15:06:19 +0300 Subject: commented regex --- src/wallet/api/wallet_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index 2327d11f8..3a97538b4 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -85,7 +85,7 @@ bool WalletManagerImpl::walletExists(const std::string &path) std::vector WalletManagerImpl::findWallets(const std::string &path) { std::vector result; - const boost::regex wallet_rx("(.*)\\.(address\\.txt)$"); + const boost::regex wallet_rx("(.*)\\.(address\\.txt)$"); // searching for .address.txt files boost::filesystem::recursive_directory_iterator end_itr; // Default ctor yields past-the-end boost::filesystem::path work_dir(path); -- cgit v1.2.3 From 4e5521d87d3897e8ce547e7bf11ef24024a9dbdf Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 22 Jun 2016 15:50:59 +0300 Subject: PendingTransactionImpl: pointer->reference --- src/wallet/api/pending_transaction.cpp | 4 ++-- src/wallet/api/pending_transaction.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/wallet/api') diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp index db40851b4..c4a770f87 100644 --- a/src/wallet/api/pending_transaction.cpp +++ b/src/wallet/api/pending_transaction.cpp @@ -48,7 +48,7 @@ namespace Bitmonero { PendingTransaction::~PendingTransaction() {} -PendingTransactionImpl::PendingTransactionImpl(WalletImpl *wallet) +PendingTransactionImpl::PendingTransactionImpl(WalletImpl &wallet) : m_wallet(wallet) { @@ -77,7 +77,7 @@ bool PendingTransactionImpl::commit() try { while (!m_pending_tx.empty()) { auto & ptx = m_pending_tx.back(); - m_wallet->m_wallet->commit_tx(ptx); + m_wallet.m_wallet->commit_tx(ptx); // success_msg_writer(true) << tr("Money successfully sent, transaction ") << get_transaction_hash(ptx.tx); // if no exception, remove element from vector m_pending_tx.pop_back(); diff --git a/src/wallet/api/pending_transaction.h b/src/wallet/api/pending_transaction.h index 0ae3eb8e2..8e09bec91 100644 --- a/src/wallet/api/pending_transaction.h +++ b/src/wallet/api/pending_transaction.h @@ -41,7 +41,7 @@ class WalletImpl; class PendingTransactionImpl : public PendingTransaction { public: - PendingTransactionImpl(WalletImpl * wallet); + PendingTransactionImpl(WalletImpl &wallet); ~PendingTransactionImpl(); int status() const; std::string errorString() const; @@ -53,7 +53,7 @@ public: private: friend class WalletImpl; - WalletImpl * m_wallet; + WalletImpl &m_wallet; int m_status; std::string m_errorString; -- cgit v1.2.3