diff options
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r-- | src/wallet/wallet2.cpp | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 151da5602..63205f429 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -676,6 +676,40 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri } /*! +* \brief Creates a watch only wallet from a public address and a view secret key. +* \param wallet_ Name of wallet file +* \param password Password of wallet file +* \param viewkey view secret key +*/ +void wallet2::generate(const std::string& wallet_, const std::string& password, + const cryptonote::account_public_address &account_public_address, + const crypto::secret_key& viewkey) +{ + clear(); + prepare_file_names(wallet_); + + boost::system::error_code ignored_ec; + THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file); + THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file); + + m_account.create_from_viewkey(account_public_address, viewkey); + m_account_public_address = account_public_address; + m_watch_only = true; + + bool r = store_keys(m_keys_file, password, true); + THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file); + + r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet)); + if(!r) LOG_PRINT_RED_L0("String with address text not saved"); + + cryptonote::block b; + generate_genesis(b); + m_blockchain.push_back(get_block_hash(b)); + + store(); +} + +/*! * \brief Rewrites to the wallet file for wallet upgrade (doesn't generate key, assumes it's already there) * \param wallet_name Name of wallet file (should exist) * \param password Password for wallet file @@ -689,8 +723,8 @@ void wallet2::rewrite(const std::string& wallet_name, const std::string& passwor THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file); } /*! - * \brief Rewrites to the wallet file for wallet upgrade (doesn't generate key, assumes it's already there) - * \param wallet_name Name of wallet file (should exist) + * \brief Writes to a file named based on the normal wallet (doesn't generate key, assumes it's already there) + * \param wallet_name Base name of wallet file * \param password Password for wallet file */ void wallet2::write_watch_only_wallet(const std::string& wallet_name, const std::string& password) @@ -1146,10 +1180,12 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto for(attempt_count = 1; ;attempt_count++) { - auto split_values = split_amounts(dsts, attempt_count); + size_t num_tx = 0.5 + pow(1.7,attempt_count-1); + + auto split_values = split_amounts(dsts, num_tx); // Throw if split_amounts comes back with a vector of size different than it should - if (split_values.size() != attempt_count) + if (split_values.size() != num_tx) { throw std::runtime_error("Splitting transactions returned a number of potential tx not equal to what was requested"); } @@ -1357,13 +1393,14 @@ std::vector<wallet2::pending_tx> wallet2::create_dust_sweep_transactions() for(attempt_count = 1; ;attempt_count++) { - size_t num_outputs_per_tx = (num_dust_outputs + attempt_count - 1) / attempt_count; + size_t num_tx = 0.5 + pow(1.7,attempt_count-1); + size_t num_outputs_per_tx = (num_dust_outputs + num_tx - 1) / num_tx; std::vector<pending_tx> ptx_vector; try { // for each new tx - for (size_t i=0; i<attempt_count;++i) + for (size_t i=0; i<num_tx;++i) { cryptonote::transaction tx; pending_tx ptx; |