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

Commit

Permalink
Operation dump plugin #1287
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 authored and soft-bagel-93 committed May 7, 2019
1 parent ef7858a commit 492109b
Show file tree
Hide file tree
Showing 19 changed files with 488 additions and 5 deletions.
5 changes: 5 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,11 @@ namespace golos { namespace chain {
modify(get_account(comment.author), [&](account_object &a) {
a.posting_rewards += author_tokens;
});

auto author_golos = asset(author_tokens, STEEM_SYMBOL);
auto benefactor_golos = asset(total_beneficiary, STEEM_SYMBOL);
auto curator_golos = asset(reward_tokens.to_uint64() - (author_tokens + total_beneficiary), STEEM_SYMBOL);
push_virtual_operation(total_comment_reward_operation(comment.author, to_string(comment.permlink), author_golos, benefactor_golos, curator_golos, comment.net_rshares.value));
}

fc::uint128_t old_rshares2 = calculate_vshares(comment.net_rshares.value);
Expand Down
3 changes: 2 additions & 1 deletion libraries/protocol/include/golos/protocol/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ namespace golos { namespace protocol {
return_vesting_delegation_operation,
producer_reward_operation,
delegation_reward_operation,
auction_window_reward_operation
auction_window_reward_operation,
total_comment_reward_operation
> operation;

/*void operation_get_required_authorities( const operation& op,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ namespace golos { namespace protocol {
account_name_type account;
asset vesting_shares;
};

struct total_comment_reward_operation : public virtual_operation {
total_comment_reward_operation() {
}

total_comment_reward_operation(const account_name_type& a, const string &p, const asset& ar, const asset& br, const asset& cr, int64_t nr)
: author(a), permlink(p), author_reward(ar), benefactor_reward(br), curator_reward(cr), net_rshares(nr) {
}

account_name_type author;
string permlink;
asset author_reward;
asset benefactor_reward;
asset curator_reward;
int64_t net_rshares;
};
} } //golos::protocol

FC_REFLECT((golos::protocol::author_reward_operation), (author)(permlink)(sbd_payout)(steem_payout)(vesting_payout))
Expand All @@ -251,3 +267,4 @@ FC_REFLECT((golos::protocol::comment_benefactor_reward_operation), (benefactor)(
FC_REFLECT((golos::protocol::return_vesting_delegation_operation), (account)(vesting_shares))
FC_REFLECT((golos::protocol::producer_reward_operation), (producer)(vesting_shares))
FC_REFLECT((golos::protocol::delegation_reward_operation), (delegator)(delegatee)(payout_strategy)(vesting_shares))
FC_REFLECT((golos::protocol::total_comment_reward_operation), (author)(permlink)(author_reward)(benefactor_reward)(curator_reward)(net_rshares))
4 changes: 4 additions & 0 deletions plugins/account_history/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ if (options.count(name)) { \
insert_receiver(op.account);
}

void operator()(const total_comment_reward_operation& op) {
insert_dual(op.author);
}

// todo: proposal tx signers are receivers
void operator()(const proposal_create_operation& op) {
insert_dual(op.author);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace mongo_db {
result_type operator()(const chain_properties_update_operation& op);
result_type operator()(const delegation_reward_operation& op);
result_type operator()(const auction_window_reward_operation& op);
result_type operator()(const total_comment_reward_operation& op);
};

}}} // golos::plugins::mongo_db
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace mongo_db {
result_type operator()(const chain_properties_update_operation& op);
result_type operator()(const delegation_reward_operation& op);
result_type operator()(const auction_window_reward_operation& op);
result_type operator()(const total_comment_reward_operation& op);

void write_global_property_object(const dynamic_global_property_object& dgpo, bool history);

Expand Down
5 changes: 5 additions & 0 deletions plugins/mongo_db/mongo_db_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,9 @@ namespace mongo_db {
return body;
}

auto operation_writer::operator()(const total_comment_reward_operation& op) -> result_type {
result_type body;
return body;
}

}}}
4 changes: 4 additions & 0 deletions plugins/mongo_db/mongo_db_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,4 +1927,8 @@ namespace mongo_db {

}

auto state_writer::operator()(const total_comment_reward_operation& op) -> result_type {

}

}}}
44 changes: 44 additions & 0 deletions plugins/operation_dump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set(CURRENT_TARGET operation_dump)

list(APPEND CURRENT_TARGET_HEADERS
include/golos/plugins/operation_dump/operation_dump_plugin.hpp
include/golos/plugins/operation_dump/operation_dump_container.hpp
)

list(APPEND CURRENT_TARGET_SOURCES
operation_dump_plugin.cpp
)

if(BUILD_SHARED_LIBRARIES)
add_library(golos_${CURRENT_TARGET} SHARED
${CURRENT_TARGET_HEADERS}
${CURRENT_TARGET_SOURCES}
)
else()
add_library(golos_${CURRENT_TARGET} STATIC
${CURRENT_TARGET_HEADERS}
${CURRENT_TARGET_SOURCES}
)
endif()

add_library(golos::${CURRENT_TARGET} ALIAS golos_${CURRENT_TARGET})
set_property(TARGET golos_${CURRENT_TARGET} PROPERTY EXPORT_NAME ${CURRENT_TARGET})

target_link_libraries(
golos_${CURRENT_TARGET}
golos::chain_plugin
golos::follow
golos::tags
appbase
)

target_include_directories(golos_${CURRENT_TARGET}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

install(TARGETS
golos_${CURRENT_TARGET}

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <boost/filesystem/fstream.hpp>

namespace golos { namespace plugins { namespace operation_dump {

namespace bfs = boost::filesystem;

// Structure size can differ - uses sizeof
struct dump_header {
char magic[13] = "Golos\adumpOP";
uint32_t version = 1;
};

using operation_number = std::pair<uint32_t, uint16_t>;

class dump_buffer : public std::stringstream {
public:
dump_buffer() {
}

using std::stringstream::write;

void write(const operation_number& op_num) {
fc::raw::pack(*this, op_num);
}
};

using dump_buffers = std::map<std::string, dump_buffer>;

class dump_file : public bfs::ofstream {
public:
dump_file(const bfs::path& p): bfs::ofstream(p, std::ios_base::binary | std::ios_base::app) {
bfs::ofstream::exceptions(std::ofstream::failbit | std::ofstream::badbit);
}

void write(const dump_header& hdr) {
bfs::ofstream::write((const char*)&hdr, sizeof(dump_header));
}
};

} } } // golos::plugins::operation_dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <appbase/plugin.hpp>
#include <golos/chain/database.hpp>
#include <golos/chain/operation_notification.hpp>
#include <golos/plugins/chain/plugin.hpp>

namespace golos { namespace plugins { namespace operation_dump {

namespace bpo = boost::program_options;
using namespace golos::chain;

class operation_dump_plugin final : public appbase::plugin<operation_dump_plugin> {
public:
APPBASE_PLUGIN_REQUIRES((chain::plugin))

operation_dump_plugin();

~operation_dump_plugin();

void set_program_options(bpo::options_description& cli, bpo::options_description& cfg) override;

void plugin_initialize(const bpo::variables_map& options) override;

void plugin_startup() override;

void plugin_shutdown() override;

static const std::string& name();

private:
class operation_dump_plugin_impl;

std::unique_ptr<operation_dump_plugin_impl> my;
};

} } } //golos::plugins::operation_dump
Loading

0 comments on commit 492109b

Please sign in to comment.