diff options
author | Ilya Kitaev <mbg033@gmail.com> | 2016-07-14 12:47:01 +0300 |
---|---|---|
committer | Ilya Kitaev <mbg033@gmail.com> | 2016-07-18 23:03:09 +0300 |
commit | 6d32a3d16b8bb1bf2a51a41ce9f826cf31d02352 (patch) | |
tree | 02f16ea19e0bfaf5a15614ccf1691595a5f3ff8d /src/wallet/api | |
parent | libwallet_api cmake: conditionally creating libwallet_merged2 only for (diff) | |
download | monero-6d32a3d16b8bb1bf2a51a41ce9f826cf31d02352.tar.xz |
wallet_api: async init, Wallet::connected status, log level
Diffstat (limited to '')
-rw-r--r-- | src/wallet/api/wallet.cpp | 52 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 2 | ||||
-rw-r--r-- | src/wallet/api/wallet_manager.cpp | 5 |
3 files changed, 45 insertions, 14 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index e75f5afdb..2322cac76 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -76,7 +76,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback virtual void on_new_block(uint64_t height, const cryptonote::block& block) { // TODO; - LOG_PRINT_L0(__FUNCTION__ << ": new block. height: " << height); + LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height); } virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, size_t out_index) @@ -85,7 +85,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(tx)); uint64_t amount = tx.vout[out_index].amount; - LOG_PRINT_L0(__FUNCTION__ << ": money received. height: " << height + LOG_PRINT_L3(__FUNCTION__ << ": money received. height: " << height << ", tx: " << tx_hash << ", amount: " << print_money(amount)); if (m_listener) { @@ -100,7 +100,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback // 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_L0(__FUNCTION__ << ": money spent. height: " << height + LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height << ", tx: " << tx_hash << ", amount: " << print_money(amount)); if (m_listener) { @@ -121,6 +121,7 @@ Wallet::~Wallet() {} WalletListener::~WalletListener() {} + string Wallet::displayAmount(uint64_t amount) { return cryptonote::print_money(amount); @@ -269,8 +270,12 @@ bool WalletImpl::close() clearStatus(); bool result = false; try { + // LOG_PRINT_L0("Calling wallet::store..."); m_wallet->store(); + // LOG_PRINT_L0("wallet::store done"); + // LOG_PRINT_L0("Calling wallet::stop..."); m_wallet->stop(); + // LOG_PRINT_L0("wallet::stop done"); result = true; } catch (const std::exception &e) { m_status = Status_Error; @@ -366,21 +371,30 @@ string WalletImpl::keysFilename() const 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); - if (Utils::isAddressLocal(daemon_address)) { - this->setTrustedDaemon(true); - } - refresh(); - } catch (const std::exception &e) { - LOG_ERROR("Error initializing wallet: " << e.what()); - m_status = Status_Error; - m_errorString = e.what(); + + m_wallet->init(daemon_address, upper_transaction_size_limit); + if (Utils::isAddressLocal(daemon_address)) { + this->setTrustedDaemon(true); } + bool result = this->refresh(); + // enabling background refresh thread + startRefresh(); + return result; - return m_status == Status_Ok; } +void WalletImpl::initAsync(const string &daemon_address, uint64_t upper_transaction_size_limit) +{ + clearStatus(); + m_wallet->init(daemon_address, upper_transaction_size_limit); + if (Utils::isAddressLocal(daemon_address)) { + this->setTrustedDaemon(true); + } + startRefresh(); +} + + + uint64_t WalletImpl::balance() const { return m_wallet->balance(); @@ -594,6 +608,11 @@ bool WalletImpl::connectToDaemon() return result; } +bool WalletImpl::connected() const +{ + return m_wallet->check_connection(); +} + void WalletImpl::setTrustedDaemon(bool arg) { m_trustedDaemon = arg; @@ -619,8 +638,13 @@ void WalletImpl::refreshThreadFunc() if (m_refreshThreadDone) { break; } + LOG_PRINT_L3(__FUNCTION__ << ": waiting for refresh..."); m_refreshCV.wait_for(lock, std::chrono::seconds(m_refreshIntervalSeconds)); + LOG_PRINT_L3(__FUNCTION__ << ": refresh lock acquired..."); + LOG_PRINT_L3(__FUNCTION__ << ": m_refreshEnabled: " << m_refreshEnabled); + LOG_PRINT_L3(__FUNCTION__ << ": m_status: " << m_status); if (m_refreshEnabled && m_status == Status_Ok) { + LOG_PRINT_L3(__FUNCTION__ << ": refreshing..."); doRefresh(); } } diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index e9da05347..68ca364cf 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -68,7 +68,9 @@ public: std::string filename() const; std::string keysFilename() const; bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit); + void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit); bool connectToDaemon(); + bool connected() const; void setTrustedDaemon(bool arg); bool trustedDaemon() const; uint64_t balance() const; diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index bf072ccca..ca83806ff 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -137,6 +137,11 @@ WalletManager *WalletManagerFactory::getWalletManager() return g_walletManager; } +void WalletManagerFactory::setLogLevel(int level) +{ + epee::log_space::log_singletone::get_set_log_detalisation_level(true, level); +} + } |