aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md44
-rw-r--r--contrib/epee/src/CMakeLists.txt10
-rw-r--r--src/common/unordered_containers_boost_serialization.h6
-rw-r--r--src/cryptonote_core/blockchain.cpp3
-rw-r--r--src/cryptonote_core/blockchain.h1
-rw-r--r--src/cryptonote_core/cryptonote_boost_serialization.h1
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp11
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.cpp33
-rw-r--r--src/cryptonote_core/miner.cpp3
-rw-r--r--src/cryptonote_core/tx_pool.cpp8
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp1
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl14
-rw-r--r--src/daemon/rpc_command_executor.cpp1
-rw-r--r--src/p2p/connection_basic.cpp1
-rw-r--r--src/p2p/net_node.h1
-rw-r--r--src/p2p/net_node.inl4
-rw-r--r--src/p2p/net_peerlist.h10
-rw-r--r--src/p2p/network_throttle-detail.cpp1
-rw-r--r--src/p2p/network_throttle.hpp1
-rw-r--r--src/p2p/p2p_protocol_defs.h2
-rw-r--r--src/ringct/rctTypes.h2
-rw-r--r--src/rpc/core_rpc_server.cpp15
-rw-r--r--src/wallet/api/wallet.cpp130
-rw-r--r--src/wallet/api/wallet.h6
-rw-r--r--src/wallet/api/wallet_manager.cpp16
-rw-r--r--src/wallet/api/wallet_manager.h7
-rw-r--r--src/wallet/wallet2.cpp46
-rw-r--r--src/wallet/wallet2.h16
-rw-r--r--src/wallet/wallet2_api.h21
-rw-r--r--src/wallet/wallet_rpc_server.cpp2
30 files changed, 321 insertions, 96 deletions
diff --git a/README.md b/README.md
index a6a57da2b..436e8398d 100644
--- a/README.md
+++ b/README.md
@@ -385,6 +385,50 @@ If you want to help out, see CONTRIBUTING for a set of guidelines.
This section contains general instructions for debugging failed installs or problems encountered with Monero. First ensure you are running the latest version built from the github repo.
+## Obtaining Stack Traces and Core Dumps on Unix Systems
+
+We generally use the tool `gdb` (GNU debugger) to provide stack trace functionality, and `ulimit` to provide core dumps in builds which crash or segfault.
+
+* To use gdb in order to obtain a stack trace for a build that has stalled:
+
+Run the build.
+
+Once it stalls, enter the following command:
+
+```
+gdb /path/to/monerod `pidof monerod`
+```
+
+Type `thread apply all bt` within gdb in order to obtain the stack trace
+
+* If however the core dumps or segfaults:
+
+Enter `ulimit -c unlimited` on the command line to enable unlimited filesizes for core dumps
+
+Run the build.
+
+When it terminates with an output along the lines of "Segmentation fault (core dumped)", there should be a core dump file in the same directory as monerod.
+
+You can now analyse this core dump with `gdb` as follows:
+
+`gdb /path/to/monerod /path/to/dumpfile`
+
+Print the stack trace with `bt`
+
+* To run monero within gdb:
+
+Type `gdb /path/to/monerod`
+
+Pass command-line options with `--args` followed by the relevant arguments
+
+Type `run` to run monerod
+
+## Analysing Memory Corruption
+
+We use the tool `valgrind` for this.
+
+Run with `valgrind /path/to/monerod`. It will be slow.
+
## LMDB
Instructions for debugging suspected blockchain corruption as per @HYC
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 8bc512893..93c9a94f7 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -27,3 +27,13 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_library(epee STATIC http_auth.cpp mlog.cpp)
+# Build and install libepee if we're building for GUI
+if (BUILD_GUI_DEPS)
+ if(IOS)
+ set(lib_folder lib-${ARCH})
+ else()
+ set(lib_folder lib)
+ endif()
+ install(TARGETS epee
+ ARCHIVE DESTINATION ${lib_folder})
+endif() \ No newline at end of file
diff --git a/src/common/unordered_containers_boost_serialization.h b/src/common/unordered_containers_boost_serialization.h
index 08b5d9ccf..b2d5b27a6 100644
--- a/src/common/unordered_containers_boost_serialization.h
+++ b/src/common/unordered_containers_boost_serialization.h
@@ -43,7 +43,7 @@ namespace boost
{
size_t s = x.size();
a << s;
- BOOST_FOREACH(auto& v, x)
+ for(auto& v: x)
{
a << v.first;
a << v.second;
@@ -72,7 +72,7 @@ namespace boost
{
size_t s = x.size();
a << s;
- BOOST_FOREACH(auto& v, x)
+ for(auto& v: x)
{
a << v.first;
a << v.second;
@@ -101,7 +101,7 @@ namespace boost
{
size_t s = x.size();
a << s;
- BOOST_FOREACH(auto& v, x)
+ for(auto& v: x)
{
a << v;
}
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 789687ce0..b344c5597 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -31,6 +31,7 @@
#include <algorithm>
#include <cstdio>
#include <boost/filesystem.hpp>
+#include <boost/range/adaptor/reversed.hpp>
#include "include_base_utils.h"
#include "cryptonote_basic_impl.h"
@@ -933,7 +934,7 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
size_t count = 0;
size_t max_i = timestamps.size()-1;
// get difficulties and timestamps from most recent blocks in alt chain
- BOOST_REVERSE_FOREACH(auto it, alt_chain)
+ for(auto it: boost::adaptors::reverse(alt_chain))
{
timestamps[max_i - count] = it->second.bl.timestamp;
cumulative_difficulties[max_i - count] = it->second.cumulative_difficulty;
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index ca665e1d4..cd452faf4 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -36,7 +36,6 @@
#include <boost/multi_index/global_fun.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
-#include <boost/foreach.hpp>
#include <atomic>
#include <unordered_map>
#include <unordered_set>
diff --git a/src/cryptonote_core/cryptonote_boost_serialization.h b/src/cryptonote_core/cryptonote_boost_serialization.h
index 7423b222a..409b9798c 100644
--- a/src/cryptonote_core/cryptonote_boost_serialization.h
+++ b/src/cryptonote_core/cryptonote_boost_serialization.h
@@ -35,7 +35,6 @@
#include <boost/serialization/variant.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/map.hpp>
-#include <boost/foreach.hpp>
#include <boost/serialization/is_bitwise_serializable.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/portable_binary_iarchive.hpp>
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 22d473b35..ef473cfba 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -31,7 +31,6 @@
#include "include_base_utils.h"
using namespace epee;
-#include <boost/foreach.hpp>
#include <unordered_set>
#include "cryptonote_core.h"
#include "common/command_line.h"
@@ -668,7 +667,7 @@ namespace cryptonote
bool core::are_key_images_spent(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const
{
spent.clear();
- BOOST_FOREACH(auto& ki, key_im)
+ for(auto& ki: key_im)
{
spent.push_back(m_blockchain_storage.have_tx_keyimg_as_spent(ki));
}
@@ -681,14 +680,14 @@ namespace cryptonote
uint64_t emission_amount = 0;
uint64_t total_fee_amount = 0;
this->get_blocks(start_offset, count, blocks);
- BOOST_FOREACH(auto& b, blocks)
+ for(auto& b: blocks)
{
std::list<transaction> txs;
std::list<crypto::hash> missed_txs;
uint64_t coinbase_amount = get_outs_money_amount(b.miner_tx);
this->get_transactions(b.tx_hashes, txs, missed_txs);
uint64_t tx_fee_amount = 0;
- BOOST_FOREACH(const auto& tx, txs)
+ for(const auto& tx: txs)
{
tx_fee_amount += get_tx_fee(tx);
}
@@ -703,7 +702,7 @@ namespace cryptonote
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
{
std::unordered_set<crypto::key_image> ki;
- BOOST_FOREACH(const auto& in, tx.vin)
+ for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
if(!ki.insert(tokey_in.k_image).second)
@@ -869,7 +868,7 @@ namespace cryptonote
block_to_blob(b, arg.b.block);
//pack transactions
- BOOST_FOREACH(auto& tx, txs)
+ for(auto& tx: txs)
arg.b.txs.push_back(t_serializable_object_to_blob(tx));
m_pprotocol->relay_block(arg, exclude_context);
diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp
index e04409d87..70ba7ee18 100644
--- a/src/cryptonote_core/cryptonote_format_utils.cpp
+++ b/src/cryptonote_core/cryptonote_format_utils.cpp
@@ -32,7 +32,6 @@
using namespace epee;
#include "cryptonote_format_utils.h"
-#include <boost/foreach.hpp>
#include "cryptonote_config.h"
#include "miner.h"
#include "crypto/crypto.h"
@@ -274,12 +273,12 @@ namespace cryptonote
}
uint64_t amount_in = 0;
uint64_t amount_out = 0;
- BOOST_FOREACH(auto& in, tx.vin)
+ for(auto& in: tx.vin)
{
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), 0, "unexpected type id in transaction");
amount_in += boost::get<txin_to_key>(in).amount;
}
- BOOST_FOREACH(auto& o, tx.vout)
+ for(auto& o: tx.vout)
amount_out += o.amount;
CHECK_AND_ASSERT_MES(amount_in >= amount_out, false, "transaction spend (" <<amount_in << ") more than it has (" << amount_out << ")");
@@ -540,7 +539,7 @@ namespace cryptonote
uint64_t summary_inputs_money = 0;
//fill inputs
int idx = -1;
- BOOST_FOREACH(const tx_source_entry& src_entr, sources)
+ for(const tx_source_entry& src_entr: sources)
{
++idx;
if(src_entr.real_output >= src_entr.outputs.size())
@@ -574,7 +573,7 @@ namespace cryptonote
input_to_key.k_image = img;
//fill outputs array and use relative offsets
- BOOST_FOREACH(const tx_source_entry::output_entry& out_entry, src_entr.outputs)
+ for(const tx_source_entry::output_entry& out_entry: src_entr.outputs)
input_to_key.key_offsets.push_back(out_entry.first);
input_to_key.key_offsets = absolute_output_offsets_to_relative(input_to_key.key_offsets);
@@ -588,7 +587,7 @@ namespace cryptonote
uint64_t summary_outs_money = 0;
//fill outputs
size_t output_index = 0;
- BOOST_FOREACH(const tx_destination_entry& dst_entr, shuffled_dsts)
+ for(const tx_destination_entry& dst_entr: shuffled_dsts)
{
CHECK_AND_ASSERT_MES(dst_entr.amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.amount);
crypto::key_derivation derivation;
@@ -639,13 +638,13 @@ namespace cryptonote
std::stringstream ss_ring_s;
size_t i = 0;
- BOOST_FOREACH(const tx_source_entry& src_entr, sources)
+ for(const tx_source_entry& src_entr: sources)
{
ss_ring_s << "pub_keys:" << ENDL;
std::vector<const crypto::public_key*> keys_ptrs;
std::vector<crypto::public_key> keys(src_entr.outputs.size());
size_t ii = 0;
- BOOST_FOREACH(const tx_source_entry::output_entry& o, src_entr.outputs)
+ for(const tx_source_entry::output_entry& o: src_entr.outputs)
{
keys[ii] = rct2pk(o.second.dest);
keys_ptrs.push_back(&keys[ii]);
@@ -677,7 +676,7 @@ namespace cryptonote
if (!use_simple_rct)
{
// non simple ringct requires all real inputs to be at the same index for all inputs
- BOOST_FOREACH(const tx_source_entry& src_entr, sources)
+ for(const tx_source_entry& src_entr: sources)
{
if(src_entr.real_output != sources.begin()->real_output)
{
@@ -784,7 +783,7 @@ namespace cryptonote
bool get_inputs_money_amount(const transaction& tx, uint64_t& money)
{
money = 0;
- BOOST_FOREACH(const auto& in, tx.vin)
+ for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
money += tokey_in.amount;
@@ -801,7 +800,7 @@ namespace cryptonote
//---------------------------------------------------------------
bool check_inputs_types_supported(const transaction& tx)
{
- BOOST_FOREACH(const auto& in, tx.vin)
+ for(const auto& in: tx.vin)
{
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: "
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
@@ -813,7 +812,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool check_outs_valid(const transaction& tx)
{
- BOOST_FOREACH(const tx_out& out, tx.vout)
+ for(const tx_out& out: tx.vout)
{
CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key), false, "wrong variant type: "
<< out.target.type().name() << ", expected " << typeid(txout_to_key).name()
@@ -838,7 +837,7 @@ namespace cryptonote
bool check_inputs_overflow(const transaction& tx)
{
uint64_t money = 0;
- BOOST_FOREACH(const auto& in, tx.vin)
+ for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
if(money > tokey_in.amount + money)
@@ -851,7 +850,7 @@ namespace cryptonote
bool check_outs_overflow(const transaction& tx)
{
uint64_t money = 0;
- BOOST_FOREACH(const auto& o, tx.vout)
+ for(const auto& o: tx.vout)
{
if(money > o.amount + money)
return false;
@@ -863,7 +862,7 @@ namespace cryptonote
uint64_t get_outs_money_amount(const transaction& tx)
{
uint64_t outputs_amount = 0;
- BOOST_FOREACH(const auto& o, tx.vout)
+ for(const auto& o: tx.vout)
outputs_amount += o.amount;
return outputs_amount;
}
@@ -905,7 +904,7 @@ namespace cryptonote
{
money_transfered = 0;
size_t i = 0;
- BOOST_FOREACH(const tx_out& o, tx.vout)
+ for(const tx_out& o: tx.vout)
{
CHECK_AND_ASSERT_MES(o.target.type() == typeid(txout_to_key), false, "wrong type id in transaction out" );
if(is_out_to_acc(acc, boost::get<txout_to_key>(o.target), tx_pub_key, i))
@@ -1177,7 +1176,7 @@ namespace cryptonote
size_t bl_sz = 0;
get_transaction_hash(b.miner_tx, h, bl_sz);
txs_ids.push_back(h);
- BOOST_FOREACH(auto& th, b.tx_hashes)
+ for(auto& th: b.tx_hashes)
txs_ids.push_back(th);
return get_tx_tree_hash(txs_ids);
}
diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp
index 51f508858..88c631f80 100644
--- a/src/cryptonote_core/miner.cpp
+++ b/src/cryptonote_core/miner.cpp
@@ -33,7 +33,6 @@
#include <boost/utility/value_init.hpp>
#include <boost/interprocess/detail/atomic.hpp>
#include <boost/limits.hpp>
-#include <boost/foreach.hpp>
#include "misc_language.h"
#include "include_base_utils.h"
#include "cryptonote_basic_impl.h"
@@ -292,7 +291,7 @@ namespace cryptonote
send_stop_signal();
CRITICAL_REGION_LOCAL(m_threads_lock);
- BOOST_FOREACH(boost::thread& th, m_threads)
+ for(boost::thread& th: m_threads)
th.join();
MINFO("Mining has been stopped, " << m_threads.size() << " finished" );
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 6ad139023..f810f6a60 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -240,7 +240,7 @@ namespace cryptonote
// assume failure during verification steps until success is certain
tvc.m_verifivation_failed = true;
- BOOST_FOREACH(const auto& in, tx.vin)
+ for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, txin, false);
std::unordered_set<crypto::hash>& kei_image_set = m_spent_key_images[txin.k_image];
@@ -275,7 +275,7 @@ namespace cryptonote
// ND: Speedup
// 1. Move transaction hash calcuation outside of loop. ._.
crypto::hash actual_hash = get_transaction_hash(tx);
- BOOST_FOREACH(const txin_v& vi, tx.vin)
+ for(const txin_v& vi: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(vi, const txin_to_key, txin, false);
auto it = m_spent_key_images.find(txin.k_image);
@@ -415,7 +415,7 @@ namespace cryptonote
void tx_memory_pool::get_transactions(std::list<transaction>& txs) const
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
- BOOST_FOREACH(const auto& tx_vt, m_transactions)
+ for(const auto& tx_vt: m_transactions)
txs.push_back(tx_vt.second.tx);
}
//------------------------------------------------------------------
@@ -488,7 +488,7 @@ namespace cryptonote
bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx) const
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
- BOOST_FOREACH(const auto& in, tx.vin)
+ for(const auto& in: tx.vin)
{
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, true);//should never fail
if(have_tx_keyimg_as_spent(tokey_in.k_image))
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
index 56b82ed15..09c202e79 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
@@ -52,7 +52,6 @@
#include "../../contrib/epee/include/net/net_utils_base.h"
#include "../../contrib/epee/include/misc_log_ex.h"
#include <boost/lambda/bind.hpp>
-#include <boost/foreach.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 73e4fa72f..1309ff742 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -411,7 +411,7 @@ namespace cryptonote
transaction tx;
crypto::hash tx_hash;
- BOOST_FOREACH(auto& tx_blob, arg.b.txs)
+ for(auto& tx_blob: arg.b.txs)
{
if(parse_and_validate_tx_from_blob(tx_blob, tx))
{
@@ -527,7 +527,7 @@ namespace cryptonote
}
size_t tx_idx = 0;
- BOOST_FOREACH(auto& tx_hash, new_block.tx_hashes)
+ for(auto& tx_hash: new_block.tx_hashes)
{
if(m_core.get_pool_transaction(tx_hash, tx))
{
@@ -638,7 +638,7 @@ namespace cryptonote
fluffy_response.current_blockchain_height = m_core.get_current_blockchain_height();
fluffy_response.hop = arg.hop;
size_t local_txs_count = local_txs.size();
- BOOST_FOREACH(auto& tx_idx, arg.missing_tx_indices)
+ for(auto& tx_idx: arg.missing_tx_indices)
{
if(tx_idx < local_txs_count)
{
@@ -790,7 +790,7 @@ namespace cryptonote
context.m_remote_blockchain_height = arg.current_blockchain_height;
size_t count = 0;
- BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
+ for(const block_complete_entry& block_entry: arg.blocks)
{
if (m_stopping)
{
@@ -859,7 +859,7 @@ namespace cryptonote
uint64_t previous_height = m_core.get_current_blockchain_height();
m_core.prepare_handle_incoming_blocks(arg.blocks);
- BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
+ for(const block_complete_entry& block_entry: arg.blocks)
{
if (m_stopping)
{
@@ -869,7 +869,7 @@ namespace cryptonote
// process transactions
TIME_MEASURE_START(transactions_process_time);
- BOOST_FOREACH(auto& tx_blob, block_entry.txs)
+ for(auto& tx_blob: block_entry.txs)
{
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
m_core.handle_incoming_tx(tx_blob, tvc, true, true, false);
@@ -1077,7 +1077,7 @@ namespace cryptonote
m_p2p->drop_connection(context);
}
- BOOST_FOREACH(auto& bl_id, arg.m_block_ids)
+ for(auto& bl_id: arg.m_block_ids)
{
if(!m_core.have_block(bl_id))
context.m_needed_objects.push_back(bl_id);
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 8558ebc17..7bc9afbb9 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1451,6 +1451,7 @@ bool t_rpc_command_executor::print_blockchain_dynamic_stats(uint64_t nblocks)
std::string fail_message = "Problem fetching info";
+ fereq.grace_blocks = 0;
if (m_is_rpc)
{
if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp
index 80915e9a3..bdb239ca8 100644
--- a/src/p2p/connection_basic.cpp
+++ b/src/p2p/connection_basic.cpp
@@ -56,7 +56,6 @@
#include "../../contrib/epee/include/net/net_utils_base.h"
#include "../../contrib/epee/include/misc_log_ex.h"
#include <boost/lambda/bind.hpp>
-#include <boost/foreach.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 40598fc0f..5ed96c00b 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -31,7 +31,6 @@
#pragma once
#include <boost/thread.hpp>
#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
#include <boost/bimap.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 0e43d9579..d67c5dd93 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -1182,7 +1182,7 @@ namespace nodetool
time(&now);
delta = now - local_time;
- BOOST_FOREACH(peerlist_entry& be, local_peerlist)
+ for(peerlist_entry& be: local_peerlist)
{
if(be.last_seen > local_time)
{
@@ -1320,7 +1320,7 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::relay_notify_to_list(int command, const std::string& data_buff, const std::list<boost::uuids::uuid> &connections)
{
- BOOST_FOREACH(const auto& c_id, connections)
+ for(const auto& c_id: connections)
{
m_net_server.get_config_object().notify(command, data_buff, c_id);
}
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 160206ed3..c73d6615d 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -33,7 +33,6 @@
#include <list>
#include <set>
#include <map>
-#include <boost/foreach.hpp>
//#include <boost/bimap.hpp>
//#include <boost/bimap/multiset_of.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -45,6 +44,7 @@
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>
+#include <boost/range/adaptor/reversed.hpp>
#include "syncobj.h"
@@ -230,7 +230,7 @@ namespace nodetool
bool peerlist_manager::merge_peerlist(const std::list<peerlist_entry>& outer_bs)
{
CRITICAL_REGION_LOCAL(m_peerlist_lock);
- BOOST_FOREACH(const peerlist_entry& be, outer_bs)
+ for(const peerlist_entry& be: outer_bs)
{
append_with_peer_gray(be);
}
@@ -283,7 +283,7 @@ namespace nodetool
CRITICAL_REGION_LOCAL(m_peerlist_lock);
peers_indexed::index<by_time>::type& by_time_index=m_peers_white.get<by_time>();
uint32_t cnt = 0;
- BOOST_REVERSE_FOREACH(const peers_indexed::value_type& vl, by_time_index)
+ for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index))
{
if(!vl.last_seen)
continue;
@@ -301,13 +301,13 @@ namespace nodetool
{
CRITICAL_REGION_LOCAL(m_peerlist_lock);
peers_indexed::index<by_time>::type& by_time_index_gr=m_peers_gray.get<by_time>();
- BOOST_REVERSE_FOREACH(const peers_indexed::value_type& vl, by_time_index_gr)
+ for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index_gr))
{
pl_gray.push_back(vl);
}
peers_indexed::index<by_time>::type& by_time_index_wt=m_peers_white.get<by_time>();
- BOOST_REVERSE_FOREACH(const peers_indexed::value_type& vl, by_time_index_wt)
+ for(const peers_indexed::value_type& vl: boost::adaptors::reverse(by_time_index_wt))
{
pl_white.push_back(vl);
}
diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp
index 9efaaf95a..d4fe356a9 100644
--- a/src/p2p/network_throttle-detail.cpp
+++ b/src/p2p/network_throttle-detail.cpp
@@ -54,7 +54,6 @@
#include "../../contrib/epee/include/net/net_utils_base.h"
#include "../../contrib/epee/include/misc_log_ex.h"
#include <boost/lambda/bind.hpp>
-#include <boost/foreach.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp
index b954c5b3a..4f6cbe9cf 100644
--- a/src/p2p/network_throttle.hpp
+++ b/src/p2p/network_throttle.hpp
@@ -57,7 +57,6 @@
#include "../../contrib/epee/include/net/net_utils_base.h"
#include "../../contrib/epee/include/misc_log_ex.h"
#include <boost/lambda/bind.hpp>
-#include <boost/foreach.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index ce1ee1449..6d6ac7b98 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -83,7 +83,7 @@ namespace nodetool
time(&now_time);
std::stringstream ss;
ss << std::setfill ('0') << std::setw (8) << std::hex << std::noshowbase;
- BOOST_FOREACH(const peerlist_entry& pe, pl)
+ for(const peerlist_entry& pe: pl)
{
ss << pe.id << "\t" << epee::string_tools::get_ip_string_from_int32(pe.adr.ip) << ":" << boost::lexical_cast<std::string>(pe.adr.port) << " \tlast_seen: " << epee::misc_utils::get_time_interval_string(now_time - pe.last_seen) << std::endl;
}
diff --git a/src/ringct/rctTypes.h b/src/ringct/rctTypes.h
index b1aa243b9..0c27745e1 100644
--- a/src/ringct/rctTypes.h
+++ b/src/ringct/rctTypes.h
@@ -40,11 +40,11 @@
#include <cinttypes>
extern "C" {
-#include "crypto/generic-ops.h"
#include "crypto/crypto-ops.h"
#include "crypto/random.h"
#include "crypto/keccak.h"
}
+#include "crypto/generic-ops.h"
#include "crypto/crypto.h"
#include "serialization/serialization.h"
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 7d896e491..1ce7c2b89 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -28,7 +28,6 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-#include <boost/foreach.hpp>
#include "include_base_utils.h"
using namespace epee;
@@ -160,7 +159,7 @@ namespace cryptonote
return false;
}
- BOOST_FOREACH(auto& b, bs)
+ for(auto& b: bs)
{
res.blocks.resize(res.blocks.size()+1);
res.blocks.back().block = block_to_blob(b.first);
@@ -173,7 +172,7 @@ namespace cryptonote
return false;
}
size_t txidx = 0;
- BOOST_FOREACH(auto& t, b.second)
+ for(auto& t: b.second)
{
res.blocks.back().txs.push_back(tx_to_blob(t));
res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices());
@@ -381,7 +380,7 @@ namespace cryptonote
{
CHECK_CORE_BUSY();
std::vector<crypto::hash> vh;
- BOOST_FOREACH(const auto& tx_hex_str, req.txs_hashes)
+ for(const auto& tx_hex_str: req.txs_hashes)
{
blobdata b;
if(!string_tools::parse_hexstr_to_binbuff(tx_hex_str, b))
@@ -433,7 +432,7 @@ namespace cryptonote
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)
+ for(auto& tx: txs)
{
res.txs.push_back(COMMAND_RPC_GET_TRANSACTIONS::entry());
COMMAND_RPC_GET_TRANSACTIONS::entry &e = res.txs.back();
@@ -471,7 +470,7 @@ namespace cryptonote
}
}
- BOOST_FOREACH(const auto& miss_tx, missed_txs)
+ for(const auto& miss_tx: missed_txs)
{
res.missed_tx.push_back(string_tools::pod_to_hex(miss_tx));
}
@@ -485,7 +484,7 @@ namespace cryptonote
{
CHECK_CORE_BUSY();
std::vector<crypto::key_image> key_images;
- BOOST_FOREACH(const auto& ki_hex_str, req.key_images)
+ for(const auto& ki_hex_str: req.key_images)
{
blobdata b;
if(!string_tools::parse_hexstr_to_binbuff(ki_hex_str, b))
@@ -908,7 +907,7 @@ namespace cryptonote
uint64_t core_rpc_server::get_block_reward(const block& blk)
{
uint64_t reward = 0;
- BOOST_FOREACH(const tx_out& out, blk.miner_tx.vout)
+ for(const tx_out& out: blk.miner_tx.vout)
{
reward += out.amount;
}
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 52ecc2e6a..c1cc5d10d 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -197,6 +197,44 @@ bool Wallet::addressValid(const std::string &str, bool testnet)
return get_account_integrated_address_from_str(address, has_payment_id, pid, testnet, str);
}
+bool Wallet::keyValid(const std::string &secret_key_string, const std::string &address_string, bool isViewKey, bool testnet, std::string &error)
+{
+ bool has_payment_id;
+ cryptonote::account_public_address address;
+ crypto::hash8 pid;
+ if(!get_account_integrated_address_from_str(address, has_payment_id, pid, testnet, address_string)) {
+ error = tr("Failed to parse address");
+ return false;
+ }
+
+ cryptonote::blobdata key_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(secret_key_string, key_data) || key_data.size() != sizeof(crypto::secret_key))
+ {
+ error = tr("Failed to parse key");
+ return false;
+ }
+ crypto::secret_key key = *reinterpret_cast<const crypto::secret_key*>(key_data.data());
+
+ // check the key match the given address
+ crypto::public_key pkey;
+ if (!crypto::secret_key_to_public_key(key, pkey)) {
+ error = tr("failed to verify key");
+ return false;
+ }
+ bool matchAddress = false;
+ if(isViewKey)
+ matchAddress = address.m_view_public_key == pkey;
+ else
+ matchAddress = address.m_spend_public_key == pkey;
+
+ if(!matchAddress) {
+ error = tr("key does not match address");
+ return false;
+ }
+
+ return true;
+}
+
std::string Wallet::paymentIdFromAddress(const std::string &str, bool testnet)
{
bool has_payment_id;
@@ -337,6 +375,98 @@ bool WalletImpl::createWatchOnly(const std::string &path, const std::string &pas
return true;
}
+bool WalletImpl::recoverFromKeys(const std::string &path,
+ const std::string &language,
+ const std::string &address_string,
+ const std::string &viewkey_string,
+ const std::string &spendkey_string)
+{
+ 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, m_wallet->testnet(), address_string))
+ {
+ m_errorString = tr("failed to parse address");
+ m_status = Status_Error;
+ return false;
+ }
+
+ // parse optional spend key
+ crypto::secret_key spendkey;
+ bool has_spendkey = false;
+ if (!spendkey_string.empty()) {
+ cryptonote::blobdata spendkey_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(spendkey_string, spendkey_data) || spendkey_data.size() != sizeof(crypto::secret_key))
+ {
+ m_errorString = tr("failed to parse secret spend key");
+ m_status = Status_Error;
+ return false;
+ }
+ has_spendkey = true;
+ spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
+ }
+
+ // parse view secret key
+ if (viewkey_string.empty()) {
+ m_errorString = tr("No view key supplied, cancelled");
+ m_status = Status_Error;
+ return false;
+ }
+ cryptonote::blobdata viewkey_data;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(viewkey_string, viewkey_data) || viewkey_data.size() != sizeof(crypto::secret_key))
+ {
+ m_errorString = tr("failed to parse secret view key");
+ m_status = Status_Error;
+ return false;
+ }
+ crypto::secret_key viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
+
+ // check the spend and view keys match the given address
+ crypto::public_key pkey;
+ if(has_spendkey) {
+ if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
+ m_errorString = tr("failed to verify secret spend key");
+ m_status = Status_Error;
+ return false;
+ }
+ if (address.m_spend_public_key != pkey) {
+ m_errorString = tr("spend key does not match address");
+ m_status = Status_Error;
+ return false;
+ }
+ }
+ if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
+ m_errorString = tr("failed to verify secret view key");
+ m_status = Status_Error;
+ return false;
+ }
+ if (address.m_view_public_key != pkey) {
+ m_errorString = tr("view key does not match address");
+ m_status = Status_Error;
+ return false;
+ }
+
+ try
+ {
+ if (has_spendkey) {
+ m_wallet->generate(path, "", address, spendkey, viewkey);
+ LOG_PRINT_L1("Generated new wallet from keys");
+ }
+ else {
+ m_wallet->generate(path, "", address, viewkey);
+ LOG_PRINT_L1("Generated new view only wallet from keys");
+ }
+
+ }
+ catch (const std::exception& e) {
+ m_errorString = string(tr("failed to generate new wallet: ")) + e.what();
+ m_status = Status_Error;
+ return false;
+ }
+ return true;
+}
+
+
bool WalletImpl::open(const std::string &path, const std::string &password)
{
clearStatus();
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index e3df7fd01..16a7f5d95 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -58,6 +58,11 @@ public:
const std::string &language) const;
bool open(const std::string &path, const std::string &password);
bool recover(const std::string &path, const std::string &seed);
+ bool recoverFromKeys(const std::string &path,
+ const std::string &language,
+ const std::string &address_string,
+ const std::string &viewkey_string,
+ const std::string &spendkey_string = "");
bool close();
std::string seed() const;
std::string getSeedLanguage() const;
@@ -94,6 +99,7 @@ public:
void setRecoveringFromSeed(bool recoveringFromSeed);
bool watchOnly() const;
bool rescanSpent();
+ bool testnet() const {return m_wallet->testnet();}
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index 904338a72..fcb39d1f3 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -72,6 +72,22 @@ Wallet *WalletManagerImpl::recoveryWallet(const std::string &path, const std::st
return wallet;
}
+Wallet *WalletManagerImpl::createWalletFromKeys(const std::string &path,
+ const std::string &language,
+ bool testnet,
+ uint64_t restoreHeight,
+ const std::string &addressString,
+ const std::string &viewKeyString,
+ const std::string &spendKeyString)
+{
+ WalletImpl * wallet = new WalletImpl(testnet);
+ if(restoreHeight > 0){
+ wallet->setRefreshFromBlockHeight(restoreHeight);
+ }
+ wallet->recoverFromKeys(path, language, addressString, viewKeyString, spendKeyString);
+ return wallet;
+}
+
bool WalletManagerImpl::closeWallet(Wallet *wallet)
{
WalletImpl * wallet_ = dynamic_cast<WalletImpl*>(wallet);
diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h
index ca9570254..ce9b70e96 100644
--- a/src/wallet/api/wallet_manager.h
+++ b/src/wallet/api/wallet_manager.h
@@ -41,6 +41,13 @@ public:
const std::string &language, bool testnet);
Wallet * openWallet(const std::string &path, const std::string &password, bool testnet);
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet, uint64_t restoreHeight);
+ virtual Wallet * createWalletFromKeys(const std::string &path,
+ const std::string &language,
+ bool testnet,
+ uint64_t restoreHeight,
+ const std::string &addressString,
+ const std::string &viewKeyString,
+ const std::string &spendKeyString = "");
virtual bool closeWallet(Wallet *wallet);
bool walletExists(const std::string &path);
std::vector<std::string> findWallets(const std::string &path);
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 4348b8a62..14f180e00 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -841,7 +841,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
" not match with daemon response size=" + std::to_string(o_indices.size()));
}
- BOOST_FOREACH(size_t o, outs)
+ for(size_t o: outs)
{
THROW_WALLET_EXCEPTION_IF(tx.vout.size() <= o, error::wallet_internal_error, "wrong out in transaction: internal index=" +
std::to_string(o) + ", total_outs=" + std::to_string(tx.vout.size()));
@@ -945,7 +945,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
uint64_t tx_money_spent_in_ins = 0;
// check all outputs for spending (compare key images)
- BOOST_FOREACH(auto& in, tx.vin)
+ for(auto& in: tx.vin)
{
if(in.type() != typeid(cryptonote::txin_to_key))
continue;
@@ -1106,7 +1106,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
TIME_MEASURE_FINISH(miner_tx_handle_time);
TIME_MEASURE_START(txs_handle_time);
- BOOST_FOREACH(auto& txblob, bche.txs)
+ for(auto& txblob: bche.txs)
{
cryptonote::transaction tx;
bool r = parse_and_validate_tx_from_blob(txblob, tx);
@@ -1275,7 +1275,7 @@ void wallet2::process_blocks(uint64_t start_height, const std::list<cryptonote::
}
else
{
- BOOST_FOREACH(auto& bl_entry, blocks)
+ for(auto& bl_entry: blocks)
{
cryptonote::block bl;
bool r = cryptonote::parse_and_validate_block_from_blob(bl_entry.block, bl);
@@ -1556,7 +1556,7 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height,
}
}
current_index = blocks_start_height;
- BOOST_FOREACH(auto& bl_id, hashes)
+ for(auto& bl_id: hashes)
{
if(current_index >= m_blockchain.size())
{
@@ -2514,7 +2514,7 @@ void wallet2::store_to(const std::string &path, const std::string &password)
uint64_t wallet2::unlocked_balance() const
{
uint64_t amount = 0;
- BOOST_FOREACH(const transfer_details& td, m_transfers)
+ for(const transfer_details& td: m_transfers)
if(!td.m_spent && is_transfer_unlocked(td))
amount += td.amount();
@@ -2524,12 +2524,12 @@ uint64_t wallet2::unlocked_balance() const
uint64_t wallet2::balance() const
{
uint64_t amount = 0;
- BOOST_FOREACH(auto& td, m_transfers)
+ for(auto& td: m_transfers)
if(!td.m_spent)
amount += td.amount();
- BOOST_FOREACH(auto& utx, m_unconfirmed_txs)
+ for(auto& utx: m_unconfirmed_txs)
if (utx.second.m_state != wallet2::unconfirmed_transfer_details::failed)
amount+= utx.second.m_change;
@@ -2997,7 +2997,7 @@ void wallet2::commit_tx(pending_tx& ptx)
{
payment_id = get_payment_id(ptx);
dests = ptx.dests;
- BOOST_FOREACH(size_t idx, ptx.selected_transfers)
+ for(size_t idx: ptx.selected_transfers)
amount_in += m_transfers[idx].amount();
}
add_unconfirmed_tx(ptx.tx, amount_in, dests, payment_id, ptx.change_dts.amount);
@@ -3008,7 +3008,7 @@ void wallet2::commit_tx(pending_tx& ptx)
LOG_PRINT_L2("transaction " << txid << " generated ok and sent to daemon, key_images: [" << ptx.key_images << "]");
- BOOST_FOREACH(size_t idx, ptx.selected_transfers)
+ for(size_t idx: ptx.selected_transfers)
{
set_spent(idx, 0);
}
@@ -3356,7 +3356,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
ptx_vector.push_back(ptx);
// mark transfers to be used as "spent"
- BOOST_FOREACH(size_t idx, ptx.selected_transfers)
+ for(size_t idx: ptx.selected_transfers)
{
set_spent(idx, 0);
}
@@ -3368,7 +3368,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
for (auto & ptx : ptx_vector)
{
// mark transfers to be used as not spent
- BOOST_FOREACH(size_t idx2, ptx.selected_transfers)
+ for(size_t idx2: ptx.selected_transfers)
{
set_unspent(idx2);
}
@@ -3387,7 +3387,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
for (auto & ptx : ptx_vector)
{
// mark transfers to be used as not spent
- BOOST_FOREACH(size_t idx2, ptx.selected_transfers)
+ for(size_t idx2: ptx.selected_transfers)
{
set_unspent(idx2);
}
@@ -3406,7 +3406,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
for (auto & ptx : ptx_vector)
{
// mark transfers to be used as not spent
- BOOST_FOREACH(size_t idx2, ptx.selected_transfers)
+ for(size_t idx2: ptx.selected_transfers)
{
set_unspent(idx2);
}
@@ -3667,7 +3667,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
// calculate total amount being sent to all destinations
// throw if total amount overflows uint64_t
- BOOST_FOREACH(auto& dt, dsts)
+ for(auto& dt: dsts)
{
THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination);
needed_money += dt.amount;
@@ -3676,7 +3676,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
}
uint64_t found_money = 0;
- BOOST_FOREACH(size_t idx, selected_transfers)
+ for(size_t idx: selected_transfers)
{
found_money += m_transfers[idx].amount();
}
@@ -3692,7 +3692,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
typedef cryptonote::tx_source_entry::output_entry tx_output_entry;
size_t i = 0, out_index = 0;
std::vector<cryptonote::tx_source_entry> sources;
- BOOST_FOREACH(size_t idx, selected_transfers)
+ for(size_t idx: selected_transfers)
{
sources.resize(sources.size()+1);
cryptonote::tx_source_entry& src = sources.back();
@@ -3743,11 +3743,11 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
std::vector<cryptonote::tx_destination_entry> splitted_dsts, dust_dsts;
uint64_t dust = 0;
destination_split_strategy(dsts, change_dts, dust_policy.dust_threshold, splitted_dsts, dust_dsts);
- BOOST_FOREACH(auto& d, dust_dsts) {
+ for(auto& d: dust_dsts) {
THROW_WALLET_EXCEPTION_IF(dust_policy.dust_threshold < d.amount, error::wallet_internal_error, "invalid dust value: dust = " +
std::to_string(d.amount) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
}
- BOOST_FOREACH(auto& d, dust_dsts) {
+ for(auto& d: dust_dsts) {
if (!dust_policy.add_to_fee)
splitted_dsts.push_back(cryptonote::tx_destination_entry(d.amount, dust_policy.addr_for_dust));
dust += d.amount;
@@ -3812,7 +3812,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
// calculate total amount being sent to all destinations
// throw if total amount overflows uint64_t
- BOOST_FOREACH(auto& dt, dsts)
+ for(auto& dt: dsts)
{
THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination);
needed_money += dt.amount;
@@ -3821,7 +3821,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
}
uint64_t found_money = 0;
- BOOST_FOREACH(size_t idx, selected_transfers)
+ for(size_t idx: selected_transfers)
{
found_money += m_transfers[idx].amount();
}
@@ -3836,7 +3836,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
LOG_PRINT_L2("preparing outputs");
size_t i = 0, out_index = 0;
std::vector<cryptonote::tx_source_entry> sources;
- BOOST_FOREACH(size_t idx, selected_transfers)
+ for(size_t idx: selected_transfers)
{
sources.resize(sources.size()+1);
cryptonote::tx_source_entry& src = sources.back();
@@ -4107,7 +4107,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
// calculate total amount being sent to all destinations
// throw if total amount overflows uint64_t
needed_money = 0;
- BOOST_FOREACH(auto& dt, dsts)
+ for(auto& dt: dsts)
{
THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination);
needed_money += dt.amount;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 629011800..e136c568c 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -924,7 +924,7 @@ namespace tools
splitted_dsts.clear();
dust_dsts.clear();
- BOOST_FOREACH(auto& de, dsts)
+ for(auto& de: dsts)
{
cryptonote::decompose_amount_into_digits(de.amount, 0,
[&](uint64_t chunk) { splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, de.addr)); },
@@ -987,7 +987,7 @@ namespace tools
// calculate total amount being sent to all destinations
// throw if total amount overflows uint64_t
- BOOST_FOREACH(auto& dt, dsts)
+ for(auto& dt: dsts)
{
THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination);
needed_money += dt.amount;
@@ -1008,7 +1008,7 @@ namespace tools
{
COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req);
req.outs_count = fake_outputs_count + 1;// add one to make possible (if need) to skip real output key
- BOOST_FOREACH(size_t idx, selected_transfers)
+ for(size_t idx: selected_transfers)
{
const transfer_container::const_iterator it = m_transfers.begin() + idx;
THROW_WALLET_EXCEPTION_IF(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error,
@@ -1028,7 +1028,7 @@ namespace tools
std::to_string(daemon_resp.outs.size()) + ", expected " + std::to_string(selected_transfers.size()));
std::unordered_map<uint64_t, uint64_t> scanty_outs;
- BOOST_FOREACH(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& amount_outs, daemon_resp.outs)
+ for(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& amount_outs: daemon_resp.outs)
{
if (amount_outs.outs.size() < fake_outputs_count)
{
@@ -1041,7 +1041,7 @@ namespace tools
//prepare inputs
size_t i = 0;
std::vector<cryptonote::tx_source_entry> sources;
- BOOST_FOREACH(size_t idx, selected_transfers)
+ for(size_t idx: selected_transfers)
{
sources.resize(sources.size()+1);
cryptonote::tx_source_entry& src = sources.back();
@@ -1052,7 +1052,7 @@ namespace tools
if(daemon_resp.outs.size())
{
daemon_resp.outs[i].outs.sort([](const out_entry& a, const out_entry& b){return a.global_amount_index < b.global_amount_index;});
- BOOST_FOREACH(out_entry& daemon_oe, daemon_resp.outs[i].outs)
+ for(out_entry& daemon_oe: daemon_resp.outs[i].outs)
{
if(td.m_global_output_index == daemon_oe.global_amount_index)
continue;
@@ -1094,11 +1094,11 @@ namespace tools
std::vector<cryptonote::tx_destination_entry> splitted_dsts, dust_dsts;
uint64_t dust = 0;
destination_split_strategy(dsts, change_dts, dust_policy.dust_threshold, splitted_dsts, dust_dsts);
- BOOST_FOREACH(auto& d, dust_dsts) {
+ for(auto& d: dust_dsts) {
THROW_WALLET_EXCEPTION_IF(dust_policy.dust_threshold < d.amount, error::wallet_internal_error, "invalid dust value: dust = " +
std::to_string(d.amount) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
}
- BOOST_FOREACH(auto& d, dust_dsts) {
+ for(auto& d: dust_dsts) {
if (!dust_policy.add_to_fee)
splitted_dsts.push_back(cryptonote::tx_destination_entry(d.amount, dust_policy.addr_for_dust));
dust += d.amount;
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index 78caddc0b..563f16eaa 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -295,6 +295,7 @@ struct Wallet
virtual bool setPassword(const std::string &password) = 0;
virtual std::string address() const = 0;
virtual std::string path() const = 0;
+ virtual bool testnet() const = 0;
/*!
* \brief integratedAddress - returns integrated address for current wallet address and given payment_id.
@@ -434,6 +435,7 @@ struct Wallet
static std::string genPaymentId();
static bool paymentIdValid(const std::string &paiment_id);
static bool addressValid(const std::string &str, bool testnet);
+ static bool keyValid(const std::string &secret_key_string, const std::string &address_string, bool isViewKey, bool testnet, std::string &error);
static std::string paymentIdFromAddress(const std::string &str, bool testnet);
static uint64_t maximumAllowedAmount();
@@ -613,6 +615,25 @@ struct WalletManager
*/
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0;
+ /*!
+ * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
+ * \param path Name of wallet file to be created
+ * \param language language
+ * \param testnet testnet
+ * \param restoreHeight restore from start height
+ * \param addressString public address
+ * \param viewKeyString view key
+ * \param spendKeyString spend key (optional)
+ * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
+ */
+ virtual Wallet * createWalletFromKeys(const std::string &path,
+ const std::string &language,
+ bool testnet,
+ uint64_t restoreHeight,
+ const std::string &addressString,
+ const std::string &viewKeyString,
+ const std::string &spendKeyString = "") = 0;
+
/*!
* \brief Closes wallet. In case operation succeded, wallet object deleted. in case operation failed, wallet object not deleted
* \param wallet previously opened / created wallet instance
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 33e099ceb..d35e51068 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -369,7 +369,7 @@ namespace tools
cryptonote::set_payment_id_to_tx_extra_nonce(extra_nonce, long_payment_id);
}
/* or short payment ID */
- else if (!wallet2::parse_short_payment_id(payment_id_str, short_payment_id)) {
+ else if (wallet2::parse_short_payment_id(payment_id_str, short_payment_id)) {
cryptonote::set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, short_payment_id);
}
else {