From 230fca2d562bc498a07f41f4e2c687df474b7cd8 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 27 Jul 2016 21:37:58 +0100 Subject: [PATCH] wallet: use the prefered rct case only when enough rct outs exist --- src/wallet/wallet2.cpp | 26 +++++++++++++++++++++++++- src/wallet/wallet2.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d307124ec..6f4f32b80 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3303,7 +3303,9 @@ std::vector wallet2::create_transactions_2(std::vector prefered_inputs; - if (use_rct) + uint64_t rct_outs_needed = 2 * (fake_outs_count + 1); + rct_outs_needed += 100; // some fudge factor since we don't know how many are locked + if (use_rct && get_num_rct_outputs() >= rct_outs_needed) { // this is used to build a tx that's 1 or 2 inputs, and 2 outputs, which // will get us a known fee. @@ -3878,6 +3880,28 @@ std::vector wallet2::select_available_outputs_from_histogram(uint64_t co }); } //---------------------------------------------------------------------------------------------------- +uint64_t wallet2::get_num_rct_outputs() +{ + epee::json_rpc::request req_t = AUTO_VAL_INIT(req_t); + epee::json_rpc::response resp_t = AUTO_VAL_INIT(resp_t); + m_daemon_rpc_mutex.lock(); + req_t.jsonrpc = "2.0"; + req_t.id = epee::serialization::storage_entry(0); + req_t.method = "get_output_histogram"; + req_t.params.amounts.push_back(0); + req_t.params.min_count = 0; + req_t.params.max_count = 0; + bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client); + m_daemon_rpc_mutex.unlock(); + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "get_num_rct_outputs"); + THROW_WALLET_EXCEPTION_IF(resp_t.result.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "get_output_histogram"); + THROW_WALLET_EXCEPTION_IF(resp_t.result.status != CORE_RPC_STATUS_OK, error::get_histogram_error, resp_t.result.status); + THROW_WALLET_EXCEPTION_IF(resp_t.result.histogram.size() != 1, error::get_histogram_error, "Expected exactly one response"); + THROW_WALLET_EXCEPTION_IF(resp_t.result.histogram[0].amount != 0, error::get_histogram_error, "Expected 0 amount"); + + return resp_t.result.histogram[0].instances; +} +//---------------------------------------------------------------------------------------------------- std::vector wallet2::select_available_unmixable_outputs(bool trusted_daemon) { // request all outputs with less than 3 instances diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ef4cec6eb..e3df68bb8 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -391,6 +391,8 @@ namespace tools bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const; + uint64_t get_num_rct_outputs(); + void get_hard_fork_info(uint8_t version, uint64_t &earliest_height); bool use_fork_rules(uint8_t version, uint64_t early_blocks = 0);