Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Break_free, hardforks, main part started #295
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Aug 27, 2018
1 parent 7d5c790 commit c72edaa
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 46 deletions.
2 changes: 1 addition & 1 deletion libraries/api/account_api_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ account_api_object::account_api_object(const account_object& a, const golos::cha
withdrawn(a.withdrawn), to_withdraw(a.to_withdraw), withdraw_routes(a.withdraw_routes),
witnesses_voted_for(a.witnesses_voted_for), last_post(a.last_post),
referrer_account(a.referrer_account), referrer_interest_rate(a.referrer_interest_rate),
referral_end_date(a.referral_end_date), referral_break_free(a.referral_break_free) {
referral_end_date(a.referral_end_date), referral_break_fee(a.referral_break_fee) {
size_t n = a.proxied_vsf_votes.size();
proxied_vsf_votes.reserve(n);
for (size_t i = 0; i < n; i++) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/api/include/golos/api/account_api_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct account_api_object {
account_name_type referrer_account;
uint16_t referrer_interest_rate;
time_point_sec referral_end_date;
asset referral_break_free;
asset referral_break_fee;
};

} } // golos::api
Expand All @@ -119,6 +119,6 @@ FC_REFLECT((golos::api::account_api_object),
(last_bandwidth_update)(last_market_bandwidth_update)
(last_post)(last_root_post)(post_bandwidth)
(witness_votes)(reputation)
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_free))
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_fee))

