From a03edd14c2e93cefea1e661f999c1226ce3814a8 Mon Sep 17 00:00:00 2001 From: necklace Date: Thu, 14 Jun 2018 18:31:26 +0800 Subject: [PATCH] merge impacted into db_notify --- libraries/app/CMakeLists.txt | 1 - libraries/app/api.cpp | 1 - libraries/app/impacted.cpp | 284 ------------------ libraries/chain/db_notify.cpp | 8 +- .../include/graphene/chain}/impacted.hpp | 2 +- .../account_history_plugin.cpp | 4 +- .../elasticsearch/elasticsearch_plugin.cpp | 4 +- 7 files changed, 10 insertions(+), 294 deletions(-) delete mode 100644 libraries/app/impacted.cpp rename libraries/{app/include/graphene/app => chain/include/graphene/chain}/impacted.hpp (97%) diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index d03f9f111e..827f42634f 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -6,7 +6,6 @@ add_library( graphene_app application.cpp util.cpp database_api.cpp - impacted.cpp plugin.cpp ${HEADERS} ${EGENESIS_HEADERS} diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 613aad812f..22500c6220 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp deleted file mode 100644 index 2486dd107f..0000000000 --- a/libraries/app/impacted.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -namespace graphene { namespace app { - -using namespace fc; -using namespace graphene::chain; - -// TODO: Review all of these, especially no-ops -struct get_impacted_account_visitor -{ - flat_set& _impacted; - get_impacted_account_visitor( flat_set& impact ):_impacted(impact) {} - typedef void result_type; - - void operator()( const transfer_operation& op ) - { - _impacted.insert( op.to ); - _impacted.insert( op.fee_payer() ); // from - } - void operator()( const asset_claim_fees_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const asset_claim_pool_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const limit_order_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // seller - } - void operator()( const limit_order_cancel_operation& op ) - { - _impacted.insert( op.fee_payer() ); // fee_paying_account - } - void operator()( const call_order_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // funding_account - } - void operator()( const bid_collateral_operation& op ) - { - _impacted.insert( op.fee_payer() ); // bidder - } - void operator()( const fill_order_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account_id - } - void operator()( const execute_bid_operation& op ) - { - _impacted.insert( op.fee_payer() ); // bidder - } - void operator()( const account_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // registrar - _impacted.insert( op.referrer ); - add_authority_accounts( _impacted, op.owner ); - add_authority_accounts( _impacted, op.active ); - } - void operator()( const account_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account - if( op.owner ) - add_authority_accounts( _impacted, *(op.owner) ); - if( op.active ) - add_authority_accounts( _impacted, *(op.active) ); - } - void operator()( const account_whitelist_operation& op ) - { - _impacted.insert( op.fee_payer() ); // authorizing_account - _impacted.insert( op.account_to_list ); - } - void operator()( const account_upgrade_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account_to_upgrade - } - void operator()( const account_transfer_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account_id - } - void operator()( const asset_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const asset_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - if( op.new_issuer ) - _impacted.insert( *(op.new_issuer) ); - } - void operator()( const asset_update_issuer_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - _impacted.insert( op.new_issuer ); - } - void operator()( const asset_update_bitasset_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const asset_update_feed_producers_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const asset_issue_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - _impacted.insert( op.issue_to_account ); - } - void operator()( const asset_reserve_operation& op ) - { - _impacted.insert( op.fee_payer() ); // payer - } - void operator()( const asset_fund_fee_pool_operation& op ) - { - _impacted.insert( op.fee_payer() ); // from_account - } - void operator()( const asset_settle_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account - } - void operator()( const asset_global_settle_operation& op ) - { - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const asset_publish_feed_operation& op ) - { - _impacted.insert( op.fee_payer() ); // publisher - } - void operator()( const witness_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // witness_account - } - void operator()( const witness_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // witness_account - } - void operator()( const proposal_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // fee_paying_account - vector other; - for( const auto& proposed_op : op.proposed_ops ) - operation_get_required_authorities( proposed_op.op, _impacted, _impacted, other ); - for( auto& o : other ) - add_authority_accounts( _impacted, o ); - } - void operator()( const proposal_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // fee_paying_account - } - void operator()( const proposal_delete_operation& op ) - { - _impacted.insert( op.fee_payer() ); // fee_paying_account - } - void operator()( const withdraw_permission_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // withdraw_from_account - _impacted.insert( op.authorized_account ); - } - void operator()( const withdraw_permission_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // withdraw_from_account - _impacted.insert( op.authorized_account ); - } - void operator()( const withdraw_permission_claim_operation& op ) - { - _impacted.insert( op.fee_payer() ); // withdraw_to_account - _impacted.insert( op.withdraw_from_account ); - } - void operator()( const withdraw_permission_delete_operation& op ) - { - _impacted.insert( op.fee_payer() ); // withdraw_from_account - _impacted.insert( op.authorized_account ); - } - void operator()( const committee_member_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // committee_member_account - } - void operator()( const committee_member_update_operation& op ) - { - _impacted.insert( op.fee_payer() ); // committee_member_account - } - void operator()( const committee_member_update_global_parameters_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account_id_type() - } - void operator()( const vesting_balance_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // creator - _impacted.insert( op.owner ); - } - void operator()( const vesting_balance_withdraw_operation& op ) - { - _impacted.insert( op.fee_payer() ); // owner - } - void operator()( const worker_create_operation& op ) - { - _impacted.insert( op.fee_payer() ); // owner - } - void operator()( const custom_operation& op ) - { - _impacted.insert( op.fee_payer() ); // payer - } - void operator()( const assert_operation& op ) - { - _impacted.insert( op.fee_payer() ); // fee_paying_account - } - void operator()( const balance_claim_operation& op ) - { - _impacted.insert( op.fee_payer() ); // deposit_to_account - } - void operator()( const override_transfer_operation& op ) - { - _impacted.insert( op.to ); - _impacted.insert( op.from ); - _impacted.insert( op.fee_payer() ); // issuer - } - void operator()( const transfer_to_blind_operation& op ) - { - _impacted.insert( op.fee_payer() ); // from - for( const auto& out : op.outputs ) - add_authority_accounts( _impacted, out.owner ); - } - void operator()( const blind_transfer_operation& op ) - { - _impacted.insert( op.fee_payer() ); // GRAPHENE_TEMP_ACCOUNT - for( const auto& in : op.inputs ) - add_authority_accounts( _impacted, in.owner ); - for( const auto& out : op.outputs ) - add_authority_accounts( _impacted, out.owner ); - } - void operator()( const transfer_from_blind_operation& op ) - { - _impacted.insert( op.fee_payer() ); // GRAPHENE_TEMP_ACCOUNT - _impacted.insert( op.to ); - for( const auto& in : op.inputs ) - add_authority_accounts( _impacted, in.owner ); - } - void operator()( const asset_settle_cancel_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account - } - void operator()( const fba_distribute_operation& op ) - { - _impacted.insert( op.fee_payer() ); // account_id - } -}; - -void operation_get_impacted_accounts( const operation& op, flat_set& result ) -{ - get_impacted_account_visitor vtor = get_impacted_account_visitor( result ); - op.visit( vtor ); -} - -void transaction_get_impacted_accounts( const transaction& tx, flat_set& result ) -{ - for( const auto& op : tx.operations ) - operation_get_impacted_accounts( op, result ); -} - -} } diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index 3690de47f2..08c2b88928 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -15,6 +15,8 @@ #include #include +#include + using namespace fc; using namespace graphene::chain; @@ -257,19 +259,19 @@ struct get_impacted_account_visitor } }; -static void operation_get_impacted_accounts( const operation& op, flat_set& result ) +void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set& result ) { get_impacted_account_visitor vtor = get_impacted_account_visitor( result ); op.visit( vtor ); } -static void transaction_get_impacted_accounts( const transaction& tx, flat_set& result ) +void graphene::chain::transaction_get_impacted_accounts( const transaction& tx, flat_set& result ) { for( const auto& op : tx.operations ) operation_get_impacted_accounts( op, result ); } -static void get_relevant_accounts( const object* obj, flat_set& accounts ) +void get_relevant_accounts( const object* obj, flat_set& accounts ) { if( obj->id.space() == protocol_ids ) { diff --git a/libraries/app/include/graphene/app/impacted.hpp b/libraries/chain/include/graphene/chain/impacted.hpp similarity index 97% rename from libraries/app/include/graphene/app/impacted.hpp rename to libraries/chain/include/graphene/chain/impacted.hpp index 2e59b91047..739997a874 100644 --- a/libraries/app/include/graphene/app/impacted.hpp +++ b/libraries/chain/include/graphene/chain/impacted.hpp @@ -28,7 +28,7 @@ #include #include -namespace graphene { namespace app { +namespace graphene { namespace chain { void operation_get_impacted_accounts( const graphene::chain::operation& op, diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 37ec1393e1..e3ff7a1f10 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -24,7 +24,7 @@ #include -#include +#include #include #include @@ -134,7 +134,7 @@ void account_history_plugin_impl::update_account_histories( const signed_block& if( op.op.which() == operation::tag< account_create_operation >::value ) impacted.insert( op.result.get() ); else - graphene::app::operation_get_impacted_accounts( op.op, impacted ); + graphene::chain::operation_get_impacted_accounts( op.op, impacted ); for( auto& a : other ) for( auto& item : a.account_auths ) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 2398fc7b42..f0287919f8 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -24,7 +24,7 @@ #include -#include +#include #include #include @@ -135,7 +135,7 @@ void elasticsearch_plugin_impl::update_account_histories( const signed_block& b if( op.op.which() == operation::tag< account_create_operation >::value ) impacted.insert( op.result.get() ); else - graphene::app::operation_get_impacted_accounts( op.op, impacted ); + graphene::chain::operation_get_impacted_accounts( op.op, impacted ); for( auto& a : other ) for( auto& item : a.account_auths )