Skip to content

Commit

Permalink
Merge branch 'staging' v0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Jul 22, 2016
2 parents 5c7378e + bb9721a commit 0cca4bc
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2545,13 +2545,13 @@ void database::apply_block( const signed_block& next_block, uint32_t skip )
_apply_block( next_block );
} );

try
/*try
{
/// check invariants
if( is_producing() || !( skip & skip_validate_invariants ) )
validate_invariants();
}
FC_CAPTURE_AND_RETHROW( (next_block) );
FC_CAPTURE_AND_RETHROW( (next_block) );*/
}

void database::_apply_block( const signed_block& next_block )
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steemit/chain/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, 12, 0) )
#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 12, 1) )
#define STEEMIT_BLOCKCHAIN_HARDFORK_VERSION ( hardfork_version( STEEMIT_BLOCKCHAIN_VERSION ) )

#ifdef IS_TEST_NET
Expand Down
11 changes: 11 additions & 0 deletions libraries/plugins/raw_block/CMakeLists.txt
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" )
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)
)
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;
};

} } }
71 changes: 71 additions & 0 deletions libraries/plugins/raw_block/raw_block_api.cpp
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
35 changes: 35 additions & 0 deletions libraries/plugins/raw_block/raw_block_plugin.cpp
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 )

0 comments on commit 0cca4bc

Please sign in to comment.