Support genesis vesting balances tied to account objects

This commit is contained in:
Eric Frias 2017-06-04 18:26:50 -04:00
parent f6bf447820
commit ea7e8e6f31
2 changed files with 65 additions and 3 deletions

View file

@ -641,7 +641,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
} }
// Create balances for all bts accounts // Create balances for all bts accounts
for( const auto& account : genesis_state.initial_bts_accounts ) for( const auto& account : genesis_state.initial_bts_accounts ) {
if (account.core_balance != share_type()) { if (account.core_balance != share_type()) {
total_supplies[asset_id_type()] += account.core_balance; total_supplies[asset_id_type()] += account.core_balance;
@ -651,6 +651,34 @@ void database::init_genesis(const genesis_state_type& genesis_state)
}); });
} }
// create any vesting balances for this account
if (account.vesting_balances)
for (const auto& vesting_balance : *account.vesting_balances) {
create<vesting_balance_object>([&](vesting_balance_object& vbo) {
vbo.owner = get_account_id(account.name);
vbo.balance = asset(vesting_balance.amount, get_asset_id(vesting_balance.asset_symbol));
if (vesting_balance.policy_type == "linear") {
auto initial_linear_vesting_policy = vesting_balance.policy.as<genesis_state_type::initial_bts_account_type::initial_linear_vesting_policy>();
linear_vesting_policy new_vesting_policy;
new_vesting_policy.begin_timestamp = initial_linear_vesting_policy.begin_timestamp;
new_vesting_policy.vesting_cliff_seconds = initial_linear_vesting_policy.vesting_cliff_seconds;
new_vesting_policy.vesting_duration_seconds = initial_linear_vesting_policy.vesting_duration_seconds;
new_vesting_policy.begin_balance = initial_linear_vesting_policy.begin_balance;
vbo.policy = new_vesting_policy;
} else if (vesting_balance.policy_type == "cdd") {
auto initial_cdd_vesting_policy = vesting_balance.policy.as<genesis_state_type::initial_bts_account_type::initial_cdd_vesting_policy>();
cdd_vesting_policy new_vesting_policy;
new_vesting_policy.vesting_seconds = initial_cdd_vesting_policy.vesting_seconds;
new_vesting_policy.coin_seconds_earned = initial_cdd_vesting_policy.coin_seconds_earned;
new_vesting_policy.start_claim = initial_cdd_vesting_policy.start_claim;
new_vesting_policy.coin_seconds_earned_last_update = initial_cdd_vesting_policy.coin_seconds_earned_last_update;
vbo.policy = new_vesting_policy;
}
});
}
}
// Create initial balances // Create initial balances
share_type total_allocation; share_type total_allocation;
for( const auto& handout : genesis_state.initial_balances ) for( const auto& handout : genesis_state.initial_balances )

View file

@ -59,6 +59,24 @@ struct genesis_state_type {
flat_map<public_key_type, weight_type> key_auths; flat_map<public_key_type, weight_type> key_auths;
flat_map<address, weight_type> address_auths; flat_map<address, weight_type> address_auths;
}; };
struct initial_cdd_vesting_policy {
uint32_t vesting_seconds;
fc::uint128_t coin_seconds_earned;
fc::time_point_sec start_claim;
fc::time_point_sec coin_seconds_earned_last_update;
};
struct initial_linear_vesting_policy {
fc::time_point_sec begin_timestamp;
uint32_t vesting_cliff_seconds;
uint32_t vesting_duration_seconds;
share_type begin_balance;
};
struct initial_vesting_balance {
string asset_symbol;
share_type amount;
std::string policy_type; // either "linear" or "cdd"
fc::variant policy; // either an initial_cdd_vesting_policy or initial_linear_vesting_policy
};
initial_bts_account_type(const string& name = string(), initial_bts_account_type(const string& name = string(),
const initial_authority& owner_authority = initial_authority(), const initial_authority& owner_authority = initial_authority(),
const initial_authority& active_authority = initial_authority(), const initial_authority& active_authority = initial_authority(),
@ -72,6 +90,7 @@ struct genesis_state_type {
initial_authority owner_authority; initial_authority owner_authority;
initial_authority active_authority; initial_authority active_authority;
share_type core_balance; share_type core_balance;
fc::optional<std::vector<initial_vesting_balance> > vesting_balances;
}; };
struct initial_asset_type { struct initial_asset_type {
struct initial_collateral_position { struct initial_collateral_position {
@ -174,12 +193,27 @@ FC_REFLECT(graphene::chain::genesis_state_type::initial_bts_account_type::initia
(account_auths) (account_auths)
(key_auths) (key_auths)
(address_auths)) (address_auths))
FC_REFLECT(graphene::chain::genesis_state_type::initial_bts_account_type::initial_cdd_vesting_policy,
(vesting_seconds)
(coin_seconds_earned)
(start_claim)
(coin_seconds_earned_last_update))
FC_REFLECT(graphene::chain::genesis_state_type::initial_bts_account_type::initial_linear_vesting_policy,
(begin_timestamp)
(vesting_cliff_seconds)
(vesting_duration_seconds)
(begin_balance))
FC_REFLECT(graphene::chain::genesis_state_type::initial_bts_account_type::initial_vesting_balance,
(asset_symbol)
(amount)
(policy_type)
(policy))
FC_REFLECT(graphene::chain::genesis_state_type::initial_bts_account_type, FC_REFLECT(graphene::chain::genesis_state_type::initial_bts_account_type,
(name) (name)
(owner_authority) (owner_authority)
(active_authority) (active_authority)
(core_balance)) (core_balance)
(vesting_balances))
FC_REFLECT(graphene::chain::genesis_state_type, FC_REFLECT(graphene::chain::genesis_state_type,
(initial_timestamp)(max_core_supply)(initial_parameters)(initial_bts_accounts)(initial_accounts)(initial_assets)(initial_balances) (initial_timestamp)(max_core_supply)(initial_parameters)(initial_bts_accounts)(initial_accounts)(initial_assets)(initial_balances)