mirror of
https://github.com/jwinterm/wownero.git
synced 2026-11-11 08:33:57 +01:00
Merge pull request #1462
07b9138csupport importing unportable outputs (kenshi84)2ac80075also use portable serializer for boost_serialization_helper.h and net_node.inl, completely adandon boost/archive/binary_oarchive.hpp (kenshi84)d1d6e27amoved boost cpp into hpp since they're supposed to be header only (kenshi84)66e6af89added experimental boost::archive::portable_binary_{i|o}archive (kenshi84)
This commit is contained in:
@@ -30,8 +30,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||
|
||||
|
||||
namespace tools
|
||||
@@ -75,7 +76,7 @@ namespace tools
|
||||
return false;
|
||||
#endif
|
||||
|
||||
boost::archive::binary_oarchive a(data_file);
|
||||
boost::archive::portable_binary_oarchive a(data_file);
|
||||
a << obj;
|
||||
if (data_file.fail())
|
||||
return false;
|
||||
@@ -99,9 +100,23 @@ namespace tools
|
||||
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
|
||||
if(data_file.fail())
|
||||
return false;
|
||||
boost::archive::binary_iarchive a(data_file);
|
||||
|
||||
a >> obj;
|
||||
try
|
||||
{
|
||||
// first try reading in portable mode
|
||||
boost::archive::portable_binary_iarchive a(data_file);
|
||||
a >> obj;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// if failed, try reading in unportable mode
|
||||
boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||
data_file.close();
|
||||
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
|
||||
if(data_file.fail())
|
||||
return false;
|
||||
boost::archive::binary_iarchive a(data_file);
|
||||
a >> obj;
|
||||
}
|
||||
return !data_file.fail();
|
||||
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <fstream>
|
||||
|
||||
#include "include_base_utils.h"
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "include_base_utils.h"
|
||||
|
||||
@@ -38,7 +38,8 @@
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||
#include "cryptonote_basic.h"
|
||||
#include "common/unordered_containers_boost_serialization.h"
|
||||
#include "crypto/crypto.h"
|
||||
@@ -230,7 +231,8 @@ namespace boost
|
||||
// a & x.senderPk; // not serialized, as we do not use it in monero currently
|
||||
}
|
||||
|
||||
inline void serializeOutPk(boost::archive::binary_iarchive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
|
||||
template <class Archive>
|
||||
inline typename std::enable_if<Archive::is_loading::value, void>::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
|
||||
{
|
||||
rct::keyV outPk;
|
||||
a & outPk;
|
||||
@@ -242,7 +244,8 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
inline void serializeOutPk(boost::archive::binary_oarchive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
|
||||
template <class Archive>
|
||||
inline typename std::enable_if<Archive::is_saving::value, void>::type serializeOutPk(Archive &a, rct::ctkeyV &outPk_, const boost::serialization::version_type ver)
|
||||
{
|
||||
rct::keyV outPk(outPk_.size());
|
||||
for (size_t n = 0; n < outPk_.size(); ++n)
|
||||
|
||||
+26
-6
@@ -137,14 +137,34 @@ namespace nodetool
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::archive::binary_iarchive a(p2p_data);
|
||||
// first try reading in portable mode
|
||||
boost::archive::portable_binary_iarchive a(p2p_data);
|
||||
a >> *this;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
catch (...)
|
||||
{
|
||||
LOG_ERROR("Failed to load p2p config file, falling back to default config");
|
||||
m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load
|
||||
make_default_config();
|
||||
// if failed, try reading in unportable mode
|
||||
boost::filesystem::copy_file(state_file_path, state_file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||
p2p_data.close();
|
||||
p2p_data.open( state_file_path , std::ios_base::binary | std::ios_base::in);
|
||||
if(!p2p_data.fail())
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::archive::binary_iarchive a(p2p_data);
|
||||
a >> *this;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR("Failed to load p2p config file, falling back to default config");
|
||||
m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load
|
||||
make_default_config();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
make_default_config();
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
@@ -645,7 +665,7 @@ namespace nodetool
|
||||
return false;
|
||||
};
|
||||
|
||||
boost::archive::binary_oarchive a(p2p_data);
|
||||
boost::archive::portable_binary_oarchive a(p2p_data);
|
||||
a << *this;
|
||||
return true;
|
||||
CATCH_ENTRY_L0("blockchain_storage::save", false);
|
||||
|
||||
@@ -36,8 +36,9 @@
|
||||
#include <boost/foreach.hpp>
|
||||
//#include <boost/bimap.hpp>
|
||||
//#include <boost/bimap/multiset_of.hpp>
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
|
||||
#include <boost/multi_index_container.hpp>
|
||||
|
||||
@@ -3882,7 +3882,7 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args)
|
||||
std::vector<tools::wallet2::transfer_details> outs = m_wallet->export_outputs();
|
||||
|
||||
std::stringstream oss;
|
||||
boost::archive::binary_oarchive ar(oss);
|
||||
boost::archive::portable_binary_oarchive ar(oss);
|
||||
ar << outs;
|
||||
|
||||
std::string magic(OUTPUT_EXPORT_FILE_MAGIC, strlen(OUTPUT_EXPORT_FILE_MAGIC));
|
||||
@@ -3962,10 +3962,19 @@ bool simple_wallet::import_outputs(const std::vector<std::string> &args)
|
||||
std::string body(data, headerlen);
|
||||
std::stringstream iss;
|
||||
iss << body;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
std::vector<tools::wallet2::transfer_details> outputs;
|
||||
ar >> outputs;
|
||||
|
||||
try
|
||||
{
|
||||
boost::archive::portable_binary_iarchive ar(iss);
|
||||
ar >> outputs;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
iss.str("");
|
||||
iss << body;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
ar >> outputs;
|
||||
}
|
||||
size_t n_outputs = m_wallet->import_outputs(outputs);
|
||||
success_msg_writer() << boost::lexical_cast<std::string>(n_outputs) << " outputs imported";
|
||||
}
|
||||
|
||||
+27
-7
@@ -30,8 +30,6 @@
|
||||
|
||||
#include <random>
|
||||
#include <tuple>
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <boost/utility/value_init.hpp>
|
||||
@@ -2313,16 +2311,38 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
|
||||
|
||||
std::stringstream iss;
|
||||
iss << cache_data;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
ar >> *this;
|
||||
try {
|
||||
boost::archive::portable_binary_iarchive ar(iss);
|
||||
ar >> *this;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
|
||||
boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||
iss.str("");
|
||||
iss << cache_data;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
ar >> *this;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_PRINT_L1("Failed to load encrypted cache, trying unencrypted");
|
||||
std::stringstream iss;
|
||||
iss << buf;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
ar >> *this;
|
||||
try {
|
||||
boost::archive::portable_binary_iarchive ar(iss);
|
||||
ar >> *this;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
|
||||
boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
|
||||
iss.str("");
|
||||
iss << buf;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
ar >> *this;
|
||||
}
|
||||
}
|
||||
THROW_WALLET_EXCEPTION_IF(
|
||||
m_account_public_address.m_spend_public_key != m_account.get_keys().m_account_address.m_spend_public_key ||
|
||||
@@ -2396,7 +2416,7 @@ void wallet2::store_to(const std::string &path, const std::string &password)
|
||||
}
|
||||
// preparing wallet data
|
||||
std::stringstream oss;
|
||||
boost::archive::binary_oarchive ar(oss);
|
||||
boost::archive::portable_binary_oarchive ar(oss);
|
||||
ar << *this;
|
||||
|
||||
wallet2::cache_file_data cache_file_data = boost::value_initialized<wallet2::cache_file_data>();
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
@@ -676,11 +675,11 @@ namespace boost
|
||||
namespace serialization
|
||||
{
|
||||
template <class Archive>
|
||||
inline void initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
|
||||
inline typename std::enable_if<!Archive::is_loading::value, void>::type initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
}
|
||||
template<>
|
||||
inline void initialize_transfer_details(boost::archive::binary_iarchive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
|
||||
template <class Archive>
|
||||
inline typename std::enable_if<Archive::is_loading::value, void>::type initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
if (ver < 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user