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

Commit

Permalink
Remove all authors and permlinks from worker objects #1129
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Feb 22, 2019
1 parent 5740216 commit 2ab0eae
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 104 deletions.
38 changes: 8 additions & 30 deletions libraries/chain/database_worker_objects.cpp
Expand Up @@ -28,36 +28,15 @@ namespace golos { namespace chain {
return find<worker_techspec_object, by_post>(post);
}

const worker_techspec_object& database::get_worker_result(
const account_name_type& author,
const std::string& permlink
) const { try {
return get<worker_techspec_object, by_worker_result>(std::make_tuple(author, permlink));
const worker_techspec_object& database::get_worker_result(const comment_id_type& post) const { try {
return get<worker_techspec_object, by_worker_result>(post);
} catch (const std::out_of_range &e) {
GOLOS_THROW_MISSING_OBJECT("worker_techspec_object", fc::mutable_variant_object()("author",author)("worker_result_permlink",permlink));
} FC_CAPTURE_AND_RETHROW((author)(permlink)) }

const worker_techspec_object& database::get_worker_result(
const account_name_type& author,
const shared_string& permlink
) const { try {
return get<worker_techspec_object, by_worker_result>(std::make_tuple(author, permlink));
} catch (const std::out_of_range &e) {
GOLOS_THROW_MISSING_OBJECT("worker_techspec_object", fc::mutable_variant_object()("author",author)("worker_result_permlink",permlink));
} FC_CAPTURE_AND_RETHROW((author)(permlink)) }

const worker_techspec_object* database::find_worker_result(
const account_name_type& author,
const std::string& permlink
) const {
return find<worker_techspec_object, by_worker_result>(std::make_tuple(author, permlink));
}
const auto& comment = get_comment(post);
GOLOS_THROW_MISSING_OBJECT("worker_techspec_object", fc::mutable_variant_object()("author",comment.author)("worker_result_permlink",comment.permlink));
} FC_CAPTURE_AND_RETHROW((post)) }

const worker_techspec_object* database::find_worker_result(
const account_name_type& author,
const shared_string& permlink
) const {
return find<worker_techspec_object, by_worker_result>(std::make_tuple(author, permlink));
const worker_techspec_object* database::find_worker_result(const comment_id_type& post) const {
return find<worker_techspec_object, by_worker_result>(post);
}

void database::process_worker_cashout() {
Expand Down Expand Up @@ -87,8 +66,7 @@ namespace golos { namespace chain {
}

if (remaining_payments_count == 1) {
const auto& wpo_post = get_comment(wto_itr->worker_proposal_author, wto_itr->worker_proposal_permlink);
const auto& wpo = get_worker_proposal(wpo_post.id);
const auto& wpo = get_worker_proposal(wto_itr->worker_proposal_post);
modify(wpo, [&](worker_proposal_object& wpo) {
wpo.state = worker_proposal_state::closed;
});
Expand Down
6 changes: 2 additions & 4 deletions libraries/chain/include/golos/chain/database.hpp
Expand Up @@ -183,10 +183,8 @@ namespace golos { namespace chain {

const worker_techspec_object& get_worker_techspec(const comment_id_type& post) const;
const worker_techspec_object* find_worker_techspec(const comment_id_type& post) const;
const worker_techspec_object& get_worker_result(const account_name_type& author, const std::string& permlink) const;
const worker_techspec_object& get_worker_result(const account_name_type& author, const shared_string& permlink) const;
const worker_techspec_object* find_worker_result(const account_name_type& author, const std::string& permlink) const;
const worker_techspec_object* find_worker_result(const account_name_type& author, const shared_string& permlink) const;
const worker_techspec_object& get_worker_result(const comment_id_type& post) const;
const worker_techspec_object* find_worker_result(const comment_id_type& post) const;

const comment_object &get_comment(const account_name_type &author, const shared_string &permlink) const;

Expand Down
28 changes: 8 additions & 20 deletions libraries/chain/include/golos/chain/worker_objects.hpp
Expand Up @@ -18,8 +18,7 @@ namespace golos { namespace chain {
worker_proposal_object() = delete;

template <typename Constructor, typename Allocator>
worker_proposal_object(Constructor&& c, allocator <Allocator> a)
: approved_techspec_permlink(a) {
worker_proposal_object(Constructor&& c, allocator <Allocator> a) {
c(*this);
};

Expand All @@ -29,8 +28,7 @@ namespace golos { namespace chain {
comment_id_type post;
worker_proposal_type type;
worker_proposal_state state;
account_name_type approved_techspec_author;
shared_string approved_techspec_permlink;
comment_id_type approved_techspec_post;
};

enum class worker_techspec_state {
Expand All @@ -44,17 +42,15 @@ namespace golos { namespace chain {
worker_techspec_object() = delete;

template <typename Constructor, typename Allocator>
worker_techspec_object(Constructor&& c, allocator <Allocator> a)
: worker_proposal_permlink(a), worker_result_permlink(a) {
worker_techspec_object(Constructor&& c, allocator <Allocator> a) {
c(*this);
};

id_type id;

account_name_type author;
comment_id_type post;
account_name_type worker_proposal_author;
shared_string worker_proposal_permlink;
comment_id_type worker_proposal_post;
worker_techspec_state state;
time_point_sec created;
time_point_sec modified;
Expand All @@ -65,7 +61,7 @@ namespace golos { namespace chain {
uint16_t disapproves = 0;
account_name_type worker;
time_point_sec work_beginning_time;
shared_string worker_result_permlink;
comment_id_type worker_result_post;
time_point_sec completion_date;
uint16_t payments_count;
uint32_t payments_interval;
Expand Down Expand Up @@ -141,22 +137,14 @@ namespace golos { namespace chain {
tag<by_worker_proposal>,
composite_key<
worker_techspec_object,
member<worker_techspec_object, account_name_type, &worker_techspec_object::worker_proposal_author>,
member<worker_techspec_object, shared_string, &worker_techspec_object::worker_proposal_permlink>,
member<worker_techspec_object, comment_id_type, &worker_techspec_object::worker_proposal_post>,
member<worker_techspec_object, account_name_type, &worker_techspec_object::author>>,
composite_key_compare<
std::less<account_name_type>,
chainbase::strcmp_less,
std::less<comment_id_type>,
std::less<account_name_type>>>,
ordered_unique<
tag<by_worker_result>,
composite_key<
worker_techspec_object,
member<worker_techspec_object, account_name_type, &worker_techspec_object::author>,
member<worker_techspec_object, shared_string, &worker_techspec_object::worker_result_permlink>>,
composite_key_compare<
std::less<account_name_type>,
chainbase::strcmp_less>>,
member<worker_techspec_object, comment_id_type, &worker_techspec_object::worker_result_post>>,
ordered_unique<
tag<by_next_cashout_time>,
composite_key<
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/steem_evaluator.cpp
Expand Up @@ -387,7 +387,7 @@ namespace golos { namespace chain {
logic_exception::cannot_delete_post_with_worker_techspec,
"Cannot delete a post with worker techspec.");

const auto* wto_result = _db.find_worker_result(comment.author, comment.permlink);
const auto* wto_result = _db.find_worker_result(comment.id);
GOLOS_CHECK_LOGIC(!wto_result,
logic_exception::cannot_delete_post_with_worker_result,
"Cannot delete a post with worker result.");
Expand Down
56 changes: 30 additions & 26 deletions libraries/chain/worker_evaluators.cpp
Expand Up @@ -49,7 +49,7 @@ namespace golos { namespace chain {
"Cannot delete worker proposal with approved techspec");

const auto& wto_idx = _db.get_index<worker_techspec_index, by_worker_proposal>();
auto wto_itr = wto_idx.find(std::make_tuple(post.author, post.permlink));
auto wto_itr = wto_idx.find(wpo.post);
GOLOS_CHECK_LOGIC(wto_itr == wto_idx.end(),
logic_exception::cannot_delete_worker_proposal_with_techspecs,
"Cannot delete worker proposal with techspecs");
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace golos { namespace chain {
"This worker proposal already has approved techspec");

const auto& wto_idx = _db.get_index<worker_techspec_index, by_worker_proposal>();
auto wto_itr = wto_idx.find(std::make_tuple(wpo_post.author, wpo_post.permlink, o.author));
auto wto_itr = wto_idx.find(std::make_tuple(wpo->post, o.author));
if (wto_itr != wto_idx.end()) {
GOLOS_CHECK_LOGIC(o.permlink == to_string(post.permlink),
logic_exception::there_already_is_your_techspec_with_another_permlink,
Expand All @@ -107,8 +107,7 @@ namespace golos { namespace chain {
_db.create<worker_techspec_object>([&](worker_techspec_object& wto) {
wto.author = o.author;
wto.post = post.id;
wto.worker_proposal_author = o.worker_proposal_author;
from_string(wto.worker_proposal_permlink, o.worker_proposal_permlink);
wto.worker_proposal_post = wpo->post;
wto.state = worker_techspec_state::created;
wto.created = now;
wto.net_rshares = post.net_rshares;
Expand All @@ -125,8 +124,7 @@ namespace golos { namespace chain {
const auto& post = _db.get_comment(o.author, o.permlink);
const auto& wto = _db.get_worker_techspec(post.id);

const auto& wpo_post = _db.get_comment(wto.worker_proposal_author, wto.worker_proposal_permlink);
const auto& wpo = _db.get_worker_proposal(wpo_post.id);
const auto& wpo = _db.get_worker_proposal(wto.worker_proposal_post);

GOLOS_CHECK_LOGIC(wpo.state < worker_proposal_state::payment,
logic_exception::cannot_delete_worker_techspec_for_paying_proposal,
Expand All @@ -135,6 +133,7 @@ namespace golos { namespace chain {
if (wto.state == worker_techspec_state::approved) {
_db.modify(wpo, [&](worker_proposal_object& wpo) {
wpo.state = worker_proposal_state::created;
wpo.approved_techspec_post = comment_id_type();
});
}

Expand Down Expand Up @@ -206,12 +205,20 @@ namespace golos { namespace chain {

_db.clear_worker_techspec_approves(wto);

const auto& wpo_post = _db.get_comment(wto.worker_proposal_author, wto.worker_proposal_permlink);
const auto& wpo = _db.get_worker_proposal(wpo_post.id);
_db.modify(wto, [&](worker_techspec_object& wto) {
wto.state = worker_techspec_state::closed;
});
} else if (o.state == worker_techspec_approve_state::approve) {
auto approvers = count_approvers(worker_techspec_approve_state::approve);

if (approvers < STEEMIT_MAJOR_VOTED_WITNESSES) {
return;
}

const auto& wpo = _db.get_worker_proposal(wto.worker_proposal_post);

_db.modify(wpo, [&](worker_proposal_object& wpo) {
wpo.approved_techspec_author = o.author;
from_string(wpo.approved_techspec_permlink, o.permlink);
wpo.approved_techspec_post = wto_post.id;
wpo.state = worker_proposal_state::techspec;
});

Expand Down Expand Up @@ -241,13 +248,12 @@ namespace golos { namespace chain {
const auto& wto_post = _db.get_comment(o.author, o.worker_techspec_permlink);
const auto& wto = _db.get_worker_techspec(wto_post.id);

const auto* wto_result = _db.find_worker_result(o.author, o.permlink);
const auto* wto_result = _db.find_worker_result(post.id);
GOLOS_CHECK_LOGIC(!wto_result,
logic_exception::this_post_already_used_as_worker_result,
"This post already used as worker result");

const auto& wpo_post = _db.get_comment(wto.worker_proposal_author, wto.worker_proposal_permlink);
const auto& wpo = _db.get_worker_proposal(wpo_post.id);
const auto& wpo = _db.get_worker_proposal(wto.worker_proposal_post);

GOLOS_CHECK_LOGIC(wto.state == worker_techspec_state::approved,
logic_exception::worker_result_can_be_created_only_for_techspec_in_work,
Expand All @@ -263,7 +269,7 @@ namespace golos { namespace chain {
}

_db.modify(wto, [&](worker_techspec_object& wto) {
from_string(wto.worker_result_permlink, o.permlink);
wto.worker_result_post = post.id;

if (o.completion_date != time_point_sec::min()) {
wto.completion_date = o.completion_date;
Expand All @@ -280,10 +286,10 @@ namespace golos { namespace chain {
void worker_result_delete_evaluator::do_apply(const worker_result_delete_operation& o) {
ASSERT_REQ_HF(STEEMIT_HARDFORK_0_21__1013, "worker_result_delete_operation");

const auto& wto = _db.get_worker_result(o.author, o.permlink);
const auto& worker_result_post = _db.get_comment(o.author, o.permlink);
const auto& wto = _db.get_worker_result(worker_result_post.id);

const auto& wpo_post = _db.get_comment(wto.worker_proposal_author, wto.worker_proposal_permlink);
const auto& wpo = _db.get_worker_proposal(wpo_post.id);
const auto& wpo = _db.get_worker_proposal(wto.worker_proposal_post);

GOLOS_CHECK_LOGIC(wpo.state < worker_proposal_state::payment,
logic_exception::cannot_delete_worker_result_for_paying_proposal,
Expand All @@ -294,7 +300,7 @@ namespace golos { namespace chain {
});

_db.modify(wto, [&](worker_techspec_object& wto) {
wto.worker_result_permlink.clear();
wto.worker_result_post = comment_id_type();
wto.completion_date = time_point::min();
});
}
Expand All @@ -307,11 +313,10 @@ namespace golos { namespace chain {
logic_exception::approver_of_result_should_be_in_top19_of_witnesses,
"Approver of result should be in Top 19 of witnesses");

const auto& wto_post = _db.get_comment(o.author, o.permlink);
const auto& wto = _db.get_worker_result(o.author, o.permlink);
const auto& worker_result_post = _db.get_comment(o.author, o.permlink);
const auto& wto = _db.get_worker_result(worker_result_post.id);

const auto& wpo_post = _db.get_comment(wto.worker_proposal_author, wto.worker_proposal_permlink);
const auto& wpo = _db.get_worker_proposal(wpo_post.id);
const auto& wpo = _db.get_worker_proposal(wto.worker_proposal_post);

GOLOS_CHECK_LOGIC(wpo.state == worker_proposal_state::witnesses_review,
logic_exception::worker_proposal_should_be_in_review_state_to_approve,
Expand All @@ -323,7 +328,7 @@ namespace golos { namespace chain {
"Approve term has expired");

const auto& wrao_idx = _db.get_index<worker_result_approve_index, by_result_approver>();
auto wrao_itr = wrao_idx.find(std::make_tuple(wto_post.id, o.approver));
auto wrao_itr = wrao_idx.find(std::make_tuple(worker_result_post.id, o.approver));

if (o.state == worker_techspec_approve_state::abstain) {
if (wrao_itr != wrao_idx.end()) {
Expand All @@ -340,7 +345,7 @@ namespace golos { namespace chain {
} else {
_db.create<worker_result_approve_object>([&](worker_result_approve_object& wrao) {
wrao.approver = o.approver;
wrao.post = wto.post;
wrao.post = worker_result_post.id;
wrao.state = o.state;
});
}
Expand Down Expand Up @@ -425,8 +430,7 @@ namespace golos { namespace chain {
const auto& wto_post = _db.get_comment(o.worker_techspec_author, o.worker_techspec_permlink);
const auto& wto = _db.get_worker_techspec(wto_post.id);

const auto& wpo_post = _db.get_comment(wto.worker_proposal_author, wto.worker_proposal_permlink);
const auto& wpo = _db.get_worker_proposal(wpo_post.id);
const auto& wpo = _db.get_worker_proposal(wto.worker_proposal_post);

if (!o.worker.size()) { // Unassign worker
GOLOS_CHECK_LOGIC(wpo.state == worker_proposal_state::work,
Expand Down
Expand Up @@ -70,15 +70,12 @@ namespace golos { namespace plugins { namespace worker_api {
void fill_worker_proposal(const worker_proposal_object& wpo) {
type = wpo.type;
state = wpo.state;
approved_techspec_author = wpo.approved_techspec_author;
approved_techspec_permlink = to_string(wpo.approved_techspec_permlink);
}

comment_api_object post;
worker_proposal_type type;
worker_proposal_state state;
account_name_type approved_techspec_author;
std::string approved_techspec_permlink;
comment_api_object approved_techspec_post;
time_point_sec created;
time_point_sec modified;
share_type net_rshares;
Expand All @@ -87,8 +84,6 @@ namespace golos { namespace plugins { namespace worker_api {
struct worker_techspec_api_object {
worker_techspec_api_object(const worker_techspec_object& o, const comment_api_object& p)
: post(p),
worker_proposal_author(o.worker_proposal_author),
worker_proposal_permlink(to_string(o.worker_proposal_permlink)),
state(o.state),
created(o.created),
modified(o.modified),
Expand All @@ -99,7 +94,6 @@ namespace golos { namespace plugins { namespace worker_api {
disapproves(o.disapproves),
worker(o.worker),
work_beginning_time(o.work_beginning_time),
worker_result_permlink(to_string(o.worker_result_permlink)),
completion_date(o.completion_date),
payments_count(o.payments_count),
payments_interval(o.payments_interval),
Expand All @@ -113,8 +107,7 @@ namespace golos { namespace plugins { namespace worker_api {
}

comment_api_object post;
account_name_type worker_proposal_author;
std::string worker_proposal_permlink;
comment_api_object worker_proposal_post;
worker_techspec_state state;
time_point_sec created;
time_point_sec modified;
Expand All @@ -125,7 +118,7 @@ namespace golos { namespace plugins { namespace worker_api {
uint16_t disapproves = 0;
account_name_type worker;
time_point_sec work_beginning_time;
std::string worker_result_permlink;
comment_api_object worker_result_post;
time_point_sec completion_date;
uint16_t payments_count = 0;
uint32_t payments_interval = 0;
Expand All @@ -142,11 +135,11 @@ CHAINBASE_SET_INDEX_TYPE(
golos::plugins::worker_api::worker_proposal_metadata_index)

FC_REFLECT((golos::plugins::worker_api::worker_proposal_api_object),
(post)(type)(state)(approved_techspec_author)(approved_techspec_permlink)(created)(modified)(net_rshares)
(post)(type)(state)(approved_techspec_post)(created)(modified)(net_rshares)
)

FC_REFLECT((golos::plugins::worker_api::worker_techspec_api_object),
(post)(worker_proposal_author)(worker_proposal_permlink)(state)(created)(modified)(net_rshares)(specification_cost)
(development_cost)(approves)(disapproves)(worker)(work_beginning_time)(worker_result_permlink)(completion_date)(payments_count)
(payments_interval)(month_consumption)(payment_beginning_time)(next_cashout_time)(finished_payments_count)
(post)(worker_proposal_post)(state)(created)(modified)(net_rshares)(specification_cost)(development_cost)(approves)(disapproves)
(worker)(work_beginning_time)(worker_result_post)(completion_date)(payments_count)(payments_interval)(month_consumption)
(payment_beginning_time)(next_cashout_time)(finished_payments_count)
)

0 comments on commit 2ab0eae

Please sign in to comment.