nft_lottery4 - add config based ticket deletion, progressive jackpot, db, cli changes

This commit is contained in:
sierra19XX 2020-10-03 02:52:59 +10:00
parent 001a58155a
commit 9d503e7802
12 changed files with 136 additions and 48 deletions

View file

@ -192,6 +192,9 @@ const uint8_t offer_history_object::type_id;
const uint8_t account_role_object::space_id;
const uint8_t account_role_object::type_id;
const uint8_t nft_lottery_balance_object::space_id;
const uint8_t nft_lottery_balance_object::type_id;
void database::initialize_evaluators()
{
_operation_evaluators.resize(255);
@ -366,7 +369,7 @@ void database::initialize_indexes()
add_index< primary_index<lottery_balance_index > >();
add_index< primary_index<sweeps_vesting_balance_index > >();
add_index< primary_index<offer_history_index > >();
add_index< primary_index<nft_lottery_balance_index > >();
}
void database::init_genesis(const genesis_state_type& genesis_state)

View file

@ -508,6 +508,8 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
break;
case impl_fba_accumulator_object_type:
break;
case impl_nft_lottery_balance_object_type:
break;
}
}
} // end get_relevant_accounts( const object* obj, flat_set<account_id_type>& accounts )

View file

@ -6,14 +6,27 @@
namespace graphene { namespace chain {
using namespace graphene::db;
class nft_lottery_balance_object : public abstract_object<nft_lottery_balance_object>
{
public:
static const uint8_t space_id = implementation_ids;
static const uint8_t type_id = impl_nft_lottery_balance_object_type;
// Total Progressive jackpot carried over from previous lotteries
asset total_progressive_jackpot;
// Current total jackpot in this lottery inclusive of the progressive jackpot
asset jackpot;
// Total tickets sold
share_type sweeps_tickets_sold;
};
struct nft_lottery_data
{
nft_lottery_data() {}
nft_lottery_data(const nft_lottery_options &options)
: lottery_options(options), jackpot(asset(0, options.ticket_price.asset_id)) {}
nft_lottery_data(const nft_lottery_options &options, nft_lottery_balance_id_type lottery_id)
: lottery_options(options), lottery_balance_id(lottery_id) {}
nft_lottery_options lottery_options;
asset jackpot;
share_type sweeps_tickets_sold;
nft_lottery_balance_id_type lottery_balance_id;
};
class nft_metadata_object : public abstract_object<nft_metadata_object>
@ -38,10 +51,10 @@ namespace graphene { namespace chain {
bool is_lottery() const { return lottery_data.valid(); }
uint32_t get_owner_num() const { return owner.instance.value; }
time_point_sec get_lottery_expiration() const;
asset get_lottery_jackpot() const;
share_type get_token_current_supply(database &db) const;
vector<account_id_type> get_holders(database &db) const;
vector<uint64_t> get_ticket_ids(database &db) const;
asset get_lottery_jackpot(const database &db) const;
share_type get_token_current_supply(const database &db) const;
vector<account_id_type> get_holders(const database &db) const;
vector<uint64_t> get_ticket_ids(const database &db) const;
void distribute_benefactors_part(database &db);
map<account_id_type, vector<uint16_t>> distribute_winners_part(database &db);
void distribute_sweeps_holders_part(database &db);
@ -154,9 +167,22 @@ namespace graphene { namespace chain {
>;
using nft_index = generic_index<nft_object, nft_multi_index_type>;
using nft_lottery_balance_index_type = multi_index_container<
nft_lottery_balance_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >
>
>;
using nft_lottery_balance_index = generic_index<nft_lottery_balance_object, nft_lottery_balance_index_type>;
} } // graphene::chain
FC_REFLECT( graphene::chain::nft_lottery_data, (lottery_options)(jackpot)(sweeps_tickets_sold) )
FC_REFLECT_DERIVED( graphene::chain::nft_lottery_balance_object, (graphene::db::object),
(total_progressive_jackpot)
(jackpot)
(sweeps_tickets_sold) )
FC_REFLECT( graphene::chain::nft_lottery_data, (lottery_options)(lottery_balance_id) )
FC_REFLECT_DERIVED( graphene::chain::nft_metadata_object, (graphene::db::object),
(owner)

View file

@ -21,6 +21,8 @@ namespace graphene { namespace chain {
time_point_sec end_date;
bool ending_on_soldout;
bool is_active;
bool delete_tickets_after_draw = false;
std::vector<nft_metadata_id_type> progressive_jackpots;
void validate() const;
};
@ -159,7 +161,7 @@ namespace graphene { namespace chain {
} } // graphene::chain
FC_REFLECT( graphene::chain::nft_lottery_benefactor, (id)(share) )
FC_REFLECT( graphene::chain::nft_lottery_options, (benefactors)(winning_tickets)(ticket_price)(end_date)(ending_on_soldout)(is_active) )
FC_REFLECT( graphene::chain::nft_lottery_options, (benefactors)(winning_tickets)(ticket_price)(end_date)(ending_on_soldout)(is_active)(delete_tickets_after_draw)(progressive_jackpots) )
FC_REFLECT( graphene::chain::nft_metadata_create_operation::fee_parameters_type, (fee) (price_per_kbyte) )
FC_REFLECT( graphene::chain::nft_metadata_update_operation::fee_parameters_type, (fee) )

View file

@ -206,7 +206,8 @@ namespace graphene { namespace chain {
impl_global_betting_statistics_object_type,
impl_lottery_balance_object_type,
impl_sweeps_vesting_balance_object_type,
impl_offer_history_object_type
impl_offer_history_object_type,
impl_nft_lottery_balance_object_type
};
//typedef fc::unsigned_int object_id_type;
@ -299,6 +300,7 @@ namespace graphene { namespace chain {
class lottery_balance_object;
class sweeps_vesting_balance_object;
class offer_history_object;
class nft_lottery_balance_object;
typedef object_id< implementation_ids, impl_global_property_object_type, global_property_object> global_property_id_type;
typedef object_id< implementation_ids, impl_dynamic_global_property_object_type, dynamic_global_property_object> dynamic_global_property_id_type;
@ -328,6 +330,7 @@ namespace graphene { namespace chain {
typedef object_id< implementation_ids, impl_lottery_balance_object_type, lottery_balance_object > lottery_balance_id_type;
typedef object_id< implementation_ids, impl_sweeps_vesting_balance_object_type, sweeps_vesting_balance_object> sweeps_vesting_balance_id_type;
typedef object_id< implementation_ids, impl_offer_history_object_type, offer_history_object> offer_history_id_type;
typedef object_id< implementation_ids, impl_nft_lottery_balance_object_type, nft_lottery_balance_object> nft_lottery_balance_id_type;
typedef fc::array<char, GRAPHENE_MAX_ASSET_SYMBOL_LENGTH> symbol_type;
typedef fc::ripemd160 block_id_type;
@ -491,6 +494,7 @@ FC_REFLECT_ENUM( graphene::chain::impl_object_type,
(impl_lottery_balance_object_type)
(impl_sweeps_vesting_balance_object_type)
(impl_offer_history_object_type)
(impl_nft_lottery_balance_object_type)
)
FC_REFLECT_TYPENAME( graphene::chain::share_type )
@ -540,6 +544,7 @@ FC_REFLECT_TYPENAME( graphene::chain::offer_history_id_type )
FC_REFLECT_TYPENAME( graphene::chain::nft_metadata_id_type )
FC_REFLECT_TYPENAME( graphene::chain::nft_id_type )
FC_REFLECT_TYPENAME( graphene::chain::account_role_id_type )
FC_REFLECT_TYPENAME( graphene::chain::nft_lottery_balance_id_type )
FC_REFLECT( graphene::chain::void_t, )

View file

@ -33,6 +33,17 @@ void_result nft_metadata_create_evaluator::do_evaluate( const nft_metadata_creat
if (op.max_supply) {
FC_ASSERT(*op.max_supply >= 5);
}
for(auto lottery_id: (*op.lottery_options).progressive_jackpots) {
const auto& lottery_obj = lottery_id(db());
FC_ASSERT(lottery_obj.owner == op.owner, "Only the Owner can attach progressive jackpots");
FC_ASSERT(lottery_obj.is_lottery(), "Only lottery objects can be attached as progressive jackpots");
FC_ASSERT(lottery_obj.lottery_data->lottery_options.is_active == false, "Lottery should not be active");
FC_ASSERT(lottery_obj.lottery_data->lottery_options.ticket_price.asset_id == (*op.lottery_options).ticket_price.asset_id, "Lottery asset type should be same");
const auto& lottery_balance_obj = lottery_obj.lottery_data->lottery_balance_id(db());
FC_ASSERT(lottery_balance_obj.jackpot.amount > 0, "Non zero progressive jackpot not allowed");
}
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
@ -52,7 +63,21 @@ object_id_type nft_metadata_create_evaluator::do_apply( const nft_metadata_creat
obj.max_supply = *op.max_supply;
}
if (op.lottery_options) {
obj.lottery_data = nft_lottery_data(*op.lottery_options);
asset jackpot_sum(0,(*op.lottery_options).ticket_price.asset_id);
for(auto lottery_id: (*op.lottery_options).progressive_jackpots) {
const auto& lottery_obj = lottery_id(db());
const auto& lottery_balance_obj = lottery_obj.lottery_data->lottery_balance_id(db());
FC_ASSERT(lottery_balance_obj.jackpot.amount > 0, "Non zero progressive jackpot not allowed");
db().modify(lottery_balance_obj, [&] ( nft_lottery_balance_object& nlbo ) {
jackpot_sum += nlbo.jackpot;
nlbo.jackpot -= nlbo.jackpot;
});
}
const auto& new_lottery_balance_obj = db().create<nft_lottery_balance_object>([&](nft_lottery_balance_object& nlbo) {
nlbo.total_progressive_jackpot = jackpot_sum;
nlbo.jackpot = jackpot_sum;
});
obj.lottery_data = nft_lottery_data(*op.lottery_options, new_lottery_balance_obj.id);
}
});
return new_nft_metadata_object.id;

View file

@ -53,8 +53,8 @@ namespace graphene
nft_id = db().apply_operation(nft_mint_context, mint_op).get<object_id_type>();
}
db().adjust_balance(op.buyer, -op.amount);
db().modify(lottery_md_obj, [&](nft_metadata_object &obj) {
obj.lottery_data->jackpot += op.amount;
db().modify(lottery_md_obj.lottery_data->lottery_balance_id(db()), [&](nft_lottery_balance_object &obj) {
obj.jackpot += op.amount;
});
return nft_id;
}
@ -75,7 +75,7 @@ namespace graphene
const auto &lottery_options = lottery_md_obj.lottery_data->lottery_options;
FC_ASSERT(lottery_options.is_active);
FC_ASSERT(lottery_md_obj.get_lottery_jackpot() >= op.amount);
FC_ASSERT(lottery_md_obj.get_lottery_jackpot(d) >= op.amount);
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))
@ -87,8 +87,8 @@ namespace graphene
{
const auto &lottery_md_obj = op.lottery_id(db());
db().adjust_balance(op.winner, op.amount);
db().modify(lottery_md_obj, [&](nft_metadata_object &obj) {
obj.lottery_data->jackpot -= op.amount;
db().modify(lottery_md_obj.lottery_data->lottery_balance_id(db()), [&](nft_lottery_balance_object &obj) {
obj.jackpot -= op.amount;
});
return void_result();
}
@ -107,7 +107,7 @@ namespace graphene
const auto &lottery_options = lottery_md_obj.lottery_data->lottery_options;
FC_ASSERT(lottery_options.is_active);
FC_ASSERT(lottery_md_obj.get_lottery_jackpot().amount == 0);
FC_ASSERT(lottery_md_obj.get_lottery_jackpot(d).amount == 0);
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))
@ -119,9 +119,11 @@ namespace graphene
{
const auto &lottery_md_obj = op.lottery_id(db());
db().modify(lottery_md_obj, [&](nft_metadata_object &obj) {
obj.lottery_data->sweeps_tickets_sold = obj.get_token_current_supply(db());
obj.lottery_data->lottery_options.is_active = false;
});
db().modify(lottery_md_obj.lottery_data->lottery_balance_id(db()), [&](nft_lottery_balance_object &obj) {
obj.sweeps_tickets_sold = lottery_md_obj.get_token_current_supply(db());
});
return void_result();
}
FC_CAPTURE_AND_RETHROW((op))

View file

@ -12,14 +12,14 @@ namespace graphene
return time_point_sec();
}
asset nft_metadata_object::get_lottery_jackpot() const
asset nft_metadata_object::get_lottery_jackpot(const database &db) const
{
if (lottery_data)
return lottery_data->jackpot;
return lottery_data->lottery_balance_id(db).jackpot;
return asset();
}
share_type nft_metadata_object::get_token_current_supply(database &db) const
share_type nft_metadata_object::get_token_current_supply(const database &db) const
{
share_type current_supply;
const auto &idx_lottery_by_md = db.get_index_type<nft_index>().indices().get<by_metadata>();
@ -28,7 +28,7 @@ namespace graphene
return current_supply;
}
vector<account_id_type> nft_metadata_object::get_holders(database &db) const
vector<account_id_type> nft_metadata_object::get_holders(const database &db) const
{
const auto &idx_lottery_by_md = db.get_index_type<nft_index>().indices().get<by_metadata>();
auto lottery_range = idx_lottery_by_md.equal_range(id);
@ -41,7 +41,7 @@ namespace graphene
return holders;
}
vector<uint64_t> nft_metadata_object::get_ticket_ids(database &db) const
vector<uint64_t> nft_metadata_object::get_ticket_ids(const database &db) const
{
const auto &idx_lottery_by_md = db.get_index_type<nft_index>().indices().get<by_metadata>();
auto lottery_range = idx_lottery_by_md.equal_range(id);
@ -58,7 +58,7 @@ namespace graphene
{
transaction_evaluation_state eval(&db);
const auto &lottery_options = lottery_data->lottery_options;
share_type jackpot = lottery_options.ticket_price.amount * get_token_current_supply(db).value;
share_type jackpot = lottery_options.ticket_price.amount * get_token_current_supply(db) + lottery_data->lottery_balance_id(db).total_progressive_jackpot.amount;
for (auto benefactor : lottery_options.benefactors)
{
@ -81,14 +81,14 @@ namespace graphene
auto holders = get_holders(db);
vector<uint64_t> ticket_ids = get_ticket_ids(db);
FC_ASSERT(current_supply.value == (int64_t)holders.size());
FC_ASSERT(lottery_data->jackpot.amount.value == current_supply.value * lottery_options.ticket_price.amount.value);
FC_ASSERT(get_lottery_jackpot(db).amount.value == current_supply.value * lottery_options.ticket_price.amount.value);
map<account_id_type, vector<uint16_t>> structurized_participants;
for (account_id_type holder : holders)
{
if (!structurized_participants.count(holder))
structurized_participants.emplace(holder, vector<uint16_t>());
}
uint64_t jackpot = lottery_data->jackpot.amount.value;
uint64_t jackpot = get_lottery_jackpot(db).amount.value;
auto winner_numbers = db.get_winner_numbers(id, holders.size(), lottery_options.winning_tickets.size());
auto &tickets(lottery_options.winning_tickets);
@ -132,7 +132,7 @@ namespace graphene
auto sweeps_params = db.get_global_properties().parameters;
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(sweeps_params.sweeps_distribution_asset()));
asset remaining_jackpot = get_id()(db).lottery_data->jackpot;
asset remaining_jackpot = get_lottery_jackpot(db);
uint64_t holders_sum = 0;
for (const account_balance_object &holder_balance : boost::make_iterator_range(range.first, range.second))
{
@ -142,8 +142,8 @@ namespace graphene
}
uint64_t balance_rest = remaining_jackpot.amount.value * SWEEPS_VESTING_BALANCE_MULTIPLIER - holders_sum;
db.adjust_sweeps_vesting_balance(sweeps_params.sweeps_vesting_accumulator_account(), balance_rest);
db.modify(get_id()(db), [&](nft_metadata_object &obj) {
obj.lottery_data->jackpot -= remaining_jackpot;
db.modify(lottery_data->lottery_balance_id(db), [&](nft_lottery_balance_object &obj) {
obj.jackpot -= remaining_jackpot;
});
}

View file

@ -1951,6 +1951,8 @@ class wallet_api
bool is_transferable,
bool is_sellable,
optional<account_role_id_type> role_id,
optional<share_type> max_supply,
optional<nft_lottery_options> lottery_options,
bool broadcast);
/**
@ -2088,6 +2090,7 @@ class wallet_api
* @return Returns vector of NFT objects, empty vector if none
*/
vector<nft_object> nft_get_all_tokens() const;
signed_transaction nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast );
signed_transaction create_offer(set<nft_id_type> item_ids,
string issuer_accound_id_or_name,
@ -2399,6 +2402,7 @@ FC_API( graphene::wallet::wallet_api,
(nft_get_approved)
(nft_is_approved_for_all)
(nft_get_all_tokens)
(nft_lottery_buy_ticket)
(create_offer)
(create_bid)
(cancel_offer)

View file

@ -6376,6 +6376,8 @@ signed_transaction wallet_api::nft_metadata_create(string owner_account_id_or_na
bool is_transferable,
bool is_sellable,
optional<account_role_id_type> role_id,
optional<share_type> max_supply,
optional<nft_lottery_options> lottery_options,
bool broadcast)
{
account_object owner_account = my->get_account(owner_account_id_or_name);
@ -6399,6 +6401,8 @@ signed_transaction wallet_api::nft_metadata_create(string owner_account_id_or_na
op.is_transferable = is_transferable;
op.is_sellable = is_sellable;
op.account_role = role_id;
op.max_supply = max_supply;
op.lottery_options = lottery_options;
signed_transaction trx;
trx.operations.push_back(op);
@ -6582,6 +6586,21 @@ vector<nft_object> wallet_api::nft_get_all_tokens() const
return my->_remote_db->nft_get_all_tokens();
}
signed_transaction wallet_api::nft_lottery_buy_ticket( nft_metadata_id_type lottery, account_id_type buyer, uint64_t tickets_to_buy, bool broadcast )
{
nft_lottery_token_purchase_operation op;
op.lottery_id = lottery;
op.buyer = buyer;
op.tickets_to_buy = tickets_to_buy;
signed_transaction trx;
trx.operations.push_back(op);
my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees );
trx.validate();
return my->sign_transaction( trx, broadcast );
}
signed_transaction wallet_api::create_offer(set<nft_id_type> item_ids,
string issuer_accound_id_or_name,
asset minimum_price,

View file

@ -328,7 +328,7 @@ void database_fixture::verify_asset_supplies( const database& db )
{
if (o.lottery_data)
{
total_balances[o.lottery_data->jackpot.asset_id] += o.lottery_data->jackpot.amount;
total_balances[o.get_lottery_jackpot(db).asset_id] += o.get_lottery_jackpot(db).amount;
}
}

View file

@ -85,8 +85,8 @@ BOOST_AUTO_TEST_CASE(create_lottery_nft_md_test)
BOOST_CHECK(obj.max_supply == share_type(200));
BOOST_CHECK(obj.is_lottery());
BOOST_CHECK(obj.get_token_current_supply(db) == share_type(0));
BOOST_CHECK(obj.get_lottery_jackpot() == asset());
BOOST_CHECK(obj.lottery_data->sweeps_tickets_sold == share_type(0));
BOOST_CHECK(obj.get_lottery_jackpot(db) == asset());
BOOST_CHECK(obj.lottery_data->lottery_balance_id(db).sweeps_tickets_sold == share_type(0));
}
catch (fc::exception &e)
{
@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(lottery_end_by_stage_test)
test_nft_md_obj = test_nft_md_id(db);
uint64_t benefactor_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot().amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value;
uint16_t winners_part = 0;
for (uint16_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets)
winners_part += win;
@ -238,13 +238,13 @@ BOOST_AUTO_TEST_CASE(lottery_end_by_stage_test)
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(participants_percents_sum == winners_part);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value == (jackpot * (GRAPHENE_100_PERCENT - winners_part) / (double)GRAPHENE_100_PERCENT) + jackpot * winners_part * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT / (double)GRAPHENE_100_PERCENT);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == (jackpot * (GRAPHENE_100_PERCENT - winners_part) / (double)GRAPHENE_100_PERCENT) + jackpot * winners_part * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT / (double)GRAPHENE_100_PERCENT);
test_nft_md_obj.distribute_benefactors_part(db);
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value == jackpot * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT * winners_part / (double)GRAPHENE_100_PERCENT);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == jackpot * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT * winners_part / (double)GRAPHENE_100_PERCENT);
test_nft_md_obj.distribute_sweeps_holders_part(db);
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value == 0);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0);
uint64_t benefactor_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - benefactor_balance_before_end;
BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == benefactor_recieved);
@ -288,7 +288,7 @@ BOOST_AUTO_TEST_CASE(lottery_end_by_stage_with_fractional_test)
}
test_nft_md_obj = test_nft_md_id(db);
uint64_t benefactor_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot().amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value;
uint16_t winners_part = 0;
for (uint16_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets)
winners_part += win;
@ -302,14 +302,14 @@ BOOST_AUTO_TEST_CASE(lottery_end_by_stage_with_fractional_test)
BOOST_CHECK(participants_percents_sum == winners_part);
// balance should be bigger than expected because of rouning during distribution
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value > (jackpot * (GRAPHENE_100_PERCENT - winners_part) / (double)GRAPHENE_100_PERCENT) + jackpot * winners_part * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT / (double)GRAPHENE_100_PERCENT);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value > (jackpot * (GRAPHENE_100_PERCENT - winners_part) / (double)GRAPHENE_100_PERCENT) + jackpot * winners_part * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT / (double)GRAPHENE_100_PERCENT);
test_nft_md_obj.distribute_benefactors_part(db);
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value > jackpot * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT * winners_part / (double)GRAPHENE_100_PERCENT);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value > jackpot * SWEEPS_DEFAULT_DISTRIBUTION_PERCENTAGE / (double)GRAPHENE_100_PERCENT * winners_part / (double)GRAPHENE_100_PERCENT);
test_nft_md_obj.distribute_sweeps_holders_part(db);
test_nft_md_obj = test_nft_md_id(db);
// but at the end is always equals 0
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value == 0);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0);
uint64_t benefactor_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - benefactor_balance_before_end;
test_nft_md_obj = test_nft_md_id(db);
@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(lottery_end_test)
generate_block();
test_nft_md_obj = test_nft_md_id(db);
uint64_t creator_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot().amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value;
uint16_t winners_part = 0;
for (uint8_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets)
winners_part += win;
@ -357,7 +357,7 @@ BOOST_AUTO_TEST_CASE(lottery_end_test)
while (db.head_block_time() < (test_nft_md_obj.lottery_data->lottery_options.end_date + fc::seconds(30)))
generate_block();
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value == 0);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0);
uint64_t creator_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - creator_balance_before_end;
BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == creator_recieved);
}
@ -480,11 +480,11 @@ BOOST_AUTO_TEST_CASE(ending_by_date_test)
generate_block();
test_nft_md_obj = test_nft_md_id(db);
auto holders = test_nft_md_obj.get_holders(db);
idump((test_nft_md_obj.get_lottery_jackpot()));
idump((test_nft_md_obj.get_lottery_jackpot(db)));
while (db.head_block_time() < (test_nft_md_obj.lottery_data->lottery_options.end_date + fc::seconds(30)))
generate_block();
test_nft_md_obj = test_nft_md_id(db);
idump((test_nft_md_obj.get_lottery_jackpot()));
idump((test_nft_md_obj.get_lottery_jackpot(db)));
vector<account_id_type> participants = {account_id_type(1), account_id_type(2), account_id_type(3)};
for (auto p : participants)
{
@ -604,7 +604,7 @@ BOOST_AUTO_TEST_CASE(lottery_winner_ticket_id_test)
generate_block();
test_nft_md_obj = test_nft_md_id(db);
uint64_t creator_balance_before_end = db.get_balance(account_id_type(), asset_id_type()).amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot().amount.value;
uint64_t jackpot = test_nft_md_obj.get_lottery_jackpot(db).amount.value;
uint16_t winners_part = 0;
for (uint8_t win : test_nft_md_obj.lottery_data->lottery_options.winning_tickets)
winners_part += win;
@ -617,7 +617,7 @@ BOOST_AUTO_TEST_CASE(lottery_winner_ticket_id_test)
idump((h));
}
test_nft_md_obj = test_nft_md_id(db);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot().amount.value == 0);
BOOST_CHECK(test_nft_md_obj.get_lottery_jackpot(db).amount.value == 0);
uint64_t creator_recieved = db.get_balance(account_id_type(), asset_id_type()).amount.value - creator_balance_before_end;
BOOST_CHECK(jackpot * test_nft_md_obj.lottery_data->lottery_options.benefactors[0].share / GRAPHENE_100_PERCENT == creator_recieved);
}