7 #include <scorum/account_identity/impacted.hpp>
16 #include <fc/smart_ref_impl.hpp>
17 #include <fc/thread/thread.hpp>
19 #include <boost/algorithm/string.hpp>
21 #define SCORUM_NAMESPACE_PREFIX "scorum::protocol::"
24 namespace blockchain_history {
71 bool _filter_content =
false;
72 bool _blacklist =
false;
92 push_history<account_history_object>(_obj);
97 push_history<account_history_object>(_obj);
98 push_history<account_transfers_to_scr_history_object>(_obj);
103 push_history<account_history_object>(_obj);
104 push_history<account_transfers_to_sp_history_object>(_obj);
109 push_history<account_history_object>(_obj);
112 push_progress<account_withdrawals_to_scr_history_object>(_obj);
114 push_history<account_withdrawals_to_scr_history_object>(_obj);
119 push_history<account_history_object>(_obj);
122 push_progress<account_withdrawals_to_scr_history_object>(_obj);
127 push_history<account_history_object>(_obj);
130 push_progress<account_withdrawals_to_scr_history_object>(_obj);
135 push_history<account_history_object>(_obj);
138 push_progress<account_withdrawals_to_scr_history_object>(_obj);
142 template <
typename history_
object_type>
void push_history(
const operation_object& op)
const
145 auto hist_itr = hist_idx.lower_bound(_item);
146 uint32_t sequence = 0;
147 if (hist_itr != hist_idx.end() && hist_itr->account == _item)
148 sequence = hist_itr->sequence + 1;
150 _db.create<history_object_type>([&](history_object_type& ahist) {
151 ahist.account = _item;
152 ahist.sequence = sequence;
157 template <
typename history_
object_type>
void push_progress(
const operation_object& op)
const
159 const auto& idx = _db.get_index<account_history_index<history_object_type>, by_account>();
160 auto it = idx.lower_bound(_item);
161 if (it != idx.end() && it->account == _item)
163 _db.modify<history_object_type>(*it, [&](history_object_type& h) { h.progress.push_back(op.id); });
191 push_devcommittee_history<devcommittee_history_object>(_obj);
192 push_devcommittee_progress<devcommittee_withdrawals_to_scr_history_object>(_obj);
193 push_devcommittee_history<devcommittee_withdrawals_to_scr_history_object>(_obj);
196 push_devcommittee_history<devcommittee_history_object>(_obj);
197 push_devcommittee_history<devcommittee_transfers_to_scr_history_object>(_obj);
200 push_devcommittee_history<devcommittee_history_object>(_obj);
203 push_devcommittee_history<devcommittee_history_object>(_obj);
206 push_devcommittee_history<devcommittee_history_object>(_obj);
212 push_devcommittee_history<devcommittee_history_object>(_obj);
213 push_devcommittee_progress<devcommittee_withdrawals_to_scr_history_object>(_obj);
218 push_devcommittee_history<devcommittee_history_object>(_obj);
219 push_devcommittee_progress<devcommittee_withdrawals_to_scr_history_object>(_obj);
223 template <
typename history_
object_type>
void push_devcommittee_history(
const operation_object& op)
const
225 _db.create<history_object_type>([&](history_object_type& ahist) { ahist.op = op.
id; });
228 template <
typename history_
object_type>
void push_devcommittee_progress(
const operation_object& op)
const
230 const auto& idx = _db.get_index<devcommittee_history_index<history_object_type>, by_id_desc>();
233 _db.modify<history_object_type>(*idx.begin(), [&](history_object_type& h) { h.progress.push_back(op.id); });
242 , _blacklist(blacklist)
248 if (_filter.find(fc::get_typename<T>::name()) != _filter.end())
263 const flat_set<std::string>& _filter;
273 obj.block = note.
block;
277 auto size = fc::raw::pack_size(note.
op);
278 obj.serialized_op.resize(
size);
279 fc::datastream<char*> ds(obj.serialized_op.data(),
size);
280 fc::raw::pack(ds, note.
op);
308 flat_set<account_name_type> impacted;
314 account_identity::operation_get_impacted_accounts(note.
op, impacted);
317 update_filtered_operation_index(new_obj, note.
op);
321 for (
const auto& item : impacted)
323 auto itr = _tracked_accounts.lower_bound(item);
344 if (itr != _tracked_accounts.begin()
345 && ((itr != _tracked_accounts.end() && itr->first != item) || itr == _tracked_accounts.end()))
350 if (!_tracked_accounts.size() || (itr != _tracked_accounts.end() && itr->first <= item && item <= itr->second))
361 , _my(new detail::blockchain_history_plugin_impl(*this))
376 boost::program_options::options_description& cfg)
379 "track-account-range", boost::program_options::value<std::vector<std::string>>()->composing()->multitoken(),
380 "Defines a range of accounts to track as a json pair [\"from\",\"to\"] [from,to] Can be specified multiple "
381 "times")(
"history-whitelist-ops", boost::program_options::value<std::vector<std::string>>()->composing(),
382 "Defines a list of operations which will be explicitly logged.")(
383 "history-blacklist-ops", boost::program_options::value<std::vector<std::string>>()->composing(),
384 "Defines a list of operations which will be explicitly ignored.");
394 typedef std::pair<account_name_type, account_name_type> pairstring;
395 LOAD_VALUE_SET(options,
"track-account-range",
_my->_tracked_accounts, pairstring);
400 if (options.count(
"history-whitelist-ops"))
402 _my->_filter_content =
true;
403 _my->_blacklist =
false;
405 for (
auto& arg : options.at(
"history-whitelist-ops").as<std::vector<std::string>>())
407 std::vector<std::string> ops;
408 boost::split(ops, arg, boost::is_any_of(
" \t,"));
410 for (
const std::string& op : ops)
417 ilog(
"Account History: whitelisting ops ${o}", (
"o",
_my->_op_list));
419 else if (options.count(
"history-blacklist-ops"))
421 _my->_filter_content =
true;
422 _my->_blacklist =
true;
423 for (
auto& arg : options.at(
"history-blacklist-ops").as<std::vector<std::string>>())
425 std::vector<std::string> ops;
426 boost::split(ops, arg, boost::is_any_of(
" \t,"));
428 for (
const std::string& op : ops)
435 ilog(
"Account History: blacklisting ops ${o}", (
"o",
_my->_op_list));
454 return _my->_tracked_accounts;
#define API_ACCOUNT_HISTORY
#define API_BLOCKCHAIN_HISTORY
#define SCORUM_NAMESPACE_PREFIX
#define BLOCKCHAIN_HISTORY_PLUGIN_NAME
void register_api_factory(const std::string &name, std::function< fc::api_ptr(const api_context &)> factory)
application & app() const
virtual void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
blockchain_history_plugin(application *app)
virtual void plugin_startup() override
Begin normal runtime operations.
virtual std::string plugin_name() const override
virtual void plugin_set_program_options(boost::program_options::options_description &cli, boost::program_options::options_description &cfg) override
Fill in command line parameters used by the plugin.
flat_map< account_name_type, account_name_type > tracked_accounts() const
virtual ~blockchain_history_plugin()
std::unique_ptr< detail::blockchain_history_plugin_impl > _my
virtual ~blockchain_history_plugin_impl()
flat_set< std::string > _op_list
flat_map< account_name_type, account_name_type > _tracked_accounts
void on_operation(const operation_notification ¬e)
void update_filtered_operation_index(const operation_object &object, const operation &op)
scorum::chain::database & database()
const operation_object & create_operation_obj(const operation_notification ¬e)
blockchain_history_plugin & _self
blockchain_history_plugin_impl(blockchain_history_plugin &_plugin)
void operator()(const devpool_to_devpool_vesting_withdraw_operation &op) const
void operator()(const Op &) const
devcommittee_operation_visitor(database &db, const operation_object &obj)
void operator()(const devpool_finished_vesting_withdraw_operation &op) const
void operator()(const proposal_virtual_operation &op) const
void operator()(const acc_to_acc_vesting_withdraw_operation &op) const
void operator()(const transfer_operation &) const
void operator()(const transfer_to_scorumpower_operation &) const
void operator()(const acc_to_devpool_vesting_withdraw_operation &op) const
void operator()(const acc_finished_vesting_withdraw_operation &op) const
operation_visitor(database &db, const operation_object &obj, const account_name_type &i)
void operator()(const withdraw_scorumpower_operation &op) const
void operator()(const Op &) const
tracks the blockchain state in an extensible manner
time_point_sec head_block_time() const
fc::signal< void(const operation_notification &)> pre_apply_operation
void set_options(const boost::program_options::variables_map &options)
boost::program_options::options_description get_options_descriptions() const
#define API_DEVCOMMITTEE_HISTORY
filtered_operation_index< filtered_market_operations_history > filtered_market_operations_history_index
filtered_operation_index< filtered_virt_operations_history > filtered_virt_operations_history_index
devcommittee_history_index< devcommittee_withdrawals_to_scr_history_object > devcommittee_withdrawals_to_scr_history_index
shared_multi_index_container< operation_object, indexed_by< ordered_unique< tag< by_id >, member< operation_object, operation_object::id_type, &operation_object::id > >, ordered_unique< tag< by_location >, composite_key< operation_object, member< operation_object, uint32_t, &operation_object::block >, member< operation_object, uint32_t, &operation_object::trx_in_block >, member< operation_object, uint16_t, &operation_object::op_in_trx >, member< operation_object, operation_object::id_type, &operation_object::id > > >, ordered_unique< tag< by_timestamp >, composite_key< operation_object, member< operation_object, fc::time_point_sec, &operation_object::timestamp >, member< operation_object, operation_object::id_type, &operation_object::id > > >, ordered_unique< tag< by_transaction_id >, composite_key< operation_object, member< operation_object, transaction_id_type, &operation_object::trx_id >, member< operation_object, operation_object::id_type, &operation_object::id > > > > > operation_index
account_history_index< account_withdrawals_to_scr_history_object > account_withdrawals_to_scr_history_index
devcommittee_history_index< devcommittee_history_object > devcommittee_operations_full_history_index
shared_multi_index_container< history_object_t, indexed_by< ordered_unique< tag< by_id >, member< history_object_t, typename history_object_t::id_type, &history_object_t::id > >, ordered_unique< tag< by_account >, composite_key< history_object_t, member< history_object_t, account_name_type, &history_object_t::account >, member< history_object_t, uint32_t, &history_object_t::sequence > >, composite_key_compare< std::less< account_name_type >, std::greater< uint32_t > >> >> account_history_index
account_history_index< account_transfers_to_sp_history_object > account_transfers_to_sp_history_index
devcommittee_history_index< devcommittee_transfers_to_scr_history_object > devcommittee_transfers_to_scr_history_index
account_history_index< account_history_object > account_operations_full_history_index
filtered_operation_index< filtered_not_virt_operations_history > filtered_not_virt_operations_history_index
account_history_index< account_transfers_to_scr_history_object > account_transfers_to_scr_history_index
size_t size(db_index &db_idx)
fc::static_variant< vote_operation, comment_operation, transfer_operation, transfer_to_scorumpower_operation, withdraw_scorumpower_operation, account_create_by_committee_operation, account_create_operation, account_create_with_delegation_operation, account_update_operation, witness_update_operation, account_witness_vote_operation, account_witness_proxy_operation, delete_comment_operation, comment_options_operation, set_withdraw_scorumpower_route_to_account_operation, set_withdraw_scorumpower_route_to_dev_pool_operation, prove_authority_operation, request_account_recovery_operation, recover_account_operation, change_recovery_account_operation, escrow_approve_operation, escrow_dispute_operation, escrow_release_operation, escrow_transfer_operation, decline_voting_rights_operation, delegate_scorumpower_operation, create_budget_operation, close_budget_operation, proposal_vote_operation, proposal_create_operation, atomicswap_initiate_operation, atomicswap_redeem_operation, atomicswap_refund_operation, close_budget_by_advertising_moderator_operation, update_budget_operation, create_game_operation, cancel_game_operation, update_game_markets_operation, update_game_start_time_operation, post_game_results_operation, post_bet_operation, cancel_pending_bets_operation, delegate_sp_from_reg_pool_operation, create_nft_operation, update_nft_meta_operation, create_game_round_operation, update_game_round_result_operation, adjust_nft_experience_operation, update_nft_name_operation, author_reward_operation, comment_benefficiary_reward_operation, comment_payout_update_operation, comment_reward_operation, curation_reward_operation, hardfork_operation, producer_reward_operation, active_sp_holders_reward_operation, return_scorumpower_delegation_operation, shutdown_witness_operation, witness_miss_block_operation, expired_contract_refund_operation, acc_finished_vesting_withdraw_operation, devpool_finished_vesting_withdraw_operation, acc_to_acc_vesting_withdraw_operation, devpool_to_acc_vesting_withdraw_operation, acc_to_devpool_vesting_withdraw_operation, devpool_to_devpool_vesting_withdraw_operation, proposal_virtual_operation, budget_outgo_operation, budget_owner_income_operation, active_sp_holders_reward_legacy_operation, budget_closing_operation, bets_matched_operation, game_status_changed_operation, bet_resolved_operation, bet_cancelled_operation, bet_restored_operation, bet_updated_operation > operation
fc::fixed_string_16 account_name_type
bool is_virtual_operation(const operation &op)
bool is_market_operation(const operation &op)
config_api & get_api_config(std::string api_name)
#define LOAD_VALUE_SET(options, name, container, type)
#define SCORUM_DEFINE_PLUGIN(plugin_name, plugin_class)
operation_visitor_filter(const flat_set< std::string > &filter, bool blacklist)
bool operator()(const T &op) const
const protocol::operation & op
const uint32_t trx_in_block
const protocol::transaction_id_type trx_id
account_name_type from_account
account_name_type from_account
account_name_type from_account
protocol::proposal_operation proposal_op
Transfers SCR from one account to another.
account_name_type account