aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r--src/wallet/wallet2.cpp56
1 files changed, 52 insertions, 4 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 5a9b96bb8..d10529194 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -48,6 +48,7 @@ using namespace epee;
#include "cryptonote_protocol/blobdatatype.h"
#include "mnemonics/electrum-words.h"
#include "common/dns_utils.h"
+#include "common/util.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
@@ -228,7 +229,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
// process the other outs from that tx
boost::asio::io_service ioservice;
boost::thread_group threadpool;
- std::auto_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice));
+ std::unique_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice));
for (int i = 0; i < threads; i++)
{
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice));
@@ -264,7 +265,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
{
boost::asio::io_service ioservice;
boost::thread_group threadpool;
- std::auto_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice));
+ std::unique_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice));
for (int i = 0; i < threads; i++)
{
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice));
@@ -1283,8 +1284,20 @@ void wallet2::store()
std::string buf;
bool r = ::serialization::dump_binary(cache_file_data, buf);
- r = r && epee::file_io_utils::save_string_to_file(m_wallet_file, buf);
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_wallet_file);
+
+ // save to new file, rename main to old, rename new to main
+ // at all times, there should be a valid file on disk
+ const std::string new_file = m_wallet_file + ".new";
+ const std::string old_file = m_wallet_file + ".old";
+ r = epee::file_io_utils::save_string_to_file(new_file, buf);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, new_file);
+ boost::filesystem::remove(old_file); // probably does not exist
+ std::error_code e = tools::replace_file(m_wallet_file, old_file);
+ THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e);
+ e = tools::replace_file(new_file, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e);
+ boost::filesystem::remove(old_file);
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::unlocked_balance() const
@@ -2326,9 +2339,44 @@ void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t n
}
//----------------------------------------------------------------------------------------------------
+bool wallet2::use_fork_rules(uint8_t version)
+{
+ cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req);
+ cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res);
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_HARD_FORK_INFO::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_HARD_FORK_INFO::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
+
+ m_daemon_rpc_mutex.lock();
+ bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, 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 current blockchain height");
+
+ m_daemon_rpc_mutex.lock();
+ req_t.jsonrpc = "2.0";
+ req_t.id = epee::serialization::storage_entry(0);
+ req_t.method = "hard_fork_info";
+ req_t.params.version = 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");
+
+ bool close_enough = res.height >= resp_t.result.earliest_height - 10; // start using the rules a bit beforehand
+ if (close_enough)
+ LOG_PRINT_L2("Using HF1 rules");
+ else
+ LOG_PRINT_L2("Not using HF1 rules");
+ return close_enough;
+}
+//----------------------------------------------------------------------------------------------------
std::vector<wallet2::pending_tx> wallet2::create_dust_sweep_transactions()
{
- tx_dust_policy dust_policy(::config::DEFAULT_DUST_THRESHOLD);
+ // 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)