diff options
author | Ilya Kitaev <mbg033@gmail.com> | 2016-03-25 17:06:30 +0300 |
---|---|---|
committer | Ilya Kitaev <mbg033@gmail.com> | 2016-03-25 17:06:30 +0300 |
commit | 8790904cf9ccba56a1cbab51b01f2cbb0a5cb143 (patch) | |
tree | 119b5c86a03d2ee3f02b67228400d92777f672b0 /src/wallet | |
parent | wallet2::store() implemented within wallet2::store_to (diff) | |
download | monero-8790904cf9ccba56a1cbab51b01f2cbb0a5cb143.tar.xz |
- testnet option added to api;
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet2.cpp | 5 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 1 | ||||
-rw-r--r-- | src/wallet/wallet2_api.cpp | 50 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 11 |
4 files changed, 54 insertions, 13 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9592810e7..f263346a7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2761,6 +2761,11 @@ std::string wallet2::get_keys_file() const return m_keys_file; } +std::string wallet2::get_daemon_address() const +{ + return m_daemon_address; +} + //---------------------------------------------------------------------------------------------------- void wallet2::generate_genesis(cryptonote::block& b) { if (m_testnet) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f798f404d..60814b7ed 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -359,6 +359,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 index cf1a2bf24..31015b355 100644 --- a/src/wallet/wallet2_api.cpp +++ b/src/wallet/wallet2_api.cpp @@ -54,7 +54,7 @@ Wallet::~Wallet() {} class WalletImpl : public Wallet { public: - WalletImpl(); + WalletImpl(bool testnet = false); ~WalletImpl(); bool create(const std::string &path, const std::string &password, const std::string &language); @@ -70,6 +70,9 @@ public: 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); + uint64_t balance() const; + bool connectToDaemon(); private: void clearStatus(); @@ -82,10 +85,10 @@ private: std::string m_password; }; -WalletImpl::WalletImpl() +WalletImpl::WalletImpl(bool testnet) :m_wallet(nullptr), m_status(Wallet::Status_Ok) { - m_wallet = new tools::wallet2(); + m_wallet = new tools::wallet2(testnet); } WalletImpl::~WalletImpl() @@ -257,6 +260,35 @@ bool WalletImpl::store(const std::string &path) 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(); +} + +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; @@ -270,8 +302,8 @@ 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); + 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); virtual bool closeWallet(Wallet *wallet); bool walletExists(const std::string &path); @@ -287,16 +319,16 @@ private: }; Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::string &password, - const std::string &language) + const std::string &language, bool testnet) { - WalletImpl * wallet = new WalletImpl(); + WalletImpl * wallet = new WalletImpl(testnet); wallet->create(path, password, language); return wallet; } -Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password) +Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password, bool testnet) { - WalletImpl * wallet = new WalletImpl(); + WalletImpl * wallet = new WalletImpl(testnet); wallet->open(path, password); return wallet; } diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index 013a260b7..ad1e08fe3 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -67,6 +67,9 @@ 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; }; /** @@ -82,7 +85,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) = 0; /*! * \brief Opens existing wallet @@ -90,7 +93,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) = 0; /*! * \brief recovers existing wallet using memo (electrum seed) @@ -111,8 +114,8 @@ struct WalletManager virtual bool walletExists(const std::string &path) = 0; virtual std::string errorString() const = 0; - - virtual void setDaemonHost(const std::string &hostname) = 0; +// //! set +// virtual void setDaemonAddress(const std::string &address) = 0; }; |