Skip to content

Commit

Permalink
Merge pull request #1 from steemit/master
Browse files Browse the repository at this point in the history
20180912
  • Loading branch information
pipergo authored Sep 12, 2018
2 parents 2e38d01 + b3f6b59 commit 2fba227
Show file tree
Hide file tree
Showing 27 changed files with 302 additions and 94 deletions.
75 changes: 71 additions & 4 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include <steem/chain/global_property_object.hpp>
#include <steem/chain/history_object.hpp>
#include <steem/chain/index.hpp>
#include <steem/chain/pending_required_action_object.hpp>
#include <steem/chain/pending_optional_action_object.hpp>
#include <steem/chain/smt_objects.hpp>
#include <steem/chain/steem_evaluator.hpp>
#include <steem/chain/steem_objects.hpp>
#include <steem/chain/transaction_object.hpp>
#include <steem/chain/shared_db_merkle.hpp>
#include <steem/chain/operation_notification.hpp>
#include <steem/chain/witness_schedule.hpp>

#include <steem/chain/util/asset.hpp>
Expand Down Expand Up @@ -1043,6 +1044,42 @@ void database::notify_pre_apply_operation( operation_notification& note )
STEEM_TRY_NOTIFY( _pre_apply_operation_signal, note )
}

void database::push_required_action( const required_automated_action& a )
{
create< pending_required_action_object >( [&]( pending_required_action_object& pending_action )
{
pending_action.action = a;
});
}

void database::push_optional_action( const optional_automated_action& a )
{
create< pending_optional_action_object >( [&]( pending_optional_action_object& pending_action )
{
pending_action.action = a;
});
}

void database::notify_pre_apply_required_action( const required_action_notification& note )
{
STEEM_TRY_NOTIFY( _pre_apply_required_action_signal, note );
}

void database::notify_post_apply_required_action( const required_action_notification& note )
{
STEEM_TRY_NOTIFY( _post_apply_required_action_signal, note );
}

void database::notify_pre_apply_optional_action( const optional_action_notification& note )
{
STEEM_TRY_NOTIFY( _pre_apply_optional_action_signal, note );
}

void database::notify_post_apply_optional_action( const optional_action_notification& note )
{
STEEM_TRY_NOTIFY( _post_apply_optional_action_signal, note );
}

void database::notify_post_apply_operation( const operation_notification& note )
{
STEEM_TRY_NOTIFY( _post_apply_operation_signal, note )
Expand Down Expand Up @@ -2690,6 +2727,8 @@ void database::initialize_indexes()
add_core_index< reward_fund_index >(*this);
add_core_index< vesting_delegation_index >(*this);
add_core_index< vesting_delegation_expiration_index >(*this);
add_core_index< pending_required_action_index >(*this);
add_core_index< pending_optional_action_index >(*this);
#ifdef STEEM_ENABLE_SMT
add_core_index< smt_token_index >(*this);
add_core_index< smt_event_token_index >(*this);
Expand Down Expand Up @@ -3259,10 +3298,14 @@ struct process_header_visitor
});
}

template<typename T>
void operator()( const T& unknown_obj ) const
void operator()( const required_automated_actions& req_actions ) const
{
FC_ASSERT( false, "Unknown extension in block header" );
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "Automated actions are not enabled until SMT hardfork." );
}

void operator()( const optional_automated_actions& opt_actions ) const
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "Automated actions are not enabled until SMT hardfork." );
}
};

Expand Down Expand Up @@ -3532,6 +3575,30 @@ boost::signals2::connection database::any_apply_operation_handler_impl( const ap
return _post_apply_operation_signal.connect(group, complex_func);
}

boost::signals2::connection database::add_pre_apply_required_action_handler( const apply_required_action_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_pre_apply_required_action_signal, func, plugin, group, "->required_action");
}

boost::signals2::connection database::add_post_apply_required_action_handler( const apply_required_action_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_post_apply_required_action_signal, func, plugin, group, "<-required_action");
}

boost::signals2::connection database::add_pre_apply_optional_action_handler( const apply_optional_action_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_pre_apply_optional_action_signal, func, plugin, group, "->optional_action");
}

boost::signals2::connection database::add_post_apply_optional_action_handler( const apply_optional_action_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_post_apply_optional_action_signal, func, plugin, group, "<-optional_action");
}

