diff options
| author | Zachary Michaels <mikezackles@gmail.com> | 2014-07-16 13:30:15 -0400 |
|---|---|---|
| committer | Riccardo Spagni <ric@spagni.net> | 2014-09-15 15:53:01 +0200 |
| commit | 07470fd400ee30b84f6227edffb24094d03781cb (patch) | |
| tree | 6399848a2020528971884f5f625d0a2403f92327 /src/cryptonote_core/blockchain_storage.cpp | |
| parent | 32004a756c605b322d07d6f9917c8edaf6ca8961 (diff) | |
| download | monzero-core-07470fd400ee30b84f6227edffb24094d03781cb.tar.gz monzero-core-07470fd400ee30b84f6227edffb24094d03781cb.tar.xz monzero-core-07470fd400ee30b84f6227edffb24094d03781cb.zip | |
Add testnet flag
Source: cryptonotefoundation
Diffstat (limited to 'src/cryptonote_core/blockchain_storage.cpp')
| -rw-r--r-- | src/cryptonote_core/blockchain_storage.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index c80cec92c..cd20cd818 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -82,7 +82,7 @@ uint64_t blockchain_storage::get_current_blockchain_height() return m_blocks.size(); } //------------------------------------------------------------------ -bool blockchain_storage::init(const std::string& config_folder) +bool blockchain_storage::init(const std::string& config_folder, bool testnet) { CRITICAL_REGION_LOCAL(m_blockchain_lock); m_config_folder = config_folder; @@ -121,11 +121,24 @@ bool blockchain_storage::init(const std::string& config_folder) if(!m_blocks.size()) { LOG_PRINT_L0("Blockchain not loaded, generating genesis block."); - block bl = boost::value_initialized<block>(); - block_verification_context bvc = boost::value_initialized<block_verification_context>(); - generate_genesis_block(bl); - add_new_block(bl, bvc); - CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain"); + + if (!store_genesis_block(testnet)) { + return false; + } + } else { + cryptonote::block b; + if (testnet) { + generate_testnet_genesis_block(b); + } else { + generate_genesis_block(b); + } + + crypto::hash genesis_hash = get_block_hash(m_blocks[0].bl); + crypto::hash testnet_genesis_hash = get_block_hash(b); + if (genesis_hash != testnet_genesis_hash) { + LOG_ERROR("Failed to init: genesis block mismatch. Probably you set --testnet flag with data dir with non-test blockchain or another network."); + return false; + } } uint64_t timestamp_diff = time(NULL) - m_blocks.back().bl.timestamp; if(!m_blocks.back().bl.timestamp) @@ -134,6 +147,21 @@ bool blockchain_storage::init(const std::string& config_folder) return true; } //------------------------------------------------------------------ +bool blockchain_storage::store_genesis_block(bool testnet) { + block bl = ::boost::value_initialized<block>(); + block_verification_context bvc = boost::value_initialized<block_verification_context>(); + + if (testnet) { + generate_testnet_genesis_block(bl); + } else { + generate_genesis_block(bl); + } + + add_new_block(bl, bvc); + CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain"); + return true; +} +//------------------------------------------------------------------ bool blockchain_storage::store_blockchain() { m_is_blockchain_storing = true; |
