#98 Implement Balance Object and Evaluator
This commit is contained in:
parent
06b836f344
commit
d3391c0fe5
7 changed files with 71 additions and 6 deletions
|
|
@ -553,4 +553,24 @@ namespace graphene { namespace app {
|
||||||
} FC_CAPTURE_AND_RETHROW( (id) ) }
|
} FC_CAPTURE_AND_RETHROW( (id) ) }
|
||||||
|
|
||||||
|
|
||||||
|
vector<balance_object> database_api::get_balance_objects( const vector<address>& addrs )const
|
||||||
|
{ try {
|
||||||
|
const auto& bal_idx = _db.get_index_type<balance_index>();
|
||||||
|
const auto& by_owner_idx = bal_idx.indices().get<by_owner>();
|
||||||
|
|
||||||
|
vector<balance_object> result;
|
||||||
|
|
||||||
|
for( const auto& owner : addrs )
|
||||||
|
{
|
||||||
|
auto itr = by_owner_idx.lower_bound( boost::make_tuple( owner, asset_id_type(0) ) );
|
||||||
|
while( itr != by_owner_idx.end() && itr->owner == owner )
|
||||||
|
{
|
||||||
|
result.push_back( *itr );
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (addrs) ) }
|
||||||
|
|
||||||
|
|
||||||
} } // graphene::app
|
} } // graphene::app
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
#include <graphene/chain/delegate_object.hpp>
|
#include <graphene/chain/delegate_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
|
#include <graphene/chain/balance_object.hpp>
|
||||||
#include <graphene/net/node.hpp>
|
#include <graphene/net/node.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -252,6 +253,9 @@ namespace graphene { namespace app {
|
||||||
*/
|
*/
|
||||||
vector<call_order_object> get_margin_positions( const account_id_type& id )const;
|
vector<call_order_object> get_margin_positions( const account_id_type& id )const;
|
||||||
|
|
||||||
|
/** @return all unclaimed balance objects for a set of addresses */
|
||||||
|
vector<balance_object> get_balance_objects( const vector<address>& addrs )const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** called every time a block is applied to report the objects that were changed */
|
/** called every time a block is applied to report the objects that were changed */
|
||||||
void on_objects_changed(const vector<object_id_type>& ids);
|
void on_objects_changed(const vector<object_id_type>& ids);
|
||||||
|
|
@ -395,6 +399,7 @@ FC_API(graphene::app::database_api,
|
||||||
(get_account_references)
|
(get_account_references)
|
||||||
(get_keys_for_address)
|
(get_keys_for_address)
|
||||||
(get_margin_positions)
|
(get_margin_positions)
|
||||||
|
(get_balance_objects)
|
||||||
)
|
)
|
||||||
FC_API(graphene::app::history_api, (get_account_history)(get_market_history)(get_market_history_buckets))
|
FC_API(graphene::app::history_api, (get_account_history)(get_market_history)(get_market_history_buckets))
|
||||||
FC_API(graphene::app::network_api, (broadcast_transaction)(add_node)(get_connected_peers))
|
FC_API(graphene::app::network_api, (broadcast_transaction)(add_node)(get_connected_peers))
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <graphene/chain/delegate_object.hpp>
|
#include <graphene/chain/delegate_object.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
#include <graphene/chain/key_object.hpp>
|
#include <graphene/chain/key_object.hpp>
|
||||||
|
#include <graphene/chain/balance_object.hpp>
|
||||||
#include <graphene/chain/limit_order_object.hpp>
|
#include <graphene/chain/limit_order_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/call_order_object.hpp>
|
#include <graphene/chain/call_order_object.hpp>
|
||||||
|
|
@ -49,6 +50,7 @@
|
||||||
#include <graphene/chain/withdraw_permission_evaluator.hpp>
|
#include <graphene/chain/withdraw_permission_evaluator.hpp>
|
||||||
#include <graphene/chain/witness_evaluator.hpp>
|
#include <graphene/chain/witness_evaluator.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/worker_evaluator.hpp>
|
||||||
|
#include <graphene/chain/balance_evaluator.hpp>
|
||||||
|
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
|
|
||||||
|
|
@ -94,6 +96,7 @@ void database::initialize_evaluators()
|
||||||
register_evaluator<withdraw_permission_update_evaluator>();
|
register_evaluator<withdraw_permission_update_evaluator>();
|
||||||
register_evaluator<withdraw_permission_delete_evaluator>();
|
register_evaluator<withdraw_permission_delete_evaluator>();
|
||||||
register_evaluator<worker_create_evaluator>();
|
register_evaluator<worker_create_evaluator>();
|
||||||
|
register_evaluator<balance_claim_evaluator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::initialize_indexes()
|
void database::initialize_indexes()
|
||||||
|
|
@ -123,6 +126,7 @@ void database::initialize_indexes()
|
||||||
add_index< primary_index<withdraw_permission_index > >();
|
add_index< primary_index<withdraw_permission_index > >();
|
||||||
add_index< primary_index<simple_index<vesting_balance_object> > >();
|
add_index< primary_index<simple_index<vesting_balance_object> > >();
|
||||||
add_index< primary_index<worker_index> >();
|
add_index< primary_index<worker_index> >();
|
||||||
|
add_index< primary_index<balance_index> >();
|
||||||
|
|
||||||
//Implementation object indexes
|
//Implementation object indexes
|
||||||
add_index< primary_index<transaction_index > >();
|
add_index< primary_index<transaction_index > >();
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,25 @@ namespace graphene { namespace chain {
|
||||||
void get_balance_delta(balance_accumulator& acc, const operation_result& result = asset())const { acc.adjust(fee_payer(), -fee); }
|
void get_balance_delta(balance_accumulator& acc, const operation_result& result = asset())const { acc.adjust(fee_payer(), -fee); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This operation will claim all initial balance objects owned by any of the addresses and
|
||||||
|
* deposit them into the deposit_to_account.
|
||||||
|
*/
|
||||||
|
struct balance_claim_operation
|
||||||
|
{
|
||||||
|
asset fee;
|
||||||
|
account_id_type deposit_to_account;
|
||||||
|
flat_set<address> owners;
|
||||||
|
asset total_claimed;
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return deposit_to_account; }
|
||||||
|
void get_required_auth(flat_set<account_id_type>& active_auth_set, flat_set<account_id_type>&)const;
|
||||||
|
share_type calculate_fee(const fee_schedule_type& k)const { return 0; }
|
||||||
|
void validate()const;
|
||||||
|
|
||||||
|
void get_balance_delta(balance_accumulator& acc, const operation_result& result = asset())const { acc.adjust(fee_payer(), total_claimed-fee); }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief reserves a new ID to refer to a particular key or address.
|
* @brief reserves a new ID to refer to a particular key or address.
|
||||||
* @ingroup operations
|
* @ingroup operations
|
||||||
|
|
@ -1391,7 +1410,8 @@ namespace graphene { namespace chain {
|
||||||
vesting_balance_withdraw_operation,
|
vesting_balance_withdraw_operation,
|
||||||
worker_create_operation,
|
worker_create_operation,
|
||||||
custom_operation,
|
custom_operation,
|
||||||
assert_operation
|
assert_operation,
|
||||||
|
balance_claim_operation
|
||||||
> operation;
|
> operation;
|
||||||
|
|
||||||
/// @} // operations group
|
/// @} // operations group
|
||||||
|
|
@ -1623,6 +1643,7 @@ FC_REFLECT( graphene::chain::custom_operation, (fee)(payer)(required_auths)(id)(
|
||||||
FC_REFLECT( graphene::chain::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths) )
|
FC_REFLECT( graphene::chain::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths) )
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::void_result, )
|
FC_REFLECT( graphene::chain::void_result, )
|
||||||
|
FC_REFLECT( graphene::chain::balance_claim_operation, (fee)(deposit_to_account)(owners)(total_claimed) )
|
||||||
|
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::operation )
|
FC_REFLECT_TYPENAME( graphene::chain::operation )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::operation_result )
|
FC_REFLECT_TYPENAME( graphene::chain::operation_result )
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ namespace graphene { namespace chain {
|
||||||
withdraw_permission_object_type,
|
withdraw_permission_object_type,
|
||||||
vesting_balance_object_type,
|
vesting_balance_object_type,
|
||||||
worker_object_type,
|
worker_object_type,
|
||||||
|
balance_object_type,
|
||||||
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -160,6 +161,7 @@ namespace graphene { namespace chain {
|
||||||
class vesting_balance_object;
|
class vesting_balance_object;
|
||||||
class witness_schedule_object;
|
class witness_schedule_object;
|
||||||
class worker_object;
|
class worker_object;
|
||||||
|
class balance_object;
|
||||||
|
|
||||||
typedef object_id< protocol_ids, key_object_type, key_object> key_id_type;
|
typedef object_id< protocol_ids, key_object_type, key_object> key_id_type;
|
||||||
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
||||||
|
|
@ -175,6 +177,7 @@ namespace graphene { namespace chain {
|
||||||
typedef object_id< protocol_ids, withdraw_permission_object_type,withdraw_permission_object> withdraw_permission_id_type;
|
typedef object_id< protocol_ids, withdraw_permission_object_type,withdraw_permission_object> withdraw_permission_id_type;
|
||||||
typedef object_id< protocol_ids, vesting_balance_object_type, vesting_balance_object> vesting_balance_id_type;
|
typedef object_id< protocol_ids, vesting_balance_object_type, vesting_balance_object> vesting_balance_id_type;
|
||||||
typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type;
|
typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type;
|
||||||
|
typedef object_id< protocol_ids, balance_object_type, balance_object> balance_id_type;
|
||||||
|
|
||||||
typedef object_id< relative_protocol_ids, key_object_type, key_object> relative_key_id_type;
|
typedef object_id< relative_protocol_ids, key_object_type, key_object> relative_key_id_type;
|
||||||
typedef object_id< relative_protocol_ids, account_object_type, account_object> relative_account_id_type;
|
typedef object_id< relative_protocol_ids, account_object_type, account_object> relative_account_id_type;
|
||||||
|
|
@ -521,6 +524,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
|
||||||
(withdraw_permission_object_type)
|
(withdraw_permission_object_type)
|
||||||
(vesting_balance_object_type)
|
(vesting_balance_object_type)
|
||||||
(worker_object_type)
|
(worker_object_type)
|
||||||
|
(balance_object_type)
|
||||||
(OBJECT_TYPE_COUNT)
|
(OBJECT_TYPE_COUNT)
|
||||||
)
|
)
|
||||||
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
||||||
|
|
|
||||||
|
|
@ -898,4 +898,17 @@ share_type assert_operation::calculate_fee(const fee_schedule_type& k)const
|
||||||
return std::max(size_t(1), fc::raw::pack_size(*this) / 1024) * k.assert_op_fee;
|
return std::max(size_t(1), fc::raw::pack_size(*this) / 1024) * k.assert_op_fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void balance_claim_operation::get_required_auth(flat_set<account_id_type>& active_auth_set, flat_set<account_id_type>&)const
|
||||||
|
{
|
||||||
|
active_auth_set.insert( fee_payer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void balance_claim_operation::validate()const
|
||||||
|
{
|
||||||
|
FC_ASSERT( owners.size() > 0 );
|
||||||
|
FC_ASSERT( total_claimed.amount > 0 );
|
||||||
|
FC_ASSERT( fee == asset() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} } // namespace graphene::chain
|
} } // namespace graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -184,11 +184,9 @@ struct operation_get_impacted_accounts
|
||||||
_impacted.insert( o.owner );
|
_impacted.insert( o.owner );
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()( const worker_create_operation& )const
|
void operator()( const worker_create_operation& )const {}
|
||||||
{}
|
void operator()( const assert_operation& )const {}
|
||||||
|
void operator()( const balance_claim_operation& )const {}
|
||||||
void operator()( const assert_operation& )const
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue