aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/epee/include/misc_log_ex.h1
-rw-r--r--contrib/epee/include/misc_os_dependent.h12
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl9
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp2
-rw-r--r--src/common/util.cpp32
-rw-r--r--src/common/util.h5
-rw-r--r--src/crypto/random.c2
-rw-r--r--src/cryptonote_core/blockchain.cpp32
-rw-r--r--src/cryptonote_core/blockchain.h1
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.cpp14
-rw-r--r--src/cryptonote_core/tx_pool.cpp2
-rw-r--r--src/cryptonote_core/tx_pool.h2
-rw-r--r--src/daemon/command_line_args.h5
-rw-r--r--src/daemon/main.cpp4
-rw-r--r--src/daemon/rpc_command_executor.cpp60
-rw-r--r--src/p2p/net_node.inl1
-rw-r--r--src/rpc/core_rpc_server.cpp53
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h61
-rw-r--r--src/simplewallet/simplewallet.cpp742
-rw-r--r--src/simplewallet/simplewallet.h6
-rw-r--r--src/wallet/wallet2.cpp351
-rw-r--r--src/wallet/wallet2.h83
-rw-r--r--src/wallet/wallet_errors.h5
-rw-r--r--src/wallet/wallet_rpc_server.cpp224
-rw-r--r--src/wallet/wallet_rpc_server.h8
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h143
-rw-r--r--src/wallet/wallet_rpc_server_error_codes.h1
-rw-r--r--tests/core_tests/chaingen.h6
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp3
-rw-r--r--tests/unit_tests/unbound.cpp4
31 files changed, 1600 insertions, 276 deletions
diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h
index d1451ff12..7cb1e61aa 100644
--- a/contrib/epee/include/misc_log_ex.h
+++ b/contrib/epee/include/misc_log_ex.h
@@ -424,6 +424,7 @@ namespace log_space
}
std::cout << buf;
+ std::cout << std::flush;
#endif
reset_console_color();
return true;
diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h
index 2abca0446..806d3e83e 100644
--- a/contrib/epee/include/misc_os_dependent.h
+++ b/contrib/epee/include/misc_os_dependent.h
@@ -53,11 +53,13 @@ namespace misc_utils
#if defined(_MSC_VER)
return ::GetTickCount64();
#elif defined(WIN32)
-# if defined(WIN64)
- return GetTickCount64();
-# else
- return GetTickCount();
-# endif
+ static LARGE_INTEGER pcfreq = {0};
+ LARGE_INTEGER ticks;
+ if (!pcfreq.QuadPart)
+ QueryPerformanceFrequency(&pcfreq);
+ QueryPerformanceCounter(&ticks);
+ ticks.QuadPart *= 1000; /* we want msec */
+ return ticks.QuadPart / pcfreq.QuadPart;
#elif defined(__MACH__)
clock_serv_t cclock;
mach_timespec_t mts;
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index b3d4e5fdb..ca9429c91 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -490,7 +490,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
sleep_before_packet(cb, 1, 1);
}
- epee::critical_region_t<decltype(m_send_que_lock)> send_guard(m_send_que_lock); // *** critical ***
+ m_send_que_lock.lock(); // *** critical ***
+ epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_send_que_lock.unlock();});
+
long int retry=0;
const long int retry_limit = 5*4;
while (m_send_que.size() > ABSTRACT_SERVER_SEND_QUE_MAX_COUNT)
@@ -504,14 +506,15 @@ PRAGMA_WARNING_DISABLE_VS(4355)
long int ms = 250 + (rand()%50);
_info_c("net/sleep", "Sleeping because QUEUE is FULL, in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<cb); // XXX debug sleep
+ m_send_que_lock.unlock();
boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) );
+ m_send_que_lock.lock();
_dbg1("sleep for queue: " << ms);
if (retry > retry_limit) {
- send_guard.unlock();
_erro("send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
// _dbg1_c("net/sleep", "send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
- close();
+ shutdown();
return false;
}
}
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index a7fa556bd..b11570e37 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -135,7 +135,7 @@ const unsigned int DB_BUFFER_LENGTH = 32 * MB;
const unsigned int DB_DEF_CACHESIZE = 256 * MB;
#if defined(BDB_BULK_CAN_THREAD)
-const unsigned int DB_BUFFER_COUNT = boost::thread::hardware_concurrency();
+const unsigned int DB_BUFFER_COUNT = tools::get_max_concurrency();
#else
const unsigned int DB_BUFFER_COUNT = 1;
#endif
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 6f75e5bad..a53a9be52 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -413,4 +413,36 @@ std::string get_nix_version_display_string()
}
return false;
}
+ void set_strict_default_file_permissions(bool strict)
+ {
+#if defined(__MINGW32__) || defined(__MINGW__)
+ // no clue about the odd one out
+#else
+ mode_t mode = strict ? 077 : 0;
+ umask(mode);
+#endif
+ }
+
+ namespace
+ {
+ boost::mutex max_concurrency_lock;
+ unsigned max_concurrency = boost::thread::hardware_concurrency();
+ }
+
+ void set_max_concurrency(unsigned n)
+ {
+ if (n < 1)
+ n = boost::thread::hardware_concurrency();
+ unsigned hwc = boost::thread::hardware_concurrency();
+ if (n > hwc)
+ n = hwc;
+ boost::lock_guard<boost::mutex> lock(max_concurrency_lock);
+ max_concurrency = n;
+ }
+
+ unsigned get_max_concurrency()
+ {
+ boost::lock_guard<boost::mutex> lock(max_concurrency_lock);
+ return max_concurrency;
+ }
}
diff --git a/src/common/util.h b/src/common/util.h
index 7554b1df7..4fcf66b8f 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -158,4 +158,9 @@ namespace tools
/*! \brief where the installed handler is stored */
static std::function<void(int)> m_handler;
};
+
+ void set_strict_default_file_permissions(bool strict);
+
+ void set_max_concurrency(unsigned n);
+ unsigned get_max_concurrency();
}
diff --git a/src/crypto/random.c b/src/crypto/random.c
index d7fcb7e65..f8a50d850 100644
--- a/src/crypto/random.c
+++ b/src/crypto/random.c
@@ -45,7 +45,7 @@ static void generate_system_random_bytes(size_t n, void *result);
static void generate_system_random_bytes(size_t n, void *result) {
HCRYPTPROV prov;
-#define must_succeed(x) do if (!(x)) assert(0); while (0)
+#define must_succeed(x) do if (!(x)) abort(); while (0)
must_succeed(CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT));
must_succeed(CryptGenRandom(prov, (DWORD)n, result));
must_succeed(CryptReleaseContext(prov, 0));
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index a0c557c79..d332f8997 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -498,6 +498,7 @@ block Blockchain::pop_block_from_blockchain()
}
}
}
+ update_next_cumulative_size_limit();
m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id());
return popped_block;
@@ -2016,18 +2017,12 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t& max_used_block
TIME_MEASURE_START(a);
bool res = check_tx_inputs(tx, tvc, &max_used_block_height);
TIME_MEASURE_FINISH(a);
- crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
if(m_show_time_stats)
LOG_PRINT_L0("HASH: " << "+" << " VIN/VOUT: " << tx.vin.size() << "/" << tx.vout.size() << " H: " << max_used_block_height << " chcktx: " << a + m_fake_scan_time);
if (!res)
return false;
- // ND: Speedup:
- // 1. keep a list of verified transactions, when the Blockchain tries to check a tx again,
- // verify against list and skip if already verified to be correct.
- m_check_tx_inputs_table.emplace(tx_prefix_hash, std::make_pair(res, max_used_block_height));
-
CHECK_AND_ASSERT_MES(max_used_block_height < m_db->height(), false, "internal error: max used block index=" << max_used_block_height << " is not less then blockchain size = " << m_db->height());
max_used_block_id = m_db->get_block_hash_from_height(max_used_block_height);
return true;
@@ -2077,16 +2072,6 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context
crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
- auto its = m_check_tx_inputs_table.find(tx_prefix_hash);
- if (its != m_check_tx_inputs_table.end())
- {
- if (!its->second.first)
- return false;
- if (pmax_used_block_height)
- *pmax_used_block_height = its->second.second;
- return true;
- }
-
// from hard fork 2, we require mixin at least 2 unless one output cannot mix with 2 others
// if one output cannot mix with 2 others, we accept at most 1 output that can mix
if (m_hardfork->get_current_version() >= 2)
@@ -2140,7 +2125,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context
std::vector < uint64_t > results;
results.resize(tx.vin.size(), 0);
- int threads = boost::thread::hardware_concurrency();
+ int threads = tools::get_max_concurrency();
boost::asio::io_service ioservice;
boost::thread_group threadpool;
@@ -2160,6 +2145,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context
if(ioservice_active) \
{ \
work.reset(); \
+ while (!ioservice.stopped()) ioservice.poll(); \
threadpool.join_all(); \
ioservice.stop(); \
ioservice_active = false; \
@@ -2728,7 +2714,11 @@ leave:
// populate various metadata about the block to be stored alongside it.
block_size = cumulative_block_size;
cumulative_difficulty = current_diffic;
- already_generated_coins = already_generated_coins + base_reward;
+ // In the "tail" state when the minimum subsidy (implemented in get_block_reward) is in effect, the number of
+ // coins will eventually exceed MONEY_SUPPLY and overflow a uint64. To prevent overflow, cap already_generated_coins
+ // at MONEY_SUPPLY. already_generated_coins is only used to compute the block subsidy and MONEY_SUPPLY yields a
+ // subsidy of 0 under the base formula and therefore the minimum subsidy >0 in the tail state.
+ already_generated_coins = base_reward < (MONEY_SUPPLY-already_generated_coins) ? already_generated_coins + base_reward : MONEY_SUPPLY;
if(m_db->height())
cumulative_difficulty += m_db->get_block_cumulative_difficulty(m_db->height() - 1);
@@ -2968,7 +2958,6 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
TIME_MEASURE_FINISH(t1);
m_blocks_longhash_table.clear();
m_scan_table.clear();
- m_check_tx_inputs_table.clear();
m_blocks_txs_check.clear();
m_check_txin_table.clear();
@@ -3013,7 +3002,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
return true;
bool blocks_exist = false;
- uint64_t threads = boost::thread::hardware_concurrency();
+ uint64_t threads = tools::get_max_concurrency();
if (blocks_entry.size() > 1 && threads > 1 && m_max_prepare_blocks_threads > 1)
{
@@ -3116,7 +3105,6 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
m_fake_pow_calc_time = 0;
m_scan_table.clear();
- m_check_tx_inputs_table.clear();
m_check_txin_table.clear();
TIME_MEASURE_FINISH(prepare);
@@ -3213,7 +3201,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
// [output] stores all transactions for each tx_out_index::hash found
std::vector<std::unordered_map<crypto::hash, cryptonote::transaction>> transactions(amounts.size());
- threads = boost::thread::hardware_concurrency();
+ threads = tools::get_max_concurrency();
if (!m_db->can_thread_bulk_indices())
threads = 1;
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index a62487d1e..21086d578 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -790,7 +790,6 @@ namespace cryptonote
// metadata containers
std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, std::vector<output_data_t>>> m_scan_table;
- std::unordered_map<crypto::hash, std::pair<bool, uint64_t>> m_check_tx_inputs_table;
std::unordered_map<crypto::hash, crypto::hash> m_blocks_longhash_table;
std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, bool>> m_check_txin_table;
diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp
index 94f3d51d2..3b9dcc8a4 100644
--- a/src/cryptonote_core/cryptonote_format_utils.cpp
+++ b/src/cryptonote_core/cryptonote_format_utils.cpp
@@ -145,7 +145,19 @@ namespace cryptonote
[&out_amounts](uint64_t a_dust) { out_amounts.push_back(a_dust); });
CHECK_AND_ASSERT_MES(1 <= max_outs, false, "max_out must be non-zero");
- CHECK_AND_ASSERT_MES(max_outs >= out_amounts.size(), false, "max_out exceeded");
+ if (height == 0)
+ {
+ // the genesis block was not decomposed, for unknown reasons
+ while (max_outs < out_amounts.size())
+ {
+ out_amounts[out_amounts.size() - 2] += out_amounts.back();
+ out_amounts.resize(out_amounts.size() - 1);
+ }
+ }
+ else
+ {
+ CHECK_AND_ASSERT_MES(max_outs >= out_amounts.size(), false, "max_out exceeded");
+ }
uint64_t summary_amounts = 0;
for (size_t no = 0; no < out_amounts.size(); no++)
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index a06826163..3d5ab86e1 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -512,7 +512,7 @@ namespace cryptonote
{
if(txd.max_used_block_height >= m_blockchain.get_current_blockchain_height())
return false;
- if(m_blockchain.get_block_id_by_height(txd.max_used_block_height) != txd.max_used_block_id)
+ if(true)
{
//if we already failed on this height and id, skip actual ring signature check
if(txd.last_failed_id == m_blockchain.get_block_id_by_height(txd.last_failed_height))
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index 84e11eeff..c7aab7f08 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -310,6 +310,7 @@ namespace cryptonote
#define CURRENT_MEMPOOL_ARCHIVE_VER 11
+#define CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER 11
/**
* @brief serialize the transaction pool to/from disk
@@ -530,6 +531,7 @@ namespace boost
}
}
BOOST_CLASS_VERSION(cryptonote::tx_memory_pool, CURRENT_MEMPOOL_ARCHIVE_VER)
+BOOST_CLASS_VERSION(cryptonote::tx_memory_pool::tx_details, CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER)
diff --git a/src/daemon/command_line_args.h b/src/daemon/command_line_args.h
index 2dca5e3e7..1fe2ddcf6 100644
--- a/src/daemon/command_line_args.h
+++ b/src/daemon/command_line_args.h
@@ -59,6 +59,11 @@ namespace daemon_args
"os-version"
, "OS for which this executable was compiled"
};
+ const command_line::arg_descriptor<unsigned> arg_max_concurrency = {
+ "max-concurrency"
+ , "Max number of threads to use for a parallel job"
+ , 0
+ };
} // namespace daemon_args
#endif // DAEMON_COMMAND_LINE_ARGS_H
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 0717fd89b..bfd829dea 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -81,6 +81,7 @@ int main(int argc, char const * argv[])
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
command_line::add_arg(core_settings, daemon_args::arg_log_file, default_log.string());
command_line::add_arg(core_settings, daemon_args::arg_log_level);
+ command_line::add_arg(core_settings, daemon_args::arg_max_concurrency);
daemonizer::init_options(hidden_options, visible_options);
daemonize::t_executor::init_options(core_settings);
@@ -260,6 +261,9 @@ int main(int argc, char const * argv[])
);
}
+ if (command_line::has_arg(vm, daemon_args::arg_max_concurrency))
+ tools::set_max_concurrency(command_line::get_arg(vm, daemon_args::arg_max_concurrency));
+
_note_c("dbg/main", "Moving from main() into the daemonize now.");
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 933c93ed7..ae9492111 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -70,6 +70,23 @@ namespace {
<< "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl
<< "reward: " << boost::lexical_cast<std::string>(header.reward);
}
+
+ std::string get_human_time_ago(time_t t, time_t now)
+ {
+ if (t == now)
+ return "now";
+ time_t dt = t > now ? t - now : now - t;
+ std::string s;
+ if (dt < 90)
+ s = boost::lexical_cast<std::string>(dt) + " seconds";
+ else if (dt < 90 * 60)
+ s = boost::lexical_cast<std::string>(dt/60) + " minutes";
+ else if (dt < 36 * 3600)
+ s = boost::lexical_cast<std::string>(dt/3600) + " hours";
+ else
+ s = boost::lexical_cast<std::string>(dt/(3600*24)) + " days";
+ return s + " " + (t > now ? "in the future" : "ago");
+ }
}
t_rpc_command_executor::t_rpc_command_executor(
@@ -575,16 +592,26 @@ bool t_rpc_command_executor::print_transaction(crypto::hash transaction_hash) {
}
}
- if (1 == res.txs_as_hex.size())
+ if (1 == res.txs.size() || 1 == res.txs_as_hex.size())
{
+ if (1 == res.txs.size())
+ {
+ // only available for new style answers
+ if (res.txs.front().in_pool)
+ tools::success_msg_writer() << "Found in pool";
+ else
+ tools::success_msg_writer() << "Found in blockchain at height " << res.txs.front().block_height;
+ }
+
// first as hex
- tools::success_msg_writer() << res.txs_as_hex.front();
+ const std::string &as_hex = (1 == res.txs.size()) ? res.txs.front().as_hex : res.txs_as_hex.front();
+ tools::success_msg_writer() << as_hex;
// then as json
crypto::hash tx_hash, tx_prefix_hash;
cryptonote::transaction tx;
cryptonote::blobdata blob;
- if (!string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), blob))
+ if (!string_tools::parse_hexstr_to_binbuff(as_hex, blob))
{
tools::fail_msg_writer() << "Failed to parse tx";
}
@@ -669,6 +696,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() {
}
if (! res.transactions.empty())
{
+ const time_t now = time(NULL);
tools::msg_writer() << "Transactions: ";
for (auto & tx_info : res.transactions)
{
@@ -676,7 +704,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() {
<< tx_info.tx_json << std::endl
<< "blob_size: " << tx_info.blob_size << std::endl
<< "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
- << "receive_time: " << tx_info.receive_time << std::endl
+ << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
<< "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
@@ -747,17 +775,21 @@ bool t_rpc_command_executor::print_transaction_pool_short() {
{
tools::msg_writer() << "Pool is empty" << std::endl;
}
- for (auto & tx_info : res.transactions)
+ else
{
- tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
- << "blob_size: " << tx_info.blob_size << std::endl
- << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
- << "receive_time: " << tx_info.receive_time << std::endl
- << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
- << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
- << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
- << "last_failed_height: " << tx_info.last_failed_height << std::endl
- << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
+ const time_t now = time(NULL);
+ for (auto & tx_info : res.transactions)
+ {
+ tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
+ << "blob_size: " << tx_info.blob_size << std::endl
+ << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
+ << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
+ << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
+ << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
+ << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
+ << "last_failed_height: " << tx_info.last_failed_height << std::endl
+ << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
+ }
}
return true;
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 6278db891..0fab40322 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -1319,6 +1319,7 @@ namespace nodetool
if(rsp.status != PING_OK_RESPONSE_STATUS_TEXT || pr != rsp.peer_id)
{
LOG_PRINT_CC_L2(ping_context, "back ping invoke wrong response \"" << rsp.status << "\" from" << ip << ":" << port << ", hsh_peer_id=" << pr_ << ", rsp.peer_id=" << rsp.peer_id);
+ m_net_server.get_config_object().close(ping_context.m_connection_id);
return;
}
m_net_server.get_config_object().close(ping_context.m_connection_id);
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 165a24c22..9e8d1108e 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -166,6 +166,25 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res)
+ {
+ CHECK_CORE_BUSY();
+ NOTIFY_RESPONSE_CHAIN_ENTRY::request resp;
+
+ resp.start_height = req.start_height;
+ if(!m_core.find_blockchain_supplement(req.block_ids, resp))
+ {
+ res.status = "Failed";
+ return false;
+ }
+ res.current_height = resp.total_height;
+ res.start_height = resp.start_height;
+ res.m_block_ids = std::move(resp.m_block_ids);
+
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res)
{
CHECK_CORE_BUSY();
@@ -240,6 +259,7 @@ namespace cryptonote
// try the pool for any missing txes
size_t found_in_pool = 0;
+ std::unordered_set<crypto::hash> pool_tx_hashes;
if (!missed_txs.empty())
{
std::list<transaction> pool_txs;
@@ -248,9 +268,11 @@ namespace cryptonote
{
for (std::list<transaction>::const_iterator i = pool_txs.begin(); i != pool_txs.end(); ++i)
{
- std::list<crypto::hash>::iterator mi = std::find(missed_txs.begin(), missed_txs.end(), get_transaction_hash(*i));
+ crypto::hash tx_hash = get_transaction_hash(*i);
+ std::list<crypto::hash>::iterator mi = std::find(missed_txs.begin(), missed_txs.end(), tx_hash);
if (mi != missed_txs.end())
{
+ pool_tx_hashes.insert(tx_hash);
missed_txs.erase(mi);
txs.push_back(*i);
++found_in_pool;
@@ -260,12 +282,33 @@ namespace cryptonote
LOG_PRINT_L2("Found " << found_in_pool << "/" << vh.size() << " transactions in the pool");
}
+ std::list<std::string>::const_iterator txhi = req.txs_hashes.begin();
+ std::vector<crypto::hash>::const_iterator vhi = vh.begin();
BOOST_FOREACH(auto& tx, txs)
{
+ res.txs.push_back(COMMAND_RPC_GET_TRANSACTIONS::entry());
+ COMMAND_RPC_GET_TRANSACTIONS::entry &e = res.txs.back();
+
+ crypto::hash tx_hash = *vhi++;
+ e.tx_hash = *txhi++;
blobdata blob = t_serializable_object_to_blob(tx);
- res.txs_as_hex.push_back(string_tools::buff_to_hex_nodelimer(blob));
+ e.as_hex = string_tools::buff_to_hex_nodelimer(blob);
+ if (req.decode_as_json)
+ e.as_json = obj_to_json_str(tx);
+ e.in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
+ if (e.in_pool)
+ {
+ e.block_height = std::numeric_limits<uint64_t>::max();
+ }
+ else
+ {
+ e.block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash);
+ }
+
+ // fill up old style responses too, in case an old wallet asks
+ res.txs_as_hex.push_back(e.as_hex);
if (req.decode_as_json)
- res.txs_as_json.push_back(obj_to_json_str(tx));
+ res.txs_as_json.push_back(e.as_json);
}
BOOST_FOREACH(const auto& miss_tx, missed_txs)
@@ -273,7 +316,7 @@ namespace cryptonote
res.missed_tx.push_back(string_tools::pod_to_hex(miss_tx));
}
- LOG_PRINT_L2(res.txs_as_hex.size() << " transactions found, " << res.missed_tx.size() << " not found");
+ LOG_PRINT_L2(res.txs.size() << " transactions found, " << res.missed_tx.size() << " not found");
res.status = CORE_RPC_STATUS_OK;
return true;
}
@@ -383,7 +426,7 @@ namespace cryptonote
return true;
}
- if(!tvc.m_should_be_relayed)
+ if(!tvc.m_should_be_relayed || req.do_not_relay)
{
LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
res.reason = "Not relayed";
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 5c3707209..4bed148fe 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -75,6 +75,7 @@ namespace cryptonote
BEGIN_URI_MAP2()
MAP_URI_AUTO_JON2("/getheight", on_get_height, COMMAND_RPC_GET_HEIGHT)
MAP_URI_AUTO_BIN2("/getblocks.bin", on_get_blocks, COMMAND_RPC_GET_BLOCKS_FAST)
+ MAP_URI_AUTO_BIN2("/gethashes.bin", on_get_hashes, COMMAND_RPC_GET_HASHES_FAST)
MAP_URI_AUTO_BIN2("/get_o_indexes.bin", on_get_indexes, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES)
MAP_URI_AUTO_BIN2("/getrandom_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS)
MAP_URI_AUTO_JON2("/gettransactions", on_get_transactions, COMMAND_RPC_GET_TRANSACTIONS)
@@ -115,6 +116,7 @@ namespace cryptonote
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res);
bool on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res);
+ bool on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res);
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res);
bool on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request& req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response& res);
bool on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& res);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 91f5e2c90..392c7501f 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -89,6 +89,36 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
};
+
+ struct COMMAND_RPC_GET_HASHES_FAST
+ {
+
+ struct request
+ {
+ std::list<crypto::hash> block_ids; //*first 10 blocks id goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */
+ uint64_t start_height;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids)
+ KV_SERIALIZE(start_height)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::list<crypto::hash> m_block_ids;
+ uint64_t start_height;
+ uint64_t current_height;
+ std::string status;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
+ KV_SERIALIZE(start_height)
+ KV_SERIALIZE(current_height)
+ KV_SERIALIZE(status)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
//-----------------------------------------------
struct COMMAND_RPC_GET_TRANSACTIONS
{
@@ -103,18 +133,41 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
+ struct entry
+ {
+ std::string tx_hash;
+ std::string as_hex;
+ std::string as_json;
+ bool in_pool;
+ uint64_t block_height;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(tx_hash)
+ KV_SERIALIZE(as_hex)
+ KV_SERIALIZE(as_json)
+ KV_SERIALIZE(in_pool)
+ KV_SERIALIZE(block_height)
+ END_KV_SERIALIZE_MAP()
+ };
struct response
{
- std::list<std::string> txs_as_hex; //transactions blobs as hex
+ // older compatibility stuff
+ std::list<std::string> txs_as_hex; //transactions blobs as hex (old compat)
+ std::list<std::string> txs_as_json; //transactions decoded as json (old compat)
+
+ // in both old and new
std::list<std::string> missed_tx; //not found transactions
- std::list<std::string> txs_as_json; //transactions decoded as json
+
+ // new style
+ std::vector<entry> txs;
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(txs_as_hex)
- KV_SERIALIZE(missed_tx)
KV_SERIALIZE(txs_as_json)
+ KV_SERIALIZE(txs)
+ KV_SERIALIZE(missed_tx)
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
@@ -221,12 +274,14 @@ namespace cryptonote
struct request
{
std::string tx_as_hex;
+ bool do_not_relay;
request() {}
explicit request(const transaction &);
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_as_hex)
+ KV_SERIALIZE(do_not_relay)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index aa571755f..cc7b7138b 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -77,6 +77,23 @@ typedef cryptonote::simple_wallet sw;
#define DEFAULT_MIX 4
+#define LOCK_REFRESH_THREAD_SCOPE() \
+ bool auto_refresh_run = m_auto_refresh_run.load(std::memory_order_relaxed); \
+ m_auto_refresh_run.store(false, std::memory_order_relaxed); \
+ /* stop any background refresh, and take over */ \
+ m_wallet->stop(); \
+ m_auto_refresh_mutex.lock(); \
+ m_auto_refresh_cond.notify_one(); \
+ m_auto_refresh_mutex.unlock(); \
+ if (auto_refresh_run) \
+ m_auto_refresh_thread.join(); \
+ boost::unique_lock<boost::mutex> lock(m_auto_refresh_mutex); \
+ epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ \
+ m_auto_refresh_run.store(auto_refresh_run, std::memory_order_relaxed); \
+ if (auto_refresh_run) \
+ m_auto_refresh_thread = boost::thread([&]{wallet_refresh_thread();}); \
+ })
+
namespace
{
const command_line::arg_descriptor<std::string> arg_wallet_file = {"wallet-file", sw::tr("Use wallet <arg>"), ""};
@@ -93,10 +110,12 @@ namespace
const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false};
const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", sw::tr("Use daemon instance at port <arg> instead of 18081"), 0};
const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0};
+ const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", "Max number of threads to use for a parallel job", 0};
const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", sw::tr("Specify log file"), ""};
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false};
const command_line::arg_descriptor<bool> arg_trusted_daemon = {"trusted-daemon", sw::tr("Enable commands which rely on a trusted daemon"), false};
+ const command_line::arg_descriptor<uint64_t> arg_restore_height = {"restore-height", sw::tr("Restore from specific blockchain height"), 0};
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
@@ -213,6 +232,44 @@ namespace
return true;
return false;
}
+
+ const struct
+ {
+ const char *name;
+ tools::wallet2::RefreshType refresh_type;
+ } refresh_type_names[] =
+ {
+ { "full", tools::wallet2::RefreshFull },
+ { "optimize-coinbase", tools::wallet2::RefreshOptimizeCoinbase },
+ { "optimized-coinbase", tools::wallet2::RefreshOptimizeCoinbase },
+ { "no-coinbase", tools::wallet2::RefreshNoCoinbase },
+ { "default", tools::wallet2::RefreshDefault },
+ };
+
+ bool parse_refresh_type(const std::string &s, tools::wallet2::RefreshType &refresh_type)
+ {
+ for (size_t n = 0; n < sizeof(refresh_type_names) / sizeof(refresh_type_names[0]); ++n)
+ {
+ if (s == refresh_type_names[n].name)
+ {
+ refresh_type = refresh_type_names[n].refresh_type;
+ return true;
+ }
+ }
+ fail_msg_writer() << tr("failed to parse refresh type");
+ return false;
+ }
+
+ std::string get_refresh_type_name(tools::wallet2::RefreshType type)
+ {
+ for (size_t n = 0; n < sizeof(refresh_type_names) / sizeof(refresh_type_names[0]); ++n)
+ {
+ if (type == refresh_type_names[n].refresh_type)
+ return refresh_type_names[n].name;
+ }
+ return "invalid";
+ }
+
}
@@ -465,32 +522,6 @@ bool simple_wallet::set_auto_refresh(const std::vector<std::string> &args/* = st
return true;
}
-static bool parse_refresh_type(const std::string &s, tools::wallet2::RefreshType &refresh_type)
-{
- static const struct
- {
- const char *name;
- tools::wallet2::RefreshType refresh_type;
- } names[] =
- {
- { "full", tools::wallet2::RefreshFull },
- { "optimize-coinbase", tools::wallet2::RefreshOptimizeCoinbase },
- { "optimized-coinbase", tools::wallet2::RefreshOptimizeCoinbase },
- { "no-coinbase", tools::wallet2::RefreshNoCoinbase },
- { "default", tools::wallet2::RefreshDefault },
- };
- for (size_t n = 0; n < sizeof(names) / sizeof(names[0]); ++n)
- {
- if (s == names[n].name)
- {
- refresh_type = names[n].refresh_type;
- return true;
- }
- }
- fail_msg_writer() << tr("failed to parse refresh type");
- return false;
-}
-
bool simple_wallet::set_refresh_type(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
bool success = false;
@@ -547,6 +578,7 @@ simple_wallet::simple_wallet()
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_unmixable", boost::bind(&simple_wallet::sweep_unmixable, this, _1), tr("Send all unmixable outputs to yourself with mixin 0"));
+ m_cmd_binder.set_handler("sweep_all", boost::bind(&simple_wallet::sweep_all, this, _1), tr("Send all unlocked balance an address"));
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"));
@@ -561,6 +593,8 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("check_tx_key", boost::bind(&simple_wallet::check_tx_key, this, _1), tr("Check amount going to <address> in <txid>"));
m_cmd_binder.set_handler("show_transfers", boost::bind(&simple_wallet::show_transfers, this, _1), tr("show_transfers [in|out] [<min_height> [<max_height>]] - Show incoming/outgoing transfers within an optional height range"));
m_cmd_binder.set_handler("rescan_bc", boost::bind(&simple_wallet::rescan_blockchain, this, _1), tr("Rescan blockchain from scratch"));
+ m_cmd_binder.set_handler("set_tx_note", boost::bind(&simple_wallet::set_tx_note, this, _1), tr("Set an arbitrary string note for a txid"));
+ m_cmd_binder.set_handler("get_tx_note", boost::bind(&simple_wallet::get_tx_note, this, _1), tr("Get a string note for a txid"));
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), tr("Show this help"));
}
//----------------------------------------------------------------------------------------------------
@@ -568,7 +602,12 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
{
if (args.empty())
{
- fail_msg_writer() << tr("set: needs an argument. available options: seed, always-confirm-transfers, default-mixin, auto-refresh, refresh-type");
+ success_msg_writer() << "seed = " << m_wallet->get_seed_language();
+ success_msg_writer() << "always-confirm-transfers = " << m_wallet->always_confirm_transfers();
+ success_msg_writer() << "store-tx-info = " << m_wallet->store_tx_info();
+ success_msg_writer() << "default-mixin = " << m_wallet->default_mixin();
+ success_msg_writer() << "auto-refresh = " << m_wallet->auto_refresh();
+ success_msg_writer() << "refresh-type = " << get_refresh_type_name(m_wallet->get_refresh_type());
return true;
}
else
@@ -829,6 +868,8 @@ 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)
{
+ bool testnet = command_line::get_arg(vm, arg_testnet);
+
std::string buf;
bool r = epee::file_io_utils::load_file_to_string(m_generate_from_json, buf);
if (!r) {
@@ -868,6 +909,11 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m
return false;
}
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
+ crypto::public_key pkey;
+ if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
+ fail_msg_writer() << tr("failed to verify view key secret key");
+ return false;
+ }
}
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, spendkey, std::string, String, false);
@@ -881,6 +927,11 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m
return false;
}
spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
+ crypto::public_key pkey;
+ if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
+ fail_msg_writer() << tr("failed to verify spend key secret key");
+ return false;
+ }
}
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, seed, std::string, String, false);
@@ -896,6 +947,8 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m
m_restore_deterministic_wallet = true;
}
+ GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, address, std::string, String, false);
+
// compatibility checks
if (!field_seed_found && !field_viewkey_found)
{
@@ -908,6 +961,44 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m
return false;
}
+ // if an address was given, we check keys against it, and deduce the spend
+ // public key if it was not given
+ if (field_address_found)
+ {
+ cryptonote::account_public_address address;
+ bool has_payment_id;
+ crypto::hash8 new_payment_id;
+ if(!get_account_integrated_address_from_str(address, has_payment_id, new_payment_id, testnet, field_address))
+ {
+ fail_msg_writer() << tr("invalid address");
+ return false;
+ }
+ if (field_viewkey_found)
+ {
+ crypto::public_key pkey;
+ if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
+ fail_msg_writer() << tr("failed to verify view key secret key");
+ return false;
+ }
+ if (address.m_view_public_key != pkey) {
+ fail_msg_writer() << tr("view key does not match standard address");
+ return false;
+ }
+ }
+ if (field_spendkey_found)
+ {
+ crypto::public_key pkey;
+ if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
+ fail_msg_writer() << tr("failed to verify spend key secret key");
+ return false;
+ }
+ if (address.m_spend_public_key != pkey) {
+ fail_msg_writer() << tr("spend key does not match standard address");
+ return false;
+ }
+ }
+ }
+
m_wallet_file = field_filename;
bool was_deprecated_wallet = m_restore_deterministic_wallet && ((old_language == crypto::ElectrumWords::old_language_name) ||
@@ -917,7 +1008,6 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m
return false;
}
- bool testnet = command_line::get_arg(vm, arg_testnet);
m_wallet.reset(new tools::wallet2(testnet));
m_wallet->callback(this);
@@ -934,17 +1024,27 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m
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 (field_spendkey.empty())
{
+ // if we have an addres but no spend key, we can deduce the spend public key
+ // from the address
+ if (field_address_found)
+ {
+ cryptonote::account_public_address address2;
+ bool has_payment_id;
+ crypto::hash8 new_payment_id;
+ get_account_integrated_address_from_str(address2, has_payment_id, new_payment_id, testnet, field_address);
+ address.m_spend_public_key = address2.m_spend_public_key;
+ }
m_wallet->generate(m_wallet_file, password, address, viewkey);
}
else
{
+ 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;
+ }
m_wallet->generate(m_wallet_file, password, address, spendkey, viewkey);
}
}
@@ -1075,6 +1175,22 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false;
}
}
+ if (!m_restore_height)
+ {
+ std::string heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): ");
+ if (std::cin.eof())
+ return false;
+ if (heightstr.size())
+ {
+ try {
+ m_restore_height = boost::lexical_cast<uint64_t>(heightstr);
+ }
+ catch (boost::bad_lexical_cast &) {
+ fail_msg_writer() << tr("bad m_restore_height parameter:") << " " << heightstr;
+ return false;
+ }
+ }
+ }
if (!m_generate_from_view_key.empty())
{
// parse address
@@ -1245,6 +1361,7 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_restore_deterministic_wallet = command_line::get_arg(vm, arg_restore_deterministic_wallet);
m_non_deterministic = command_line::get_arg(vm, arg_non_deterministic);
m_trusted_daemon = command_line::get_arg(vm, arg_trusted_daemon);
+ m_restore_height = command_line::get_arg(vm, arg_restore_height);
return true;
}
@@ -1349,6 +1466,15 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
}
m_wallet->init(m_daemon_address);
+ // for a totally new account, we don't care about older blocks.
+ if (!m_restore_deterministic_wallet)
+ {
+ std::string err;
+ m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err));
+ } else if (m_restore_height)
+ {
+ m_wallet->set_refresh_from_block_height(m_restore_height);
+ }
// convert rng value to electrum-style word list
std::string electrum_words;
@@ -1396,6 +1522,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
}
m_wallet->init(m_daemon_address);
+ m_wallet->set_refresh_from_block_height(m_restore_height);
return true;
}
@@ -1421,6 +1548,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
}
m_wallet->init(m_daemon_address);
+ m_wallet->set_refresh_from_block_height(m_restore_height);
return true;
}
@@ -1523,6 +1651,7 @@ bool simple_wallet::save(const std::vector<std::string> &args)
{
try
{
+ LOCK_REFRESH_THREAD_SCOPE();
m_wallet->store();
success_msg_writer() << tr("Wallet data saved");
}
@@ -1578,7 +1707,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet());
bool ok = true;
- size_t max_mining_threads_count = (std::max)(boost::thread::hardware_concurrency(), static_cast<unsigned>(2));
+ size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast<unsigned>(2));
if (0 == args.size())
{
req.threads_count = 1;
@@ -1691,12 +1820,7 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset)
if (!try_connect_to_daemon())
return true;
- bool auto_refresh_run = m_auto_refresh_run.load(std::memory_order_relaxed);
- m_auto_refresh_run.store(false, std::memory_order_relaxed);
- // stop any background refresh, and take over
- m_wallet->stop();
- boost::unique_lock<boost::mutex> lock(m_auto_refresh_mutex);
- m_auto_refresh_cond.notify_one();
+ LOCK_REFRESH_THREAD_SCOPE();
if (reset)
m_wallet->rescan_blockchain(false);
@@ -1709,13 +1833,13 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset)
try
{
m_in_manual_refresh.store(true, std::memory_order_relaxed);
+ epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_in_manual_refresh.store(false, std::memory_order_relaxed);});
m_wallet->refresh(start_height, fetched_blocks);
- m_in_manual_refresh.store(false, std::memory_order_relaxed);
ok = true;
// Clear line "Height xxx of xxx"
std::cout << "\r \r";
success_msg_writer(true) << tr("Refresh done, blocks received: ") << fetched_blocks;
- show_balance();
+ show_balance_unlocked();
}
catch (const tools::error::daemon_busy&)
{
@@ -1756,8 +1880,6 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset)
fail_msg_writer() << tr("refresh failed: ") << ss.str() << ". " << tr("Blocks received: ") << fetched_blocks;
}
- m_in_manual_refresh.store(false, std::memory_order_relaxed);
- m_auto_refresh_run.store(auto_refresh_run, std::memory_order_relaxed);
return true;
}
//----------------------------------------------------------------------------------------------------
@@ -1777,15 +1899,24 @@ bool simple_wallet::refresh(const std::vector<std::string>& args)
return refresh_main(start_height, false);
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
+bool simple_wallet::show_balance_unlocked()
{
success_msg_writer() << tr("Balance: ") << print_money(m_wallet->balance()) << ", "
<< tr("unlocked balance: ") << print_money(m_wallet->unlocked_balance());
return true;
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
+{
+ LOCK_REFRESH_THREAD_SCOPE();
+ show_balance_unlocked();
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args)
{
+ LOCK_REFRESH_THREAD_SCOPE();
+
bool filter = false;
bool available = false;
if (!args.empty())
@@ -1851,6 +1982,8 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args)
return true;
}
+ LOCK_REFRESH_THREAD_SCOPE();
+
message_writer() << boost::format("%68s%68s%12s%21s%16s") %
tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time");
@@ -1928,6 +2061,7 @@ bool simple_wallet::rescan_spent(const std::vector<std::string> &args)
try
{
+ LOCK_REFRESH_THREAD_SCOPE();
m_wallet->rescan_spent();
}
catch (const tools::error::daemon_busy&)
@@ -1961,11 +2095,83 @@ bool simple_wallet::rescan_spent(const std::vector<std::string> &args)
return true;
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::get_address_from_str(const std::string &str, cryptonote::account_public_address &address, bool &has_payment_id, crypto::hash8 &payment_id)
+{
+ if(!get_account_integrated_address_from_str(address, has_payment_id, payment_id, m_wallet->testnet(), str))
+ {
+ // if treating as an address fails, try as url
+ bool dnssec_ok = false;
+ std::string url = str;
+
+ // attempt to get address from dns query
+ auto addresses_from_dns = tools::wallet2::addresses_from_url(url, dnssec_ok);
+
+ // for now, move on only if one address found
+ if (addresses_from_dns.size() == 1)
+ {
+ if (get_account_integrated_address_from_str(address, has_payment_id, payment_id, m_wallet->testnet(), addresses_from_dns[0]))
+ {
+ // if it was an address, prompt user for confirmation.
+ // inform user of DNSSEC validation status as well.
+
+ std::string dnssec_str;
+ if (dnssec_ok)
+ {
+ dnssec_str = tr("DNSSEC validation passed");
+ }
+ else
+ {
+ dnssec_str = tr("WARNING: DNSSEC validation was unsuccessful, this address may not be correct!");
+ }
+ std::stringstream prompt;
+ prompt << tr("For URL: ") << url
+ << ", " << dnssec_str << std::endl
+ << tr(" Monero Address = ") << addresses_from_dns[0]
+ << std::endl
+ << tr("Is this OK? (Y/n) ")
+ ;
+
+ // prompt the user for confirmation given the dns query and dnssec status
+ std::string confirm_dns_ok = command_line::input_line(prompt.str());
+ if (std::cin.eof())
+ {
+ return false;
+ }
+ if (confirm_dns_ok != "Y" && confirm_dns_ok != "y" && confirm_dns_ok != "Yes" && confirm_dns_ok != "yes"
+ && confirm_dns_ok != tr("yes") && confirm_dns_ok != tr("no"))
+ {
+ fail_msg_writer() << tr("you have cancelled the transfer request");
+ return false;
+ }
+ }
+ else
+ {
+ fail_msg_writer() << tr("failed to get a Monero address from: ") << url;
+ return false;
+ }
+ }
+ else if (addresses_from_dns.size() > 1)
+ {
+ fail_msg_writer() << tr("not yet supported: Multiple Monero addresses found for given URL: ") << url;
+ return false;
+ }
+ else
+ {
+ fail_msg_writer() << tr("wrong address: ") << url;
+ return false;
+ }
+ }
+
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::transfer_main(bool new_algorithm, const std::vector<std::string> &args_)
{
if (!try_connect_to_daemon())
return true;
+ LOCK_REFRESH_THREAD_SCOPE();
+
std::vector<std::string> local_args = args_;
size_t fake_outs_count;
@@ -2035,69 +2241,8 @@ bool simple_wallet::transfer_main(bool new_algorithm, const std::vector<std::str
cryptonote::tx_destination_entry de;
bool has_payment_id;
crypto::hash8 new_payment_id;
- if(!get_account_integrated_address_from_str(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), local_args[i]))
- {
- // if treating as an address fails, try as url
- bool dnssec_ok = false;
- std::string url = local_args[i];
-
- // attempt to get address from dns query
- auto addresses_from_dns = tools::wallet2::addresses_from_url(url, dnssec_ok);
-
- // for now, move on only if one address found
- if (addresses_from_dns.size() == 1)
- {
- if (get_account_integrated_address_from_str(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), addresses_from_dns[0]))
- {
- // if it was an address, prompt user for confirmation.
- // inform user of DNSSEC validation status as well.
-
- std::string dnssec_str;
- if (dnssec_ok)
- {
- dnssec_str = tr("DNSSEC validation passed");
- }
- else
- {
- dnssec_str = tr("WARNING: DNSSEC validation was unsuccessful, this address may not be correct!");
- }
- std::stringstream prompt;
- prompt << tr("For URL: ") << url
- << ", " << dnssec_str << std::endl
- << tr(" Monero Address = ") << addresses_from_dns[0]
- << std::endl
- << tr("Is this OK? (Y/n) ")
- ;
-
- // prompt the user for confirmation given the dns query and dnssec status
- std::string confirm_dns_ok = command_line::input_line(prompt.str());
- if (std::cin.eof())
- {
- return true;
- }
- if (confirm_dns_ok != "Y" && confirm_dns_ok != "y" && confirm_dns_ok != "Yes" && confirm_dns_ok != "yes"
- && confirm_dns_ok != tr("yes") && confirm_dns_ok != tr("no"))
- {
- fail_msg_writer() << tr("you have cancelled the transfer request");
- return true;
- }
- }
- else
- {
- fail_msg_writer() << tr("failed to get a Monero address from: ") << local_args[i];
- return true;
- }
- }
- else if (addresses_from_dns.size() > 1)
- {
- fail_msg_writer() << tr("not yet supported: Multiple Monero addresses found for given URL: ") << url;
- }
- else
- {
- fail_msg_writer() << tr("wrong address: ") << local_args[i];
- return true;
- }
- }
+ if (!get_address_from_str(local_args[i], de.addr, has_payment_id, new_payment_id))
+ return true;
if (has_payment_id)
{
@@ -2133,32 +2278,44 @@ bool simple_wallet::transfer_main(bool new_algorithm, const std::vector<std::str
// figure out what tx will be necessary
std::vector<tools::wallet2::pending_tx> ptx_vector;
if (new_algorithm)
- ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra);
+ ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra, m_trusted_daemon);
else
- ptx_vector = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra);
+ ptx_vector = m_wallet->create_transactions(dsts, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra, m_trusted_daemon);
// if more than one tx necessary, prompt user to confirm
if (m_wallet->always_confirm_transfers() || ptx_vector.size() > 1)
{
uint64_t total_fee = 0;
+ uint64_t dust_not_in_fee = 0;
+ uint64_t dust_in_fee = 0;
for (size_t n = 0; n < ptx_vector.size(); ++n)
{
total_fee += ptx_vector[n].fee;
+
+ if (ptx_vector[n].dust_added_to_fee)
+ dust_in_fee += ptx_vector[n].dust;
+ else
+ dust_not_in_fee += ptx_vector[n].dust;
}
- std::string prompt_str;
+ std::stringstream prompt;
if (ptx_vector.size() > 1)
{
- prompt_str = (boost::format(tr("Your transaction needs to be split into %llu transactions. "
- "This will result in a transaction fee being applied to each transaction, for a total fee of %s. Is this okay? (Y/Yes/N/No)")) %
- ((unsigned long long)ptx_vector.size()) % print_money(total_fee)).str();
+ prompt << boost::format(tr("Your transaction needs to be split into %llu transactions. "
+ "This will result in a transaction fee being applied to each transaction, for a total fee of %s")) %
+ ((unsigned long long)ptx_vector.size()) % print_money(total_fee);
}
else
{
- prompt_str = (boost::format(tr("The transaction fee is %s. Is this okay? (Y/Yes/N/No)")) %
- print_money(total_fee)).str();
+ prompt << boost::format(tr("The transaction fee is %s")) %
+ print_money(total_fee);
}
- std::string accepted = command_line::input_line(prompt_str);
+ if (dust_in_fee != 0) prompt << boost::format(tr(", of which %s is dust from change")) % print_money(dust_in_fee);
+ if (dust_not_in_fee != 0) prompt << tr(".") << ENDL << boost::format(tr("A total of %s from dust change will be sent to dust address"))
+ % print_money(dust_not_in_fee);
+ prompt << tr(".") << ENDL << tr("Is this okay? (Y/Yes/N/No)");
+
+ std::string accepted = command_line::input_line(prompt.str());
if (std::cin.eof())
return true;
if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
@@ -2285,6 +2442,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
return true;
}
+ LOCK_REFRESH_THREAD_SCOPE();
try
{
// figure out what tx will be necessary
@@ -2425,6 +2583,238 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
return true;
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
+{
+ if (!try_connect_to_daemon())
+ return true;
+
+ if(m_wallet->watch_only())
+ {
+ fail_msg_writer() << tr("this is a watch only wallet");
+ return true;
+ }
+
+ std::vector<std::string> local_args = args_;
+
+ size_t fake_outs_count;
+ if(local_args.size() > 0) {
+ if(!epee::string_tools::get_xtype_from_string(fake_outs_count, local_args[0]))
+ {
+ fake_outs_count = m_wallet->default_mixin();
+ if (fake_outs_count == 0)
+ fake_outs_count = DEFAULT_MIX;
+ }
+ else
+ {
+ local_args.erase(local_args.begin());
+ }
+ }
+
+ std::vector<uint8_t> extra;
+ bool payment_id_seen = false;
+ if (2 == local_args.size())
+ {
+ std::string payment_id_str = local_args.back();
+ local_args.pop_back();
+
+ crypto::hash payment_id;
+ bool r = tools::wallet2::parse_long_payment_id(payment_id_str, payment_id);
+ if(r)
+ {
+ std::string extra_nonce;
+ set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
+ r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
+ }
+ else
+ {
+ crypto::hash8 payment_id8;
+ r = tools::wallet2::parse_short_payment_id(payment_id_str, payment_id8);
+ if(r)
+ {
+ std::string extra_nonce;
+ set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, payment_id8);
+ r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
+ }
+ }
+
+ if(!r)
+ {
+ fail_msg_writer() << tr("payment id has invalid format, expected 16 or 64 character hex string: ") << payment_id_str;
+ return true;
+ }
+ payment_id_seen = true;
+ }
+
+ if (local_args.size() == 0)
+ {
+ fail_msg_writer() << tr("No address given");
+ return true;
+ }
+
+ bool has_payment_id;
+ crypto::hash8 new_payment_id;
+ cryptonote::account_public_address address;
+ if (!get_address_from_str(local_args[0], address, has_payment_id, new_payment_id))
+ return true;
+
+ if (has_payment_id)
+ {
+ if (payment_id_seen)
+ {
+ fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[0];
+ return true;
+ }
+
+ std::string extra_nonce;
+ set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, new_payment_id);
+ bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
+ if(!r)
+ {
+ fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
+ return true;
+ }
+ }
+
+ try
+ {
+ // figure out what tx will be necessary
+ auto ptx_vector = m_wallet->create_transactions_all(address, fake_outs_count, 0 /* unlock_time */, 0 /* unused fee arg*/, extra, m_trusted_daemon);
+
+ if (ptx_vector.empty())
+ {
+ fail_msg_writer() << tr("No outputs found");
+ return true;
+ }
+
+ // give user total and fee, and prompt to confirm
+ uint64_t total_fee = 0, total_sent = 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_sent += boost::get<txin_to_key>(vin).amount;
+ }
+ }
+
+ std::string prompt_str;
+ 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_sent) %
+ ((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_sent) %
+ print_money(total_fee)).str();
+ }
+ std::string accepted = command_line::input_line(prompt_str);
+ if (std::cin.eof())
+ return true;
+ if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
+ {
+ fail_msg_writer() << tr("transaction cancelled.");
+
+ // would like to return false, because no tx made, but everything else returns true
+ // and I don't know what returning false might adversely affect. *sigh*
+ return true;
+ }
+
+ // actually commit the transactions
+ while (!ptx_vector.empty())
+ {
+ auto & ptx = ptx_vector.back();
+ m_wallet->commit_tx(ptx);
+ success_msg_writer(true) << tr("Money successfully sent, transaction: ") << get_transaction_hash(ptx.tx);
+
+ // if no exception, remove element from vector
+ ptx_vector.pop_back();
+ }
+ }
+ catch (const tools::error::daemon_busy&)
+ {
+ fail_msg_writer() << tr("daemon is busy. Please try again later.");
+ }
+ catch (const tools::error::no_connection_to_daemon&)
+ {
+ fail_msg_writer() << tr("no connection to daemon. Please make sure daemon is running.");
+ }
+ catch (const tools::error::wallet_rpc_error& e)
+ {
+ LOG_ERROR("RPC error: " << e.to_string());
+ fail_msg_writer() << tr("RPC error: ") << e.what();
+ }
+ catch (const tools::error::get_random_outs_error&)
+ {
+ fail_msg_writer() << tr("failed to get random outputs to mix");
+ }
+ 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).\n%s")) %
+ print_money(e.available()) %
+ print_money(e.tx_amount() + e.fee()) %
+ print_money(e.tx_amount()) %
+ 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)
+ {
+ auto writer = fail_msg_writer();
+ writer << tr("not enough outputs for specified mixin_count") << " = " << e.mixin_count() << ":";
+ for (const cryptonote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& outs_for_amount : e.scanty_outs())
+ {
+ writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.amount) << ", " << tr("found outputs to mix") << " = " << outs_for_amount.outs.size();
+ }
+ }
+ catch (const tools::error::tx_not_constructed&)
+ {
+ fail_msg_writer() << tr("transaction was not constructed");
+ }
+ catch (const tools::error::tx_rejected& e)
+ {
+ fail_msg_writer() << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
+ std::string reason = e.reason();
+ if (!reason.empty())
+ fail_msg_writer() << tr("Reason: ") << reason;
+ }
+ catch (const tools::error::tx_sum_overflow& e)
+ {
+ fail_msg_writer() << e.what();
+ }
+ catch (const tools::error::zero_destination&)
+ {
+ fail_msg_writer() << tr("one of destinations is zero");
+ }
+ catch (const tools::error::tx_too_big& e)
+ {
+ fail_msg_writer() << tr("failed to find a suitable way to split transactions");
+ }
+ catch (const tools::error::transfer_error& e)
+ {
+ LOG_ERROR("unknown transfer error: " << e.to_string());
+ fail_msg_writer() << tr("unknown transfer error: ") << e.what();
+ }
+ catch (const tools::error::wallet_internal_error& e)
+ {
+ LOG_ERROR("internal error: " << e.to_string());
+ fail_msg_writer() << tr("internal error: ") << e.what();
+ }
+ catch (const std::exception& e)
+ {
+ LOG_ERROR("unexpected error: " << e.what());
+ fail_msg_writer() << tr("unexpected error: ") << e.what();
+ }
+ catch (...)
+ {
+ LOG_ERROR("unknown error");
+ fail_msg_writer() << tr("unknown error");
+ }
+
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
{
std::vector<std::string> local_args = args_;
@@ -2442,6 +2832,8 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
}
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
+ LOCK_REFRESH_THREAD_SCOPE();
+
crypto::secret_key tx_key;
bool r = m_wallet->get_tx_key(txid, tx_key);
if (r)
@@ -2476,6 +2868,8 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
}
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
+ LOCK_REFRESH_THREAD_SCOPE();
+
cryptonote::blobdata tx_key_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(local_args[1], tx_key_data))
{
@@ -2497,13 +2891,18 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
COMMAND_RPC_GET_TRANSACTIONS::response res;
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
if (!net_utils::invoke_http_json_remote_command2(m_daemon_address + "/gettransactions", req, res, m_http_client) ||
- res.txs_as_hex.empty())
+ (res.txs.empty() && res.txs_as_hex.empty()))
{
fail_msg_writer() << tr("failed to get transaction from daemon");
return true;
}
cryptonote::blobdata tx_data;
- if (!string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data))
+ bool ok;
+ if (!res.txs.empty())
+ ok = string_tools::parse_hexstr_to_binbuff(res.txs.front().as_hex, tx_data);
+ else
+ ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
+ if (!ok)
{
fail_msg_writer() << tr("failed to parse transaction from daemon");
return true;
@@ -2560,6 +2959,23 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
return true;
}
//----------------------------------------------------------------------------------------------------
+static std::string get_human_readable_timestamp(uint64_t ts)
+{
+ char buffer[64];
+ if (ts < 1234567890)
+ return "<unknown>";
+ time_t tt = ts;
+ struct tm tm;
+ gmtime_r(&tt, &tm);
+ uint64_t now = time(NULL);
+ uint64_t diff = ts > now ? ts - now : now - ts;
+ if (diff > 24*3600)
+ strftime(buffer, sizeof(buffer), "%F", &tm);
+ else
+ strftime(buffer, sizeof(buffer), "%r", &tm);
+ return std::string(buffer);
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
{
std::vector<std::string> local_args = args_;
@@ -2575,6 +2991,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
return true;
}
+ LOCK_REFRESH_THREAD_SCOPE();
+
// optional in/out selector
if (local_args.size() > 0) {
if (local_args[0] == "in" || local_args[0] == "incoming") {
@@ -2632,7 +3050,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
std::string payment_id = string_tools::pod_to_hex(i->first);
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16);
- output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%20.20s %s %s %s") % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % "-").str())));
+ std::string note = m_wallet->get_tx_note(pd.m_tx_hash);
+ output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%16.16s %20.20s %s %s %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % "-" % note).str())));
}
}
@@ -2652,7 +3071,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16);
- output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%20.20s %s %s %14.14s %s") % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests).str())));
+ std::string note = m_wallet->get_tx_note(i->first);
+ output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%16.16s %20.20s %s %s %14.14s %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests % note).str())));
}
}
@@ -2675,9 +3095,10 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16);
+ std::string note = m_wallet->get_tx_note(i->first);
bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
if ((failed && is_failed) || (!is_failed && pending)) {
- message_writer() << (boost::format("%8.8s %6.6s %20.20s %s %s %14.14s") % (is_failed ? tr("failed") : tr("pending")) % tr("out") % print_money(amount - pd.m_change) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee)).str();
+ message_writer() << (boost::format("%8.8s %6.6s %16.16s %20.20s %s %s %14.14s %s") % (is_failed ? tr("failed") : tr("pending")) % tr("out") % get_human_readable_timestamp(pd.m_timestamp) % print_money(amount - pd.m_change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % note).str();
}
}
}
@@ -2729,7 +3150,12 @@ bool simple_wallet::run()
void simple_wallet::stop()
{
m_cmd_binder.stop_handling();
+
+ m_auto_refresh_run.store(false, std::memory_order_relaxed);
m_wallet->stop();
+ // make the background refresh thread quit
+ boost::unique_lock<boost::mutex> lock(m_auto_refresh_mutex);
+ m_auto_refresh_cond.notify_one();
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
@@ -2780,6 +3206,59 @@ bool simple_wallet::print_integrated_address(const std::vector<std::string> &arg
return true;
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::set_tx_note(const std::vector<std::string> &args)
+{
+ if (args.size() == 0)
+ {
+ fail_msg_writer() << tr("usage: set_tx_note [txid] free text note");
+ return true;
+ }
+
+ cryptonote::blobdata txid_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(args.front(), txid_data))
+ {
+ fail_msg_writer() << tr("failed to parse txid");
+ return false;
+ }
+ crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
+
+ std::string note = "";
+ for (size_t n = 1; n < args.size(); ++n)
+ {
+ if (n > 1)
+ note += " ";
+ note += args[n];
+ }
+ m_wallet->set_tx_note(txid, note);
+
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
+bool simple_wallet::get_tx_note(const std::vector<std::string> &args)
+{
+ if (args.size() != 1)
+ {
+ fail_msg_writer() << tr("usage: get_tx_note [txid]");
+ return true;
+ }
+
+ cryptonote::blobdata txid_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(args.front(), txid_data))
+ {
+ fail_msg_writer() << tr("failed to parse txid");
+ return false;
+ }
+ crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
+
+ std::string note = m_wallet->get_tx_note(txid);
+ if (note.empty())
+ success_msg_writer() << "no note found";
+ else
+ success_msg_writer() << "note found: " << note;
+
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::process_command(const std::vector<std::string> &args)
{
return m_cmd_binder.process_command_vec(args);
@@ -2807,6 +3286,7 @@ int main(int argc, char* argv[])
std::string lang = i18n_get_language();
tools::sanitize_locale();
+ tools::set_strict_default_file_permissions(true);
string_tools::set_module_name_and_folder(argv[0]);
@@ -2827,6 +3307,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_daemon_port);
command_line::add_arg(desc_params, arg_command);
command_line::add_arg(desc_params, arg_log_level);
+ command_line::add_arg(desc_params, arg_max_concurrency);
bf::path default_log {log_space::log_singletone::get_default_log_folder()};
std::string log_file_name = log_space::log_singletone::get_default_log_file();
@@ -2854,6 +3335,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_testnet);
command_line::add_arg(desc_params, arg_restricted);
command_line::add_arg(desc_params, arg_trusted_daemon);
+ command_line::add_arg(desc_params, arg_restore_height);
tools::wallet_rpc_server::init_options(desc_params);
po::positional_options_description positional_options;
@@ -2911,6 +3393,9 @@ int main(int argc, char* argv[])
LOG_LEVEL_4
);
+ if(command_line::has_arg(vm, arg_max_concurrency))
+ tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
+
message_writer(epee::log_space::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
if(command_line::has_arg(vm, arg_log_level))
@@ -2963,12 +3448,25 @@ int main(int argc, char* argv[])
}
tools::wallet2 wal(testnet,restricted);
+ bool quit = false;
+ tools::signal_handler::install([&wal, &quit](int) {
+ quit = true;
+ wal.stop();
+ });
try
{
LOG_PRINT_L0(sw::tr("Loading wallet..."));
wal.load(wallet_file, password);
wal.init(daemon_address);
wal.refresh();
+ // if we ^C during potentially length load/refresh, there's no server loop yet
+ if (quit)
+ {
+ LOG_PRINT_L0(sw::tr("Storing wallet..."));
+ wal.store();
+ LOG_PRINT_GREEN(sw::tr("Stored ok"), LOG_LEVEL_0);
+ return 1;
+ }
LOG_PRINT_GREEN(sw::tr("Loaded ok"), LOG_LEVEL_0);
}
catch (const std::exception& e)
@@ -2979,10 +3477,8 @@ int main(int argc, char* argv[])
tools::wallet_rpc_server wrpc(wal);
bool r = wrpc.init(vm);
CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet rpc server"));
-
tools::signal_handler::install([&wrpc, &wal](int) {
wrpc.send_stop_signal();
- wal.store();
});
LOG_PRINT_L0(sw::tr("Starting wallet rpc server"));
wrpc.run();
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 21bbfa566..0c69f0440 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -114,6 +114,7 @@ namespace cryptonote
bool stop_mining(const std::vector<std::string> &args);
bool save_bc(const std::vector<std::string>& args);
bool refresh(const std::vector<std::string> &args);
+ bool show_balance_unlocked();
bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
bool show_incoming_transfers(const std::vector<std::string> &args);
bool show_payments(const std::vector<std::string> &args);
@@ -121,6 +122,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_all(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
@@ -137,10 +139,13 @@ namespace cryptonote
bool show_transfers(const std::vector<std::string> &args);
bool rescan_blockchain(const std::vector<std::string> &args);
bool refresh_main(uint64_t start_height, bool reset = false);
+ bool set_tx_note(const std::vector<std::string> &args);
+ bool get_tx_note(const std::vector<std::string> &args);
uint64_t get_daemon_blockchain_height(std::string& err);
bool try_connect_to_daemon();
bool ask_wallet_create_if_needed();
+ bool get_address_from_str(const std::string &str, cryptonote::account_public_address &address, bool &has_payment_id, crypto::hash8 &payment_id);
/*!
* \brief Prints the seed with a nice message
@@ -231,6 +236,7 @@ namespace cryptonote
bool m_restore_deterministic_wallet; // recover flag
bool m_non_deterministic; // old 2-random generation
bool m_trusted_daemon;
+ uint64_t m_restore_height; // optional
std::string m_daemon_address;
std::string m_daemon_host;
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index a9a65535f..dd83891df 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -73,6 +73,7 @@ using namespace cryptonote;
#define KILL_IOSERVICE() \
do { \
work.reset(); \
+ while (!ioservice.stopped()) ioservice.poll(); \
threadpool.join_all(); \
ioservice.stop(); \
} while(0)
@@ -183,7 +184,7 @@ void wallet2::check_acc_out(const account_keys &acc, const tx_out &o, const cryp
error = false;
}
//----------------------------------------------------------------------------------------------------
-void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_t height, bool miner_tx)
+void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_t height, uint64_t ts, bool miner_tx)
{
if (!miner_tx)
process_unconfirmed(tx, height);
@@ -212,7 +213,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
tx_pub_key = pub_key_field.pub_key;
bool r = true;
- int threads = boost::thread::hardware_concurrency();
+ int threads = tools::get_max_concurrency();
if (miner_tx && m_refresh_type == RefreshNoCoinbase)
{
// assume coinbase isn't for us
@@ -408,7 +409,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
if (tx_money_spent_in_ins > 0)
{
- process_outgoing(tx, height, tx_money_spent_in_ins, tx_money_got_in_outs);
+ process_outgoing(tx, height, ts, tx_money_spent_in_ins, tx_money_got_in_outs);
}
uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
@@ -458,6 +459,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
payment.m_amount = received;
payment.m_block_height = height;
payment.m_unlock_time = tx.unlock_time;
+ payment.m_timestamp = ts;
m_payments.emplace(payment_id, payment);
LOG_PRINT_L2("Payment found: " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount);
}
@@ -481,7 +483,7 @@ void wallet2::process_unconfirmed(const cryptonote::transaction& tx, uint64_t he
}
}
//----------------------------------------------------------------------------------------------------
-void wallet2::process_outgoing(const cryptonote::transaction &tx, uint64_t height, uint64_t spent, uint64_t received)
+void wallet2::process_outgoing(const cryptonote::transaction &tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received)
{
crypto::hash txid = get_transaction_hash(tx);
confirmed_transfer_details &ctd = m_confirmed_txs[txid];
@@ -491,6 +493,7 @@ void wallet2::process_outgoing(const cryptonote::transaction &tx, uint64_t heigh
ctd.m_amount_out = get_outs_money_amount(tx);
ctd.m_change = received;
ctd.m_block_height = height;
+ ctd.m_timestamp = ts;
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const crypto::hash& bl_id, uint64_t height)
@@ -501,7 +504,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
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);
+ process_new_transaction(b.miner_tx, height, b.timestamp, true);
TIME_MEASURE_FINISH(miner_tx_handle_time);
TIME_MEASURE_START(txs_handle_time);
@@ -510,7 +513,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
cryptonote::transaction tx;
bool r = parse_and_validate_tx_from_blob(txblob, tx);
THROW_WALLET_EXCEPTION_IF(!r, error::tx_parse_error, txblob);
- process_new_transaction(tx, height, false);
+ process_new_transaction(tx, height, b.timestamp, false);
}
TIME_MEASURE_FINISH(txs_handle_time);
LOG_PRINT_L2("Processed block: " << bl_id << ", height " << height << ", " << miner_tx_handle_time + txs_handle_time << "(" << miner_tx_handle_time << "/" << txs_handle_time <<")ms");
@@ -577,12 +580,30 @@ void wallet2::pull_blocks(uint64_t start_height, uint64_t &blocks_start_height,
blocks = res.blocks;
}
//----------------------------------------------------------------------------------------------------
+void wallet2::pull_hashes(uint64_t start_height, uint64_t &blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<crypto::hash> &hashes)
+{
+ cryptonote::COMMAND_RPC_GET_HASHES_FAST::request req = AUTO_VAL_INIT(req);
+ cryptonote::COMMAND_RPC_GET_HASHES_FAST::response res = AUTO_VAL_INIT(res);
+ req.block_ids = short_chain_history;
+
+ req.start_height = start_height;
+ m_daemon_rpc_mutex.lock();
+ bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/gethashes.bin", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
+ m_daemon_rpc_mutex.unlock();
+ THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "gethashes.bin");
+ THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "gethashes.bin");
+ THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_hashes_error, res.status);
+
+ blocks_start_height = res.start_height;
+ hashes = res.m_block_ids;
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, uint64_t& blocks_added)
{
size_t current_index = start_height;
blocks_added = 0;
- int threads = boost::thread::hardware_concurrency();
+ int threads = tools::get_max_concurrency();
if (threads > 1)
{
std::vector<crypto::hash> round_block_hashes(threads);
@@ -771,6 +792,60 @@ void wallet2::check_pending_txes()
}
}
//----------------------------------------------------------------------------------------------------
+void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history)
+{
+ std::list<crypto::hash> hashes;
+ size_t current_index = m_blockchain.size();
+ while(current_index < stop_height)
+ {
+ pull_hashes(0, blocks_start_height, short_chain_history, hashes);
+ if (hashes.size() < 3)
+ return;
+ if (hashes.size() + current_index < stop_height) {
+ std::list<crypto::hash>::iterator right;
+ // drop early 3 off, skipping the genesis block
+ if (short_chain_history.size() > 3) {
+ right = short_chain_history.end();
+ std::advance(right,-1);
+ std::list<crypto::hash>::iterator left = right;
+ std::advance(left, -3);
+ short_chain_history.erase(left, right);
+ }
+ right = hashes.end();
+ // prepend 3 more
+ for (int i = 0; i<3; i++) {
+ right--;
+ short_chain_history.push_front(*right);
+ }
+ }
+ current_index = blocks_start_height;
+ BOOST_FOREACH(auto& bl_id, hashes)
+ {
+ if(current_index >= m_blockchain.size())
+ {
+ LOG_PRINT_L2( "Skipped block by height: " << current_index);
+ m_blockchain.push_back(bl_id);
+ ++m_local_bc_height;
+
+ if (0 != m_callback)
+ { // FIXME: this isn't right, but simplewallet just logs that we got a block.
+ cryptonote::block dummy;
+ m_callback->on_new_block(current_index, dummy);
+ }
+ }
+ else if(bl_id != m_blockchain[current_index])
+ {
+ //split detected here !!!
+ return;
+ }
+ ++current_index;
+ if (current_index >= stop_height)
+ return;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------------------------------
void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money)
{
received_money = false;
@@ -785,7 +860,22 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re
// pull the first set of blocks
get_short_chain_history(short_chain_history);
+ if (start_height > m_blockchain.size() || m_refresh_from_block_height > m_blockchain.size()) {
+ if (!start_height)
+ start_height = m_refresh_from_block_height;
+ // we can shortcut by only pulling hashes up to the start_height
+ fast_refresh(start_height, blocks_start_height, short_chain_history);
+ // regenerate the history now that we've got a full set of hashes
+ short_chain_history.clear();
+ get_short_chain_history(short_chain_history);
+ start_height = 0;
+ // and then fall through to regular refresh processing
+ }
+
pull_blocks(start_height, blocks_start_height, short_chain_history, blocks);
+ // always reset start_height to 0 to force short_chain_ history to be used on
+ // subsequent pulls in this refresh.
+ start_height = 0;
m_run.store(true, std::memory_order_relaxed);
while(m_run.load(std::memory_order_relaxed))
@@ -1749,47 +1839,12 @@ namespace
// returns:
// direct return: amount of money found
// modified reference: selected_transfers, a list of iterators/indices of input sources
-uint64_t wallet2::select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, bool hf2_rules, std::list<transfer_container::iterator>& selected_transfers)
+uint64_t wallet2::select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::list<transfer_container::iterator>& selected_transfers, bool trusted_daemon)
{
- std::vector<size_t> unused_transfers_indices;
- std::vector<size_t> unused_dust_indices;
-
- // aggregate sources available for transfers
- // if dust needed, take dust from only one source (so require source has at least dust amount)
- for (size_t i = 0; i < m_transfers.size(); ++i)
- {
- const transfer_details& td = m_transfers[i];
- if (!td.m_spent && is_transfer_unlocked(td))
- {
- if (dust < td.amount() && is_valid_decomposed_amount(td.amount()))
- unused_transfers_indices.push_back(i);
- else
- {
- // for hf2 rules, we disregard dust, which will be spendable only
- // via sweep_dust. If we're asked to add dust, though, we still
- // consider them, as this will be a mixin 0 tx (and thus we may
- // end up with a tx with one mixable output and N dusty ones).
- // This should be made better at some point...
- if (!hf2_rules || add_dust)
- unused_dust_indices.push_back(i);
- }
- }
- }
-
- bool select_one_dust = add_dust && !unused_dust_indices.empty();
uint64_t found_money = 0;
- while (found_money < needed_money && (!unused_transfers_indices.empty() || !unused_dust_indices.empty()))
+ while (found_money < needed_money && !unused_transfers_indices.empty())
{
- size_t idx;
- if (select_one_dust)
- {
- idx = pop_random_value(unused_dust_indices);
- select_one_dust = false;
- }
- else
- {
- idx = !unused_transfers_indices.empty() ? pop_random_value(unused_transfers_indices) : pop_random_value(unused_dust_indices);
- }
+ size_t idx = pop_random_value(unused_transfers_indices);
transfer_container::iterator it = m_transfers.begin() + idx;
selected_transfers.push_back(it);
@@ -1808,21 +1863,22 @@ void wallet2::add_unconfirmed_tx(const cryptonote::transaction& tx, const std::v
utd.m_dests = dests;
utd.m_payment_id = payment_id;
utd.m_state = wallet2::unconfirmed_transfer_details::pending;
+ utd.m_timestamp = time(NULL);
}
//----------------------------------------------------------------------------------------------------
-void wallet2::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)
+void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outs_count, const std::vector<size_t> &unused_transfers_indices,
+ uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx& ptx, bool trusted_daemon)
{
- transfer(dsts, fake_outputs_count, unlock_time, fee, extra, detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), tx, ptx);
+ transfer(dsts, fake_outs_count, unused_transfers_indices, unlock_time, fee, extra, detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), tx, ptx, trusted_daemon);
}
//----------------------------------------------------------------------------------------------------
-void wallet2::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 wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outs_count, const std::vector<size_t> &unused_transfers_indices,
+ uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, bool trusted_daemon)
{
cryptonote::transaction tx;
pending_tx ptx;
- transfer(dsts, fake_outputs_count, unlock_time, fee, extra, tx, ptx);
+ transfer(dsts, fake_outs_count, unused_transfers_indices, unlock_time, fee, extra, tx, ptx, trusted_daemon);
}
namespace {
@@ -1974,6 +2030,7 @@ void wallet2::commit_tx(pending_tx& ptx)
COMMAND_RPC_SEND_RAW_TX::request req;
req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(ptx.tx));
+ req.do_not_relay = false;
COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp;
m_daemon_rpc_mutex.lock();
bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000);
@@ -1999,8 +2056,9 @@ void wallet2::commit_tx(pending_tx& ptx)
BOOST_FOREACH(transfer_container::iterator it, ptx.selected_transfers)
it->m_spent = true;
+ //fee includes dust if dust policy specified it.
LOG_PRINT_L0("Transaction successfully sent. <" << txid << ">" << ENDL
- << "Commission: " << print_money(ptx.fee+ptx.dust) << " (dust: " << print_money(ptx.dust) << ")" << ENDL
+ << "Commission: " << print_money(ptx.fee) << " (dust sent to dust addr: " << print_money((ptx.dust_added_to_fee ? 0 : ptx.dust)) << ")" << ENDL
<< "Balance: " << print_money(balance()) << ENDL
<< "Unlocked: " << print_money(unlocked_balance()) << ENDL
<< "Please, wait for confirmation for your balance to be unlocked.");
@@ -2019,8 +2077,9 @@ void wallet2::commit_tx(std::vector<pending_tx>& ptx_vector)
//
// this function will make multiple calls to wallet2::transfer if multiple
// transactions will be required
-std::vector<wallet2::pending_tx> wallet2::create_transactions(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<wallet2::pending_tx> wallet2::create_transactions(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, bool trusted_daemon)
{
+ const std::vector<size_t> unused_transfers_indices = select_available_outputs_from_histogram(fake_outs_count + 1, true, trusted_daemon);
// failsafe split attempt counter
size_t attempt_count = 0;
@@ -2050,7 +2109,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
uint64_t needed_fee = 0;
do
{
- transfer(dst_vector, fake_outs_count, unlock_time, needed_fee, extra, tx, ptx);
+ transfer(dst_vector, fake_outs_count, unused_transfers_indices, unlock_time, needed_fee, extra, tx, ptx, trusted_daemon);
auto txBlob = t_serializable_object_to_blob(ptx.tx);
needed_fee = calculate_fee(txBlob);
} while (ptx.fee < needed_fee);
@@ -2257,10 +2316,17 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
return true;
});
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
+
+
+ bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key
+ || dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key);
+
+ if (dust_policy.add_to_fee || dust_sent_elsewhere) change_dts.amount -= dust;
ptx.key_images = key_images;
- ptx.fee = fee;
- ptx.dust = dust;
+ ptx.fee = (dust_policy.add_to_fee ? fee+dust : fee);
+ ptx.dust = ((dust_policy.add_to_fee || dust_sent_elsewhere) ? dust : 0);
+ ptx.dust_added_to_fee = dust_policy.add_to_fee;
ptx.tx = tx;
ptx.change_dts = change_dts;
ptx.selected_transfers = selected_transfers;
@@ -2283,7 +2349,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
// This system allows for sending (almost) the entire balance, since it does
// not generate spurious change in all txes, thus decreasing the instantaneous
// usable balance.
-std::vector<wallet2::pending_tx> wallet2::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<wallet2::pending_tx> wallet2::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, bool trusted_daemon)
{
std::vector<size_t> unused_transfers_indices;
std::vector<size_t> unused_dust_indices;
@@ -2425,7 +2491,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
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);
needed_fee = calculate_fee(txBlob);
- available_for_fee = test_ptx.fee + test_ptx.change_dts.amount;
+ available_for_fee = test_ptx.fee + test_ptx.change_dts.amount + (!test_ptx.dust_added_to_fee ? test_ptx.dust : 0);
LOG_PRINT_L2("Made a " << txBlob.size() << " kB tx, with " << print_money(available_for_fee) << " available for fee (" <<
print_money(needed_fee) << " needed)");
@@ -2507,6 +2573,133 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
return ptx_vector;
}
+std::vector<wallet2::pending_tx> wallet2::create_transactions_all(const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee_UNUSED, const std::vector<uint8_t> extra, bool trusted_daemon)
+{
+ std::vector<size_t> unused_transfers_indices;
+ std::vector<size_t> unused_dust_indices;
+ uint64_t accumulated_fee, accumulated_outputs, accumulated_change;
+ struct TX {
+ std::list<transfer_container::iterator> selected_transfers;
+ std::vector<cryptonote::tx_destination_entry> dsts;
+ cryptonote::transaction tx;
+ pending_tx ptx;
+ size_t bytes;
+ };
+ std::vector<TX> txes;
+ uint64_t needed_fee, available_for_fee = 0;
+ uint64_t upper_transaction_size_limit = get_upper_tranaction_size_limit();
+
+ // gather all our dust and non dust outputs
+ for (size_t i = 0; i < m_transfers.size(); ++i)
+ {
+ const transfer_details& td = m_transfers[i];
+ if (!td.m_spent && is_transfer_unlocked(td))
+ {
+ if (is_valid_decomposed_amount(td.amount()))
+ unused_transfers_indices.push_back(i);
+ else
+ unused_dust_indices.push_back(i);
+ }
+ }
+ LOG_PRINT_L2("Starting with " << unused_transfers_indices.size() << " non-dust outputs and " << unused_dust_indices.size() << " dust outputs");
+
+ // start with an empty tx
+ txes.push_back(TX());
+ accumulated_fee = 0;
+ accumulated_outputs = 0;
+ accumulated_change = 0;
+ needed_fee = 0;
+
+ // while we have something to send
+ while (!unused_dust_indices.empty() || !unused_transfers_indices.empty()) {
+ TX &tx = txes.back();
+
+ // get a random unspent output and use it to pay next chunk. We try to alternate
+ // dust and non dust to ensure we never get with only dust, from which we might
+ // get a tx that can't pay for itself
+ size_t idx = unused_transfers_indices.empty() ? pop_random_value(unused_dust_indices) : unused_dust_indices.empty() ? pop_random_value(unused_transfers_indices) : ((tx.selected_transfers.size() & 1) || accumulated_outputs > FEE_PER_KB * (upper_transaction_size_limit + 1023) / 1024) ? pop_random_value(unused_dust_indices) : pop_random_value(unused_transfers_indices);
+
+ const transfer_details &td = m_transfers[idx];
+ LOG_PRINT_L2("Picking output " << idx << ", amount " << print_money(td.amount()));
+
+ // add this output to the list to spend
+ tx.selected_transfers.push_back(m_transfers.begin() + idx);
+ uint64_t available_amount = td.amount();
+ accumulated_outputs += available_amount;
+
+ // here, check if we need to sent tx and start a new one
+ LOG_PRINT_L2("Considering whether to create a tx now, " << tx.selected_transfers.size() << " inputs, tx limit "
+ << upper_transaction_size_limit);
+ bool try_tx = (unused_dust_indices.empty() && unused_transfers_indices.empty()) || (tx.selected_transfers.size() * (fake_outs_count+1) * APPROXIMATE_INPUT_BYTES >= TX_SIZE_TARGET(upper_transaction_size_limit));
+
+ if (try_tx) {
+ cryptonote::transaction test_tx;
+ pending_tx test_ptx;
+
+ needed_fee = 0;
+
+ tx.dsts.push_back(tx_destination_entry(1, address));
+
+ LOG_PRINT_L2("Trying to create a tx now, with " << tx.dsts.size() << " destinations and " <<
+ tx.selected_transfers.size() << " outputs");
+ 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);
+ needed_fee = calculate_fee(txBlob);
+ available_for_fee = test_ptx.fee + test_ptx.dests[0].amount + test_ptx.change_dts.amount;
+ LOG_PRINT_L2("Made a " << txBlob.size() << " kB tx, with " << print_money(available_for_fee) << " available for fee (" <<
+ print_money(needed_fee) << " needed)");
+
+ THROW_WALLET_EXCEPTION_IF(needed_fee > available_for_fee, error::wallet_internal_error, "Transaction cannot pay for itself");
+
+ do {
+ LOG_PRINT_L2("We made a tx, adjusting fee and saving it");
+ tx.dsts[0].amount = available_for_fee - needed_fee;
+ 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);
+ txBlob = t_serializable_object_to_blob(test_ptx.tx);
+ needed_fee = calculate_fee(txBlob);
+ LOG_PRINT_L2("Made an attempt at a final " << ((txBlob.size() + 1023)/1024) << " kB tx, with " << print_money(test_ptx.fee) <<
+ " fee and " << print_money(test_ptx.change_dts.amount) << " change");
+ } while (needed_fee > test_ptx.fee);
+
+ LOG_PRINT_L2("Made a final " << ((txBlob.size() + 1023)/1024) << " kB tx, with " << print_money(test_ptx.fee) <<
+ " fee and " << print_money(test_ptx.change_dts.amount) << " change");
+
+ tx.tx = test_tx;
+ tx.ptx = test_ptx;
+ tx.bytes = txBlob.size();
+ accumulated_fee += test_ptx.fee;
+ accumulated_change += test_ptx.change_dts.amount;
+ if (!unused_transfers_indices.empty() || !unused_dust_indices.empty())
+ {
+ LOG_PRINT_L2("We have more to pay, starting another tx");
+ txes.push_back(TX());
+ }
+ }
+ }
+
+ LOG_PRINT_L1("Done creating " << txes.size() << " transactions, " << print_money(accumulated_fee) <<
+ " total fee, " << print_money(accumulated_change) << " total change");
+
+ std::vector<wallet2::pending_tx> ptx_vector;
+ for (std::vector<TX>::iterator i = txes.begin(); i != txes.end(); ++i)
+ {
+ TX &tx = *i;
+ uint64_t tx_money = 0;
+ for (std::list<transfer_container::iterator>::const_iterator mi = tx.selected_transfers.begin(); mi != tx.selected_transfers.end(); ++mi)
+ tx_money += (*mi)->amount();
+ LOG_PRINT_L1(" Transaction " << (1+std::distance(txes.begin(), i)) << "/" << txes.size() <<
+ ": " << (tx.bytes+1023)/1024 << " kB, sending " << print_money(tx_money) << " in " << tx.selected_transfers.size() <<
+ " outputs to " << tx.dsts.size() << " destination(s), including " <<
+ print_money(tx.ptx.fee) << " fee, " << print_money(tx.ptx.change_dts.amount) << " change");
+ ptx_vector.push_back(tx.ptx);
+ }
+
+ // if we made it this far, we're OK to actually send the transactions
+ return ptx_vector;
+}
+
uint64_t wallet2::unlocked_dust_balance(const tx_dust_policy &dust_policy) const
{
uint64_t money = 0;
@@ -2703,9 +2896,8 @@ std::vector<uint64_t> wallet2::get_unspent_amounts_vector()
return vector;
}
//----------------------------------------------------------------------------------------------------
-std::vector<size_t> wallet2::select_available_unmixable_outputs(bool trusted_daemon)
+std::vector<size_t> wallet2::select_available_outputs_from_histogram(uint64_t count, bool atleast, 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();
@@ -2714,7 +2906,7 @@ std::vector<size_t> wallet2::select_available_unmixable_outputs(bool trusted_dae
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.min_count = count;
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();
@@ -2728,14 +2920,32 @@ std::vector<size_t> wallet2::select_available_unmixable_outputs(bool trusted_dae
mixable.insert(i.amount);
}
- return select_available_outputs([mixable](const transfer_details &td) {
+ return select_available_outputs([mixable, atleast](const transfer_details &td) {
const uint64_t amount = td.amount();
- if (mixable.find(amount) == mixable.end())
- return true;
+ if (atleast) {
+ if (mixable.find(amount) != mixable.end())
+ return true;
+ }
+ else {
+ if (mixable.find(amount) == mixable.end())
+ return true;
+ }
return false;
});
}
//----------------------------------------------------------------------------------------------------
+std::vector<size_t> wallet2::select_available_unmixable_outputs(bool trusted_daemon)
+{
+ // request all outputs with less than 3 instances
+ return select_available_outputs_from_histogram(3, false, trusted_daemon);
+}
+//----------------------------------------------------------------------------------------------------
+std::vector<size_t> wallet2::select_available_mixable_outputs(bool trusted_daemon)
+{
+ // request all outputs with at least 3 instances, so we can use mixin 2 with
+ return select_available_outputs_from_histogram(3, true, trusted_daemon);
+}
+//----------------------------------------------------------------------------------------------------
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
@@ -2861,6 +3071,19 @@ std::string wallet2::get_keys_file() const
return m_keys_file;
}
+void wallet2::set_tx_note(const crypto::hash &txid, const std::string &note)
+{
+ m_tx_notes[txid] = note;
+}
+
+std::string wallet2::get_tx_note(const crypto::hash &txid) const
+{
+ std::unordered_map<crypto::hash, std::string>::const_iterator i = m_tx_notes.find(txid);
+ if (i == m_tx_notes.end())
+ return std::string();
+ return i->second;
+}
+
//----------------------------------------------------------------------------------------------------
void wallet2::generate_genesis(cryptonote::block& b) {
if (m_testnet)
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index b6466d3f6..846a86ef8 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -110,6 +110,7 @@ namespace tools
uint64_t m_amount;
uint64_t m_block_height;
uint64_t m_unlock_time;
+ uint64_t m_timestamp;
};
struct unconfirmed_transfer_details
@@ -120,6 +121,7 @@ namespace tools
std::vector<cryptonote::tx_destination_entry> m_dests;
crypto::hash m_payment_id;
enum { pending, pending_not_in_pool, failed } m_state;
+ uint64_t m_timestamp;
};
struct confirmed_transfer_details
@@ -130,10 +132,11 @@ namespace tools
uint64_t m_block_height;
std::vector<cryptonote::tx_destination_entry> m_dests;
crypto::hash m_payment_id;
+ uint64_t m_timestamp;
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(cryptonote::null_hash) {}
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height):
- m_amount_out(get_outs_money_amount(utd.m_tx)), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id) { get_inputs_money_amount(utd.m_tx, m_amount_in); }
+ m_amount_out(get_outs_money_amount(utd.m_tx)), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id), m_timestamp(utd.m_timestamp) { get_inputs_money_amount(utd.m_tx, m_amount_in); }
};
typedef std::vector<transfer_details> transfer_container;
@@ -143,6 +146,7 @@ namespace tools
{
cryptonote::transaction tx;
uint64_t dust, fee;
+ bool dust_added_to_fee;
cryptonote::tx_destination_entry change_dts;
std::list<transfer_container::iterator> selected_transfers;
std::string key_images;
@@ -274,11 +278,11 @@ namespace tools
uint64_t unlocked_balance() const;
uint64_t unlocked_dust_balance(const tx_dust_policy &dust_policy) const;
template<typename T>
- void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy);
+ void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, bool trusted_daemon);
template<typename T>
- void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx& ptx);
- 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);
+ void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, 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, bool trusted_daemon);
+ void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, bool trusted_daemon);
+ void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx& ptx, bool trusted_daemon);
template<typename T>
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>
@@ -287,8 +291,9 @@ namespace tools
void commit_tx(pending_tx& ptx_vector);
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_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, bool trusted_daemon);
+ 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, bool trusted_daemon);
+ std::vector<wallet2::pending_tx> create_transactions_all(const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee_UNUSED, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
bool check_connection();
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
@@ -324,6 +329,9 @@ namespace tools
if(ver < 11)
return;
a & m_refresh_from_block_height;
+ if(ver < 12)
+ return;
+ a & m_tx_notes;
}
/*!
@@ -364,6 +372,15 @@ namespace tools
std::string get_wallet_file() const;
std::string get_keys_file() const;
+
+ std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool trusted_daemon);
+ 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);
+ std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon);
+
+ void set_tx_note(const crypto::hash &txid, const std::string &note);
+ std::string get_tx_note(const crypto::hash &txid) const;
+
private:
/*!
* \brief Stores wallet information to wallet file.
@@ -379,7 +396,7 @@ namespace tools
* \param password Password of wallet file
*/
bool load_keys(const std::string& keys_file_name, const std::string& password);
- void process_new_transaction(const cryptonote::transaction& tx, uint64_t height, bool miner_tx);
+ void process_new_transaction(const cryptonote::transaction& tx, uint64_t height, uint64_t ts, bool miner_tx);
void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const crypto::hash& bl_id, uint64_t height);
void detach_blockchain(uint64_t height);
void get_short_chain_history(std::list<crypto::hash>& ids) const;
@@ -387,12 +404,14 @@ namespace tools
bool is_transfer_unlocked(const transfer_details& td) const;
bool clear();
void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<cryptonote::block_complete_entry> &blocks);
+ void pull_hashes(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<crypto::hash> &hashes);
+ void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history);
void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::list<cryptonote::block_complete_entry> &prev_blocks, std::list<cryptonote::block_complete_entry> &blocks, bool &error);
void process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, uint64_t& blocks_added);
- uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, bool hf2_rules, std::list<transfer_container::iterator>& selected_transfers);
+ uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::list<transfer_container::iterator>& selected_transfers, bool trusted_daemon);
bool prepare_file_names(const std::string& file_path);
void process_unconfirmed(const cryptonote::transaction& tx, uint64_t height);
- void process_outgoing(const cryptonote::transaction& tx, uint64_t height, uint64_t spent, uint64_t received);
+ void process_outgoing(const cryptonote::transaction& tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received);
void add_unconfirmed_tx(const cryptonote::transaction& tx, const std::vector<cryptonote::tx_destination_entry> &dests, const crypto::hash &payment_id, uint64_t change_amount);
void generate_genesis(cryptonote::block& b);
void check_genesis(const crypto::hash& genesis_hash) const; //throws
@@ -403,8 +422,6 @@ namespace tools
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;
@@ -421,6 +438,7 @@ namespace tools
payment_container m_payments;
std::unordered_map<crypto::key_image, size_t> m_key_images;
cryptonote::account_public_address m_account_public_address;
+ std::unordered_map<crypto::hash, std::string> m_tx_notes;
uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
std::atomic<bool> m_run;
@@ -441,10 +459,10 @@ namespace tools
uint64_t m_refresh_from_block_height;
};
}
-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)
+BOOST_CLASS_VERSION(tools::wallet2, 12)
+BOOST_CLASS_VERSION(tools::wallet2::payment_details, 1)
+BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 3)
+BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 2)
namespace boost
{
@@ -474,6 +492,9 @@ namespace boost
if (ver < 2)
return;
a & x.m_state;
+ if (ver < 3)
+ return;
+ a & x.m_timestamp;
}
template <class Archive>
@@ -487,6 +508,9 @@ namespace boost
return;
a & x.m_dests;
a & x.m_payment_id;
+ if (ver < 2)
+ return;
+ a & x.m_timestamp;
}
template <class Archive>
@@ -496,6 +520,9 @@ namespace boost
a & x.m_amount;
a & x.m_block_height;
a & x.m_unlock_time;
+ if (ver < 1)
+ return;
+ a & x.m_timestamp;
}
template <class Archive>
@@ -562,17 +589,17 @@ namespace tools
}
//----------------------------------------------------------------------------------------------------
template<typename T>
- void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count,
- uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy)
+ void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outs_count, const std::vector<size_t> &unused_transfers_indices,
+ uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, bool trusted_daemon)
{
pending_tx ptx;
cryptonote::transaction tx;
- transfer(dsts, fake_outputs_count, unlock_time, fee, extra, destination_split_strategy, dust_policy, tx, ptx);
+ transfer(dsts, fake_outs_count, unused_transfers_indices, unlock_time, fee, extra, destination_split_strategy, dust_policy, tx, ptx, trusted_daemon);
}
template<typename T>
- void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count,
- uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx)
+ void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices,
+ 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, bool trusted_daemon)
{
using namespace cryptonote;
// throw if attempting a transaction with no destinations
@@ -593,9 +620,7 @@ namespace tools
// randomly select inputs for transaction
// throw if requested send amount is greater than amount available to send
std::list<transfer_container::iterator> selected_transfers;
- bool hf2_rules = use_fork_rules(2); // first fork has version 2
- const bool add_dust = (0 == fake_outputs_count) && hf2_rules;
- uint64_t found_money = select_transfers(needed_money, add_dust, dust_policy.dust_threshold, hf2_rules, selected_transfers);
+ uint64_t found_money = select_transfers(needed_money, unused_transfers_indices, selected_transfers, trusted_daemon);
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;
@@ -711,10 +736,16 @@ namespace tools
return true;
});
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
+
+ bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key
+ || dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key);
+
+ if (dust_policy.add_to_fee || dust_sent_elsewhere) change_dts.amount -= dust;
ptx.key_images = key_images;
- ptx.fee = fee;
- ptx.dust = dust;
+ ptx.fee = (dust_policy.add_to_fee ? fee+dust : fee);
+ ptx.dust = ((dust_policy.add_to_fee || dust_sent_elsewhere) ? dust : 0);
+ ptx.dust_added_to_fee = dust_policy.add_to_fee;
ptx.tx = tx;
ptx.change_dts = change_dts;
ptx.selected_transfers = selected_transfers;
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 3de97f49d..184d8a2a1 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -60,6 +60,7 @@ namespace tools
// acc_outs_lookup_error
// block_parse_error
// get_blocks_error
+ // get_hashes_error
// get_out_indexes_error
// tx_parse_error
// get_tx_pool_error
@@ -107,12 +108,14 @@ namespace tools
//----------------------------------------------------------------------------------------------------
const char* const failed_rpc_request_messages[] = {
"failed to get blocks",
+ "failed to get hashes",
"failed to get out indices",
"failed to get random outs"
};
enum failed_rpc_request_message_indices
{
get_blocks_error_message_index,
+ get_hashes_error_message_index,
get_out_indices_error_message_index,
get_random_outs_error_message_index
};
@@ -291,6 +294,8 @@ namespace tools
//----------------------------------------------------------------------------------------------------
typedef failed_rpc_request<refresh_error, get_blocks_error_message_index> get_blocks_error;
//----------------------------------------------------------------------------------------------------
+ typedef failed_rpc_request<refresh_error, get_hashes_error_message_index> get_hashes_error;
+ //----------------------------------------------------------------------------------------------------
typedef failed_rpc_request<refresh_error, get_out_indices_error_message_index> get_out_indices_error;
//----------------------------------------------------------------------------------------------------
struct tx_parse_error : public refresh_error
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index d7d99c2ae..a082f731b 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -232,7 +232,7 @@ namespace tools
LOG_PRINT_L1("Requested mixin " << req.mixin << " too low for hard fork 2, using 2");
mixin = 2;
}
- std::vector<wallet2::pending_tx> ptx_vector = m_wallet.create_transactions(dsts, mixin, req.unlock_time, req.fee, extra);
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet.create_transactions(dsts, mixin, req.unlock_time, req.fee, extra, req.trusted_daemon);
// reject proposed transactions if there are more than one. see on_transfer_split below.
if (ptx_vector.size() != 1)
@@ -299,9 +299,9 @@ namespace tools
}
std::vector<wallet2::pending_tx> ptx_vector;
if (req.new_algorithm)
- ptx_vector = m_wallet.create_transactions_2(dsts, mixin, req.unlock_time, req.fee, extra);
+ ptx_vector = m_wallet.create_transactions_2(dsts, mixin, req.unlock_time, req.fee, extra, req.trusted_daemon);
else
- ptx_vector = m_wallet.create_transactions(dsts, mixin, req.unlock_time, req.fee, extra);
+ ptx_vector = m_wallet.create_transactions(dsts, mixin, req.unlock_time, req.fee, extra, req.trusted_daemon);
m_wallet.commit_tx(ptx_vector);
@@ -382,6 +382,65 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_sweep_all(const wallet_rpc::COMMAND_RPC_SWEEP_ALL::request& req, wallet_rpc::COMMAND_RPC_SWEEP_ALL::response& res, epee::json_rpc::error& er)
+ {
+ std::vector<cryptonote::tx_destination_entry> dsts;
+ std::vector<uint8_t> extra;
+
+ if (m_wallet.restricted())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_DENIED;
+ er.message = "Command unavailable in restricted mode.";
+ return false;
+ }
+
+ // validate the transfer requested and populate dsts & extra
+ std::list<wallet_rpc::transfer_destination> destination;
+ destination.push_back(wallet_rpc::transfer_destination());
+ destination.back().amount = 0;
+ destination.back().address = req.address;
+ if (!validate_transfer(destination, req.payment_id, dsts, extra, er))
+ {
+ return false;
+ }
+
+ try
+ {
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet.create_transactions_all(dsts[0].addr, req.mixin, req.unlock_time, req.fee, extra, req.trusted_daemon);
+
+ m_wallet.commit_tx(ptx_vector);
+
+ // populate response with tx hashes
+ for (auto & ptx : ptx_vector)
+ {
+ res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx)));
+ if (req.get_tx_keys)
+ res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
+ }
+
+ return true;
+ }
+ catch (const tools::error::daemon_busy& e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY;
+ er.message = e.what();
+ return false;
+ }
+ catch (const std::exception& e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
+ er.message = e.what();
+ return false;
+ }
+ catch (...)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR";
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er)
{
try
@@ -711,5 +770,164 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_set_tx_notes(const wallet_rpc::COMMAND_RPC_SET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_SET_TX_NOTES::response& res, epee::json_rpc::error& er)
+ {
+ if (req.txids.size() != req.notes.size())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Different amount of txids and notes";
+ return false;
+ }
+
+ std::list<crypto::hash> txids;
+ std::list<std::string>::const_iterator i = req.txids.begin();
+ while (i != req.txids.end())
+ {
+ cryptonote::blobdata txid_blob;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(*i++, txid_blob))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_TXID;
+ er.message = "TX ID has invalid format";
+ return false;
+ }
+
+ crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_blob.data());
+ txids.push_back(txid);
+ }
+
+ std::list<crypto::hash>::const_iterator il = txids.begin();
+ std::list<std::string>::const_iterator in = req.notes.begin();
+ while (il != txids.end())
+ {
+ m_wallet.set_tx_note(*il++, *in++);
+ }
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_get_tx_notes(const wallet_rpc::COMMAND_RPC_GET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_GET_TX_NOTES::response& res, epee::json_rpc::error& er)
+ {
+ res.notes.clear();
+
+ std::list<crypto::hash> txids;
+ std::list<std::string>::const_iterator i = req.txids.begin();
+ while (i != req.txids.end())
+ {
+ cryptonote::blobdata txid_blob;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(*i++, txid_blob))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_TXID;
+ er.message = "TX ID has invalid format";
+ return false;
+ }
+
+ crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_blob.data());
+ txids.push_back(txid);
+ }
+
+ std::list<crypto::hash>::const_iterator il = txids.begin();
+ while (il != txids.end())
+ {
+ res.notes.push_back(m_wallet.get_tx_note(*il++));
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_get_transfers(const wallet_rpc::COMMAND_RPC_GET_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_GET_TRANSFERS::response& res, epee::json_rpc::error& er)
+ {
+ if (m_wallet.restricted())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_DENIED;
+ er.message = "Command unavailable in restricted mode.";
+ return false;
+ }
+
+ uint64_t min_height = 0, max_height = (uint64_t)-1;
+ if (req.filter_by_height)
+ {
+ min_height = req.min_height;
+ max_height = req.max_height;
+ }
+
+ if (req.in)
+ {
+ std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
+ m_wallet.get_payments(payments, min_height, max_height);
+ for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
+ res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry());
+ wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back();
+ const tools::wallet2::payment_details &pd = i->second;
+
+ entry.txid = string_tools::pod_to_hex(pd.m_tx_hash);
+ entry.payment_id = string_tools::pod_to_hex(i->first);
+ if (entry.payment_id.substr(16).find_first_not_of('0') == std::string::npos)
+ entry.payment_id = entry.payment_id.substr(0,16);
+ entry.height = pd.m_block_height;
+ entry.timestamp = pd.m_timestamp;
+ entry.amount = pd.m_amount;
+ entry.fee = 0; // TODO
+ entry.note = m_wallet.get_tx_note(pd.m_tx_hash);
+ }
+ }
+
+ if (req.out)
+ {
+ std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> payments;
+ m_wallet.get_payments_out(payments, min_height, max_height);
+ for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
+ res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry());
+ wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back();
+ const tools::wallet2::confirmed_transfer_details &pd = i->second;
+
+ entry.txid = string_tools::pod_to_hex(i->first);
+ entry.payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
+ if (entry.payment_id.substr(16).find_first_not_of('0') == std::string::npos)
+ entry.payment_id = entry.payment_id.substr(0,16);
+ entry.height = pd.m_block_height;
+ entry.timestamp = pd.m_timestamp;
+ entry.fee = pd.m_amount_in - pd.m_amount_out;
+ uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known
+ entry.amount = pd.m_amount_in - change - entry.fee;
+ entry.note = m_wallet.get_tx_note(i->first);
+
+ for (const auto &d: pd.m_dests) {
+ entry.destinations.push_back(wallet_rpc::transfer_destination());
+ wallet_rpc::transfer_destination &td = entry.destinations.back();
+ td.amount = d.amount;
+ td.address = get_account_address_as_str(m_wallet.testnet(), d.addr);
+ }
+ }
+ }
+
+ if (req.pending || req.failed) {
+ std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments;
+ m_wallet.get_unconfirmed_payments_out(upayments);
+ for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) {
+ const tools::wallet2::unconfirmed_transfer_details &pd = i->second;
+ bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
+ if (!((req.failed && is_failed) || (!is_failed && req.pending)))
+ continue;
+ std::list<wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry> &entries = is_failed ? res.failed : res.pending;
+ entries.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry());
+ wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = entries.back();
+
+ entry.txid = string_tools::pod_to_hex(i->first);
+ entry.payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
+ entry.payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
+ if (entry.payment_id.substr(16).find_first_not_of('0') == std::string::npos)
+ entry.payment_id = entry.payment_id.substr(0,16);
+ entry.height = 0;
+ entry.timestamp = pd.m_timestamp;
+ uint64_t amount = 0;
+ cryptonote::get_inputs_money_amount(pd.m_tx, amount);
+ entry.fee = amount - get_outs_money_amount(pd.m_tx);
+ entry.amount = amount - pd.m_change - entry.fee;
+ entry.note = m_wallet.get_tx_note(i->first);
+ }
+ }
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
}
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 6b41df8fb..8c90aecfe 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -67,6 +67,7 @@ namespace tools
MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER)
MAP_JON_RPC_WE("transfer_split", on_transfer_split, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT)
MAP_JON_RPC_WE("sweep_dust", on_sweep_dust, wallet_rpc::COMMAND_RPC_SWEEP_DUST)
+ MAP_JON_RPC_WE("sweep_all", on_sweep_all, wallet_rpc::COMMAND_RPC_SWEEP_ALL)
MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE)
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS)
MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS)
@@ -76,6 +77,9 @@ namespace tools
MAP_JON_RPC_WE("split_integrated_address", on_split_integrated_address, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS)
MAP_JON_RPC_WE("stop_wallet", on_stop_wallet, wallet_rpc::COMMAND_RPC_STOP_WALLET)
MAP_JON_RPC_WE("rescan_blockchain", on_rescan_blockchain, wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN)
+ MAP_JON_RPC_WE("set_tx_notes", on_set_tx_notes, wallet_rpc::COMMAND_RPC_SET_TX_NOTES)
+ MAP_JON_RPC_WE("get_tx_notes", on_get_tx_notes, wallet_rpc::COMMAND_RPC_GET_TX_NOTES)
+ MAP_JON_RPC_WE("get_transfers", on_get_transfers, wallet_rpc::COMMAND_RPC_GET_TRANSFERS)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -87,6 +91,7 @@ namespace tools
bool on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er);
bool on_transfer_split(const wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::request& req, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::response& res, epee::json_rpc::error& er);
bool on_sweep_dust(const wallet_rpc::COMMAND_RPC_SWEEP_DUST::request& req, wallet_rpc::COMMAND_RPC_SWEEP_DUST::response& res, epee::json_rpc::error& er);
+ bool on_sweep_all(const wallet_rpc::COMMAND_RPC_SWEEP_ALL::request& req, wallet_rpc::COMMAND_RPC_SWEEP_ALL::response& res, epee::json_rpc::error& er);
bool on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er);
bool on_split_integrated_address(const wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er);
bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er);
@@ -95,6 +100,9 @@ namespace tools
bool on_incoming_transfers(const wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::response& res, epee::json_rpc::error& er);
bool on_stop_wallet(const wallet_rpc::COMMAND_RPC_STOP_WALLET::request& req, wallet_rpc::COMMAND_RPC_STOP_WALLET::response& res, epee::json_rpc::error& er);
bool on_rescan_blockchain(const wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN::request& req, wallet_rpc::COMMAND_RPC_RESCAN_BLOCKCHAIN::response& res, epee::json_rpc::error& er);
+ bool on_set_tx_notes(const wallet_rpc::COMMAND_RPC_SET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_SET_TX_NOTES::response& res, epee::json_rpc::error& er);
+ bool on_get_tx_notes(const wallet_rpc::COMMAND_RPC_GET_TX_NOTES::request& req, wallet_rpc::COMMAND_RPC_GET_TX_NOTES::response& res, epee::json_rpc::error& er);
+ bool on_get_transfers(const wallet_rpc::COMMAND_RPC_GET_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_GET_TRANSFERS::response& res, epee::json_rpc::error& er);
bool handle_command_line(const boost::program_options::variables_map& vm);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 2c4e26406..f8c04c007 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -115,6 +115,7 @@ namespace wallet_rpc
uint64_t unlock_time;
std::string payment_id;
bool get_tx_key;
+ bool trusted_daemon;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(destinations)
@@ -123,6 +124,7 @@ namespace wallet_rpc
KV_SERIALIZE(unlock_time)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(get_tx_key)
+ KV_SERIALIZE(trusted_daemon)
END_KV_SERIALIZE_MAP()
};
@@ -149,6 +151,7 @@ namespace wallet_rpc
std::string payment_id;
bool new_algorithm;
bool get_tx_keys;
+ bool trusted_daemon;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(destinations)
@@ -158,6 +161,7 @@ namespace wallet_rpc
KV_SERIALIZE(payment_id)
KV_SERIALIZE(new_algorithm)
KV_SERIALIZE(get_tx_keys)
+ KV_SERIALIZE(trusted_daemon)
END_KV_SERIALIZE_MAP()
};
@@ -198,6 +202,41 @@ namespace wallet_rpc
};
};
+ struct COMMAND_RPC_SWEEP_ALL
+ {
+ struct request
+ {
+ std::string address;
+ uint64_t fee;
+ uint64_t mixin;
+ uint64_t unlock_time;
+ std::string payment_id;
+ bool get_tx_keys;
+ bool trusted_daemon;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(address)
+ KV_SERIALIZE(fee)
+ KV_SERIALIZE(mixin)
+ KV_SERIALIZE(unlock_time)
+ KV_SERIALIZE(payment_id)
+ KV_SERIALIZE(get_tx_keys)
+ KV_SERIALIZE(trusted_daemon)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::list<std::string> tx_hash_list;
+ std::list<std::string> tx_key_list;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(tx_hash_list)
+ KV_SERIALIZE(tx_key_list)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
struct COMMAND_RPC_STORE
{
struct request
@@ -408,6 +447,110 @@ namespace wallet_rpc
};
};
+ struct COMMAND_RPC_SET_TX_NOTES
+ {
+ struct request
+ {
+ std::list<std::string> txids;
+ std::list<std::string> notes;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(txids)
+ KV_SERIALIZE(notes)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
+ struct COMMAND_RPC_GET_TX_NOTES
+ {
+ struct request
+ {
+ std::list<std::string> txids;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(txids)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::list<std::string> notes;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(notes)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
+ struct COMMAND_RPC_GET_TRANSFERS
+ {
+ struct request
+ {
+ bool in;
+ bool out;
+ bool pending;
+ bool failed;
+
+ bool filter_by_height;
+ uint64_t min_height;
+ uint64_t max_height;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(in);
+ KV_SERIALIZE(out);
+ KV_SERIALIZE(pending);
+ KV_SERIALIZE(failed);
+ KV_SERIALIZE(filter_by_height);
+ KV_SERIALIZE(min_height);
+ KV_SERIALIZE(max_height);
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct entry
+ {
+ std::string txid;
+ std::string payment_id;
+ uint64_t height;
+ uint64_t timestamp;
+ uint64_t amount;
+ uint64_t fee;
+ std::string note;
+ std::list<transfer_destination> destinations;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(txid);
+ KV_SERIALIZE(payment_id);
+ KV_SERIALIZE(height);
+ KV_SERIALIZE(timestamp);
+ KV_SERIALIZE(amount);
+ KV_SERIALIZE(fee);
+ KV_SERIALIZE(note);
+ KV_SERIALIZE(destinations);
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::list<entry> in;
+ std::list<entry> out;
+ std::list<entry> pending;
+ std::list<entry> failed;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(in);
+ KV_SERIALIZE(out);
+ KV_SERIALIZE(pending);
+ KV_SERIALIZE(failed);
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
}
}
diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h
index 063421d80..968836671 100644
--- a/src/wallet/wallet_rpc_server_error_codes.h
+++ b/src/wallet/wallet_rpc_server_error_codes.h
@@ -38,3 +38,4 @@
#define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5
#define WALLET_RPC_ERROR_CODE_TRANSFER_TYPE -6
#define WALLET_RPC_ERROR_CODE_DENIED -7
+#define WALLET_RPC_ERROR_CODE_WRONG_TXID -8
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index 44170d116..652413b8a 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -470,13 +470,15 @@ inline bool replay_events_through_core(cryptonote::core& cr, const std::vector<t
CATCH_ENTRY_L0("replay_events_through_core", false);
}
//--------------------------------------------------------------------------
-template<class t_test_class>
+template<typename t_test_class>
struct get_test_options {
- const std::pair<uint8_t, uint64_t> hard_forks[1] = {std::make_pair((uint8_t)1, (uint64_t)0)};
+ const std::pair<uint8_t, uint64_t> hard_forks[1];
const cryptonote::test_options test_options = {
hard_forks
};
+ get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0)}{}
};
+
//--------------------------------------------------------------------------
template<class t_test_class>
inline bool do_replay_events(std::vector<test_event_entry>& events)
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index 3c3cf3a90..6bf910101 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -85,7 +85,8 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor,
try
{
tools::wallet2::pending_tx ptx;
- w1.transfer(dsts, mix_in_factor, 0, TEST_FEE, std::vector<uint8_t>(), tools::detail::null_split_strategy, tools::tx_dust_policy(TEST_DUST_THRESHOLD), tx, ptx);
+ std::vector<size_t> indices = w1.select_available_outputs([](const tools::wallet2::transfer_details&) { return true; });
+ w1.transfer(dsts, mix_in_factor, indices, 0, TEST_FEE, std::vector<uint8_t>(), tools::detail::null_split_strategy, tools::tx_dust_policy(TEST_DUST_THRESHOLD), tx, ptx, true);
w1.commit_tx(ptx);
return true;
}
diff --git a/tests/unit_tests/unbound.cpp b/tests/unit_tests/unbound.cpp
index 25026ec58..666f68127 100644
--- a/tests/unit_tests/unbound.cpp
+++ b/tests/unit_tests/unbound.cpp
@@ -30,6 +30,8 @@
#include "gtest/gtest.h"
+#ifdef STATICLIB
+
extern "C" int dnskey_algo_id_is_supported(int);
TEST(unbound, supported_algorithms)
@@ -47,3 +49,5 @@ TEST(unbound, supported_algorithms)
ASSERT_TRUE(dnskey_algo_id_is_supported(13));
}
+#endif
+