From 4a72f943e8347fd1125d258015632c9fc9361de0 Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Sat, 21 Sep 2019 13:04:43 -0300
Subject: [PATCH 1/2] fix for get_vesting_balance API call
---
libraries/chain/vesting_balance_object.cpp | 35 ++++++++++++++--------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp
index 73448e04..794413d1 100644
--- a/libraries/chain/vesting_balance_object.cpp
+++ b/libraries/chain/vesting_balance_object.cpp
@@ -35,6 +35,7 @@ inline bool sum_below_max_shares(const asset& a, const asset& b)
}
asset linear_vesting_policy::get_allowed_withdraw( const vesting_policy_context& ctx )const
+{
{
share_type allowed_withdraw = 0;
@@ -45,23 +46,33 @@ asset linear_vesting_policy::get_allowed_withdraw( const vesting_policy_context&
if( elapsed_seconds >= vesting_cliff_seconds )
{
- share_type total_vested = 0;
- if( elapsed_seconds < vesting_duration_seconds )
+ // BLOCKBACK-154 fix, Begin balance for linear vesting applies only to initial account balance from genesis
+ // So, for any GPOS vesting, the begin balance would be 0 and should be able to withdraw balance amount based on lockin period
+ if(begin_balance == 0)
{
- total_vested = (fc::uint128_t( begin_balance.value ) * elapsed_seconds / vesting_duration_seconds).to_uint64();
+ allowed_withdraw = ctx.balance.amount;
+ return asset( allowed_withdraw, ctx.balance.asset_id );
}
else
{
- total_vested = begin_balance;
+ share_type total_vested = 0;
+ if( elapsed_seconds < vesting_duration_seconds )
+ {
+ total_vested = (fc::uint128_t( begin_balance.value ) * elapsed_seconds / vesting_duration_seconds).to_uint64();
+ }
+ else
+ {
+ total_vested = begin_balance;
+ }
+ assert( total_vested >= 0 );
+
+ const share_type withdrawn_already = begin_balance - ctx.balance.amount;
+ assert( withdrawn_already >= 0 );
+
+ allowed_withdraw = total_vested - withdrawn_already;
+ assert( allowed_withdraw >= 0 );
}
- assert( total_vested >= 0 );
-
- const share_type withdrawn_already = begin_balance - ctx.balance.amount;
- assert( withdrawn_already >= 0 );
-
- allowed_withdraw = total_vested - withdrawn_already;
- assert( allowed_withdraw >= 0 );
- }
+ }
}
return asset( allowed_withdraw, ctx.balance.asset_id );
From a7df686ebe92e6ac25c310a714bd34d26dc6c612 Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Sat, 21 Sep 2019 13:08:33 -0300
Subject: [PATCH 2/2] braces update
---
libraries/chain/vesting_balance_object.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp
index 794413d1..afba2557 100644
--- a/libraries/chain/vesting_balance_object.cpp
+++ b/libraries/chain/vesting_balance_object.cpp
@@ -35,7 +35,6 @@ inline bool sum_below_max_shares(const asset& a, const asset& b)
}
asset linear_vesting_policy::get_allowed_withdraw( const vesting_policy_context& ctx )const
-{
{
share_type allowed_withdraw = 0;