Skip to content

Commit

Permalink
Merge pull request steemit#2541 from steemit/1771-claim-account-creation
Browse files Browse the repository at this point in the history
Claim Account Creation
  • Loading branch information
Michael Vandeberg authored Jun 12, 2018
2 parents 1614386 + a3fa8a0 commit 5079bca
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 29 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,8 @@ void database::initialize_evaluators()
_my->_evaluator_registry.register_evaluator< limit_order_create_evaluator >();
_my->_evaluator_registry.register_evaluator< limit_order_create2_evaluator >();
_my->_evaluator_registry.register_evaluator< limit_order_cancel_evaluator >();
_my->_evaluator_registry.register_evaluator< placeholder_a_evaluator >();
_my->_evaluator_registry.register_evaluator< placeholder_b_evaluator >();
_my->_evaluator_registry.register_evaluator< claim_account_evaluator >();
_my->_evaluator_registry.register_evaluator< create_claimed_account_evaluator >();
_my->_evaluator_registry.register_evaluator< request_account_recovery_evaluator >();
_my->_evaluator_registry.register_evaluator< recover_account_evaluator >();
_my->_evaluator_registry.register_evaluator< change_recovery_account_evaluator >();
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/steem/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ namespace steem { namespace chain {
time_point_sec last_root_post = fc::time_point_sec::min();
uint32_t post_bandwidth = 0;

share_type pending_claimed_accounts = 0;

/// This function should be used only when the account votes for a witness directly
share_type witness_vote_weight()const {
return std::accumulate( proxied_vsf_votes.begin(),
Expand Down Expand Up @@ -416,6 +418,7 @@ FC_REFLECT( steem::chain::account_object,
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
(last_post)(last_root_post)(post_bandwidth)
(pending_claimed_accounts)
)

CHAINBASE_SET_INDEX_TYPE( steem::chain::account_object, steem::chain::account_index )
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/steem/chain/steem_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ STEEM_DEFINE_EVALUATOR( escrow_transfer )
STEEM_DEFINE_EVALUATOR( escrow_approve )
STEEM_DEFINE_EVALUATOR( escrow_dispute )
STEEM_DEFINE_EVALUATOR( escrow_release )
STEEM_DEFINE_EVALUATOR( placeholder_a )
STEEM_DEFINE_EVALUATOR( placeholder_b )
STEEM_DEFINE_EVALUATOR( claim_account )
STEEM_DEFINE_EVALUATOR( create_claimed_account )
STEEM_DEFINE_EVALUATOR( request_account_recovery )
STEEM_DEFINE_EVALUATOR( recover_account )
STEEM_DEFINE_EVALUATOR( change_recovery_account )
Expand Down
57 changes: 53 additions & 4 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,14 +1867,63 @@ void report_over_production_evaluator::do_apply( const report_over_production_op
FC_ASSERT( !_db.has_hardfork( STEEM_HARDFORK_0_4 ), "report_over_production_operation is disabled." );
}

void placeholder_a_evaluator::do_apply( const placeholder_a_operation& o )
void claim_account_evaluator::do_apply( const claim_account_operation& o )
{
FC_ASSERT( false, "This is not a valid op." );
FC_ASSERT( _db.has_hardfork( STEEM_HARDFORK_0_20__1771 ), "claim_account_operation is not enabled until hardfork 20." );

const auto& creator = _db.get_account( o.creator );
const auto& wso = _db.get_witness_schedule_object();

FC_ASSERT( creator.balance >= o.fee, "Insufficient balance to create account.", ( "creator.balance", creator.balance )( "required", o.fee ) );

FC_ASSERT( o.fee >= wso.median_props.account_creation_fee, "Insufficient Fee: ${f} required, ${p} provided.",
("f", wso.median_props.account_creation_fee)
("p", o.fee) );

_db.adjust_balance( _db.get_account( STEEM_NULL_ACCOUNT ), o.fee );

_db.modify( creator, [&]( account_object& a )
{
a.balance -= o.fee;
a.pending_claimed_accounts++;
});
}

void placeholder_b_evaluator::do_apply( const placeholder_b_operation& o )
void create_claimed_account_evaluator::do_apply( const create_claimed_account_operation& o )
{
FC_ASSERT( false, "This is not a valid op" );
FC_ASSERT( _db.has_hardfork( STEEM_HARDFORK_0_20__1771 ), "create_claimed_account_operation is not enabled until hardfork 20." );

const auto& creator = _db.get_account( o.creator );
const auto& props = _db.get_dynamic_global_properties();

FC_ASSERT( creator.pending_claimed_accounts > 0, "${creator} has no claimed accounts to create", ( "creator", o.creator ) );

verify_authority_accounts_exist( _db, o.owner, o.new_account_name, authority::owner );
verify_authority_accounts_exist( _db, o.active, o.new_account_name, authority::active );
verify_authority_accounts_exist( _db, o.posting, o.new_account_name, authority::posting );

_db.modify( creator, [&]( account_object& a )
{
a.pending_claimed_accounts--;
});

_db.create< account_object >( [&]( account_object& acc )
{
initialize_account_object( acc, o.new_account_name, o.memo_key, props, false /*mined*/, o.creator, _db.get_hardfork() );
#ifndef IS_LOW_MEM
from_string( acc.json_metadata, o.json_metadata );
#endif
});

_db.create< account_authority_object >( [&]( account_authority_object& auth )
{
auth.account = o.new_account_name;
auth.owner = o.owner;
auth.active = o.active;
auth.posting = o.posting;
auth.last_owner_update = fc::time_point_sec::min();
});

}

void request_account_recovery_evaluator::do_apply( const request_account_recovery_operation& o )
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/util/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ struct get_impacted_account_visitor
_impacted.insert( op.owner );
}

void operator()( const create_claimed_account_operation& op )
{
_impacted.insert( op.creator );
_impacted.insert( op.new_account_name );
}


// vops

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ namespace steem { namespace plugins { namespace condenser_api {

typedef account_update_operation legacy_account_update_operation;
typedef comment_operation legacy_comment_operation;
typedef placeholder_a_operation legacy_placeholder_a_operation;
typedef placeholder_b_operation legacy_placeholder_b_operation;
typedef create_claimed_account_operation legacy_create_claimed_account_operation;
typedef delete_comment_operation legacy_delete_comment_operation;
typedef vote_operation legacy_vote_operation;
typedef escrow_approve_operation legacy_escrow_approve_operation;
Expand Down Expand Up @@ -955,6 +954,30 @@ namespace steem { namespace plugins { namespace condenser_api {
legacy_asset vesting_shares;
};

struct legacy_claim_account_operation
{
legacy_claim_account_operation() {}
legacy_claim_account_operation( const claim_account_operation& op ) :
creator( op.creator ),
fee( legacy_asset::from_asset( op.fee ) )
{
extensions.insert( op.extensions.begin(), op.extensions.end() );
}

operator claim_account_operation()const
{
claim_account_operation op;
op.creator = creator;
op.fee = fee;
op.extensions.insert( extensions.begin(), extensions.end() );
return op;
}

account_name_type creator;
legacy_asset fee;
extensions_type extensions;
};

typedef fc::static_variant<
legacy_vote_operation,
legacy_comment_operation,
Expand All @@ -978,8 +1001,8 @@ namespace steem { namespace plugins { namespace condenser_api {
legacy_comment_options_operation,
legacy_set_withdraw_vesting_route_operation,
legacy_limit_order_create2_operation,
legacy_placeholder_a_operation,
legacy_placeholder_b_operation,
legacy_claim_account_operation,
legacy_create_claimed_account_operation,
legacy_request_account_recovery_operation,
legacy_recover_account_operation,
legacy_change_recovery_account_operation,
Expand Down Expand Up @@ -1026,8 +1049,7 @@ namespace steem { namespace plugins { namespace condenser_api {

bool operator()( const account_update_operation& op )const { l_op = op; return true; }
bool operator()( const comment_operation& op )const { l_op = op; return true; }
bool operator()( const placeholder_a_operation& op )const { l_op = op; return true; }
bool operator()( const placeholder_b_operation& op )const { l_op = op; return true; }
bool operator()( const create_claimed_account_operation& op )const { l_op = op; return true; }
bool operator()( const delete_comment_operation& op )const { l_op = op; return true; }
bool operator()( const vote_operation& op )const { l_op = op; return true; }
bool operator()( const escrow_approve_operation& op )const { l_op = op; return true; }
Expand Down Expand Up @@ -1233,6 +1255,12 @@ namespace steem { namespace plugins { namespace condenser_api {
return true;
}

bool operator()( const claim_account_operation& op )const
{
l_op = legacy_claim_account_operation( op );
return true;
}


// Should only be SMT ops
template< typename T >
Expand Down Expand Up @@ -1395,6 +1423,11 @@ struct convert_from_legacy_operation_visitor
return operation( producer_reward_operation( op ) );
}

operation operator()( const legacy_claim_account_operation& op )const
{
return operation( claim_account_operation( op ) );
}

template< typename T >
operation operator()( const T& t )const
{
Expand Down Expand Up @@ -1516,5 +1549,6 @@ FC_REFLECT( steem::plugins::condenser_api::legacy_fill_transfer_from_savings_ope
FC_REFLECT( steem::plugins::condenser_api::legacy_return_vesting_delegation_operation, (account)(vesting_shares) )
FC_REFLECT( steem::plugins::condenser_api::legacy_comment_benefactor_reward_operation, (benefactor)(author)(permlink)(reward) )
FC_REFLECT( steem::plugins::condenser_api::legacy_producer_reward_operation, (producer)(vesting_shares) )
FC_REFLECT( steem::plugins::condenser_api::legacy_claim_account_operation, (creator)(fee)(extensions) )

FC_REFLECT_TYPENAME( steem::plugins::condenser_api::legacy_operation )
1 change: 1 addition & 0 deletions libraries/protocol/hardfork.d/0_20.hf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define STEEM_HARDFORK_0_20__1761 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1764 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1765 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1771 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1782 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1811 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1815 (STEEM_HARDFORK_0_20)
Expand Down
4 changes: 2 additions & 2 deletions libraries/protocol/include/steem/protocol/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace steem { namespace protocol {
comment_options_operation,
set_withdraw_vesting_route_operation,
limit_order_create2_operation,
placeholder_a_operation, // A new op can go here
placeholder_b_operation, // A new op can go here
claim_account_operation,
create_claimed_account_operation,
request_account_recovery_operation,
recover_account_operation,
change_recovery_account_operation,
Expand Down
30 changes: 23 additions & 7 deletions libraries/protocol/include/steem/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace steem { namespace protocol {
*max_accepted_payout = foundI->second.get<votable_asset_info_v1>().max_accepted_payout;
if(allow_curation_rewards != nullptr)
*allow_curation_rewards = foundI->second.get<votable_asset_info_v1>().allow_curation_rewards;

return true;
}

Expand Down Expand Up @@ -202,14 +202,30 @@ namespace steem { namespace protocol {
};


struct placeholder_a_operation : public base_operation
struct claim_account_operation : public base_operation
{
void validate()const;
account_name_type creator;
asset fee;
extensions_type extensions;

void get_required_active_authorities( flat_set< account_name_type >& a ) const { a.insert( creator ); }
void validate() const;
};

struct placeholder_b_operation : public base_operation

struct create_claimed_account_operation : public base_operation
{
void validate()const;
account_name_type creator;
account_name_type new_account_name;
authority owner;
authority active;
authority posting;
public_key_type memo_key;
string json_metadata;
extensions_type extensions;

void get_required_active_authorities( flat_set< account_name_type >& a ) const { a.insert( creator ); }
void validate() const;
};


Expand Down Expand Up @@ -1126,8 +1142,8 @@ FC_REFLECT( steem::protocol::escrow_transfer_operation, (from)(to)(sbd_amount)(s
FC_REFLECT( steem::protocol::escrow_approve_operation, (from)(to)(agent)(who)(escrow_id)(approve) );
FC_REFLECT( steem::protocol::escrow_dispute_operation, (from)(to)(agent)(who)(escrow_id) );
FC_REFLECT( steem::protocol::escrow_release_operation, (from)(to)(agent)(who)(receiver)(escrow_id)(sbd_amount)(steem_amount) );
FC_REFLECT( steem::protocol::placeholder_a_operation, );
FC_REFLECT( steem::protocol::placeholder_b_operation, );
FC_REFLECT( steem::protocol::claim_account_operation, (creator)(fee)(extensions) );
FC_REFLECT( steem::protocol::create_claimed_account_operation, (creator)(new_account_name)(owner)(active)(posting)(memo_key)(json_metadata)(extensions) );
FC_REFLECT( steem::protocol::request_account_recovery_operation, (recovery_account)(account_to_recover)(new_owner_authority)(extensions) );
FC_REFLECT( steem::protocol::recover_account_operation, (account_to_recover)(new_owner_authority)(recent_owner_authority)(extensions) );
FC_REFLECT( steem::protocol::change_recovery_account_operation, (account_to_recover)(new_recovery_account)(extensions) );
Expand Down
27 changes: 21 additions & 6 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,29 @@ namespace steem { namespace protocol {
validate_account_name( author );
}

void placeholder_a_operation::validate()const
void claim_account_operation::validate()const
{
FC_ASSERT( false, "This is not a valid op" );
validate_account_name( creator );
FC_ASSERT( is_asset_type( fee, STEEM_SYMBOL ), "Account creation fee must be STEEM" );
FC_ASSERT( fee >= asset( 0, STEEM_SYMBOL ), "Account creation fee cannot be negative" );
FC_ASSERT( extensions.size() == 0, "There are no extensions for claim_account_operation." );
}

void placeholder_b_operation::validate()const
void create_claimed_account_operation::validate()const
{
FC_ASSERT( false, "This is not a valid op" );
validate_account_name( creator );
validate_account_name( new_account_name );
owner.validate();
active.validate();
posting.validate();

if( json_metadata.size() > 0 )
{
FC_ASSERT( fc::is_utf8(json_metadata), "JSON Metadata not formatted in UTF8" );
FC_ASSERT( fc::json::is_valid(json_metadata), "JSON Metadata not valid JSON" );
}

FC_ASSERT( extensions.size() == 0, "There are no extensions for create_claimed_account_operation." );
}

void vote_operation::validate() const
Expand Down Expand Up @@ -642,9 +657,9 @@ namespace steem { namespace protocol {
bool is_substantial_reward = reward_tokens.begin()->amount > 0;
for( auto itl = reward_tokens.begin(), itr = itl+1; itr != reward_tokens.end(); ++itl, ++itr )
{
FC_ASSERT( itl->symbol.to_nai() <= itr->symbol.to_nai(),
FC_ASSERT( itl->symbol.to_nai() <= itr->symbol.to_nai(),
"Reward tokens have not been inserted in ascending order." );
FC_ASSERT( itl->symbol.to_nai() != itr->symbol.to_nai(),
FC_ASSERT( itl->symbol.to_nai() != itr->symbol.to_nai(),
"Duplicate symbol ${s} inserted into claim reward operation container.", ("s", itl->symbol) );
FC_ASSERT( itr->amount >= 0, "Cannot claim a negative amount" );
is_substantial_reward |= itr->amount > 0;
Expand Down
Loading

0 comments on commit 5079bca

Please sign in to comment.