fix reindex on peerplays network
This commit is contained in:
parent
7ba965c860
commit
ee9545a2c4
12 changed files with 69 additions and 26 deletions
|
|
@ -119,7 +119,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
||||||
unsigned limit = 100,
|
unsigned limit = 100,
|
||||||
asset_id_type start = asset_id_type() )const;
|
asset_id_type start = asset_id_type() )const;
|
||||||
asset get_lottery_balance( asset_id_type lottery_id )const;
|
asset get_lottery_balance( asset_id_type lottery_id )const;
|
||||||
|
sweeps_vesting_balance_object get_sweeps_vesting_balance_object( account_id_type account )const;
|
||||||
|
asset get_sweeps_vesting_balance_available_for_claim( account_id_type account )const;
|
||||||
|
|
||||||
// Markets / feeds
|
// Markets / feeds
|
||||||
vector<limit_order_object> get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const;
|
vector<limit_order_object> get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const;
|
||||||
|
|
@ -1036,6 +1037,7 @@ vector<asset_object> database_api_impl::get_lotteries(asset_id_type stop,
|
||||||
asset_id_type start )const
|
asset_id_type start )const
|
||||||
{
|
{
|
||||||
vector<asset_object> result;
|
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>();
|
||||||
|
|
||||||
const auto range = assets.equal_range( boost::make_tuple( true ) );
|
const auto range = assets.equal_range( boost::make_tuple( true ) );
|
||||||
|
|
@ -1062,6 +1064,31 @@ asset database_api_impl::get_lottery_balance( asset_id_type lottery_id )const
|
||||||
return _db.get_balance( lottery_id );
|
return _db.get_balance( lottery_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sweeps_vesting_balance_object database_api::get_sweeps_vesting_balance_object( account_id_type account )const
|
||||||
|
{
|
||||||
|
return my->get_sweeps_vesting_balance_object( account );
|
||||||
|
}
|
||||||
|
|
||||||
|
sweeps_vesting_balance_object database_api_impl::get_sweeps_vesting_balance_object( account_id_type account )const
|
||||||
|
{
|
||||||
|
const auto& vesting_idx = _db.get_index_type<sweeps_vesting_balance_index>().indices().get<by_owner>();
|
||||||
|
auto account_balance = vesting_idx.find(account);
|
||||||
|
FC_ASSERT( account_balance != vesting_idx.end(), "NO SWEEPS VESTING BALANCE" );
|
||||||
|
return *account_balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
asset database_api::get_sweeps_vesting_balance_available_for_claim( account_id_type account )const
|
||||||
|
{
|
||||||
|
return my->get_sweeps_vesting_balance_available_for_claim( account );
|
||||||
|
}
|
||||||
|
|
||||||
|
asset database_api_impl::get_sweeps_vesting_balance_available_for_claim( account_id_type account )const
|
||||||
|
{
|
||||||
|
const auto& vesting_idx = _db.get_index_type<sweeps_vesting_balance_index>().indices().get<by_owner>();
|
||||||
|
auto account_balance = vesting_idx.find(account);
|
||||||
|
FC_ASSERT( account_balance != vesting_idx.end(), "NO SWEEPS VESTING BALANCE" );
|
||||||
|
return account_balance->available_for_claim();
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Peerplays //
|
// Peerplays //
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,9 @@ class database_api
|
||||||
vector<asset_object> get_lotteries( asset_id_type stop = asset_id_type(),
|
vector<asset_object> get_lotteries( asset_id_type stop = asset_id_type(),
|
||||||
unsigned limit = 100,
|
unsigned limit = 100,
|
||||||
asset_id_type start = asset_id_type() )const;
|
asset_id_type start = asset_id_type() )const;
|
||||||
|
|
||||||
|
sweeps_vesting_balance_object get_sweeps_vesting_balance_object( account_id_type account )const;
|
||||||
|
asset get_sweeps_vesting_balance_available_for_claim( account_id_type account )const;
|
||||||
/**
|
/**
|
||||||
* @brief Get balance of lottery assets
|
* @brief Get balance of lottery assets
|
||||||
*/
|
*/
|
||||||
|
|
@ -750,9 +753,11 @@ FC_API(graphene::app::database_api,
|
||||||
(get_unmatched_bets_for_bettor)
|
(get_unmatched_bets_for_bettor)
|
||||||
(get_all_unmatched_bets_for_bettor)
|
(get_all_unmatched_bets_for_bettor)
|
||||||
|
|
||||||
// Lottery assets
|
// Sweeps
|
||||||
(get_lotteries)
|
(get_lotteries)
|
||||||
(get_lottery_balance)
|
(get_lottery_balance)
|
||||||
|
(get_sweeps_vesting_balance_object)
|
||||||
|
(get_sweeps_vesting_balance_available_for_claim)
|
||||||
|
|
||||||
// Markets / feeds
|
// Markets / feeds
|
||||||
(get_order_book)
|
(get_order_book)
|
||||||
|
|
|
||||||
|
|
@ -118,9 +118,9 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o
|
||||||
FC_ASSERT( op.precision == op.bitasset_opts->short_backing_asset(d).precision );
|
FC_ASSERT( op.precision == op.bitasset_opts->short_backing_asset(d).precision );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( op.extension.which() == asset_extension::tag<lottery_asset_options>::value ) {
|
if( op.extensions.which() == asset_extension::tag<lottery_asset_options>::value ) {
|
||||||
FC_ASSERT( op.common_options.max_supply >= 5 );
|
FC_ASSERT( op.common_options.max_supply >= 5 );
|
||||||
op.extension.get<lottery_asset_options>().validate();
|
op.extensions.get<lottery_asset_options>().validate();
|
||||||
}
|
}
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
@ -156,9 +156,9 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o
|
||||||
a.symbol = op.symbol;
|
a.symbol = op.symbol;
|
||||||
a.precision = op.precision;
|
a.precision = op.precision;
|
||||||
a.options = op.common_options;
|
a.options = op.common_options;
|
||||||
if( op.extension.which() == asset_extension::tag<lottery_asset_options>::value ) {
|
if( op.extensions.which() == asset_extension::tag<lottery_asset_options>::value ) {
|
||||||
a.precision = 0;
|
a.precision = 0;
|
||||||
a.lottery_options = op.extension.get<lottery_asset_options>(); //a.lottery_options->balance = asset( 0, a.lottery_options->ticket_price.asset_id );
|
a.lottery_options = op.extensions.get<lottery_asset_options>(); //a.lottery_options->balance = asset( 0, a.lottery_options->ticket_price.asset_id );
|
||||||
a.lottery_options->owner = a.id;
|
a.lottery_options->owner = a.id;
|
||||||
db().create<lottery_balance_object>([&](lottery_balance_object& lbo) {
|
db().create<lottery_balance_object>([&](lottery_balance_object& lbo) {
|
||||||
lbo.lottery_id = a.id;
|
lbo.lottery_id = a.id;
|
||||||
|
|
|
||||||
|
|
@ -223,14 +223,14 @@ map< account_id_type, vector< uint16_t > > asset_object::distribute_winners_part
|
||||||
for( auto t = tickets.begin(); t != tickets.begin() + holders.size(); ++t )
|
for( auto t = tickets.begin(); t != tickets.begin() + holders.size(); ++t )
|
||||||
*t += percents_to_distribute / holders.size();
|
*t += percents_to_distribute / holders.size();
|
||||||
}
|
}
|
||||||
|
auto sweeps_distribution_percentage = db.get_global_properties().parameters.extensions.get<sweeps_parameters_extension>().sweeps_distribution_percentage;
|
||||||
for( int c = 0; c < winner_numbers.size(); ++c ) {
|
for( int c = 0; c < winner_numbers.size(); ++c ) {
|
||||||
auto winner_num = winner_numbers[c];
|
auto winner_num = winner_numbers[c];
|
||||||
lottery_reward_operation reward_op;
|
lottery_reward_operation reward_op;
|
||||||
reward_op.lottery = get_id();
|
reward_op.lottery = get_id();
|
||||||
reward_op.winner = holders[winner_num];
|
reward_op.winner = holders[winner_num];
|
||||||
reward_op.win_percentage = tickets[c];
|
reward_op.win_percentage = tickets[c];
|
||||||
reward_op.amount = asset( jackpot * tickets[c] * ( 1. - db.get_global_properties().parameters.sweeps_distribution_percentage / (double)GRAPHENE_100_PERCENT ) / GRAPHENE_100_PERCENT , db.get_balance(id).asset_id );
|
reward_op.amount = asset( jackpot * tickets[c] * ( 1. - sweeps_distribution_percentage / (double)GRAPHENE_100_PERCENT ) / GRAPHENE_100_PERCENT , db.get_balance(id).asset_id );
|
||||||
db.apply_operation(eval, reward_op);
|
db.apply_operation(eval, reward_op);
|
||||||
|
|
||||||
structurized_participants[ holders[ winner_num ] ].push_back( tickets[c] );
|
structurized_participants[ holders[ winner_num ] ].push_back( tickets[c] );
|
||||||
|
|
@ -244,9 +244,9 @@ void asset_object::distribute_sweeps_holders_part( database& db )
|
||||||
|
|
||||||
auto& asset_bal_idx = db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
|
auto& asset_bal_idx = db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
|
||||||
|
|
||||||
auto global_params = db.get_global_properties().parameters;
|
auto sweeps_params = db.get_global_properties().parameters.extensions.get<sweeps_parameters_extension>();
|
||||||
uint64_t distribution_asset_supply = global_params.sweeps_distribution_asset( db ).dynamic_data( db ).current_supply.value;
|
uint64_t distribution_asset_supply = sweeps_params.sweeps_distribution_asset( db ).dynamic_data( db ).current_supply.value;
|
||||||
const auto range = asset_bal_idx.equal_range( boost::make_tuple( global_params.sweeps_distribution_asset ) );
|
const auto range = asset_bal_idx.equal_range( boost::make_tuple( sweeps_params.sweeps_distribution_asset ) );
|
||||||
|
|
||||||
uint64_t holders_sum = 0;
|
uint64_t holders_sum = 0;
|
||||||
for( const account_balance_object& holder_balance : boost::make_iterator_range( range.first, range.second ) )
|
for( const account_balance_object& holder_balance : boost::make_iterator_range( range.first, range.second ) )
|
||||||
|
|
@ -256,7 +256,7 @@ void asset_object::distribute_sweeps_holders_part( database& db )
|
||||||
holders_sum += holder_part;
|
holders_sum += holder_part;
|
||||||
}
|
}
|
||||||
uint64_t balance_rest = db.get_balance( get_id() ).amount.value * SWEEPS_VESTING_BALANCE_MULTIPLIER - holders_sum;
|
uint64_t balance_rest = db.get_balance( get_id() ).amount.value * SWEEPS_VESTING_BALANCE_MULTIPLIER - holders_sum;
|
||||||
db.adjust_sweeps_vesting_balance( SWEEPS_ACCUMULATOR_ACCOUNT, balance_rest );
|
db.adjust_sweeps_vesting_balance( sweeps_params.sweeps_vesting_accumulator_account, balance_rest );
|
||||||
db.adjust_balance( get_id(), -db.get_balance( get_id() ) );
|
db.adjust_balance( get_id(), -db.get_balance( get_id() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ void database::adjust_sweeps_vesting_balance(account_id_type account, int64_t de
|
||||||
if( delta == 0 )
|
if( delta == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
asset_id_type asset_id = get_global_properties().parameters.sweeps_distribution_asset;
|
asset_id_type asset_id = get_global_properties().parameters.extensions.get<sweeps_parameters_extension>().sweeps_distribution_asset;
|
||||||
|
|
||||||
auto& index = get_index_type<sweeps_vesting_balance_index>().indices().get<by_owner>();
|
auto& index = get_index_type<sweeps_vesting_balance_index>().indices().get<by_owner>();
|
||||||
auto itr = index.find(account);
|
auto itr = index.find(account);
|
||||||
|
|
@ -139,8 +139,9 @@ void database::adjust_sweeps_vesting_balance(account_id_type account, int64_t de
|
||||||
} else {
|
} else {
|
||||||
if( delta < 0 )
|
if( delta < 0 )
|
||||||
FC_ASSERT( itr->get_balance() >= -delta, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", ("a",account)("b",itr->get_balance())("r",-delta));
|
FC_ASSERT( itr->get_balance() >= -delta, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", ("a",account)("b",itr->get_balance())("r",-delta));
|
||||||
modify(*itr, [&delta,&asset_id](sweeps_vesting_balance_object& b) {
|
modify(*itr, [&delta,&asset_id,this](sweeps_vesting_balance_object& b) {
|
||||||
b.adjust_balance( asset( delta, asset_id ) );
|
b.adjust_balance( asset( delta, asset_id ) );
|
||||||
|
b.last_claim_date = head_block_time();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,7 @@ namespace graphene { namespace chain {
|
||||||
/// For BitAssets, set this to true if the asset implements a @ref prediction_market; false otherwise
|
/// For BitAssets, set this to true if the asset implements a @ref prediction_market; false otherwise
|
||||||
bool is_prediction_market = false;
|
bool is_prediction_market = false;
|
||||||
// containing lottery_asset_options now
|
// containing lottery_asset_options now
|
||||||
asset_extension extension;
|
asset_extension extensions;
|
||||||
|
|
||||||
account_id_type fee_payer()const { return issuer; }
|
account_id_type fee_payer()const { return issuer; }
|
||||||
void validate()const;
|
void validate()const;
|
||||||
|
|
@ -683,7 +683,7 @@ FC_REFLECT( graphene::chain::asset_create_operation,
|
||||||
(common_options)
|
(common_options)
|
||||||
(bitasset_opts)
|
(bitasset_opts)
|
||||||
(is_prediction_market)
|
(is_prediction_market)
|
||||||
(extension)
|
(extensions)
|
||||||
)
|
)
|
||||||
FC_REFLECT( graphene::chain::asset_update_operation,
|
FC_REFLECT( graphene::chain::asset_update_operation,
|
||||||
(fee)
|
(fee)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
namespace graphene { namespace chain { struct fee_schedule; } }
|
namespace graphene { namespace chain { struct fee_schedule; } }
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
<<<<<<< HEAD
|
||||||
struct parameter_extension
|
struct parameter_extension
|
||||||
{
|
{
|
||||||
optional< bet_multiplier_type > min_bet_multiplier;
|
optional< bet_multiplier_type > min_bet_multiplier;
|
||||||
|
|
@ -46,6 +47,14 @@ namespace graphene { namespace chain {
|
||||||
optional < uint16_t > son_count;
|
optional < uint16_t > son_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
=======
|
||||||
|
struct sweeps_parameters_extension {
|
||||||
|
uint16_t sweeps_distribution_percentage = SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE;
|
||||||
|
asset_id_type sweeps_distribution_asset = SWEEPS_DEFAULT_DISTRIBUTION_ASSET;
|
||||||
|
account_id_type sweeps_vesting_accumulator_account = SWEEPS_ACCUMULATOR_ACCOUNT;
|
||||||
|
};
|
||||||
|
typedef static_variant<void_t,sweeps_parameters_extension> parameter_extension;
|
||||||
|
>>>>>>> fix reindex on peerplays network
|
||||||
struct chain_parameters
|
struct chain_parameters
|
||||||
{
|
{
|
||||||
/** using a smart ref breaks the circular dependency created between operations and the fee schedule */
|
/** using a smart ref breaks the circular dependency created between operations and the fee schedule */
|
||||||
|
|
@ -97,8 +106,7 @@ namespace graphene { namespace chain {
|
||||||
uint16_t sweeps_distribution_percentage = SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE;
|
uint16_t sweeps_distribution_percentage = SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE;
|
||||||
asset_id_type sweeps_distribution_asset = SWEEPS_DEFAULT_DISTRIBUTION_ASSET;
|
asset_id_type sweeps_distribution_asset = SWEEPS_DEFAULT_DISTRIBUTION_ASSET;
|
||||||
|
|
||||||
|
extension<parameter_extension> extensions = sweeps_parameters_extension();
|
||||||
extension<parameter_extension> extensions;
|
|
||||||
|
|
||||||
/** defined in fee_schedule.cpp */
|
/** defined in fee_schedule.cpp */
|
||||||
void validate()const;
|
void validate()const;
|
||||||
|
|
@ -146,6 +154,10 @@ FC_REFLECT( graphene::chain::parameter_extension,
|
||||||
(son_count)
|
(son_count)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::chain::sweeps_parameters_extension,
|
||||||
|
(sweeps_distribution_percentage)
|
||||||
|
(sweeps_distribution_asset) )
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::chain_parameters,
|
FC_REFLECT( graphene::chain::chain_parameters,
|
||||||
(current_fees)
|
(current_fees)
|
||||||
(block_interval)
|
(block_interval)
|
||||||
|
|
@ -189,7 +201,5 @@ FC_REFLECT( graphene::chain::chain_parameters,
|
||||||
(maximum_tournament_start_time_in_future)
|
(maximum_tournament_start_time_in_future)
|
||||||
(maximum_tournament_start_delay)
|
(maximum_tournament_start_delay)
|
||||||
(maximum_tournament_number_of_wins)
|
(maximum_tournament_number_of_wins)
|
||||||
(sweeps_distribution_percentage)
|
|
||||||
(sweeps_distribution_asset)
|
|
||||||
(extensions)
|
(extensions)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ share_type asset_create_operation::calculate_fee(const asset_create_operation::f
|
||||||
{
|
{
|
||||||
auto core_fee_required = param.long_symbol;
|
auto core_fee_required = param.long_symbol;
|
||||||
|
|
||||||
if( extension.which() == asset_extension::tag<lottery_asset_options>::value ) {
|
if( extensions.which() == asset_extension::tag<lottery_asset_options>::value ) {
|
||||||
core_fee_required = param.lottery_asset;
|
core_fee_required = param.lottery_asset;
|
||||||
} else {
|
} else {
|
||||||
switch(symbol.size()) {
|
switch(symbol.size()) {
|
||||||
|
|
|
||||||
|
|
@ -1460,7 +1460,7 @@ public:
|
||||||
create_op.precision = 0;
|
create_op.precision = 0;
|
||||||
create_op.common_options = common;
|
create_op.common_options = common;
|
||||||
|
|
||||||
create_op.extension = lottery_opts;
|
create_op.extensions = lottery_opts;
|
||||||
|
|
||||||
signed_transaction tx;
|
signed_transaction tx;
|
||||||
tx.operations.push_back( create_op );
|
tx.operations.push_back( create_op );
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ void database_fixture::verify_asset_supplies( const database& db )
|
||||||
for( const sweeps_vesting_balance_object& svbo: db.get_index_type< sweeps_vesting_balance_index >().indices() )
|
for( const sweeps_vesting_balance_object& svbo: db.get_index_type< sweeps_vesting_balance_index >().indices() )
|
||||||
sweeps_vestings += svbo.balance;
|
sweeps_vestings += svbo.balance;
|
||||||
|
|
||||||
total_balances[db.get_global_properties().parameters.sweeps_distribution_asset] += sweeps_vestings / SWEEPS_VESTING_BALANCE_MULTIPLIER;
|
total_balances[db.get_global_properties().parameters.extensions.get<sweeps_parameters_extension>().sweeps_distribution_asset] += sweeps_vestings / SWEEPS_VESTING_BALANCE_MULTIPLIER;
|
||||||
total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget;
|
total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget;
|
||||||
|
|
||||||
for( const auto& item : total_debts )
|
for( const auto& item : total_debts )
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE( create_lottery_asset_test )
|
||||||
lottery_options.is_active = test_asset_id.instance.value % 2;
|
lottery_options.is_active = test_asset_id.instance.value % 2;
|
||||||
lottery_options.ending_on_soldout = true;
|
lottery_options.ending_on_soldout = true;
|
||||||
|
|
||||||
creator.extension = lottery_options;
|
creator.extensions = lottery_options;
|
||||||
|
|
||||||
trx.operations.push_back(std::move(creator));
|
trx.operations.push_back(std::move(creator));
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue