add type field to vesting balances

This commit is contained in:
Alfredo 2018-12-30 18:01:57 -03:00
parent 62d2c1c63b
commit 604fbed498
4 changed files with 20 additions and 6 deletions

View file

@ -764,9 +764,9 @@ void schedule_pending_dividend_balances(database& db,
#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX
// get only once a collection of accounts that hold nonzero vesting balances of the dividend asset
auto vesting_balances_begin =
vesting_index.indices().get<by_asset_balance>().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id));
vesting_index.indices().get<by_asset_balance>().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id, vesting_balance_type::unspecified));
auto vesting_balances_end =
vesting_index.indices().get<by_asset_balance>().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, share_type()));
vesting_index.indices().get<by_asset_balance>().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, vesting_balance_type::unspecified, share_type()));
for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end))
{
vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount;
@ -1247,9 +1247,9 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
const vesting_balance_index& vesting_index = d.get_index_type<vesting_balance_index>();
#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX
auto vesting_balances_begin =
vesting_index.indices().get<by_asset_balance>().lower_bound(boost::make_tuple(asset_id_type()));
vesting_index.indices().get<by_asset_balance>().lower_bound(boost::make_tuple(asset_id_type(), vesting_balance_type::unspecified));
auto vesting_balances_end =
vesting_index.indices().get<by_asset_balance>().upper_bound(boost::make_tuple(asset_id_type(), share_type()));
vesting_index.indices().get<by_asset_balance>().upper_bound(boost::make_tuple(asset_id_type(), vesting_balance_type::unspecified, share_type()));
for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end))
{
vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount;

View file

@ -24,7 +24,9 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
namespace graphene { namespace chain {
namespace graphene { namespace chain {
enum class vesting_balance_type { unspecified, gpos };
struct linear_vesting_policy_initializer
{
@ -72,6 +74,7 @@ namespace graphene { namespace chain {
account_id_type owner; ///< Who is able to withdraw the balance
asset amount;
vesting_policy_initializer policy;
vesting_balance_type balance_type;
account_id_type fee_payer()const { return creator; }
void validate()const
@ -112,9 +115,11 @@ namespace graphene { namespace chain {
FC_REFLECT( graphene::chain::vesting_balance_create_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy) )
FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy)(balance_type) )
FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount) )
FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) )
FC_REFLECT(graphene::chain::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) )
FC_REFLECT_TYPENAME( graphene::chain::vesting_policy_initializer )
FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (unspecified)(gpos) )

View file

@ -24,6 +24,8 @@
#pragma once
#include <graphene/chain/protocol/asset.hpp>
#include <graphene/chain/protocol/vesting.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
@ -143,6 +145,9 @@ namespace graphene { namespace chain {
/// The vesting policy stores details on when funds vest, and controls when they may be withdrawn
vesting_policy policy;
/// We can have 2 types of vesting, gpos and all the rest
vesting_balance_type balance_type = vesting_balance_type::unspecified;
vesting_balance_object() {}
///@brief Deposit amount into vesting balance, requiring it to vest before withdrawal
@ -185,12 +190,14 @@ namespace graphene { namespace chain {
composite_key<
vesting_balance_object,
member_offset<vesting_balance_object, asset_id_type, (size_t) (offset_s(vesting_balance_object,balance) + offset_s(asset,asset_id))>,
member<vesting_balance_object, vesting_balance_type, &vesting_balance_object::balance_type>,
member_offset<vesting_balance_object, share_type, (size_t) (offset_s(vesting_balance_object,balance) + offset_s(asset,amount))>
//member<vesting_balance_object, account_id_type, &vesting_balance_object::owner>
//member_offset<vesting_balance_object, account_id_type, (size_t) (offset_s(vesting_balance_object,owner))>
>,
composite_key_compare<
std::less< asset_id_type >,
std::less< vesting_balance_type >,
std::greater< share_type >
//std::less< account_id_type >
>
@ -224,4 +231,5 @@ FC_REFLECT_DERIVED(graphene::chain::vesting_balance_object, (graphene::db::objec
(owner)
(balance)
(policy)
(balance_type)
)

View file

@ -93,6 +93,7 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance
obj.owner = op.owner;
obj.balance = op.amount;
op.policy.visit( init_policy_visitor( obj.policy, op.amount.amount, now ) );
obj.balance_type = op.balance_type;
} );