From 2a3d8a4c66456c18a7d7bd0790477a2f59295799 Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Fri, 20 Sep 2019 11:32:07 -0300
Subject: [PATCH 1/3] changes to withdraw_vesting feature(for both cdd and
GPOS)
---
libraries/chain/db_maint.cpp | 4 +-
.../chain/include/graphene/chain/config.hpp | 1 +
.../chain/protocol/chain_parameters.hpp | 5 ++
.../graphene/chain/protocol/vesting.hpp | 4 +-
.../graphene/chain/vesting_balance_object.hpp | 2 +-
libraries/chain/proposal_evaluator.cpp | 2 +-
libraries/chain/vesting_balance_evaluator.cpp | 4 +-
.../wallet/include/graphene/wallet/wallet.hpp | 4 +-
libraries/wallet/wallet.cpp | 74 +++++++++++++++----
9 files changed, 75 insertions(+), 25 deletions(-)
diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp
index 06e15a19..81fce8f9 100644
--- a/libraries/chain/db_maint.cpp
+++ b/libraries/chain/db_maint.cpp
@@ -873,7 +873,7 @@ void schedule_pending_dividend_balances(database& db,
std::map 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;
diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp
index 7b3e8743..fd080b09 100644
--- a/libraries/chain/include/graphene/chain/config.hpp
+++ b/libraries/chain/include/graphene/chain/config.hpp
@@ -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
diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp
index 87c2e3fe..a66e4ba8 100644
--- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp
+++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp
@@ -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,
diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp
index 5a78fd65..ac995aaf 100644
--- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp
+++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp
@@ -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) )
diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp
index 6e0bd689..a94e7015 100644
--- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp
+++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp
@@ -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() {}
diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp
index 8306128d..a690ab33 100644
--- a/libraries/chain/proposal_evaluator.cpp
+++ b/libraries/chain/proposal_evaluator.cpp
@@ -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
diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp
index 0b6e192e..bd44b934 100644
--- a/libraries/chain/vesting_balance_evaluator.cpp
+++ b/libraries/chain/vesting_balance_evaluator.cpp
@@ -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;
}
diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp
index a7189138..2b8012b4 100644
--- a/libraries/wallet/include/graphene/wallet/wallet.hpp
+++ b/libraries/wallet/include/graphene/wallet/wallet.hpp
@@ -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.
*
diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp
index 46acf25e..75a90f82 100644
--- a/libraries/wallet/wallet.cpp
+++ b/libraries/wallet/wallet.cpp
@@ -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 vbid = maybe_id(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 acct_id = maybe_id( 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(*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 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_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().begin_timestamp + vbo.policy.get().vesting_cliff_seconds;
+ else
+ allowed_withdraw_time = now;
}
} } // graphene::wallet
From b358241e43fbaca0669c9ab34d4116e96822bb9d Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Fri, 20 Sep 2019 14:03:59 -0300
Subject: [PATCH 2/3] Comments update
---
libraries/wallet/wallet.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp
index 75a90f82..185fc7d1 100644
--- a/libraries/wallet/wallet.cpp
+++ b/libraries/wallet/wallet.cpp
@@ -1971,7 +1971,7 @@ public:
fc::optional vbid = maybe_id(witness_name);
if( !vbid )
{
- //Changes done to retrive user accounts along with witnesses accounts based on account name
+ //Changes done to retrive user account/witness account based on account name
fc::optional acct_id = maybe_id( witness_name );
if( !acct_id )
acct_id = get_account( witness_name ).id;
@@ -1985,7 +1985,7 @@ public:
}
}
- //whether it is a witness or user, keep in container and iterate over it process all vesting balances and types
+ //whether it is a witness or user, keep it in a container and iterate over to process all vesting balances and types
if(!vbos.size())
vbos.emplace_back( get_object(*vbid) );
From 8e1c0385589e68ce879f07bc8b131690ba9b6090 Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Fri, 20 Sep 2019 16:58:06 -0300
Subject: [PATCH 3/3] update to GPOS hardfork ref
---
.../chain/include/graphene/chain/protocol/chain_parameters.hpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp
index a66e4ba8..b020c4b4 100644
--- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp
+++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp
@@ -27,7 +27,7 @@
#include
#include
-#include
+#include <../hardfork.d/GPOS.hf>
namespace graphene { namespace chain { struct fee_schedule; } }