From bc1ee2c2ee35733c2831cc949ad4baf5b1866445 Mon Sep 17 00:00:00 2001 From: stoffu Date: Wed, 17 Jan 2018 10:58:34 +0900 Subject: [PATCH] wallet2: make member functions const when possible --- src/wallet/wallet2.cpp | 36 ++++++++++++++++++------------------ src/wallet/wallet2.h | 34 +++++++++++++++++----------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0c2b7e984..671fcdd61 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4135,7 +4135,7 @@ size_t wallet2::pop_best_value(std::vector &unused_indices, const std::v // returns: // direct return: amount of money found // modified reference: selected_transfers, a list of iterators/indices of input sources -uint64_t wallet2::select_transfers(uint64_t needed_money, std::vector unused_transfers_indices, std::vector& selected_transfers, bool trusted_daemon) +uint64_t wallet2::select_transfers(uint64_t needed_money, std::vector unused_transfers_indices, std::vector& selected_transfers, bool trusted_daemon) const { uint64_t found_money = 0; selected_transfers.reserve(unused_transfers_indices.size()); @@ -4143,7 +4143,7 @@ uint64_t wallet2::select_transfers(uint64_t needed_money, std::vector un { size_t idx = pop_best_value(unused_transfers_indices, selected_transfers); - transfer_container::iterator it = m_transfers.begin() + idx; + const transfer_container::const_iterator it = m_transfers.begin() + idx; selected_transfers.push_back(idx); found_money += it->amount(); } @@ -4350,7 +4350,7 @@ void wallet2::commit_tx(std::vector& ptx_vector) } } //---------------------------------------------------------------------------------------------------- -bool wallet2::save_tx(const std::vector& ptx_vector, const std::string &filename) +bool wallet2::save_tx(const std::vector& ptx_vector, const std::string &filename) const { LOG_PRINT_L0("saving " << ptx_vector.size() << " transactions"); unsigned_tx_set txs; @@ -4379,7 +4379,7 @@ bool wallet2::save_tx(const std::vector& ptx_vector, const std::stri return epee::file_io_utils::save_string_to_file(filename, std::string(UNSIGNED_TX_PREFIX) + ciphertext); } //---------------------------------------------------------------------------------------------------- -bool wallet2::load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs) +bool wallet2::load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs) const { std::string s; boost::system::error_code errcode; @@ -4953,7 +4953,7 @@ bool wallet2::sign_multisig_tx_from_file(const std::string &filename, std::vecto return sign_multisig_tx_to_file(exported_txs, filename, txids); } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::get_fee_multiplier(uint32_t priority, int fee_algorithm) +uint64_t wallet2::get_fee_multiplier(uint32_t priority, int fee_algorithm) const { static const uint64_t old_multipliers[3] = {1, 2, 3}; static const uint64_t new_multipliers[3] = {1, 20, 166}; @@ -4990,7 +4990,7 @@ uint64_t wallet2::get_fee_multiplier(uint32_t priority, int fee_algorithm) return 1; } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::get_dynamic_per_kb_fee_estimate() +uint64_t wallet2::get_dynamic_per_kb_fee_estimate() const { uint64_t fee; boost::optional result = m_node_rpc_proxy.get_dynamic_per_kb_fee_estimate(FEE_ESTIMATE_GRACE_BLOCKS, fee); @@ -5000,7 +5000,7 @@ uint64_t wallet2::get_dynamic_per_kb_fee_estimate() return FEE_PER_KB; } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::get_per_kb_fee() +uint64_t wallet2::get_per_kb_fee() const { if(m_light_wallet) return m_light_wallet_per_kb_fee; @@ -5011,7 +5011,7 @@ uint64_t wallet2::get_per_kb_fee() return get_dynamic_per_kb_fee_estimate(); } //---------------------------------------------------------------------------------------------------- -int wallet2::get_fee_algorithm() +int wallet2::get_fee_algorithm() const { // changes at v3 and v5 if (use_fork_rules(5, 0)) @@ -5021,7 +5021,7 @@ int wallet2::get_fee_algorithm() return 0; } //------------------------------------------------------------------------------------------------------------------------------ -uint64_t wallet2::adjust_mixin(uint64_t mixin) +uint64_t wallet2::adjust_mixin(uint64_t mixin) const { if (mixin < 4 && use_fork_rules(6, 10)) { MWARNING("Requested ring size " << (mixin + 1) << " too low for hard fork 6, using 5"); @@ -7178,13 +7178,13 @@ std::vector wallet2::create_transactions_from(const crypton return ptx_vector; } //---------------------------------------------------------------------------------------------------- -void wallet2::get_hard_fork_info(uint8_t version, uint64_t &earliest_height) +void wallet2::get_hard_fork_info(uint8_t version, uint64_t &earliest_height) const { boost::optional result = m_node_rpc_proxy.get_earliest_height(version, earliest_height); throw_on_rpc_response_error(result, "get_hard_fork_info"); } //---------------------------------------------------------------------------------------------------- -bool wallet2::use_fork_rules(uint8_t version, int64_t early_blocks) +bool wallet2::use_fork_rules(uint8_t version, int64_t early_blocks) const { // TODO: How to get fork rule info from light wallet node? if(m_light_wallet) @@ -7203,7 +7203,7 @@ bool wallet2::use_fork_rules(uint8_t version, int64_t early_blocks) return close_enough; } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::get_upper_transaction_size_limit() +uint64_t wallet2::get_upper_transaction_size_limit() const { if (m_upper_transaction_size_limit > 0) return m_upper_transaction_size_limit; @@ -7211,7 +7211,7 @@ uint64_t wallet2::get_upper_transaction_size_limit() return full_reward_zone - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE; } //---------------------------------------------------------------------------------------------------- -std::vector wallet2::select_available_outputs(const std::function &f) +std::vector wallet2::select_available_outputs(const std::function &f) const { std::vector outputs; size_t n = 0; @@ -7229,7 +7229,7 @@ std::vector wallet2::select_available_outputs(const std::function wallet2::get_unspent_amounts_vector() +std::vector wallet2::get_unspent_amounts_vector() const { std::set set; for (const auto &td: m_transfers) @@ -8204,7 +8204,7 @@ std::string wallet2::get_daemon_address() const return m_daemon_address; } -uint64_t wallet2::get_daemon_blockchain_height(string &err) +uint64_t wallet2::get_daemon_blockchain_height(string &err) const { uint64_t height; @@ -8434,7 +8434,7 @@ crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::walle return crypto::null_pkey; } -bool wallet2::export_key_images(const std::string &filename) +bool wallet2::export_key_images(const std::string &filename) const { std::vector> ski = export_key_images(); std::string magic(KEY_IMAGE_EXPORT_FILE_MAGIC, strlen(KEY_IMAGE_EXPORT_FILE_MAGIC)); @@ -9238,7 +9238,7 @@ std::string wallet2::decrypt_with_view_secret_key(const std::string &ciphertext, return decrypt(ciphertext, get_account().get_keys().m_view_secret_key, authenticated); } //---------------------------------------------------------------------------------------------------- -std::string wallet2::make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error) +std::string wallet2::make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error) const { cryptonote::address_parse_info info; if(!get_account_address_from_str(info, testnet(), address)) @@ -9536,7 +9536,7 @@ std::vector> wallet2::estimate_backlog(uint64_t mi return blocks; } //---------------------------------------------------------------------------------------------------- -void wallet2::generate_genesis(cryptonote::block& b) { +void wallet2::generate_genesis(cryptonote::block& b) const { if (m_testnet) { cryptonote::generate_genesis_block(b, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 04d789f18..a6dd80861 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -656,7 +656,7 @@ namespace tools void commit_tx(pending_tx& ptx_vector); void commit_tx(std::vector& ptx_vector); - bool save_tx(const std::vector& ptx_vector, const std::string &filename); + bool save_tx(const std::vector& ptx_vector, const std::string &filename) const; std::string save_multisig_tx(multisig_tx_set txs); bool save_multisig_tx(const multisig_tx_set &txs, const std::string &filename); std::string save_multisig_tx(const std::vector& ptx_vector); @@ -666,7 +666,7 @@ namespace tools // sign unsigned tx. Takes unsigned_tx_set as argument. Used by GUI bool sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_filename, std::vector &ptx, bool export_raw = false); // load unsigned_tx_set from file. - bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs); + bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs) const; bool load_tx(const std::string &signed_filename, std::vector &ptx, std::function accept_func = NULL); std::vector create_transactions(std::vector dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector& extra, bool trusted_daemon); std::vector create_transactions_2(std::vector dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, bool trusted_daemon); // pass subaddr_indices by value on purpose @@ -877,15 +877,15 @@ namespace tools size_t get_num_transfer_details() const { return m_transfers.size(); } const transfer_details &get_transfer_details(size_t idx) const; - void get_hard_fork_info(uint8_t version, uint64_t &earliest_height); - bool use_fork_rules(uint8_t version, int64_t early_blocks = 0); - int get_fee_algorithm(); + void get_hard_fork_info(uint8_t version, uint64_t &earliest_height) const; + bool use_fork_rules(uint8_t version, int64_t early_blocks = 0) const; + int get_fee_algorithm() const; std::string get_wallet_file() const; std::string get_keys_file() const; std::string get_daemon_address() const; const boost::optional& get_daemon_login() const { return m_daemon_login; } - uint64_t get_daemon_blockchain_height(std::string& err); + uint64_t get_daemon_blockchain_height(std::string& err) const; uint64_t get_daemon_blockchain_target_height(std::string& err); /*! * \brief Calculates the approximate blockchain height from current date/time. @@ -893,7 +893,7 @@ namespace tools uint64_t get_approximate_blockchain_height() const; uint64_t estimate_blockchain_height(); std::vector select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon); - std::vector select_available_outputs(const std::function &f); + std::vector select_available_outputs(const std::function &f) const; std::vector select_available_unmixable_outputs(bool trusted_daemon); std::vector select_available_mixable_outputs(bool trusted_daemon); @@ -935,7 +935,7 @@ namespace tools void import_payments_out(const std::list> &confirmed_payments); std::tuple> export_blockchain() const; void import_blockchain(const std::tuple> &bc); - bool export_key_images(const std::string &filename); + bool export_key_images(const std::string &filename) const; std::vector> export_key_images() const; uint64_t import_key_images(const std::vector> &signed_key_images, uint64_t &spent, uint64_t &unspent, bool check_spent = true); uint64_t import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent); @@ -948,7 +948,7 @@ namespace tools std::string decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated = true) const; std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated = true) const; - std::string make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error); + std::string make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error) const; 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 &unknown_parameters, std::string &error); uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31 @@ -957,9 +957,9 @@ namespace tools std::vector> estimate_backlog(uint64_t min_blob_size, uint64_t max_blob_size, const std::vector &fees); - uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1); - uint64_t get_per_kb_fee(); - uint64_t adjust_mixin(uint64_t mixin); + uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1) const; + uint64_t get_per_kb_fee() const; + uint64_t adjust_mixin(uint64_t mixin) const; // Light wallet specific functions // fetch unspent outs from lw node and store in m_transfers @@ -1029,20 +1029,20 @@ namespace tools void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list &short_chain_history); void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list &short_chain_history, const std::list &prev_blocks, std::list &blocks, std::vector &o_indices, bool &error); void process_blocks(uint64_t start_height, const std::list &blocks, const std::vector &o_indices, uint64_t& blocks_added); - uint64_t select_transfers(uint64_t needed_money, std::vector unused_transfers_indices, std::vector& selected_transfers, bool trusted_daemon); + uint64_t select_transfers(uint64_t needed_money, std::vector unused_transfers_indices, std::vector& selected_transfers, bool trusted_daemon) const; bool prepare_file_names(const std::string& file_path); void process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height); void process_outgoing(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received, uint32_t subaddr_account, const std::set& subaddr_indices); void add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t amount_in, const std::vector &dests, const crypto::hash &payment_id, uint64_t change_amount, uint32_t subaddr_account, const std::set& subaddr_indices); - void generate_genesis(cryptonote::block& b); + void generate_genesis(cryptonote::block& b) const; void check_genesis(const crypto::hash& genesis_hash) const; //throws bool generate_chacha_key_from_secret_keys(crypto::chacha_key &key) const; crypto::hash get_payment_id(const pending_tx &ptx) const; void check_acc_out_precomp(const cryptonote::tx_out &o, const crypto::key_derivation &derivation, const std::vector &additional_derivations, size_t i, tx_scan_info_t &tx_scan_info) const; void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const; - uint64_t get_upper_transaction_size_limit(); - std::vector get_unspent_amounts_vector(); - uint64_t get_dynamic_per_kb_fee_estimate(); + uint64_t get_upper_transaction_size_limit() const; + std::vector get_unspent_amounts_vector() const; + uint64_t get_dynamic_per_kb_fee_estimate() const; float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const; std::vector pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set &subaddr_indices) const; void set_spent(size_t idx, uint64_t height);