Skip to content

Commit

Permalink
steemit#3595: Rename steem_units_cap to steem_satoshi_cap
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Feb 8, 2020
1 parent 1c7e88d commit f36d5b0
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class smt_ico_tier_object : public object< smt_ico_tier_object_type, smt_ico_tie

id_type id;
asset_symbol_type symbol;
share_type steem_units_cap = -1;
share_type steem_satoshi_cap = -1;
shared_smt_generation_unit generation_unit;
};

Expand Down Expand Up @@ -379,17 +379,17 @@ typedef multi_index_container <
allocator< smt_ico_object >
> smt_ico_index;

struct by_symbol_steem_units_cap;
struct by_symbol_steem_satoshi_cap;

typedef multi_index_container <
smt_ico_tier_object,
indexed_by <
ordered_unique< tag< by_id >,
member< smt_ico_tier_object, smt_ico_tier_object_id_type, &smt_ico_tier_object::id > >,
ordered_unique< tag< by_symbol_steem_units_cap >,
ordered_unique< tag< by_symbol_steem_satoshi_cap >,
composite_key< smt_ico_tier_object,
member< smt_ico_tier_object, asset_symbol_type, &smt_ico_tier_object::symbol >,
member< smt_ico_tier_object, share_type, &smt_ico_tier_object::steem_units_cap >
member< smt_ico_tier_object, share_type, &smt_ico_tier_object::steem_satoshi_cap >
>,
composite_key_compare< std::less< asset_symbol_type >, std::less< share_type > >
>
Expand Down Expand Up @@ -489,7 +489,7 @@ FC_REFLECT( steem::chain::shared_smt_generation_unit,
FC_REFLECT( steem::chain::smt_ico_tier_object,
(id)
(symbol)
(steem_units_cap)
(steem_satoshi_cap)
(generation_unit)
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steem/chain/util/smt_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool schedule_next_contributor_payout( database& db, const asset_symbol_type& a
bool schedule_founder_payout( database& db, const asset_symbol_type& a );

share_type payout( database& db, const asset_symbol_type& symbol, const account_object& account, const std::vector< contribution_payout >& payouts );
fc::optional< share_type > steem_units_hard_cap( database& db, const asset_symbol_type& a );
fc::optional< share_type > steem_hard_cap( database& db, const asset_symbol_type& a );
std::size_t ico_tier_size( database& db, const asset_symbol_type& symbol );
void remove_ico_objects( database& db, const asset_symbol_type& symbol );

Expand Down
14 changes: 7 additions & 7 deletions libraries/chain/smt_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void smt_setup_evaluator::do_apply( const smt_setup_operation& o )

if ( o.steem_satoshi_min > 0 )
{
auto possible_hard_cap = util::smt::ico::steem_units_hard_cap( _db, o.symbol );
auto possible_hard_cap = util::smt::ico::steem_hard_cap( _db, o.symbol );

FC_ASSERT( possible_hard_cap.valid(),
"An SMT with a Steem Satoshi Minimum of ${s} cannot succeed without an ICO tier.", ("s", o.steem_satoshi_min) );
Expand Down Expand Up @@ -218,12 +218,12 @@ void smt_setup_ico_tier_evaluator::do_apply( const smt_setup_ico_tier_operation&

if ( o.remove )
{
auto key = boost::make_tuple( token.liquid_symbol, o.steem_units_cap );
const auto* ito = _db.find< smt_ico_tier_object, by_symbol_steem_units_cap >( key );
auto key = boost::make_tuple( token.liquid_symbol, o.steem_satoshi_cap );
const auto* ito = _db.find< smt_ico_tier_object, by_symbol_steem_satoshi_cap >( key );

FC_ASSERT( ito != nullptr,
"The specified ICO tier does not exist. Symbol: ${s}, Steem Units Cap: ${c}",
("s", token.liquid_symbol)("c", o.steem_units_cap)
"The specified ICO tier does not exist. Symbol: ${s}, Steem Satoshi Cap: ${c}",
("s", token.liquid_symbol)("c", o.steem_satoshi_cap)
);

_db.remove( *ito );
Expand All @@ -240,7 +240,7 @@ void smt_setup_ico_tier_evaluator::do_apply( const smt_setup_ico_tier_operation&
_db.create< smt_ico_tier_object >( [&]( smt_ico_tier_object& ito )
{
ito.symbol = token.liquid_symbol;
ito.steem_units_cap = o.steem_units_cap;
ito.steem_satoshi_cap = o.steem_satoshi_cap;
ito.generation_unit = generation_policy.generation_unit;
});
}
Expand Down Expand Up @@ -374,7 +374,7 @@ void smt_contribute_evaluator::do_apply( const smt_contribute_operation& o )
FC_ASSERT( token->phase >= smt_phase::ico, "SMT has not begun accepting contributions" );
FC_ASSERT( token->phase < smt_phase::ico_completed, "SMT is no longer accepting contributions" );

auto possible_hard_cap = util::smt::ico::steem_units_hard_cap( _db, o.symbol );
auto possible_hard_cap = util::smt::ico::steem_hard_cap( _db, o.symbol );
FC_ASSERT( possible_hard_cap.valid(), "The specified token does not feature an ICO" );
share_type hard_cap = *possible_hard_cap;

Expand Down
26 changes: 13 additions & 13 deletions libraries/chain/util/smt_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static payout_vars calculate_payout_vars( database& db, const smt_ico_object& ic
{
payout_vars vars;

auto hard_cap = util::smt::ico::steem_units_hard_cap( db, ico.symbol );
auto hard_cap = util::smt::ico::steem_hard_cap( db, ico.symbol );
FC_ASSERT( hard_cap.valid(), "Unable to find ICO hard cap." );
share_type steem_hard_cap = *hard_cap;

Expand Down Expand Up @@ -239,7 +239,7 @@ bool schedule_next_contributor_payout( database& db, const asset_symbol_type& a
payout_action.symbol = itr->symbol;

const auto& ico = db.get< smt_ico_object, by_symbol >( itr->symbol );
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();

using generation_unit_share = std::tuple< smt_generation_unit, share_type >;

Expand All @@ -251,8 +251,8 @@ bool schedule_next_contributor_payout( database& db, const asset_symbol_type& a
{
auto tier_contributions = unprocessed_contributions;

if ( ico.processed_contributions + unprocessed_contributions > ico_tier->steem_units_cap )
tier_contributions = ico_tier->steem_units_cap - ico.processed_contributions;
if ( ico.processed_contributions + unprocessed_contributions > ico_tier->steem_satoshi_cap )
tier_contributions = ico_tier->steem_satoshi_cap - ico.processed_contributions;

generation_unit_shares.push_back( std::make_tuple( ico_tier->generation_unit, tier_contributions ) );

Expand Down Expand Up @@ -322,7 +322,7 @@ bool schedule_founder_payout( database& db, const asset_symbol_type& a )
{
bool action_scheduled = false;
const auto& ico = db.get< smt_ico_object, by_symbol >( a );
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();

using generation_unit_share = std::tuple< smt_generation_unit, share_type >;

Expand All @@ -334,12 +334,12 @@ bool schedule_founder_payout( database& db, const asset_symbol_type& a )
{
auto tier_contributions = unprocessed_contributions;

if ( ico.contributed.amount > ico_tier->steem_units_cap )
if ( ico.contributed.amount > ico_tier->steem_satoshi_cap )
{
if ( last_ico_tier != ico_tier_idx.end() )
tier_contributions = last_ico_tier->steem_units_cap - ico_tier->steem_units_cap;
tier_contributions = last_ico_tier->steem_satoshi_cap - ico_tier->steem_satoshi_cap;
else
tier_contributions = ico_tier->steem_units_cap;
tier_contributions = ico_tier->steem_satoshi_cap;
}

generation_unit_shares.push_back( std::make_tuple( ico_tier->generation_unit, tier_contributions ) );
Expand Down Expand Up @@ -443,17 +443,17 @@ bool schedule_founder_payout( database& db, const asset_symbol_type& a )
return action_scheduled;
}

fc::optional< share_type > steem_units_hard_cap( database& db, const asset_symbol_type& a )
fc::optional< share_type > steem_hard_cap( database& db, const asset_symbol_type& a )
{
const auto& idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();

const auto range = idx.equal_range( a );

auto itr = range.second;
while ( itr != range.first )
{
--itr;
return itr->steem_units_cap;
return itr->steem_satoshi_cap;
}

return {};
Expand All @@ -463,7 +463,7 @@ void remove_ico_objects( database& db, const asset_symbol_type& symbol )
{
db.remove( db.get< smt_ico_object, by_symbol >( symbol ) );

const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();
auto itr = ico_tier_idx.lower_bound( symbol );
while( itr != ico_tier_idx.end() && itr->symbol == symbol )
{
Expand All @@ -478,7 +478,7 @@ std::size_t ico_tier_size( database& db, const asset_symbol_type& symbol )
{
std::size_t num_ico_tiers = 0;

const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();
auto ico_tier_itr = ico_tier_idx.lower_bound( symbol );
while ( ico_tier_itr != ico_tier_idx.end() && ico_tier_itr->symbol == symbol )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ namespace steem { namespace plugins { namespace condenser_api {
legacy_smt_setup_ico_tier_operation( const smt_setup_ico_tier_operation& op ) :
control_account( op.control_account ),
symbol( op.symbol ),
steem_units_cap( op.steem_units_cap ),
steem_satoshi_cap( op.steem_satoshi_cap ),
remove( op.remove )
{
op.generation_policy.visit( convert_to_legacy_static_variant< legacy_smt_generation_policy >( generation_policy ) );
Expand All @@ -788,7 +788,7 @@ namespace steem { namespace plugins { namespace condenser_api {
smt_setup_ico_tier_operation op;
op.control_account = control_account;
op.symbol = symbol;
op.steem_units_cap = steem_units_cap;
op.steem_satoshi_cap = steem_satoshi_cap;
op.generation_policy = generation_policy;
op.remove = remove;

Expand All @@ -798,7 +798,7 @@ namespace steem { namespace plugins { namespace condenser_api {
account_name_type control_account;
asset_symbol_type symbol;

share_type steem_units_cap;
share_type steem_satoshi_cap;
legacy_smt_generation_policy generation_policy;
bool remove = false;
extensions_type extensions;
Expand Down Expand Up @@ -1910,7 +1910,7 @@ FC_REFLECT( steem::plugins::condenser_api::legacy_curation_reward_operation, (cu
FC_REFLECT( steem::plugins::condenser_api::legacy_comment_reward_operation, (author)(permlink)(payout) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_operation, (control_account)(symbol)(max_supply)(contribution_begin_time)(contribution_end_time)(launch_time)(steem_satoshi_min)(min_unit_ratio)(max_unit_ratio)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_set_setup_parameters_operation, (control_account)(symbol)(setup_parameters)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_ico_tier_operation, (control_account)(symbol)(steem_units_cap)(generation_policy)(remove)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_ico_tier_operation, (control_account)(symbol)(steem_satoshi_cap)(generation_policy)(remove)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_set_runtime_parameters_operation, (control_account)(symbol)(runtime_parameters)(extensions))
FC_REFLECT( steem::plugins::condenser_api::legacy_fill_convert_request_operation, (owner)(requestid)(amount_in)(amount_out) )
FC_REFLECT( steem::plugins::condenser_api::legacy_liquidity_reward_operation, (owner)(payout) )
Expand Down
4 changes: 2 additions & 2 deletions libraries/protocol/include/steem/protocol/smt_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct smt_setup_ico_tier_operation : public base_operation
account_name_type control_account;
asset_symbol_type symbol;

share_type steem_units_cap;
share_type steem_satoshi_cap;
smt_generation_policy generation_policy;
bool remove = false;

Expand Down Expand Up @@ -267,7 +267,7 @@ FC_REFLECT(
steem::protocol::smt_setup_ico_tier_operation,
(control_account)
(symbol)
(steem_units_cap)
(steem_satoshi_cap)
(generation_policy)
(remove)
(extensions)
Expand Down
4 changes: 2 additions & 2 deletions libraries/protocol/smt_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void smt_setup_ico_tier_operation::validate()const
{
smt_admin_operation_validate( *this );

FC_ASSERT( steem_units_cap >= 0, "Steem units cap must be greater than or equal to 0" );
FC_ASSERT( steem_units_cap <= STEEM_MAX_SHARE_SUPPLY, "Steem units cap must be less than or equal to ${n}", ("n", STEEM_MAX_SHARE_SUPPLY) );
FC_ASSERT( steem_satoshi_cap >= 0, "Steem satoshi cap must be greater than or equal to 0" );
FC_ASSERT( steem_satoshi_cap <= STEEM_MAX_SHARE_SUPPLY, "Steem satoshi cap must be less than or equal to ${n}", ("n", STEEM_MAX_SHARE_SUPPLY) );

validate_visitor vtor;
generation_policy.visit( vtor );
Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/include/steem/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,14 +1279,14 @@ class wallet_api
*
* @param control_account The name of the controlling account
* @param symbol The asset symbol of the created token
* @param steem_units_cap The maximum amount of STEEM this ICO tier applies to
* @param steem_satoshi_cap The maximum amount of STEEM this ICO tier applies to
* @param json_generation_policy The steem and token destination routes of the ICO process
* @param broadcast To broadcast this transaction or not
*/
condenser_api::legacy_signed_transaction smt_setup_ico_tier(
account_name_type control_account,
asset_symbol_type symbol,
share_type steem_units_cap,
share_type steem_satoshi_cap,
string json_generation_policy,
bool broadcast );

Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ condenser_api::legacy_signed_transaction wallet_api::follow( string follower, st
condenser_api::legacy_signed_transaction wallet_api::smt_setup_ico_tier(
account_name_type control_account,
asset_symbol_type symbol,
share_type steem_units_cap,
share_type steem_satoshi_cap,
string json_generation_policy,
bool broadcast )
{
Expand All @@ -2724,7 +2724,7 @@ condenser_api::legacy_signed_transaction wallet_api::follow( string follower, st
op.control_account = control_account;
op.symbol = symbol;
op.generation_policy = fc::json::from_string( json_generation_policy ).as< smt_generation_policy >();
op.steem_units_cap = steem_units_cap;
op.steem_satoshi_cap = steem_satoshi_cap;

signed_transaction trx;
trx.operations.push_back( op );
Expand Down
20 changes: 10 additions & 10 deletions tests/tests/smt_operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2957,13 +2957,13 @@ BOOST_AUTO_TEST_CASE( smt_contribute_apply )
db.create< smt_ico_tier_object >( [&]( smt_ico_tier_object& o )
{
o.symbol = alice_symbol;
o.steem_units_cap = 1000;
o.steem_satoshi_cap = 1000;
} );

db.create< smt_ico_tier_object >( [&]( smt_ico_tier_object& o )
{
o.symbol = alice_symbol;
o.steem_units_cap = 99000;
o.steem_satoshi_cap = 99000;
} );
} );

Expand Down Expand Up @@ -4891,7 +4891,7 @@ BOOST_AUTO_TEST_CASE( smt_setup_ico_tier_validate )
smt_setup_ico_tier_operation op;
op.control_account = "alice";
op.symbol = symbol;
op.steem_units_cap = 0;
op.steem_satoshi_cap = 0;

smt_capped_generation_policy valid_capped_generation_policy;
valid_capped_generation_policy.generation_unit.steem_unit[ "alice" ] = 2;
Expand All @@ -4914,16 +4914,16 @@ BOOST_AUTO_TEST_CASE( smt_setup_ico_tier_validate )
BOOST_REQUIRE_THROW( op.validate(), fc::assert_exception );
op.control_account = "alice";

BOOST_TEST_MESSAGE( " -- Failure on negative steem_units_cap" );
op.steem_units_cap = -1;
BOOST_TEST_MESSAGE( " -- Failure on negative steem_satoshi_cap" );
op.steem_satoshi_cap = -1;
BOOST_REQUIRE_THROW( op.validate(), fc::assert_exception );

op.steem_units_cap = 0;
BOOST_TEST_MESSAGE( " -- Success on steem_units_cap" );
op.steem_satoshi_cap = 0;
BOOST_TEST_MESSAGE( " -- Success on steem_satoshi_cap" );
op.validate();

op.steem_units_cap = 1000;
BOOST_TEST_MESSAGE( " -- Success on positive steem_units_cap" );
op.steem_satoshi_cap = 1000;
BOOST_TEST_MESSAGE( " -- Success on positive steem_satoshi_cap" );
op.validate();

BOOST_TEST_MESSAGE( " -- Failure on SMT_DESTINATION_REWARDS in steem_unit" );
Expand Down Expand Up @@ -5057,7 +5057,7 @@ BOOST_AUTO_TEST_CASE( smt_setup_ico_tier_apply )
smt_setup_ico_tier_operation op;
op.control_account = "alice";
op.symbol = symbol;
op.steem_units_cap = 0;
op.steem_satoshi_cap = 0;

smt_capped_generation_policy valid_capped_generation_policy;
valid_capped_generation_policy.generation_unit.steem_unit[ "alice" ] = 2;
Expand Down
Loading

0 comments on commit f36d5b0

Please sign in to comment.