forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request steemit#700 from GolosChain/643-mongo-db-plugin
Mongo_db steemit#421, steemit#608, steemit#609, steemit#635, steemit#643
- Loading branch information
Showing
25 changed files
with
2,899 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
if(ENABLE_MONGO_PLUGIN) | ||
|
||
# Golos has no direct dependencies on libmongoc but its shared libraries | ||
# will need to be present at runtime for the C++ libraries we use: | ||
# libbsoncxx & libmongocxx (both from github.com/mongodb/mongo-cxx-driver) | ||
|
||
# The *.cmake package files provided by mongo-cxx-driver don't give us the | ||
# absolute path to the libraries, which is needed whenever they are not | ||
# installed in system-known locations. CMake requires the absolute paths | ||
# in target_link_libraries() since we are builiding an archive and the | ||
# link step for all executables using this archive must include the | ||
# mongo-cxx-driver libraries libmongocxx and libbsoncxx. | ||
|
||
find_package(libmongoc-1.0 1.8) | ||
|
||
if (libmongoc-1.0_FOUND) | ||
|
||
message("MongoDB found, building plugin...") | ||
|
||
find_package(libbsoncxx REQUIRED) | ||
find_package(libmongocxx REQUIRED) | ||
|
||
set(CURRENT_TARGET mongo_db) | ||
|
||
list(APPEND CURRENT_TARGET_HEADERS | ||
include/golos/plugins/mongo_db/mongo_db_plugin.hpp | ||
include/golos/plugins/mongo_db/mongo_db_writer.hpp | ||
include/golos/plugins/mongo_db/mongo_db_operations.hpp | ||
include/golos/plugins/mongo_db/mongo_db_state.hpp | ||
include/golos/plugins/mongo_db/mongo_db_types.hpp | ||
) | ||
|
||
list(APPEND CURRENT_TARGET_SOURCES | ||
mongo_db_plugin.cpp | ||
mongo_db_writer.cpp | ||
mongo_db_operations.cpp | ||
mongo_db_state.cpp | ||
mongo_db_types.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::json_rpc | ||
golos_chain | ||
golos::chain_plugin | ||
golos::follow | ||
appbase | ||
fc | ||
${LIBBSONCXX_LIBRARIES} | ||
${LIBMONGOCXX_LIBRARIES} | ||
) | ||
target_include_directories(golos_${CURRENT_TARGET} PUBLIC "include" ${LIBMONGOCXX_INCLUDE_DIRS} ${LIBBSONCXX_INCLUDE_DIRS}) | ||
|
||
install(TARGETS | ||
golos_${CURRENT_TARGET} | ||
|
||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
) | ||
install( FILES ${HEADERS} DESTINATION "include/golos/plugins/mongo_db" ) | ||
else() | ||
message("Mongo drivers NOT found. Use proper Dockerfile") | ||
endif() | ||
endif() |
85 changes: 85 additions & 0 deletions
85
plugins/mongo_db/include/golos/plugins/mongo_db/mongo_db_operations.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#pragma once | ||
|
||
#include <golos/protocol/operations.hpp> | ||
#include <golos/chain/database.hpp> | ||
|
||
#include <golos/plugins/mongo_db/mongo_db_types.hpp> | ||
|
||
|
||
namespace golos { | ||
namespace plugins { | ||
namespace mongo_db { | ||
|
||
class operation_writer { | ||
public: | ||
using result_type = document; | ||
|
||
operation_writer(); | ||
|
||
result_type operator()(const vote_operation& op); | ||
result_type operator()(const comment_operation& op); | ||
result_type operator()(const transfer_operation& op); | ||
result_type operator()(const transfer_to_vesting_operation& op); | ||
result_type operator()(const withdraw_vesting_operation& op); | ||
result_type operator()(const limit_order_create_operation& op); | ||
result_type operator()(const limit_order_cancel_operation& op); | ||
result_type operator()(const feed_publish_operation& op); | ||
result_type operator()(const convert_operation& op); | ||
result_type operator()(const account_create_operation& op); | ||
result_type operator()(const account_update_operation& op); | ||
result_type operator()(const witness_update_operation& op); | ||
result_type operator()(const account_witness_vote_operation& op); | ||
result_type operator()(const account_witness_proxy_operation& op); | ||
result_type operator()(const pow_operation& op); | ||
result_type operator()(const custom_operation& op); | ||
result_type operator()(const report_over_production_operation& op); | ||
result_type operator()(const delete_comment_operation& op); | ||
result_type operator()(const custom_json_operation& op); | ||
result_type operator()(const comment_options_operation& op); | ||
result_type operator()(const set_withdraw_vesting_route_operation& op); | ||
result_type operator()(const limit_order_create2_operation& op); | ||
result_type operator()(const challenge_authority_operation& op); | ||
result_type operator()(const prove_authority_operation& op); | ||
result_type operator()(const request_account_recovery_operation& op); | ||
result_type operator()(const recover_account_operation& op); | ||
result_type operator()(const change_recovery_account_operation& op); | ||
result_type operator()(const escrow_transfer_operation& op); | ||
result_type operator()(const escrow_dispute_operation& op); | ||
result_type operator()(const escrow_release_operation&op); | ||
result_type operator()(const pow2_operation& op); | ||
result_type operator()(const escrow_approve_operation& op); | ||
result_type operator()(const transfer_to_savings_operation& op); | ||
result_type operator()(const transfer_from_savings_operation& op); | ||
result_type operator()(const cancel_transfer_from_savings_operation&op); | ||
result_type operator()(const custom_binary_operation& op); | ||
result_type operator()(const decline_voting_rights_operation& op); | ||
result_type operator()(const reset_account_operation& op); | ||
result_type operator()(const set_reset_account_operation& op); | ||
// | ||
result_type operator()(const delegate_vesting_shares_operation& op); | ||
result_type operator()(const account_create_with_delegation_operation& op); | ||
result_type operator()(const account_metadata_operation& op); | ||
result_type operator()(const proposal_create_operation& op); | ||
result_type operator()(const proposal_update_operation& op); | ||
result_type operator()(const proposal_delete_operation& op); | ||
// | ||
result_type operator()(const fill_convert_request_operation& op); | ||
result_type operator()(const author_reward_operation& op); | ||
result_type operator()(const curation_reward_operation& op); | ||
result_type operator()(const comment_reward_operation& op); | ||
result_type operator()(const liquidity_reward_operation& op); | ||
result_type operator()(const interest_operation& op); | ||
result_type operator()(const fill_vesting_withdraw_operation& op); | ||
result_type operator()(const fill_order_operation& op); | ||
result_type operator()(const shutdown_witness_operation& op); | ||
result_type operator()(const fill_transfer_from_savings_operation& op); | ||
result_type operator()(const hardfork_operation& op); | ||
result_type operator()(const comment_payout_update_operation& op); | ||
result_type operator()(const comment_benefactor_reward_operation& op); | ||
// | ||
result_type operator()(const return_vesting_delegation_operation& op); | ||
// | ||
result_type operator()(const chain_properties_update_operation& op); | ||
}; | ||
|
||
}}} // golos::plugins::mongo_db |
50 changes: 50 additions & 0 deletions
50
plugins/mongo_db/include/golos/plugins/mongo_db/mongo_db_plugin.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <golos/chain/database.hpp> | ||
#include <appbase/plugin.hpp> | ||
#include <golos/plugins/json_rpc/utility.hpp> | ||
#include <golos/plugins/json_rpc/plugin.hpp> | ||
#include <golos/plugins/chain/plugin.hpp> | ||
|
||
|
||
namespace golos { | ||
namespace plugins { | ||
namespace mongo_db { | ||
|
||
class mongo_db_plugin final : public appbase::plugin<mongo_db_plugin> { | ||
public: | ||
|
||
APPBASE_PLUGIN_REQUIRES( | ||
(chain::plugin) | ||
) | ||
|
||
mongo_db_plugin(); | ||
|
||
virtual ~mongo_db_plugin(); | ||
|
||
void set_program_options( | ||
boost::program_options::options_description& cli, | ||
boost::program_options::options_description& cfg | ||
) override; | ||
|
||
void plugin_initialize(const boost::program_options::variables_map& options) override; | ||
|
||
void plugin_startup() override; | ||
|
||
void plugin_shutdown() override; | ||
|
||
constexpr const static char *plugin_name = "mongo_db"; | ||
|
||
static const std::string& name() { | ||
static std::string name = plugin_name; | ||
return name; | ||
} | ||
|
||
private: | ||
class mongo_db_plugin_impl; | ||
|
||
std::unique_ptr<mongo_db_plugin_impl> pimpl_; | ||
}; | ||
|
||
}}} // namespace golos::plugins::mongo_db | ||
|
102 changes: 102 additions & 0 deletions
102
plugins/mongo_db/include/golos/plugins/mongo_db/mongo_db_state.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#pragma once | ||
|
||
#include <boost/multi_index_container.hpp> | ||
#include <boost/multi_index/ordered_index.hpp> | ||
#include <boost/multi_index/hashed_index.hpp> | ||
#include <boost/multi_index/key_extractors.hpp> | ||
#include <boost/multi_index/random_access_index.hpp> | ||
#include <boost/multi_index/sequenced_index.hpp> | ||
|
||
#include <golos/protocol/operations.hpp> | ||
#include <golos/chain/database.hpp> | ||
|
||
#include <golos/plugins/mongo_db/mongo_db_types.hpp> | ||
|
||
namespace golos { | ||
namespace plugins { | ||
namespace mongo_db { | ||
|
||
class state_writer { | ||
public: | ||
using result_type = void; | ||
|
||
state_writer(db_map& bmi_to_add, const signed_block& block); | ||
|
||
result_type operator()(const vote_operation& op); | ||
result_type operator()(const comment_operation& op); | ||
result_type operator()(const transfer_operation& op); | ||
result_type operator()(const transfer_to_vesting_operation& op); | ||
result_type operator()(const withdraw_vesting_operation& op); | ||
result_type operator()(const limit_order_create_operation& op); | ||
result_type operator()(const limit_order_cancel_operation& op); | ||
result_type operator()(const feed_publish_operation& op); | ||
result_type operator()(const convert_operation& op); | ||
result_type operator()(const account_create_operation& op); | ||
result_type operator()(const account_update_operation& op); | ||
result_type operator()(const witness_update_operation& op); | ||
result_type operator()(const account_witness_vote_operation& op); | ||
result_type operator()(const account_witness_proxy_operation& op); | ||
result_type operator()(const pow_operation& op); | ||
result_type operator()(const custom_operation& op); | ||
result_type operator()(const report_over_production_operation& op); | ||
result_type operator()(const delete_comment_operation& op); | ||
result_type operator()(const custom_json_operation& op); | ||
result_type operator()(const comment_options_operation& op); | ||
result_type operator()(const set_withdraw_vesting_route_operation& op); | ||
result_type operator()(const limit_order_create2_operation& op); | ||
result_type operator()(const challenge_authority_operation& op); | ||
result_type operator()(const prove_authority_operation& op); | ||
result_type operator()(const request_account_recovery_operation& op); | ||
result_type operator()(const recover_account_operation& op); | ||
result_type operator()(const change_recovery_account_operation& op); | ||
result_type operator()(const escrow_transfer_operation& op); | ||
result_type operator()(const escrow_dispute_operation& op); | ||
result_type operator()(const escrow_release_operation&op); | ||
result_type operator()(const pow2_operation& op); | ||
result_type operator()(const escrow_approve_operation& op); | ||
result_type operator()(const transfer_to_savings_operation& op); | ||
result_type operator()(const transfer_from_savings_operation& op); | ||
result_type operator()(const cancel_transfer_from_savings_operation&op); | ||
result_type operator()(const custom_binary_operation& op); | ||
result_type operator()(const decline_voting_rights_operation& op); | ||
result_type operator()(const reset_account_operation& op); | ||
result_type operator()(const set_reset_account_operation& op); | ||
result_type operator()(const delegate_vesting_shares_operation& op); | ||
result_type operator()(const account_create_with_delegation_operation& op); | ||
result_type operator()(const account_metadata_operation& op); | ||
result_type operator()(const proposal_create_operation& op); | ||
result_type operator()(const proposal_update_operation& op); | ||
result_type operator()(const proposal_delete_operation& op); | ||
result_type operator()(const fill_convert_request_operation& op); | ||
result_type operator()(const author_reward_operation& op); | ||
result_type operator()(const curation_reward_operation& op); | ||
result_type operator()(const comment_reward_operation& op); | ||
result_type operator()(const liquidity_reward_operation& op); | ||
result_type operator()(const interest_operation& op); | ||
result_type operator()(const fill_vesting_withdraw_operation& op); | ||
result_type operator()(const fill_order_operation& op); | ||
result_type operator()(const shutdown_witness_operation& op); | ||
result_type operator()(const fill_transfer_from_savings_operation& op); | ||
result_type operator()(const hardfork_operation& op); | ||
result_type operator()(const comment_payout_update_operation& op); | ||
result_type operator()(const comment_benefactor_reward_operation& op); | ||
result_type operator()(const return_vesting_delegation_operation& op); | ||
result_type operator()(const chain_properties_update_operation& op); | ||
|
||
private: | ||
database &db_; | ||
|
||
const signed_block &state_block; | ||
|
||
db_map &all_docs; | ||
|
||
void format_comment(const std::string& auth, const std::string& perm); | ||
|
||
named_document create_document(const std::string& name, | ||
const std::string& key, const std::string& keyval); | ||
|
||
named_document create_removal_document(const std::string& name, | ||
const std::string& key, const std::string& keyval); | ||
}; | ||
|
||
}}} // golos::plugins::mongo_db |
Oops, something went wrong.