boost::signals2::connection database::add_pre_apply_operation_handler( const apply_operation_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
Expand Down
20 changes: 0 additions & 20 deletions libraries/chain/include/steem/chain/block_notification.hpp

This file was deleted.

42 changes: 30 additions & 12 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
*/
#pragma once
#include <steem/chain/block_log.hpp>
#include <steem/chain/block_notification.hpp>
#include <steem/chain/fork_database.hpp>
#include <steem/chain/global_property_object.hpp>
#include <steem/chain/hardfork_property_object.hpp>
#include <steem/chain/node_property_object.hpp>
#include <steem/chain/operation_notification.hpp>
#include <steem/chain/transaction_notification.hpp>
#include <steem/chain/notifications.hpp>

#include <steem/chain/util/advanced_benchmark_dumper.hpp>
#include <steem/chain/util/signal.hpp>
Expand Down Expand Up @@ -248,6 +246,14 @@ namespace steem { namespace chain {
void pre_push_virtual_operation( const operation& op );
void post_push_virtual_operation( const operation& op );

void push_required_action( const required_automated_action& a );
void push_optional_action( const optional_automated_action& a );

void notify_pre_apply_required_action( const required_action_notification& note );
void notify_post_apply_required_action( const required_action_notification& note );

void notify_pre_apply_optional_action( const optional_action_notification& note );
void notify_post_apply_optional_action( const optional_action_notification& note );
/**
* This method is used to track applied operations during the evaluation of a block, these
* operations should include any operation actually included in a transaction as well
Expand All @@ -262,6 +268,8 @@ namespace steem { namespace chain {
void notify_pre_apply_transaction( const transaction_notification& note );
void notify_post_apply_transaction( const transaction_notification& note );

using apply_required_action_handler_t = std::function< void(const required_action_notification&) >;
using apply_optional_action_handler_t = std::function< void(const optional_action_notification&) >;
using apply_operation_handler_t = std::function< void(const operation_notification&) >;
using apply_transaction_handler_t = std::function< void(const transaction_notification&) >;
using apply_block_handler_t = std::function< void(const block_notification&) >;
Expand All @@ -281,15 +289,19 @@ namespace steem { namespace chain {

public:

boost::signals2::connection add_pre_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_transaction_handler( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_irreversible_block_handler ( const irreversible_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_required_action_handler ( const apply_required_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_required_action_handler( const apply_required_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_optional_action_handler ( const apply_optional_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_optional_action_handler( const apply_optional_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_irreversible_block_handler ( const irreversible_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );

//////////////////// db_witness_schedule.cpp ////////////////////

Expand Down Expand Up @@ -565,6 +577,12 @@ namespace steem { namespace chain {

util::advanced_benchmark_dumper _benchmark_dumper;

fc::signal<void(const required_action_notification&)> _pre_apply_required_action_signal;
fc::signal<void(const required_action_notification&)> _post_apply_required_action_signal;

fc::signal<void(const optional_action_notification&)> _pre_apply_optional_action_signal;
fc::signal<void(const optional_action_notification&)> _post_apply_optional_action_signal;

fc::signal<void(const operation_notification&)> _pre_apply_operation_signal;
/**
* This signal is emitted for plugins to process every operation after it has been fully applied.
Expand Down
57 changes: 57 additions & 0 deletions libraries/chain/include/steem/chain/notifications.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#include <steem/protocol/block.hpp>

namespace steem { namespace chain {

struct block_notification
{
block_notification( const steem::protocol::signed_block& b ) : block(b)
{
block_id = b.id();
block_num = block_header::num_from_id( block_id );
}

steem::protocol::block_id_type block_id;
uint32_t block_num = 0;
const steem::protocol::signed_block& block;
};

struct transaction_notification
{
transaction_notification( const steem::protocol::signed_transaction& tx ) : transaction(tx)
{
transaction_id = tx.id();
}

steem::protocol::transaction_id_type transaction_id;
const steem::protocol::signed_transaction& transaction;
};

struct operation_notification
{
operation_notification( const operation& o ) : op(o) {}

transaction_id_type trx_id;
uint32_t block = 0;
uint32_t trx_in_block = 0;
uint32_t op_in_trx = 0;
uint32_t virtual_op = 0;
const operation& op;
};

struct required_action_notification
{
required_action_notification( const required_automated_action& a ) : action(a) {}

const required_automated_action& action;
};

struct optional_action_notification
{
optional_action_notification( const optional_automated_action& a ) : action(a) {}

const optional_automated_action& action;
};

} }
21 changes: 0 additions & 21 deletions libraries/chain/include/steem/chain/operation_notification.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include <steem/protocol/required_automated_actions.hpp>

#include <steem/chain/steem_object_types.hpp>

#include <boost/multi_index/composite_key.hpp>

namespace steem { namespace chain {

using steem::protocol::optional_automated_action;

class pending_optional_action_object : public object< pending_optional_action_object_type, pending_optional_action_object >
{
pending_optional_action_object() = delete;

public:
template< typename Constructor, typename Allocator >
pending_optional_action_object( Constructor&& c, allocator< Allocator > a )
{
c( *this );
}

id_type id;

optional_automated_action action;
};

typedef multi_index_container<
pending_optional_action_object,
indexed_by<
ordered_unique< tag< by_id >, member< pending_optional_action_object, pending_optional_action_id_type, &pending_optional_action_object::id > >
>,
allocator< pending_optional_action_object >
> pending_optional_action_index;

} } //steem::chain

FC_REFLECT( steem::chain::pending_optional_action_object,
(id)(action) )
CHAINBASE_SET_INDEX_TYPE( steem::chain::pending_optional_action_object, steem::chain::pending_optional_action_index )
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include <steem/protocol/required_automated_actions.hpp>

#include <steem/chain/steem_object_types.hpp>

#include <boost/multi_index/composite_key.hpp>

namespace steem { namespace chain {

using steem::protocol::required_automated_action;

class pending_required_action_object : public object< pending_required_action_object_type, pending_required_action_object >
{
pending_required_action_object() = delete;

public:
template< typename Constructor, typename Allocator >
pending_required_action_object( Constructor&& c, allocator< Allocator > a )
{
c( *this );
}

id_type id;

required_automated_action action;
};

typedef multi_index_container<
pending_required_action_object,
indexed_by<
ordered_unique< tag< by_id >, member< pending_required_action_object, pending_required_action_id_type, &pending_required_action_object::id > >
>,
allocator< pending_required_action_object >
> pending_required_action_index;

} } //steem::chain

FC_REFLECT( steem::chain::pending_required_action_object,
(id)(action) )
CHAINBASE_SET_INDEX_TYPE( steem::chain::pending_required_action_object, steem::chain::pending_required_action_index )
Loading

0 comments on commit 2fba227

Please sign in to comment.