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

Commit

Permalink
Merge pull request #1042 from GolosChain/golos-v0.19.1
Browse files Browse the repository at this point in the history
Golos v0.19.1
  • Loading branch information
afalaleev authored Dec 28, 2018
2 parents 3a1e2bb + f8da6e7 commit a88d70e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 81 deletions.
47 changes: 26 additions & 21 deletions libraries/api/discussion_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace golos { namespace api {

discussion get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t offset) const;

void fill_discussion(discussion& d, const comment_object& comment, uint32_t vote_limit, uint32_t offset) const;

void fill_comment_api_object(const comment_object& o, comment_api_object& d) const;

private:
Expand Down Expand Up @@ -136,8 +138,28 @@ namespace golos { namespace api {
// get_discussion
discussion discussion_helper::impl::get_discussion(const comment_object& comment, uint32_t vote_limit, uint32_t offset) const {
discussion d = create_discussion(comment);
fill_discussion(d, comment, vote_limit, offset);
return d;
}

discussion discussion_helper::get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t offset) const {
return pimpl->get_discussion(c, vote_limit, offset);
}

void discussion_helper::impl::fill_discussion(
discussion& d, const comment_object& comment, uint32_t vote_limit, uint32_t offset
) const {
set_url(d);

fill_reputation_(database_, d.author, d.author_reputation);

if (d.body.size() > 1024 * 128) {
d.body = "body pruned due to size";
}
if (d.parent_author.size() > 0 && d.body.size() > 1024 * 16) {
d.body = "comment pruned due to size";
}

d.active_votes_count = comment.total_votes;

comment_curation_info c{database_, comment, true};
Expand All @@ -149,12 +171,12 @@ namespace golos { namespace api {
d.active_votes = select_active_votes(c, vote_limit, offset);

set_pending_payout(d);

return d;
}

discussion discussion_helper::get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t offset) const {
return pimpl->get_discussion(c, vote_limit, offset);
void discussion_helper::fill_discussion(
discussion& d, const comment_object& comment, uint32_t vote_limit, uint32_t offset
) const {
pimpl->fill_discussion(d, comment, vote_limit, offset);
}
//

Expand Down Expand Up @@ -293,22 +315,8 @@ namespace golos { namespace api {

d.total_pending_payout_value = db.to_sbd(asset(static_cast<uint64_t>(tpp), pot.symbol));
}

fill_reputation_(db, d.author, d.author_reputation);

if (d.body.size() > 1024 * 128) {
d.body = "body pruned due to size";
}
if (d.parent_author.size() > 0 && d.body.size() > 1024 * 16) {
d.body = "comment pruned due to size";
}

set_url(d);
}

void discussion_helper::set_pending_payout(discussion& d) const {
pimpl->set_pending_payout(d);
}
//
// set_url
void discussion_helper::impl::set_url(discussion& d) const {
Expand All @@ -321,9 +329,6 @@ namespace golos { namespace api {
}
}

void discussion_helper::set_url(discussion& d) const {
pimpl->set_url(d);
}
//
// create_discussion
discussion discussion_helper::impl::create_discussion(const std::string& author) const {
Expand Down
7 changes: 2 additions & 5 deletions libraries/api/include/golos/api/discussion_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ namespace golos { namespace api {
);
~discussion_helper();


void set_pending_payout(discussion& d) const;

void set_url(discussion& d) const;

std::vector<vote_state> select_active_votes(
const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset
) const;
Expand All @@ -38,6 +33,8 @@ namespace golos { namespace api {

comment_api_object create_comment_api_object(const comment_object& o) const;

void fill_discussion(discussion&, const comment_object&, uint32_t vote_limit, uint32_t offset) const;

void fill_comment_api_object(const comment_object& o, comment_api_object& d) const;


Expand Down
2 changes: 1 addition & 1 deletion libraries/protocol/include/golos/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
#pragma once

#define STEEMIT_BLOCKCHAIN_VERSION (version(0, 19, 0))
#define STEEMIT_BLOCKCHAIN_VERSION (version(0, 19, 1))
#define STEEMIT_BLOCKCHAIN_HARDFORK_VERSION (hardfork_version(STEEMIT_BLOCKCHAIN_VERSION))

#ifdef STEEMIT_BUILD_TESTNET
Expand Down
16 changes: 9 additions & 7 deletions plugins/database_api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ struct plugin::api_impl final {
uint64_t get_account_count() const;

// Authority / validation
std::string get_transaction_hex(const signed_transaction &trx) const;
std::set<public_key_type> get_required_signatures(const signed_transaction &trx, const flat_set<public_key_type> &available_keys) const;
std::set<public_key_type> get_potential_signatures(const signed_transaction &trx) const;
bool verify_authority(const signed_transaction &trx) const;
Expand Down Expand Up @@ -572,17 +571,20 @@ DEFINE_API(plugin, get_account_bandwidth) {
// //
//////////////////////////////////////////////////////////////////////

DEFINE_API(plugin, get_transaction_hex) {
DEFINE_API(plugin, get_transaction_digest) {
PLUGIN_API_VALIDATE_ARGS(
(signed_transaction, trx)
(transaction, trx)
);
return my->database().with_weak_read_lock([&]() {
return my->get_transaction_hex(trx);
});
static const auto chain_id = STEEMIT_CHAIN_ID;
return trx.sig_digest(chain_id).str();
}

std::string plugin::api_impl::get_transaction_hex(const signed_transaction &trx) const {
DEFINE_API(plugin, get_transaction_hex) {
PLUGIN_API_VALIDATE_ARGS(
(transaction, trx)
);
return fc::to_hex(fc::raw::pack(trx));

}

DEFINE_API(plugin, get_required_signatures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ DEFINE_API_ARGS(get_vesting_delegations, msg_pack, vector<vesting_deleg
DEFINE_API_ARGS(get_expiring_vesting_delegations, msg_pack, vector<vesting_delegation_expiration_api_object>)

DEFINE_API_ARGS(get_conversion_requests, msg_pack, std::vector<convert_request_api_object>)
DEFINE_API_ARGS(get_transaction_digest, msg_pack, std::string)
DEFINE_API_ARGS(get_transaction_hex, msg_pack, std::string)
DEFINE_API_ARGS(get_required_signatures, msg_pack, std::set<public_key_type>)
DEFINE_API_ARGS(get_potential_signatures, msg_pack, std::set<public_key_type>)
Expand Down Expand Up @@ -284,6 +285,9 @@ class plugin final : public appbase::plugin<plugin> {
// Authority / Validation //
////////////////////////////

/// @brief Get a hexdump of the serialized binary form of a transaction digest
(get_transaction_digest)

/// @brief Get a hexdump of the serialized binary form of a transaction
(get_transaction_hex)

Expand Down
64 changes: 40 additions & 24 deletions plugins/social_network/social_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,32 +230,30 @@ namespace golos { namespace plugins { namespace social_network {
}

void operator()(const delete_comment_operation& o) const {
const auto& comment = impl.db.get_comment(o.author, o.permlink);
const auto content = impl.find_comment_content(comment.id);

if (content == nullptr) {
const auto* comment = impl.db.find_comment(o.author, o.permlink);
if (comment == nullptr) {
return;
}

impl.db.remove(*content);
const auto content = impl.find_comment_content(comment->id);

if (impl.db.template has_index<comment_last_update_index>()) {
if (comment.net_rshares > 0) {
return;
}
if (content != nullptr) {
impl.db.remove(*content);
}

impl.activate_parent_comments(comment);
if (impl.db.template has_index<comment_last_update_index>()) {
impl.activate_parent_comments(*comment);

auto& idx = impl.db.template get_index<comment_last_update_index>().indices().template get<by_comment>();
auto itr = idx.find(comment.id);
auto itr = idx.find(comment->id);
if (idx.end() != itr) {
impl.db.remove(*itr);
}
}

if (impl.db.template has_index<comment_reward_index>()) {
auto& idx = impl.db.template get_index<comment_reward_index>().indices().template get<by_comment>();
auto itr = idx.find(comment.id);
auto itr = idx.find(comment->id);
if (idx.end() != itr) {
impl.db.remove(*itr);
}
Expand Down Expand Up @@ -287,10 +285,14 @@ namespace golos { namespace plugins { namespace social_network {
} /// ignore all other ops

void operator()(const golos::protocol::comment_operation& o) const {
const auto& comment = db.get_comment(o.author, o.permlink);
const auto* comment = db.find_comment(o.author, o.permlink);
if (nullptr == comment) {
return;
}

const auto& dp = depth_parameters;
if (!dp.miss_content()) {
const auto comment_content = impl.find_comment_content(comment.id);
const auto comment_content = impl.find_comment_content(comment->id);
if ( comment_content != nullptr) {
// Edit case
db.modify(*comment_content, [&]( comment_content_object& con ) {
Expand Down Expand Up @@ -331,7 +333,7 @@ namespace golos { namespace plugins { namespace social_network {
} else {
// Creation case
db.create<comment_content_object>([&](comment_content_object& con) {
con.comment = comment.id;
con.comment = comment->id;
if (!dp.has_comment_title_depth || dp.comment_title_depth > 0) {
from_string(con.title, o.title);
}
Expand All @@ -351,8 +353,8 @@ namespace golos { namespace plugins { namespace social_network {

if (db.has_index<comment_last_update_index>()) {
auto now = db.head_block_time();
if (!impl.set_comment_update(comment, now, true)) { // If create case
impl.activate_parent_comments(comment);
if (!impl.set_comment_update(*comment, now, true)) { // If create case
impl.activate_parent_comments(*comment);
}
}
}
Expand Down Expand Up @@ -472,10 +474,14 @@ namespace golos { namespace plugins { namespace social_network {
auto& content = *itr;
++itr;

auto& comment = db.get_comment(content.comment);
auto* comment = db.find<comment_object, by_id>(content.comment);
if (nullptr == comment) {
db.remove(content);
continue;
}

auto delta = head_block_num - content.block_number;
if (comment.mode == archived && dp.should_delete_part_of_content_object(delta)) {
if (comment->mode == archived && dp.should_delete_part_of_content_object(delta)) {
if (dp.should_delete_whole_content_object(delta)) {
db.remove(content);
continue;
Expand Down Expand Up @@ -509,10 +515,14 @@ namespace golos { namespace plugins { namespace social_network {
auto& clu = *itr;
++itr;

auto& comment = db.get_comment(clu.comment);
auto* comment = db.find<comment_object, by_id>(clu.comment);
if (nullptr == comment) {
db.remove(clu);
continue;
}

auto delta = head_block_num - clu.block_number;
if (comment.mode == archived && depth_parameters.should_delete_last_update_object(delta)) {
if (comment->mode == archived && depth_parameters.should_delete_last_update_object(delta)) {
db.remove(clu);
} else {
break;
Expand Down Expand Up @@ -720,9 +730,12 @@ namespace golos { namespace plugins { namespace social_network {
continue;
}

const auto& vo = db.get(itr->comment);
const auto* vo = db.find(itr->comment);
if (nullptr == vo) {
continue;
}
account_vote avote;
avote.authorperm = vo.author + "/" + to_string(vo.permlink);
avote.authorperm = vo->author + "/" + to_string(vo->permlink);
//avote.weight = itr->weight; // TODO:
avote.rshares = itr->rshares;
avote.percent = itr->vote_percent;
Expand Down Expand Up @@ -806,7 +819,10 @@ namespace golos { namespace plugins { namespace social_network {
result.reserve(limit);

while (itr != clu_idx.end() && result.size() < limit && itr->parent_author == *parent_author) {
result.emplace_back(get_discussion(db.get_comment(itr->comment), vote_limit, vote_offset));
auto* comment = db.find<comment_object, by_id>(itr->comment);
if (nullptr != comment) {
result.emplace_back(get_discussion(*comment, vote_limit, vote_offset));
}
++itr;
}

Expand Down
25 changes: 2 additions & 23 deletions plugins/tags/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ namespace golos { namespace plugins { namespace tags {
return database_;
}

std::vector<vote_state> select_active_votes(const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset) const;

bool filter_tags(const tags::tag_type type, std::set<std::string>& select_tags) const;

bool filter_authors(discussion_query& query) const;
Expand Down Expand Up @@ -84,10 +82,6 @@ namespace golos { namespace plugins { namespace tags {

std::vector<std::pair<std::string, uint32_t>> get_tags_used_by_author(const std::string& author) const;

void set_pending_payout(discussion& d) const;

void set_url(discussion& d) const;

std::vector<discussion> get_replies_by_last_update(
account_name_type start_parent_author, std::string start_permlink,
uint32_t limit, uint32_t vote_limit
Expand All @@ -111,12 +105,6 @@ namespace golos { namespace plugins { namespace tags {
std::unique_ptr<discussion_helper> helper;
};

std::vector<vote_state> tags_plugin::impl::select_active_votes(
const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset
) const {
return helper->select_active_votes(author, permlink, limit, offset);
}

discussion tags_plugin::impl::get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t votes_offset) const {
return helper->get_discussion(c, vote_limit, votes_offset);
}
Expand All @@ -139,9 +127,8 @@ namespace golos { namespace plugins { namespace tags {
}

void tags_plugin::impl::fill_discussion(discussion& d, const discussion_query& query) const {
set_url(d);
set_pending_payout(d);
d.active_votes = select_active_votes(d.author, d.permlink, query.vote_limit, query.vote_offset);
helper->fill_discussion(d, database_.get_comment(d.author, d.permlink), query.vote_limit, query.vote_offset);

d.body_length = static_cast<uint32_t>(d.body.size());
if (query.truncate_body) {
if (d.body.size() > query.truncate_body) {
Expand Down Expand Up @@ -231,21 +218,13 @@ namespace golos { namespace plugins { namespace tags {

tags_plugin::~tags_plugin() = default;

void tags_plugin::impl::set_url(discussion& d) const {
helper->set_url( d );
}

boost::multiprecision::uint256_t to256(const fc::uint128_t& t) {
boost::multiprecision::uint256_t result(t.high_bits());
result <<= 65;
result += t.low_bits();
return result;
}

void tags_plugin::impl::set_pending_payout(discussion& d) const {
helper->set_pending_payout(d);
}

bool tags_plugin::impl::filter_tags(const tags::tag_type type, std::set<std::string>& select_tags) const {
if (select_tags.empty()) {
return true;
Expand Down

0 comments on commit a88d70e

Please sign in to comment.