diff options
author | Zachary Michaels <mikezackles@gmail.com> | 2014-09-08 15:09:59 -0400 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-09-15 15:53:50 +0200 |
commit | 96eed84aad89e6e2799a9db91e2dd2e9fe0889f9 (patch) | |
tree | 81ae5c4709effb79c5cbc031c452a71ac07ac9f6 | |
parent | Separate network id for testnet (diff) | |
download | monero-96eed84aad89e6e2799a9db91e2dd2e9fe0889f9.tar.xz |
Pass tx and nonce to genesis block constructor
-rw-r--r-- | src/cryptonote_core/blockchain_storage.cpp | 32 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.cpp | 18 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.h | 7 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 12 | ||||
-rw-r--r-- | tests/core_proxy/core_proxy.cpp | 2 |
5 files changed, 43 insertions, 28 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index cd20cd818..e664a39c5 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -114,7 +114,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet) LOG_PRINT_L0("Can't load blockchain storage from file, generating genesis block."); block bl = boost::value_initialized<block>(); block_verification_context bvc = boost::value_initialized<block_verification_context>(); - generate_genesis_block(bl); + if (testnet) + { + generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE); + } add_new_block(bl, bvc); CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed && bvc.m_added_to_main_chain, false, "Failed to add genesis block to blockchain"); } @@ -127,10 +134,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet) } } else { cryptonote::block b; - if (testnet) { - generate_testnet_genesis_block(b); - } else { - generate_genesis_block(b); + + if (testnet) + { + generate_genesis_block(b, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(b, config::GENESIS_TX, config::GENESIS_NONCE); } crypto::hash genesis_hash = get_block_hash(m_blocks[0].bl); @@ -151,10 +162,13 @@ 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); + if (testnet) + { + generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE); } add_new_block(bl, bvc); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index f7cddeded..33cad30c4 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -660,7 +660,11 @@ namespace cryptonote return p; } //--------------------------------------------------------------- - bool generate_genesis_block(block& bl) + bool generate_genesis_block( + block& bl + , std::string const & genesis_tx + , uint32_t nonce + ) { //genesis block bl = boost::value_initialized<block>(); @@ -681,20 +685,10 @@ namespace cryptonote bl.major_version = CURRENT_BLOCK_MAJOR_VERSION; bl.minor_version = CURRENT_BLOCK_MINOR_VERSION; bl.timestamp = 0; - bl.nonce = config::GENESIS_NONCE; + bl.nonce = nonce; miner::find_nonce_for_given_block(bl, 1, 0); return true; } - - bool generate_testnet_genesis_block(cryptonote::block& b) { - if (!generate_genesis_block(b)) { - return false; - } - - b.nonce += 1; - return true; - } - //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 4457f6cc6..9fa7f0545 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -105,8 +105,11 @@ namespace cryptonote crypto::hash get_block_hash(const block& b); bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height); crypto::hash get_block_longhash(const block& b, uint64_t height); - bool generate_genesis_block(block& bl); - bool generate_testnet_genesis_block(block& bl); + bool generate_genesis_block( + block& bl + , std::string const & genesis_tx + , uint32_t nonce + ); bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b); bool get_inputs_money_amount(const transaction& tx, uint64_t& money); uint64_t get_outs_money_amount(const transaction& tx); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b8b728425..78fac0e87 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -35,6 +35,7 @@ #include "include_base_utils.h" using namespace epee; +#include "cryptonote_config.h" #include "wallet2.h" #include "cryptonote_core/cryptonote_format_utils.h" #include "rpc/core_rpc_server_commands_defs.h" @@ -939,10 +940,13 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto //---------------------------------------------------------------------------------------------------- void wallet2::generate_genesis(cryptonote::block& b) { - if (m_testnet) { - cryptonote::generate_testnet_genesis_block(b); - } else { - cryptonote::generate_genesis_block(b); + if (m_testnet) + { + cryptonote::generate_genesis_block(b, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE); + } + else + { + cryptonote::generate_genesis_block(b, config::GENESIS_TX, config::GENESIS_NONCE); } } } diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp index f973f548d..3a44e91eb 100644 --- a/tests/core_proxy/core_proxy.cpp +++ b/tests/core_proxy/core_proxy.cpp @@ -227,7 +227,7 @@ bool tests::proxy_core::get_blockchain_top(uint64_t& height, crypto::hash& top_i } bool tests::proxy_core::init(const boost::program_options::variables_map& /*vm*/) { - generate_genesis_block(m_genesis); + generate_genesis_block(m_genesis, config::GENESIS_TX, config::GENESIS_NONCE); crypto::hash h = get_block_hash(m_genesis); add_block(h, get_block_longhash(m_genesis, 0), m_genesis, block_to_blob(m_genesis)); return true; |