added get_account_lotteries method to db_api and cli, lottery end_date and ticket_price verification

This commit is contained in:
kstdl 2018-01-03 15:34:15 +03:00 committed by gladcow
parent 51b2ca625e
commit 62dd8482d9
7 changed files with 65 additions and 9 deletions

View file

@ -118,6 +118,10 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<asset_object> get_lotteries( asset_id_type stop = asset_id_type(),
unsigned limit = 100,
asset_id_type start = asset_id_type() )const;
vector<asset_object> get_account_lotteries( account_id_type issuer,
asset_id_type stop,
unsigned limit,
asset_id_type start )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;
@ -1032,9 +1036,9 @@ vector<asset_object> database_api::get_lotteries( asset_id_type stop,
{
return my->get_lotteries( stop, limit, start );
}
vector<asset_object> database_api_impl::get_lotteries(asset_id_type stop,
unsigned limit,
asset_id_type start )const
vector<asset_object> database_api_impl::get_lotteries( asset_id_type stop,
unsigned limit,
asset_id_type start )const
{
vector<asset_object> result;
if( limit > 100 ) limit = 100;
@ -1051,6 +1055,34 @@ vector<asset_object> database_api_impl::get_lotteries(asset_id_type stop,
return result;
}
vector<asset_object> database_api::get_account_lotteries( account_id_type issuer,
asset_id_type stop,
unsigned limit,
asset_id_type start )const
{
return my->get_account_lotteries( issuer, stop, limit, start );
}
vector<asset_object> database_api_impl::get_account_lotteries( account_id_type issuer,
asset_id_type stop,
unsigned limit,
asset_id_type start )const
{
vector<asset_object> result;
if( limit > 100 ) limit = 100;
const auto& assets = _db.get_index_type<asset_index>().indices().get<by_lottery>();
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 ) )
{
if( start == asset_id_type() || (a.get_id().instance.value <= start.instance.value) )
result.push_back( a );
if( a.get_id().instance.value < stop.instance.value || result.size() >= limit )
break;
}
return result;
}
asset database_api::get_lottery_balance( asset_id_type lottery_id )const
{

View file

@ -359,7 +359,10 @@ class database_api
vector<asset_object> get_lotteries( asset_id_type stop = asset_id_type(),
unsigned limit = 100,
asset_id_type start = asset_id_type() )const;
vector<asset_object> get_account_lotteries( account_id_type issuer,
asset_id_type stop,
unsigned limit,
asset_id_type start )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;
/**
@ -755,6 +758,7 @@ FC_API(graphene::app::database_api,
// Sweeps
(get_lotteries)
(get_account_lotteries)
(get_lottery_balance)
(get_sweeps_vesting_balance_object)
(get_sweeps_vesting_balance_available_for_claim)

View file

@ -120,7 +120,9 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o
if( op.extensions.which() == asset_extension::tag<lottery_asset_options>::value ) {
FC_ASSERT( op.common_options.max_supply >= 5 );
op.extensions.get<lottery_asset_options>().validate();
auto lottery_options = op.extensions.get<lottery_asset_options>();
lottery_options.validate();
FC_ASSERT( lottery_options.end_date > d.head_block_time() );
}
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -118,6 +118,8 @@ namespace graphene { namespace chain {
string amount_to_pretty_string(const asset &amount)const
{ FC_ASSERT(amount.asset_id == id); return amount_to_pretty_string(amount.amount); }
uint32_t get_issuer_num()const
{ return issuer.instance.value; }
/// Ticker symbol for this asset, i.e. "USD"
string symbol;
/// Maximum number of digits after the decimal point (must be <= 12)
@ -280,10 +282,12 @@ namespace graphene { namespace chain {
composite_key<
asset_object,
const_mem_fun<asset_object, bool, &asset_object::is_lottery>,
const_mem_fun<asset_object, uint32_t, &asset_object::get_issuer_num>,
member<object, object_id_type, &object::id>
>,
composite_key_compare<
std::greater< bool >,
std::greater< uint32_t >,
std::greater< object_id_type >
>
>,

View file

@ -252,6 +252,7 @@ void asset_claim_fees_operation::validate()const {
void lottery_asset_options::validate() const
{
FC_ASSERT( winning_tickets.size() <= 64 );
FC_ASSERT( ticket_price.amount >= 1 );
uint16_t total = 0;
for( auto benefactor : benefactors ) {
total += benefactor.share;

View file

@ -353,6 +353,10 @@ class wallet_api
vector<asset_object> get_lotteries( asset_id_type stop = asset_id_type(),
unsigned limit = 100,
asset_id_type start = asset_id_type() )const;
vector<asset_object> get_account_lotteries( account_id_type issuer,
asset_id_type stop = asset_id_type(),
unsigned limit = 100,
asset_id_type start = asset_id_type() )const;
asset get_lottery_balance( asset_id_type lottery_id ) const;
/** Returns the most recent operations on the named account.
@ -1964,6 +1968,7 @@ FC_API( graphene::wallet::wallet_api,
(get_asset)
(get_bitasset_data)
(get_lotteries)
(get_account_lotteries)
(get_lottery_balance)
(fund_asset_fee_pool)
(reserve_asset)

View file

@ -1816,10 +1816,10 @@ public:
witness_create_op.block_signing_key = witness_public_key;
witness_create_op.url = url;
secret_hash_type::encoder enc;
fc::raw::pack(enc, witness_private_key);
fc::raw::pack(enc, secret_hash_type());
witness_create_op.initial_secret = secret_hash_type::hash(enc.result());
// secret_hash_type::encoder enc;
// fc::raw::pack(enc, witness_private_key);
// fc::raw::pack(enc, secret_hash_type());
witness_create_op.initial_secret = secret_hash_type();
if (_remote_db->get_witness_by_account(witness_create_op.witness_account))
@ -3513,6 +3513,14 @@ vector<asset_object> wallet_api::get_lotteries( asset_id_type stop,
return my->_remote_db->get_lotteries( stop, limit, start );
}
vector<asset_object> wallet_api::get_account_lotteries( account_id_type issuer,
asset_id_type stop,
unsigned limit,
asset_id_type start )const
{
return my->_remote_db->get_account_lotteries( issuer, stop, limit, start );
}
asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const
{
return my->_remote_db->get_lottery_balance( lottery_id );