aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/CMakeLists.txt14
-rw-r--r--src/wallet/api/common_defines.h7
-rw-r--r--src/wallet/api/pending_transaction.cpp138
-rw-r--r--src/wallet/api/pending_transaction.h64
-rw-r--r--src/wallet/api/transaction_history.cpp123
-rw-r--r--src/wallet/api/transaction_history.h57
-rw-r--r--src/wallet/api/transaction_info.cpp103
-rw-r--r--src/wallet/api/transaction_info.h74
-rw-r--r--src/wallet/api/wallet.cpp414
-rw-r--r--src/wallet/api/wallet.h90
-rw-r--r--src/wallet/api/wallet_manager.cpp108
-rw-r--r--src/wallet/api/wallet_manager.h55
-rw-r--r--src/wallet/wallet2.cpp127
-rw-r--r--src/wallet/wallet2.h1
-rw-r--r--src/wallet/wallet2_api.cpp346
-rw-r--r--src/wallet/wallet2_api.h82
16 files changed, 1375 insertions, 428 deletions
diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt
index a6fc37dec..33af4f30d 100644
--- a/src/wallet/CMakeLists.txt
+++ b/src/wallet/CMakeLists.txt
@@ -32,17 +32,27 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(wallet_sources
wallet2.cpp
wallet_rpc_server.cpp
- wallet2_api.cpp)
+ api/wallet.cpp
+ api/wallet_manager.cpp
+ api/transaction_info.cpp
+ api/transaction_history.cpp
+ api/pending_transaction.cpp)
set(wallet_headers)
set(wallet_private_headers
wallet2.h
+ wallet2_api.h
wallet_errors.h
wallet_rpc_server.h
wallet_rpc_server_commands_defs.h
wallet_rpc_server_error_codes.h
- wallet2_api.h)
+ api/wallet.h
+ api/wallet_manager.h
+ api/transaction_info.h
+ api/transaction_history.h
+ api/pending_transaction.h
+ api/common_defines.h)
bitmonero_private_headers(wallet
${wallet_private_headers})
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..db40851b4
--- /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 <memory>
+#include <vector>
+#include <sstream>
+#include <boost/format.hpp>
+
+using namespace std;
+
+namespace Bitmonero {
+
+PendingTransaction::~PendingTransaction() {}
+
+
+PendingTransactionImpl::PendingTransactionImpl(WalletImpl *wallet)
+ : m_wallet(wallet)
+{
+
+}
+
+PendingTransactionImpl::~PendingTransactionImpl()
+{
+
+}
+
+int PendingTransactionImpl::status() const
+{
+ return m_status;
+}
+
+string PendingTransactionImpl::errorString() const
+{
+ return m_errorString;
+}
+
+bool PendingTransactionImpl::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 PendingTransactionImpl::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 PendingTransactionImpl::dust() const
+{
+ uint32_t result = 0;
+ for (const auto & ptx : m_pending_tx) {
+ result += ptx.dust;
+ }
+ return result;
+}
+
+uint64_t PendingTransactionImpl::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 <string>
+#include <vector>
+
+
+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<tools::wallet2::pending_tx> 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..c7e7472e9
--- /dev/null
+++ b/src/wallet/api/transaction_history.cpp
@@ -0,0 +1,123 @@
+// 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"
+#include "transaction_info.h"
+#include "wallet.h"
+
+#include "crypto/hash.h"
+#include "wallet/wallet2.h"
+
+
+#include <string>
+#include <list>
+
+using namespace epee;
+
+namespace Bitmonero {
+
+TransactionHistory::~TransactionHistory() {}
+
+
+TransactionHistoryImpl::TransactionHistoryImpl(WalletImpl *wallet)
+ : m_wallet(wallet)
+{
+
+}
+
+TransactionHistoryImpl::~TransactionHistoryImpl()
+{
+
+}
+
+int TransactionHistoryImpl::count() const
+{
+ return m_history.size();
+}
+
+TransactionInfo *TransactionHistoryImpl::transaction(const std::string &id) const
+{
+ return nullptr;
+}
+
+std::vector<TransactionInfo *> TransactionHistoryImpl::getAll() const
+{
+ return m_history;
+}
+
+void TransactionHistoryImpl::refresh()
+{
+ // TODO: configurable values;
+ uint64_t min_height = 0;
+ uint64_t max_height = (uint64_t)-1;
+
+ // 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;
+ 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
+ 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);
+ ti->m_blockheight = pd.m_block_height;
+ // 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())));*/
+ }
+}
+
+TransactionInfo *TransactionHistoryImpl::transaction(int index) const
+{
+ return nullptr;
+}
+
+}
diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h
new file mode 100644
index 000000000..171fd2210
--- /dev/null
+++ b/src/wallet/api/transaction_history.h
@@ -0,0 +1,57 @@
+// 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 TransactionInfo;
+class WalletImpl;
+
+class TransactionHistoryImpl : public TransactionHistory
+{
+public:
+ TransactionHistoryImpl(WalletImpl * wallet);
+ ~TransactionHistoryImpl();
+ virtual int count() const;
+ virtual TransactionInfo * transaction(int index) const;
+ virtual TransactionInfo * transaction(const std::string &id) const;
+ virtual std::vector<TransactionInfo*> getAll() const;
+ 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
new file mode 100644
index 000000000..578b84832
--- /dev/null
+++ b/src/wallet/api/transaction_info.cpp
@@ -0,0 +1,103 @@
+// 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 {
+
+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)
+{
+
+}
+
+TransactionInfoImpl::~TransactionInfoImpl()
+{
+
+}
+
+int TransactionInfoImpl::direction() const
+{
+ return TransactionInfo::Direction_In;
+}
+
+
+bool TransactionInfoImpl::isHold() const
+{
+ return m_hold;
+}
+
+bool TransactionInfoImpl::isFailed() const
+{
+ return m_failed;
+}
+
+uint64_t TransactionInfoImpl::amount() const
+{
+ return m_amount;
+}
+
+uint64_t TransactionInfoImpl::fee() const
+{
+ return m_fee;
+}
+
+uint64_t TransactionInfoImpl::blockHeight() const
+{
+ return m_blockheight;
+}
+
+string TransactionInfoImpl::hash() const
+{
+ return m_hash;
+}
+
+std::time_t TransactionInfoImpl::timestamp() const
+{
+ return m_timestamp;
+}
+
+string TransactionInfoImpl::paymentId() const
+{
+ return m_paymentid;
+}
+
+} // namespace
diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h
new file mode 100644
index 000000000..a06bc367e
--- /dev/null
+++ b/src/wallet/api/transaction_info.h
@@ -0,0 +1,74 @@
+// 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 <string>
+#include <ctime>
+
+namespace Bitmonero {
+
+class TransactionHistoryImpl;
+
+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 uint64_t blockHeight() const;
+
+ virtual std::string hash() 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 m_blockheight;
+ std::string m_hash;
+ std::time_t m_timestamp;
+ std::string m_paymentid;
+
+
+ friend class TransactionHistoryImpl;
+
+};
+
+} // namespace
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
new file mode 100644
index 000000000..5f32908de
--- /dev/null
+++ b/src/wallet/api/wallet.cpp
@@ -0,0 +1,414 @@
+// 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 "transaction_history.h"
+#include "common_defines.h"
+
+#include "mnemonics/electrum-words.h"
+#include <boost/format.hpp>
+
+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);
+ m_history = new TransactionHistoryImpl(this);
+}
+
+WalletImpl::~WalletImpl()
+{
+ delete m_history;
+ 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<cryptonote::tx_destination_entry> 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;
+
+ PendingTransactionImpl * transaction = new PendingTransactionImpl(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<tools::wallet2::pending_tx> ptx_vector;
+ std::vector<uint8_t> 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 m_history;
+}
+
+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..3eaaec59e
--- /dev/null
+++ b/src/wallet/api/wallet.h
@@ -0,0 +1,90 @@
+// 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 <string>
+
+
+namespace Bitmonero {
+class TransactionHistoryImpl;
+class PendingTransactionImpl;
+
+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 PendingTransactionImpl;
+ friend class TransactionHistoryImpl;
+
+ tools::wallet2 * m_wallet;
+ int m_status;
+ std::string m_errorString;
+ std::string m_password;
+ TransactionHistoryImpl * m_history;
+};
+
+
+} // 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<WalletImpl*>(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 <string>
+
+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
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 14da8d7a2..1be715dbd 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1447,6 +1447,42 @@ void wallet2::check_genesis(const crypto::hash& genesis_hash) const {
//----------------------------------------------------------------------------------------------------
void wallet2::store()
{
+ store_to("", "");
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::store_to(const std::string &path, const std::string &password)
+{
+ // if file is the same, we do:
+ // 1. save wallet to the *.new file
+ // 2. remove old wallet file
+ // 3. rename *.new to wallet_name
+
+ // handle if we want just store wallet state to current files (ex store() replacement);
+ bool same_file = true;
+ if (!path.empty())
+ {
+ std::string canonical_path = boost::filesystem::canonical(m_wallet_file).string();
+ size_t pos = canonical_path.find(path);
+ same_file = pos != std::string::npos;
+ }
+
+
+ if (!same_file)
+ {
+ // check if we want to store to directory which doesn't exists yet
+ boost::filesystem::path parent_path = boost::filesystem::path(path).parent_path();
+
+ // if path is not exists, try to create it
+ if (!parent_path.empty() && !boost::filesystem::exists(parent_path))
+ {
+ boost::system::error_code ec;
+ if (!boost::filesystem::create_directories(parent_path, ec))
+ {
+ throw std::logic_error(ec.message());
+ }
+ }
+ }
+ // preparing wallet data
std::stringstream oss;
boost::archive::binary_oarchive ar(oss);
ar << *this;
@@ -1461,10 +1497,10 @@ void wallet2::store()
crypto::chacha8(cache_file_data.cache_data.data(), cache_file_data.cache_data.size(), key, cache_file_data.iv, &cipher[0]);
cache_file_data.cache_data = cipher;
- // save to new file, rename main to old, rename new to main
- // at all times, there should be a valid file on disk
- const std::string new_file = m_wallet_file + ".new";
- const std::string old_file = m_wallet_file + ".old";
+ const std::string new_file = same_file ? m_wallet_file + ".new" : path;
+ const std::string old_file = m_wallet_file;
+ const std::string old_keys_file = m_keys_file;
+ const std::string old_address_file = m_wallet_file + ".address.txt";
// save to new file
std::ofstream ostr;
@@ -1474,87 +1510,35 @@ void wallet2::store()
ostr.close();
THROW_WALLET_EXCEPTION_IF(!success || !ostr.good(), error::file_save_error, new_file);
- // rename
- boost::filesystem::remove(old_file); // probably does not exist
- if (boost::filesystem::exists(m_wallet_file)) {
- std::error_code e = tools::replace_file(m_wallet_file, old_file);
- THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e);
- }
- std::error_code e = tools::replace_file(new_file, m_wallet_file);
- THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e);
- boost::filesystem::remove(old_file);
-}
-
-void wallet2::store_to(const std::string &path, const std::string &password)
-{
- // TODO: merge it with wallet2::store() function
-
- // check if we want to store to directory which doesn't exists yet
- boost::filesystem::path parent_path = boost::filesystem::path(path).parent_path();
-
- // if path is not exists, try to create it
- if (!parent_path.empty() && !boost::filesystem::exists(parent_path)) {
- boost::system::error_code ec;
- if (!boost::filesystem::create_directories(parent_path, ec)) {
- throw std::logic_error(ec.message());
- }
- }
-
-
- std::stringstream oss;
- boost::archive::binary_oarchive ar(oss);
- ar << *this;
-
- wallet2::cache_file_data cache_file_data = boost::value_initialized<wallet2::cache_file_data>();
- cache_file_data.cache_data = oss.str();
- crypto::chacha8_key key;
- generate_chacha8_key_from_secret_keys(key);
- std::string cipher;
- cipher.resize(cache_file_data.cache_data.size());
- cache_file_data.iv = crypto::rand<crypto::chacha8_iv>();
- crypto::chacha8(cache_file_data.cache_data.data(), cache_file_data.cache_data.size(), key, cache_file_data.iv, &cipher[0]);
- cache_file_data.cache_data = cipher;
-
-
- const std::string new_file = path;
- const std::string old_file = m_wallet_file;
- const std::string old_keys_file = m_keys_file;
- const std::string old_address_file = m_wallet_file + ".address.txt";
-
- // save to new file
- std::ofstream ostr;
- ostr.open(new_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
- binary_archive<true> oar(ostr);
- bool success = ::serialization::serialize(oar, cache_file_data);
- ostr.close();
- THROW_WALLET_EXCEPTION_IF(!success || !ostr.good(), error::file_save_error, new_file);
-
- // save keys to the new file
- // if we here, main wallet file is saved and we only need to save keys and address files
+ // save keys to the new file
+ // if we here, main wallet file is saved and we only need to save keys and address files
+ if (!same_file) {
prepare_file_names(path);
store_keys(m_keys_file, password, false);
-
// save address to the new file
const std::string address_file = m_wallet_file + ".address.txt";
bool r = file_io_utils::save_string_to_file(address_file, m_account.get_public_address_str(m_testnet));
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_wallet_file);
-
-
// remove old wallet file
r = boost::filesystem::remove(old_file);
if (!r) {
- LOG_ERROR("error removing file: " << old_file);
+ LOG_ERROR("error removing file: " << old_file);
}
// remove old keys file
r = boost::filesystem::remove(old_keys_file);
if (!r) {
- LOG_ERROR("error removing file: " << old_keys_file);
+ LOG_ERROR("error removing file: " << old_keys_file);
}
// remove old address file
r = boost::filesystem::remove(old_address_file);
if (!r) {
- LOG_ERROR("error removing file: " << old_address_file);
+ LOG_ERROR("error removing file: " << old_address_file);
}
+ } else {
+ // here we have "*.new" file, we need to rename it to be without ".new"
+ std::error_code e = tools::replace_file(new_file, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e);
+ }
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::unlocked_balance() const
@@ -2838,12 +2822,17 @@ bool wallet2::get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) c
std::string wallet2::get_wallet_file() const
{
- return m_wallet_file;
+ return m_wallet_file;
}
std::string wallet2::get_keys_file() const
{
- return m_keys_file;
+ return m_keys_file;
+}
+
+std::string wallet2::get_daemon_address() const
+{
+ return m_daemon_address;
}
//----------------------------------------------------------------------------------------------------
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 179d1553e..0c3d8eab1 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -364,6 +364,7 @@ namespace tools
std::string get_wallet_file() const;
std::string get_keys_file() const;
+ std::string get_daemon_address() const;
private:
/*!
* \brief Stores wallet information to wallet file.
diff --git a/src/wallet/wallet2_api.cpp b/src/wallet/wallet2_api.cpp
deleted file mode 100644
index 0644e3690..000000000
--- a/src/wallet/wallet2_api.cpp
+++ /dev/null
@@ -1,346 +0,0 @@
-// 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 "wallet2_api.h"
-#include "wallet2.h"
-#include "mnemonics/electrum-words.h"
-#include <memory>
-
-namespace epee {
- unsigned int g_test_dbg_lock_sleep = 0;
-}
-
-namespace Bitmonero {
-
-struct WalletManagerImpl;
-
-namespace {
- static WalletManagerImpl * g_walletManager = nullptr;
-
-
-
-}
-
-Wallet::~Wallet() {}
-
-///////////////////////// Wallet implementation ////////////////////////////////
-class WalletImpl : public Wallet
-{
-public:
- WalletImpl();
- ~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);
-
-private:
- void clearStatus();
-
-private:
- //std::unique_ptr<tools::wallet2> m_wallet;
- tools::wallet2 * m_wallet;
- int m_status;
- std::string m_errorString;
- std::string m_password;
-};
-
-WalletImpl::WalletImpl()
- :m_wallet(nullptr), m_status(Wallet::Status_Ok)
-{
- m_wallet = new tools::wallet2();
-}
-
-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;
-}
-
-void WalletImpl::clearStatus()
-{
- m_status = Status_Ok;
- m_errorString.clear();
-}
-
-
-
-///////////////////////// WalletManager implementation /////////////////////////
-class WalletManagerImpl : public WalletManager
-{
-public:
- Wallet * createWallet(const std::string &path, const std::string &password,
- const std::string &language);
- Wallet * openWallet(const std::string &path, const std::string &password);
- virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo);
- virtual bool closeWallet(Wallet *wallet);
- bool walletExists(const std::string &path);
- std::string errorString() const;
-
-
-private:
- WalletManagerImpl() {}
- friend struct WalletManagerFactory;
-
- std::string m_errorString;
-};
-
-Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::string &password,
- const std::string &language)
-{
- WalletImpl * wallet = new WalletImpl();
- wallet->create(path, password, language);
- return wallet;
-}
-
-Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password)
-{
- WalletImpl * wallet = new WalletImpl();
- wallet->open(path, password);
- return wallet;
-}
-
-Wallet *WalletManagerImpl::recoveryWallet(const std::string &path, const std::string &memo)
-{
- WalletImpl * wallet = new WalletImpl();
- wallet->recover(path, memo);
- return wallet;
-}
-
-bool WalletManagerImpl::closeWallet(Wallet *wallet)
-{
- WalletImpl * wallet_ = dynamic_cast<WalletImpl*>(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;
-}
-
-
-
-///////////////////// WalletManagerFactory implementation //////////////////////
-WalletManager *WalletManagerFactory::getWalletManager()
-{
-
- if (!g_walletManager) {
- epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_0);
- g_walletManager = new WalletManagerImpl();
- }
-
- return g_walletManager;
-}
-
-}
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index c7e7c536c..4954db0d2 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -32,10 +32,64 @@
#include <string>
+#include <vector>
+#include <ctime>
// Public interface for libwallet library
namespace Bitmonero {
+/**
+ * @brief Transaction-like interface for sending money
+ */
+struct PendingTransaction
+{
+ enum Status {
+ Status_Ok,
+ Status_Error
+ };
+ virtual ~PendingTransaction() = 0;
+ virtual int status() const = 0;
+ virtual std::string errorString() const = 0;
+ virtual bool commit() = 0;
+ virtual uint64_t amount() const = 0;
+ virtual uint64_t dust() const = 0;
+ virtual uint64_t fee() const = 0;
+};
+
+/**
+ * @brief The TransactionInfo - interface for displaying transaction information
+ */
+struct TransactionInfo
+{
+ enum Direction {
+ Direction_In,
+ Direction_Out
+ };
+ virtual ~TransactionInfo() = 0;
+ virtual int direction() const = 0;
+ virtual bool isHold() const = 0;
+ virtual bool isFailed() const = 0;
+ virtual uint64_t amount() const = 0;
+ virtual uint64_t fee() const = 0;
+ virtual uint64_t blockHeight() const = 0;
+ virtual std::string hash() const = 0;
+ virtual std::time_t timestamp() const = 0;
+ virtual std::string paymentId() const = 0;
+};
+/**
+ * @brief The TransactionHistory - interface for displaying transaction history
+ */
+struct TransactionHistory
+{
+ virtual ~TransactionHistory() = 0;
+ virtual int count() const = 0;
+ virtual TransactionInfo * transaction(int index) const = 0;
+ virtual TransactionInfo * transaction(const std::string &id) const = 0;
+ virtual std::vector<TransactionInfo*> getAll() const = 0;
+ virtual void refresh() = 0;
+};
+
+
/**
* @brief Interface for wallet operations.
@@ -43,23 +97,17 @@ namespace Bitmonero {
*/
struct Wallet
{
- // TODO define wallet interface (decide what needed from wallet2)
enum Status {
Status_Ok,
Status_Error
};
- struct Listener
- {
- // TODO
- };
-
virtual ~Wallet() = 0;
virtual std::string seed() const = 0;
virtual std::string getSeedLanguage() const = 0;
virtual void setSeedLanguage(const std::string &arg) = 0;
- virtual void setListener(Listener * listener) = 0;
+ // virtual void setListener(Listener * listener) = 0;
//! returns wallet status (Status_Ok | Status_Error)
virtual int status() const = 0;
//! in case error status, returns error string
@@ -67,6 +115,17 @@ struct Wallet
virtual bool setPassword(const std::string &password) = 0;
virtual std::string address() const = 0;
virtual bool store(const std::string &path) = 0;
+ virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0;
+ virtual bool connectToDaemon() = 0;
+ virtual uint64_t balance() const = 0;
+ virtual uint64_t unlockedBalance() const = 0;
+ static std::string displayAmount(uint64_t amount);
+ // TODO?
+ // virtual uint64_t unlockedDustBalance() const = 0;
+ virtual bool refresh() = 0;
+ virtual PendingTransaction * createTransaction(const std::string &dst_addr, uint64_t amount) = 0;
+ virtual void disposeTransaction(PendingTransaction * t) = 0;
+ virtual TransactionHistory * history() const = 0;
};
/**
@@ -82,7 +141,7 @@ struct WalletManager
* \param language Language to be used to generate electrum seed memo
* \return Wallet instance (Wallet::status() needs to be called to check if created successfully)
*/
- virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language) = 0;
+ virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language, bool testnet = false) = 0;
/*!
* \brief Opens existing wallet
@@ -90,7 +149,7 @@ struct WalletManager
* \param password Password of wallet file
* \return Wallet instance (Wallet::status() needs to be called to check if opened successfully)
*/
- virtual Wallet * openWallet(const std::string &path, const std::string &password) = 0;
+ virtual Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) = 0;
/*!
* \brief recovers existing wallet using memo (electrum seed)
@@ -98,7 +157,7 @@ struct WalletManager
* \param memo memo (25 words electrum seed)
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
*/
- virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo) = 0;
+ virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet = false) = 0;
/*!
* \brief Closes wallet. In case operation succeded, wallet object deleted. in case operation failed, wallet object not deleted
@@ -111,7 +170,8 @@ struct WalletManager
virtual bool walletExists(const std::string &path) = 0;
virtual std::string errorString() const = 0;
-
+// //! set
+// virtual void setDaemonAddress(const std::string &address) = 0;
};