Implement chain_id #374

This commit is contained in:
theoreticalbts 2015-10-12 11:46:32 -04:00
parent a61c23fa6a
commit 9ccbc55ba6
5 changed files with 20 additions and 6 deletions

View file

@ -36,6 +36,7 @@
#include <fc/smart_ref_impl.hpp>
#include <fc/io/fstream.hpp>
#include <fc/rpc/api_connection.hpp>
#include <fc/rpc/websocket_api.hpp>
#include <fc/network/resolve.hpp>
@ -94,6 +95,7 @@ namespace detail {
initial_state.initial_balances.push_back({nathan_key.get_public_key(),
GRAPHENE_SYMBOL,
GRAPHENE_MAX_SHARE_SUPPLY});
initial_state.initial_chain_id = fc::sha256::hash( "BOGUS" );
return initial_state;
}
@ -243,7 +245,9 @@ namespace detail {
ilog("Initializing database...");
if( _options->count("genesis-json") )
{
genesis_state_type genesis = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>();
std::string genesis_str;
fc::read_file_contents( _options->at("genesis-json").as<boost::filesystem::path>(), genesis_str );
genesis_state_type genesis = fc::json::from_string( genesis_str ).as<genesis_state_type>();
bool modified_genesis = false;
if( _options->count("genesis-timestamp") )
{
@ -263,7 +267,11 @@ namespace detail {
if( modified_genesis )
{
std::cerr << "WARNING: GENESIS WAS MODIFIED, YOUR CHAIN ID MAY BE DIFFERENT\n";
genesis_str += "BOGUS";
genesis.initial_chain_id = fc::sha256::hash( genesis_str );
}
else
genesis.initial_chain_id = fc::sha256::hash( genesis_str );
return genesis;
}
else

View file

@ -104,7 +104,7 @@ void database::wipe(const fc::path& data_dir, bool include_blocks)
void database::open(
const fc::path& data_dir,
std::function<genesis_state_type()> genesis_loader )
std::function<genesis_state_type()> genesis_loader)
{
try
{

View file

@ -9,7 +9,7 @@ namespace graphene { namespace chain {
chain_id_type genesis_state_type::compute_chain_id() const
{
return fc::sha256::hash( *this );
return initial_chain_id;
}
} } // graphene::chain

View file

@ -89,6 +89,11 @@ struct genesis_state_type {
vector<initial_committee_member_type> initial_committee_candidates;
vector<initial_worker_type> initial_worker_candidates;
/**
* Temporary, will be moved elsewhere.
*/
chain_id_type initial_chain_id;
/**
* Get the chain_id corresponding to this genesis state.
*
@ -123,4 +128,5 @@ FC_REFLECT(graphene::chain::genesis_state_type,
(initial_timestamp)(max_core_supply)(initial_parameters)(initial_accounts)(initial_assets)(initial_balances)
(initial_vesting_balances)(initial_active_witnesses)(initial_witness_candidates)
(initial_committee_candidates)(initial_worker_candidates)
(initial_chain_id)
(immutable_parameters))

View file

@ -168,12 +168,12 @@ struct egenesis_info
std::cerr << "embed_genesis: Need genesis or genesis_json\n";
exit(1);
}
// init chain_id from genesis
if( !chain_id.valid() )
chain_id = genesis->compute_chain_id();
// init genesis_json_hash from genesis_json
if( !genesis_json_hash.valid() )
genesis_json_hash = fc::sha256::hash( *genesis_json );
// init chain_id from genesis_json_hash
if( !chain_id.valid() )
chain_id = genesis_json_hash;
// init genesis_json_array from genesis_json
if( !genesis_json_array.valid() )
{