diff options
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/api/pending_transaction.cpp | 5 | ||||
-rw-r--r-- | src/wallet/api/unsigned_transaction.cpp | 5 | ||||
-rw-r--r-- | src/wallet/api/utils.cpp | 9 | ||||
-rw-r--r-- | src/wallet/api/wallet.cpp | 38 | ||||
-rw-r--r-- | src/wallet/api/wallet.h | 4 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 26 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 11 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 20 | ||||
-rw-r--r-- | src/wallet/wallet_errors.h | 2 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 4 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_commands_defs.h | 2 |
11 files changed, 59 insertions, 67 deletions
diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp index 760c84f4f..09010a688 100644 --- a/src/wallet/api/pending_transaction.cpp +++ b/src/wallet/api/pending_transaction.cpp @@ -32,9 +32,8 @@ #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 "cryptonote_basic/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include <memory> #include <vector> diff --git a/src/wallet/api/unsigned_transaction.cpp b/src/wallet/api/unsigned_transaction.cpp index 84ec2d9d2..b412084b0 100644 --- a/src/wallet/api/unsigned_transaction.cpp +++ b/src/wallet/api/unsigned_transaction.cpp @@ -32,9 +32,8 @@ #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 "cryptonote_basic/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include <memory> #include <vector> diff --git a/src/wallet/api/utils.cpp b/src/wallet/api/utils.cpp index 788d98f25..c369427b4 100644 --- a/src/wallet/api/utils.cpp +++ b/src/wallet/api/utils.cpp @@ -39,8 +39,13 @@ namespace Monero { namespace Utils { bool isAddressLocal(const std::string &address) -{ - return tools::is_local_address(address); +{ + try { + return tools::is_local_address(address); + } catch (const std::exception &e) { + MERROR("error: " << e.what()); + return false; + } } } diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 325f8522e..c46de6b06 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -44,6 +44,9 @@ using namespace std; using namespace cryptonote; +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "WalletAPI" + namespace Monero { namespace { @@ -85,11 +88,14 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback virtual void on_new_block(uint64_t height, const cryptonote::block& block) { - //LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height); - - if (m_listener) { - m_listener->newBlock(height); - // m_listener->updated(); + // Don't flood the GUI with signals. On fast refresh - send signal every 1000th block + // get_refresh_from_block_height() returns the blockheight from when the wallet was + // created or the restore height specified when wallet was recovered + if(height >= m_wallet->m_wallet->get_refresh_from_block_height() || height % 1000 == 0) { + // LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height); + if (m_listener) { + m_listener->newBlock(height); + } } } @@ -252,6 +258,9 @@ uint64_t Wallet::maximumAllowedAmount() return std::numeric_limits<uint64_t>::max(); } +void Wallet::debug(const std::string &str) { + MDEBUG(str); +} ///////////////////////// WalletImpl implementation //////////////////////// WalletImpl::WalletImpl(bool testnet) @@ -515,7 +524,6 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed) 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_Critical; @@ -535,7 +543,7 @@ bool WalletImpl::close() if (status() != Status_Critical) m_wallet->store(); else - LOG_PRINT_L3("Status_Critical - not storing wallet"); + LOG_ERROR("Status_Critical - not storing wallet"); LOG_PRINT_L1("wallet::store done"); LOG_PRINT_L1("Calling wallet::stop..."); m_wallet->stop(); @@ -646,19 +654,7 @@ string WalletImpl::keysFilename() const bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) { clearStatus(); - if (!doInit(daemon_address, upper_transaction_size_limit)) - return false; - bool result = this->refresh(); - // enabling background refresh thread - startRefresh(); - return result; -} - -void WalletImpl::initAsync(const string &daemon_address, uint64_t upper_transaction_size_limit) -{ - clearStatus(); - doInit(daemon_address, upper_transaction_size_limit); - startRefresh(); + return doInit(daemon_address, upper_transaction_size_limit); } void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height) @@ -1323,8 +1319,8 @@ void WalletImpl::doRefresh() void WalletImpl::startRefresh() { - LOG_PRINT_L2(__FUNCTION__ << ": refresh started/resumed..."); if (!m_refreshEnabled) { + LOG_PRINT_L2(__FUNCTION__ << ": refresh started/resumed..."); m_refreshEnabled = true; m_refreshCV.notify_one(); } diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 7daf63e43..3994afaa3 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -78,8 +78,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); - void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit); + bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0); bool connectToDaemon(); ConnectionStatus connected() const; void setTrustedDaemon(bool arg); @@ -135,7 +134,6 @@ private: bool isNewWallet() const; bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit); - private: friend class PendingTransactionImpl; friend class UnsignedTransactionImpl; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0c6d23cc4..e7a175dc7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -39,10 +39,10 @@ using namespace epee; #include "cryptonote_config.h" #include "wallet2.h" #include "wallet2_api.h" -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" #include "rpc/core_rpc_server_commands_defs.h" #include "misc_language.h" -#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include "common/boost_serialization_helper.h" #include "common/command_line.h" #include "profile_tools.h" @@ -501,6 +501,8 @@ std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_new(const //---------------------------------------------------------------------------------------------------- bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, uint64_t upper_transaction_size_limit) { + if(m_http_client.is_connected()) + m_http_client.disconnect(); m_upper_transaction_size_limit = upper_transaction_size_limit; m_daemon_address = std::move(daemon_address); m_daemon_login = std::move(daemon_login); @@ -3328,7 +3330,7 @@ uint64_t wallet2::get_per_kb_fee() // transactions will be required std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon) { - const std::vector<size_t> unused_transfers_indices = select_available_outputs_from_histogram(fake_outs_count + 1, true, true, trusted_daemon); + const std::vector<size_t> unused_transfers_indices = select_available_outputs_from_histogram(fake_outs_count + 1, true, true, true, trusted_daemon); const bool use_new_fee = use_fork_rules(3, -720 * 14); const uint64_t fee_per_kb = get_per_kb_fee(); @@ -4133,7 +4135,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp THROW_WALLET_EXCEPTION_IF(needed_money == 0, error::zero_destination); // gather all our dust and non dust outputs - const std::vector<size_t> unused_indices = select_available_outputs_from_histogram(fake_outs_count + 1, true, true, trusted_daemon); + const std::vector<size_t> unused_indices = select_available_outputs_from_histogram(fake_outs_count + 1, true, true, true, trusted_daemon); for (size_t i: unused_indices) { const transfer_details& td = m_transfers[i]; @@ -4627,7 +4629,7 @@ std::vector<uint64_t> wallet2::get_unspent_amounts_vector() for (const auto &td: m_transfers) { if (!td.m_spent) - set.insert(td.amount()); + set.insert(td.is_rct() ? 0 : td.amount()); } std::vector<uint64_t> vector; vector.reserve(set.size()); @@ -4638,7 +4640,7 @@ std::vector<uint64_t> wallet2::get_unspent_amounts_vector() return vector; } //---------------------------------------------------------------------------------------------------- -std::vector<size_t> wallet2::select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool trusted_daemon) +std::vector<size_t> wallet2::select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon) { epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request> req_t = AUTO_VAL_INIT(req_t); epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response, std::string> resp_t = AUTO_VAL_INIT(resp_t); @@ -4653,7 +4655,7 @@ std::vector<size_t> wallet2::select_available_outputs_from_histogram(uint64_t co req_t.params.unlocked = unlocked; bool r = net_utils::invoke_http_json("/json_rpc", req_t, resp_t, m_http_client); m_daemon_rpc_mutex.unlock(); - THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "select_available_unmixable_outputs"); + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "select_available_outputs_from_histogram"); THROW_WALLET_EXCEPTION_IF(resp_t.result.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_output_histogram"); THROW_WALLET_EXCEPTION_IF(resp_t.result.status != CORE_RPC_STATUS_OK, error::get_histogram_error, resp_t.result.status); @@ -4663,10 +4665,10 @@ std::vector<size_t> wallet2::select_available_outputs_from_histogram(uint64_t co mixable.insert(i.amount); } - return select_available_outputs([mixable, atleast](const transfer_details &td) { - if (td.is_rct()) + return select_available_outputs([mixable, atleast, allow_rct](const transfer_details &td) { + if (!allow_rct && td.is_rct()) return false; - const uint64_t amount = td.amount(); + const uint64_t amount = td.is_rct() ? 0 : td.amount(); if (atleast) { if (mixable.find(amount) != mixable.end()) return true; @@ -4711,14 +4713,14 @@ std::vector<size_t> wallet2::select_available_unmixable_outputs(bool trusted_dae { // request all outputs with less than 3 instances const size_t min_mixin = use_fork_rules(5, 10) ? 4 : 2; // v5 increases min mixin from 2 to 4 - return select_available_outputs_from_histogram(min_mixin + 1, false, true, trusted_daemon); + return select_available_outputs_from_histogram(min_mixin + 1, false, true, false, trusted_daemon); } //---------------------------------------------------------------------------------------------------- std::vector<size_t> wallet2::select_available_mixable_outputs(bool trusted_daemon) { // request all outputs with at least 3 instances, so we can use mixin 2 with const size_t min_mixin = use_fork_rules(5, 10) ? 4 : 2; // v5 increases min mixin from 2 to 4 - return select_available_outputs_from_histogram(min_mixin + 1, true, true, trusted_daemon); + return select_available_outputs_from_histogram(min_mixin + 1, true, true, true, trusted_daemon); } //---------------------------------------------------------------------------------------------------- std::vector<wallet2::pending_tx> wallet2::create_unmixable_sweep_transactions(bool trusted_daemon) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 9842ddf32..dba9a400d 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -39,13 +39,14 @@ #include <atomic> #include "include_base_utils.h" -#include "cryptonote_core/account.h" -#include "cryptonote_core/account_boost_serialization.h" -#include "cryptonote_core/cryptonote_basic_impl.h" +#include "cryptonote_basic/account.h" +#include "cryptonote_basic/account_boost_serialization.h" +#include "cryptonote_basic/cryptonote_basic_impl.h" #include "net/http_client.h" #include "storages/http_abstract_invoke.h" #include "rpc/core_rpc_server_commands_defs.h" -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" +#include "cryptonote_core/cryptonote_tx_utils.h" #include "common/unordered_containers_boost_serialization.h" #include "crypto/chacha8.h" #include "crypto/hash.h" @@ -535,7 +536,7 @@ namespace tools * \brief Calculates the approximate blockchain height from current date/time. */ uint64_t get_approximate_blockchain_height() const; - std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool trusted_daemon); + std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon); std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f); std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon); std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon); diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index 563f16eaa..daa3deeee 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -332,26 +332,16 @@ struct Wallet */ virtual std::string keysFilename() const = 0; /*! - * \brief init - initializes wallet with daemon connection params. implicitly connects to the daemon - * and refreshes the wallet. "refreshed" callback will be invoked. if daemon_address is - * local address, "trusted daemon" will be set to true forcibly + * \brief init - initializes wallet with daemon connection params. + * if daemon_address is local address, "trusted daemon" will be set to true forcibly + * startRefresh() should be called when wallet is initialized. * * \param daemon_address - daemon address in "hostname:port" format * \param upper_transaction_size_limit - * \return - true if initialized and refreshed successfully + * \return - true on success */ virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0; - /*! - * \brief init - initalizes wallet asynchronously. logic is the same as "init" but returns immediately. - * "refreshed" callback will be invoked. - * - * \param daemon_address - daemon address in "hostname:port" format - * \param upper_transaction_size_limit - * \return - true if initialized and refreshed successfully - */ - virtual void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0; - /*! * \brief createWatchOnly - Creates a watch only wallet * \param path - where to store the wallet @@ -438,6 +428,8 @@ struct Wallet static bool keyValid(const std::string &secret_key_string, const std::string &address_string, bool isViewKey, bool testnet, std::string &error); static std::string paymentIdFromAddress(const std::string &str, bool testnet); static uint64_t maximumAllowedAmount(); + // Easylogger wrapper + static void debug(const std::string &str); /** * @brief StartRefresh - Start/resume refresh thread (refresh every 10 seconds) diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 785a72e4b..fc0471be7 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -35,7 +35,7 @@ #include <string> #include <vector> -#include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" #include "rpc/core_rpc_server_commands_defs.h" #include "include_base_utils.h" diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 76520c185..881279e42 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -38,8 +38,8 @@ using namespace epee; #include "common/command_line.h" #include "common/i18n.h" #include "common/util.h" -#include "cryptonote_core/cryptonote_format_utils.h" -#include "cryptonote_core/account.h" +#include "cryptonote_basic/cryptonote_format_utils.h" +#include "cryptonote_basic/account.h" #include "wallet_rpc_server_commands_defs.h" #include "misc_language.h" #include "string_coding.h" diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index e132b4e2b..86f37c658 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -30,7 +30,7 @@ #pragma once #include "cryptonote_protocol/cryptonote_protocol_defs.h" -#include "cryptonote_core/cryptonote_basic.h" +#include "cryptonote_basic/cryptonote_basic.h" #include "crypto/hash.h" #include "wallet_rpc_server_error_codes.h" |