forked from lthn/blockchain
fixed cleaning and reseting genesis
This commit is contained in:
parent
caaca44f1e
commit
7b0eaf7ae4
3 changed files with 55 additions and 13 deletions
32
src/common/atomics_boost_serialization.h
Normal file
32
src/common/atomics_boost_serialization.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
template <class Archive, class value_t>
|
||||
inline void save(Archive &a, const std::atomic<value_t> &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
a << x.load();
|
||||
}
|
||||
|
||||
template <class Archive, class value_t>
|
||||
inline void load(Archive &a, std::atomic<value_t> &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
value_t s = AUTO_VAL_INIT(s);
|
||||
a >> s;
|
||||
x.store(s);
|
||||
}
|
||||
template <class Archive, class value_t>
|
||||
inline void serialize(Archive &a, std::atomic<value_t> &x, const boost::serialization::version_type ver)
|
||||
{
|
||||
split_free(a, x, ver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1242,7 +1242,7 @@ void wallet2::get_short_chain_history(std::list<epee::pod_pair<uint64_t, crypto:
|
|||
//readjust item current_back_offset
|
||||
current_back_offset = sz - item.first;
|
||||
|
||||
ids.push_back(item);
|
||||
ids.push_back({ item.first, item.second });
|
||||
current_offset_distance *= 2;
|
||||
current_back_offset += current_offset_distance;
|
||||
}
|
||||
|
|
@ -2041,15 +2041,24 @@ bool wallet2::deinit()
|
|||
bool wallet2::clear()
|
||||
{
|
||||
reset_all();
|
||||
currency::block b;
|
||||
currency::generate_genesis_block(b);
|
||||
m_blockchain.push_back(get_block_hash(b));
|
||||
//currency::block b;
|
||||
//currency::generate_genesis_block(b);
|
||||
m_local_bc_size = 1;
|
||||
m_last_10_blocks.clear();
|
||||
m_last_144_blocks_every_10.clear();
|
||||
m_last_144_blocks_every_100.clear();
|
||||
m_last_144_blocks_every_1000.clear();
|
||||
//m_blockchain.push_back(get_block_hash(b));
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::reset_all()
|
||||
{
|
||||
m_blockchain.clear();
|
||||
//m_blockchain.clear();
|
||||
m_last_10_blocks.clear();
|
||||
m_last_144_blocks_every_10.clear();
|
||||
m_last_144_blocks_every_100.clear();
|
||||
m_last_144_blocks_every_1000.clear();
|
||||
m_transfers.clear();
|
||||
m_key_images.clear();
|
||||
// m_pending_key_images is not cleared intentionally
|
||||
|
|
@ -3036,9 +3045,7 @@ bool wallet2::reset_history()
|
|||
std::string pass = m_password;
|
||||
std::wstring file_path = m_wallet_file;
|
||||
account_base acc_tmp = m_account;
|
||||
crypto::hash genesis_hash = m_blockchain[0];
|
||||
clear();
|
||||
m_blockchain[0] = genesis_hash;
|
||||
m_account = acc_tmp;
|
||||
m_password = pass;
|
||||
prepare_file_names(file_path);
|
||||
|
|
@ -4278,12 +4285,13 @@ void wallet2::process_genesis_if_needed(const currency::block& genesis)
|
|||
THROW_IF_TRUE_WALLET_EX(get_blockchain_current_size() > 1, error::wallet_internal_error, "Can't change wallet genesis block once the blockchain has been populated");
|
||||
|
||||
crypto::hash genesis_hash = get_block_hash(genesis);
|
||||
if (get_blockchain_current_size() == 1 && m_blockchain[0] != genesis_hash)
|
||||
WLT_LOG_L0("Changing genesis block for wallet " << m_account.get_public_address_str() << ":" << ENDL << " " << m_blockchain[0] << " -> " << genesis_hash);
|
||||
if (get_blockchain_current_size() == 1 && m_genesis != genesis_hash)
|
||||
WLT_LOG_L0("Changing genesis block for wallet " << m_account.get_public_address_str() << ":" << ENDL << " " << m_genesis << " -> " << genesis_hash);
|
||||
|
||||
m_blockchain.clear();
|
||||
//m_blockchain.clear();
|
||||
|
||||
m_blockchain.push_back(genesis_hash);
|
||||
//m_blockchain.push_back(genesis_hash);
|
||||
m_genesis = genesis_hash;
|
||||
m_local_bc_size = 1;
|
||||
m_last_bc_timestamp = genesis.timestamp;
|
||||
|
||||
|
|
@ -4294,8 +4302,8 @@ void wallet2::process_genesis_if_needed(const currency::block& genesis)
|
|||
void wallet2::set_genesis(const crypto::hash& genesis_hash)
|
||||
{
|
||||
THROW_IF_TRUE_WALLET_EX(get_blockchain_current_size() != 1, error::wallet_internal_error, "Can't change wallet genesis hash once the blockchain has been populated");
|
||||
WLT_LOG_L0("Changing genesis hash for wallet " << m_account.get_public_address_str() << ":" << ENDL << " " << m_blockchain[0] << " -> " << genesis_hash);
|
||||
m_blockchain[0] = genesis_hash;
|
||||
WLT_LOG_L0("Changing genesis hash for wallet " << m_account.get_public_address_str() << ":" << ENDL << " " << m_genesis << " -> " << genesis_hash);
|
||||
m_genesis = genesis_hash;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::print_tx_sent_message(const currency::transaction& tx, const std::string& description, uint64_t fee /* = UINT64_MAX */)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <boost/serialization/shared_ptr.hpp>
|
||||
#include <atomic>
|
||||
|
||||
|
||||
#include "include_base_utils.h"
|
||||
#include "profile_tools.h"
|
||||
#include "sync_locked_object.h"
|
||||
|
|
@ -26,6 +27,7 @@
|
|||
#include "wallet_public_structs_defs.h"
|
||||
#include "currency_core/currency_format_utils.h"
|
||||
#include "common/unordered_containers_boost_serialization.h"
|
||||
#include "common/atomics_boost_serialization.h"
|
||||
#include "storages/portable_storage_template_helper.h"
|
||||
#include "crypto/chacha8.h"
|
||||
#include "crypto/hash.h"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue