diff options
author | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-04-07 16:02:15 +0100 |
---|---|---|
committer | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-04-07 16:02:15 +0100 |
commit | a401a02ddb3fb045d998cf650292cab3b3ebfd58 (patch) | |
tree | 61d021af997193aba90b95b70836c2d031334aff /src | |
parent | json rpc for wallet and bugfix (diff) | |
download | monero-a401a02ddb3fb045d998cf650292cab3b3ebfd58.tar.xz |
Improvements in JSON RPC
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_config.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain_storage.h | 16 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/miner.cpp | 8 | ||||
-rw-r--r-- | src/daemon/daemon.cpp | 2 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 26 | ||||
-rw-r--r-- | src/version.h.in | 4 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 54 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 33 | ||||
-rw-r--r-- | src/wallet/wallet_errors.h | 2 |
10 files changed, 72 insertions, 77 deletions
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 35dfcb3bb..9f0b5bd9b 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -64,7 +64,7 @@ #define P2P_DEFAULT_PEERS_IN_HANDSHAKE 250 #define P2P_DEFAULT_CONNECTION_TIMEOUT 5000 //5 seconds #define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000 //2 seconds -#define P2P_DEFAULT_INVOKE_TIMEOUT 20*1000 //2 minutes +#define P2P_DEFAULT_INVOKE_TIMEOUT 60*2*1000 //2 minutes #define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 //5 seconds #define P2P_STAT_TRUSTED_PUB_KEY "8f80f9a5a434a9f1510d13336228debfee9c918ce505efe225d8c94d045fa115" #define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT 70 diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h index 5a3ff3d84..1ea5e29ea 100644 --- a/src/cryptonote_core/blockchain_storage.h +++ b/src/cryptonote_core/blockchain_storage.h @@ -63,9 +63,6 @@ namespace cryptonote bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks, std::list<transaction>& txs); bool get_blocks(uint64_t start_offset, size_t count, std::list<block>& blocks); bool get_alternative_blocks(std::list<block>& blocks); - //bool get_orphaned_blocks(std::list<block>& orphaned_by_prev_id, std::list<block>& orphaned_by_tx); - //size_t get_orphaned_by_prev_blocks_count(); - //size_t get_orphaned_by_tx_blocks_count(); size_t get_alternative_blocks_count(); crypto::hash get_block_id_by_height(uint64_t height); bool get_block_by_hash(const crypto::hash &h, block &blk); @@ -87,7 +84,6 @@ namespace cryptonote crypto::hash get_tail_id(uint64_t& height); difficulty_type get_difficulty_for_next_block(); bool add_new_block(const block& bl_, block_verification_context& bvc); - bool reset_and_set_genesis_block(const block& b); bool create_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, const blobdata& ex_nonce); bool have_block(const crypto::hash& id); @@ -97,11 +93,9 @@ namespace cryptonote bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp); bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset); bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count); - //bool get_chain_entry(const NOTIFY_REQUEST_CHAIN_ENTRY::request& req, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp); bool handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp); bool handle_get_objects(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res); bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res); - //bool get_outs_for_amounts(uint64_t amount, std::vector<std::pair<crypto::hash, size_t> >& keys, std::map<crypto::hash, transaction>& txs); bool get_backward_blocks_sizes(size_t from_height, std::vector<size_t>& sz, size_t count); bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs); bool store_blockchain(); @@ -111,6 +105,7 @@ namespace cryptonote bool check_tx_inputs(const transaction& tx, uint64_t& pmax_used_block_height, crypto::hash& max_used_block_id); uint64_t get_current_comulative_blocksize_limit(); bool is_storing_blockchain(){return m_is_blockchain_storing;} + uint64_t block_difficulty(size_t i); template<class t_ids_container, class t_blocks_container, class t_missed_container> bool get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs) @@ -191,9 +186,6 @@ namespace cryptonote std::atomic<bool> m_is_in_checkpoint_zone; std::atomic<bool> m_is_blockchain_storing; - - - bool switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain); bool pop_block_from_blockchain(); bool purge_block_data_from_blockchain(const block& b, size_t processed_tx_count); @@ -203,26 +195,20 @@ namespace cryptonote bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc); bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc); bool handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc); - //bool handle_block_as_orphaned(const block& b, const crypto::hash& id, block_verification_context& bvc); difficulty_type get_next_difficulty_for_alternative_chain(const std::list<blocks_ext_by_hash::iterator>& alt_chain, block_extended_info& bei); bool prevalidate_miner_transaction(const block& b, uint64_t height); bool validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins); bool validate_transaction(const block& b, uint64_t height, const transaction& tx); - //bool add_block_to_orphaned_by_tx(const block& bl, const crypto::hash& h); - //bool finish_forward_orphaned_chain(std::list< orphans_indexed_container::index<by_id>::type::iterator >& orph_chain); bool rollback_blockchain_switching(std::list<block>& original_chain, size_t rollback_height); bool add_transaction_from_block(const transaction& tx, const crypto::hash& tx_id, const crypto::hash& bl_id, uint64_t bl_height); bool push_transaction_to_global_outs_index(const transaction& tx, const crypto::hash& tx_id, std::vector<uint64_t>& global_indexes); bool pop_transaction_from_global_index(const transaction& tx, const crypto::hash& tx_id); - //bool review_orphaned_blocks_with_new_block_id(const crypto::hash& id, bool main_chain); - //void review_orphaned_blocks_finisher(); bool get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t count); bool add_out_to_get_random_outs(std::vector<std::pair<crypto::hash, size_t> >& amount_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, uint64_t amount, size_t i); bool is_tx_spendtime_unlocked(uint64_t unlock_time); bool add_block_as_invalid(const block& bl, const crypto::hash& h); bool add_block_as_invalid(const block_extended_info& bei, const crypto::hash& h); size_t find_end_of_allowed_index(const std::vector<std::pair<crypto::hash, size_t> >& amount_outs); - uint64_t block_difficulty(size_t i); bool check_block_timestamp_main(const block& b); bool check_block_timestamp(std::vector<uint64_t> timestamps, const block& b); uint64_t get_adjusted_time(); diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 8f42b807a..554e466cc 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -36,7 +36,7 @@ namespace cryptonote uint64_t amount; //money account_public_address addr; //destination address - tx_destination_entry() { } + tx_destination_entry() : amount(0), addr(AUTO_VAL_INIT(addr)) { } tx_destination_entry(uint64_t a, const account_public_address &ad) : amount(a), addr(ad) { } }; diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp index a882e1899..142c81f68 100644 --- a/src/cryptonote_core/miner.cpp +++ b/src/cryptonote_core/miner.cpp @@ -48,7 +48,8 @@ namespace cryptonote m_last_hr_merge_time(0), m_hashes(0), m_do_print_hashrate(false), - m_do_mining(false) + m_do_mining(false), + m_current_hash_rate(0) { } @@ -225,7 +226,10 @@ namespace cryptonote //----------------------------------------------------------------------------------------------------- uint64_t miner::get_speed() { - return m_current_hash_rate; + if(is_mining()) + return m_current_hash_rate; + else + return 0; } //----------------------------------------------------------------------------------------------------- void miner::send_stop_signal() diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index b537f91ca..329f44e7f 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0); - log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, 0); + log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); LOG_PRINT_L0("Starting..."); TRY_ENTRY(); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a8aa7dc00..a4cae0480 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -92,10 +92,10 @@ namespace } template<typename T> - message_writer& operator<<(const T& val) + std::ostream& operator<<(const T& val) { m_oss << val; - return *this; + return m_oss; } ~message_writer() @@ -166,7 +166,7 @@ simple_wallet::simple_wallet() : m_daemon_port(0) , m_refresh_progress_reporter(*this) { - m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining <threads_count> - Start mining in daemon"); + m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining [<number_of_threads>] - Start mining in daemon"); m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), "Stop mining in daemon"); m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, _1), "Resynchronize transactions and balance"); m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance"); @@ -295,7 +295,7 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas try { m_wallet->generate(wallet_file, password); - message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str(); + message_writer(epee::log_space::console_color_white, true) << "Generated new wallet: " << m_wallet->get_account().get_public_address_str() << std::endl << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); } catch (const std::exception& e) { @@ -389,6 +389,8 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args) COMMAND_RPC_START_MINING::request req; req.miner_address = m_wallet->get_account().get_public_address_str(); + bool ok = true; + size_t max_mining_threads_count = (std::max)(std::thread::hardware_concurrency(), static_cast<unsigned>(2)); if (0 == args.size()) { req.threads_count = 1; @@ -396,17 +398,19 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args) else if (1 == args.size()) { uint16_t num; - bool ok = string_tools::get_xtype_from_string(num, args[0]); - if(!ok || 0 == num) - { - fail_msg_writer() << "wrong number of mining threads: \"" << args[0] << "\""; - return true; - } + ok = string_tools::get_xtype_from_string(num, args[0]); + ok &= (1 <= num && num <= max_mining_threads_count); req.threads_count = num; } else { - fail_msg_writer() << "wrong number of arguments, expected the number of mining threads"; + ok = false; + } + + if (!ok) + { + fail_msg_writer() << "invalid arguments. Please use start_mining [<number_of_threads>], " << + "<number_of_threads> should be from 1 to " << max_mining_threads_count; return true; } diff --git a/src/version.h.in b/src/version.h.in index b4e144387..2fc114a34 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -1,4 +1,4 @@ #define BUILD_COMMIT_ID "@VERSION@" -#define PROJECT_VERSION "0.8.3" -#define PROJECT_VERSION_BUILD_NO "288" +#define PROJECT_VERSION "0.8.4" +#define PROJECT_VERSION_BUILD_NO "289" #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO "(" BUILD_COMMIT_ID ")" diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 572affb2f..e8b6c22fd 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -38,10 +38,10 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ uint64_t tx_money_got_in_outs = 0; crypto::public_key tx_pub_key = null_pkey; bool r = parse_and_validate_tx_extra(tx, tx_pub_key); - CHECK_AND_THROW_WALLET_EX(!r, error::tx_extra_parse_error, tx); + THROW_WALLET_EXCEPTION_IF(!r, error::tx_extra_parse_error, tx); r = lookup_acc_outs(m_account.get_keys(), tx, tx_pub_key, outs, tx_money_got_in_outs); - CHECK_AND_THROW_WALLET_EX(!r, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys()); + THROW_WALLET_EXCEPTION_IF(!r, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys()); if(!outs.empty() && tx_money_got_in_outs) { @@ -51,16 +51,16 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ cryptonote::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response res = AUTO_VAL_INIT(res); req.txid = get_transaction_hash(tx); bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/get_o_indexes.bin", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT); - CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "get_o_indexes.bin"); - CHECK_AND_THROW_WALLET_EX(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_o_indexes.bin"); - CHECK_AND_THROW_WALLET_EX(res.status != CORE_RPC_STATUS_OK, error::get_out_indices_error, res.status); - CHECK_AND_THROW_WALLET_EX(res.o_indexes.size() != tx.vout.size(), error::wallet_internal_error, + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "get_o_indexes.bin"); + THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_o_indexes.bin"); + THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_out_indices_error, res.status); + THROW_WALLET_EXCEPTION_IF(res.o_indexes.size() != tx.vout.size(), error::wallet_internal_error, "transactions outputs size=" + std::to_string(tx.vout.size()) + " not match with COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES response size=" + std::to_string(res.o_indexes.size())); BOOST_FOREACH(size_t o, outs) { - CHECK_AND_THROW_WALLET_EX(tx.vout.size() <= o, error::wallet_internal_error, "wrong out in transaction: internal index=" + + THROW_WALLET_EXCEPTION_IF(tx.vout.size() <= o, error::wallet_internal_error, "wrong out in transaction: internal index=" + std::to_string(o) + ", total_outs=" + std::to_string(tx.vout.size())); m_transfers.push_back(boost::value_initialized<transfer_details>()); @@ -72,7 +72,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ td.m_spent = false; cryptonote::keypair in_ephemeral; cryptonote::generate_key_image_helper(m_account.get_keys(), tx_pub_key, o, in_ephemeral, td.m_key_image); - CHECK_AND_THROW_WALLET_EX(in_ephemeral.pub != boost::get<cryptonote::txout_to_key>(tx.vout[o].target).key, + THROW_WALLET_EXCEPTION_IF(in_ephemeral.pub != boost::get<cryptonote::txout_to_key>(tx.vout[o].target).key, error::wallet_internal_error, "key_image generated ephemeral public key not matched with output_key"); m_key_images[td.m_key_image] = m_transfers.size()-1; @@ -108,7 +108,7 @@ void wallet2::process_unconfirmed(const cryptonote::transaction& tx) void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height) { //handle transactions from new block - CHECK_AND_THROW_WALLET_EX(height != m_blockchain.size(), error::wallet_internal_error, + THROW_WALLET_EXCEPTION_IF(height != m_blockchain.size(), error::wallet_internal_error, "current_index=" + std::to_string(height) + ", m_blockchain.size()=" + std::to_string(m_blockchain.size())); //optimization: seeking only for blocks that are not older then the wallet creation time plus 1 day. 1 day is for possible user incorrect time setup @@ -123,7 +123,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonot { cryptonote::transaction tx; bool r = parse_and_validate_tx_from_blob(txblob, tx); - CHECK_AND_THROW_WALLET_EX(!r, error::tx_parse_error, txblob); + THROW_WALLET_EXCEPTION_IF(!r, error::tx_parse_error, txblob); process_new_transaction(tx, height); } TIME_MEASURE_FINISH(txs_handle_time); @@ -173,10 +173,10 @@ void wallet2::pull_blocks(size_t& blocks_added) cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::response res = AUTO_VAL_INIT(res); get_short_chain_history(req.block_ids); bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getblocks.bin", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT); - CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "getblocks.bin"); - CHECK_AND_THROW_WALLET_EX(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getblocks.bin"); - CHECK_AND_THROW_WALLET_EX(res.status != CORE_RPC_STATUS_OK, error::get_blocks_error, res.status); - CHECK_AND_THROW_WALLET_EX(m_blockchain.size() <= res.start_height, error::wallet_internal_error, + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getblocks.bin"); + THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getblocks.bin"); + THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_blocks_error, res.status); + THROW_WALLET_EXCEPTION_IF(m_blockchain.size() <= res.start_height, error::wallet_internal_error, "wrong daemon response: m_start_height=" + std::to_string(res.start_height) + " not less than local blockchain size=" + std::to_string(m_blockchain.size())); @@ -185,7 +185,7 @@ void wallet2::pull_blocks(size_t& blocks_added) { cryptonote::block bl; r = cryptonote::parse_and_validate_block_from_blob(bl_entry.block, bl); - CHECK_AND_THROW_WALLET_EX(!r, error::block_parse_error, bl_entry.block); + THROW_WALLET_EXCEPTION_IF(!r, error::block_parse_error, bl_entry.block); crypto::hash bl_id = get_block_hash(bl); if(current_index >= m_blockchain.size()) @@ -196,7 +196,7 @@ void wallet2::pull_blocks(size_t& blocks_added) else if(bl_id != m_blockchain[current_index]) { //split detected here !!! - CHECK_AND_THROW_WALLET_EX(current_index == res.start_height, error::wallet_internal_error, + THROW_WALLET_EXCEPTION_IF(current_index == res.start_height, error::wallet_internal_error, "wrong daemon response: split starts from the first block in response " + string_tools::pod_to_hex(bl_id) + " (height " + std::to_string(res.start_height) + "), local block id at this height: " + string_tools::pod_to_hex(m_blockchain[current_index])); @@ -288,7 +288,7 @@ void wallet2::detach_blockchain(uint64_t height) for(size_t i = i_start; i!= m_transfers.size();i++) { auto it_ki = m_key_images.find(m_transfers[i].m_key_image); - CHECK_AND_THROW_WALLET_EX(it_ki == m_key_images.end(), error::wallet_internal_error, "key image not found"); + THROW_WALLET_EXCEPTION_IF(it_ki == m_key_images.end(), error::wallet_internal_error, "key image not found"); m_key_images.erase(it_ki); ++transfers_detached; } @@ -355,9 +355,9 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa wallet2::keys_file_data keys_file_data; std::string buf; bool r = epee::file_io_utils::load_file_to_string(keys_file_name, buf); - CHECK_AND_THROW_WALLET_EX(!r, error::file_read_error, keys_file_name); + THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, keys_file_name); r = ::serialization::parse_binary(buf, keys_file_data); - CHECK_AND_THROW_WALLET_EX(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + keys_file_name + '\"'); + THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + keys_file_name + '\"'); crypto::chacha8_key key; crypto::generate_chacha8_key(password, key); @@ -369,7 +369,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa r = epee::serialization::load_t_from_binary(m_account, account_data); r = r && verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key); r = r && verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key); - CHECK_AND_THROW_WALLET_EX(!r, error::invalid_password); + THROW_WALLET_EXCEPTION_IF(!r, error::invalid_password); } //---------------------------------------------------------------------------------------------------- void wallet2::generate(const std::string& wallet_, const std::string& password) @@ -378,14 +378,14 @@ void wallet2::generate(const std::string& wallet_, const std::string& password) prepare_file_names(wallet_); boost::system::error_code ignored_ec; - CHECK_AND_THROW_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file); - CHECK_AND_THROW_WALLET_EX(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file); + 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.generate(); m_account_public_address = m_account.get_keys().m_account_address; bool r = store_keys(m_keys_file, password); - CHECK_AND_THROW_WALLET_EX(!r, error::file_save_error, m_keys_file); + 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()); if(!r) LOG_PRINT_RED_L0("String with address text not saved"); @@ -427,7 +427,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password) boost::system::error_code e; bool exists = boost::filesystem::exists(m_keys_file, e); - CHECK_AND_THROW_WALLET_EX(e || !exists, error::file_not_found, m_keys_file); + THROW_WALLET_EXCEPTION_IF(e || !exists, error::file_not_found, m_keys_file); load_keys(m_keys_file, password); LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str()); @@ -441,8 +441,8 @@ void wallet2::load(const std::string& wallet_, const std::string& password) return; } bool r = tools::unserialize_obj_from_file(*this, m_wallet_file); - CHECK_AND_THROW_WALLET_EX(!r, error::file_read_error, m_wallet_file); - CHECK_AND_THROW_WALLET_EX( + THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, m_wallet_file); + THROW_WALLET_EXCEPTION_IF( m_account_public_address.m_spend_public_key != m_account.get_keys().m_account_address.m_spend_public_key || m_account_public_address.m_view_public_key != m_account.get_keys().m_account_address.m_view_public_key, error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file); @@ -459,7 +459,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password) void wallet2::store() { bool r = tools::serialize_obj_to_file(*this, m_wallet_file); - CHECK_AND_THROW_WALLET_EX(!r, error::file_save_error, m_wallet_file); + THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_wallet_file); } //---------------------------------------------------------------------------------------------------- uint64_t wallet2::unlocked_balance() diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 74de1b6d9..221f3d25c 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -272,18 +272,19 @@ namespace tools uint64_t unlock_time, uint64_t fee, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction &tx) { using namespace cryptonote; + THROW_WALLET_EXCEPTION_IF(dsts.empty(), error::zero_destination); uint64_t needed_money = fee; BOOST_FOREACH(auto& dt, dsts) { - CHECK_AND_THROW_WALLET_EX(0 == dt.amount, error::zero_destination); + THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination); needed_money += dt.amount; - CHECK_AND_THROW_WALLET_EX(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee); + THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee); } std::list<transfer_container::iterator> selected_transfers; uint64_t found_money = select_transfers(needed_money, 0 == fake_outputs_count, dust_policy.dust_threshold, selected_transfers); - CHECK_AND_THROW_WALLET_EX(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee); + THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee); typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry; typedef cryptonote::tx_source_entry::output_entry tx_output_entry; @@ -295,17 +296,17 @@ namespace tools req.outs_count = fake_outputs_count + 1;// add one to make possible (if need) to skip real output key BOOST_FOREACH(transfer_container::iterator it, selected_transfers) { - CHECK_AND_THROW_WALLET_EX(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error, + THROW_WALLET_EXCEPTION_IF(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error, "m_internal_output_index = " + std::to_string(it->m_internal_output_index) + " is greater or equal to outputs count = " + std::to_string(it->m_tx.vout.size())); req.amounts.push_back(it->amount()); } bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getrandom_outs.bin", req, daemon_resp, m_http_client, 200000); - CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "getrandom_outs.bin"); - CHECK_AND_THROW_WALLET_EX(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin"); - CHECK_AND_THROW_WALLET_EX(daemon_resp.status != CORE_RPC_STATUS_OK, error::get_random_outs_error, daemon_resp.status); - CHECK_AND_THROW_WALLET_EX(daemon_resp.outs.size() != selected_transfers.size(), error::wallet_internal_error, + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getrandom_outs.bin"); + THROW_WALLET_EXCEPTION_IF(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin"); + THROW_WALLET_EXCEPTION_IF(daemon_resp.status != CORE_RPC_STATUS_OK, error::get_random_outs_error, daemon_resp.status); + THROW_WALLET_EXCEPTION_IF(daemon_resp.outs.size() != selected_transfers.size(), error::wallet_internal_error, "daemon returned wrong response for getrandom_outs.bin, wrong amounts count = " + std::to_string(daemon_resp.outs.size()) + ", expected " + std::to_string(selected_transfers.size())); @@ -317,7 +318,7 @@ namespace tools scanty_outs.push_back(amount_outs); } } - CHECK_AND_THROW_WALLET_EX(!scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count); + THROW_WALLET_EXCEPTION_IF(!scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count); } //prepare inputs @@ -373,7 +374,7 @@ namespace tools uint64_t dust = 0; std::vector<cryptonote::tx_destination_entry> splitted_dsts; destination_split_strategy(dsts, change_dts, dust_policy.dust_threshold, splitted_dsts, dust); - CHECK_AND_THROW_WALLET_EX(dust_policy.dust_threshold < dust, error::wallet_internal_error, "invalid dust value: dust = " + + THROW_WALLET_EXCEPTION_IF(dust_policy.dust_threshold < dust, error::wallet_internal_error, "invalid dust value: dust = " + std::to_string(dust) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold)); if (0 != dust && !dust_policy.add_to_fee) { @@ -381,8 +382,8 @@ namespace tools } bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, tx, unlock_time); - CHECK_AND_THROW_WALLET_EX(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time); - CHECK_AND_THROW_WALLET_EX(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit); + THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time); + THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit); std::string key_images; bool all_are_txin_to_key = std::all_of(tx.vin.begin(), tx.vin.end(), [&](const txin_v& s_e) -> bool @@ -391,15 +392,15 @@ namespace tools key_images += boost::to_string(in.k_image) + " "; return true; }); - CHECK_AND_THROW_WALLET_EX(!all_are_txin_to_key, error::unexpected_txin_type, tx); + THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx); COMMAND_RPC_SEND_RAW_TX::request req; req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx)); COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp; r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000); - CHECK_AND_THROW_WALLET_EX(!r, error::no_connection_to_daemon, "sendrawtransaction"); - CHECK_AND_THROW_WALLET_EX(daemon_send_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "sendrawtransaction"); - CHECK_AND_THROW_WALLET_EX(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, tx, daemon_send_resp.status); + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "sendrawtransaction"); + THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "sendrawtransaction"); + THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, tx, daemon_send_resp.status); add_unconfirmed_tx(tx, change_dts.amount); diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index b517d64f9..b2a863436 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -603,7 +603,7 @@ namespace tools #define STRINGIZE_DETAIL(x) #x #define STRINGIZE(x) STRINGIZE_DETAIL(x) -#define CHECK_AND_THROW_WALLET_EX(cond, err_type, ...) \ +#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \ if (cond) \ { \ LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \ |