diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index 4e798712..e18e6e11 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -3,6 +3,7 @@ file(GLOB HEADERS "include/graphene/app/*.hpp") add_library( graphene_app api.cpp application.cpp + impacted.cpp plugin.cpp ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 79651410..b8325ced 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -659,7 +660,7 @@ namespace graphene { namespace app { const auto& aobj = dynamic_cast(obj); assert( aobj != nullptr ); flat_set impacted; - aobj->proposed_transaction.get_impacted_accounts( impacted ); + transaction_get_impacted_accounts( aobj->proposed_transaction, impacted ); result.reserve( impacted.size() ); for( auto& item : impacted ) result.emplace_back(item); break; @@ -717,7 +718,7 @@ namespace graphene { namespace app { const auto& aobj = dynamic_cast(obj); assert( aobj != nullptr ); flat_set impacted; - aobj->trx.get_impacted_accounts( impacted ); + transaction_get_impacted_accounts( aobj->trx, impacted ); result.reserve( impacted.size() ); for( auto& item : impacted ) result.emplace_back(item); break; diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp new file mode 100644 index 00000000..7fb87397 --- /dev/null +++ b/libraries/app/impacted.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2015, Cryptonomex, Inc. + * All rights reserved. + * + * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and + * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, + * are permitted until September 8, 2015, provided that the following conditions are met: + * + * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#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 ); + } + + void operator()( const limit_order_create_operation& op ) {} + void operator()( const limit_order_cancel_operation& op ) {} + void operator()( const call_order_update_operation& op ) {} + void operator()( const fill_order_operation& op ) + { + _impacted.insert( op.account_id ); + } + + void operator()( const account_create_operation& op ) + { + _impacted.insert( op.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.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.account_to_list ); + } + + void operator()( const account_upgrade_operation& op ) {} + void operator()( const account_transfer_operation& op ) + { + _impacted.insert( op.new_owner ); + } + + void operator()( const asset_create_operation& op ) {} + void operator()( const asset_update_operation& op ) + { + if( op.new_issuer ) + _impacted.insert( *(op.new_issuer) ); + } + + void operator()( const asset_update_bitasset_operation& op ) {} + void operator()( const asset_update_feed_producers_operation& op ) {} + + void operator()( const asset_issue_operation& op ) + { + _impacted.insert( op.issue_to_account ); + } + + void operator()( const asset_reserve_operation& op ) {} + void operator()( const asset_fund_fee_pool_operation& op ) {} + void operator()( const asset_settle_operation& op ) {} + void operator()( const asset_global_settle_operation& op ) {} + void operator()( const asset_publish_feed_operation& op ) {} + void operator()( const witness_create_operation& op ) {} + + void operator()( const proposal_create_operation& op ) + { + 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 ) {} + void operator()( const proposal_delete_operation& op ) {} + + void operator()( const withdraw_permission_create_operation& op ) + { + _impacted.insert( op.authorized_account ); + } + + void operator()( const withdraw_permission_update_operation& op ) + { + _impacted.insert( op.authorized_account ); + } + + void operator()( const withdraw_permission_claim_operation& op ) + { + _impacted.insert( op.withdraw_from_account ); + } + + void operator()( const withdraw_permission_delete_operation& op ) + { + _impacted.insert( op.authorized_account ); + } + + void operator()( const committee_member_create_operation& op ) {} + void operator()( const committee_member_update_global_parameters_operation& op ) {} + + void operator()( const vesting_balance_create_operation& op ) + { + _impacted.insert( op.owner ); + } + + void operator()( const vesting_balance_withdraw_operation& op ) {} + void operator()( const worker_create_operation& op ) {} + void operator()( const custom_operation& op ) {} + void operator()( const assert_operation& op ) {} + void operator()( const balance_claim_operation& op ) {} + + void operator()( const override_transfer_operation& op ) + { + _impacted.insert( op.to ); + _impacted.insert( op.from ); + _impacted.insert( op.issuer ); + } + + void operator()( const transfer_to_blind_operation& op ) + { + _impacted.insert( op.from ); + for( const auto& out : op.outputs ) + add_authority_accounts( _impacted, out.owner ); + } + + void operator()( const blind_transfer_operation& op ) + { + 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.to ); + for( const auto& in : op.inputs ) + add_authority_accounts( _impacted, in.owner ); + } +}; + +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/app/include/graphene/app/impacted.hpp b/libraries/app/include/graphene/app/impacted.hpp new file mode 100644 index 00000000..9c869917 --- /dev/null +++ b/libraries/app/include/graphene/app/impacted.hpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, Cryptonomex, Inc. + * All rights reserved. + * + * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and + * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, + * are permitted until September 8, 2015, provided that the following conditions are met: + * + * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include +#include +#include +#include + +namespace graphene { namespace app { + +void operation_get_impacted_accounts( + const graphene::chain::operation& op, + fc::flat_set& result ); + +void transaction_get_impacted_accounts( + const graphene::chain::transaction& tx, + fc::flat_set& result + ); + +} } // graphene::app diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 86095f19..fe4272b3 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -19,6 +19,7 @@ add_library( graphene_chain protocol/types.cpp protocol/address.cpp + protocol/authority.cpp protocol/asset.cpp protocol/assert.cpp protocol/account.cpp diff --git a/libraries/chain/include/graphene/chain/protocol/account.hpp b/libraries/chain/include/graphene/chain/protocol/account.hpp index 2008cf55..5c0045e3 100644 --- a/libraries/chain/include/graphene/chain/protocol/account.hpp +++ b/libraries/chain/include/graphene/chain/protocol/account.hpp @@ -63,14 +63,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return registrar; } void validate()const; share_type calculate_fee(const fee_parameters_type& )const; - - void get_impacted_accounts( flat_set& i )const - { - i.insert(registrar); - i.insert(referrer); - add_authority_accounts( i, owner ); - add_authority_accounts( i, active ); - } }; /** @@ -109,16 +101,8 @@ namespace graphene { namespace chain { void get_required_active_authorities( flat_set& a )const { if( !owner ) a.insert( account ); } - - void get_impacted_accounts( flat_set& i )const - { - i.insert(account); - if( owner ) add_authority_accounts( i, *owner ); - if( active ) add_authority_accounts( i, *active ); - } }; - /** * @brief This operation is used to whitelist and blacklist accounts, primarily for transacting in whitelisted assets * @ingroup operations @@ -161,13 +145,8 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return authorizing_account; } void validate()const { FC_ASSERT( fee.amount >= 0 ); FC_ASSERT(new_listing < 0x4); } - - void get_impacted_accounts( flat_set& i )const - { i.insert(account_to_list); } - }; - /** * @brief Manage an account's membership status * @ingroup operations @@ -224,15 +203,10 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return account_id; } void validate()const; - - void get_impacted_accounts( flat_set& i )const - { - i.insert(new_owner); - } - }; -} } +} } // graphene::chain + FC_REFLECT(graphene::chain::account_options, (memo_key)(voting_account)(num_witness)(num_committee)(votes)(extensions)) FC_REFLECT_TYPENAME( graphene::chain::account_whitelist_operation::account_listing) FC_REFLECT_ENUM( graphene::chain::account_whitelist_operation::account_listing, diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index b79345af..f79b3aec 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -242,8 +242,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return issuer; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; - void get_impacted_accounts( flat_set& i)const - { if( new_issuer ) i.insert( *new_issuer ); } }; /** @@ -358,8 +356,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return issuer; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; - void get_impacted_accounts( flat_set& i)const - { i.insert( issue_to_account ); } }; /** @@ -381,8 +377,8 @@ namespace graphene { namespace chain { void validate()const; }; - } } // graphene::chain + FC_REFLECT( graphene::chain::asset_options, (max_supply) (market_fee_percent) diff --git a/libraries/chain/include/graphene/chain/protocol/authority.hpp b/libraries/chain/include/graphene/chain/protocol/authority.hpp index 28e7c7c2..0c7d1ac0 100644 --- a/libraries/chain/include/graphene/chain/protocol/authority.hpp +++ b/libraries/chain/include/graphene/chain/protocol/authority.hpp @@ -101,6 +101,14 @@ namespace graphene { namespace chain { flat_map address_auths; }; +/** + * Add all account members of the given authority to the given flat_set. + */ +void add_authority_accounts( + flat_set& result, + const authority& a + ); + } } // namespace graphene::chain FC_REFLECT( graphene::chain::authority, (weight_threshold)(account_auths)(key_auths)(address_auths) ) diff --git a/libraries/chain/include/graphene/chain/protocol/balance.hpp b/libraries/chain/include/graphene/chain/protocol/balance.hpp index 612a8214..bb7355b5 100644 --- a/libraries/chain/include/graphene/chain/protocol/balance.hpp +++ b/libraries/chain/include/graphene/chain/protocol/balance.hpp @@ -29,7 +29,7 @@ namespace graphene { namespace chain { } }; -}} // graphene::chain +} } // graphene::chain FC_REFLECT( graphene::chain::balance_claim_operation::fee_parameters_type, ) FC_REFLECT( graphene::chain::balance_claim_operation, diff --git a/libraries/chain/include/graphene/chain/protocol/base.hpp b/libraries/chain/include/graphene/chain/protocol/base.hpp index b162eea4..a721ea57 100644 --- a/libraries/chain/include/graphene/chain/protocol/base.hpp +++ b/libraries/chain/include/graphene/chain/protocol/base.hpp @@ -1,9 +1,9 @@ #pragma once + #include #include #include - namespace graphene { namespace chain { /** @@ -70,15 +70,9 @@ namespace graphene { namespace chain { void get_required_authorities( vector& )const{} void get_required_active_authorities( flat_set& )const{} void get_required_owner_authorities( flat_set& )const{} - void get_impacted_accounts( flat_set& )const{} void validate()const{} static uint64_t calculate_data_fee( uint64_t bytes, uint64_t price_per_kbyte ); - static void add_authority_accounts( flat_set& i, const authority& a ) - { - for( auto& item : a.account_auths ) - i.insert( item.first ); - } }; /** @@ -100,6 +94,7 @@ namespace graphene { namespace chain { ///@} -} } +} } // graphene::chain + FC_REFLECT_TYPENAME( graphene::chain::operation_result ) FC_REFLECT( graphene::chain::void_result, ) diff --git a/libraries/chain/include/graphene/chain/protocol/confidential.hpp b/libraries/chain/include/graphene/chain/protocol/confidential.hpp index 3374909f..f9f976f5 100644 --- a/libraries/chain/include/graphene/chain/protocol/confidential.hpp +++ b/libraries/chain/include/graphene/chain/protocol/confidential.hpp @@ -143,13 +143,6 @@ struct transfer_to_blind_operation : public base_operation account_id_type fee_payer()const { return from; } void validate()const; share_type calculate_fee(const fee_parameters_type& )const; - - void get_impacted_accounts( flat_set& i )const - { - i.insert(from); - for( const auto& out : outputs ) - add_authority_accounts( i, out.owner ); - } }; /** @@ -171,12 +164,6 @@ struct transfer_from_blind_operation : public base_operation account_id_type fee_payer()const { return GRAPHENE_TEMP_ACCOUNT; } void validate()const; - void get_impacted_accounts( flat_set& i )const - { - i.insert(to); - for( const auto& in : inputs ) - add_authority_accounts( i, in.owner ); - } void get_required_authorities( vector& a )const { for( const auto& in : inputs ) @@ -243,13 +230,6 @@ struct blind_transfer_operation : public base_operation void validate()const; share_type calculate_fee( const fee_parameters_type& k )const; - void get_impacted_accounts( flat_set& i )const - { - for( const auto& in : inputs ) - add_authority_accounts( i, in.owner ); - for( const auto& out : outputs ) - add_authority_accounts( i, out.owner ); - } void get_required_authorities( vector& a )const { for( const auto& in : inputs ) @@ -258,6 +238,7 @@ struct blind_transfer_operation : public base_operation }; ///@} endgroup stealth + } } // graphene::chain FC_REFLECT( graphene::chain::stealth_confirmation, @@ -281,4 +262,3 @@ FC_REFLECT( graphene::chain::blind_transfer_operation, FC_REFLECT( graphene::chain::transfer_to_blind_operation::fee_parameters_type, (fee)(price_per_output) ) FC_REFLECT( graphene::chain::transfer_from_blind_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::blind_transfer_operation::fee_parameters_type, (fee)(price_per_output) ) - diff --git a/libraries/chain/include/graphene/chain/protocol/custom.hpp b/libraries/chain/include/graphene/chain/protocol/custom.hpp index 552f5b45..5d3f8b2a 100644 --- a/libraries/chain/include/graphene/chain/protocol/custom.hpp +++ b/libraries/chain/include/graphene/chain/protocol/custom.hpp @@ -29,7 +29,7 @@ namespace graphene { namespace chain { share_type calculate_fee(const fee_parameters_type& k)const; }; - } } // namespace graphene::chain + FC_REFLECT( graphene::chain::custom_operation::fee_parameters_type, (fee)(price_per_kbyte) ) FC_REFLECT( graphene::chain::custom_operation, (fee)(payer)(required_auths)(id)(data) ) diff --git a/libraries/chain/include/graphene/chain/protocol/market.hpp b/libraries/chain/include/graphene/chain/protocol/market.hpp index 45bdde48..99a2c3f7 100644 --- a/libraries/chain/include/graphene/chain/protocol/market.hpp +++ b/libraries/chain/include/graphene/chain/protocol/market.hpp @@ -133,8 +133,6 @@ namespace graphene { namespace chain { /// This is a virtual operation; there is no fee share_type calculate_fee(const fee_parameters_type& k)const { return 0; } - void get_impacted_accounts( flat_set& i)const - { i.insert( account_id ); } }; } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 25fff129..68860bc2 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -79,25 +79,8 @@ namespace graphene { namespace chain { flat_set& owner, vector& other ); - void operation_get_impacted_accounts( const operation& op, - flat_set& accounts ); - void operation_validate( const operation& op ); - /** - * Used to track the result of applying an operation and when it was applied. - * - * TODO: this doesn't belong here. - */ - struct applied_operation - { - operation op; - operation_result result; - uint32_t block_num; - uint16_t transaction_num; - uint16_t op_num; - }; - /** * @brief necessary to support nested operations inside the proposal_create_operation */ diff --git a/libraries/chain/include/graphene/chain/protocol/proposal.hpp b/libraries/chain/include/graphene/chain/protocol/proposal.hpp index e23329f9..d7136690 100644 --- a/libraries/chain/include/graphene/chain/protocol/proposal.hpp +++ b/libraries/chain/include/graphene/chain/protocol/proposal.hpp @@ -64,8 +64,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return fee_paying_account; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; - - void get_impacted_accounts( flat_set& )const; }; /** diff --git a/libraries/chain/include/graphene/chain/protocol/transaction.hpp b/libraries/chain/include/graphene/chain/protocol/transaction.hpp index 3979de13..dd353b43 100644 --- a/libraries/chain/include/graphene/chain/protocol/transaction.hpp +++ b/libraries/chain/include/graphene/chain/protocol/transaction.hpp @@ -104,7 +104,6 @@ namespace graphene { namespace chain { } void get_required_authorities( flat_set& active, flat_set& owner, vector& other )const; - void get_impacted_accounts( flat_set& )const; }; /** @@ -194,8 +193,7 @@ namespace graphene { namespace chain { /// @} transactions group - -} } +} } // graphene::chain FC_REFLECT( graphene::chain::transaction, (ref_block_num)(ref_block_prefix)(expiration)(operations)(extensions) ) FC_REFLECT_DERIVED( graphene::chain::signed_transaction, (graphene::chain::transaction), (signatures) ) diff --git a/libraries/chain/include/graphene/chain/protocol/transfer.hpp b/libraries/chain/include/graphene/chain/protocol/transfer.hpp index 46251fd0..50d00653 100644 --- a/libraries/chain/include/graphene/chain/protocol/transfer.hpp +++ b/libraries/chain/include/graphene/chain/protocol/transfer.hpp @@ -40,8 +40,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return from; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; - void get_impacted_accounts( flat_set& i )const - { i.insert(to); } }; /** @@ -75,12 +73,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return issuer; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; - void get_impacted_accounts( flat_set& i )const - { - i.insert(to); - i.insert(from); - i.insert(issuer); - } }; }} // graphene::chain diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp index c3674a6c..4f5af7df 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp @@ -56,9 +56,6 @@ namespace graphene { namespace chain { FC_ASSERT( fee.amount >= 0 ); FC_ASSERT( amount.amount > 0 ); } - void get_impacted_accounts( flat_set& i )const - { i.insert(owner); } - }; /** @@ -87,7 +84,8 @@ namespace graphene { namespace chain { } }; -}} // graphene::chain +} } // graphene::chain + FC_REFLECT( graphene::chain::vesting_balance_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type, (fee) ) diff --git a/libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp b/libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp index a6d7582e..2ae4ca33 100644 --- a/libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp +++ b/libraries/chain/include/graphene/chain/protocol/withdraw_permission.hpp @@ -43,9 +43,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return withdraw_from_account; } void validate()const; - - void get_impacted_accounts( flat_set& i)const - { i.insert( authorized_account ); } }; /** @@ -81,8 +78,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return withdraw_from_account; } void validate()const; - void get_impacted_accounts( flat_set& i)const - { i.insert( authorized_account ); } }; /** @@ -121,8 +116,6 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return withdraw_to_account; } void validate()const; share_type calculate_fee(const fee_parameters_type& k)const; - void get_impacted_accounts( flat_set& i)const - { i.insert( withdraw_from_account ); } }; /** @@ -147,11 +140,10 @@ namespace graphene { namespace chain { account_id_type fee_payer()const { return withdraw_from_account; } void validate()const; - void get_impacted_accounts( flat_set& i)const - { i.insert( authorized_account ); } }; } } // graphene::chain + FC_REFLECT( graphene::chain::withdraw_permission_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::withdraw_permission_update_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::withdraw_permission_claim_operation::fee_parameters_type, (fee)(price_per_kbyte) ) @@ -164,4 +156,3 @@ FC_REFLECT( graphene::chain::withdraw_permission_update_operation, (fee)(withdra FC_REFLECT( graphene::chain::withdraw_permission_claim_operation, (fee)(withdraw_permission)(withdraw_from_account)(withdraw_to_account)(amount_to_withdraw)(memo) ); FC_REFLECT( graphene::chain::withdraw_permission_delete_operation, (fee)(withdraw_from_account)(authorized_account) (withdrawal_permission) ) - diff --git a/libraries/chain/protocol/authority.cpp b/libraries/chain/protocol/authority.cpp new file mode 100644 index 00000000..ac0f8f4b --- /dev/null +++ b/libraries/chain/protocol/authority.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, Cryptonomex, Inc. + * All rights reserved. + * + * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and + * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, + * are permitted until September 8, 2015, provided that the following conditions are met: + * + * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +namespace graphene { namespace chain { + +void add_authority_accounts( + flat_set& result, + const authority& a + ) +{ + for( auto& item : a.account_auths ) + result.insert( item.first ); +} + +} } // graphene::chain diff --git a/libraries/chain/protocol/operations.cpp b/libraries/chain/protocol/operations.cpp index 0c5a9cc0..3c7a053a 100644 --- a/libraries/chain/protocol/operations.cpp +++ b/libraries/chain/protocol/operations.cpp @@ -50,24 +50,6 @@ struct required_auth_visitor } }; -struct get_impacted_account_visitor -{ - flat_set& _impacted; - get_impacted_account_visitor( flat_set& impact ):_impacted(impact) {} - typedef void result_type; - - template - void operator()( const T& o )const - { - o.get_impacted_accounts( _impacted ); - } -}; - -void operation_get_impacted_accounts( const operation& op, flat_set& result ) -{ - op.visit( get_impacted_account_visitor( result ) ); -} - void operation_get_required_authorities( const operation& op, vector& result ) { op.visit( required_auth_visitor( result ) ); diff --git a/libraries/chain/protocol/proposal.cpp b/libraries/chain/protocol/proposal.cpp index 148dfea9..46ca683d 100644 --- a/libraries/chain/protocol/proposal.cpp +++ b/libraries/chain/protocol/proposal.cpp @@ -56,14 +56,6 @@ share_type proposal_update_operation::calculate_fee(const fee_parameters_type& k { return k.fee + calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte ); } -void proposal_create_operation::get_impacted_accounts( flat_set& i )const -{ - vector other; - for( const auto& op : proposed_ops ) - operation_get_required_authorities( op.op, i, i, other ); - for( auto& o : other ) - add_authority_accounts( i, o ); -} void proposal_update_operation::get_required_authorities( vector& o )const { @@ -76,14 +68,17 @@ void proposal_update_operation::get_required_authorities( vector& o ) o.emplace_back( std::move(auth) ); } + void proposal_update_operation::get_required_active_authorities( flat_set& a )const { for( const auto& i : active_approvals_to_add ) a.insert(i); for( const auto& i : active_approvals_to_remove ) a.insert(i); } + void proposal_update_operation::get_required_owner_authorities( flat_set& a )const { for( const auto& i : owner_approvals_to_add ) a.insert(i); for( const auto& i : owner_approvals_to_remove ) a.insert(i); } + } } // graphene::chain diff --git a/libraries/chain/protocol/transaction.cpp b/libraries/chain/protocol/transaction.cpp index 6695c711..97c7b1c2 100644 --- a/libraries/chain/protocol/transaction.cpp +++ b/libraries/chain/protocol/transaction.cpp @@ -316,10 +316,4 @@ void signed_transaction::verify_authority( const std::function& impacted ) const -{ - for( const auto& op : operations ) - operation_get_impacted_accounts( op, impacted ); -} - } } // graphene::chain diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 24d5b0f4..480e6239 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -18,6 +18,8 @@ #include +#include + #include #include #include @@ -58,35 +60,11 @@ class account_history_plugin_impl flat_set _tracked_accounts; }; -struct operation_get_impacted_accounts -{ - const operation_history_object& _op_history; - const account_history_plugin& _plugin; - flat_set& _impacted; - operation_get_impacted_accounts( const operation_history_object& oho, const account_history_plugin& ahp, flat_set& impact ) - :_op_history(oho),_plugin(ahp),_impacted(impact) - {} - typedef void result_type; - - void operator()( const account_create_operation& o )const { - _impacted.insert( _op_history.result.get() ); - } - - template - void operator()( const T& o )const - { - o.get_impacted_accounts( _impacted ); - } -}; - - account_history_plugin_impl::~account_history_plugin_impl() { return; } - - void account_history_plugin_impl::update_account_histories( const signed_block& b ) { graphene::chain::database& db = database(); @@ -102,7 +80,11 @@ void account_history_plugin_impl::update_account_histories( const signed_block& flat_set impacted; vector other; operation_get_required_authorities( op.op, impacted, impacted, other ); - op.op.visit( operation_get_impacted_accounts( oho, _self, impacted ) ); + + if( op.op.which() == operation::tag< account_create_operation >::value ) + impacted.insert( oho.result.get() ); + else + graphene::app::operation_get_impacted_accounts( op.op, impacted ); for( auto& a : other ) for( auto& item : a.account_auths )