changes to withdraw_vesting feature(for both cdd and GPOS)
This commit is contained in:
parent
8613bab257
commit
2a3d8a4c66
9 changed files with 75 additions and 25 deletions
|
|
@ -873,7 +873,7 @@ void schedule_pending_dividend_balances(database& db,
|
|||
|
||||
std::map<account_id_type, share_type> vesting_amounts;
|
||||
|
||||
auto balance_type = vesting_balance_type::unspecified;
|
||||
auto balance_type = vesting_balance_type::normal;
|
||||
if(db.head_block_time() >= HARDFORK_GPOS_TIME)
|
||||
balance_type = vesting_balance_type::gpos;
|
||||
|
||||
|
|
@ -1403,7 +1403,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
d._committee_count_histogram_buffer.resize(props.parameters.maximum_committee_count / 2 + 1);
|
||||
d._total_voting_stake = 0;
|
||||
|
||||
auto balance_type = vesting_balance_type::unspecified;
|
||||
auto balance_type = vesting_balance_type::normal;
|
||||
if(d.head_block_time() >= HARDFORK_GPOS_TIME)
|
||||
balance_type = vesting_balance_type::gpos;
|
||||
|
||||
|
|
|
|||
|
|
@ -228,3 +228,4 @@
|
|||
#define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week
|
||||
#define GPOS_PERIOD (60*60*24*30*6) // 6 months
|
||||
#define GPOS_SUBPERIOD (60*60*24*30) // 1 month
|
||||
#define GPOS_VESTING_LOCKIN_PERIOD (60*60*24*30) // 1 month
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ namespace graphene { namespace chain {
|
|||
optional < uint32_t > gpos_period;
|
||||
optional < uint32_t > gpos_subperiod;
|
||||
optional < uint32_t > gpos_period_start;
|
||||
optional < uint32_t > gpos_vesting_lockin_period;
|
||||
};
|
||||
|
||||
struct chain_parameters
|
||||
|
|
@ -121,6 +122,9 @@ namespace graphene { namespace chain {
|
|||
inline uint32_t gpos_period_start()const {
|
||||
return extensions.value.gpos_period_start.valid() ? *extensions.value.gpos_period_start : HARDFORK_GPOS_TIME.sec_since_epoch(); /// current period start date
|
||||
}
|
||||
inline uint32_t gpos_vesting_lockin_period()const {
|
||||
return extensions.value.gpos_vesting_lockin_period.valid() ? *extensions.value.gpos_vesting_lockin_period : GPOS_VESTING_LOCKIN_PERIOD; /// GPOS vesting lockin period
|
||||
}
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
|
@ -134,6 +138,7 @@ FC_REFLECT( graphene::chain::parameter_extension,
|
|||
(gpos_period)
|
||||
(gpos_subperiod)
|
||||
(gpos_period_start)
|
||||
(gpos_vesting_lockin_period)
|
||||
)
|
||||
|
||||
FC_REFLECT( graphene::chain::chain_parameters,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
enum class vesting_balance_type { unspecified, gpos };
|
||||
enum class vesting_balance_type { normal, gpos };
|
||||
|
||||
struct linear_vesting_policy_initializer
|
||||
{
|
||||
|
|
@ -122,4 +122,4 @@ FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)
|
|||
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) )
|
||||
FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (normal)(gpos) )
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ namespace graphene { namespace chain {
|
|||
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_type balance_type = vesting_balance_type::normal;
|
||||
|
||||
vesting_balance_object() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ struct proposal_operation_hardfork_visitor
|
|||
|
||||
void operator()(const vesting_balance_create_operation &vbco) const {
|
||||
if(block_time < HARDFORK_GPOS_TIME)
|
||||
FC_ASSERT( vbco.balance_type == vesting_balance_type::unspecified, "balance_type in vesting create not allowed yet!" );
|
||||
FC_ASSERT( vbco.balance_type == vesting_balance_type::normal, "balance_type in vesting create not allowed yet!" );
|
||||
}
|
||||
|
||||
// loop and self visit in proposals
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ void_result vesting_balance_create_evaluator::do_evaluate( const vesting_balance
|
|||
FC_ASSERT( !op.amount.asset_id(d).is_transfer_restricted() );
|
||||
|
||||
if(d.head_block_time() < HARDFORK_GPOS_TIME) // Todo: can be removed after gpos hf time pass
|
||||
FC_ASSERT( op.balance_type == vesting_balance_type::unspecified);
|
||||
FC_ASSERT( op.balance_type == vesting_balance_type::normal);
|
||||
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
|
@ -101,7 +101,7 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance
|
|||
// forcing gpos policy
|
||||
linear_vesting_policy p;
|
||||
p.begin_timestamp = now;
|
||||
p.vesting_cliff_seconds = gpo.parameters.gpos_subperiod();
|
||||
p.vesting_cliff_seconds = gpo.parameters.gpos_vesting_lockin_period();
|
||||
p.vesting_duration_seconds = gpo.parameters.gpos_subperiod();
|
||||
obj.policy = p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1349,12 +1349,14 @@ class wallet_api
|
|||
* @param amount The amount to withdraw.
|
||||
* @param asset_symbol The symbol of the asset to withdraw.
|
||||
* @param broadcast true if you wish to broadcast the transaction
|
||||
* @param vb_type vestig balance type to withdraw 0-OLD, 1-GPOS, 2-SONS(if required)
|
||||
*/
|
||||
signed_transaction withdraw_vesting(
|
||||
string witness_name,
|
||||
string amount,
|
||||
string asset_symbol,
|
||||
bool broadcast = false);
|
||||
bool broadcast = false,
|
||||
uint8_t vb_type = 0);
|
||||
|
||||
/** Vote for a given committee_member.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1963,26 +1963,64 @@ public:
|
|||
string witness_name,
|
||||
string amount,
|
||||
string asset_symbol,
|
||||
bool broadcast = false )
|
||||
bool broadcast = false,
|
||||
uint8_t vb_type = 0 )
|
||||
{ try {
|
||||
asset_object asset_obj = get_asset( asset_symbol );
|
||||
vector< vesting_balance_object > vbos;
|
||||
fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(witness_name);
|
||||
if( !vbid )
|
||||
{
|
||||
witness_object wit = get_witness( witness_name );
|
||||
FC_ASSERT( wit.pay_vb );
|
||||
vbid = wit.pay_vb;
|
||||
//Changes done to retrive user accounts along with witnesses accounts based on account name
|
||||
fc::optional<account_id_type> acct_id = maybe_id<account_id_type>( witness_name );
|
||||
if( !acct_id )
|
||||
acct_id = get_account( witness_name ).id;
|
||||
|
||||
vbos = _remote_db->get_vesting_balances( *acct_id );
|
||||
if( vbos.size() == 0 )
|
||||
{
|
||||
witness_object wit = get_witness( witness_name );
|
||||
FC_ASSERT( wit.pay_vb );
|
||||
vbid = wit.pay_vb;
|
||||
}
|
||||
}
|
||||
|
||||
vesting_balance_object vbo = get_object< vesting_balance_object >( *vbid );
|
||||
vesting_balance_withdraw_operation vesting_balance_withdraw_op;
|
||||
|
||||
vesting_balance_withdraw_op.vesting_balance = *vbid;
|
||||
vesting_balance_withdraw_op.owner = vbo.owner;
|
||||
vesting_balance_withdraw_op.amount = asset_obj.amount_from_string(amount);
|
||||
|
||||
//whether it is a witness or user, keep in container and iterate over it process all vesting balances and types
|
||||
if(!vbos.size())
|
||||
vbos.emplace_back( get_object<vesting_balance_object>(*vbid) );
|
||||
|
||||
signed_transaction tx;
|
||||
tx.operations.push_back( vesting_balance_withdraw_op );
|
||||
asset withdraw_amount = asset_obj.amount_from_string(amount);
|
||||
|
||||
for(const vesting_balance_object& vbo: vbos )
|
||||
{
|
||||
if((vb_type == (uint8_t)vbo.balance_type) && vbo.balance.amount > 0)
|
||||
{
|
||||
fc::optional<vesting_balance_id_type> vest_id = vbo.id;
|
||||
vesting_balance_withdraw_operation vesting_balance_withdraw_op;
|
||||
|
||||
vesting_balance_withdraw_op.vesting_balance = *vest_id;
|
||||
vesting_balance_withdraw_op.owner = vbo.owner;
|
||||
if(withdraw_amount.amount >= vbo.balance.amount)
|
||||
{
|
||||
vesting_balance_withdraw_op.amount = vbo.balance.amount;
|
||||
withdraw_amount.amount -= vbo.balance.amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
vesting_balance_withdraw_op.amount = withdraw_amount.amount;
|
||||
tx.operations.push_back( vesting_balance_withdraw_op );
|
||||
withdraw_amount.amount -= vbo.balance.amount;
|
||||
break;
|
||||
}
|
||||
|
||||
tx.operations.push_back( vesting_balance_withdraw_op );
|
||||
}
|
||||
}
|
||||
|
||||
if( withdraw_amount.amount > 0)
|
||||
FC_THROW("Account has insufficient balance to withdraw");
|
||||
|
||||
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees );
|
||||
tx.validate();
|
||||
|
||||
|
|
@ -4045,9 +4083,10 @@ signed_transaction wallet_api::withdraw_vesting(
|
|||
string witness_name,
|
||||
string amount,
|
||||
string asset_symbol,
|
||||
bool broadcast /* = false */)
|
||||
bool broadcast,
|
||||
uint8_t vb_type)
|
||||
{
|
||||
return my->withdraw_vesting( witness_name, amount, asset_symbol, broadcast );
|
||||
return my->withdraw_vesting( witness_name, amount, asset_symbol, broadcast, vb_type );
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::vote_for_committee_member(string voting_account,
|
||||
|
|
@ -5783,7 +5822,7 @@ signed_transaction wallet_api::create_vesting_balance(string owner,
|
|||
|
||||
fc::optional<asset_object> asset_obj = get_asset(asset_symbol);
|
||||
|
||||
auto type = vesting_balance_type::unspecified;
|
||||
auto type = vesting_balance_type::normal;
|
||||
if(is_gpos)
|
||||
type = vesting_balance_type::gpos;
|
||||
|
||||
|
|
@ -5856,7 +5895,10 @@ vesting_balance_object_with_info::vesting_balance_object_with_info( const vestin
|
|||
: vesting_balance_object( vbo )
|
||||
{
|
||||
allowed_withdraw = get_allowed_withdraw( now );
|
||||
allowed_withdraw_time = now;
|
||||
if(vbo.balance_type == vesting_balance_type::gpos)
|
||||
allowed_withdraw_time = vbo.policy.get<linear_vesting_policy>().begin_timestamp + vbo.policy.get<linear_vesting_policy>().vesting_cliff_seconds;
|
||||
else
|
||||
allowed_withdraw_time = now;
|
||||
}
|
||||
|
||||
} } // graphene::wallet
|
||||
|
|
|
|||
Loading…
Reference in a new issue