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

Commit

Permalink
Referral program, ASSERT_REQ_HF improved, HF 19 #295
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Sep 11, 2018
1 parent 0d44ab9 commit 50cd36c
Show file tree
Hide file tree
Showing 22 changed files with 790 additions and 130 deletions.
7 changes: 7 additions & 0 deletions libraries/api/account_api_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ account_api_object::account_api_object(const account_object& a, const golos::cha
lifetime_market_bandwidth = market->lifetime_bandwidth;
last_market_bandwidth_update = market->last_bandwidth_update;
}

if (db.head_block_time() < a.referral_end_date) {
referrer_account = a.referrer_account;
referrer_interest_rate = a.referrer_interest_rate;
referral_end_date = a.referral_end_date;
referral_break_fee = a.referral_break_fee;
}
}

account_api_object::account_api_object() = default;
Expand Down
8 changes: 7 additions & 1 deletion libraries/api/include/golos/api/account_api_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ struct account_api_object {
set<string> witness_votes;

fc::optional<share_type> reputation;

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

} } // golos::api
Expand All @@ -113,6 +118,7 @@ FC_REFLECT((golos::api::account_api_object),
(average_bandwidth)(average_market_bandwidth)(lifetime_bandwidth)(lifetime_market_bandwidth)
(last_bandwidth_update)(last_market_bandwidth_update)
(last_post)(last_root_post)(post_bandwidth)
(witness_votes)(reputation))
(witness_votes)(reputation)
(referrer_account)(referrer_interest_rate)(referral_end_date)(referral_break_fee))

#endif //GOLOS_ACCOUNT_API_OBJ_HPP
24 changes: 17 additions & 7 deletions libraries/chain/chain_properties_evaluators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ namespace golos { namespace chain {
}
}

struct chain_properties_convert {
using result_type = chain_properties_19;
struct chain_properties_update {
using result_type = void;

const database& _db;
chain_properties& _wprops;

chain_properties_update(const database& db, chain_properties& wprops)
: _db(db), _wprops(wprops) {
}

result_type operator()(const chain_properties_19& p) const {
ASSERT_REQ_HF(STEEMIT_HARDFORK_0_19__295, "chain_properties_19");
_wprops = p;
}

template<typename Props>
result_type operator()(Props&& p) const {
result_type r;
r = p;
return r;
_wprops = p;
}
};

Expand All @@ -58,13 +68,13 @@ namespace golos { namespace chain {
auto itr = idx.find(o.owner);
if (itr != idx.end()) {
_db.modify(*itr, [&](witness_object& w) {
w.props = o.props.visit(chain_properties_convert());
o.props.visit(chain_properties_update(_db, w.props));
});
} else {
_db.create<witness_object>([&](witness_object& w) {
w.owner = o.owner;
w.created = _db.head_block_time();
w.props = o.props.visit(chain_properties_convert());
o.props.visit(chain_properties_update(_db, w.props));
});
}
}
Expand Down
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
34 changes: 20 additions & 14 deletions libraries/chain/include/golos/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class account_object

time_point_sec last_post;

account_name_type referrer_account;
uint16_t referrer_interest_rate = 0;
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 {
return std::accumulate(proxied_vsf_votes.begin(),
Expand Down Expand Up @@ -495,20 +500,21 @@ change_recovery_account_request_index;


FC_REFLECT((golos::chain::account_object),
(id)(name)(memo_key)(proxy)(last_account_update)
(created)(mined)
(owner_challenged)(active_challenged)(last_owner_proved)(last_active_proved)(recovery_account)(last_account_recovery)(reset_account)
(comment_count)(lifetime_vote_count)(post_count)(can_vote)(voting_power)(last_vote_time)
(balance)
(savings_balance)
(sbd_balance)(sbd_seconds)(sbd_seconds_last_update)(sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)(savings_withdraw_requests)
(vesting_shares)(delegated_vesting_shares)(received_vesting_shares)
(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(curation_rewards)
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
(last_post)
(id)(name)(memo_key)(proxy)(last_account_update)
(created)(mined)
(owner_challenged)(active_challenged)(last_owner_proved)(last_active_proved)(recovery_account)(last_account_recovery)(reset_account)
(comment_count)(lifetime_vote_count)(post_count)(can_vote)(voting_power)(last_vote_time)
(balance)
(savings_balance)
(sbd_balance)(sbd_seconds)(sbd_seconds_last_update)(sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)(savings_withdraw_requests)
(vesting_shares)(delegated_vesting_shares)(received_vesting_shares)
(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(curation_rewards)
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
(last_post)
(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
8 changes: 8 additions & 0 deletions libraries/chain/include/golos/chain/evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
#include <golos/protocol/exceptions.hpp>
#include <golos/protocol/operations.hpp>

#define ASSERT_REQ_HF_IN_DB(HF, FEATURE, DATABASE) \
GOLOS_ASSERT(DATABASE.has_hardfork(HF), unsupported_operation, \
"${feature} is not enabled until HF ${hardfork}", \
("feature",FEATURE)("hardfork",BOOST_PP_STRINGIZE(HF)));
#define ASSERT_REQ_HF(HF, FEATURE) \
ASSERT_REQ_HF_IN_DB(HF, FEATURE, _db)
namespace golos {
namespace chain {
Expand Down
6 changes: 1 addition & 5 deletions libraries/chain/include/golos/chain/steem_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include <golos/protocol/proposal_operations.hpp>
#include <golos/chain/evaluator.hpp>

#define ASSERT_REQ_HF(HF, FEATURE) \
GOLOS_ASSERT(db().has_hardfork(HF), unsupported_operation, \
"${feature} is not enabled until HF ${hardfork}", \
("feature",FEATURE)("hardfork",BOOST_PP_STRINGIZE(HF)));
namespace golos { namespace chain {
using namespace golos::protocol;

Expand Down Expand Up @@ -56,6 +51,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
Loading

0 comments on commit 50cd36c

Please sign in to comment.