fixed indices sorting and lottery end checking by date

This commit is contained in:
kstdl 2018-01-10 12:06:34 +03:00
parent c32269ee8e
commit 8cb335a515
3 changed files with 18 additions and 3 deletions

View file

@ -950,7 +950,7 @@ vector<asset_object> database_api_impl::get_account_lotteries( account_id_type i
{
vector<asset_object> result;
if( limit > 100 ) limit = 100;
const auto& assets = _db.get_index_type<asset_index>().indices().get<by_lottery>();
const auto& assets = _db.get_index_type<asset_index>().indices().get<by_lottery_owner>();
const auto range = assets.equal_range( boost::make_tuple( true, issuer.instance.value ) );
for( const auto& a : boost::make_iterator_range( range.first, range.second ) )

View file

@ -187,12 +187,13 @@ void database::close(bool rewind)
void database::check_ending_lotteries()
{
try {
const auto& lotteries_idx = get_index_type<asset_index>().indices().get<active_lotteries>();
const auto& lotteries_idx = get_index_type<asset_index>().indices().get<active_lotteries>();
for( auto checking_asset: lotteries_idx )
{
FC_ASSERT( checking_asset.is_lottery() );
FC_ASSERT( checking_asset.lottery_options->is_active );
FC_ASSERT( checking_asset.lottery_options->end_date < head_block_time() );
FC_ASSERT( checking_asset.lottery_options->end_date != time_point_sec() );
if( checking_asset.lottery_options->end_date > head_block_time() ) continue;
checking_asset.end_lottery(*this);
}
} catch( ... ) {}

View file

@ -259,6 +259,7 @@ namespace graphene { namespace chain {
if ( !lhs.is_lottery() ) return false;
if ( !lhs.lottery_options->is_active && !rhs.is_lottery()) return true; // not active lotteries first, just assets then
if ( !lhs.lottery_options->is_active ) return false;
if ( lhs.lottery_options->is_active && ( !rhs.is_lottery() || !rhs.lottery_options->is_active ) ) return true;
return lhs.get_lottery_expiration() > rhs.get_lottery_expiration();
}
};
@ -267,6 +268,7 @@ namespace graphene { namespace chain {
struct by_type;
struct active_lotteries;
struct by_lottery;
struct by_lottery_owner;
typedef multi_index_container<
asset_object,
indexed_by<
@ -277,6 +279,17 @@ namespace graphene { namespace chain {
lottery_asset_comparer
>,
ordered_unique< tag<by_lottery>,
composite_key<
asset_object,
const_mem_fun<asset_object, bool, &asset_object::is_lottery>,
member<object, object_id_type, &object::id>
>,
composite_key_compare<
std::greater< bool >,
std::greater< object_id_type >
>
>,
ordered_unique< tag<by_lottery_owner>,
composite_key<
asset_object,
const_mem_fun<asset_object, bool, &asset_object::is_lottery>,
@ -299,6 +312,7 @@ namespace graphene { namespace chain {
> asset_object_multi_index_type;
typedef generic_index<asset_object, asset_object_multi_index_type> asset_index;
/**
* @brief contains properties that only apply to dividend-paying assets
*