From 48dd9f3482cb9ab89ad261ef56aae8cbac430b4d Mon Sep 17 00:00:00 2001
From: arkpar <arkady.paronyan@gmail.com>
Date: Tue, 14 Apr 2015 11:54:28 +0200
Subject: [PATCH] replaced Aversion with ImportRequirements

---
 libethcore/Common.h        |  6 +++---
 libethereum/BlockChain.cpp | 10 +++++-----
 libethereum/BlockChain.h   | 10 ++--------
 libethereum/State.cpp      |  2 +-
 mix/MixClient.cpp          |  2 +-
 5 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/libethcore/Common.h b/libethcore/Common.h
index 303adc739..12ac55735 100644
--- a/libethcore/Common.h
+++ b/libethcore/Common.h
@@ -101,9 +101,9 @@ struct ImportRequirements
 	using value = unsigned;
 	enum
 	{
-		ValidNonce = 1,
-		DontHave = 2,
-		Default = ValidNonce
+		ValidNonce = 1, ///< Validate Nonce
+		DontHave = 2, ///< Avoid old blocks
+		Default = ValidNonce | DontHave
 	};
 };
 
diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp
index 751dafc16..633b5b382 100644
--- a/libethereum/BlockChain.cpp
+++ b/libethereum/BlockChain.cpp
@@ -240,7 +240,7 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
 				return;
 			}
 			lastHash = bi.hash();
-			import(b, s.db(), Aversion::ImportOldBlocks);
+			import(b, s.db(), ImportRequirements::Default);
 		}
 		catch (...)
 		{
@@ -334,11 +334,11 @@ tuple<h256s, h256s, bool> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st
 	return make_tuple(fresh, dead, _bq.doneDrain(badBlocks));
 }
 
-pair<h256s, h256> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, Aversion _force) noexcept
+pair<h256s, h256> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir) noexcept
 {
 	try
 	{
-		return import(_block, _stateDB, _force);
+		return import(_block, _stateDB, _ir);
 	}
 	catch (...)
 	{
@@ -347,7 +347,7 @@ pair<h256s, h256> BlockChain::attemptImport(bytes const& _block, OverlayDB const
 	}
 }
 
-pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db, Aversion _force, ImportRequirements::value _ir)
+pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db, ImportRequirements::value _ir)
 {
 	//@tidy This is a behemoth of a method - could do to be split into a few smaller ones.
 
@@ -386,7 +386,7 @@ pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db,
 #endif
 
 	// Check block doesn't already exist first!
-	if (isKnown(bi.hash()) && _force == Aversion::AvoidOldBlocks)
+	if (isKnown(bi.hash()) && (_ir & ImportRequirements::DontHave))
 	{
 		clog(BlockChainNote) << bi.hash() << ": Not new.";
 		BOOST_THROW_EXCEPTION(AlreadyHaveBlock());
diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h
index 00f41ab0a..6b6a3ffe2 100644
--- a/libethereum/BlockChain.h
+++ b/libethereum/BlockChain.h
@@ -80,12 +80,6 @@ enum {
 
 using ProgressCallback = std::function<void(unsigned, unsigned)>;
 
-enum class Aversion
-{
-	AvoidOldBlocks,
-	ImportOldBlocks
-};
-
 /**
  * @brief Implements the blockchain database. All data this gives is disk-backed.
  * @threadsafe
@@ -108,11 +102,11 @@ public:
 
 	/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB.
 	/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
-	std::pair<h256s, h256> attemptImport(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks) noexcept;
+	std::pair<h256s, h256> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default) noexcept;
 
 	/// Import block into disk-backed DB
 	/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
-	std::pair<h256s, h256> import(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks, ImportRequirements::value _ir = ImportRequirements::Default);
+	std::pair<h256s, h256> import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default);
 
 	/// Returns true if the given block is known (though not necessarily a part of the canon chain).
 	bool isKnown(h256 const& _hash) const;
diff --git a/libethereum/State.cpp b/libethereum/State.cpp
index a4548ce60..73d0d3783 100644
--- a/libethereum/State.cpp
+++ b/libethereum/State.cpp
@@ -542,7 +542,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement
 {
 	// m_currentBlock is assumed to be prepopulated and reset.
 
-	BlockInfo bi(_block, ((_ir & (ImportRequirements::ValidNonce | ImportRequirements::DontHave)) == ImportRequirements::ValidNonce) ? CheckEverything : IgnoreNonce);
+	BlockInfo bi(_block, (_ir & ImportRequirements::ValidNonce) ? CheckEverything : IgnoreNonce);
 
 #if !ETH_RELEASE
 	assert(m_previousBlock.hash() == bi.parentHash);
diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp
index c15117d67..e2eac7c20 100644
--- a/mix/MixClient.cpp
+++ b/mix/MixClient.cpp
@@ -251,7 +251,7 @@ void MixClient::mine()
 	WriteGuard l(x_state);
 	m_state.commitToMine(bc());
 	m_state.completeMine();
-	bc().import(m_state.blockData(), m_stateDB, Aversion::AvoidOldBlocks, ImportRequirements::ValidNonce | ImportRequirements::DontHave);
+	bc().import(m_state.blockData(), m_stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce);
 	m_state.sync(bc());
 	m_startState = m_state;
 	h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };