diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-10-09 14:34:59 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-10-09 14:34:59 +0200 |
commit | 0673db16ad7a8b91c0216d41a1363262f7000bb4 (patch) | |
tree | 29cbe76d2a481b7023bff133473e597eb70a6551 /src/wallet/api/wallet.cpp | |
parent | Merge pull request #1194 (diff) | |
parent | libwallet_api: reverted deleted curly brace (diff) | |
download | monero-0673db16ad7a8b91c0216d41a1363262f7000bb4.tar.xz |
Merge pull request #1195
697ce1d libwallet_api: reverted deleted curly brace (Ilya Kitaev)
bb9094f libwallet_api: fixes for transaction history (Ilya Kitaev)
62b3708 libwallet_api: do not signal on sent/received tx until wallet completely synchronized (Ilya Kitaev)
11fab41 libwallet_api: TransactionHistory: read/write syncchronization (Ilya Kitaev)
559f379 libwallet_api: test: adjusted mixin_count=4 as it's minumum allowed (Ilya Kitaev)
8b0cb8c libwallet_api: some renamings (Ilya Kitaev)
db3282c Initialize transaction history if empty (Ilya Kitaev)
85f5e73 libwallet_api: fixes for transaction history (Ilya Kitaev)
Diffstat (limited to 'src/wallet/api/wallet.cpp')
-rw-r--r-- | src/wallet/api/wallet.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 447d46651..674670b16 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -54,8 +54,9 @@ namespace { struct Wallet2CallbackImpl : public tools::i_wallet2_callback { - Wallet2CallbackImpl() + Wallet2CallbackImpl(WalletImpl * wallet) : m_listener(nullptr) + , m_wallet(wallet) { } @@ -93,7 +94,8 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback LOG_PRINT_L3(__FUNCTION__ << ": money received. height: " << height << ", tx: " << tx_hash << ", amount: " << print_money(amount)); - if (m_listener) { + // do not signal on received tx if wallet is not syncronized completely + if (m_listener && m_wallet->synchronized()) { m_listener->moneyReceived(tx_hash, amount); m_listener->updated(); } @@ -107,7 +109,8 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height << ", tx: " << tx_hash << ", amount: " << print_money(amount)); - if (m_listener) { + // do not signal on sent tx if wallet is not syncronized completely + if (m_listener && m_wallet->synchronized()) { m_listener->moneySpent(tx_hash, amount); m_listener->updated(); } @@ -119,6 +122,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback } WalletListener * m_listener; + WalletImpl * m_wallet; }; Wallet::~Wallet() {} @@ -166,12 +170,16 @@ uint64_t Wallet::maximumAllowedAmount() ///////////////////////// WalletImpl implementation //////////////////////// WalletImpl::WalletImpl(bool testnet) - :m_wallet(nullptr), m_status(Wallet::Status_Ok), m_trustedDaemon(false), - m_wallet2Callback(nullptr), m_recoveringFromSeed(false) + :m_wallet(nullptr) + , m_status(Wallet::Status_Ok) + , m_trustedDaemon(false) + , m_wallet2Callback(nullptr) + , m_recoveringFromSeed(false) + , m_synchronized(false) { m_wallet = new tools::wallet2(testnet); m_history = new TransactionHistoryImpl(this); - m_wallet2Callback = new Wallet2CallbackImpl; + m_wallet2Callback = new Wallet2CallbackImpl(this); m_wallet->callback(m_wallet2Callback); m_refreshThreadDone = false; m_refreshEnabled = false; @@ -201,7 +209,6 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co 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); @@ -459,6 +466,11 @@ uint64_t WalletImpl::daemonBlockChainTargetHeight() const return result; } +bool WalletImpl::synchronized() const +{ + return m_synchronized; +} + bool WalletImpl::refresh() { clearStatus(); @@ -727,6 +739,15 @@ void WalletImpl::doRefresh() boost::lock_guard<boost::mutex> guarg(m_refreshMutex2); try { m_wallet->refresh(); + if (!m_synchronized) { + m_synchronized = true; + } + // assuming if we have empty history, it wasn't initialized yet + // for futher history changes client need to update history in + // "on_money_received" and "on_money_sent" callbacks + if (m_history->count() == 0) { + m_history->refresh(); + } } catch (const std::exception &e) { m_status = Status_Error; m_errorString = e.what(); |