forked from btscube/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
201 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
file(GLOB HEADERS "include/steemit/plugins/raw_block/*.hpp") | ||
|
||
add_library( steemit_raw_block | ||
${HEADERS} | ||
raw_block_plugin.cpp | ||
raw_block_api.cpp | ||
) | ||
|
||
target_link_libraries( steemit_raw_block steemit_app steemit_chain fc graphene_db ) | ||
target_include_directories( steemit_raw_block | ||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) |
61 changes: 61 additions & 0 deletions
61
libraries/plugins/raw_block/include/steemit/plugins/raw_block/raw_block_api.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,61 @@ | ||
|
||
#pragma once | ||
|
||
#include <steemit/chain/protocol/types.hpp> | ||
|
||
#include <fc/api.hpp> | ||
|
||
namespace steemit { namespace app { | ||
struct api_context; | ||
} } | ||
|
||
namespace steemit { namespace plugin { namespace raw_block { | ||
|
||
namespace detail { | ||
class raw_block_api_impl; | ||
} | ||
|
||
struct get_raw_block_args | ||
{ | ||
uint32_t block_num = 0; | ||
}; | ||
|
||
struct get_raw_block_result | ||
{ | ||
chain::block_id_type block_id; | ||
chain::block_id_type previous; | ||
fc::time_point_sec timestamp; | ||
std::string raw_block; | ||
}; | ||
|
||
class raw_block_api | ||
{ | ||
public: | ||
raw_block_api( const steemit::app::api_context& ctx ); | ||
|
||
void on_api_startup(); | ||
|
||
get_raw_block_result get_raw_block( get_raw_block_args args ); | ||
void push_raw_block( std::string block_b64 ); | ||
|
||
private: | ||
std::shared_ptr< detail::raw_block_api_impl > my; | ||
}; | ||
|
||
} } } | ||
|
||
FC_REFLECT( steemit::plugin::raw_block::get_raw_block_args, | ||
(block_num) | ||
) | ||
|
||
FC_REFLECT( steemit::plugin::raw_block::get_raw_block_result, | ||
(block_id) | ||
(previous) | ||
(timestamp) | ||
(raw_block) | ||
) | ||
|
||
FC_API( steemit::plugin::raw_block::raw_block_api, | ||
(get_raw_block) | ||
(push_raw_block) | ||
) |
20 changes: 20 additions & 0 deletions
20
libraries/plugins/raw_block/include/steemit/plugins/raw_block/raw_block_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,20 @@ | ||
|
||
#pragma once | ||
|
||
#include <steemit/app/plugin.hpp> | ||
|
||
namespace steemit { namespace plugin { namespace raw_block { | ||
|
||
class raw_block_plugin : public steemit::app::plugin | ||
{ | ||
public: | ||
raw_block_plugin(); | ||
virtual ~raw_block_plugin(); | ||
|
||
virtual std::string plugin_name()const override; | ||
virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; | ||
virtual void plugin_startup() override; | ||
virtual void plugin_shutdown() override; | ||
}; | ||
|
||
} } } |
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,71 @@ | ||
|
||
#include <steemit/app/api_context.hpp> | ||
#include <steemit/app/application.hpp> | ||
|
||
#include <steemit/plugins/raw_block/raw_block_api.hpp> | ||
#include <steemit/plugins/raw_block/raw_block_plugin.hpp> | ||
|
||
namespace steemit { namespace plugin { namespace raw_block { | ||
|
||
namespace detail { | ||
|
||
class raw_block_api_impl | ||
{ | ||
public: | ||
raw_block_api_impl( steemit::app::application& _app ); | ||
|
||
std::shared_ptr< steemit::plugin::raw_block::raw_block_plugin > get_plugin(); | ||
|
||
steemit::app::application& app; | ||
}; | ||
|
||
raw_block_api_impl::raw_block_api_impl( steemit::app::application& _app ) : app( _app ) | ||
{} | ||
|
||
std::shared_ptr< steemit::plugin::raw_block::raw_block_plugin > raw_block_api_impl::get_plugin() | ||
{ | ||
return app.get_plugin< raw_block_plugin >( "raw_block" ); | ||
} | ||
|
||
} // detail | ||
|
||
raw_block_api::raw_block_api( const steemit::app::api_context& ctx ) | ||
{ | ||
my = std::make_shared< detail::raw_block_api_impl >(ctx.app); | ||
} | ||
|
||
get_raw_block_result raw_block_api::get_raw_block( get_raw_block_args args ) | ||
{ | ||
get_raw_block_result result; | ||
std::shared_ptr< steemit::chain::database > db = my->app.chain_database(); | ||
|
||
fc::optional<chain::signed_block> block = db->fetch_block_by_number( args.block_num ); | ||
if( !block.valid() ) | ||
{ | ||
return result; | ||
} | ||
std::stringstream ss; | ||
fc::raw::pack( ss, *block ); | ||
result.raw_block = fc::base64_encode( ss.str() ); | ||
result.block_id = block->id(); | ||
result.previous = block->previous; | ||
result.timestamp = block->timestamp; | ||
} | ||
|
||
void raw_block_api::push_raw_block( std::string block_b64 ) | ||
{ | ||
std::shared_ptr< steemit::chain::database > db = my->app.chain_database(); | ||
|
||
std::string block_bin = fc::base64_decode( block_b64 ); | ||
std::stringstream ss( block_bin ); | ||
chain::signed_block block; | ||
fc::raw::unpack( ss, block ); | ||
|
||
db->push_block( block ); | ||
|
||
return; | ||
} | ||
|
||
void raw_block_api::on_api_startup() { } | ||
|
||
} } } // steemit::plugin::raw_block |
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,35 @@ | ||
|
||
|
||
#include <steemit/plugins/raw_block/raw_block_api.hpp> | ||
#include <steemit/plugins/raw_block/raw_block_plugin.hpp> | ||
|
||
#include <string> | ||
|
||
namespace steemit { namespace plugin { namespace raw_block { | ||
|
||
raw_block_plugin::raw_block_plugin() {} | ||
raw_block_plugin::~raw_block_plugin() {} | ||
|
||
std::string raw_block_plugin::plugin_name()const | ||
{ | ||
return "raw_block"; | ||
} | ||
|
||
void raw_block_plugin::plugin_initialize( const boost::program_options::variables_map& options ) | ||
{ | ||
} | ||
|
||
void raw_block_plugin::plugin_startup() | ||
{ | ||
chain::database& db = database(); | ||
|
||
app().register_api_factory< raw_block_api >( "raw_block_api" ); | ||
} | ||
|
||
void raw_block_plugin::plugin_shutdown() | ||
{ | ||
} | ||
|
||
} } } // steemit::plugin::raw_block | ||
|
||
STEEMIT_DEFINE_PLUGIN( raw_block, steemit::plugin::raw_block::raw_block_plugin ) |