diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-10-15 18:25:08 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-10-15 18:25:08 +0200 |
commit | 960886aa04f0b50265884c0d4338031a93b1bc5d (patch) | |
tree | b74d770e86309091072c4ca66a6dbef7fff5597a /src/wallet/api | |
parent | Merge pull request #2555 (diff) | |
parent | wallet2+API: use separate callbacks for lightwallets (diff) | |
download | monero-960886aa04f0b50265884c0d4338031a93b1bc5d.tar.xz |
Merge pull request #2109
97c2e449 wallet2+API: use separate callbacks for lightwallets (Jaquee)
d9261867 walletAPI: correct confirmations in txHistory for unsynced wallets (Jaquee)
9442b043 walletAPI: lightwallet exceptions (Jaquee)
fc922934 walletAPI: add lightwallet login() and importWalletRequest() (Jaquee)
79207743 walletAPI: init() lightwallet and SSL support (Jaquee)
dde5a1fc walletAPI: add tx unlock_time (Jaquee)
bba5cbed wallet2: remove obsolete get_num_rct_outputs() call from create_transactions_2 (Jaquee)
7a482f30 wallet2: create_transactions_2 lightwallet support (Jaquee)
ce61b818 wallet2: get_outs lightwallet support (Jaquee)
1197cb71 wallet2: commit_tx() lightwallet support (Jaquee)
43b57804 wallet2: refactor is_tx_spendtime_unlocked() (Jaquee)
32e2b003 wallet2: add lightwallet exceptions to common functions (Jaquee)
2e692fc0 wallet2: refresh() lightwallet support (Jaquee)
f44d156c my/openmonero API functions (Jaquee)
288d3c75 wallet2: add remove_obsolete_pool_txs() (Jaquee)
2c6aad7e wallet2: add on_pool_tx_removed callback (Jaquee)
ff7c30aa wallet2: light wallet member variables (Jaquee)
e2a276cb wallet2: add ssl option to init() (Jaquee)
a13540be add string_tools::validate_hex() (Jaquee)
fd773d88 refactor cryptonote_basic::add_tx_pub_key_to_extra (Jaquee)
8bfa6c2d lightwallet rpc server commands (Jaquee)
76961ddc Serializer: string to integer conversion for MyMonero compatibility (Jaquee)
1cf940f2 epee http_client SSL support (Jaquee)
eec10137 CMakeLists.txt - Add openssl include dir (Jaquee)
Diffstat (limited to 'src/wallet/api')
-rw-r--r-- | src/wallet/api/transaction_history.cpp | 8 | ||||
-rw-r--r-- | src/wallet/api/wallet.cpp | 88 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 6 |
3 files changed, 88 insertions, 14 deletions
diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp index b6ba8c359..59eca3dd7 100644 --- a/src/wallet/api/transaction_history.cpp +++ b/src/wallet/api/transaction_history.cpp @@ -134,14 +134,10 @@ void TransactionHistoryImpl::refresh() ti->m_subaddrAccount = pd.m_subaddr_index.major; ti->m_label = m_wallet->m_wallet->get_subaddress_label(pd.m_subaddr_index); ti->m_timestamp = pd.m_timestamp; - ti->m_confirmations = wallet_height - pd.m_block_height; + ti->m_confirmations = (wallet_height > pd.m_block_height) ? wallet_height - pd.m_block_height : 0; ti->m_unlock_time = pd.m_unlock_time; 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()))); */ } // confirmed output transactions @@ -181,7 +177,7 @@ void TransactionHistoryImpl::refresh() ti->m_subaddrAccount = pd.m_subaddr_account; ti->m_label = pd.m_subaddr_indices.size() == 1 ? m_wallet->m_wallet->get_subaddress_label({pd.m_subaddr_account, *pd.m_subaddr_indices.begin()}) : ""; ti->m_timestamp = pd.m_timestamp; - ti->m_confirmations = wallet_height - pd.m_block_height; + ti->m_confirmations = (wallet_height > pd.m_block_height) ? wallet_height - pd.m_block_height : 0; // single output transaction might contain multiple transfers for (const auto &d: pd.m_dests) { diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index a932d9d6f..db7e60cd7 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -155,6 +155,38 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback // TODO; } + // Light wallet callbacks + virtual void on_lw_new_block(uint64_t height) + { + if (m_listener) { + m_listener->newBlock(height); + } + } + + virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) + { + if (m_listener) { + std::string tx_hash = epee::string_tools::pod_to_hex(txid); + m_listener->moneyReceived(tx_hash, amount); + } + } + + virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) + { + if (m_listener) { + std::string tx_hash = epee::string_tools::pod_to_hex(txid); + m_listener->unconfirmedMoneyReceived(tx_hash, amount); + } + } + + virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount) + { + if (m_listener) { + std::string tx_hash = epee::string_tools::pod_to_hex(txid); + m_listener->moneySpent(tx_hash, amount); + } + } + WalletListener * m_listener; WalletImpl * m_wallet; }; @@ -703,12 +735,45 @@ string WalletImpl::keysFilename() const return m_wallet->get_keys_file(); } -bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password) +bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password, bool use_ssl, bool lightWallet) { clearStatus(); + m_wallet->set_light_wallet(lightWallet); if(daemon_username != "") m_daemon_login.emplace(daemon_username, daemon_password); - return doInit(daemon_address, upper_transaction_size_limit); + return doInit(daemon_address, upper_transaction_size_limit, use_ssl); +} + +bool WalletImpl::lightWalletLogin(bool &isNewWallet) const +{ + return m_wallet->light_wallet_login(isNewWallet); +} + +bool WalletImpl::lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status) +{ + try + { + cryptonote::COMMAND_RPC_IMPORT_WALLET_REQUEST::response response; + if(!m_wallet->light_wallet_import_wallet_request(response)){ + m_errorString = tr("Failed to send import wallet request"); + m_status = Status_Error; + return false; + } + fee = response.import_fee; + payment_id = response.payment_id; + new_request = response.new_request; + request_fulfilled = response.request_fulfilled; + payment_address = response.payment_address; + status = response.status; + } + catch (const std::exception &e) + { + LOG_ERROR("Error sending import wallet request: " << e.what()); + m_errorString = e.what(); + m_status = Status_Error; + return false; + } + return true; } void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height) @@ -733,6 +798,9 @@ uint64_t WalletImpl::unlockedBalance(uint32_t accountIndex) const uint64_t WalletImpl::blockChainHeight() const { + if(m_wallet->light_wallet()) { + return m_wallet->get_light_wallet_scanned_block_height(); + } return m_wallet->get_blockchain_current_height(); } uint64_t WalletImpl::approximateBlockChainHeight() const @@ -741,6 +809,9 @@ uint64_t WalletImpl::approximateBlockChainHeight() const } uint64_t WalletImpl::daemonBlockChainHeight() const { + if(m_wallet->light_wallet()) { + return m_wallet->get_light_wallet_scanned_block_height(); + } if (!m_is_connected) return 0; std::string err; @@ -760,6 +831,9 @@ uint64_t WalletImpl::daemonBlockChainHeight() const uint64_t WalletImpl::daemonBlockChainTargetHeight() const { + if(m_wallet->light_wallet()) { + return m_wallet->get_light_wallet_blockchain_height(); + } if (!m_is_connected) return 0; std::string err; @@ -1348,7 +1422,8 @@ Wallet::ConnectionStatus WalletImpl::connected() const m_is_connected = m_wallet->check_connection(&version, DEFAULT_CONNECTION_TIMEOUT_MILLIS); if (!m_is_connected) return Wallet::ConnectionStatus_Disconnected; - if ((version >> 16) != CORE_RPC_VERSION_MAJOR) + // Version check is not implemented in light wallets nodes/wallets + if (!m_wallet->light_wallet() && (version >> 16) != CORE_RPC_VERSION_MAJOR) return Wallet::ConnectionStatus_WrongVersion; return Wallet::ConnectionStatus_Connected; } @@ -1411,7 +1486,7 @@ void WalletImpl::doRefresh() try { // Syncing daemon and refreshing wallet simultaneously is very resource intensive. // Disable refresh if wallet is disconnected or daemon isn't synced. - if (daemonSynced()) { + if (m_wallet->light_wallet() || daemonSynced()) { m_wallet->refresh(); if (!m_synchronized) { m_synchronized = true; @@ -1476,13 +1551,14 @@ bool WalletImpl::isNewWallet() const return !(blockChainHeight() > 1 || m_recoveringFromSeed || m_rebuildWalletCache) && !watchOnly(); } -bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit) +bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit, bool ssl) { - if (!m_wallet->init(daemon_address, m_daemon_login, upper_transaction_size_limit)) + if (!m_wallet->init(daemon_address, m_daemon_login, upper_transaction_size_limit, ssl)) return false; // in case new wallet, this will force fast-refresh (pulling hashes instead of blocks) // If daemon isn't synced a calculated block height will be used instead + //TODO: Handle light wallet scenario where block height = 0. if (isNewWallet() && daemonSynced()) { LOG_PRINT_L2(__FUNCTION__ << ":New Wallet - fast refresh until " << daemonBlockChainHeight()); m_wallet->set_refresh_from_block_height(daemonBlockChainHeight()); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 020c5e46a..ecb218ea0 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -83,7 +83,7 @@ public: 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 = 0, const std::string &daemon_username = "", const std::string &daemon_password = ""); + bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false); bool connectToDaemon(); ConnectionStatus connected() const; void setTrustedDaemon(bool arg); @@ -143,6 +143,8 @@ public: virtual void pauseRefresh(); virtual bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error); virtual std::string getDefaultDataDir() const; + virtual bool lightWalletLogin(bool &isNewWallet) const; + virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status); private: void clearStatus() const; @@ -151,7 +153,7 @@ private: bool daemonSynced() const; void stopRefresh(); bool isNewWallet() const; - bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit); + bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, bool ssl = false); private: friend class PendingTransactionImpl; |