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

Commit

Permalink
Fix #295
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Sep 4, 2018
1 parent e723cec commit 5e40b65
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
18 changes: 9 additions & 9 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ namespace golos { namespace chain {
&& _c.beneficiaries.front().account == _a.referrer_account) {
total_weight += _c.beneficiaries[0].weight;
auto& referrer = _a.referrer_account;
const auto& referrer_find = std::find_if(cpb.beneficiaries.begin(), cpb.beneficiaries.end(),
const auto& itr = std::find_if(cpb.beneficiaries.begin(), cpb.beneficiaries.end(),
[&referrer](const beneficiary_route_type& benef) {
return benef.account == referrer;
});
GOLOS_CHECK_LOGIC(referrer_find == cpb.beneficiaries.end(),
GOLOS_CHECK_LOGIC(itr == cpb.beneficiaries.end(),
logic_exception::beneficiaries_should_be_unique,
"Comment already has '${referrer}' as a referrer-beneficiary.", ("referrer",referrer));
} else {
Expand All @@ -530,9 +530,10 @@ namespace golos { namespace chain {
}
});

GOLOS_CHECK_LOGIC(total_weight <= STEEMIT_100_PERCENT,
logic_exception::beneficiaries_weight_too_large,
"Beneficiaries total weight must not be more than 100 percents.");
GOLOS_CHECK_PARAM(beneficiaries, {
GOLOS_CHECK_VALUE(total_weight <= STEEMIT_100_PERCENT,
"Cannot allocate more than 100% of rewards to a comment");
});
}
};

Expand Down Expand Up @@ -2373,10 +2374,9 @@ namespace golos { namespace chain {
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_LOGIC(referral.referral_break_fee.amount != 0,
logic_exception::no_right_to_break_referral,
"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);
Expand Down
2 changes: 0 additions & 2 deletions libraries/protocol/include/golos/protocol/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ namespace golos {
comment_cannot_accept_greater_percent_GBG,
cannot_specify_more_beneficiaries,
comment_already_has_beneficiaries,
beneficiaries_weight_too_large,
beneficiaries_should_be_unique,
comment_must_not_have_been_voted,

Expand Down Expand Up @@ -494,7 +493,6 @@ FC_REFLECT_ENUM(golos::logic_exception::error_types,
(comment_cannot_accept_greater_percent_GBG)
(cannot_specify_more_beneficiaries)
(comment_already_has_beneficiaries)
(beneficiaries_weight_too_large)
(beneficiaries_should_be_unique)
(comment_must_not_have_been_voted)

Expand Down
10 changes: 3 additions & 7 deletions libraries/protocol/include/golos/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace golos { namespace protocol {
void validate() const;
};

typedef static_variant <
using account_create_with_delegation_extension = static_variant<
account_referral_options
> account_create_with_delegation_extension;
>;

typedef flat_set<account_create_with_delegation_extension> account_create_with_delegation_extensions_type;
using account_create_with_delegation_extensions_type = flat_set<account_create_with_delegation_extension>;

struct account_create_with_delegation_operation: public base_operation {
asset fee;
Expand Down Expand Up @@ -541,10 +541,6 @@ namespace golos { namespace protocol {

chain_properties_19& operator=(const chain_properties_18& src) {
chain_properties_18::operator=(src);
create_account_min_golos_fee = src.create_account_min_golos_fee;
create_account_min_delegation = src.create_account_min_delegation;
create_account_delegation_time = src.create_account_delegation_time;
min_delegation = src.min_delegation;
return *this;
}

Expand Down
7 changes: 4 additions & 3 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,18 @@ namespace golos { namespace protocol {
GOLOS_CHECK_PARAM(beneficiaries, {
GOLOS_CHECK_VALUE(beneficiaries.size(), "Must specify at least one beneficiary");
GOLOS_CHECK_VALUE(beneficiaries.size() < 128,
"Cannot specify more than 127 beneficiaries."); // Require size serializtion fits in one byte.
"Cannot specify more than 127 beneficiaries."); // Require size serialization fits in one byte.

for (auto& beneficiary : beneficiaries) {
validate_account_name(beneficiary.account);
GOLOS_CHECK_VALUE(beneficiary.weight <= STEEMIT_100_PERCENT,
"Cannot allocate more than 100% of rewards to one account");
sum += beneficiary.weight;
GOLOS_CHECK_VALUE(sum <= STEEMIT_100_PERCENT,
"Cannot allocate more than 100% of rewards to a comment");
}

GOLOS_CHECK_VALUE(sum <= STEEMIT_100_PERCENT,
"Cannot allocate more than 100% of rewards to a comment");

for (size_t i = 1; i < beneficiaries.size(); i++) {
GOLOS_CHECK_VALUE(beneficiaries[i - 1] < beneficiaries[i],
"Benficiaries ${first} and ${second} not in sorted order (account ascending)",
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6146,7 +6146,7 @@ BOOST_FIXTURE_TEST_SUITE(operation_tests, clean_database_fixture)
op.extensions.clear();
op.extensions.insert(b);
GOLOS_CHECK_ERROR_PROPS(op.validate(),
CHECK_ERROR(invalid_parameter, "beneficiaries"));
CHECK_ERROR(logic_exception, logic_exception::cannot_specify_more_beneficiaries));

BOOST_TEST_MESSAGE("--- Testing duplicate accounts");
b.beneficiaries.clear();
Expand Down

0 comments on commit 5e40b65

Please sign in to comment.