Progress #98: restrict withdrawal rate of vesting genesis balances
This commit is contained in:
parent
256b95ac5e
commit
9cb9d2e07f
4 changed files with 11 additions and 3 deletions
|
|
@ -389,7 +389,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
{
|
||||
create<balance_object>([&](balance_object& b) {
|
||||
b.owner = vest.owner;
|
||||
b.balance = asset( vest.amount, assets_by_symbol.find( vest.asset_symbol )->get_id() );
|
||||
b.balance = asset(vest.amount, assets_by_symbol.find(vest.asset_symbol)->get_id());
|
||||
|
||||
linear_vesting_policy policy;
|
||||
policy.begin_timestamp = vest.begin_timestamp;
|
||||
|
|
@ -397,7 +397,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
policy.vesting_duration_seconds = vest.vesting_duration_seconds;
|
||||
policy.begin_balance = vest.begin_balance;
|
||||
|
||||
b.vesting_policy = std::move( policy );
|
||||
b.vesting_policy = std::move(policy);
|
||||
});
|
||||
total_allocation += vest.amount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <graphene/chain/transaction_evaluation_state.hpp>
|
||||
#include <graphene/chain/balance_object.hpp>
|
||||
#include <graphene/chain/evaluator.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
|
|
@ -34,6 +35,9 @@ public:
|
|||
|
||||
if( balance->vesting_policy.valid() ) {
|
||||
FC_ASSERT(op.total_claimed.amount == 0);
|
||||
if( d.head_block_time() - balance->last_claim_date < fc::days(1) )
|
||||
FC_THROW_EXCEPTION(balance_claimed_too_often,
|
||||
"Genesis vesting balances may not be claimed more than once per day.");
|
||||
return amount_withdrawn = balance->vesting_policy->get_allowed_withdraw({balance->balance,
|
||||
d.head_block_time(),
|
||||
{}});
|
||||
|
|
@ -55,6 +59,7 @@ public:
|
|||
d.modify(*balance, [&](balance_object& b) {
|
||||
b.vesting_policy->on_withdraw({b.balance, d.head_block_time(), amount_withdrawn});
|
||||
b.balance -= amount_withdrawn;
|
||||
b.last_claim_date = d.head_block_time();
|
||||
});
|
||||
else
|
||||
d.remove(*balance);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace graphene { namespace chain {
|
|||
address owner;
|
||||
asset balance;
|
||||
optional<linear_vesting_policy> vesting_policy;
|
||||
time_point_sec last_claim_date;
|
||||
asset_id_type asset_type()const { return balance.asset_id; }
|
||||
};
|
||||
|
||||
|
|
@ -39,4 +40,5 @@ namespace graphene { namespace chain {
|
|||
using balance_index = generic_index<balance_object, balance_multi_index_type>;
|
||||
} }
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::balance_object, (graphene::db::object), (owner)(balance)(vesting_policy) )
|
||||
FC_REFLECT_DERIVED( graphene::chain::balance_object, (graphene::db::object),
|
||||
(owner)(balance)(vesting_policy)(last_claim_date) )
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ namespace graphene { namespace chain {
|
|||
FC_DECLARE_DERIVED_EXCEPTION( expired_transaction, graphene::chain::evaluation_error, 31010, "expired transaction" );
|
||||
FC_DECLARE_DERIVED_EXCEPTION( invalid_transaction_expiration, graphene::chain::evaluation_error, 31011, "invalid transaction expiration" );
|
||||
FC_DECLARE_DERIVED_EXCEPTION( oversized_transaction, graphene::chain::evaluation_error, 31012, "transaction exceeded the maximum transaction size" );
|
||||
FC_DECLARE_DERIVED_EXCEPTION( balance_claimed_too_often, graphene::chain::evaluation_error, 31013, "balance claimed too often" );
|
||||
|
||||
FC_DECLARE_DERIVED_EXCEPTION( invalid_account_name, graphene::chain::evaluation_error, 32001, "invalid account name" );
|
||||
FC_DECLARE_DERIVED_EXCEPTION( unknown_account_id, graphene::chain::evaluation_error, 32002, "unknown account id" );
|
||||
|
|
|
|||
Loading…
Reference in a new issue