adding missing files
This commit is contained in:
parent
48d9c9c6b2
commit
4695405c52
2 changed files with 86 additions and 0 deletions
47
libraries/chain/include/graphene/chain/balance_evaluator.hpp
Normal file
47
libraries/chain/include/graphene/chain/balance_evaluator.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
#pragma once
|
||||||
|
#include <graphene/chain/evaluator.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup operations
|
||||||
|
*/
|
||||||
|
class balance_claim_evaluator : public evaluator<balance_claim_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<balance_index>();
|
||||||
|
const auto& by_owner_idx = bal_idx.indices().get<by_owner>();
|
||||||
|
|
||||||
|
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
|
||||||
39
libraries/chain/include/graphene/chain/balance_object.hpp
Normal file
39
libraries/chain/include/graphene/chain/balance_object.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
class balance_object : public abstract_object<balance_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<by_id>, member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_non_unique< tag<by_owner>, composite_key<
|
||||||
|
balance_object,
|
||||||
|
member<balance_object, address, &balance_object::owner>,
|
||||||
|
const_mem_fun<balance_object, asset_id_type, &balance_object::asset_type>
|
||||||
|
> >
|
||||||
|
>
|
||||||
|
> balance_multi_index_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup object_index
|
||||||
|
*/
|
||||||
|
typedef generic_index<balance_object, balance_multi_index_type> balance_index;
|
||||||
|
} }
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::balance_object, (graphene::db::object), (owner)(balance) )
|
||||||
Loading…
Reference in a new issue