From c94412cb7a06d842da65b51f685759fc8a07100c Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 15 Oct 2019 20:28:04 -0300 Subject: [PATCH] add vesting balance type support --- .../include/graphene/chain/protocol/chain_parameters.hpp | 2 ++ .../chain/include/graphene/chain/protocol/vesting.hpp | 9 +++++++-- .../include/graphene/chain/vesting_balance_object.hpp | 5 +++++ libraries/chain/vesting_balance_evaluator.cpp | 7 +++++++ tests/tests/son_operations_tests.cpp | 8 ++++---- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index a71a0b18..d152bddd 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -27,6 +27,8 @@ #include #include +#include + namespace graphene { namespace chain { struct fee_schedule; } } namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp index 4915b62e..731b8804 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp @@ -24,7 +24,9 @@ #pragma once #include -namespace graphene { namespace chain { +namespace graphene { namespace chain { + + enum class vesting_balance_type { normal, gpos, son }; 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, (normal)(gpos)(son) ) diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 789442fd..fc236272 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include #include @@ -140,6 +141,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 3 types of vesting, gpos, son and the rest + vesting_balance_type balance_type = vesting_balance_type::normal; + vesting_balance_object() {} asset_id_type get_asset_id() const { return balance.asset_id; } @@ -225,4 +229,5 @@ FC_REFLECT_DERIVED(graphene::chain::vesting_balance_object, (graphene::db::objec (owner) (balance) (policy) + (balance_type) ) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index ee918fd1..3bb798f3 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -42,6 +42,12 @@ void_result vesting_balance_create_evaluator::do_evaluate( const vesting_balance FC_ASSERT( d.get_balance( creator_account.id, op.amount.asset_id ) >= op.amount ); FC_ASSERT( !op.amount.asset_id(d).is_transfer_restricted() ); + if(d.head_block_time() < HARDFORK_SON_TIME) // Todo: can be removed after gpos hf time pass + FC_ASSERT( op.balance_type == vesting_balance_type::normal); + + if(d.head_block_time() >= HARDFORK_SON_TIME && op.balance_type == vesting_balance_type::son) // Todo: hf check can be removed after pass + FC_ASSERT( op.amount.amount >= d.get_global_properties().parameters.son_vesting_amount() ); + return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -92,6 +98,7 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance // If making changes to this logic, check if those changes should also be made there as well. obj.owner = op.owner; obj.balance = op.amount; + obj.balance_type = op.balance_type; op.policy.visit( init_policy_visitor( obj.policy, op.amount.amount, now ) ); } ); diff --git a/tests/tests/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index db992544..bd45d648 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -36,8 +36,8 @@ BOOST_AUTO_TEST_CASE( create_son_test ) { vesting_balance_create_operation op; op.creator = alice_id; op.owner = alice_id; - op.amount = asset(10); - //op.balance_type = vesting_balance_type::unspecified; + op.amount = asset(50); + op.balance_type = vesting_balance_type::son; trx.operations.push_back(op); set_expiration(db, trx); @@ -51,8 +51,8 @@ BOOST_AUTO_TEST_CASE( create_son_test ) { vesting_balance_create_operation op; op.creator = alice_id; op.owner = alice_id; - op.amount = asset(10); - //op.balance_type = vesting_balance_type::unspecified; + op.amount = asset(50); + op.balance_type = vesting_balance_type::normal; trx.operations.push_back(op); set_expiration(db, trx);