From 4695405c52599f65c6615167596dd24d42bc62e6 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sun, 28 Jun 2015 15:12:00 -0400 Subject: [PATCH] adding missing files --- .../graphene/chain/balance_evaluator.hpp | 47 +++++++++++++++++++ .../include/graphene/chain/balance_object.hpp | 39 +++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 libraries/chain/include/graphene/chain/balance_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/balance_object.hpp diff --git a/libraries/chain/include/graphene/chain/balance_evaluator.hpp b/libraries/chain/include/graphene/chain/balance_evaluator.hpp new file mode 100644 index 00000000..237b8d2e --- /dev/null +++ b/libraries/chain/include/graphene/chain/balance_evaluator.hpp @@ -0,0 +1,47 @@ +#pragma once +#include + +namespace graphene { namespace chain { + + /** + * @ingroup operations + */ + class balance_claim_evaluator : public evaluator + { + public: + typedef balance_claim_operation operation_type; + + void_result do_evaluate( const balance_claim_operation& op ) + { + return void_result(); + } + + /** + * @note the fee is always 0 for this particular operation because once the + * balance is claimed it frees up memory and it cannot be used to spam the network + */ + void_result do_apply( const balance_claim_operation& op ) + { + const auto& bal_idx = db().get_index_type(); + const auto& by_owner_idx = bal_idx.indices().get(); + + asset total(0, op.total_claimed.asset_id); + for( const auto& owner : op.owners ) + { + auto itr = by_owner_idx.find( boost::make_tuple( owner, total.asset_id ) ); + if( itr != by_owner_idx.end() ) + { + total += itr->balance; + db().remove( *itr ); + } + } + + FC_ASSERT( total == op.total_claimed, "", ("total",total)("op",op) ); + + db().adjust_balance( op.deposit_to_account, total ); + + return void_result(); + } + }; + +} } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp new file mode 100644 index 00000000..e1a5fb32 --- /dev/null +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -0,0 +1,39 @@ +#pragma once + +namespace graphene { namespace chain { + + class balance_object : public abstract_object + { + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = balance_object_type; + + address owner; + asset balance; + asset_id_type asset_type()const { return balance.asset_id; } + }; + + struct by_owner; + + /** + * @ingroup object_index + */ + typedef multi_index_container< + balance_object, + indexed_by< + hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_non_unique< tag, composite_key< + balance_object, + member, + const_mem_fun + > > + > + > balance_multi_index_type; + + /** + * @ingroup object_index + */ + typedef generic_index balance_index; +} } + +FC_REFLECT_DERIVED( graphene::chain::balance_object, (graphene::db::object), (owner)(balance) )