Progress #17: Create vesting balances in genesis

This commit is contained in:
Nathan Hourt 2015-06-30 17:47:37 -04:00
parent c41f1057d5
commit 210c109acf
2 changed files with 33 additions and 12 deletions

View file

@ -259,28 +259,38 @@ void database::init_genesis(const genesis_state_type& genesis_state)
create<block_summary_object>([&](block_summary_object&) {});
// Create initial balances
const auto& asset_idx = get_index_type<asset_index>().indices().get<by_symbol>();
share_type total_allocation = 0;
if( !genesis_state.initial_balances.empty() )
{
share_type total_allocation = 0;
for( const auto& handout : genesis_state.initial_balances )
total_allocation += handout.amount;
const auto& asset_idx = get_index_type<asset_index>().indices().get<by_symbol>();
for( const auto& handout : genesis_state.initial_balances )
{
create<balance_object>([&handout,&asset_idx,total_allocation](balance_object& b) {
b.balance = asset(handout.amount, asset_idx.find(handout.asset_symbol)->get_id());
b.owner = handout.owner;
});
total_allocation += handout.amount;
}
modify(dyn_asset, [total_allocation](asset_dynamic_data_object& d) {
d.current_supply = total_allocation;
});
adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{}));
}
// TODO: Create initial vesting balances
// Create initial vesting balances
if( !genesis_state.initial_vesting_balances.empty() )
{
for( const genesis_state_type::initial_vesting_balance_type& vest : genesis_state.initial_vesting_balances )
{
create<balance_object>([&](balance_object& b) {
b.balance = asset(vest.amount, asset_idx.find(vest.asset_symbol)->get_id());
b.owner = vest.owner;
linear_vesting_policy policy;
policy.earliest_withdraw_time = vest.earliest_withdrawal_date;
policy.begin_date = vest.vesting_start_date;
policy.vesting_seconds = (vest.vesting_end_date - vest.vesting_start_date).to_seconds();
policy.begin_balance = b.balance.amount;
b.vesting_policy = policy;
});
total_allocation += vest.amount;
}
}
// Create initial accounts
if( !genesis_state.initial_accounts.empty() )
@ -318,6 +328,15 @@ void database::init_genesis(const genesis_state_type& genesis_state)
}
}
// Set current supply based on allocations, if they happened
if( total_allocation > 0 )
{
modify(dyn_asset, [total_allocation](asset_dynamic_data_object& d) {
d.current_supply = total_allocation;
});
adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{}));
}
flat_set<delegate_id_type> init_delegates;
flat_set<witness_id_type> init_witnesses;
const auto& accounts_by_name = get_index_type<account_index>().indices().get<by_name>();

View file

@ -82,6 +82,7 @@ namespace graphene { namespace chain {
chain_parameters initial_parameters;
vector<initial_account_type> initial_accounts;
vector<initial_balance_type> initial_balances;
vector<initial_vesting_balance_type> initial_vesting_balances;
vector<initial_witness_type> initial_witnesses;
vector<initial_committee_member_type> initial_committee;
};
@ -535,4 +536,5 @@ FC_REFLECT(graphene::chain::genesis_state_type::initial_vesting_balance_type,
FC_REFLECT(graphene::chain::genesis_state_type::initial_witness_type, (owner_name)(block_signing_key)(initial_secret))
FC_REFLECT(graphene::chain::genesis_state_type::initial_committee_member_type, (owner_name))
FC_REFLECT(graphene::chain::genesis_state_type,
(initial_parameters)(initial_accounts)(initial_balances)(initial_witnesses)(initial_committee))
(initial_parameters)(initial_accounts)(initial_balances)
(initial_vesting_balances)(initial_witnesses)(initial_committee))