Skip to content

Commit

Permalink
steemit#3371: Implementation of contribution hard cap enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Jun 29, 2019
1 parent db709db commit 906d80d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class smt_ico_object : public object< smt_ico_object_type, smt_ico_object >
time_point_sec launch_time;
share_type steem_units_soft_cap = -1;
share_type steem_units_hard_cap = -1;
asset contributed = asset( 0, STEEM_SYMBOL );
};

class smt_token_emissions_object : public object< smt_token_emissions_object_type, smt_token_emissions_object >
Expand Down Expand Up @@ -311,6 +312,7 @@ FC_REFLECT( steem::chain::smt_ico_object,
(launch_time)
(steem_units_soft_cap)
(steem_units_hard_cap)
(contributed)
)

FC_REFLECT( steem::chain::smt_token_emissions_object,
Expand Down
11 changes: 10 additions & 1 deletion libraries/chain/smt_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,16 @@ void smt_contribute_evaluator::do_apply( const smt_contribute_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );

FC_ASSERT( _db.get_balance( o.contributor, o.contribution.symbol ) >= o.contribution, "Account does not have sufficient funds for contribution" );

const smt_token_object* token = util::smt::find_token( _db, o.symbol );
FC_ASSERT( token != nullptr, "Cannot contribute to an unknown SMT" );
FC_ASSERT( token->phase >= smt_phase::contribution_begin_time_completed, "SMT has yet to enter the contribution phase" );
FC_ASSERT( token->phase < smt_phase::contribution_end_time_completed, "SMT is no longer in the contribution phase" );

FC_ASSERT( _db.get_balance( o.contributor, o.contribution.symbol ) >= o.contribution, "Account does not have sufficient funds for contribution" );
const smt_ico_object* token_ico = db.find< smt_ico_object, by_symbol >( token->liquid_symbol );
FC_ASSERT( token_ico != nullptr, "Unable to find ICO data for symbol: ${sym}", ("sym", token->liquid_symbol) );
FC_ASSERT( token_ico->contributed.amount < token_ico->steem_units_hard_cap, "SMT ICO has reached its hard cap and no longer accepts contributions" );

auto key = boost::tuple< asset_symbol_type, account_name_type, uint32_t >( o.contribution.symbol, o.contributor, o.contribution_id );
auto contrib_ptr = _db.find< smt_contribution_object, by_symbol_contributor >( key );
Expand All @@ -318,6 +322,11 @@ void smt_contribute_evaluator::do_apply( const smt_contribute_operation& o )
obj.contribution_id = o.contribution_id;
obj.contribution = o.contribution;
} );

_db.modify( *token_ico, [&]( smt_ico_object& ico )
{
ico.contributed += o.contribution;
} );
}
FC_CAPTURE_AND_RETHROW( (o) )
}
Expand Down

0 comments on commit 906d80d

Please sign in to comment.