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

Commit

Permalink
fixes after review #971
Browse files Browse the repository at this point in the history
  • Loading branch information
e-schepachev committed Oct 23, 2018
1 parent b400c63 commit 3a3fe74
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
15 changes: 1 addition & 14 deletions libraries/chain/include/golos/chain/steem_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace golos { namespace chain {
DEFINE_EVALUATOR(challenge_authority)
DEFINE_EVALUATOR(prove_authority)
DEFINE_EVALUATOR(request_account_recovery)
DEFINE_EVALUATOR(recover_account)
DEFINE_EVALUATOR(change_recovery_account)
DEFINE_EVALUATOR(transfer_to_savings)
DEFINE_EVALUATOR(transfer_from_savings)
Expand Down Expand Up @@ -79,18 +80,4 @@ namespace golos { namespace chain {
int depth_ = 0;
};

class recover_account_evaluator : public evaluator_impl<recover_account_evaluator> {
public:
using operation_type = recover_account_operation;

recover_account_evaluator(database& db) : evaluator_impl<recover_account_evaluator>(db) {}

void do_apply(const operation_type& o);

private:
void reset_vesting_withdraw(const account_object& account);
void stop_withdraw(const account_object& account);
void remove_vesting_routes(const account_object& account);
};

} } // golos::chain
55 changes: 29 additions & 26 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,34 @@ namespace golos { namespace chain {
}
}

namespace {

void stop_withdraw(database& db, const golos::chain::account_object& account) {
db.modify(account, [&](account_object& a) {
a.vesting_withdraw_rate.amount = 0;
a.next_vesting_withdrawal = fc::time_point_sec::maximum();
a.withdrawn = 0;
a.to_withdraw = 0;
});
}

void remove_vesting_routes(database& db, const golos::chain::account_object& account) {
const auto & withdraw_idx = db.get_index<withdraw_vesting_route_index>().indices().get<by_withdraw_route>();
auto withdraw_it = withdraw_idx.upper_bound(account.id);

while (withdraw_it != withdraw_idx.end() && withdraw_it->from_account == account.id) {
const auto& val = *withdraw_it;
++withdraw_it;
db.remove(val);
}
}

void reset_vesting_withdraw(database& db, const account_object& account) {
stop_withdraw(db, account);
remove_vesting_routes(db, account);
}
}

void recover_account_evaluator::do_apply(const recover_account_operation& o) {
const auto& account = _db.get_account(o.account_to_recover);
const auto now = _db.head_block_time();
Expand Down Expand Up @@ -2241,32 +2269,7 @@ namespace golos { namespace chain {
a.last_account_recovery = now;
});

reset_vesting_withdraw(account);
}

void recover_account_evaluator::reset_vesting_withdraw(const account_object& account) {
stop_withdraw(account);
remove_vesting_routes(account);
}

void golos::chain::recover_account_evaluator::stop_withdraw(const golos::chain::account_object &account) {
_db.modify(account, [&](account_object &a) {
a.vesting_withdraw_rate.amount = 0;
a.next_vesting_withdrawal = fc::time_point_sec::maximum();
a.withdrawn = 0;
a.to_withdraw = 0;
});
}

void golos::chain::recover_account_evaluator::remove_vesting_routes(const golos::chain::account_object &account) {
const auto & withdraw_index = _db.get_index<withdraw_vesting_route_index>().indices().get<by_withdraw_route>();
auto it = withdraw_index.upper_bound(boost::make_tuple(account.id, account_id_type()));

while (it != withdraw_index.end() && it->from_account == account.id) {
const auto& val = *it;
++it;
_db.remove(val);
}
reset_vesting_withdraw(_db, account);
}

void change_recovery_account_evaluator::do_apply(const change_recovery_account_operation& o) {
Expand Down
9 changes: 4 additions & 5 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4178,21 +4178,20 @@ BOOST_FIXTURE_TEST_SUITE(operation_tests, clean_database_fixture)
set_withdraw_vesting_route_operation to_chewy;
to_chewy.from_account = "bob";
to_chewy.to_account = "chewy";
to_chewy.percent = 5000;
to_chewy.percent = 50 * STEEMIT_1_PERCENT;

set_withdraw_vesting_route_operation to_donna;

to_donna.from_account = "bob";
to_donna.to_account = "donna";
to_donna.percent = 5000;
to_donna.percent = 50 * STEEMIT_1_PERCENT;

tx.clear();

BOOST_CHECK_NO_THROW(push_tx_with_ops(tx, bob_private_key, to_chewy, to_donna));

BOOST_TEST_MESSAGE("--- Start vesting withdraw");


withdraw_vesting_operation withdraw_vesting_op;
withdraw_vesting_op.account = "bob";
withdraw_vesting_op.vesting_shares = asset(db->get_account("bob").vesting_shares.amount / 2, VESTS_SYMBOL);
Expand Down Expand Up @@ -4263,8 +4262,8 @@ BOOST_FIXTURE_TEST_SUITE(operation_tests, clean_database_fixture)
const auto& chewy = db->get_account("chewy");
const auto& donna = db->get_account("donna");

const auto & withdraw_index = db->get_index<withdraw_vesting_route_index>().indices().get<by_withdraw_route>();
auto it = withdraw_index.upper_bound(boost::make_tuple(bob.id, account_id_type()));
const auto& withdraw_index = db->get_index<withdraw_vesting_route_index>().indices().get<by_withdraw_route>();
auto it = withdraw_index.upper_bound(bob.id);

while (it != withdraw_index.end() && it->from_account == bob.id) {
BOOST_CHECK_NE(it->to_account, chewy.id);
Expand Down

0 comments on commit 3a3fe74

Please sign in to comment.