diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.cpp | 2 | ||||
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.h | 2 | ||||
-rw-r--r-- | src/blockchain_db/blockchain_db.cpp | 2 | ||||
-rw-r--r-- | src/blockchain_db/blockchain_db.h | 2 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 119 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.h | 6 | ||||
-rw-r--r-- | src/daemon/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/daemon/daemon_commands_handler.h | 529 | ||||
-rw-r--r-- | src/daemon/main.cpp | 17 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 3 | ||||
-rw-r--r-- | src/p2p/net_peerlist.h | 4 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 8 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.h | 1 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 49 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 18 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 19 |
16 files changed, 165 insertions, 617 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index 4b254500b..221c0cf2e 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -502,7 +502,7 @@ void BlockchainBDB::remove_spent_key(const crypto::key_image& k_image) throw1(DB_ERROR("Error adding removal of key image to db transaction")); } -blobdata BlockchainBDB::output_to_blob(const tx_out& output) +blobdata BlockchainBDB::output_to_blob(const tx_out& output) const { LOG_PRINT_L3("BlockchainBDB::" << __func__); blobdata b; diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h index d4eb5434c..83588b031 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.h +++ b/src/blockchain_db/berkeleydb/db_bdb.h @@ -232,7 +232,7 @@ private: * * @return the resultant blob */ - blobdata output_to_blob(const tx_out& output); + blobdata output_to_blob(const tx_out& output) const; /** * @brief convert a tx output blob to a tx output diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index d648be44e..bfe93948a 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -129,7 +129,7 @@ void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs) } } -bool BlockchainDB::is_open() +bool BlockchainDB::is_open() const { return m_open; } diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 04d9c5384..46c860122 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -330,7 +330,7 @@ public: virtual void open(const std::string& filename, const int db_flags = 0) = 0; // returns true of the db is open/ready, else false - bool is_open(); + bool is_open() const; // close and sync the db virtual void close() = 0; diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 7d06ae57a..0ed044954 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -189,11 +189,10 @@ void mdb_txn_safe::commit(std::string message) message = "Failed to commit a transaction to the db"; } - if (mdb_txn_commit(m_txn)) + if (auto result = mdb_txn_commit(m_txn)) { m_txn = NULL; - LOG_PRINT_L0(message); - throw DB_ERROR(message.c_str()); + throw0(DB_ERROR((message + ": ").append(mdb_strerror(result)).c_str())); } m_txn = NULL; } @@ -212,7 +211,7 @@ void mdb_txn_safe::abort() } } -uint64_t mdb_txn_safe::num_active_tx() +uint64_t mdb_txn_safe::num_active_tx() const { return num_active_txns; } @@ -273,7 +272,7 @@ void BlockchainLMDB::do_resize() mdb_txn_safe::allow_new_txns(); } -bool BlockchainLMDB::need_resize() +bool BlockchainLMDB::need_resize() const { MDB_envinfo mei; @@ -285,7 +284,7 @@ bool BlockchainLMDB::need_resize() uint64_t size_used = mst.ms_psize * mei.me_last_pgno; - if ((double)size_used / mei.me_mapsize > 0.8) + if ((double)size_used / mei.me_mapsize > RESIZE_PERCENT) { return true; } @@ -322,34 +321,42 @@ void BlockchainLMDB::add_block( const block& blk throw0(BLOCK_PARENT_DNE("Top block is not new block's parent")); } + int result = 0; + MDB_val_copy<uint64_t> key(m_height); MDB_val_copy<blobdata> blob(block_to_blob(blk)); - auto res = mdb_put(*m_write_txn, m_blocks, &key, &blob, 0); - if (res) - throw0(DB_ERROR(std::string("Failed to add block blob to db transaction: ").append(mdb_strerror(res)).c_str())); + result = mdb_put(*m_write_txn, m_blocks, &key, &blob, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block blob to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<size_t> sz(block_size); - if (mdb_put(*m_write_txn, m_block_sizes, &key, &sz, 0)) - throw0(DB_ERROR("Failed to add block size to db transaction")); + result = mdb_put(*m_write_txn, m_block_sizes, &key, &sz, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block size to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> ts(blk.timestamp); - if (mdb_put(*m_write_txn, m_block_timestamps, &key, &ts, 0)) - throw0(DB_ERROR("Failed to add block timestamp to db transaction")); + result = mdb_put(*m_write_txn, m_block_timestamps, &key, &ts, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block timestamp to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<difficulty_type> diff(cumulative_difficulty); - if (mdb_put(*m_write_txn, m_block_diffs, &key, &diff, 0)) - throw0(DB_ERROR("Failed to add block cumulative difficulty to db transaction")); + result = mdb_put(*m_write_txn, m_block_diffs, &key, &diff, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block cumulative difficulty to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> coinsgen(coins_generated); - if (mdb_put(*m_write_txn, m_block_coins, &key, &coinsgen, 0)) - throw0(DB_ERROR("Failed to add block total generated coins to db transaction")); + result = mdb_put(*m_write_txn, m_block_coins, &key, &coinsgen, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block total generated coins to db transaction: ").append(mdb_strerror(result)).c_str())); - if (mdb_put(*m_write_txn, m_block_heights, &val_h, &key, 0)) - throw0(DB_ERROR("Failed to add block height by hash to db transaction")); + result = mdb_put(*m_write_txn, m_block_heights, &val_h, &key, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block height by hash to db transaction: ").append(mdb_strerror(result)).c_str())); - if (mdb_put(*m_write_txn, m_block_hashes, &key, &val_h, 0)) - throw0(DB_ERROR("Failed to add block hash to db transaction")); + result = mdb_put(*m_write_txn, m_block_hashes, &key, &val_h, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add block hash to db transaction: ").append(mdb_strerror(result)).c_str())); } @@ -393,22 +400,27 @@ void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const tr LOG_PRINT_L3("BlockchainLMDB::" << __func__); check_open(); + int result = 0; + MDB_val_copy<crypto::hash> val_h(tx_hash); MDB_val unused; if (mdb_get(*m_write_txn, m_txs, &val_h, &unused) == 0) throw1(TX_EXISTS("Attempting to add transaction that's already in the db")); MDB_val_copy<blobdata> blob(tx_to_blob(tx)); - if (mdb_put(*m_write_txn, m_txs, &val_h, &blob, 0)) - throw0(DB_ERROR("Failed to add tx blob to db transaction")); + result = mdb_put(*m_write_txn, m_txs, &val_h, &blob, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add tx blob to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> height(m_height); - if (mdb_put(*m_write_txn, m_tx_heights, &val_h, &height, 0)) - throw0(DB_ERROR("Failed to add tx block height to db transaction")); + result = mdb_put(*m_write_txn, m_tx_heights, &val_h, &height, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add tx block height to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> unlock_time(tx.unlock_time); - if (mdb_put(*m_write_txn, m_tx_unlocks, &val_h, &unlock_time, 0)) - throw0(DB_ERROR("Failed to add tx unlock time to db transaction")); + result = mdb_put(*m_write_txn, m_tx_unlocks, &val_h, &unlock_time, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add tx unlock time to db transaction: ").append(mdb_strerror(result)).c_str())); } void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx) @@ -440,27 +452,34 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou LOG_PRINT_L3("BlockchainLMDB::" << __func__); check_open(); + int result = 0; + MDB_val_copy<uint64_t> k(m_num_outputs); MDB_val_copy<crypto::hash> v(tx_hash); - if (mdb_put(*m_write_txn, m_output_txs, &k, &v, 0)) - throw0(DB_ERROR("Failed to add output tx hash to db transaction")); - if (mdb_put(*m_write_txn, m_tx_outputs, &v, &k, 0)) - throw0(DB_ERROR("Failed to add tx output index to db transaction")); + result = mdb_put(*m_write_txn, m_output_txs, &k, &v, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add output tx hash to db transaction: ").append(mdb_strerror(result)).c_str())); + result = mdb_put(*m_write_txn, m_tx_outputs, &v, &k, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add <tx hash, global output index> to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> val_local_index(local_index); - if (mdb_put(*m_write_txn, m_output_indices, &k, &val_local_index, 0)) - throw0(DB_ERROR("Failed to add tx output index to db transaction")); + result = mdb_put(*m_write_txn, m_output_indices, &k, &val_local_index, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add tx output index to db transaction: ").append(mdb_strerror(result)).c_str())); MDB_val_copy<uint64_t> val_amount(tx_output.amount); - if (auto result = mdb_put(*m_write_txn, m_output_amounts, &val_amount, &k, 0)) - throw0(DB_ERROR(std::string("Failed to add output amount to db transaction").append(mdb_strerror(result)).c_str())); + result = mdb_put(*m_write_txn, m_output_amounts, &val_amount, &k, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add output amount to db transaction: ").append(mdb_strerror(result)).c_str())); if (tx_output.target.type() == typeid(txout_to_key)) { MDB_val_copy<crypto::public_key> val_pubkey(boost::get<txout_to_key>(tx_output.target).key); - if (mdb_put(*m_write_txn, m_output_keys, &k, &val_pubkey, 0)) - throw0(DB_ERROR("Failed to add output pubkey to db transaction")); + result = mdb_put(*m_write_txn, m_output_keys, &k, &val_pubkey, 0); + if (result) + throw0(DB_ERROR(std::string("Failed to add output pubkey to db transaction: ").append(mdb_strerror(result)).c_str())); } @@ -668,7 +687,7 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image) throw1(DB_ERROR("Error adding removal of key image to db transaction")); } -blobdata BlockchainLMDB::output_to_blob(const tx_out& output) +blobdata BlockchainLMDB::output_to_blob(const tx_out& output) const { LOG_PRINT_L3("BlockchainLMDB::" << __func__); blobdata b; @@ -803,11 +822,29 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) throw0(DB_ERROR("Failed to set max number of dbs")); size_t mapsize = DEFAULT_MAPSIZE; - if (auto result = mdb_env_set_mapsize(m_env, mapsize)) - throw0(DB_ERROR(std::string("Failed to set max memory map size: ").append(mdb_strerror(result)).c_str())); + if (auto result = mdb_env_open(m_env, filename.c_str(), mdb_flags, 0644)) throw0(DB_ERROR(std::string("Failed to open lmdb environment: ").append(mdb_strerror(result)).c_str())); + MDB_envinfo mei; + mdb_env_info(m_env, &mei); + uint64_t cur_mapsize = (double)mei.me_mapsize; + + if (cur_mapsize < mapsize) + { + if (auto result = mdb_env_set_mapsize(m_env, mapsize)) + throw0(DB_ERROR(std::string("Failed to set max memory map size: ").append(mdb_strerror(result)).c_str())); + mdb_env_info(m_env, &mei); + cur_mapsize = (double)mei.me_mapsize; + LOG_PRINT_L1("LMDB memory map size: " << cur_mapsize); + } + + if (need_resize()) + { + LOG_PRINT_L0("LMDB memory map needs resized, doing that now."); + do_resize(); + } + int txn_flags = 0; if (mdb_flags & MDB_RDONLY) txn_flags |= MDB_RDONLY; @@ -890,7 +927,7 @@ void BlockchainLMDB::sync() // MDB_NOMETASYNC. Force flush to be synchronous. if (auto result = mdb_env_sync(m_env, true)) { - throw0(DB_ERROR(std::string("Failed to sync database").append(mdb_strerror(result)).c_str())); + throw0(DB_ERROR(std::string("Failed to sync database: ").append(mdb_strerror(result)).c_str())); } } diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h index ec552a0f6..6a2646816 100644 --- a/src/blockchain_db/lmdb/db_lmdb.h +++ b/src/blockchain_db/lmdb/db_lmdb.h @@ -59,7 +59,7 @@ struct mdb_txn_safe return &m_txn; } - uint64_t num_active_tx(); + uint64_t num_active_tx() const; static void prevent_new_txns(); static void wait_no_active_txns(); @@ -201,7 +201,7 @@ public: private: void do_resize(); - bool need_resize(); + bool need_resize() const; virtual void add_block( const block& blk , const size_t& block_size @@ -236,7 +236,7 @@ private: * * @return the resultant blob */ - blobdata output_to_blob(const tx_out& output); + blobdata output_to_blob(const tx_out& output) const; /** * @brief convert a tx output blob to a tx output diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt index bf25bbca9..f06712946 100644 --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -42,7 +42,6 @@ set(daemon_private_headers command_server.h core.h daemon.h - daemon_commands_handler.h executor.h p2p.h protocol.h diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h deleted file mode 100644 index 215cf26de..000000000 --- a/src/daemon/daemon_commands_handler.h +++ /dev/null @@ -1,529 +0,0 @@ -// Copyright (c) 2014-2015, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - - -/* This isn't a header file, may want to refactor this... */ -#pragma once - -#include <boost/lexical_cast.hpp> - -#include "console_handler.h" -#include "p2p/net_node.h" -#include "cryptonote_protocol/cryptonote_protocol_handler.h" -#include "common/util.h" -#include "crypto/hash.h" -#include "version.h" -#include "../../contrib/otshell_utils/utils.hpp" - -//#include "net/net_helper.h" -//#include "../p2p/p2p_protocol_defs.h" -//#include "../p2p/net_peerlist_boost_serialization.h" -//#include "net/local_ip.h" -//#include "crypto/crypto.h" -//#include "storages/levin_abstract_invoke2.h" - -class daemon_cmmands_handler -{ - nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& m_srv; -public: - daemon_cmmands_handler(nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& srv):m_srv(srv) - { - m_cmd_binder.set_handler("help", boost::bind(&daemon_cmmands_handler::help, this, _1), "Show this help"); - m_cmd_binder.set_handler("print_pl", boost::bind(&daemon_cmmands_handler::print_pl, this, _1), "Print peer list"); - m_cmd_binder.set_handler("print_cn", boost::bind(&daemon_cmmands_handler::print_cn, this, _1), "Print connections"); - m_cmd_binder.set_handler("print_bc", boost::bind(&daemon_cmmands_handler::print_bc, this, _1), "Print blockchain info in a given blocks range, print_bc <begin_height> [<end_height>]"); - //m_cmd_binder.set_handler("print_bci", boost::bind(&daemon_cmmands_handler::print_bci, this, _1)); - //m_cmd_binder.set_handler("print_bc_outs", boost::bind(&daemon_cmmands_handler::print_bc_outs, this, _1)); - m_cmd_binder.set_handler("print_block", boost::bind(&daemon_cmmands_handler::print_block, this, _1), "Print block, print_block <block_hash> | <block_height>"); - m_cmd_binder.set_handler("print_tx", boost::bind(&daemon_cmmands_handler::print_tx, this, _1), "Print transaction, print_tx <transaction_hash>"); - m_cmd_binder.set_handler("start_mining", boost::bind(&daemon_cmmands_handler::start_mining, this, _1), "Start mining for specified address, start_mining <addr> [threads=1]"); - m_cmd_binder.set_handler("stop_mining", boost::bind(&daemon_cmmands_handler::stop_mining, this, _1), "Stop mining"); - m_cmd_binder.set_handler("print_pool", boost::bind(&daemon_cmmands_handler::print_pool, this, _1), "Print transaction pool (long format)"); - m_cmd_binder.set_handler("print_pool_sh", boost::bind(&daemon_cmmands_handler::print_pool_sh, this, _1), "Print transaction pool (short format)"); - m_cmd_binder.set_handler("show_hr", boost::bind(&daemon_cmmands_handler::show_hr, this, _1), "Start showing hash rate"); - m_cmd_binder.set_handler("hide_hr", boost::bind(&daemon_cmmands_handler::hide_hr, this, _1), "Stop showing hash rate"); - m_cmd_binder.set_handler("save", boost::bind(&daemon_cmmands_handler::save, this, _1), "Save blockchain"); - m_cmd_binder.set_handler("set_log", boost::bind(&daemon_cmmands_handler::set_log, this, _1), "set_log <level> - Change current log detalization level, <level> is a number 0-4"); - m_cmd_binder.set_handler("diff", boost::bind(&daemon_cmmands_handler::diff, this, _1), "Show difficulty"); - m_cmd_binder.set_handler("out_peers", boost::bind(&daemon_cmmands_handler::out_peers_limit, this, _1), "Set max limit of out peers"); - m_cmd_binder.set_handler("limit_up", boost::bind(&daemon_cmmands_handler::limit_up, this, _1), "Set upload limit [kB/s]"); - m_cmd_binder.set_handler("limit_down", boost::bind(&daemon_cmmands_handler::limit_down, this, _1), "Set download limit [kB/s]"); - m_cmd_binder.set_handler("limit", boost::bind(&daemon_cmmands_handler::limit, this, _1), "Set download and upload limit [kB/s]"); - m_cmd_binder.set_handler("fast_exit", boost::bind(&daemon_cmmands_handler::fast_exit, this, _1), "Exit"); - m_cmd_binder.set_handler("test_drop_download", boost::bind(&daemon_cmmands_handler::test_drop_download, this, _1), "For network testing, drop downloaded blocks instead checking/adding them to blockchain. Can fake-download blocks very fast."); - m_cmd_binder.set_handler("start_save_graph", boost::bind(&daemon_cmmands_handler::start_save_graph, this, _1), ""); - m_cmd_binder.set_handler("stop_save_graph", boost::bind(&daemon_cmmands_handler::stop_save_graph, this, _1), ""); - } - - bool start_handling() - { - m_cmd_binder.start_handling(&m_srv, "", ""); - return true; - } - - void stop_handling() - { - m_cmd_binder.stop_handling(); - } - -private: - epee::srv_console_handlers_binder<nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> > > m_cmd_binder; - - - //-------------------------------------------------------------------------------- - std::string get_commands_str() - { - std::stringstream ss; - ss << CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL << ENDL; - ss << "Commands: " << ENDL; - std::string usage = m_cmd_binder.get_usage(); - boost::replace_all(usage, "\n", "\n "); - usage.insert(0, " "); - ss << usage << ENDL; - return ss.str(); - } - //-------------------------------------------------------------------------------- - bool help(const std::vector<std::string>& args) - { - std::cout << get_commands_str() << ENDL; - return true; - } - //-------------------------------------------------------------------------------- - bool print_pl(const std::vector<std::string>& args) - { - m_srv.log_peerlist(); - return true; - } - //-------------------------------------------------------------------------------- - bool save(const std::vector<std::string>& args) - { - m_srv.get_payload_object().get_core().get_blockchain_storage().store_blockchain(); - return true; - } - //-------------------------------------------------------------------------------- - bool limit_up(const std::vector<std::string>& args) - { - if(args.size()!=1) { - std::cout << "Usage: limit_up <speed>" << ENDL; - return false; - } - - int limit; - try { - limit = std::stoi(args[0]); - } - catch(std::invalid_argument& ex) { - return false; - } - - if (limit==-1) { - limit=128; - //this->islimitup=false; - } - - limit *= 1024; - - - //nodetool::epee::net_utils::connection<epee::levin::async_protocol_handler<nodetool::p2p_connection_context> >::set_rate_up_limit( limit ); - epee::net_utils::connection_basic::set_rate_up_limit( limit ); - std::cout << "Set limit-up to " << limit/1024 << " kB/s" << std::endl; - - return true; - } - - //-------------------------------------------------------------------------------- - bool limit_down(const std::vector<std::string>& args) - { - - if(args.size()!=1) { - std::cout << "Usage: limit_down <speed>" << ENDL; - return true; - } - - int limit; - try { - limit = std::stoi(args[0]); - } - - catch(std::invalid_argument& ex) { - return false; - } - - if (limit==-1) { - limit=128; - //this->islimitup=false; - } - - limit *= 1024; - - - //nodetool::epee::net_utils::connection<epee::levin::async_protocol_handler<nodetool::p2p_connection_context> >::set_rate_up_limit( limit ); - epee::net_utils::connection_basic::set_rate_down_limit( limit ); - std::cout << "Set limit-down to " << limit/1024 << " kB/s" << std::endl; - - return true; - } - -//-------------------------------------------------------------------------------- - bool limit(const std::vector<std::string>& args) - { - if(args.size()!=1) { - std::cout << "Usage: limit_down <speed>" << ENDL; - return true; - } - - int limit; - try { - limit = std::stoi(args[0]); - } - catch(std::invalid_argument& ex) { - return false; - } - - if (limit==-1) { - limit=128; - //this->islimitup=false; - } - - limit *= 1024; - - - //nodetool::epee::net_utils::connection<epee::levin::async_protocol_handler<nodetool::p2p_connection_context> >::set_rate_up_limit( limit ); - epee::net_utils::connection_basic::set_rate_down_limit( limit ); - epee::net_utils::connection_basic::set_rate_up_limit( limit ); - std::cout << "Set limit-down to " << limit/1024 << " kB/s" << std::endl; - std::cout << "Set limit-up to " << limit/1024 << " kB/s" << std::endl; - - return true; - } - //-------------------------------------------------------------------------------- - bool out_peers_limit(const std::vector<std::string>& args) { - if(args.size()!=1) { - std::cout << "Usage: limit_down <speed>" << ENDL; - return true; - } - - int limit; - try { - limit = std::stoi(args[0]); - } - - catch(std::invalid_argument& ex) { - return false; - } - - LOG_PRINT_RED_L0("connections_count: " << limit); - m_srv.m_config.m_net_config.connections_count = limit; - return true; - } - //-------------------------------------------------------------------------------- - bool show_hr(const std::vector<std::string>& args) - { - if(!m_srv.get_payload_object().get_core().get_miner().is_mining()) - { - std::cout << "Mining is not started. You need start mining before you can see hash rate." << ENDL; - } else - { - m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(true); - } - return true; - } - //-------------------------------------------------------------------------------- - bool hide_hr(const std::vector<std::string>& args) - { - m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(false); - return true; - } - //-------------------------------------------------------------------------------- - bool diff(const std::vector<std::string>& args) - { - cryptonote::difficulty_type difficulty = m_srv.get_payload_object().get_core().get_blockchain_storage().get_difficulty_for_next_block(); - uint64_t height = m_srv.get_payload_object().get_core().get_blockchain_storage().get_current_blockchain_height(); - - LOG_PRINT_GREEN("BH: " << height << ", DIFF: " << difficulty - << ", HR: " << (int) difficulty / 60L << " H/s", LOG_LEVEL_0); - - return true; - } - //-------------------------------------------------------------------------------- - bool print_bc_outs(const std::vector<std::string>& args) - { - if(args.size() != 1) - { - std::cout << "need file path as parameter" << ENDL; - return true; - } - m_srv.get_payload_object().get_core().print_blockchain_outs(args[0]); - return true; - } - //-------------------------------------------------------------------------------- - bool print_cn(const std::vector<std::string>& args) - { - m_srv.get_payload_object().log_connections(); - return true; - } - //-------------------------------------------------------------------------------- - bool print_bc(const std::vector<std::string>& args) - { - if(!args.size()) - { - std::cout << "need block index parameter" << ENDL; - return false; - } - uint64_t start_index = 0; - uint64_t end_index = 0; - uint64_t end_block_parametr = m_srv.get_payload_object().get_core().get_current_blockchain_height(); - if(!string_tools::get_xtype_from_string(start_index, args[0])) - { - std::cout << "wrong starter block index parameter" << ENDL; - return false; - } - if(args.size() >1 && !string_tools::get_xtype_from_string(end_index, args[1])) - { - std::cout << "wrong end block index parameter" << ENDL; - return false; - } - if (end_index == 0) - { - end_index = end_block_parametr; - } - if (end_index > end_block_parametr) - { - std::cout << "end block index parameter shouldn't be greater than " << end_block_parametr << ENDL; - return false; - } - if (end_index <= start_index) - { - std::cout << "end block index should be greater than starter block index" << ENDL; - return false; - } - - m_srv.get_payload_object().get_core().print_blockchain(start_index, end_index); - return true; - } - //-------------------------------------------------------------------------------- - bool print_bci(const std::vector<std::string>& args) - { - m_srv.get_payload_object().get_core().print_blockchain_index(); - return true; - } - - bool set_log(const std::vector<std::string>& args) - { - if(args.size() != 1) - { - std::cout << "use: set_log <log_level_number_0-4>" << ENDL; - return true; - } - - uint16_t l = 0; - if(!string_tools::get_xtype_from_string(l, args[0])) - { - std::cout << "wrong number format, use: set_log <log_level_number_0-4>" << ENDL; - return true; - } - - if(LOG_LEVEL_4 < l) - { - std::cout << "wrong number range, use: set_log <log_level_number_0-4>" << ENDL; - return true; - } - - // TODO what the hell causes compilation warning in following code line -PUSH_WARNINGS -DISABLE_GCC_WARNING(maybe-uninitialized) - log_space::log_singletone::get_set_log_detalisation_level(true, l); - int otshell_utils_log_level = 100 - (l * 25); - gCurrentLogger.setDebugLevel(otshell_utils_log_level); -POP_WARNINGS - - return true; - } - - //-------------------------------------------------------------------------------- - template <typename T> - static bool print_as_json(T& obj) - { - std::cout << cryptonote::obj_to_json_str(obj) << ENDL; - return true; - } - //-------------------------------------------------------------------------------- - bool print_block_by_height(uint64_t height) - { - std::list<cryptonote::block> blocks; - m_srv.get_payload_object().get_core().get_blocks(height, 1, blocks); - - if (1 == blocks.size()) - { - cryptonote::block& block = blocks.front(); - std::cout << "block_id: " << get_block_hash(block) << ENDL; - print_as_json(block); - } - else - { - uint64_t current_height; - crypto::hash top_id; - m_srv.get_payload_object().get_core().get_blockchain_top(current_height, top_id); - std::cout << "block wasn't found. Current block chain height: " << current_height << ", requested: " << height << std::endl; - return false; - } - - return true; - } - //-------------------------------------------------------------------------------- - bool print_block_by_hash(const std::string& arg) - { - crypto::hash block_hash; - if (!parse_hash256(arg, block_hash)) - { - return false; - } - - std::list<crypto::hash> block_ids; - block_ids.push_back(block_hash); - std::list<cryptonote::block> blocks; - std::list<crypto::hash> missed_ids; - m_srv.get_payload_object().get_core().get_blocks(block_ids, blocks, missed_ids); - - if (1 == blocks.size()) - { - cryptonote::block block = blocks.front(); - print_as_json(block); - } - else - { - std::cout << "block wasn't found: " << arg << std::endl; - return false; - } - - return true; - } - //-------------------------------------------------------------------------------- - bool print_block(const std::vector<std::string>& args) - { - if (args.empty()) - { - std::cout << "expected: print_block (<block_hash> | <block_height>)" << std::endl; - return true; - } - - const std::string& arg = args.front(); - try - { - uint64_t height = boost::lexical_cast<uint64_t>(arg); - print_block_by_height(height); - } - catch (boost::bad_lexical_cast&) - { - print_block_by_hash(arg); - } - - return true; - } - //-------------------------------------------------------------------------------- - bool print_tx(const std::vector<std::string>& args) - { - if (args.empty()) - { - std::cout << "expected: print_tx <transaction hash>" << std::endl; - return true; - } - - const std::string& str_hash = args.front(); - crypto::hash tx_hash; - if (!parse_hash256(str_hash, tx_hash)) - { - return true; - } - - std::vector<crypto::hash> tx_ids; - tx_ids.push_back(tx_hash); - std::list<cryptonote::transaction> txs; - std::list<crypto::hash> missed_ids; - m_srv.get_payload_object().get_core().get_transactions(tx_ids, txs, missed_ids); - - if (1 == txs.size()) - { - cryptonote::transaction tx = txs.front(); - print_as_json(tx); - } - else - { - std::cout << "transaction wasn't found: <" << str_hash << '>' << std::endl; - } - - return true; - } - //-------------------------------------------------------------------------------- - bool print_pool(const std::vector<std::string>& args) - { - LOG_PRINT_L0("Pool state: " << ENDL << m_srv.get_payload_object().get_core().print_pool(false)); - return true; - } - //-------------------------------------------------------------------------------- - bool print_pool_sh(const std::vector<std::string>& args) - { - LOG_PRINT_L0("Pool state: " << ENDL << m_srv.get_payload_object().get_core().print_pool(true)); - return true; - } //-------------------------------------------------------------------------------- - bool start_mining(const std::vector<std::string>& args) - { - if(!args.size()) - { - std::cout << "Please, specify wallet address to mine for: start_mining <addr> [threads=1]" << std::endl; - return true; - } - - cryptonote::account_public_address adr; - if(!cryptonote::get_account_address_from_str(adr, args.front())) - { - std::cout << "target account address has wrong format" << std::endl; - return true; - } - size_t threads_count = 1; - if(args.size() > 1) - { - bool ok = string_tools::get_xtype_from_string(threads_count, args[1]); - threads_count = (ok && 0 < threads_count) ? threads_count : 1; - } - - boost::thread::attributes attrs; - attrs.set_stack_size(THREAD_STACK_SIZE); - - m_srv.get_payload_object().get_core().get_miner().start(adr, threads_count, attrs); - return true; - } - //-------------------------------------------------------------------------------- - bool stop_mining(const std::vector<std::string>& args) - { - m_srv.get_payload_object().get_core().get_miner().stop(); - return true; - } -}; diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index 62b655ccd..b8f0b697b 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -155,6 +155,12 @@ int main(int argc, char const * argv[]) auto data_dir_arg = testnet_mode ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; + // data_dir + // default: e.g. ~/.bitmonero/ or ~/.bitmonero/testnet + // if data-dir argument given: + // absolute path + // relative path: relative to cwd + // Create data dir if it doesn't exist boost::filesystem::path data_dir = boost::filesystem::absolute( command_line::get_arg(vm, data_dir_arg)); @@ -238,9 +244,18 @@ int main(int argc, char const * argv[]) } } + // log_file_path + // default: <data_dir>/<CRYPTONOTE_NAME>.log + // if log-file argument given: + // absolute path + // relative path: relative to data_dir + // Set log file { - bf::path log_file_path{bf::absolute(command_line::get_arg(vm, daemon_args::arg_log_file), relative_path_base)}; + bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")}; + if (! vm["log-file"].defaulted()) + log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file); + log_file_path = bf::absolute(log_file_path, relative_path_base); epee::log_space::log_singletone::add_logger( LOGGER_FILE diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 79b52711a..4f6d0228a 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -621,11 +621,10 @@ bool t_rpc_command_executor::print_transaction_pool_short() { return true; } -// TODO: update this for testnet bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads) { cryptonote::COMMAND_RPC_START_MINING::request req; cryptonote::COMMAND_RPC_START_MINING::response res; - req.miner_address = cryptonote::get_account_address_as_str(false, address); + req.miner_address = cryptonote::get_account_address_as_str(m_rpc_server->is_testnet(), address); req.threads_count = num_threads; std::string fail_message = "Mining did not start"; diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index 9407e7bce..f738c68f6 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -204,7 +204,7 @@ namespace nodetool return true; } //-------------------------------------------------------------------------------------------------- - inline void peerlist_manager::trim_white_peerlist() + inline void peerlist_manager::trim_gray_peerlist() { while(m_peers_gray.size() > P2P_LOCAL_GRAY_PEERLIST_LIMIT) { @@ -213,7 +213,7 @@ namespace nodetool } } //-------------------------------------------------------------------------------------------------- - inline void peerlist_manager::trim_gray_peerlist() + inline void peerlist_manager::trim_white_peerlist() { while(m_peers_white.size() > P2P_LOCAL_WHITE_PEERLIST_LIMIT) { diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 561161950..24c7d242f 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -291,6 +291,7 @@ namespace cryptonote if(!get_account_address_from_str(adr, m_testnet, req.miner_address)) { res.status = "Failed, wrong address"; + LOG_PRINT_L0(res.status); return true; } @@ -300,6 +301,7 @@ namespace cryptonote if(!m_core.get_miner().start(adr, static_cast<size_t>(req.threads_count), attrs)) { res.status = "Failed, mining not started"; + LOG_PRINT_L0(res.status); return true; } res.status = CORE_RPC_STATUS_OK; @@ -311,6 +313,7 @@ namespace cryptonote if(!m_core.get_miner().stop()) { res.status = "Failed, mining not stopped"; + LOG_PRINT_L0(res.status); return true; } res.status = CORE_RPC_STATUS_OK; @@ -349,10 +352,10 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res) { - /* std::list<nodetool::peerlist_entry> white_list; std::list<nodetool::peerlist_entry> gray_list; - m_p2p.get_peerlist(white_list, gray_list); + m_p2p.get_peerlist_manager().get_peerlist_full(white_list, gray_list); + for (auto & entry : white_list) { @@ -364,7 +367,6 @@ namespace cryptonote res.gray_list.emplace_back(entry.id, entry.adr.ip, entry.adr.port, entry.last_seen); } - */ res.status = CORE_RPC_STATUS_OK; return true; } diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index cee8df25d..6152dea03 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -67,6 +67,7 @@ namespace cryptonote bool init( const boost::program_options::variables_map& vm ); + bool is_testnet() const { return m_testnet; } CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 2b2488952..e47938357 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -64,6 +64,7 @@ using namespace epee; using namespace cryptonote; using boost::lexical_cast; namespace po = boost::program_options; +namespace bf = boost::filesystem; #define EXTENDED_LOGS_FILE "wallet_details.log" @@ -82,7 +83,8 @@ namespace const command_line::arg_descriptor<bool> arg_restore_deterministic_wallet = {"restore-deterministic-wallet", "Recover wallet using electrum-style mnemonic", false}; const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", "creates non-deterministic view and spend keys", false}; const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", "Use daemon instance at port <arg> instead of 8081", 0}; - const command_line::arg_descriptor<uint32_t> arg_log_level = {"set_log", "", 0, true}; + const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0}; + const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", "Specify log file", ""}; const command_line::arg_descriptor<bool> arg_testnet = {"testnet", "Used to deploy test nets. The daemon must be launched with --testnet flag", false}; const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", "Restricts RPC to view only commands", false}; @@ -203,14 +205,16 @@ std::string simple_wallet::get_commands_str() bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { - success_msg_writer() << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl; + // don't log + std::cout << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl; return true; } bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { - success_msg_writer() << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl; + // don't log + std::cout << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl; return true; } @@ -423,6 +427,7 @@ void simple_wallet::print_seed(std::string seed) "your email or on file storage services outside of your immediate control.\n"; boost::replace_nth(seed, " ", 15, "\n"); boost::replace_nth(seed, " ", 7, "\n"); + // don't log std::cout << seed << std::endl; } @@ -624,8 +629,8 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string { recovery_val = m_wallet->generate(wallet_file, password, recovery_key, recover, two_random); message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " - << m_wallet->get_account().get_public_address_str(m_wallet->testnet()) << std::endl << "view key: " - << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); + << m_wallet->get_account().get_public_address_str(m_wallet->testnet()); + std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << ENDL; } catch (const std::exception& e) { @@ -1349,6 +1354,12 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_daemon_port); command_line::add_arg(desc_params, arg_command); command_line::add_arg(desc_params, arg_log_level); + + bf::path default_log {log_space::log_singletone::get_default_log_folder()}; + default_log /= log_space::log_singletone::get_default_log_file(); + std::cout << "default_log: " << default_log << ENDL; + command_line::add_arg(desc_params, arg_log_file, default_log.string()); + command_line::add_arg(desc_params, arg_restore_deterministic_wallet ); command_line::add_arg(desc_params, arg_non_deterministic ); command_line::add_arg(desc_params, arg_electrum_seed ); @@ -1388,20 +1399,32 @@ int main(int argc, char* argv[]) if (!r) return 0; - //set up logging options - log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); + // log_file_path + // default: <simplewallet_path>/simplewallet.log + // if log-file argument given: + // absolute path + // relative path: relative to cwd + + // Set log file + bf::path log_file_path {bf::absolute(command_line::get_arg(vm, arg_log_file))}; + + // Set up logging options + int log_level = LOG_LEVEL_2; + log_space::get_set_log_detalisation_level(true, log_level); //log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_0); log_space::log_singletone::add_logger(LOGGER_FILE, - log_space::log_singletone::get_default_log_file().c_str(), - log_space::log_singletone::get_default_log_folder().c_str(), LOG_LEVEL_4); + log_file_path.filename().string().c_str(), + log_file_path.parent_path().string().c_str(), + LOG_LEVEL_4 + ); message_writer(epee::log_space::console_color_white, true) << CRYPTONOTE_NAME << " wallet v" << MONERO_VERSION_FULL; if(command_line::has_arg(vm, arg_log_level)) - { - LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, arg_log_level)); - log_space::get_set_log_detalisation_level(true, command_line::get_arg(vm, arg_log_level)); - } + log_level = command_line::get_arg(vm, arg_log_level); + LOG_PRINT_L0("Setting log level = " << log_level); + message_writer(epee::log_space::console_color_white, true) << "Logging at log level " << log_level << " to " << log_file_path.string(); + log_space::get_set_log_detalisation_level(true, log_level); if(command_line::has_arg(vm, tools::wallet_rpc_server::arg_rpc_bind_port)) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7928e1c62..5ff8ae408 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -89,7 +89,7 @@ void wallet2::init(const std::string& daemon_address, uint64_t upper_transaction m_daemon_address = daemon_address; } //---------------------------------------------------------------------------------------------------- -bool wallet2::is_deterministic() +bool wallet2::is_deterministic() const { crypto::secret_key second; keccak((uint8_t *)&get_account().get_keys().m_spend_secret_key, sizeof(crypto::secret_key), (uint8_t *)&second, sizeof(crypto::secret_key)); @@ -98,7 +98,7 @@ bool wallet2::is_deterministic() return keys_deterministic; } //---------------------------------------------------------------------------------------------------- -bool wallet2::get_seed(std::string& electrum_words) +bool wallet2::get_seed(std::string& electrum_words) const { bool keys_deterministic = is_deterministic(); if (!keys_deterministic) @@ -119,7 +119,7 @@ bool wallet2::get_seed(std::string& electrum_words) /*! * \brief Gets the seed language */ -const std::string wallet2::get_seed_language() +const std::string &wallet2::get_seed_language() const { return seed_language; } @@ -287,7 +287,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonot m_callback->on_new_block(height, b); } //---------------------------------------------------------------------------------------------------- -void wallet2::get_short_chain_history(std::list<crypto::hash>& ids) +void wallet2::get_short_chain_history(std::list<crypto::hash>& ids) const { size_t i = 0; size_t current_multiplier = 1; @@ -580,7 +580,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa * can be used prior to rewriting wallet keys file, to ensure user has entered the correct password * */ -bool wallet2::verify_password(const std::string& password) +bool wallet2::verify_password(const std::string& password) const { const std::string keys_file_name = m_keys_file; wallet2::keys_file_data keys_file_data; @@ -765,7 +765,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password) m_local_bc_height = m_blockchain.size(); } //---------------------------------------------------------------------------------------------------- -void wallet2::check_genesis(const crypto::hash& genesis_hash) { +void wallet2::check_genesis(const crypto::hash& genesis_hash) const { std::string what("Genesis block missmatch. You probably use wallet without testnet flag with blockchain from test network or vice versa"); THROW_WALLET_EXCEPTION_IF(genesis_hash != m_blockchain[0], error::wallet_internal_error, what); @@ -777,17 +777,17 @@ void wallet2::store() THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_wallet_file); } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::unlocked_balance() +uint64_t wallet2::unlocked_balance() const { uint64_t amount = 0; - BOOST_FOREACH(transfer_details& td, m_transfers) + BOOST_FOREACH(const transfer_details& td, m_transfers) if(!td.m_spent && is_transfer_unlocked(td)) amount += td.amount(); return amount; } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::balance() +uint64_t wallet2::balance() const { uint64_t amount = 0; BOOST_FOREACH(auto& td, m_transfers) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 1febfba39..712cda40a 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -157,8 +157,9 @@ namespace tools /*! * \brief verifies given password is correct for default wallet keys file */ - bool verify_password(const std::string& password); + bool verify_password(const std::string& password) const; cryptonote::account_base& get_account(){return m_account;} + const cryptonote::account_base& get_account()const{return m_account;} // upper_transaction_size_limit as defined below is set to // approximately 125% of the fixed minimum allowable penalty @@ -176,12 +177,12 @@ namespace tools /*! * \brief Checks if deterministic wallet */ - bool is_deterministic(); - bool get_seed(std::string& electrum_words); + bool is_deterministic() const; + bool get_seed(std::string& electrum_words) const; /*! * \brief Gets the seed language */ - const std::string get_seed_language(); + const std::string &get_seed_language() const; /*! * \brief Sets the seed language */ @@ -195,11 +196,11 @@ namespace tools void refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money); bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok); - bool testnet() { return m_testnet; } + bool testnet() const { return m_testnet; } bool restricted() const { return m_restricted; } - uint64_t balance(); - uint64_t unlocked_balance(); + uint64_t balance() const; + uint64_t unlocked_balance() const; template<typename T> void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy); template<typename T> @@ -267,7 +268,7 @@ namespace tools void process_new_transaction(const cryptonote::transaction& tx, uint64_t height); void process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height); void detach_blockchain(uint64_t height); - void get_short_chain_history(std::list<crypto::hash>& ids); + void get_short_chain_history(std::list<crypto::hash>& ids) const; bool is_tx_spendtime_unlocked(uint64_t unlock_time) const; bool is_transfer_unlocked(const transfer_details& td) const; bool clear(); @@ -277,7 +278,7 @@ namespace tools void process_unconfirmed(const cryptonote::transaction& tx); void add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t change_amount); void generate_genesis(cryptonote::block& b); - void check_genesis(const crypto::hash& genesis_hash); //throws + void check_genesis(const crypto::hash& genesis_hash) const; //throws cryptonote::account_base m_account; std::string m_daemon_address; |