#endif //GOLOS_ACCOUNT_API_OBJ_HPP
1 change: 1 addition & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,7 @@ namespace golos { namespace chain {
_my->_evaluator_registry.register_evaluator<proposal_update_evaluator>();
_my->_evaluator_registry.register_evaluator<proposal_delete_evaluator>();
_my->_evaluator_registry.register_evaluator<chain_properties_update_evaluator>();
_my->_evaluator_registry.register_evaluator<break_free_referral_evaluator>();
}

void database::set_custom_operation_interpreter(const std::string &id, std::shared_ptr<custom_operation_interpreter> registry) {
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/hardfork.d/0_19.hf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef STEEMIT_HARDFORK_0_19
#define STEEMIT_HARDFORK_0_19 19
#define STEEMIT_HARDFORK_0_19__295 (STEEMIT_HARDFORK_0_19) // Referral program implemented

#ifdef STEEMIT_BUILD_TESTNET
#define STEEMIT_HARDFORK_0_19_TIME 1534755600 // 20 aug 2018 12:00:00 MSK
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/golos/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class account_object

account_name_type referrer_account;
uint16_t referrer_interest_rate = 0;
time_point_sec referral_end_date;
asset referral_break_free = asset(0, STEEM_SYMBOL);
time_point_sec referral_end_date = time_point_sec::min();
asset referral_break_fee = asset(0, STEEM_SYMBOL);

/// This function should be used only when the account votes for a witness directly
share_type witness_vote_weight() const {
Expand Down Expand Up @@ -514,7 +514,7 @@ FC_REFLECT((golos::chain::account_object),
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
(last_post)
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_free)
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_fee)
)
CHAINBASE_SET_INDEX_TYPE(golos::chain::account_object, golos::chain::account_index)

Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/golos/chain/steem_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace golos { namespace chain {
DEFINE_EVALUATOR(delegate_vesting_shares)
DEFINE_EVALUATOR(proposal_delete)
DEFINE_EVALUATOR(chain_properties_update)
DEFINE_EVALUATOR(break_free_referral)
class proposal_create_evaluator: public evaluator_impl<proposal_create_evaluator> {
public:
Expand Down
47 changes: 44 additions & 3 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ namespace golos { namespace chain {
database& _db;

void operator()(const account_referral_options& aro) const {
if (!_db.has_hardfork(STEEMIT_HARDFORK_0_19__295)) {
FC_THROW_EXCEPTION(golos::unsupported_operation,
"account_referral_options is not supported until STEEMIT_HARDFORK_0_19__295");
}

_db.get_account(aro.referrer);

const auto& median_props = _db.get_witness_schedule_object().median_props;
Expand All @@ -259,7 +264,7 @@ namespace golos { namespace chain {
a.referrer_account = aro.referrer;
a.referrer_interest_rate = aro.interest_rate;
a.referral_end_date = aro.end_date;
a.referral_break_free = aro.break_fee;
a.referral_break_fee = aro.break_fee;
});
}
};
Expand Down Expand Up @@ -567,10 +572,11 @@ namespace golos { namespace chain {

const auto &auth = _db.get_account(o.author); /// prove it exists

if (_db.has_hardfork(STEEMIT_HARDFORK_0_10))
if (_db.has_hardfork(STEEMIT_HARDFORK_0_10)) {
GOLOS_CHECK_LOGIC(!(auth.owner_challenged || auth.active_challenged),
logic_exception::account_is_currently_challenged,
"Operation cannot be processed because account is currently challenged.");
}

comment_id_type id;

Expand Down Expand Up @@ -691,10 +697,19 @@ namespace golos { namespace chain {
com.cashout_time = fc::time_point_sec::maximum();
}

if (_db.has_hardfork( STEEMIT_HARDFORK_0_17__431)) {
if (_db.has_hardfork(STEEMIT_HARDFORK_0_17__431)) {
com.cashout_time = com.created + STEEMIT_CASHOUT_WINDOW_SECONDS;
}

if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__295)
&& auth.referrer_account != account_name_type()) {
if (_db.head_block_time() < auth.referral_end_date) {
//com.beneficiaries.push_back(auth.referrer_account);
} else {
//com.beneficiaries.
}
}

});

while (parent) {
Expand Down Expand Up @@ -2323,4 +2338,30 @@ namespace golos { namespace chain {
}
}

void break_free_referral_evaluator::do_apply(const break_free_referral_operation& op) {
if (!_db.has_hardfork(STEEMIT_HARDFORK_0_19__295)) {
FC_THROW_EXCEPTION(golos::unsupported_operation,
"break_free_referral_operation is not supported until STEEMIT_HARDFORK_0_19__295");
}

const auto& referral = _db.get_account(op.referral);
const auto& referrer = _db.get_account(referral.referrer_account);

if (referral.referral_break_fee.amount == 0) {
FC_THROW_EXCEPTION(golos::unsupported_operation,
"This referral account has no right to break referral");
}

GOLOS_CHECK_BALANCE(referral, MAIN_BALANCE, referral.referral_break_fee);
_db.adjust_balance(referral, -referral.referral_break_fee);
_db.adjust_balance(referrer, referral.referral_break_fee);

_db.modify(referral, [&](account_object& a) {
a.referrer_account = account_name_type();
a.referrer_interest_rate = 0;
a.referral_end_date = time_point_sec::min();
a.referral_break_fee.amount = 0;
});
}

} } // golos::chain
1 change: 1 addition & 0 deletions libraries/protocol/include/golos/protocol/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace golos { namespace protocol {
proposal_update_operation,
proposal_delete_operation,
chain_properties_update_operation,
break_free_referral_operation,

/// virtual operations below this point
fill_convert_request_operation,
Expand Down
13 changes: 13 additions & 0 deletions libraries/protocol/include/golos/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,18 @@ namespace golos { namespace protocol {
a.insert(delegator);
}
};

class break_free_referral_operation : public base_operation {
public:
account_name_type referral;

extensions_type extensions; ///< Extensions. Not currently used.

void validate() const;
void get_required_active_authorities(flat_set<account_name_type>& a) const {
a.insert(referral);
}
};
} } // golos::protocol


Expand Down Expand Up @@ -1261,3 +1273,4 @@ FC_REFLECT((golos::protocol::change_recovery_account_operation), (account_to_rec
FC_REFLECT((golos::protocol::decline_voting_rights_operation), (account)(decline));
FC_REFLECT((golos::protocol::delegate_vesting_shares_operation), (delegator)(delegatee)(vesting_shares));
FC_REFLECT((golos::protocol::chain_properties_update_operation), (owner)(props));
FC_REFLECT((golos::protocol::break_free_referral_operation), (referral)(extensions));
4 changes: 4 additions & 0 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,8 @@ namespace golos { namespace protocol {
GOLOS_CHECK_PARAM(vesting_shares, GOLOS_CHECK_ASSET_GE0(vesting_shares, GESTS));
}

void break_free_referral_operation::validate() const {
GOLOS_CHECK_PARAM_ACCOUNT(referral);
}

} } // golos::protocol
10 changes: 9 additions & 1 deletion libraries/wallet/include/golos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ namespace golos { namespace wallet {
* This method will generate new owner, active, posting and memo keys for the new account which
* will be controlable by this wallet. There is a fee associated with account creation
* that is paid by the creator. The current account creation fee can be found with the
* 'info' wallet command. TODO
* 'info' wallet command.
*
* These accounts are created with combination of GOLOS and delegated GP, and with the referral duty.
*
Expand All @@ -606,6 +606,13 @@ namespace golos { namespace wallet {
string creator, asset steem_fee, asset delegated_vests, string new_account_name, string json_meta,
account_referral_options referral_options, bool broadcast);

/**
* This method pays the break fee to remove the referral duty from an account.
*
* @param referral The name of the referral account
*/
annotated_signed_transaction break_free_referral(string referral, bool broadcast);

/**
* This method updates the keys of an existing account.
*
Expand Down Expand Up @@ -1423,6 +1430,7 @@ FC_API( golos::wallet::wallet_api,
(update_account_auth_threshold)
(update_account_meta)
(update_account_memo_key)
(break_free_referral)
(delegate_vesting_shares)
(update_witness)
(update_chain_properties)
Expand Down
18 changes: 18 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,24 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
FC_CAPTURE_AND_RETHROW((creator)(new_account_name)(json_meta));
}

/**
* This method pays the break fee to remove the referral duty from an account.
*/
annotated_signed_transaction wallet_api::break_free_referral(string referral, bool broadcast) {
try {
WALLET_CHECK_UNLOCKED();

break_free_referral_operation op;
op.referral = referral;

signed_transaction tx;
tx.operations.push_back(op);
tx.validate();
return my->sign_transaction(tx, broadcast);
}
FC_CAPTURE_AND_RETHROW((referral));
}

/**
* This method is used by faucets to create new accounts for other users which must
* provide their desired keys. The resulting account may not be controllable by this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace mongo_db {
result_type operator()(const delegate_vesting_shares_operation& op);
result_type operator()(const account_create_with_delegation_operation& op);
result_type operator()(const account_metadata_operation& op);
result_type operator()(const break_free_referral_operation& op);
result_type operator()(const proposal_create_operation& op);
result_type operator()(const proposal_update_operation& op);
result_type operator()(const proposal_delete_operation& op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace mongo_db {
result_type operator()(const account_create_operation& op);
result_type operator()(const account_create_with_delegation_operation& op);
result_type operator()(const account_metadata_operation& op);
result_type operator()(const break_free_referral_operation& op);
result_type operator()(const account_update_operation& op);
result_type operator()(const witness_update_operation& op);
result_type operator()(const account_witness_vote_operation& op);
Expand Down
14 changes: 14 additions & 0 deletions plugins/mongo_db/mongo_db_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,37 +549,51 @@ namespace mongo_db {
}

//

auto operation_writer::operator()(const delegate_vesting_shares_operation& op) -> result_type {
result_type body;

return body;
}

auto operation_writer::operator()(const account_create_with_delegation_operation& op) -> result_type {
result_type body;

return body;
}

auto operation_writer::operator()(const account_metadata_operation& op) -> result_type {
result_type body;

return body;
}

auto operation_writer::operator()(const break_free_referral_operation& op) -> result_type {
result_type body;

return body;
}

auto operation_writer::operator()(const proposal_create_operation& op) -> result_type {
result_type body;

return body;
}

auto operation_writer::operator()(const proposal_update_operation& op) -> result_type {
result_type body;

return body;
}

auto operation_writer::operator()(const proposal_delete_operation& op) -> result_type {
result_type body;

return body;
}

//

auto operation_writer::operator()(const fill_convert_request_operation& op) -> result_type {
result_type body;

Expand Down
Loading

0 comments on commit c72edaa

Please sign in to comment.