aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/epee/include/storages/portable_storage_template_helper.h4
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp6
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h9
-rw-r--r--src/blockchain_db/blockchain_db.h9
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp57
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h10
-rw-r--r--src/connectivity_tool/CMakeLists.txt46
-rw-r--r--src/connectivity_tool/conn_tool.cpp377
-rw-r--r--src/cryptonote_core/blockchain.cpp20
-rw-r--r--src/cryptonote_core/blockchain.h12
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.cpp15
-rw-r--r--src/daemon/command_parser_executor.cpp18
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp5
-rw-r--r--src/daemon/rpc_command_executor.cpp36
-rw-r--r--src/daemon/rpc_command_executor.h2
-rw-r--r--src/rpc/core_rpc_server.cpp32
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h41
-rw-r--r--src/simplewallet/simplewallet.cpp221
-rw-r--r--src/simplewallet/simplewallet.h4
-rw-r--r--src/wallet/wallet2.cpp147
-rw-r--r--src/wallet/wallet2.h19
-rw-r--r--src/wallet/wallet_errors.h9
-rw-r--r--src/wallet/wallet_rpc_server.cpp2
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h2
-rw-r--r--tests/unit_tests/hardfork.cpp1
-rw-r--r--utils/munin_plugins/alt_blocks_count2
-rw-r--r--utils/munin_plugins/difficulty2
-rw-r--r--utils/munin_plugins/grey_peerlist_size2
-rw-r--r--utils/munin_plugins/height2
-rw-r--r--utils/munin_plugins/incoming_connections_count2
-rw-r--r--utils/munin_plugins/outgoing_connections_count2
-rw-r--r--utils/munin_plugins/tx_count2
-rw-r--r--utils/munin_plugins/tx_pool_size2
-rw-r--r--utils/munin_plugins/white_peerlist_size2
37 files changed, 615 insertions, 512 deletions
diff --git a/contrib/epee/include/storages/portable_storage_template_helper.h b/contrib/epee/include/storages/portable_storage_template_helper.h
index 88515b5c3..bbd8413fc 100644
--- a/contrib/epee/include/storages/portable_storage_template_helper.h
+++ b/contrib/epee/include/storages/portable_storage_template_helper.h
@@ -72,7 +72,7 @@ namespace epee
{
std::string json_buff;
store_t_to_json(str_in, json_buff, indent, insert_newlines);
- return std::move(json_buff);
+ return json_buff;
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
@@ -117,7 +117,7 @@ namespace epee
{
std::string binary_buff;
store_t_to_binary(str_in, binary_buff, indent);
- return std::move(binary_buff);
+ return binary_buff;
}
}
}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0ac4a0aa1..e2349744d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -87,7 +87,6 @@ add_subdirectory(wallet)
add_subdirectory(p2p)
add_subdirectory(cryptonote_protocol)
-add_subdirectory(connectivity_tool)
add_subdirectory(miner)
add_subdirectory(simplewallet)
add_subdirectory(daemonizer)
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 1fef9e619..a7fa556bd 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -2180,6 +2180,12 @@ void BlockchainBDB::get_output_tx_and_index(const uint64_t& amount, const std::v
LOG_PRINT_L3("db3: " << db3);
}
+std::map<uint64_t, uint64_t>::BlockchainBDB::get_output_histogram(const std::vector<uint64_t> &amounts) const
+{
+ LOG_PRINT_L3("BlockchainBDB::" << __func__);
+ throw1(DB_ERROR("Not implemented."));
+}
+
void BlockchainBDB::set_hard_fork_starting_height(uint8_t version, uint64_t height)
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index d7cbd24e7..5c6bda4eb 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -341,6 +341,15 @@ public:
virtual bool can_thread_bulk_indices() const { return false; }
#endif
+ /**
+ * @brief return a histogram of outputs on the blockchain
+ *
+ * @param amounts optional set of amounts to lookup
+ *
+ * @return a set of amount/instances
+ */
+ std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const;
+
private:
virtual void add_block( const block& blk
, const size_t& block_size
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 3e0ca141e..3585bd061 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -1289,6 +1289,15 @@ public:
virtual void drop_hard_fork_info() = 0;
/**
+ * @brief return a histogram of outputs on the blockchain
+ *
+ * @param amounts optional set of amounts to lookup
+ *
+ * @return a set of amount/instances
+ */
+ virtual std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const = 0;
+
+ /**
* @brief is BlockchainDB in read-only mode?
*
* @return true if in read-only mode, otherwise false
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index e928ab803..9b99520a1 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -2692,6 +2692,63 @@ void BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const std::
LOG_PRINT_L3("db3: " << db3);
}
+std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vector<uint64_t> &amounts) const
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ check_open();
+
+ TXN_PREFIX_RDONLY();
+ RCURSOR(output_amounts);
+
+ std::map<uint64_t, uint64_t> histogram;
+ MDB_val k;
+ MDB_val v;
+
+ if (amounts.empty())
+ {
+ MDB_cursor_op op = MDB_FIRST;
+ while (1)
+ {
+ int ret = mdb_cursor_get(m_cur_output_amounts, &k, &v, op);
+ op = MDB_NEXT_NODUP;
+ if (ret == MDB_NOTFOUND)
+ break;
+ if (ret)
+ throw0(DB_ERROR(lmdb_error("Failed to enumerate outputs: ", ret).c_str()));
+ mdb_size_t num_elems = 0;
+ mdb_cursor_count(m_cur_output_amounts, &num_elems);
+ uint64_t amount = *(const uint64_t*)k.mv_data;
+ histogram[amount] = num_elems;
+ }
+ }
+ else
+ {
+ for (const auto &amount: amounts)
+ {
+ MDB_val_copy<uint64_t> k(amount);
+ int ret = mdb_cursor_get(m_cur_output_amounts, &k, &v, MDB_SET);
+ if (ret == MDB_NOTFOUND)
+ {
+ histogram[amount] = 0;
+ }
+ else if (ret == MDB_SUCCESS)
+ {
+ mdb_size_t num_elems = 0;
+ mdb_cursor_count(m_cur_output_amounts, &num_elems);
+ histogram[amount] = num_elems;
+ }
+ else
+ {
+ throw0(DB_ERROR(lmdb_error("Failed to enumerate outputs: ", ret).c_str()));
+ }
+ }
+ }
+
+ TXN_POSTFIX_RDONLY();
+
+ return histogram;
+}
+
void BlockchainLMDB::check_hard_fork_info()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index a3f32ffaa..6cd3e0e8f 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -280,6 +280,16 @@ public:
virtual void pop_block(block& blk, std::vector<transaction>& txs);
virtual bool can_thread_bulk_indices() const { return true; }
+
+ /**
+ * @brief return a histogram of outputs on the blockchain
+ *
+ * @param amounts optional set of amounts to lookup
+ *
+ * @return a set of amount/instances
+ */
+ std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const;
+
private:
void do_resize(uint64_t size_increase=0);
diff --git a/src/connectivity_tool/CMakeLists.txt b/src/connectivity_tool/CMakeLists.txt
deleted file mode 100644
index 0ade952d2..000000000
--- a/src/connectivity_tool/CMakeLists.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (c) 2014-2016, 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.
-
-set(connectivity_tool_sources
- conn_tool.cpp)
-
-set(connectivity_tool_private_headers)
-
-bitmonero_add_executable(connectivity_tool
- ${connectivity_tool_sources}
- ${connectivity_tool_private_headers})
-target_link_libraries(connectivity_tool
- LINK_PRIVATE
- cryptonote_core
- crypto
- common
- ${CMAKE_THREAD_LIBS_INIT}
- ${Boost_PROGRAM_OPTIONS_LIBRARY}
- ${Boost_REGEX_LIBRARY}
- ${Boost_CHRONO_LIBRARY}
- ${Boost_SYSTEM_LIBRARY})
diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp
deleted file mode 100644
index 458d30cc3..000000000
--- a/src/connectivity_tool/conn_tool.cpp
+++ /dev/null
@@ -1,377 +0,0 @@
-// Copyright (c) 2014-2016, 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
-
-#include "include_base_utils.h"
-#include "version.h"
-
-using namespace epee;
-#include <boost/program_options.hpp>
-#include "p2p/p2p_protocol_defs.h"
-#include "common/command_line.h"
-#include "cryptonote_core/cryptonote_core.h"
-#include "cryptonote_protocol/cryptonote_protocol_handler.h"
-#include "net/levin_client.h"
-#include "storages/levin_abstract_invoke2.h"
-#include "cryptonote_core/cryptonote_core.h"
-#include "storages/portable_storage_template_helper.h"
-#include "crypto/crypto.h"
-#include "storages/http_abstract_invoke.h"
-#include "net/http_client.h"
-
-namespace po = boost::program_options;
-using namespace cryptonote;
-using namespace nodetool;
-
-namespace
-{
- const command_line::arg_descriptor<std::string, true> arg_ip = {"ip", "set ip"};
- const command_line::arg_descriptor<size_t> arg_port = {"port", "set port"};
- const command_line::arg_descriptor<size_t> arg_rpc_port = {"rpc_port", "set rpc port"};
- const command_line::arg_descriptor<uint32_t, true> arg_timeout = {"timeout", "set timeout"};
- const command_line::arg_descriptor<std::string> arg_priv_key = {"private_key", "private key to subscribe debug command", "", true};
- const command_line::arg_descriptor<uint64_t> arg_peer_id = {"peer_id", "peer_id if known(if not - will be requested)", 0};
- const command_line::arg_descriptor<bool> arg_generate_keys = {"generate_keys_pair", "generate private and public keys pair"};
- const command_line::arg_descriptor<bool> arg_request_stat_info = {"request_stat_info", "request statistics information"};
- const command_line::arg_descriptor<bool> arg_request_net_state = {"request_net_state", "request network state information (peer list, connections count)"};
- const command_line::arg_descriptor<bool> arg_get_daemon_info = {"rpc_get_daemon_info", "request daemon state info vie rpc (--rpc_port option should be set ).", "", true};
-}
-
-typedef COMMAND_REQUEST_STAT_INFO_T<t_cryptonote_protocol_handler<core>::stat_info> COMMAND_REQUEST_STAT_INFO;
-
-struct response_schema
-{
- std::string status;
- std::string COMMAND_REQUEST_STAT_INFO_status;
- std::string COMMAND_REQUEST_NETWORK_STATE_status;
- enableable<COMMAND_REQUEST_STAT_INFO::response> si_rsp;
- enableable<COMMAND_REQUEST_NETWORK_STATE::response> ns_rsp;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(status)
- KV_SERIALIZE(COMMAND_REQUEST_STAT_INFO_status)
- KV_SERIALIZE(COMMAND_REQUEST_NETWORK_STATE_status)
- KV_SERIALIZE(si_rsp)
- KV_SERIALIZE(ns_rsp)
- END_KV_SERIALIZE_MAP()
-};
-
- std::string get_response_schema_as_json(response_schema& rs)
- {
- std::stringstream ss;
- ss << "{" << ENDL
- << " \"status\": \"" << rs.status << "\"," << ENDL
- << " \"COMMAND_REQUEST_NETWORK_STATE_status\": \"" << rs.COMMAND_REQUEST_NETWORK_STATE_status << "\"," << ENDL
- << " \"COMMAND_REQUEST_STAT_INFO_status\": \"" << rs.COMMAND_REQUEST_STAT_INFO_status << "\"";
- if(rs.si_rsp.enabled)
- {
- ss << "," << ENDL << " \"si_rsp\": " << epee::serialization::store_t_to_json(rs.si_rsp.v, 1);
- }
- if(rs.ns_rsp.enabled)
- {
- ss << "," << ENDL << " \"ns_rsp\": {" << ENDL
- << " \"local_time\": " << rs.ns_rsp.v.local_time << "," << ENDL
- << " \"my_id\": \"" << rs.ns_rsp.v.my_id << "\"," << ENDL
- << " \"connections_list\": [" << ENDL;
-
- size_t i = 0;
- BOOST_FOREACH(const connection_entry& ce, rs.ns_rsp.v.connections_list)
- {
- ss << " {\"peer_id\": \"" << ce.id << "\", \"ip\": \"" << string_tools::get_ip_string_from_int32(ce.adr.ip) << "\", \"port\": " << ce.adr.port << ", \"is_income\": "<< ce.is_income << "}";
- if(rs.ns_rsp.v.connections_list.size()-1 != i)
- ss << ",";
- ss << ENDL;
- i++;
- }
- ss << " ]," << ENDL;
- ss << " \"local_peerlist_white\": [" << ENDL;
- i = 0;
- BOOST_FOREACH(const peerlist_entry& pe, rs.ns_rsp.v.local_peerlist_white)
- {
- ss << " {\"peer_id\": \"" << pe.id << "\", \"ip\": \"" << string_tools::get_ip_string_from_int32(pe.adr.ip) << "\", \"port\": " << pe.adr.port << ", \"last_seen\": "<< rs.ns_rsp.v.local_time - pe.last_seen << "}";
- if(rs.ns_rsp.v.local_peerlist_white.size()-1 != i)
- ss << ",";
- ss << ENDL;
- i++;
- }
- ss << " ]," << ENDL;
-
- ss << " \"local_peerlist_gray\": [" << ENDL;
- i = 0;
- BOOST_FOREACH(const peerlist_entry& pe, rs.ns_rsp.v.local_peerlist_gray)
- {
- ss << " {\"peer_id\": \"" << pe.id << "\", \"ip\": \"" << string_tools::get_ip_string_from_int32(pe.adr.ip) << "\", \"port\": " << pe.adr.port << ", \"last_seen\": "<< rs.ns_rsp.v.local_time - pe.last_seen << "}";
- if(rs.ns_rsp.v.local_peerlist_gray.size()-1 != i)
- ss << ",";
- ss << ENDL;
- i++;
- }
- ss << " ]" << ENDL << " }" << ENDL;
- }
- ss << "}";
- return std::move(ss.str());
- }
-//---------------------------------------------------------------------------------------------------------------
-bool print_COMMAND_REQUEST_STAT_INFO(const COMMAND_REQUEST_STAT_INFO::response& si)
-{
- std::cout << " ------ COMMAND_REQUEST_STAT_INFO ------ " << ENDL;
- std::cout << "Version: " << si.version << ENDL;
- std::cout << "OS Version: " << si.os_version << ENDL;
- std::cout << "Connections: " << si.connections_count << ENDL;
- std::cout << "INC Connections: " << si.incoming_connections_count << ENDL;
-
-
- std::cout << "Tx pool size: " << si.payload_info.tx_pool_size << ENDL;
- std::cout << "BC height: " << si.payload_info.blockchain_height << ENDL;
- std::cout << "Mining speed: " << si.payload_info.mining_speed << ENDL;
- std::cout << "Alternative blocks: " << si.payload_info.alternative_blocks << ENDL;
- std::cout << "Top block id: " << si.payload_info.top_block_id_str << ENDL;
- return true;
-}
-//---------------------------------------------------------------------------------------------------------------
-bool print_COMMAND_REQUEST_NETWORK_STATE(const COMMAND_REQUEST_NETWORK_STATE::response& ns)
-{
- std::cout << " ------ COMMAND_REQUEST_NETWORK_STATE ------ " << ENDL;
- std::cout << "Peer id: " << ns.my_id << ENDL;
- std::cout << "Active connections:" << ENDL;
- BOOST_FOREACH(const connection_entry& ce, ns.connections_list)
- {
- std::cout << ce.id << "\t" << string_tools::get_ip_string_from_int32(ce.adr.ip) << ":" << ce.adr.port << (ce.is_income ? "(INC)":"(OUT)") << ENDL;
- }
-
- std::cout << "Peer list white:" << ns.my_id << ENDL;
- BOOST_FOREACH(const peerlist_entry& pe, ns.local_peerlist_white)
- {
- std::cout << pe.id << "\t" << string_tools::get_ip_string_from_int32(pe.adr.ip) << ":" << pe.adr.port << "\t" << misc_utils::get_time_interval_string(ns.local_time - pe.last_seen) << ENDL;
- }
-
- std::cout << "Peer list gray:" << ns.my_id << ENDL;
- BOOST_FOREACH(const peerlist_entry& pe, ns.local_peerlist_gray)
- {
- std::cout << pe.id << "\t" << string_tools::get_ip_string_from_int32(pe.adr.ip) << ":" << pe.adr.port << "\t" << misc_utils::get_time_interval_string(ns.local_time - pe.last_seen) << ENDL;
- }
-
-
- return true;
-}
-//---------------------------------------------------------------------------------------------------------------
-bool handle_get_daemon_info(po::variables_map& vm)
-{
- if(!command_line::has_arg(vm, arg_rpc_port))
- {
- std::cout << "ERROR: rpc port not set" << ENDL;
- return false;
- }
-
- epee::net_utils::http::http_simple_client http_client;
-
- cryptonote::COMMAND_RPC_GET_INFO::request req = AUTO_VAL_INIT(req);
- cryptonote::COMMAND_RPC_GET_INFO::response res = AUTO_VAL_INIT(res);
- std::string daemon_addr = command_line::get_arg(vm, arg_ip) + ":" + std::to_string(command_line::get_arg(vm, arg_rpc_port));
- bool r = net_utils::invoke_http_json_remote_command2(daemon_addr + "/getinfo", req, res, http_client, command_line::get_arg(vm, arg_timeout));
- if(!r)
- {
- std::cout << "ERROR: failed to invoke request" << ENDL;
- return false;
- }
- std::cout << "OK" << ENDL
- << "height: " << res.height << ENDL
- << "difficulty: " << res.difficulty << ENDL
- << "tx_count: " << res.tx_count << ENDL
- << "tx_pool_size: " << res.tx_pool_size << ENDL
- << "alt_blocks_count: " << res.alt_blocks_count << ENDL
- << "outgoing_connections_count: " << res.outgoing_connections_count << ENDL
- << "incoming_connections_count: " << res.incoming_connections_count << ENDL
- << "white_peerlist_size: " << res.white_peerlist_size << ENDL
- << "grey_peerlist_size: " << res.grey_peerlist_size << ENDL;
-
- return true;
-}
-//---------------------------------------------------------------------------------------------------------------
-bool handle_request_stat(po::variables_map& vm, peerid_type peer_id)
-{
-
- if(!command_line::has_arg(vm, arg_priv_key))
- {
- std::cout << "{" << ENDL << " \"status\": \"ERROR: " << "secret key not set \"" << ENDL << "}";
- return false;
- }
- crypto::secret_key prvk = AUTO_VAL_INIT(prvk);
- if(!string_tools::hex_to_pod(command_line::get_arg(vm, arg_priv_key) , prvk))
- {
- std::cout << "{" << ENDL << " \"status\": \"ERROR: " << "wrong secret key set \"" << ENDL << "}";
- return false;
- }
-
-
- response_schema rs = AUTO_VAL_INIT(rs);
-
- levin::levin_client_impl2 transport;
- if(!transport.connect(command_line::get_arg(vm, arg_ip), static_cast<int>(command_line::get_arg(vm, arg_port)), static_cast<int>(command_line::get_arg(vm, arg_timeout))))
- {
- std::cout << "{" << ENDL << " \"status\": \"ERROR: " << "Failed to connect to " << command_line::get_arg(vm, arg_ip) << ":" << command_line::get_arg(vm, arg_port) << "\"" << ENDL << "}";
- return false;
- }else
- rs.status = "OK";
-
- if(!peer_id)
- {
- COMMAND_REQUEST_PEER_ID::request req = AUTO_VAL_INIT(req);
- COMMAND_REQUEST_PEER_ID::response rsp = AUTO_VAL_INIT(rsp);
- if(!net_utils::invoke_remote_command2(COMMAND_REQUEST_PEER_ID::ID, req, rsp, transport))
- {
- std::cout << "{" << ENDL << " \"status\": \"ERROR: " << "Failed to connect to " << command_line::get_arg(vm, arg_ip) << ":" << command_line::get_arg(vm, arg_port) << "\"" << ENDL << "}";
- return false;
- }else
- {
- peer_id = rsp.my_id;
- }
- }
-
-
- nodetool::proof_of_trust pot = AUTO_VAL_INIT(pot);
- pot.peer_id = peer_id;
- pot.time = time(NULL);
- crypto::public_key pubk = AUTO_VAL_INIT(pubk);
- string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pubk);
- crypto::hash h = tools::get_proof_of_trust_hash(pot);
- crypto::generate_signature(h, pubk, prvk, pot.sign);
-
- if(command_line::get_arg(vm, arg_request_stat_info))
- {
- COMMAND_REQUEST_STAT_INFO::request req = AUTO_VAL_INIT(req);
- req.tr = pot;
- if(!net_utils::invoke_remote_command2(COMMAND_REQUEST_STAT_INFO::ID, req, rs.si_rsp.v, transport))
- {
- std::stringstream ss;
- ss << "ERROR: " << "Failed to invoke remote command COMMAND_REQUEST_STAT_INFO to " << command_line::get_arg(vm, arg_ip) << ":" << command_line::get_arg(vm, arg_port);
- rs.COMMAND_REQUEST_STAT_INFO_status = ss.str();
- }else
- {
- rs.si_rsp.enabled = true;
- rs.COMMAND_REQUEST_STAT_INFO_status = "OK";
- }
- }
-
-
- if(command_line::get_arg(vm, arg_request_net_state))
- {
- ++pot.time;
- h = tools::get_proof_of_trust_hash(pot);
- crypto::generate_signature(h, pubk, prvk, pot.sign);
- COMMAND_REQUEST_NETWORK_STATE::request req = AUTO_VAL_INIT(req);
- req.tr = pot;
- if(!net_utils::invoke_remote_command2(COMMAND_REQUEST_NETWORK_STATE::ID, req, rs.ns_rsp.v, transport))
- {
- std::stringstream ss;
- ss << "ERROR: " << "Failed to invoke remote command COMMAND_REQUEST_NETWORK_STATE to " << command_line::get_arg(vm, arg_ip) << ":" << command_line::get_arg(vm, arg_port);
- rs.COMMAND_REQUEST_NETWORK_STATE_status = ss.str();
- }else
- {
- rs.ns_rsp.enabled = true;
- rs.COMMAND_REQUEST_NETWORK_STATE_status = "OK";
- }
- }
- std::cout << get_response_schema_as_json(rs);
- return true;
-}
-//---------------------------------------------------------------------------------------------------------------
-bool generate_and_print_keys()
-{
- crypto::public_key pk = AUTO_VAL_INIT(pk);
- crypto::secret_key sk = AUTO_VAL_INIT(sk);
- generate_keys(pk, sk);
- std::cout << "PUBLIC KEY: " << epee::string_tools::pod_to_hex(pk) << ENDL
- << "PRIVATE KEY: " << epee::string_tools::pod_to_hex(sk);
- return true;
-}
-int main(int argc, char* argv[])
-{
- string_tools::set_module_name_and_folder(argv[0]);
- log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
-
- // Declare the supported options.
- po::options_description desc_general("General options");
- command_line::add_arg(desc_general, command_line::arg_help);
-
- po::options_description desc_params("Connectivity options");
- command_line::add_arg(desc_params, arg_ip);
- command_line::add_arg(desc_params, arg_port);
- command_line::add_arg(desc_params, arg_rpc_port);
- command_line::add_arg(desc_params, arg_timeout);
- command_line::add_arg(desc_params, arg_request_stat_info);
- command_line::add_arg(desc_params, arg_request_net_state);
- command_line::add_arg(desc_params, arg_generate_keys);
- command_line::add_arg(desc_params, arg_peer_id);
- command_line::add_arg(desc_params, arg_priv_key);
- command_line::add_arg(desc_params, arg_get_daemon_info);
-
-
- po::options_description desc_all;
- desc_all.add(desc_general).add(desc_params);
-
- po::variables_map vm;
- bool r = command_line::handle_error_helper(desc_all, [&]()
- {
- po::store(command_line::parse_command_line(argc, argv, desc_general, true), vm);
- if (command_line::get_arg(vm, command_line::arg_help))
- {
- std::cout << desc_all << ENDL;
- return false;
- }
-
- po::store(command_line::parse_command_line(argc, argv, desc_params, false), vm);
- po::notify(vm);
-
- return true;
- });
- if (!r)
- return 1;
-
- if(command_line::has_arg(vm, arg_request_stat_info) || command_line::has_arg(vm, arg_request_net_state))
- {
- return handle_request_stat(vm, command_line::get_arg(vm, arg_peer_id)) ? 0:1;
- }
- if(command_line::has_arg(vm, arg_get_daemon_info))
- {
- return handle_get_daemon_info(vm) ? 0:1;
- }
- else if(command_line::has_arg(vm, arg_generate_keys))
- {
- return generate_and_print_keys() ? 0:1;
- }
- else
- {
- std::cerr << "Not enough arguments." << ENDL;
- std::cerr << desc_all << ENDL;
- }
-
- return 1;
-}
-
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index dec7b8e29..da14d7575 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -948,7 +948,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
}
//------------------------------------------------------------------
// This function validates the miner transaction reward
-bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, bool &partial_block_reward)
+bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, bool &partial_block_reward, uint8_t version)
{
LOG_PRINT_L3("Blockchain::" << __func__);
//validate reward
@@ -957,6 +957,15 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
money_in_use += o.amount;
partial_block_reward = false;
+ if (version >= 3) {
+ for (auto &o: b.miner_tx.vout) {
+ if (!is_valid_decomposed_amount(o.amount)) {
+ LOG_PRINT_L1("miner tx output " << print_money(o.amount) << " is not a valid decomposed amount");
+ return false;
+ }
+ }
+ }
+
std::vector<size_t> last_blocks_sizes;
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward, get_current_hard_fork_version()))
@@ -984,9 +993,9 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
// to show the amount of coins that were actually generated, the remainder will be pushed back for later
// emission. This modifies the emission curve very slightly.
CHECK_AND_ASSERT_MES(money_in_use - fee <= base_reward, false, "base reward calculation bug");
- base_reward = money_in_use - fee;
if(base_reward + fee != money_in_use)
partial_block_reward = true;
+ base_reward = money_in_use - fee;
}
return true;
}
@@ -2698,7 +2707,7 @@ leave:
TIME_MEASURE_START(vmt);
uint64_t base_reward = 0;
uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
- if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins, bvc.m_partial_block_reward))
+ if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins, bvc.m_partial_block_reward, m_hardfork->get_current_version()))
{
LOG_PRINT_L1("Block with id: " << id << " has incorrect miner transaction");
bvc.m_verifivation_failed = true;
@@ -3313,6 +3322,11 @@ bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, ui
return m_hardfork->get_voting_info(version, window, votes, threshold, earliest_height, voting);
}
+std::map<uint64_t, uint64_t> Blockchain:: get_output_histogram(const std::vector<uint64_t> &amounts) const
+{
+ return m_db->get_output_histogram(amounts);
+}
+
void Blockchain::load_compiled_in_block_hashes()
{
if (m_fast_sync && get_blocks_dat_start(m_testnet) != nullptr)
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 94def1aa9..6bae0364d 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -683,6 +683,15 @@ namespace cryptonote
bool flush_txes_from_pool(const std::list<crypto::hash> &txids);
/**
+ * @brief return a histogram of outputs on the blockchain
+ *
+ * @param amounts optional set of amounts to lookup
+ *
+ * @return a set of amount/instances
+ */
+ std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const;
+
+ /**
* @brief perform a check on all key images in the blockchain
*
* @param std::function the check to perform, pass/fail
@@ -980,10 +989,11 @@ namespace cryptonote
* @param base_reward return-by-reference the new block's generated coins
* @param already_generated_coins the amount of currency generated prior to this block
* @param partial_block_reward return-by-reference true if miner accepted only partial reward
+ * @param version hard fork version for that transaction
*
* @return false if anything is found wrong with the miner transaction, otherwise true
*/
- 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 &partial_block_reward);
+ 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 &partial_block_reward, uint8_t version);
/**
* @brief reverts the blockchain to its previous state following a failed switch
diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp
index 253e568b5..3c1acd8a9 100644
--- a/src/cryptonote_core/cryptonote_format_utils.cpp
+++ b/src/cryptonote_core/cryptonote_format_utils.cpp
@@ -126,20 +126,19 @@ namespace cryptonote
return false;
}
- // from hard fork 2, we cut out the low significant digits. This makes the tx smaller, and
- // keeps the paid amount almost the same. The unpaid remainder gets pushed back to the
- // emission schedule
- if (hard_fork_version >= 2)
- {
- block_reward = block_reward - block_reward % ::config::BASE_REWARD_CLAMP_THRESHOLD;
- }
-
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
LOG_PRINT_L1("Creating block template: reward " << block_reward <<
", fee " << fee)
#endif
block_reward += fee;
+ // from hard fork 2, we cut out the low significant digits. This makes the tx smaller, and
+ // keeps the paid amount almost the same. The unpaid remainder gets pushed back to the
+ // emission schedule
+ if (hard_fork_version >= 2) {
+ block_reward = block_reward - block_reward % ::config::BASE_REWARD_CLAMP_THRESHOLD;
+ }
+
std::vector<uint64_t> out_amounts;
decompose_amount_into_digits(block_reward, hard_fork_version >= 2 ? 0 : ::config::DEFAULT_DUST_THRESHOLD,
[&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); },
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 0b42257e7..166fe04ca 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -439,5 +439,23 @@ bool t_command_parser_executor::flush_txpool(const std::vector<std::string>& arg
return m_executor.flush_txpool(txid);
}
+bool t_command_parser_executor::output_histogram(const std::vector<std::string>& args)
+{
+ if (args.size() > 2) return false;
+
+ uint64_t min_count = 3;
+ uint64_t max_count = 0;
+
+ if (args.size() >= 1)
+ {
+ min_count = boost::lexical_cast<uint64_t>(args[0]);
+ }
+ if (args.size() >= 2)
+ {
+ max_count = boost::lexical_cast<uint64_t>(args[1]);
+ }
+ return m_executor.output_histogram(min_count, max_count);
+}
+
} // namespace daemonize
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index 51c55a8c0..11df92a5e 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -114,6 +114,8 @@ public:
bool unban(const std::vector<std::string>& args);
bool flush_txpool(const std::vector<std::string>& args);
+
+ bool output_histogram(const std::vector<std::string>& args);
};
} // namespace daemonize
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 206de9d4a..aabc2f09a 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -214,6 +214,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::flush_txpool, &m_parser, p::_1)
, "Flush a transaction from the tx pool by its txid, or the whole tx pool"
);
+ m_command_lookup.set_handler(
+ "output_histogram"
+ , std::bind(&t_command_parser_executor::output_histogram, &m_parser, p::_1)
+ , "Print output histogram (amount, instances)"
+ );
}
bool t_command_server::process_command_str(const std::string& cmd)
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 15ddc081f..933c93ed7 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1203,5 +1203,41 @@ bool t_rpc_command_executor::flush_txpool(const std::string &txid)
return true;
}
+bool t_rpc_command_executor::output_histogram(uint64_t min_count, uint64_t max_count)
+{
+ cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request req;
+ cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response res;
+ std::string fail_message = "Unsuccessful";
+ epee::json_rpc::error error_resp;
+
+ req.min_count = min_count;
+ req.max_count = max_count;
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "get_output_histogram", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_output_histogram(req, res, error_resp))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ std::sort(res.histogram.begin(), res.histogram.end(),
+ [](const cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry &e1, const cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry &e2)->bool { return e1.instances < e2.instances; });
+ for (const auto &e: res.histogram)
+ {
+ tools::msg_writer() << e.instances << " " << cryptonote::print_money(e.amount);
+ }
+
+ return true;
+}
+
}// namespace daemonize
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index bc3f2d5c5..7e73e7faf 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -132,6 +132,8 @@ public:
bool unban(const std::string &ip);
bool flush_txpool(const std::string &txid);
+
+ bool output_histogram(uint64_t min_count, uint64_t max_count);
};
} // namespace daemonize
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 6b625e77b..5350b6fe0 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1041,6 +1041,38 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request& req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res, epee::json_rpc::error& error_resp)
+ {
+ if(!check_core_busy())
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
+ error_resp.message = "Core is busy.";
+ return false;
+ }
+
+ std::map<uint64_t, uint64_t> histogram;
+ try
+ {
+ histogram = m_core.get_blockchain_storage().get_output_histogram(req.amounts);
+ }
+ catch (const std::exception &e)
+ {
+ res.status = "Failed to get output histogram";
+ return true;
+ }
+
+ res.histogram.clear();
+ res.histogram.reserve(histogram.size());
+ for (const auto &i: histogram)
+ {
+ if (i.second >= req.min_count && (i.second <= req.max_count || req.max_count == 0))
+ res.histogram.push_back(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry(i.first, i.second));
+ }
+
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_fast_exit(const COMMAND_RPC_FAST_EXIT::request& req, COMMAND_RPC_FAST_EXIT::response& res)
{
cryptonote::core::set_fast_exit();
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index f79087030..5c3707209 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -109,6 +109,7 @@ namespace cryptonote
MAP_JON_RPC_WE("setbans", on_set_bans, COMMAND_RPC_SETBANS)
MAP_JON_RPC_WE("getbans", on_get_bans, COMMAND_RPC_GETBANS)
MAP_JON_RPC_WE("flush_txpool", on_flush_txpool, COMMAND_RPC_FLUSH_TRANSACTION_POOL)
+ MAP_JON_RPC_WE("get_output_histogram", on_get_output_histogram, COMMAND_RPC_GET_OUTPUT_HISTOGRAM)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -149,6 +150,7 @@ namespace cryptonote
bool on_set_bans(const COMMAND_RPC_SETBANS::request& req, COMMAND_RPC_SETBANS::response& res, epee::json_rpc::error& error_resp);
bool on_get_bans(const COMMAND_RPC_GETBANS::request& req, COMMAND_RPC_GETBANS::response& res, epee::json_rpc::error& error_resp);
bool on_flush_txpool(const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request& req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response& res, epee::json_rpc::error& error_resp);
+ bool on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request& req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res, epee::json_rpc::error& error_resp);
//-----------------------
private:
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 72e399ec4..6d4dd1252 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -986,5 +986,46 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
};
+
+ struct COMMAND_RPC_GET_OUTPUT_HISTOGRAM
+ {
+ struct request
+ {
+ std::vector<uint64_t> amounts;
+ uint64_t min_count;
+ uint64_t max_count;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(amounts);
+ KV_SERIALIZE(min_count);
+ KV_SERIALIZE(max_count);
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct entry
+ {
+ uint64_t amount;
+ uint64_t instances;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(amount);
+ KV_SERIALIZE(instances);
+ END_KV_SERIALIZE_MAP()
+
+ entry(uint64_t amount, uint64_t instances): amount(amount), instances(instances) {}
+ entry() {}
+ };
+
+ struct response
+ {
+ std::string status;
+ std::vector<entry> histogram;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ KV_SERIALIZE(histogram)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
}
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index ea1993c80..04170df62 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -57,6 +57,7 @@
#include "version.h"
#include "crypto/crypto.h" // for crypto::secret_key definition
#include "mnemonics/electrum-words.h"
+#include "rapidjson/document.h"
#include <stdexcept>
#if defined(WIN32)
@@ -81,6 +82,7 @@ namespace
const command_line::arg_descriptor<std::string> arg_generate_new_wallet = {"generate-new-wallet", sw::tr("Generate new wallet and save it to <arg> or <address>.wallet by default"), ""};
const command_line::arg_descriptor<std::string> arg_generate_from_view_key = {"generate-from-view-key", sw::tr("Generate incoming-only wallet from view key"), ""};
const command_line::arg_descriptor<std::string> arg_generate_from_keys = {"generate-from-keys", sw::tr("Generate wallet from private keys"), ""};
+ const command_line::arg_descriptor<std::string> arg_generate_from_json = {"generate-from-json", sw::tr("Generate wallet from JSON format file"), ""};
const command_line::arg_descriptor<std::string> arg_daemon_address = {"daemon-address", sw::tr("Use daemon instance at <host>:<port>"), ""};
const command_line::arg_descriptor<std::string> arg_daemon_host = {"daemon-host", sw::tr("Use daemon instance at host <arg> instead of localhost"), ""};
const command_line::arg_descriptor<std::string> arg_password = {"password", sw::tr("Wallet password"), "", true};
@@ -539,7 +541,7 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this, _1), tr("Show blockchain height"));
m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this, _1), tr("transfer [<mixin_count>] <addr_1> <amount_1> [<addr_2> <amount_2> ... <addr_N> <amount_N>] [payment_id] - Transfer <amount_1>,... <amount_N> to <address_1>,... <address_N>, respectively. <mixin_count> is the number of extra inputs to include for untraceability (from 0 to maximum available)"));
m_cmd_binder.set_handler("transfer_new", boost::bind(&simple_wallet::transfer_new, this, _1), tr("Same as transfer, but using a new transaction building algorithm"));
- m_cmd_binder.set_handler("sweep_dust", boost::bind(&simple_wallet::sweep_dust, this, _1), tr("Send all dust outputs to yourself with mixin 0"));
+ m_cmd_binder.set_handler("sweep_unmixable", boost::bind(&simple_wallet::sweep_unmixable, this, _1), tr("Send all unmixable outputs to yourself with mixin 0"));
m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), tr("set_log <level> - Change current log detail level, <0-4>"));
m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), tr("Show current wallet public address"));
m_cmd_binder.set_handler("integrated_address", boost::bind(&simple_wallet::print_integrated_address, this, _1), tr("integrated_address [PID] - Encode a payment ID into an integrated address for the current wallet public address (no argument uses a random payment ID), or decode an integrated address to standard address and payment ID"));
@@ -716,7 +718,7 @@ bool simple_wallet::ask_wallet_create_if_needed()
// add logic to error out if new wallet requested but named wallet file exists
if (keys_file_exists || wallet_file_exists)
{
- if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty())
+ if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty() || !m_generate_from_json.empty())
{
fail_msg_writer() << tr("attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting.");
return false;
@@ -763,6 +765,13 @@ void simple_wallet::print_seed(std::string seed)
//----------------------------------------------------------------------------------------------------
static bool get_password(const boost::program_options::variables_map& vm, bool allow_entry, tools::password_container &pwd_container)
{
+ // has_arg returns true even when the parameter is not passed ??
+ const std::string gfj = command_line::get_arg(vm, arg_generate_from_json);
+ if (!gfj.empty()) {
+ // will be in the json file, if any
+ return true;
+ }
+
if (has_arg(vm, arg_password) && has_arg(vm, arg_password_file))
{
fail_msg_writer() << tr("can't specify more than one of --password and --password-file");
@@ -809,6 +818,153 @@ static bool get_password(const boost::program_options::variables_map& vm, bool a
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::generate_from_json(const boost::program_options::variables_map& vm, std::string &wallet_file, std::string &password)
+{
+ std::string buf;
+ bool r = epee::file_io_utils::load_file_to_string(m_generate_from_json, buf);
+ if (!r) {
+ fail_msg_writer() << tr("Failed to load file ") << m_generate_from_json;
+ return false;
+ }
+
+ rapidjson::Document json;
+ if (json.Parse(buf.c_str()).HasParseError()) {
+ fail_msg_writer() << tr("Failed to parse JSON");
+ return false;
+ }
+
+ if (!json.HasMember("version")) {
+ fail_msg_writer() << tr("Version not found in JSON");
+ return false;
+ }
+ unsigned int version = json["version"].GetUint();
+ const int current_version = 1;
+ if (version > current_version) {
+ fail_msg_writer() << boost::format(tr("Version %u too new, we can only grok up to %u")) % version % current_version;
+ return false;
+ }
+ if (!json.HasMember("filename")) {
+ fail_msg_writer() << tr("Filename not found in JSON");
+ return false;
+ }
+ std::string filename = json["filename"].GetString();
+
+ bool recover = false;
+ uint64_t scan_from_height = 0;
+ if (json.HasMember("scan_from_height")) {
+ scan_from_height = json["scan_from_height"].GetUint64();
+ recover = true;
+ }
+
+ password = "";
+ if (json.HasMember("password")) {
+ password = json["password"].GetString();
+ }
+
+ std::string viewkey_string("");
+ crypto::secret_key viewkey;
+ if (json.HasMember("viewkey")) {
+ viewkey_string = json["viewkey"].GetString();
+ cryptonote::blobdata viewkey_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(viewkey_string, viewkey_data))
+ {
+ fail_msg_writer() << tr("failed to parse view key secret key");
+ return false;
+ }
+ viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
+ }
+
+ std::string spendkey_string("");
+ crypto::secret_key spendkey;
+ if (json.HasMember("spendkey")) {
+ spendkey_string = json["spendkey"].GetString();
+ cryptonote::blobdata spendkey_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(spendkey_string, spendkey_data))
+ {
+ fail_msg_writer() << tr("failed to parse spend key secret key");
+ return false;
+ }
+ spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
+ }
+
+ std::string seed("");
+ std::string old_language;
+ if (json.HasMember("seed")) {
+ seed = json["seed"].GetString();
+ if (!crypto::ElectrumWords::words_to_bytes(seed, m_recovery_key, old_language))
+ {
+ fail_msg_writer() << tr("Electrum-style word list failed verification");
+ return false;
+ }
+ m_electrum_seed = seed;
+ m_restore_deterministic_wallet = true;
+ }
+
+ // compatibility checks
+ if (seed.empty() && viewkey_string.empty()) {
+ fail_msg_writer() << tr("At least one of Electrum-style word list and private view key must be specified");
+ return false;
+ }
+ if (!seed.empty() && (!viewkey_string.empty() || !spendkey_string.empty())) {
+ fail_msg_writer() << tr("Both Electrum-style word list and private key(s) specified");
+ return false;
+ }
+
+ m_wallet_file = filename;
+
+ bool was_deprecated_wallet = m_restore_deterministic_wallet && ((old_language == crypto::ElectrumWords::old_language_name) ||
+ crypto::ElectrumWords::get_is_old_style_seed(m_electrum_seed));
+ if (was_deprecated_wallet) {
+ fail_msg_writer() << tr("Cannot create deprecated wallets from JSON");
+ return false;
+ }
+
+ bool testnet = command_line::get_arg(vm, arg_testnet);
+ m_wallet.reset(new tools::wallet2(testnet));
+ m_wallet->callback(this);
+
+ try
+ {
+ if (!seed.empty())
+ {
+ m_wallet->generate(m_wallet_file, password, m_recovery_key, recover, false);
+ }
+ else
+ {
+ cryptonote::account_public_address address;
+ if (!crypto::secret_key_to_public_key(viewkey, address.m_view_public_key)) {
+ fail_msg_writer() << tr("failed to verify view key secret key");
+ return false;
+ }
+ if (!crypto::secret_key_to_public_key(spendkey, address.m_spend_public_key)) {
+ fail_msg_writer() << tr("failed to verify spend key secret key");
+ return false;
+ }
+
+ if (spendkey_string.empty())
+ {
+ m_wallet->generate(m_wallet_file, password, address, viewkey);
+ }
+ else
+ {
+ m_wallet->generate(m_wallet_file, password, address, spendkey, viewkey);
+ }
+ }
+ }
+ catch (const std::exception& e)
+ {
+ fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
+ return false;
+ }
+
+ m_wallet->set_refresh_from_block_height(scan_from_height);
+
+ wallet_file = m_wallet_file;
+
+ return r;
+}
+
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
if (!handle_command_line(vm))
@@ -820,12 +976,12 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false;
}
- if((!m_generate_new.empty()) + (!m_wallet_file.empty()) + (!m_generate_from_view_key.empty()) + (!m_generate_from_keys.empty()) > 1)
+ if((!m_generate_new.empty()) + (!m_wallet_file.empty()) + (!m_generate_from_view_key.empty()) + (!m_generate_from_keys.empty()) + (!m_generate_from_json.empty()) > 1)
{
- fail_msg_writer() << tr("can't specify more than one of --generate-new-wallet=\"wallet_name\", --wallet-file=\"wallet_name\", --generate-from-view-key=\"wallet_name\" and --generate-from-keys=\"wallet_name\"");
+ fail_msg_writer() << tr("can't specify more than one of --generate-new-wallet=\"wallet_name\", --wallet-file=\"wallet_name\", --generate-from-view-key=\"wallet_name\", --generate-from-json=\"jsonfilename\" and --generate-from-keys=\"wallet_name\"");
return false;
}
- else if (m_generate_new.empty() && m_wallet_file.empty() && m_generate_from_view_key.empty() && m_generate_from_keys.empty())
+ else if (m_generate_new.empty() && m_wallet_file.empty() && m_generate_from_view_key.empty() && m_generate_from_keys.empty() && m_generate_from_json.empty())
{
if(!ask_wallet_create_if_needed()) return false;
}
@@ -847,7 +1003,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
if (!get_password(vm, true, pwd_container))
return false;
- if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty())
+ if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty() || !m_generate_from_json.empty())
{
if (m_wallet_file.empty()) m_wallet_file = m_generate_new; // alias for simplicity later
@@ -993,6 +1149,12 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
bool r = new_wallet(m_wallet_file, pwd_container.password(), address, spendkey, viewkey, testnet);
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
}
+ else if (!m_generate_from_json.empty())
+ {
+ std::string wallet_file, password; // we don't need to remember them
+ if (!generate_from_json(vm, wallet_file, password))
+ return false;
+ }
else
{
bool r = new_wallet(m_wallet_file, pwd_container.password(), m_recovery_key, m_restore_deterministic_wallet,
@@ -1023,6 +1185,7 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_generate_new = command_line::get_arg(vm, arg_generate_new_wallet);
m_generate_from_view_key = command_line::get_arg(vm, arg_generate_from_view_key);
m_generate_from_keys = command_line::get_arg(vm, arg_generate_from_keys);
+ m_generate_from_json = command_line::get_arg(vm, arg_generate_from_json);
m_daemon_address = command_line::get_arg(vm, arg_daemon_address);
m_daemon_host = command_line::get_arg(vm, arg_daemon_host);
m_daemon_port = command_line::get_arg(vm, arg_daemon_port);
@@ -1559,8 +1722,7 @@ bool simple_wallet::refresh(const std::vector<std::string>& args)
bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
{
success_msg_writer() << tr("Balance: ") << print_money(m_wallet->balance()) << ", "
- << tr("unlocked balance: ") << print_money(m_wallet->unlocked_balance()) << ", "
- << tr("including unlocked dust: ") << print_money(m_wallet->unlocked_dust_balance(tools::tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD)));
+ << tr("unlocked balance: ") << print_money(m_wallet->unlocked_balance());
return true;
}
//----------------------------------------------------------------------------------------------------
@@ -2045,7 +2207,7 @@ bool simple_wallet::transfer_new(const std::vector<std::string> &args_)
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::sweep_dust(const std::vector<std::string> &args_)
+bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
{
if (!try_connect_to_daemon())
return true;
@@ -2058,28 +2220,37 @@ bool simple_wallet::sweep_dust(const std::vector<std::string> &args_)
try
{
- uint64_t total_dust = m_wallet->unlocked_dust_balance(tools::tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD));
-
// figure out what tx will be necessary
- auto ptx_vector = m_wallet->create_dust_sweep_transactions();
+ auto ptx_vector = m_wallet->create_unmixable_sweep_transactions(m_trusted_daemon);
+
+ if (ptx_vector.empty())
+ {
+ fail_msg_writer() << tr("No unmixable outputs found");
+ return true;
+ }
// give user total and fee, and prompt to confirm
- uint64_t total_fee = 0;
+ uint64_t total_fee = 0, total_unmixable = 0;
for (size_t n = 0; n < ptx_vector.size(); ++n)
{
total_fee += ptx_vector[n].fee;
+ for (const auto &vin: ptx_vector[n].tx.vin)
+ {
+ if (vin.type() == typeid(txin_to_key))
+ total_unmixable += boost::get<txin_to_key>(vin).amount;
+ }
}
- std::string prompt_str = tr("Sweeping ") + print_money(total_dust);
+ std::string prompt_str = tr("Sweeping ") + print_money(total_unmixable);
if (ptx_vector.size() > 1) {
prompt_str = (boost::format(tr("Sweeping %s in %llu transactions for a total fee of %s. Is this okay? (Y/Yes/N/No)")) %
- print_money(total_dust) %
+ print_money(total_unmixable) %
((unsigned long long)ptx_vector.size()) %
print_money(total_fee)).str();
}
else {
prompt_str = (boost::format(tr("Sweeping %s for a total fee of %s. Is this okay? (Y/Yes/N/No)")) %
- print_money(total_dust) %
+ print_money(total_unmixable) %
print_money(total_fee)).str();
}
std::string accepted = command_line::input_line(prompt_str);
@@ -2122,11 +2293,12 @@ bool simple_wallet::sweep_dust(const std::vector<std::string> &args_)
}
catch (const tools::error::not_enough_money& e)
{
- fail_msg_writer() << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) %
+ fail_msg_writer() << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee).\n%s")) %
print_money(e.available()) %
print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
- print_money(e.fee());
+ print_money(e.fee()) %
+ tr("This is usually due to dust which is so small it cannot pay for itself in fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
@@ -2575,6 +2747,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_generate_new_wallet);
command_line::add_arg(desc_params, arg_generate_from_view_key);
command_line::add_arg(desc_params, arg_generate_from_keys);
+ command_line::add_arg(desc_params, arg_generate_from_json);
command_line::add_arg(desc_params, arg_password);
command_line::add_arg(desc_params, arg_password_file);
command_line::add_arg(desc_params, arg_daemon_address);
@@ -2707,11 +2880,21 @@ int main(int argc, char* argv[])
if (daemon_address.empty())
daemon_address = std::string("http://") + daemon_host + ":" + std::to_string(daemon_port);
+ std::string password;
+ const std::string gfj = command_line::get_arg(vm, arg_generate_from_json);
+ if (!gfj.empty()) {
+ if (!w.generate_from_json(vm, wallet_file, password))
+ return 1;
+ }
+ else {
+ password = pwd_container.password();
+ }
+
tools::wallet2 wal(testnet,restricted);
try
{
LOG_PRINT_L0(sw::tr("Loading wallet..."));
- wal.load(wallet_file, pwd_container.password());
+ wal.load(wallet_file, password);
wal.init(daemon_address);
wal.refresh();
LOG_PRINT_GREEN(sw::tr("Loaded ok"), LOG_LEVEL_0);
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index d1617dbf4..21bbfa566 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -69,6 +69,7 @@ namespace cryptonote
bool run();
void stop();
void interrupt();
+ bool generate_from_json(const boost::program_options::variables_map& vm, std::string &wallet_file, std::string &password);
//wallet *create_wallet();
bool process_command(const std::vector<std::string> &args);
@@ -120,7 +121,7 @@ namespace cryptonote
bool transfer_main(bool new_algorithm, const std::vector<std::string> &args);
bool transfer(const std::vector<std::string> &args);
bool transfer_new(const std::vector<std::string> &args);
- bool sweep_dust(const std::vector<std::string> &args);
+ bool sweep_unmixable(const std::vector<std::string> &args);
std::vector<std::vector<cryptonote::tx_destination_entry>> split_amounts(
std::vector<cryptonote::tx_destination_entry> dsts, size_t num_splits
);
@@ -221,6 +222,7 @@ namespace cryptonote
std::string m_generate_new;
std::string m_generate_from_view_key;
std::string m_generate_from_keys;
+ std::string m_generate_from_json;
std::string m_import_path;
std::string m_electrum_seed; // electrum-style seed parameter
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 2afe08cb1..363665024 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -92,6 +92,13 @@ void do_prepare_file_names(const std::string& file_path, std::string& keys_file,
}
}
+uint64_t calculate_fee(const cryptonote::blobdata &blob)
+{
+ uint64_t bytes = blob.size();
+ uint64_t kB = (bytes + 1023) / 1024;
+ return kB * FEE_PER_KB;
+}
+
} //namespace
namespace tools
@@ -490,7 +497,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
//handle transactions from new block
//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
- if(b.timestamp + 60*60*24 > m_account.get_createtime())
+ if(b.timestamp + 60*60*24 > m_account.get_createtime() && height >= m_refresh_from_block_height)
{
TIME_MEASURE_START(miner_tx_handle_time);
process_new_transaction(b.miner_tx, height, true);
@@ -1207,7 +1214,7 @@ void wallet2::generate(const std::string& wallet_, const std::string& password,
m_account_public_address = account_public_address;
m_watch_only = false;
- bool r = store_keys(m_keys_file, password, true);
+ bool r = store_keys(m_keys_file, password, false);
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
@@ -2030,13 +2037,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
{
transfer(dst_vector, fake_outs_count, unlock_time, needed_fee, extra, tx, ptx);
auto txBlob = t_serializable_object_to_blob(ptx.tx);
- uint64_t txSize = txBlob.size();
- uint64_t numKB = txSize / 1024;
- if (txSize % 1024)
- {
- numKB++;
- }
- needed_fee = numKB * FEE_PER_KB;
+ needed_fee = calculate_fee(txBlob);
} while (ptx.fee < needed_fee);
ptx_vector.push_back(ptx);
@@ -2408,15 +2409,9 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx);
auto txBlob = t_serializable_object_to_blob(test_ptx.tx);
- uint64_t txSize = txBlob.size();
- uint64_t numKB = txSize / 1024;
- if (txSize % 1024)
- {
- numKB++;
- }
- needed_fee = numKB * FEE_PER_KB;
+ needed_fee = calculate_fee(txBlob);
available_for_fee = test_ptx.fee + test_ptx.change_dts.amount;
- LOG_PRINT_L2("Made a " << numKB << " kB tx, with " << print_money(available_for_fee) << " available for fee (" <<
+ LOG_PRINT_L2("Made a " << txBlob.size() << " kB tx, with " << print_money(available_for_fee) << " available for fee (" <<
print_money(needed_fee) << " needed)");
if (needed_fee > available_for_fee && dsts[0].amount > 0)
@@ -2513,7 +2508,7 @@ uint64_t wallet2::unlocked_dust_balance(const tx_dust_policy &dust_policy) const
}
template<typename T>
-void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t needed_fee, T destination_split_strategy, const tx_dust_policy& dust_policy, const std::vector<uint8_t> &extra, cryptonote::transaction& tx, pending_tx &ptx)
+void wallet2::transfer_from(const std::vector<size_t> &outs, size_t num_outputs, uint64_t unlock_time, uint64_t needed_fee, T destination_split_strategy, const tx_dust_policy& dust_policy, const std::vector<uint8_t> &extra, cryptonote::transaction& tx, pending_tx &ptx)
{
using namespace cryptonote;
@@ -2523,6 +2518,19 @@ void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t n
// throw if there are none
uint64_t money = 0;
std::list<transfer_container::iterator> selected_transfers;
+#if 1
+ for (size_t n = 0; n < outs.size(); ++n)
+ {
+ const transfer_details& td = m_transfers[outs[n]];
+ if (!td.m_spent)
+ {
+ selected_transfers.push_back (m_transfers.begin() + outs[n]);
+ money += td.amount();
+ if (selected_transfers.size() >= num_outputs)
+ break;
+ }
+ }
+#else
for (transfer_container::iterator i = m_transfers.begin(); i != m_transfers.end(); ++i)
{
const transfer_details& td = *i;
@@ -2534,6 +2542,7 @@ void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t n
break;
}
}
+#endif
// we don't allow no output to self, easier, but one may want to burn the dust if = fee
THROW_WALLET_EXCEPTION_IF(money <= needed_fee, error::not_enough_money, money, needed_fee, needed_fee);
@@ -2627,8 +2636,8 @@ bool wallet2::use_fork_rules(uint8_t version)
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();
CHECK_AND_ASSERT_MES(r, false, "Failed to connect to daemon");
- CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, false, "Failed to connect to daemon");
- CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, false, "Failed to get hard fork status");
+ CHECK_AND_ASSERT_MES(resp_t.result.status != CORE_RPC_STATUS_BUSY, false, "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(resp_t.result.status == CORE_RPC_STATUS_OK, false, "Failed to get hard fork status");
bool close_enough = res.height >= resp_t.result.earliest_height - 10; // start using the rules a bit beforehand
if (close_enough)
@@ -2646,20 +2655,85 @@ uint64_t wallet2::get_upper_tranaction_size_limit()
return ((full_reward_zone * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
}
//----------------------------------------------------------------------------------------------------
-std::vector<wallet2::pending_tx> wallet2::create_dust_sweep_transactions()
+std::vector<size_t> wallet2::select_available_outputs(const std::function<bool(const transfer_details &td)> &f)
+{
+ std::vector<size_t> outputs;
+ size_t n = 0;
+ for (transfer_container::const_iterator i = m_transfers.begin(); i != m_transfers.end(); ++i, ++n)
+ {
+ if (i->m_spent)
+ continue;
+ if (!is_transfer_unlocked(*i))
+ continue;
+ if (f(*i))
+ outputs.push_back(n);
+ }
+ return outputs;
+}
+//----------------------------------------------------------------------------------------------------
+std::vector<uint64_t> wallet2::get_unspent_amounts_vector()
+{
+ std::set<uint64_t> set;
+ for (const auto &td: m_transfers)
+ {
+ if (!td.m_spent)
+ set.insert(td.amount());
+ }
+ std::vector<uint64_t> vector;
+ vector.reserve(set.size());
+ for (const auto &i: set)
+ {
+ vector.push_back(i);
+ }
+ return vector;
+}
+//----------------------------------------------------------------------------------------------------
+std::vector<size_t> wallet2::select_available_unmixable_outputs(bool trusted_daemon)
+{
+ // request all outputs with at least 3 instances, so we can use mixin 2 with
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response, std::string> 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";
+ if (trusted_daemon)
+ req_t.params.amounts = get_unspent_amounts_vector();
+ req_t.params.min_count = 3;
+ 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, "select_available_unmixable_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);
+
+ std::set<uint64_t> mixable;
+ for (const auto &i: resp_t.result.histogram)
+ {
+ mixable.insert(i.amount);
+ }
+
+ return select_available_outputs([mixable](const transfer_details &td) {
+ const uint64_t amount = td.amount();
+ if (mixable.find(amount) == mixable.end())
+ return true;
+ return false;
+ });
+}
+//----------------------------------------------------------------------------------------------------
+std::vector<wallet2::pending_tx> wallet2::create_unmixable_sweep_transactions(bool trusted_daemon)
{
// From hard fork 1, we don't consider small amounts to be dust anymore
const bool hf1_rules = use_fork_rules(2); // first hard fork has version 2
tx_dust_policy dust_policy(hf1_rules ? 0 : ::config::DEFAULT_DUST_THRESHOLD);
- size_t num_dust_outputs = 0;
- for (transfer_container::const_iterator i = m_transfers.begin(); i != m_transfers.end(); ++i)
+ // may throw
+ std::vector<size_t> unmixable_outputs = select_available_unmixable_outputs(trusted_daemon);
+ size_t num_dust_outputs = unmixable_outputs.size();
+
+ if (num_dust_outputs == 0)
{
- const transfer_details& td = *i;
- if (!td.m_spent && (td.amount() < dust_policy.dust_threshold || !is_valid_decomposed_amount(td.amount())) && is_transfer_unlocked(td))
- {
- num_dust_outputs++;
- }
+ return std::vector<wallet2::pending_tx>();
}
// failsafe split attempt counter
@@ -2682,23 +2756,18 @@ std::vector<wallet2::pending_tx> wallet2::create_dust_sweep_transactions()
// loop until fee is met without increasing tx size to next KB boundary.
uint64_t needed_fee = 0;
- if (1)
+ do
{
- transfer_dust(num_outputs_per_tx, (uint64_t)0 /* unlock_time */, 0, detail::digit_split_strategy, dust_policy, extra, tx, ptx);
+ transfer_from(unmixable_outputs, num_outputs_per_tx, (uint64_t)0 /* unlock_time */, 0, detail::digit_split_strategy, dust_policy, extra, tx, ptx);
auto txBlob = t_serializable_object_to_blob(ptx.tx);
- uint64_t txSize = txBlob.size();
- uint64_t numKB = txSize / 1024;
- if (txSize % 1024)
- {
- numKB++;
- }
- needed_fee = numKB * FEE_PER_KB;
+ needed_fee = calculate_fee(txBlob);
// reroll the tx with the actual amount minus the fee
// if there's not enough for the fee, it'll throw
- transfer_dust(num_outputs_per_tx, (uint64_t)0 /* unlock_time */, needed_fee, detail::digit_split_strategy, dust_policy, extra, tx, ptx);
+ transfer_from(unmixable_outputs, num_outputs_per_tx, (uint64_t)0 /* unlock_time */, needed_fee, detail::digit_split_strategy, dust_policy, extra, tx, ptx);
txBlob = t_serializable_object_to_blob(ptx.tx);
- }
+ needed_fee = calculate_fee(txBlob);
+ } while (ptx.fee < needed_fee);
ptx_vector.push_back(ptx);
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index f798f404d..fc700a3de 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -88,10 +88,10 @@ namespace tools
};
private:
- wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers (false), m_store_tx_info(true), m_default_mixin(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true) {}
+ wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers (false), m_store_tx_info(true), m_default_mixin(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0) {}
public:
- wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_restricted(restricted), is_old_file_format(false), m_store_tx_info(true), m_default_mixin(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true) {}
+ wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_restricted(restricted), is_old_file_format(false), m_store_tx_info(true), m_default_mixin(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0) {}
struct transfer_details
{
uint64_t m_block_height;
@@ -226,6 +226,8 @@ namespace tools
cryptonote::account_base& get_account(){return m_account;}
const cryptonote::account_base& get_account()const{return m_account;}
+ void set_refresh_from_block_height(uint64_t height) {m_refresh_from_block_height = height;}
+
// upper_transaction_size_limit as defined below is set to
// approximately 125% of the fixed minimum allowable penalty
// free block size. TODO: fix this so that it actually takes
@@ -278,7 +280,7 @@ namespace tools
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);
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, cryptonote::transaction& tx, pending_tx& ptx);
template<typename T>
- void transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t needed_fee, T destination_split_strategy, const tx_dust_policy& dust_policy, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx);
+ void transfer_from(const std::vector<size_t> &outs, size_t num_outputs, uint64_t unlock_time, uint64_t needed_fee, T destination_split_strategy, const tx_dust_policy& dust_policy, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx);
template<typename T>
void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<transfer_container::iterator> selected_transfers, 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, cryptonote::transaction& tx, pending_tx &ptx);
@@ -287,7 +289,7 @@ namespace tools
void commit_tx(std::vector<pending_tx>& ptx_vector);
std::vector<pending_tx> create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee, const std::vector<uint8_t> extra);
std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee_UNUSED, const std::vector<uint8_t> extra);
- std::vector<pending_tx> create_dust_sweep_transactions();
+ std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
bool check_connection();
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
@@ -319,6 +321,9 @@ namespace tools
if(ver < 9)
return;
a & m_confirmed_txs;
+ if(ver < 11)
+ return;
+ a & m_refresh_from_block_height;
}
/*!
@@ -397,6 +402,9 @@ namespace tools
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
uint64_t get_upper_tranaction_size_limit();
void check_pending_txes();
+ std::vector<uint64_t> get_unspent_amounts_vector();
+ std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
+ std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon);
cryptonote::account_base m_account;
std::string m_daemon_address;
@@ -430,9 +438,10 @@ namespace tools
uint32_t m_default_mixin;
RefreshType m_refresh_type;
bool m_auto_refresh;
+ uint64_t m_refresh_from_block_height;
};
}
-BOOST_CLASS_VERSION(tools::wallet2, 10)
+BOOST_CLASS_VERSION(tools::wallet2, 11)
BOOST_CLASS_VERSION(tools::wallet2::payment_details, 0)
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 2)
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 1)
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 6074e0858..652b19499 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -76,6 +76,7 @@ namespace tools
// daemon_busy
// no_connection_to_daemon
// is_key_image_spent_error
+ // get_histogram_error
// wallet_files_doesnt_correspond
//
// * - class with protected ctor
@@ -600,6 +601,14 @@ namespace tools
}
};
//----------------------------------------------------------------------------------------------------
+ struct get_histogram_error : public wallet_rpc_error
+ {
+ explicit get_histogram_error(std::string&& loc, const std::string& request)
+ : wallet_rpc_error(std::move(loc), "failed to get output histogram", request)
+ {
+ }
+ };
+ //----------------------------------------------------------------------------------------------------
struct wallet_files_doesnt_correspond : public wallet_logic_error
{
explicit wallet_files_doesnt_correspond(std::string&& loc, const std::string& keys_file, const std::string& wallet_file)
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 418de327c..d7d99c2ae 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -347,7 +347,7 @@ namespace tools
try
{
- std::vector<wallet2::pending_tx> ptx_vector = m_wallet.create_dust_sweep_transactions();
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet.create_unmixable_sweep_transactions(req.trusted_daemon);
m_wallet.commit_tx(ptx_vector);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 40d6fd8f8..2c4e26406 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -178,9 +178,11 @@ namespace wallet_rpc
struct request
{
bool get_tx_keys;
+ bool trusted_daemon;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(get_tx_keys)
+ KV_SERIALIZE(trusted_daemon)
END_KV_SERIALIZE_MAP()
};
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 50e0e5ae8..cc3eba8ea 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -108,6 +108,7 @@ public:
virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const { return true; }
virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const { return true; }
virtual bool is_read_only() const { return false; }
+ virtual std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const { return std::map<uint64_t, uint64_t>(); }
virtual void add_block( const block& blk
, const size_t& block_size
diff --git a/utils/munin_plugins/alt_blocks_count b/utils/munin_plugins/alt_blocks_count
index d68289c34..cf6b3651b 100644
--- a/utils/munin_plugins/alt_blocks_count
+++ b/utils/munin_plugins/alt_blocks_count
@@ -42,4 +42,4 @@ EOM
esac
printf "alt_blocks_count.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep alt_blocks_count | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep alt_blocks_count | cut -d ' ' -f2
diff --git a/utils/munin_plugins/difficulty b/utils/munin_plugins/difficulty
index e22b76829..edfd2bf16 100644
--- a/utils/munin_plugins/difficulty
+++ b/utils/munin_plugins/difficulty
@@ -42,4 +42,4 @@ EOM
esac
printf "difficulty.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep difficulty | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep difficulty | cut -d ' ' -f2
diff --git a/utils/munin_plugins/grey_peerlist_size b/utils/munin_plugins/grey_peerlist_size
index e18c4cd06..d7b1bd6a7 100644
--- a/utils/munin_plugins/grey_peerlist_size
+++ b/utils/munin_plugins/grey_peerlist_size
@@ -42,4 +42,4 @@ EOM
esac
printf "grey_peerlist_size.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep grey_peerlist_size | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep grey_peerlist_size | cut -d ' ' -f2
diff --git a/utils/munin_plugins/height b/utils/munin_plugins/height
index ca68b31b9..3f79fa302 100644
--- a/utils/munin_plugins/height
+++ b/utils/munin_plugins/height
@@ -43,4 +43,4 @@ EOM
esac
printf "height.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep height | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep height | cut -d ' ' -f2
diff --git a/utils/munin_plugins/incoming_connections_count b/utils/munin_plugins/incoming_connections_count
index 2521d4c99..7232e5736 100644
--- a/utils/munin_plugins/incoming_connections_count
+++ b/utils/munin_plugins/incoming_connections_count
@@ -42,4 +42,4 @@ EOM
esac
printf "incoming_connections_count.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep incoming_connections_count | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep incoming_connections_count | cut -d ' ' -f2
diff --git a/utils/munin_plugins/outgoing_connections_count b/utils/munin_plugins/outgoing_connections_count
index 92edb3d67..773ce4624 100644
--- a/utils/munin_plugins/outgoing_connections_count
+++ b/utils/munin_plugins/outgoing_connections_count
@@ -42,4 +42,4 @@ EOM
esac
printf "outgoing_connections_count.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep outgoing_connections_count | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep outgoing_connections_count | cut -d ' ' -f2
diff --git a/utils/munin_plugins/tx_count b/utils/munin_plugins/tx_count
index 95bb8b540..f2504cd5f 100644
--- a/utils/munin_plugins/tx_count
+++ b/utils/munin_plugins/tx_count
@@ -43,4 +43,4 @@ EOM
esac
printf "tx_count.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep tx_count| cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep tx_count| cut -d ' ' -f2
diff --git a/utils/munin_plugins/tx_pool_size b/utils/munin_plugins/tx_pool_size
index 58717cf1f..3bf952071 100644
--- a/utils/munin_plugins/tx_pool_size
+++ b/utils/munin_plugins/tx_pool_size
@@ -42,4 +42,4 @@ EOM
esac
printf "tx_pool_size.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep tx_pool_size| cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep tx_pool_size| cut -d ' ' -f2
diff --git a/utils/munin_plugins/white_peerlist_size b/utils/munin_plugins/white_peerlist_size
index 2b92622e5..9e5771cc3 100644
--- a/utils/munin_plugins/white_peerlist_size
+++ b/utils/munin_plugins/white_peerlist_size
@@ -42,4 +42,4 @@ EOM
esac
printf "white_peerlist_size.value "
-/home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep white_peerlist_size | cut -d ' ' -f2
+# rewrite using curl or similar: /home/user/bitmonero/build/release/src/connectivity_tool --ip=127.0.0.1 --rpc_port=8081 --timeout=1000 --rpc_get_daemon_info | grep white_peerlist_size | cut -d ' ' -f2