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

Commit

Permalink
Mongo_db plugin #421, #608, #609, #635, #643
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Jun 1, 2018
1 parent 97fbbfb commit cbc129f
Show file tree
Hide file tree
Showing 24 changed files with 2,898 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Expand Up @@ -90,6 +90,14 @@ if(CHAINBASE_CHECK_LOCKING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCHAINBASE_CHECK_LOCKING")
endif()

option(ENABLE_MONGO_PLUGIN "Build with mongodb plugin" FALSE)
if(ENABLE_MONGO_PLUGIN)
set(MONGO_LIB golos::mongo_db)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMONGODB_PLUGIN_BUILT")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMONGODB_PLUGIN_BUILT")
endif()

if(WIN32)
set(BOOST_ROOT $ENV{BOOST_ROOT})
set(Boost_USE_MULTITHREADED ON)
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Expand Up @@ -43,6 +43,7 @@ RUN \
-DBUILD_SHARED_LIBRARIES=FALSE \
-DLOW_MEMORY_NODE=FALSE \
-DCHAINBASE_CHECK_LOCKING=FALSE \
-DENABLE_MONGO_PLUGIN=FALSE \
.. \
&& \
make -j$(nproc) && \
Expand Down
81 changes: 81 additions & 0 deletions plugins/mongo_db/CMakeLists.txt
@@ -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()
@@ -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
@@ -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 plugins/mongo_db/include/golos/plugins/mongo_db/mongo_db_state.hpp
@@ -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

0 comments on commit cbc129f

Please sign in to comment.