From 5e91e095c04bde597ad44ca28100d2262aacf121 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 27 Oct 2015 15:00:57 -0400 Subject: [PATCH] vesting_balance_object.cpp: Handle vesting_seconds == 0 case #390 --- libraries/chain/vesting_balance_object.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 296e4cea..fc32a249 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -94,7 +94,7 @@ fc::uint128_t cdd_vesting_policy::compute_coin_seconds_earned(const vesting_poli delta_coin_seconds *= delta_seconds; fc::uint128_t coin_seconds_earned_cap = ctx.balance.amount.value; - coin_seconds_earned_cap *= vesting_seconds; + coin_seconds_earned_cap *= std::max(vesting_seconds, 1u); return std::min(coin_seconds_earned + delta_coin_seconds, coin_seconds_earned_cap); } @@ -110,7 +110,7 @@ asset cdd_vesting_policy::get_allowed_withdraw(const vesting_policy_context& ctx if(ctx.now <= start_claim) return asset(0, ctx.balance.asset_id); fc::uint128_t cs_earned = compute_coin_seconds_earned(ctx); - fc::uint128_t withdraw_available = cs_earned / vesting_seconds; + fc::uint128_t withdraw_available = cs_earned / std::max(vesting_seconds, 1u); assert(withdraw_available <= ctx.balance.amount.value); return asset(withdraw_available.to_uint64(), ctx.balance.asset_id); } @@ -123,14 +123,14 @@ void cdd_vesting_policy::on_deposit(const vesting_policy_context& ctx) void cdd_vesting_policy::on_deposit_vested(const vesting_policy_context& ctx) { on_deposit(ctx); - coin_seconds_earned += ctx.amount.amount.value * vesting_seconds; + coin_seconds_earned += ctx.amount.amount.value * std::max(vesting_seconds, 1u); } void cdd_vesting_policy::on_withdraw(const vesting_policy_context& ctx) { update_coin_seconds_earned(ctx); fc::uint128_t coin_seconds_needed = ctx.amount.amount.value; - coin_seconds_needed *= vesting_seconds; + coin_seconds_needed *= std::max(vesting_seconds, 1u); // is_withdraw_allowed should forbid any withdrawal that // would trigger this assert assert(coin_seconds_needed <= coin_seconds_earned);