chain_property_object: Implement chain_property_object as container for unchangeable properties set at genesis #238
This commit is contained in:
parent
ab7fcb9b4a
commit
3a7e65c888
10 changed files with 90 additions and 13 deletions
|
|
@ -136,6 +136,11 @@ namespace graphene { namespace app {
|
|||
return result;
|
||||
}
|
||||
|
||||
chain_property_object database_api::get_chain_properties()const
|
||||
{
|
||||
return _db.get(chain_property_id_type());
|
||||
}
|
||||
|
||||
global_property_object database_api::get_global_properties()const
|
||||
{
|
||||
return _db.get(global_property_id_type());
|
||||
|
|
@ -780,6 +785,7 @@ namespace graphene { namespace app {
|
|||
} case impl_block_summary_object_type:{
|
||||
} case impl_account_transaction_history_object_type:{
|
||||
} case impl_witness_schedule_object_type: {
|
||||
} case impl_chain_property_object_type: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ namespace detail {
|
|||
}
|
||||
|
||||
if (!_options->count("genesis-json") &&
|
||||
_chain_db->get_global_properties().chain_id != graphene::egenesis::get_egenesis_chain_id()) {
|
||||
_chain_db->get_chain_id() != graphene::egenesis::get_egenesis_chain_id()) {
|
||||
elog("Detected old database. Nuking and starting over.");
|
||||
_chain_db->wipe(_data_dir / "blockchain", true);
|
||||
_chain_db.reset();
|
||||
|
|
@ -450,7 +450,7 @@ namespace detail {
|
|||
|
||||
virtual chain_id_type get_chain_id()const override
|
||||
{
|
||||
return _chain_db->get_global_properties().chain_id;
|
||||
return _chain_db->get_chain_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,13 +24,14 @@
|
|||
#include <graphene/chain/database.hpp>
|
||||
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/operation_history_object.hpp>
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
#include <graphene/chain/market_evaluator.hpp>
|
||||
#include <graphene/chain/committee_member_object.hpp>
|
||||
#include <graphene/chain/witness_object.hpp>
|
||||
#include <graphene/chain/proposal_object.hpp>
|
||||
#include <graphene/chain/balance_object.hpp>
|
||||
#include <graphene/chain/chain_property_object.hpp>
|
||||
#include <graphene/chain/committee_member_object.hpp>
|
||||
#include <graphene/chain/market_evaluator.hpp>
|
||||
#include <graphene/chain/operation_history_object.hpp>
|
||||
#include <graphene/chain/proposal_object.hpp>
|
||||
#include <graphene/chain/witness_object.hpp>
|
||||
|
||||
#include <graphene/chain/confidential_evaluator.hpp>
|
||||
|
||||
|
|
@ -84,6 +85,11 @@ namespace graphene { namespace app {
|
|||
*/
|
||||
processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;
|
||||
|
||||
/**
|
||||
* @brief Retrieve the @ref chain_property_object associated with the chain
|
||||
*/
|
||||
chain_property_object get_chain_properties()const;
|
||||
|
||||
/**
|
||||
* @brief Retrieve the current @ref global_property_object
|
||||
*/
|
||||
|
|
@ -546,6 +552,7 @@ FC_API(graphene::app::database_api,
|
|||
(get_block_header)
|
||||
(get_block)
|
||||
(get_transaction)
|
||||
(get_chain_properties)
|
||||
(get_global_properties)
|
||||
(get_chain_id)
|
||||
(get_dynamic_global_properties)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include <graphene/chain/database.hpp>
|
||||
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
#include <graphene/chain/chain_property_object.hpp>
|
||||
#include <graphene/chain/global_property_object.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
|
@ -33,6 +34,11 @@ const global_property_object& database::get_global_properties()const
|
|||
return get( global_property_id_type() );
|
||||
}
|
||||
|
||||
const chain_property_object& database::get_chain_properties()const
|
||||
{
|
||||
return get( chain_property_id_type() );
|
||||
}
|
||||
|
||||
const dynamic_global_property_object&database::get_dynamic_global_properties() const
|
||||
{
|
||||
return get( dynamic_global_property_id_type() );
|
||||
|
|
@ -65,7 +71,7 @@ decltype( chain_parameters::block_interval ) database::block_interval( )const
|
|||
|
||||
const chain_id_type& database::get_chain_id( )const
|
||||
{
|
||||
return get_global_properties().chain_id;
|
||||
return get_chain_properties().chain_id;
|
||||
}
|
||||
|
||||
const node_property_object& database::get_node_properties()const
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@
|
|||
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/asset_object.hpp>
|
||||
#include <graphene/chain/balance_object.hpp>
|
||||
#include <graphene/chain/block_summary_object.hpp>
|
||||
#include <graphene/chain/chain_property_object.hpp>
|
||||
#include <graphene/chain/committee_member_object.hpp>
|
||||
#include <graphene/chain/global_property_object.hpp>
|
||||
#include <graphene/chain/balance_object.hpp>
|
||||
#include <graphene/chain/proposal_object.hpp>
|
||||
#include <graphene/chain/transaction_object.hpp>
|
||||
#include <graphene/chain/vesting_balance_object.hpp>
|
||||
|
|
@ -193,6 +194,7 @@ void database::initialize_indexes()
|
|||
add_index< primary_index<simple_index<asset_dynamic_data_object >> >();
|
||||
add_index< primary_index<flat_index< block_summary_object >> >();
|
||||
add_index< primary_index<simple_index<witness_schedule_object >> >();
|
||||
add_index< primary_index<simple_index<chain_property_object > > >();
|
||||
}
|
||||
|
||||
void database::init_genesis(const genesis_state_type& genesis_state)
|
||||
|
|
@ -301,9 +303,11 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) );
|
||||
(void)core_asset;
|
||||
|
||||
chain_id_type chain_id = genesis_state.compute_chain_id();
|
||||
|
||||
// Create global properties
|
||||
create<global_property_object>([&](global_property_object& p) {
|
||||
p.chain_id = genesis_state.compute_chain_id();
|
||||
p.chain_id = chain_id;
|
||||
p.parameters = genesis_state.initial_parameters;
|
||||
// Set fees to zero initially, so that genesis initialization needs not pay them
|
||||
// We'll fix it at the end of the function
|
||||
|
|
@ -315,6 +319,10 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
p.dynamic_flags = 0;
|
||||
p.witness_budget = 0;
|
||||
});
|
||||
create<chain_property_object>([&](chain_property_object& p)
|
||||
{
|
||||
p.chain_id = chain_id;
|
||||
} );
|
||||
create<block_summary_object>([&](block_summary_object&) {});
|
||||
|
||||
// Create initial accounts
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Cryptonomex, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
|
||||
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted until September 8, 2015, provided that the following conditions are met:
|
||||
*
|
||||
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
class chain_property_object;
|
||||
|
||||
/**
|
||||
* Contains invariants which are set at genesis and never changed.
|
||||
*/
|
||||
class chain_property_object : public abstract_object<chain_property_object>
|
||||
{
|
||||
public:
|
||||
static const uint8_t space_id = implementation_ids;
|
||||
static const uint8_t type_id = impl_chain_property_object_type;
|
||||
|
||||
chain_id_type chain_id;
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::chain_property_object, (graphene::db::object),
|
||||
(chain_id)
|
||||
)
|
||||
|
|
@ -254,6 +254,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
const chain_id_type& get_chain_id()const;
|
||||
const asset_object& get_core_asset()const;
|
||||
const chain_property_object& get_chain_properties()const;
|
||||
const global_property_object& get_global_properties()const;
|
||||
const dynamic_global_property_object& get_dynamic_global_properties()const;
|
||||
const node_property_object& get_node_properties()const;
|
||||
|
|
|
|||
|
|
@ -141,7 +141,8 @@ namespace graphene { namespace chain {
|
|||
impl_block_summary_object_type,
|
||||
impl_account_transaction_history_object_type,
|
||||
impl_witness_schedule_object_type,
|
||||
impl_blinded_balance_object_type
|
||||
impl_blinded_balance_object_type,
|
||||
impl_chain_property_object_type
|
||||
};
|
||||
|
||||
enum meta_info_object_type
|
||||
|
|
@ -194,6 +195,7 @@ namespace graphene { namespace chain {
|
|||
class transaction_object;
|
||||
class block_summary_object;
|
||||
class account_transaction_history_object;
|
||||
class chain_property_object;
|
||||
|
||||
typedef object_id< implementation_ids, impl_global_property_object_type, global_property_object> global_property_id_type;
|
||||
typedef object_id< implementation_ids, impl_dynamic_global_property_object_type, dynamic_global_property_object> dynamic_global_property_id_type;
|
||||
|
|
@ -208,6 +210,7 @@ namespace graphene { namespace chain {
|
|||
impl_account_transaction_history_object_type,
|
||||
account_transaction_history_object> account_transaction_history_id_type;
|
||||
typedef object_id< implementation_ids, impl_witness_schedule_object_type, witness_schedule_object > witness_schedule_id_type;
|
||||
typedef object_id< implementation_ids, impl_chain_property_object_type, chain_property_object> chain_property_id_type;
|
||||
|
||||
typedef fc::array<char, GRAPHENE_MAX_ASSET_SYMBOL_LENGTH> symbol_type;
|
||||
typedef fc::ripemd160 block_id_type;
|
||||
|
|
@ -285,6 +288,7 @@ FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
|||
(impl_account_transaction_history_object_type)
|
||||
(impl_witness_schedule_object_type)
|
||||
(impl_blinded_balance_object_type)
|
||||
(impl_chain_property_object_type)
|
||||
)
|
||||
|
||||
FC_REFLECT_ENUM( graphene::chain::meta_info_object_type, (meta_account_object_type)(meta_asset_object_type) )
|
||||
|
|
|
|||
|
|
@ -462,6 +462,7 @@ public:
|
|||
|
||||
variant info() const
|
||||
{
|
||||
auto chain_props = get_chain_properties();
|
||||
auto global_props = get_global_properties();
|
||||
auto dynamic_props = get_dynamic_global_properties();
|
||||
fc::mutable_variant_object result;
|
||||
|
|
@ -471,12 +472,16 @@ public:
|
|||
time_point_sec(time_point::now()),
|
||||
" old");
|
||||
result["next_maintenance_time"] = fc::get_approximate_relative_time_string(dynamic_props.next_maintenance_time);
|
||||
result["chain_id"] = global_props.chain_id;
|
||||
result["chain_id"] = chain_props.chain_id;
|
||||
result["active_witnesses"] = global_props.active_witnesses;
|
||||
result["active_committee_members"] = global_props.active_committee_members;
|
||||
result["entropy"] = dynamic_props.random;
|
||||
return result;
|
||||
}
|
||||
chain_property_object get_chain_properties() const
|
||||
{
|
||||
return _remote_db->get_chain_properties();
|
||||
}
|
||||
global_property_object get_global_properties() const
|
||||
{
|
||||
return _remote_db->get_global_properties();
|
||||
|
|
|
|||
|
|
@ -1204,7 +1204,7 @@ BOOST_AUTO_TEST_CASE(transfer_with_memo) {
|
|||
op.memo = memo_data();
|
||||
op.memo->set_message(alice_private_key, bob_public_key, "Dear Bob,\n\nMoney!\n\nLove, Alice");
|
||||
trx.operations = {op};
|
||||
trx.sign(alice_private_key, db.get_global_properties().chain_id);
|
||||
trx.sign(alice_private_key, db.get_chain_id());
|
||||
db.push_transaction(trx);
|
||||
|
||||
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 500);
|
||||
|
|
|
|||
Loading…
Reference in a new issue